-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsvm.h
56 lines (47 loc) · 1.96 KB
/
svm.h
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
49
50
51
52
53
54
55
56
#ifndef VA_SVM_H_
#define VA_SVM_H_
#include "utilities.h"
enum { C_SVC, NU_SVC }; // svm_type
enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; // kernel_type
struct SVMParameter {
int svm_type;
int kernel_type;
int degree; // for poly
double gamma; // for poly/rbf/sigmoid
double coef0; // for poly/sigmoid
double cache_size; // in MB
double eps; // stopping criteria
double C; // for C_SVC
int num_weights; // for C_SVC
int *weight_labels; // for C_SVC
double *weights; // for C_SVC
double nu; // for NU_SVC
int shrinking; // use the shrinking heuristics
};
struct SVMModel {
struct SVMParameter param;
int num_ex;
int num_classes; // number of classes (k)
int total_sv; // total #SV
struct Node **svs; // SVs (SV[total_sv])
double **sv_coef; // coefficients for SVs in decision functions (sv_coef[k-1][total_sv])
double *rho; // constants in decision functions (rho[k*(k-1)/2])
int *sv_indices; // sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set
int *labels; // label of each class (label[k])
int *num_svs; // number of SVs for each class (nSV[k])
// nSV[0] + nSV[1] + ... + nSV[k-1] = total_sv
int free_sv; // 1 if SVMModel is created by LoadSVMModel
// 0 if SVMModel is created by TrainSVM
};
SVMModel *TrainSVM(const struct Problem *prob, const struct SVMParameter *param);
double PredictSVMValues(const struct SVMModel *model, const struct Node *x, double *decision_values);
double PredictSVM(const struct SVMModel *model, const struct Node *x);
int SaveSVMModel(std::ofstream &model_file, const struct SVMModel *model);
SVMModel *LoadSVMModel(std::ifstream &model_file);
void FreeSVMModel(struct SVMModel **model);
void FreeSVMParam(struct SVMParameter *param);
void InitSVMParam(struct SVMParameter *param);
const char *CheckSVMParameter(const struct SVMParameter *param);
void SetPrintNull();
void SetPrintCout();
#endif // VA_SVM_H_