GestureRecognitionToolkit  Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
libsvm.h
Go to the documentation of this file.
1 
47 #ifndef GRT_LIB_SVM_HEADER
48 #define GRT_LIB_SVM_HEADER
49 
50 //Define the following to stop issues with visual studio
51 
52 // Must be defined before following inclusions
53 // May be already defined : check with ifndef
54 #ifndef _CRT_SECURE_NO_WARNINGS
55 #define _CRT_SECURE_NO_WARNINGS
56 #endif
57 #ifndef _CRT_NONSTDC_NO_DEPRECATE
58 #define _CRT_NONSTDC_NO_DEPRECATE
59 #endif
60 
61 #include <math.h>
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <ctype.h>
65 #include <float.h>
66 #include <string.h>
67 #include <stdarg.h>
68 #include <limits.h>
69 #include <locale.h>
70 #include <iostream>
71 #include <algorithm>
72 
73 namespace LIBSVM {
74 
75 #define LIBSVM_VERSION 312
76 
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 
81 extern int libsvm_version;
82 
83 struct svm_node
84 {
85  int index;
86  double value;
87 };
88 
90 {
91  svm_problem(){
92  y = NULL;
93  x = NULL;
94  }
95 
96  int l;
97  double *y;
98  struct svm_node **x;
99 };
100 
101 enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */
102 enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
103 
105 {
106  svm_parameter(){
107  weight_label = NULL;
108  weight = NULL;
109  }
110  int svm_type;
111  int kernel_type;
112  int degree; /* for poly */
113  double gamma; /* for poly/rbf/sigmoid */
114  double coef0; /* for poly/sigmoid */
115 
116  /* these are for training only */
117  double cache_size; /* in MB */
118  double eps; /* stopping criteria */
119  double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
120  int nr_weight; /* for C_SVC */
121  int *weight_label; /* for C_SVC */
122  double* weight; /* for C_SVC */
123  double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
124  double p; /* for EPSILON_SVR */
125  int shrinking; /* use the shrinking heuristics */
126  int probability; /* do probability estimates */
127 };
128 
129 //
130 // svm_model
131 //
132 struct svm_model
133 {
134  struct svm_parameter param; /* parameter */
135  int nr_class; /* number of classes, = 2 in regression/one class svm */
136  int l; /* total #SV */
137  struct svm_node **SV; /* SVs (SV[l]) */
138  double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
139  double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
140  double *probA; /* pariwise probability information */
141  double *probB;
142 
143  /* for classification only */
144 
145  int *label; /* label of each class (label[k]) */
146  int *nSV; /* number of SVs for each class (nSV[k]) */
147  /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
148  /* XXX */
149  int free_sv; /* 1 if svm_model is created by svm_load_model*/
150  /* 0 if svm_model is created by svm_train */
151 };
152 
153 struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);
154 void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);
155 
156 int svm_save_model(const char *model_file_name, const struct svm_model *model);
157 struct svm_model *svm_load_model(const char *model_file_name);
158 
159 int svm_get_svm_type(const struct svm_model *model);
160 int svm_get_nr_class(const struct svm_model *model);
161 void svm_get_labels(const struct svm_model *model, int *label);
162 double svm_get_svr_probability(const struct svm_model *model);
163 
164 double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
165 double svm_predict(const struct svm_model *model, const struct svm_node *x);
166 double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
167 
168 void svm_free_model_content(struct svm_model *model_ptr);
169 void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
170 void svm_destroy_param(struct svm_parameter *param);
171 
172 const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
173 int svm_check_probability_model(const struct svm_model *model);
174 
175 void svm_set_print_string_function(void (*print_func)(const char *));
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 } //End of namespace LIBSVM
182 
183 #endif //GRT_LIB_SVM_HEADER
Definition: libsvm.cpp:4