summaryrefslogtreecommitdiff
path: root/model/ranksvm.cpp
blob: 628ef375149e61d9deca69a596fdddb05fd65e40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include"ranksvm.h"
#include"ranksvmtn.h"
#include"../tools/matrixIO.h"
#include<iostream>
#include<fstream>
#include<string>

using namespace Eigen;
using namespace std;

int RSVM::saveModel(const string fname){

    std::ofstream fout(fname.c_str());
    fout<<this->getName()<<endl;
    fout<<this->fsize<<endl;
    Eigen::write_stream(fout, this->model);
    return 0;
}

RSVM* RSVM::loadModel(const string fname){
    std::ifstream fin(fname.c_str());
    std::string type;
    int fsize;
    fin>>type;
    fin>>fsize;

    RSVM* rsvm;

    if (type=="TN")
        rsvm = new RSVMTN();

    rsvm->fsize=fsize;
    VectorXd model;
    Eigen::read_stream(fin, model);
    rsvm->setModel(model);

    return rsvm;
}

int RSVM::setModel(const Labels &model) {
    if (model.rows()!=fsize)
        LOG(FATAL) << "Feature size mismatch: "<<fsize<<" "<<model.cols();
    this->model=model;
    return 0;
}