SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BaggingMachine.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) 2013 Viktor Gal
8  * Copyright (C) 2013 Viktor Gal
9  */
10 
11 #ifndef BAGGINGMACHINE_H
12 #define BAGGINGMACHINE_H
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/machine/Machine.h>
17 
18 namespace shogun
19 {
20  class CCombinationRule;
21  class CEvaluation;
22 
27  class CBaggingMachine : public CMachine
28  {
29  public:
32 
39  CBaggingMachine(CFeatures* features, CLabels* labels);
40 
41  virtual ~CBaggingMachine();
42 
43  virtual CBinaryLabels* apply_binary(CFeatures* data=NULL);
44  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
45  virtual CRegressionLabels* apply_regression(CFeatures* data=NULL);
46 
52  void set_num_bags(int32_t num_bags);
53 
59  int32_t get_num_bags() const;
60 
67  void set_bag_size(int32_t bag_size);
68 
75  int32_t get_bag_size() const;
76 
82  CMachine* get_machine() const;
83 
89  void set_machine(CMachine* machine);
90 
98 
105 
111 
118  float64_t get_oob_error(CEvaluation* eval) const;
119 
121  virtual const char* get_name() const { return "BaggingMachine"; }
122 
123  protected:
124  virtual bool train_machine(CFeatures* data=NULL);
125 
133 
134  private:
135  void register_parameters();
136  void init();
137 
145  CDynamicArray<index_t>* get_oob_indices(const SGVector<index_t>& in_bag);
146 
147  void clear_oob_indicies();
148 
149  private:
151  CDynamicObjectArray* m_bags;
152 
154  CFeatures* m_features;
155 
157  CMachine* m_machine;
158 
160  int32_t m_num_bags;
161 
163  int32_t m_bag_size;
164 
166  CCombinationRule* m_combination_rule;
167 
169  SGVector<bool> m_all_oob_idx;
170 
172  CDynamicObjectArray* m_oob_indices;
173  };
174 }
175 
176 #endif /* BAGGINGMACHINE_H */

SHOGUN Machine Learning Toolbox - Documentation