From 056619260ebce11867ed6385fba130c4037fbfec Mon Sep 17 00:00:00 2001 From: Giovanni De Toni Date: Mon, 5 Jun 2017 20:52:45 +0200 Subject: [PATCH] [ProgressBar] Replace all SG_SABS_PROGRESS with progress(). --- src/shogun/classifier/svm/LibLinear.cpp | 25 +++++++++++-------- src/shogun/lib/external/libocas.cpp | 9 ++++--- src/shogun/lib/external/shogun_libsvm.cpp | 5 ++-- .../malsar/malsar_joint_feature_learning.cpp | 1 - src/shogun/optimization/liblinear/tron.cpp | 6 +++-- .../regression/svr/LibLinearRegression.cpp | 7 +++--- .../transfer/multitask/LibLinearMTL.cpp | 6 +++-- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/shogun/classifier/svm/LibLinear.cpp b/src/shogun/classifier/svm/LibLinear.cpp index d81989f62d6..8ecd83d1136 100644 --- a/src/shogun/classifier/svm/LibLinear.cpp +++ b/src/shogun/classifier/svm/LibLinear.cpp @@ -18,6 +18,7 @@ #include #include #include +#include using namespace shogun; @@ -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()) { @@ -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) { @@ -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) { @@ -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()) { @@ -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) { @@ -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") @@ -893,6 +894,7 @@ void CLibLinear::solve_l1r_lr( } } + auto pb=progress(range(10)); CTime start_time; while (iter < max_iterations && !CSignal::cancel_computations()) { @@ -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) { @@ -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") @@ -1230,6 +1232,7 @@ void CLibLinear::solve_l2r_lr_dual(SGVector& w, const liblinear_probl index[i] = i; } + auto pb=progress(range(10)); while (iter < max_iter) { for (i=0; i& 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; @@ -1314,7 +1317,7 @@ void CLibLinear::solve_l2r_lr_dual(SGVector& 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") diff --git a/src/shogun/lib/external/libocas.cpp b/src/shogun/lib/external/libocas.cpp index e577fa157ce..22e3c36f075 100644 --- a/src/shogun/lib/external/libocas.cpp +++ b/src/shogun/lib/external/libocas.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace shogun { @@ -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; @@ -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; @@ -936,6 +938,7 @@ ocas_return_value_T svm_ocas_solver( } /* end of the main loop */ + pb.complete_absolute(); cleanup: LIBOCAS_FREE(H); @@ -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); diff --git a/src/shogun/lib/external/shogun_libsvm.cpp b/src/shogun/lib/external/shogun_libsvm.cpp index ed7e9e673b5..9b219038ea7 100644 --- a/src/shogun/lib/external/shogun_libsvm.cpp +++ b/src/shogun/lib/external/shogun_libsvm.cpp @@ -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) @@ -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; @@ -674,6 +674,7 @@ void Solver::Solve( } #endif } + pb.complete_absolute(); // calculate rho diff --git a/src/shogun/lib/malsar/malsar_joint_feature_learning.cpp b/src/shogun/lib/malsar/malsar_joint_feature_learning.cpp index 02bb4bfadbf..dfacec83278 100644 --- a/src/shogun/lib/malsar/malsar_joint_feature_learning.cpp +++ b/src/shogun/lib/malsar/malsar_joint_feature_learning.cpp @@ -177,7 +177,6 @@ malsar_result_t malsar_joint_feature_learning( //for (task=0; task #include +#include #include #include #include @@ -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())) { @@ -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) { @@ -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); diff --git a/src/shogun/regression/svr/LibLinearRegression.cpp b/src/shogun/regression/svr/LibLinearRegression.cpp index 74344281c40..01cc4eec088 100644 --- a/src/shogun/regression/svr/LibLinearRegression.cpp +++ b/src/shogun/regression/svr/LibLinearRegression.cpp @@ -15,6 +15,7 @@ #include #include #include +#include using namespace shogun; @@ -206,7 +207,7 @@ void CLibLinearRegression::solve_l2r_l1l2_svr(SGVector& w, const libl index[i] = i; } - + auto pb=progress(range(10)); while(iter < max_iter) { Gmax_new = 0; @@ -305,7 +306,7 @@ void CLibLinearRegression::solve_l2r_l1l2_svr(SGVector& 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) { @@ -322,7 +323,7 @@ void CLibLinearRegression::solve_l2r_l1l2_svr(SGVector& 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") diff --git a/src/shogun/transfer/multitask/LibLinearMTL.cpp b/src/shogun/transfer/multitask/LibLinearMTL.cpp index 4b79636e172..7f1d071e51f 100644 --- a/src/shogun/transfer/multitask/LibLinearMTL.cpp +++ b/src/shogun/transfer/multitask/LibLinearMTL.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using namespace shogun; @@ -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()) { @@ -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) { @@ -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) {