SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SubsetStack.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Heiko Strathmann
8  */
9 
10 #ifndef __SUBSETSTACK_H_
11 #define __SUBSETSTACK_H_
12 
13 #include <shogun/lib/config.h>
14 
15 #include <shogun/base/SGObject.h>
18 #include <shogun/features/Subset.h>
19 
20 
21 namespace shogun
22 {
23 
37 class CSubsetStack: public CSGObject
38 {
39 public:
42  CSubsetStack();
43 
46  CSubsetStack(const CSubsetStack& other);
47 
49  virtual ~CSubsetStack();
50 
52  inline const char* get_name() const { return "SubsetStack"; }
53 
62  virtual void add_subset(SGVector<index_t> subset);
63 
71  virtual void add_subset_in_place(SGVector<index_t> subset);
72 
74  virtual void remove_subset();
75 
77  virtual void remove_all_subsets();
78 
80  inline index_t get_size() const
81  {
82  if (!has_subsets())
83  SG_WARNING("CSubsetStack::get_size(): No subset in stack!\n")
84 
85  return has_subsets() ? m_active_subset->get_size() : -1;
86  }
87 
89  virtual bool has_subsets() const
90  {
91  return m_active_subsets_stack->get_num_elements();
92  }
93 
98  CSubset* get_last_subset() const { return m_active_subset; }
99 
106  {
107  return m_active_subset ? m_active_subset->m_subset_idx.vector[idx] : idx;
108  }
109 
110 private:
112  void init();
113 
114 private:
119  CDynamicObjectArray* m_active_subsets_stack;
120 
122  CSubset* m_active_subset;
123 };
124 
125 }
126 #endif /* __SUBSETSTACK_H_ */
Wrapper class for an index subset which is used by SubsetStack.
Definition: Subset.h:24
int32_t index_t
Definition: common.h:62
index_t get_size() const
Definition: SubsetStack.h:80
const char * get_name() const
Definition: SubsetStack.h:52
class to add subset support to another class. A CSubsetStackStack instance should be added and wrappe...
Definition: SubsetStack.h:37
CSubset * get_last_subset() const
Definition: SubsetStack.h:98
virtual void add_subset(SGVector< index_t > subset)
Definition: SubsetStack.cpp:80
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
virtual void remove_all_subsets()
Definition: SubsetStack.cpp:59
virtual void add_subset_in_place(SGVector< index_t > subset)
index_t subset_idx_conversion(index_t idx) const
Definition: SubsetStack.h:105
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual bool has_subsets() const
Definition: SubsetStack.h:89
virtual void remove_subset()
index_t get_size() const
Definition: Subset.h:42
#define SG_WARNING(...)
Definition: SGIO.h:128

SHOGUN Machine Learning Toolbox - Documentation