From f50bb1ee0d6011969fcfc7cb084bab0ce9c4dd39 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Sat, 7 Mar 2015 16:42:46 +0800 Subject: scaffolding, decided to abandon libsvm format & using matrices for easier input & output operation --- model/ranksvm.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- model/ranksvm.h | 19 +++++++++++-------- model/ranksvmtn.h | 20 ++++++++++++++++++++ 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 model/ranksvmtn.h (limited to 'model') diff --git a/model/ranksvm.cpp b/model/ranksvm.cpp index 38fb70c..b15d2ef 100644 --- a/model/ranksvm.cpp +++ b/model/ranksvm.cpp @@ -1 +1,43 @@ -#include"ranksvm.h" \ No newline at end of file +#include"ranksvm.h" +#include"ranksvmtron.h" +#include +#include +#include + +using namespace Eigen; + +int RSVM::saveModel(string fname){ + + std::ofstream fout(fname); + fout<getName()<model; + return 0; +} + +static RSVM* RSVM::loadModel(string fname){ + std::ifstream fin(fname); + std::string type; + int fsize; + fin>>type; + fin>>fsize; + + RSVM* rsvm; + + // TODO multiplex type + if (type=="TN") + RSVM = new RSVMTN(); + + rsvm->fsize=fsize; + VectorXd model; + fin>>model; + rsvm->setModel(model); + + return rsvm; +} + +int RSVM::setModel(Eigen::VectorXd model) { + if (model.cols()!=fsize) + LOG(FATAL) << "Feature size mismatch";; + this->model=model; + return 0; +} \ No newline at end of file diff --git a/model/ranksvm.h b/model/ranksvm.h index ba79c48..8993b87 100644 --- a/model/ranksvm.h +++ b/model/ranksvm.h @@ -4,19 +4,22 @@ #include #include #include"../tools/dataProvider.h" +#include "../tools/easylogging++.h" class RSVM //Virtual base class for all RSVM operations { protected: - Eigen::VectorXd* model; + Eigen::VectorXd model; + int fsize; public: - virtual int train(DataProvider &D)=0; - int test(); - int saveModel(string fname); - static RSVM loadModel(string fname); - string getName(); - Eigen::MatrixXd getModel(); - Eigen::MatrixXd setModel(); + virtual int train(DataProvider D)=0; + virtual int predict(DataProvider D); + int saveModel(std::string fname); + static RSVM loadModel(std::string fname); + virtual std::string getName()=0; + Eigen::MatrixXd getModel(){ + return model;}; + void setModel(Eigen::VectorXd model); }; #endif \ No newline at end of file diff --git a/model/ranksvmtn.h b/model/ranksvmtn.h new file mode 100644 index 0000000..2a8f524 --- /dev/null +++ b/model/ranksvmtn.h @@ -0,0 +1,20 @@ +#ifndef RSVMTN_H +#define RSVMTN_H + +// Truncated Newton method based RankSVM + +#include"ranksvm.h" + +class RSVMTN:public RSVM +{ +public: + std::string getName() + { + return "TN"; + }; + + int train(DataProvider D){return 0;}; + int predict(DataProvider D){return 0;}; +}; + +#endif \ No newline at end of file -- cgit v1.2.3-70-g09d2