Debian Codegraph @

src/algorithms/svm.h

raw symbols SCIP
1 #ifndef _LIBSVM_H
2 #define _LIBSVM_H
3
4 #define LIBSVM_VERSION 312
5
6 #include <vector>//pk 2/10/2017
7 #include <string>//pk 2/10/2017
8 #include <map>//pk 2/10/2017
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 extern int libsvm_version;
14
15 struct svm_node
16 {
17 int index;
18 double value;
19 };
20
21 struct svm_problem
22 {
23 int l;
24 double *y;
25 struct svm_node **x;
26 };
27
28 enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */
29 enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
30
31 struct svm_parameter
32 {
33 int svm_type;
34 int kernel_type;
35 int degree; /* for poly */
36 double gamma; /* for poly/rbf/sigmoid */
37 double coef0; /* for poly/sigmoid */
38
39 /* these are for training only */
40 double cache_size; /* in MB */
41 double eps; /* stopping criteria */
42 double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
43 int nr_weight; /* for C_SVC */
44 int *weight_label; /* for C_SVC */
45 double* weight; /* for C_SVC */
46 double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
47 double p; /* for EPSILON_SVR */
48 int shrinking; /* use the shrinking heuristics */
49 int probability; /* do probability estimates */
50 bool verbose;//pk
51 };
52
53 //
54 // svm_model
55 //
56 struct svm_model
57 {
58 struct svm_parameter param; /* parameter */
59 int nr_class; /* number of classes, = 2 in regression/one class svm */
60 int l; /* total #SV */
61 struct svm_node **SV; /* SVs (SV[l]) */
62 double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
63 double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
64 double *probA; /* pariwise probability information */
65 double *probB;
66
67 /* for classification only */
68
69 int *label; /* label of each class (label[k]) */
70 int *nSV; /* number of SVs for each class (nSV[k]) */
71 /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
72 /* XXX */
73 int free_sv; /* 1 if svm_model is created by svm_load_model*/
74 /* 0 if svm_model is created by svm_train */
75 };
76
77 struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);
78 void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);
79
80 int svm_save_model(const std::string &model_file_name, const struct svm_model *model, const std::vector<double> &offset, const std::vector<double> &scale, const std::map<std::string,short> &classValueMap, const std::vector<std::string> &nameVector, const std::vector<std::string> &bandNames=std::vector<std::string>());//pk 11/04/2018
81 int svm_serialize_model(std::ostream &outputStream, const struct svm_model *model, const std::vector<double> &offset, const std::vector<double> &scale, const std::map<std::string,short> &classValueMap, const std::vector<std::string> &nameVector, const std::vector<std::string> &bandNames);//pk 11/04/2018
82 //int svm_save_model(const std::string model_file_name, const struct svm_model *model);
83 int svm_save_model_old(const char *model_file_name, const struct svm_model *model);
84 struct svm_model *svm_load_model(const std::string &model_file_name, std::vector<double> &offset, std::vector<double> &scale, std::map<std::string,short> &classValueMap, std::vector<std::string> &nameVector, std::vector<std::string> &bandNames);//pk 2/10/2017
85
86 int svm_get_svm_type(const struct svm_model *model);
87 int svm_get_nr_class(const struct svm_model *model);
88 void svm_get_labels(const struct svm_model *model, int *label);
89 double svm_get_svr_probability(const struct svm_model *model);
90
91 double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
92 double svm_predict(const struct svm_model *model, const struct svm_node *x);
93 double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
94
95 void svm_free_model_content(struct svm_model *model_ptr);
96 void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
97 void svm_destroy_param(struct svm_parameter *param);
98
99 const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
100 int svm_check_probability_model(const struct svm_model *model);
101
102 void svm_set_print_string_function(void (*print_func)(const char *));
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif /* _LIBSVM_H */