14 using namespace shogun;
20 register_parameters();
27 register_parameters();
32 m_features = features;
72 REQUIRE(m_combination_rule != NULL,
"Combination rule is not set!");
78 #pragma omp parallel for num_threads(parallel->get_num_threads())
79 for (int32_t i = 0; i < m_num_bags; ++i)
84 float64_t* bag_results = output.get_column_vector(i);
98 REQUIRE(m_machine != NULL,
"Machine is not set!");
99 REQUIRE(m_bag_size > 0,
"Bag size is not set!");
100 REQUIRE(m_num_bags > 0,
"Number of bag is not set!");
112 ASSERT(m_bag_size < m_features->get_num_vectors());
119 m_all_oob_idx.
zero();
129 for (int32_t i = 0; i < m_num_bags; ++i)
154 c->
train(m_features);
169 void CBaggingMachine::register_parameters()
171 SG_ADD((
CSGObject**)&m_features,
"features",
"Train features for bagging",
177 "Combination rule to use for aggregating",
MS_AVAILABLE);
178 SG_ADD(&m_all_oob_idx,
"all_oob_idx",
"Indices of all oob vectors",
186 m_num_bags = num_bags;
196 m_bag_size = bag_size;
217 void CBaggingMachine::init()
222 m_combination_rule = NULL;
227 m_oob_indices = NULL;
234 m_combination_rule = rule;
239 SG_REF(m_combination_rule);
240 return m_combination_rule;
245 REQUIRE(m_combination_rule != NULL,
"Combination rule is not set!");
252 output.set_const(
NAN);
272 for (
index_t j = 0; j < oob.vlen; j++)
273 output(oob[j], i) = lv[j];
280 output.display_matrix();
285 if (m_all_oob_idx[i])
306 SG_ERROR(
"Unsupported label type\n");
325 if (out_of_bag[in_bag[i]])
327 out_of_bag[in_bag[i]] =
false;
334 for (
index_t i = 0; i < out_of_bag.vlen; i++)
339 m_all_oob_idx[i] =
true;
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
void set_combination_rule(CCombinationRule *rule)
virtual ELabelType get_label_type() const =0
Real Labels are real-valued labels.
CCombinationRule * get_combination_rule() const
The class Labels models labels, i.e. class assignments of objects.
virtual CSGObject * clone()
virtual int32_t get_num_labels() const =0
real valued labels (e.g. for regression, classifier outputs)
virtual bool train_machine(CFeatures *data=NULL)
multi-class labels 0,1,...
int32_t get_bag_size() const
virtual float64_t evaluate(CLabels *predicted, CLabels *ground_truth)=0
virtual int32_t get_num_vectors() const =0
int32_t get_num_elements() const
void random(T min_value, T max_value)
int32_t get_num_bags() const
int32_t get_num_elements() const
SGVector< float64_t > apply_get_outputs(CFeatures *data)
int32_t get_num_elements() const
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
A generic learning machine interface.
CMachine * get_machine() const
virtual SGVector< float64_t > combine(const SGMatrix< float64_t > &ensemble_result) const =0
Multiclass Labels for multi-class classification.
Class SGObject is the base class of all shogun objects.
void push_back(T element)
void set_machine(CMachine *machine)
virtual ~CBaggingMachine()
Template Dynamic array class that creates an array that can be used like a list or an array...
virtual void remove_subset()
virtual void add_subset(SGVector< index_t > subset)
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
void set_const(T const_elem)
void set_num_bags(int32_t num_bags)
virtual SGVector< float64_t > get_values()
Template Dynamic array class that creates an array that can be used like a list or an array...
virtual void remove_subset()
The class Features is the base class of all feature objects.
CombinationRule abstract class The CombinationRule defines an interface to how to combine the classif...
virtual bool train(CFeatures *data=NULL)
Binary Labels for binary classification.
CSGObject * get_element(int32_t index) const
void push_back(CSGObject *e)
void display_vector(const char *name="vector", const char *prefix="") const
virtual CBinaryLabels * apply_binary(CFeatures *data=NULL)
float64_t get_oob_error(CEvaluation *eval) const
virtual void set_labels(CLabels *lab)
Class Evaluation, a base class for other classes used to evaluate labels, e.g. accuracy of classifica...
virtual void add_subset(SGVector< index_t > subset)
void set_bag_size(int32_t bag_size)
bool append_element(CSGObject *e)
virtual CLabels * apply(CFeatures *data=NULL)