svm.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2014 Chih-Chung Chang and Chih-Jen Lin
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither name of copyright holders nor the names of its contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
25  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _LIBSVM_H
35 #define _LIBSVM_H
36 
37 #include <cstdlib>
38 
39 #define LIBSVM_VERSION 314
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45  extern int libsvm_version;
46 
47  struct svm_node
48  {
49  int index;
50  double value;
51  };
52 
53  struct svm_problem
54  {
55  int l;
56  double *y;
57  struct svm_node **x;
58  double *W; /* instance weight */
59  };
60 
61  enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */
62  enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
63 
65  {
66  int svm_type;
68  int degree; /* for poly */
69  double gamma; /* for poly/rbf/sigmoid */
70  double coef0; /* for poly/sigmoid */
71 
72  /* these are for training only */
73  double cache_size; /* in MB */
74  double eps; /* stopping criteria */
75  double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
76  int nr_weight; /* for C_SVC */
77  int *weight_label; /* for C_SVC */
78  double* weight; /* for C_SVC */
79  double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
80  double p; /* for EPSILON_SVR */
81  int shrinking; /* use the shrinking heuristics */
82  int probability; /* do probability estimates */
83  };
84 
85  //
86  // svm_model
87  //
88  struct svm_model
89  {
90  struct svm_parameter param; /* parameter */
91  int nr_class; /* number of classes, = 2 in regression/one class svm */
92  int l; /* total #SV */
93  struct svm_node **SV; /* SVs (SV[l]) */
94  double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
95  double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
96  double *probA; /* pairwise probability information */
97  double *probB;
98  int *sv_indices; /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
99 
100 
101  /* for classification only */
102 
103  int *label; /* label of each class (label[k]) */
104  int *nSV; /* number of SVs for each class (nSV[k]) */
105  /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
106  /* XXX */
107  int free_sv; /* 1 if svm_model is created by svm_load_model*/
108  /* 0 if svm_model is created by svm_train */
109  };
110 
111  struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);
112  void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);
113 
114  int svm_save_model(const char *model_file_name, const struct svm_model *model);
115  struct svm_model *svm_load_model(const char *model_file_name);
116 
117  int svm_get_svm_type(const struct svm_model *model);
118  int svm_get_nr_class(const struct svm_model *model);
119  void svm_get_labels(const struct svm_model *model, int *label);
120  void svm_get_sv_indices(const struct svm_model *model, int *sv_indices);
121  int svm_get_nr_sv(const struct svm_model *model);
122  double svm_get_svr_probability(const struct svm_model *model);
123 
124  double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
125  double svm_predict(const struct svm_model *model, const struct svm_node *x);
126  double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
127 
128  double svm_predict_values_twoclass(const struct svm_model* model, const struct svm_node* x);
129  double svm_hyper_w_normsqr_twoclass(const struct svm_model* model);
130 
131 
132  double k_function(const svm_node* x, const svm_node* y, const svm_parameter& param);
133 
134 
135  void svm_free_model_content(struct svm_model *model_ptr);
136  void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
137  void svm_destroy_param(struct svm_parameter *param);
138 
139  const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
140  int svm_check_probability_model(const struct svm_model *model);
141 
142  void svm_set_print_string_function(void (*print_func)(const char *));
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* _LIBSVM_H */
svm_check_parameter
const char * svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param)
k_function
double k_function(const svm_node *x, const svm_node *y, const svm_parameter &param)
Definition: svm.cpp:289
svm_problem::y
double * y
Definition: svm.h:56
svm_model::rho
double * rho
Definition: svm.h:95
svm_get_labels
void svm_get_labels(const struct svm_model *model, int *label)
svm_check_probability_model
int svm_check_probability_model(const struct svm_model *model)
svm_model::nSV
int * nSV
Definition: svm.h:104
svm_parameter::weight_label
int * weight_label
Definition: svm.h:77
svm_parameter::kernel_type
int kernel_type
Definition: svm.h:67
libsvm_version
int libsvm_version
Definition: svm.cpp:45
svm_parameter::eps
double eps
Definition: svm.h:74
svm_model::sv_indices
int * sv_indices
Definition: svm.h:98
svm_predict_values
double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double *dec_values)
svm_model::l
int l
Definition: svm.h:92
RBF
@ RBF
Definition: svm.h:62
svm_node::index
int index
Definition: svm.h:49
svm_problem::l
int l
Definition: svm.h:55
svm_parameter::C
double C
Definition: svm.h:75
svm_model::probA
double * probA
Definition: svm.h:96
NU_SVC
@ NU_SVC
Definition: svm.h:61
svm_get_sv_indices
void svm_get_sv_indices(const struct svm_model *model, int *sv_indices)
svm_node
Definition: svm.h:47
EPSILON_SVR
@ EPSILON_SVR
Definition: svm.h:61
svm_parameter::cache_size
double cache_size
Definition: svm.h:73
PRECOMPUTED
@ PRECOMPUTED
Definition: svm.h:62
svm_model::label
int * label
Definition: svm.h:103
label
string label
Definition: test_half_space_convex.cpp:143
svm_model::SV
struct svm_node ** SV
Definition: svm.h:93
svm_parameter::coef0
double coef0
Definition: svm.h:70
svm_problem
Definition: svm.h:53
SIGMOID
@ SIGMOID
Definition: svm.h:62
svm_predict
double svm_predict(const struct svm_model *model, const struct svm_node *x)
POLY
@ POLY
Definition: svm.h:62
svm_model::sv_coef
double ** sv_coef
Definition: svm.h:94
svm_parameter::probability
int probability
Definition: svm.h:82
svm_parameter
Definition: svm.h:64
svm_model::nr_class
int nr_class
Definition: svm.h:91
svm_parameter::gamma
double gamma
Definition: svm.h:69
svm_cross_validation
void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target)
svm_parameter::nr_weight
int nr_weight
Definition: svm.h:76
svm_model::param
struct svm_parameter param
Definition: svm.h:90
svm_parameter::nu
double nu
Definition: svm.h:79
svm_predict_values_twoclass
double svm_predict_values_twoclass(const struct svm_model *model, const struct svm_node *x)
Definition: svm.cpp:2643
svm_get_svm_type
int svm_get_svm_type(const struct svm_model *model)
svm_get_nr_sv
int svm_get_nr_sv(const struct svm_model *model)
svm_save_model
int svm_save_model(const char *model_file_name, const struct svm_model *model)
svm_parameter::degree
int degree
Definition: svm.h:68
LINEAR
@ LINEAR
Definition: svm.h:62
NU_SVR
@ NU_SVR
Definition: svm.h:61
svm_problem::W
double * W
Definition: svm.h:58
svm_problem::x
struct svm_node ** x
Definition: svm.h:57
C_SVC
@ C_SVC
Definition: svm.h:61
svm_set_print_string_function
void svm_set_print_string_function(void(*print_func)(const char *))
Definition: svm.cpp:3315
svm_parameter::svm_type
int svm_type
Definition: svm.h:66
svm_node::value
double value
Definition: svm.h:50
svm_parameter::weight
double * weight
Definition: svm.h:78
ONE_CLASS
@ ONE_CLASS
Definition: svm.h:61
svm_parameter::p
double p
Definition: svm.h:80
svm_model::free_sv
int free_sv
Definition: svm.h:107
svm_load_model
struct svm_model * svm_load_model(const char *model_file_name)
Definition: svm.cpp:2923
svm_train
struct svm_model * svm_train(const struct svm_problem *prob, const struct svm_parameter *param)
svm_model
Definition: svm.h:88
svm_parameter::shrinking
int shrinking
Definition: svm.h:81
svm_destroy_param
void svm_destroy_param(struct svm_parameter *param)
Definition: svm.cpp:3180
svm_predict_probability
double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double *prob_estimates)
svm_free_model_content
void svm_free_model_content(struct svm_model *model_ptr)
Definition: svm.cpp:3138
svm_hyper_w_normsqr_twoclass
double svm_hyper_w_normsqr_twoclass(const struct svm_model *model)
Definition: svm.cpp:2622
svm_free_and_destroy_model
void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr)
Definition: svm.cpp:3170
svm_model::probB
double * probB
Definition: svm.h:97
svm_get_nr_class
int svm_get_nr_class(const struct svm_model *model)
svm_get_svr_probability
double svm_get_svr_probability(const struct svm_model *model)


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:49