Skip to content

Commit

Permalink
Fix BaggingMachine based on @karlnapf feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vigsterkr committed Jun 14, 2013
1 parent a1dec8b commit e4f8384
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
35 changes: 19 additions & 16 deletions src/shogun/machine/BaggingMachine.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -95,6 +90,7 @@ bool CBaggingMachine::train_machine(CFeatures* data)
for (int32_t i = 0; i < m_num_bags; ++i)
{
CMachine* c = dynamic_cast<CMachine*>(m_machine->clone());
ASSERT(c != NULL);
SGVector<index_t> idx(m_bag_size);
idx.random(0, m_features->get_num_vectors());
m_features->add_subset(idx);
Expand Down Expand Up @@ -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;
}
7 changes: 4 additions & 3 deletions src/shogun/machine/BaggingMachine.h
Expand Up @@ -8,8 +8,8 @@
* Copyright (C) 2013 Viktor Gal
*/

#ifndef __BAGGINGMACHINE_H__
#define __BAGGINGMACHINE_H__
#ifndef BAGGINGMACHINE_H
#define BAGGINGMACHINE_H

#include <shogun/machine/Machine.h>

Expand Down Expand Up @@ -90,6 +90,7 @@ namespace shogun

private:
void register_parameters();
void init();

private:
/** bags array */
Expand All @@ -109,4 +110,4 @@ namespace shogun
};
}

#endif /* __BAGGINGMACHINE_H__ */
#endif /* BAGGINGMACHINE_H */

0 comments on commit e4f8384

Please sign in to comment.