diff options
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | model/rankaccu.cpp | 20 | ||||
-rw-r--r-- | model/ranksvmtn.cpp | 22 | ||||
-rw-r--r-- | tools/fileDataProvider.h | 3 |
4 files changed, 23 insertions, 24 deletions
@@ -50,8 +50,6 @@ int predict(DataProvider &dp) { LOG(INFO)<<"Prediction started"; ofstream fout; - if (vm.count("output")) - fout.open(vm["output"].as<string>().c_str()); ostream* ot; diff --git a/model/rankaccu.cpp b/model/rankaccu.cpp index 73b5d18..ba8aee6 100644 --- a/model/rankaccu.cpp +++ b/model/rankaccu.cpp @@ -75,20 +75,21 @@ void rank_accu(DataList &D,const vector<double> pred) unsigned long n = D.getSize(); vector<int> orig_rank(n),pred_rank(n),C(n); vector<double> orig(n); + vector<DataEntry*> &dat = D.getData(); int i,j; - for (i=0;i<D.getSize();++i) + for (i=0;i<dat.size();++i) { orig_rank[i]=i; pred_rank[i]=i; - orig[i]=D.getData()[i]->rank; + orig[i]=dat[i]->rank; } int cnt=0; double accu_nDCG=0; double accu_AP=0; i=j=0; - while (i<D.getSize()) + while (i<dat.size()) { - if ((i+1 == D.getSize())|| D.getData()[i]->qid!=D.getData()[i+1]->qid) + if ((i+1 == dat.size())|| dat[i]->qid!=dat[i+1]->qid) { double Y=0,Z=0; double AP=0; @@ -117,24 +118,25 @@ void rank_CMC(DataList &D,const std::vector<double> pred,CMC & cmc) { unsigned long n = D.getSize(); vector<int> orig_rank(n),pred_rank(n); vector<double> orig(n); + vector<DataEntry*> &dat = D.getData(); int i,j; - for (i=0;i<D.getSize();++i) + for (i=0;i<dat.size();++i) { orig_rank[i]=i; pred_rank[i]=i; - orig[i]=D.getData()[i]->rank; + orig[i]=dat[i]->rank; } int cnt=0; i=j=0; - while (i<D.getSize()) + while (i<dat.size()) { - if ((i+1 == D.getSize())|| D.getData()[i]->qid!=D.getData()[i+1]->qid) + if ((i+1 == dat.size())|| dat[i]->qid!=dat[i+1]->qid) { ranksort(j,i,pred_rank,pred,orig); for (int k=j;k<=i;++k) if (orig[pred_rank[k]]>0) { - cout<<pred_rank[k]<<" "<<pred[k+1]<<" "<< k <<" "<< j<<endl; + cout<<dat[pred_rank[k]]->qid<<" "<<pred[k]<<" "<< k-j<<endl; cmc.addEntry(k-j); break; // account only for the first match; } diff --git a/model/ranksvmtn.cpp b/model/ranksvmtn.cpp index c2ca639..01d9851 100644 --- a/model/ranksvmtn.cpp +++ b/model/ranksvmtn.cpp @@ -6,9 +6,9 @@ using namespace std; using namespace Eigen; -const double C=1e-5; // Compensating & scaling +const double C=1e-4; // Compensating & scaling // Main terminating criteria -const int maxiter = 10; // max iteration count +const int maxiter = 20; // max iteration count const double prec=1e-10; // precision // conjugate gradient const double cg_prec=1e-10; // precision @@ -44,7 +44,7 @@ int cal_Hs(const MatrixXd &D,const vector<int> &rank,const VectorXd &corr,const int cg_solve(const MatrixXd &D,const vector<int> &rank,const VectorXd &corr,const VectorXd &alph,const vector<int> &A1,const vector<int> &A2,const VectorXd &b, VectorXd &x) { double alpha,beta,r_1,r_2; - int step=0; + int iter=0; VectorXd q; VectorXd Hs; cal_Hs(D,rank,corr,alph,A1,A2,x,Hs); @@ -56,7 +56,12 @@ int cg_solve(const MatrixXd &D,const vector<int> &rank,const VectorXd &corr,cons r_1 = res.dot(res); if (r_1<cg_prec) // Terminate condition break; - if (step){ + if (iter > cg_maxiter) + { + LOG(INFO) << "CG forced termination by maxiter, r:"<<r_1; + break; + } + if (iter){ beta = r_1 / r_2; p = res + p * beta; } @@ -64,12 +69,7 @@ int cg_solve(const MatrixXd &D,const vector<int> &rank,const VectorXd &corr,cons alpha = r_1/p.dot(q); x=x+p*alpha; res=res-q*alpha; - ++step; - if (step > cg_maxiter) - { - LOG(INFO) << "CG force terminated by maxiter"; - break; - } + ++iter; r_2=r_1; } return 0; @@ -167,7 +167,7 @@ int line_search(const VectorXd &w,const MatrixXd &D,const VectorXd &corr,const v ++iter; if (iter > cg_maxiter) { - LOG(INFO) << "line search force terminated by maxiter"; + LOG(INFO) << "line search forced termination by maxiter, prec:"<<g*g/h; break; } } diff --git a/tools/fileDataProvider.h b/tools/fileDataProvider.h index 8ebda20..f54a38e 100644 --- a/tools/fileDataProvider.h +++ b/tools/fileDataProvider.h @@ -95,7 +95,6 @@ public: { e = new DataEntry; e->rank=1; - dat[i]->qid=std::to_string(qid); dat[i]->rank=qid; } else @@ -104,7 +103,7 @@ public: e->rank=-1; } e->feature.resize(d.getfSize()); - e->qid=std::to_string(qid); + e->qid=dat[pos]->qid; for (int j = 0; j < fsize; ++j) { e->feature(j) = fabs(dat[i]->feature(j) -dat[pos]->feature(j)); } |