Skip to content

Commit

Permalink
[ProgressBar] Replace all SG_SABS_PROGRESS with progress().
Browse files Browse the repository at this point in the history
  • Loading branch information
geektoni committed Jun 6, 2017
1 parent 9621165 commit 0566192
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
25 changes: 14 additions & 11 deletions src/shogun/classifier/svm/LibLinear.cpp
Expand Up @@ -18,6 +18,7 @@
#include <shogun/optimization/liblinear/tron.h>
#include <shogun/features/DotFeatures.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/base/progress.h>

using namespace shogun;

Expand Down Expand Up @@ -313,7 +314,7 @@ void CLibLinear::solve_l2r_l1l2_svc(
index[i] = i;
}


auto pb = progress(range(10));
CTime start_time;
while (iter < max_iterations && !CSignal::cancel_computations())
{
Expand Down Expand Up @@ -392,7 +393,7 @@ void CLibLinear::solve_l2r_l1l2_svc(

iter++;
float64_t gap=PGmax_new - PGmin_new;
SG_SABS_PROGRESS(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(eps), 6)
pb.print_absolute(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(eps));

if(gap <= eps)
{
Expand All @@ -414,7 +415,7 @@ void CLibLinear::solve_l2r_l1l2_svc(
PGmin_old = -CMath::INFTY;
}

SG_DONE()
pb.complete_absolute();
SG_INFO("optimization finished, #iter = %d\n",iter)
if (iter >= max_iterations)
{
Expand Down Expand Up @@ -522,7 +523,7 @@ void CLibLinear::solve_l1r_l2_svc(
}
}


auto pb = progress(range(10));
CTime start_time;
while (iter < max_iterations && !CSignal::cancel_computations())
{
Expand Down Expand Up @@ -742,8 +743,8 @@ void CLibLinear::solve_l1r_l2_svc(
Gmax_init = Gmax_new;
iter++;

SG_SABS_PROGRESS(Gmax_new, -CMath::log10(Gmax_new),
-CMath::log10(Gmax_init), -CMath::log10(eps*Gmax_init), 6);
pb.print_absolute(Gmax_new, -CMath::log10(Gmax_new),
-CMath::log10(Gmax_init), -CMath::log10(eps*Gmax_init));

if(Gmax_new <= eps*Gmax_init)
{
Expand All @@ -760,7 +761,7 @@ void CLibLinear::solve_l1r_l2_svc(
Gmax_old = Gmax_new;
}

SG_DONE()
pb.complete_absolute();
SG_INFO("optimization finished, #iter = %d\n", iter)
if(iter >= max_iterations)
SG_WARNING("\nWARNING: reaching max number of iterations\n")
Expand Down Expand Up @@ -893,6 +894,7 @@ void CLibLinear::solve_l1r_lr(
}
}

auto pb=progress(range(10));
CTime start_time;
while (iter < max_iterations && !CSignal::cancel_computations())
{
Expand Down Expand Up @@ -1105,7 +1107,7 @@ void CLibLinear::solve_l1r_lr(
if(iter == 0)
Gmax_init = Gmax_new;
iter++;
SG_SABS_PROGRESS(Gmax_new, -CMath::log10(Gmax_new), -CMath::log10(Gmax_init), -CMath::log10(eps*Gmax_init), 6)
pb.print_absolute(Gmax_new, -CMath::log10(Gmax_new), -CMath::log10(Gmax_init), -CMath::log10(eps*Gmax_init));

if(Gmax_new <= eps*Gmax_init)
{
Expand All @@ -1122,7 +1124,7 @@ void CLibLinear::solve_l1r_lr(
Gmax_old = Gmax_new;
}

SG_DONE()
pb.complete_absolute();
SG_INFO("optimization finished, #iter = %d\n", iter)
if(iter >= max_iterations)
SG_WARNING("\nWARNING: reaching max number of iterations\n")
Expand Down Expand Up @@ -1230,6 +1232,7 @@ void CLibLinear::solve_l2r_lr_dual(SGVector<float64_t>& w, const liblinear_probl
index[i] = i;
}

auto pb=progress(range(10));
while (iter < max_iter)
{
for (i=0; i<l; i++)
Expand Down Expand Up @@ -1304,7 +1307,7 @@ void CLibLinear::solve_l2r_lr_dual(SGVector<float64_t>& w, const liblinear_probl
Gmax_init = Gmax;
iter++;

SG_SABS_PROGRESS(Gmax, -CMath::log10(Gmax), -CMath::log10(Gmax_init), -CMath::log10(eps*Gmax_init), 6)
pb.print_absolute(Gmax, -CMath::log10(Gmax), -CMath::log10(Gmax_init), -CMath::log10(eps*Gmax_init));

if(Gmax < eps)
break;
Expand All @@ -1314,7 +1317,7 @@ void CLibLinear::solve_l2r_lr_dual(SGVector<float64_t>& w, const liblinear_probl

}

SG_DONE()
pb.complete_absolute();
SG_INFO("optimization finished, #iter = %d\n",iter)
if (iter >= max_iter)
SG_WARNING("reaching max number of iterations\nUsing -s 0 may be faster (also see FAQ)\n\n")
Expand Down
9 changes: 6 additions & 3 deletions src/shogun/lib/external/libocas.cpp
Expand Up @@ -28,6 +28,7 @@
#include <shogun/lib/external/libocas.h>
#include <shogun/lib/external/libocas_common.h>
#include <shogun/lib/external/libqp.h>
#include <shogun/base/progress.h>

namespace shogun
{
Expand Down Expand Up @@ -690,12 +691,13 @@ ocas_return_value_T svm_ocas_solver(
ocas.Q_D = 0;

/* Compute the initial cutting plane */
auto pb=progress(range(10));
cut_length = nData;
for(i=0; i < nData; i++)
new_cut[i] = i;

gap=(ocas.Q_P-ocas.Q_D)/CMath::abs(ocas.Q_P);
SG_SABS_PROGRESS(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(TolRel), 6)
pb.print_absolute(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(TolRel));

ocas.trn_err = nData;
ocas.ocas_time = get_time() - ocas_start_time;
Expand Down Expand Up @@ -765,7 +767,7 @@ ocas_return_value_T svm_ocas_solver(
}
ocas.output_time += get_time()-start_time;
gap=(ocas.Q_P-ocas.Q_D)/CMath::abs(ocas.Q_P);
SG_SABS_PROGRESS(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(TolRel), 6)
pb.print_absolute(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(TolRel));

xi = 0;
cut_length = 0;
Expand Down Expand Up @@ -936,6 +938,7 @@ ocas_return_value_T svm_ocas_solver(

} /* end of the main loop */

pb.complete_absolute();
cleanup:

LIBOCAS_FREE(H);
Expand Down Expand Up @@ -1385,8 +1388,8 @@ ocas_return_value_T svm_ocas_solver_difC(

} /* end of the main loop */

cleanup:

cleanup:
LIBOCAS_FREE(H);
LIBOCAS_FREE(b);
LIBOCAS_FREE(alpha);
Expand Down
5 changes: 3 additions & 2 deletions src/shogun/lib/external/shogun_libsvm.cpp
Expand Up @@ -466,7 +466,7 @@ void Solver::Solve(

int32_t iter = 0;
int32_t counter = CMath::min(l,1000)+1;

auto pb = progress(range(10));
while (!CSignal::cancel_computations())
{
if (Q->max_train_time > 0 && start_time.cur_time_diff() > Q->max_train_time)
Expand Down Expand Up @@ -496,7 +496,7 @@ void Solver::Solve(
counter = 1; // do shrinking next iteration
}

SG_SABS_PROGRESS(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(eps), 6)
pb.print_absolute(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(eps));

++iter;

Expand Down Expand Up @@ -674,6 +674,7 @@ void Solver::Solve(
}
#endif
}
pb.complete_absolute();

// calculate rho

Expand Down
1 change: 0 additions & 1 deletion src/shogun/lib/malsar/malsar_joint_feature_learning.cpp
Expand Up @@ -177,7 +177,6 @@ malsar_result_t malsar_joint_feature_learning(
//for (task=0; task<n_tasks; task++)
// obj += rho1*(Wz.col(task).norm());
SG_SDEBUG("Obj = %f\n",obj)
//SG_SABS_PROGRESS(obj,0.0)
// check if process should be terminated
switch (options.termination)
{
Expand Down
6 changes: 4 additions & 2 deletions src/shogun/optimization/liblinear/tron.cpp
Expand Up @@ -7,6 +7,7 @@
#include <shogun/lib/Signal.h>
#include <shogun/lib/Time.h>

#include <shogun/base/progress.h>
#include <shogun/mathematics/lapack.h>
#include <shogun/mathematics/Math.h>
#include <shogun/optimization/liblinear/tron.h>
Expand Down Expand Up @@ -105,6 +106,7 @@ void CTron::tron(float64_t *w, float64_t max_train_time)

CSignal::clear_cancel();
CTime start_time;
auto pb=progress(range(10));

while (iter <= max_iter && search && (!CSignal::cancel_computations()))
{
Expand Down Expand Up @@ -156,7 +158,7 @@ void CTron::tron(float64_t *w, float64_t max_train_time)
gnorm = tron_dnrm2(n, g, inc);
if (gnorm < eps*gnorm1)
break;
SG_SABS_PROGRESS(gnorm, -CMath::log10(gnorm), -CMath::log10(1), -CMath::log10(eps*gnorm1), 6)
pb.print_absolute(gnorm, -CMath::log10(gnorm), -CMath::log10(1), -CMath::log10(eps*gnorm1));
}
if (f < -1.0e+32)
{
Expand All @@ -176,7 +178,7 @@ void CTron::tron(float64_t *w, float64_t max_train_time)
}
}

SG_DONE()
pb.complete_absolute();

SG_FREE(g);
SG_FREE(r);
Expand Down
7 changes: 4 additions & 3 deletions src/shogun/regression/svr/LibLinearRegression.cpp
Expand Up @@ -15,6 +15,7 @@
#include <shogun/labels/RegressionLabels.h>
#include <shogun/optimization/liblinear/tron.h>
#include <shogun/lib/Signal.h>
#include <shogun/base/progress.h>

using namespace shogun;

Expand Down Expand Up @@ -206,7 +207,7 @@ void CLibLinearRegression::solve_l2r_l1l2_svr(SGVector<float64_t>& w, const libl
index[i] = i;
}


auto pb=progress(range(10));
while(iter < max_iter)
{
Gmax_new = 0;
Expand Down Expand Up @@ -305,7 +306,7 @@ void CLibLinearRegression::solve_l2r_l1l2_svr(SGVector<float64_t>& w, const libl
Gnorm1_init = Gnorm1_new;
iter++;

SG_SABS_PROGRESS(Gnorm1_new, -CMath::log10(Gnorm1_new), -CMath::log10(eps*Gnorm1_init), -CMath::log10(Gnorm1_init), 6)
pb.print_absolute(Gnorm1_new, -CMath::log10(Gnorm1_new), -CMath::log10(eps*Gnorm1_init), -CMath::log10(Gnorm1_init));

if(Gnorm1_new <= eps*Gnorm1_init)
{
Expand All @@ -322,7 +323,7 @@ void CLibLinearRegression::solve_l2r_l1l2_svr(SGVector<float64_t>& w, const libl
Gmax_old = Gmax_new;
}

SG_DONE()
pb.complete_absolute();
SG_INFO("\noptimization finished, #iter = %d\n", iter)
if(iter >= max_iter)
SG_INFO("\nWARNING: reaching max number of iterations\nUsing -s 11 may be faster\n\n")
Expand Down
6 changes: 4 additions & 2 deletions src/shogun/transfer/multitask/LibLinearMTL.cpp
Expand Up @@ -22,6 +22,7 @@
#include <shogun/transfer/multitask/LibLinearMTL.h>
#include <shogun/optimization/liblinear/tron.h>
#include <shogun/features/DotFeatures.h>
#include <shogun/base/progress.h>

using namespace shogun;

Expand Down Expand Up @@ -253,6 +254,7 @@ void CLibLinearMTL::solve_l2r_l1l2_svc(const liblinear_problem *prob, double eps
index[i] = i;
}

auto pb=progress(range(10));
CTime start_time;
while (iter < max_iterations && !CSignal::cancel_computations())
{
Expand Down Expand Up @@ -352,7 +354,7 @@ void CLibLinearMTL::solve_l2r_l1l2_svc(const liblinear_problem *prob, double eps

iter++;
float64_t gap=PGmax_new - PGmin_new;
SG_SABS_PROGRESS(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(eps), 6)
pb.print_absolute(gap, -CMath::log10(gap), -CMath::log10(1), -CMath::log10(eps));

if(gap <= eps)
{
Expand All @@ -374,7 +376,7 @@ void CLibLinearMTL::solve_l2r_l1l2_svc(const liblinear_problem *prob, double eps
PGmin_old = -CMath::INFTY;
}

SG_DONE()
pb.complete_absolute();
SG_INFO("optimization finished, #iter = %d\n",iter)
if (iter >= max_iterations)
{
Expand Down

0 comments on commit 0566192

Please sign in to comment.