blob: dc2ad9f8b3c14cebd3eb087e5dba8e21344ccea8 (
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
46
47
48
|
#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.weight);
fout<<this->model.beta<<endl;
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;
SVMModel model;
Eigen::read_stream(fin, model.weight);
fin>>model.beta;
rsvm->setModel(model);
return rsvm;
}
int RSVM::setModel(const SVMModel &model) {
if (model.weight.cols()!=fsize)
LOG(FATAL) << "Feature size mismatch: "<<fsize<<" "<<model.weight.cols();
this->model.weight=model.weight;
this->model.beta=model.beta;
return 0;
}
|