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