Skip to content

Commit

Permalink
measure running time of each round in ShareBoost.
Browse files Browse the repository at this point in the history
  • Loading branch information
pluskid committed Jul 7, 2012
1 parent 564295a commit d66fc4a
Show file tree
Hide file tree
Showing 3 changed files with 16 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
13 changes: 12 additions & 1 deletion src/shogun/multiclass/ShareBoost.cpp
Expand Up @@ -9,6 +9,7 @@
*/

#include <algorithm>
#include <ctime>

#include <shogun/mathematics/Math.h>
#include <shogun/multiclass/ShareBoost.h>
Expand Down Expand Up @@ -68,14 +69,24 @@ 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());

clock_t t_compute_pred = 0;
for (int32_t t=0; t < m_nonzero_feas; ++t)
{
clock_t t_start = clock();
compute_rho();
int32_t i_fea = choose_feature();
m_activeset.vector[m_activeset.vlen] = i_fea;
m_activeset.vlen += 1;
clock_t t_choose_feature = clock();
optimize_coefficients();
clock_t t_optimize = clock();

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

compute_pred();
t_compute_pred = clock() - t_optimize;
}

// release memory
Expand Down Expand Up @@ -174,7 +185,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 d66fc4a

Please sign in to comment.