diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-05-18 16:17:01 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-05-18 16:17:01 +0800 |
commit | 653bee4b89131a997043a074d51c28dedb907f5c (patch) | |
tree | dd07194c85199aa1a3c38701bcc5d595f3d6f2b3 /model/ranksvmtn.cpp | |
parent | 20587ac550cfcb2d7b3d6ec16e46ba1a8d0af869 (diff) | |
download | ranksvm-mbk.tar.gz ranksvm-mbk.tar.bz2 ranksvm-mbk.zip |
output updatembk
Diffstat (limited to 'model/ranksvmtn.cpp')
-rw-r--r-- | model/ranksvmtn.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/model/ranksvmtn.cpp b/model/ranksvmtn.cpp index 01d9851..0e41861 100644 --- a/model/ranksvmtn.cpp +++ b/model/ranksvmtn.cpp @@ -6,13 +6,13 @@ using namespace std; using namespace Eigen; -const double C=1e-4; // Compensating & scaling // Main terminating criteria -const int maxiter = 20; // max iteration count +const int maxiter = 40; // max iteration count const double prec=1e-10; // precision // conjugate gradient const double cg_prec=1e-10; // precision -const int cg_maxiter = 30; +const int cg_maxiter = 5; // not worth having a large number +const int ls_maxiter = 10; // line search const double line_prec=1e-10; // precision const double line_turb=1e-15; // purturbation @@ -54,11 +54,13 @@ int cg_solve(const MatrixXd &D,const vector<int> &rank,const VectorXd &corr,cons { // Non preconditioned version r_1 = res.dot(res); + if (iter) + LOG(INFO) << "CG iter "<<iter<<", r:"<<r_1; if (r_1<cg_prec) // Terminate condition break; - if (iter > cg_maxiter) + if (iter >= cg_maxiter) { - LOG(INFO) << "CG forced termination by maxiter, r:"<<r_1; + LOG(INFO) << "CG forced termination by maxiter"; break; } if (iter){ @@ -162,10 +164,11 @@ int line_search(const VectorXd &w,const MatrixXd &D,const VectorXd &corr,const v g=g+line_turb; h = h+line_turb; t=t-g/h; + ++iter; + LOG(INFO) << "line search iter "<<iter<<", prec:"<<g*g/h; if (g*g/h<line_prec) break; - ++iter; - if (iter > cg_maxiter) + if (iter >= ls_maxiter) { LOG(INFO) << "line search forced termination by maxiter, prec:"<<g*g/h; break; @@ -189,7 +192,6 @@ int train_orig(int fsize, MatrixXd &D,const vector<int> &A1,const vector<int> &A VectorXd alpha,beta; while (true) { - iter+=1; if (iter> maxiter) { LOG(INFO)<< "Maxiter reached"; @@ -208,8 +210,15 @@ int train_orig(int fsize, MatrixXd &D,const vector<int> &A1,const vector<int> &A line_search(weight,D,corr,A1,A2,step,t); weight=weight+step*t; // When dec is small enough - LOG(INFO)<<"Iter: "<<iter<<" Obj: " <<obj << " Newton decr:"<<step.dot(grad)/2 << " linesearch: "<< -t ; - if (step.dot(grad) < prec * obj) + double nprec = step.dot(grad)/obj; + ++iter; + LOG(INFO)<<"Iter: "<<iter<<" Obj: " <<obj << " Ndec/Obj:"<<nprec << " linesearch: "<< -t ; + if (iter> maxiter) + { + LOG(INFO)<< "Maxiter reached"; + break; + } + if (nprec < prec) break; } return 0; |