ThunderSVM
ThunderSVM: An Open-Source SVM Library on GPUs and CPUs
svmmodel.h
1 //
2 // Created by jiashuai on 17-9-21.
3 //
4 
5 #ifndef THUNDERSVM_SVMMODEL_H
6 #define THUNDERSVM_SVMMODEL_H
7 
8 #include <thundersvm/dataset.h>
9 #include <thundersvm/svmparam.h>
10 #include <thundersvm/kernelmatrix.h>
11 #include <map>
12 
13 using std::map;
14 
18 class SvmModel {
19 public:
25  virtual void train(const DataSet &dataset, SvmParam param) = 0;
26 
33  virtual vector<float_type> predict(const DataSet::node2d &instances, int batch_size);
34 
41  void predict_dec_values(const DataSet::node2d &instances, SyncArray<float_type> &dec_values, int batch_size) const;
42 
53  virtual vector<float_type> cross_validation(DataSet dataset, SvmParam param, int n_fold);
54 
59  virtual void save_to_file(string path);
60 
67  virtual void load_from_file(string path);
68 
69 protected:
70 
76  virtual void model_setup(const DataSet &dataset, SvmParam &param);
77 
78  SvmParam param;
96  DataSet::node2d sv;
99 
102 
105 
107  int n_classes = 2;
108 
111 
113  vector<float_type> probA;
114 
116  vector<float_type> probB;
117 
119  vector<int> label;
120 };
121 
122 #endif //THUNDERSVM_SVMMODEL_H
vector< int > label
only for SVC, maps logical label (0,1,2,...) to real label in dataset (maybe 2,4,5,...)
Definition: svmmodel.h:119
virtual void model_setup(const DataSet &dataset, SvmParam &param)
Definition: svmmodel.cpp:20
virtual vector< float_type > predict(const DataSet::node2d &instances, int batch_size)
Definition: svmmodel.cpp:112
int n_total_sv
the number of support vectors for all classes
Definition: svmmodel.h:101
void predict_dec_values(const DataSet::node2d &instances, SyncArray< float_type > &dec_values, int batch_size) const
Definition: svmmodel.cpp:72
vector< float_type > probB
be used to predict probability for each binary model
Definition: svmmodel.h:116
DataSet::node2d sv
Definition: svmmodel.h:96
SyncArray< int > n_sv
the number of support vectors for each class
Definition: svmmodel.h:98
virtual void save_to_file(string path)
Definition: svmmodel.cpp:121
SyncArray< float_type > coef
Definition: svmmodel.h:89
size_t n_binary_models
the number of binary models, equal to , where is the number of classes
Definition: svmmodel.h:110
vector< float_type > probA
be used to predict probability for each binary model
Definition: svmmodel.h:113
Dataset reader.
Definition: dataset.h:14
virtual void load_from_file(string path)
Definition: svmmodel.cpp:187
virtual void train(const DataSet &dataset, SvmParam param)=0
params for ThunderSVM
Definition: svmparam.h:13
virtual vector< float_type > cross_validation(DataSet dataset, SvmParam param, int n_fold)
Definition: svmmodel.cpp:28
Abstract class for different SVM models.
Definition: svmmodel.h:18
SyncArray< float_type > rho
the bias term for each binary model
Definition: svmmodel.h:104
int n_classes
the number of classes
Definition: svmmodel.h:107