Xmipp  v3.23.11-Nereus
svm.h
Go to the documentation of this file.
1 /* This file has been taken from LibSVM 3.25 */
2 /* Authors: Chih-Chung Chang and Chih-Jen Lin, LIBSVM : */
3 /* Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm */
4 
5 #ifndef _LIBSVM_H
6 #define _LIBSVM_H
7 
8 #define LIBSVM_VERSION 325
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 extern int libsvm_version;
15 
16 struct svm_node
17 {
18  int index;
19  double value;
20 };
21 
23 {
24  int l;
25  double *y;
26  struct svm_node **x;
27 };
28 
29 namespace libsvm {
30  enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */
31  enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
32 }
33 
35 {
36  int svm_type;
38  int degree; /* for poly */
39  double gamma; /* for poly/rbf/sigmoid */
40  double coef0; /* for poly/sigmoid */
41 
42  /* these are for training only */
43  double cache_size; /* in MB */
44  double eps; /* stopping criteria */
45  double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
46  int nr_weight; /* for C_SVC */
47  int *weight_label; /* for C_SVC */
48  double* weight; /* for C_SVC */
49  double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
50  double p; /* for EPSILON_SVR */
51  int shrinking; /* use the shrinking heuristics */
52  int probability; /* do probability estimates */
53 };
54 
55 //
56 // svm_model
57 //
58 struct svm_model
59 {
60  struct svm_parameter param; /* parameter */
61  int nr_class; /* number of classes, = 2 in regression/one class svm */
62  int l; /* total #SV */
63  struct svm_node **SV; /* SVs (SV[l]) */
64  double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
65  double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
66  double *probA; /* pariwise probability information */
67  double *probB;
68  int *sv_indices; /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
69 
70  /* for classification only */
71 
72  int *label; /* label of each class (label[k]) */
73  int *nSV; /* number of SVs for each class (nSV[k]) */
74  /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
75  /* XXX */
76  int free_sv; /* 1 if svm_model is created by svm_load_model*/
77  /* 0 if svm_model is created by svm_train */
78 };
79 
80 struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);
81 void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);
82 
83 int svm_save_model(const char *model_file_name, const struct svm_model *model);
84 struct svm_model *svm_load_model(const char *model_file_name);
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 void svm_get_sv_indices(const struct svm_model *model, int *sv_indices);
90 int svm_get_nr_sv(const struct svm_model *model);
91 double svm_get_svr_probability(const struct svm_model *model);
92 
93 double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
94 double svm_predict(const struct svm_model *model, const struct svm_node *x);
95 double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
96 
97 void svm_free_model_content(struct svm_model *model_ptr);
98 void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
100 
101 const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
102 int svm_check_probability_model(const struct svm_model *model);
103 
104 void svm_set_print_string_function(void (*print_func)(const char *));
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* _LIBSVM_H */
int * nSV
Definition: svm.h:73
int svm_get_nr_sv(const struct svm_model *model)
int svm_check_probability_model(const struct svm_model *model)
int libsvm_version
Definition: svm.cpp:17
int svm_get_svm_type(const struct svm_model *model)
void svm_destroy_param(struct svm_parameter *param)
Definition: svm.cpp:3046
double value
Definition: svm.h:19
int l
Definition: svm.h:62
int nr_weight
Definition: svm.h:46
struct svm_node ** SV
Definition: svm.h:63
double * probB
Definition: svm.h:67
int * weight_label
Definition: svm.h:47
Definition: svm.h:29
const char * svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param)
struct svm_model * svm_load_model(const char *model_file_name)
Definition: svm.cpp:2893
void svm_set_print_string_function(void(*print_func)(const char *))
Definition: svm.cpp:3182
doublereal * x
double * probA
Definition: svm.h:66
int nr_class
Definition: svm.h:61
Definition: svm.h:58
double p
Definition: svm.h:50
void svm_free_model_content(struct svm_model *model_ptr)
Definition: svm.cpp:3001
double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double *prob_estimates)
double cache_size
Definition: svm.h:43
double eps
Definition: svm.h:44
int shrinking
Definition: svm.h:51
int svm_save_model(const char *model_file_name, const struct svm_model *model)
struct svm_node ** x
Definition: svm.h:26
int * label
Definition: svm.h:72
int svm_get_nr_class(const struct svm_model *model)
int * sv_indices
Definition: svm.h:68
double * rho
Definition: svm.h:65
int index
Definition: svm.h:18
struct _parameter * param
double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double *dec_values)
double svm_get_svr_probability(const struct svm_model *model)
double ** sv_coef
Definition: svm.h:64
void svm_get_sv_indices(const struct svm_model *model, int *sv_indices)
int probability
Definition: svm.h:52
int degree
Definition: svm.h:38
int free_sv
Definition: svm.h:76
struct svm_model * svm_train(const struct svm_problem *prob, const struct svm_parameter *param)
Definition: svm.h:16
double * y
Definition: svm.h:25
double svm_predict(const struct svm_model *model, const struct svm_node *x)
double gamma
Definition: svm.h:39
int l
Definition: svm.h:24
double * weight
Definition: svm.h:48
void svm_get_labels(const struct svm_model *model, int *label)
double C
Definition: svm.h:45
void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target)
int svm_type
Definition: svm.h:36
double nu
Definition: svm.h:49
double coef0
Definition: svm.h:40
int kernel_type
Definition: svm.h:37
void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr)
Definition: svm.cpp:3036