From b15766bef024f086c51e56aa9af17783d3c1ff68 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Wed, 20 May 2015 16:59:50 +0800 Subject: speedup, internalize libop --- CMakeLists.txt | 2 +- model/ranksvm.cpp | 2 +- model/ranksvmtn.cpp | 19 +++++++++----- tools/dataProvider.h | 73 ++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 70 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c579851..4ae8e51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES ( "/usr/include/eigen3" ) # Use Random Library for Random Number Generation -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp") FIND_PACKAGE( Boost COMPONENTS program_options REQUIRED ) INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR}) diff --git a/model/ranksvm.cpp b/model/ranksvm.cpp index a468729..acc2f4e 100644 --- a/model/ranksvm.cpp +++ b/model/ranksvm.cpp @@ -15,7 +15,7 @@ int maxiter = 1; // max iteration count double prec=1e-10; // precision // conjugate gradient double cg_prec=1e-3; // precision -int cg_maxiter = 500; +int cg_maxiter = 1000; int ls_maxiter = 20; // line search double line_prec=1e-10; // precision diff --git a/model/ranksvmtn.cpp b/model/ranksvmtn.cpp index 7f292f5..ba2d5a3 100644 --- a/model/ranksvmtn.cpp +++ b/model/ranksvmtn.cpp @@ -9,23 +9,26 @@ using namespace Eigen; void cal_Dw(RidList &D,const VectorXd &w, VectorXd &Dw) { int n = D.getSize(); - #pragma omp parallel for + // static chunk size of 1 to interleave the iterations + #pragma omp parallel for schedule(static,1) for (int i=0;i &rank,const VectorXd &corr,const VectorX else g+=Ds[rank[i+j]]; } - VectorXd tmp = alpha.cwiseProduct(Ds)-gamma; - VectorXd res = VectorXd::Zero(D.getSize()); + VectorXd tmp(n); + for (int i=0;i #include "../tools/easylogging++.h" #include +#include // TODO decide how to construct training data // One possible way for training data: @@ -93,8 +94,8 @@ public: } inline std::string getQid(int x) { - int a,b,n=getqSize(); - a=x/n; + int a,b,q=getqSize(); + a=x/q; return getU(a)->qid; } inline int getqSize() @@ -112,25 +113,63 @@ public: return getuSize()*getqSize(); } inline Eigen::VectorXd getVec(int x){ - int a,b,n=getqSize(); - a=x/n; - b=x%n; - Eigen::VectorXd vec; + int a,b,q=getqSize(); + a=x/q; + b=x%q; + Eigen::VectorXd *id,*oth; + id = &(uniq[a]->feature); if (single) - return (uniq[a]->feature-other[b]->feature).cwiseAbs(); - if (bfeature-uniq[b]->feature; + oth = &(other[b]->feature); + else if (bfeature); + else if (bfeature); else - if (bfeature-uniq[b+1]->feature; - else - vec=uniq[a]->feature-other[b-uniq.size()+1]->feature; - return vec.cwiseAbs(); + oth = &(other[b-uniq.size()+1]->feature); + return (*id-*oth).cwiseAbs(); }; + inline double getVecDot(int x,const Eigen::VectorXd &w) + { + int a,b,q=getqSize(); + a=x/q; + b=x%q; + double res = 0; + Eigen::VectorXd *id,*oth; + id = &(uniq[a]->feature); + if (single) + oth = &(other[b]->feature); + else if (bfeature); + else if (bfeature); + else + oth = &(other[b-uniq.size()+1]->feature); + for (int i=0;ifeature); + if (single) + oth = &(other[b]->feature); + else if (bfeature); + else if (bfeature); + else + oth = &(other[b-uniq.size()+1]->feature); + for (int i=0;irank - a) < 1e-5) -- cgit v1.2.3-70-g09d2