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