diff --git a/src/shogun/machine/BaggingMachine.cpp b/src/shogun/machine/BaggingMachine.cpp index 6d721e4870b..2b4449a98b1 100644 --- a/src/shogun/machine/BaggingMachine.cpp +++ b/src/shogun/machine/BaggingMachine.cpp @@ -14,35 +14,30 @@ using namespace shogun; CBaggingMachine::CBaggingMachine() - : CMachine(), - m_features(NULL), - m_num_bags(0), - m_bag_size(0) + : CMachine() { + init(); register_parameters(); } CBaggingMachine::CBaggingMachine(CFeatures* features, CLabels* labels) - : CMachine(), - m_num_bags(0), - m_bag_size(0) + : CMachine() { + init(); + register_parameters(); + set_labels(labels); + SG_REF(m_features); m_features = features; - register_parameters(); } CBaggingMachine::~CBaggingMachine() { - if (m_machine) { - SG_UNREF(m_machine); - m_machine = NULL; - } - - if (m_features) { - SG_UNREF(m_features); - } + SG_UNREF(m_machine); + m_machine = NULL; + SG_UNREF(m_features); + m_features = NULL; } CLabels* CBaggingMachine::apply(CFeatures* data) @@ -95,6 +90,7 @@ bool CBaggingMachine::train_machine(CFeatures* data) for (int32_t i = 0; i < m_num_bags; ++i) { CMachine* c = dynamic_cast(m_machine->clone()); + ASSERT(c != NULL); SGVector idx(m_bag_size); idx.random(0, m_features->get_num_vectors()); m_features->add_subset(idx); @@ -151,3 +147,10 @@ void CBaggingMachine::set_machine(CMachine* machine) SG_REF(machine); m_machine = machine; } + +void CBaggingMachine::init() +{ + m_features = NULL; + m_num_bags = 0; + m_bag_size = 0; +} diff --git a/src/shogun/machine/BaggingMachine.h b/src/shogun/machine/BaggingMachine.h index ba6cae8953e..891a6f045d9 100644 --- a/src/shogun/machine/BaggingMachine.h +++ b/src/shogun/machine/BaggingMachine.h @@ -8,8 +8,8 @@ * Copyright (C) 2013 Viktor Gal */ -#ifndef __BAGGINGMACHINE_H__ -#define __BAGGINGMACHINE_H__ +#ifndef BAGGINGMACHINE_H +#define BAGGINGMACHINE_H #include @@ -90,6 +90,7 @@ namespace shogun private: void register_parameters(); + void init(); private: /** bags array */ @@ -109,4 +110,4 @@ namespace shogun }; } -#endif /* __BAGGINGMACHINE_H__ */ +#endif /* BAGGINGMACHINE_H */