SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2013 Viktor Gal 00008 * Copyright (C) 2013 Viktor Gal 00009 */ 00010 00011 #ifndef BAGGINGMACHINE_H 00012 #define BAGGINGMACHINE_H 00013 00014 #include <shogun/machine/Machine.h> 00015 #include <shogun/ensemble/CombinationRule.h> 00016 #include <shogun/evaluation/Evaluation.h> 00017 00018 namespace shogun 00019 { 00024 class CBaggingMachine : public CMachine 00025 { 00026 public: 00028 CBaggingMachine(); 00029 00036 CBaggingMachine(CFeatures* features, CLabels* labels); 00037 00038 virtual ~CBaggingMachine(); 00039 00040 virtual CBinaryLabels* apply_binary(CFeatures* data=NULL); 00041 virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL); 00042 virtual CRegressionLabels* apply_regression(CFeatures* data=NULL); 00043 00049 void set_num_bags(int32_t num_bags); 00050 00056 int32_t get_num_bags() const; 00057 00064 void set_bag_size(int32_t bag_size); 00065 00072 int32_t get_bag_size() const; 00073 00079 CMachine* get_machine() const; 00080 00086 void set_machine(CMachine* machine); 00087 00094 void set_combination_rule(CCombinationRule* rule); 00095 00101 CCombinationRule* get_combination_rule() const; 00102 00107 virtual EMachineType get_classifier_type() { return CT_BAGGING; } 00108 00115 float64_t get_oob_error(CEvaluation* eval) const; 00116 00118 virtual const char* get_name() const { return "BaggingMachine"; } 00119 00120 protected: 00121 virtual bool train_machine(CFeatures* data=NULL); 00122 00129 SGVector<float64_t> apply_get_outputs(CFeatures* data); 00130 00131 private: 00132 void register_parameters(); 00133 void init(); 00134 00142 CDynamicArray<index_t>* get_oob_indices(const SGVector<index_t>& in_bag); 00143 00144 void clear_oob_indicies(); 00145 00146 private: 00148 CDynamicObjectArray* m_bags; 00149 00151 CFeatures* m_features; 00152 00154 CMachine* m_machine; 00155 00157 int32_t m_num_bags; 00158 00160 int32_t m_bag_size; 00161 00163 CCombinationRule* m_combination_rule; 00164 00166 SGVector<bool> m_all_oob_idx; 00167 00169 CDynamicObjectArray* m_oob_indices; 00170 }; 00171 } 00172 00173 #endif /* BAGGINGMACHINE_H */