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