#include "ranksvmtn.h" #include #include"../tools/matrixIO.h" using namespace std; using namespace Eigen; const int maxiter = 10; const double prec=1e-3; int cg_solve(const MatrixXd &A, const VectorXd &b, VectorXd &x) { double alpha,beta,r_1,r_2; int step=0; VectorXd q; VectorXd res = b - A*x; // TODO Hessian product VectorXd p = res; while (1) { // Non preconditioned version r_1 = res.dot(res); cout<0) sv(i,i)=1; else sv(i,i)=0; return 0; } // line search using newton method int line_search(const VectorXd &w,const MatrixXd &D,const MatrixXd &A,const VectorXd &step,VectorXd &pred,double &t) { double wd=w.dot(step),dd=step.dot(step); double g,h; t = 0; VectorXd Xd=A*(D*step); while (1) { pred = pred - t*Xd; g=wd+t*dd; h=dd; for (int i=0;i0) { g += pred(i)*Xd(i); h += Xd(i)*Xd(i); } if (g*g/h<1e-10) break; } return 0; } int RSVMTN::train(DataSet &D, Labels &label){ int iter = 0; double C=1; MatrixXd A; // TODO Undefined long n=D.rows(); LOG(INFO) << "training with feature size:" << fsize << " Data size:" << n; MatrixXd sv=MatrixXd::Identity(n, n); VectorXd grad(fsize); VectorXd step(fsize); VectorXd pred(n); double obj,t; pred=VectorXd::Ones(n) - (A*(D*model.weight)); while (true) { iter+=1; if (iter> maxiter) { LOG(INFO)<< "Maxiter :"<0) H = H + 2*C*A.row(i).transpose()*A.row(i); // Solve cg_solve(H,grad,step); // do line search line_search(model.weight,D,A,step,pred,t); model.weight=model.weight+step*t; // When dec is small enough if (-step.dot(grad) < prec * obj) break; } return 0; }; int RSVMTN::predict(DataSet &D, Labels &res){ //TODO define A MatrixXd A; res = A*(D * model.weight); return 0; };