Skip to content

Commit

Permalink
Merge branch 'multiclass' of git://github.com/pluskid/shogun
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jul 7, 2012
2 parents 9d82c0b + 658757d commit 6af57ce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Expand Up @@ -8,11 +8,13 @@ def classifier_multiclass_shareboost (fm_train_real=traindat,fm_test_real=testda
from shogun.Features import RealFeatures, RealSubsetFeatures, MulticlassLabels
from shogun.Classifier import ShareBoost

print('Working on a problem of %d features and %d samples' % fm_train_real.shape)

feats_train = RealFeatures(fm_train_real)

labels = MulticlassLabels(label_train_multiclass)

shareboost = ShareBoost(feats_train, labels, min(fm_train_real.shape[0]-1, 20))
shareboost = ShareBoost(feats_train, labels, min(fm_train_real.shape[0]-1, 30))
shareboost.train();
print(shareboost.get_activeset())

Expand Down
18 changes: 17 additions & 1 deletion src/shogun/multiclass/ShareBoost.cpp
Expand Up @@ -10,6 +10,7 @@

#include <algorithm>

#include <shogun/lib/Time.h>
#include <shogun/mathematics/Math.h>
#include <shogun/multiclass/ShareBoost.h>
#include <shogun/multiclass/ShareBoostOptimizer.h>
Expand Down Expand Up @@ -68,16 +69,31 @@ bool CShareBoost::train_machine(CFeatures* data)
for (int32_t i=0; i < m_multiclass_strategy->get_num_classes(); ++i)
m_machines->push_back(new CLinearMachine());

CTime *timer = new CTime();

float64_t t_compute_pred = 0; // t of 1st round is 0, since no pred to compute
for (int32_t t=0; t < m_nonzero_feas; ++t)
{
timer->start();
compute_rho();
int32_t i_fea = choose_feature();
m_activeset.vector[m_activeset.vlen] = i_fea;
m_activeset.vlen += 1;
float64_t t_choose_feature = timer->cur_time_diff();
timer->start();
optimize_coefficients();
float64_t t_optimize = timer->cur_time_diff();

SG_SPRINT(" SB[round %03d]: (%8.4f + %8.4f) sec.\n", t,
t_compute_pred + t_choose_feature, t_optimize);

timer->start();
compute_pred();
t_compute_pred = timer->cur_time_diff();
}

SG_UNREF(timer);

// release memory
m_fea = SGMatrix<float64_t>();
m_rho = SGMatrix<float64_t>();
Expand Down Expand Up @@ -174,7 +190,7 @@ int32_t CShareBoost::choose_feature()

void CShareBoost::optimize_coefficients()
{
ShareBoostOptimizer optimizer(this, true);
ShareBoostOptimizer optimizer(this, false);
optimizer.optimize();
}

Expand Down
2 changes: 1 addition & 1 deletion src/shogun/multiclass/ShareBoostOptimizer.cpp
Expand Up @@ -97,7 +97,7 @@ int ShareBoostOptimizer::lbfgs_progress(
int ls
)
{
if (k % 100 != 0)
if (k != 1 && k % 100 != 0)
return 0;

SG_SPRINT("Iteration %d:\n", k);
Expand Down

0 comments on commit 6af57ce

Please sign in to comment.