SVM_libsvm.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2000-2009 Chih-Chung Chang and Chih-Jen Lin
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  * notice, this list of conditions and the following disclaimer.
00011  *
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  * notice, this list of conditions and the following disclaimer in the
00014  * documentation and/or other materials provided with the distribution.
00015  *
00016  * 3. Neither name of copyright holders nor the names of its contributors
00017  * may be used to endorse or promote products derived from this software
00018  * without specific prior written permission.
00019  *
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00024  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
00025  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00027  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00028  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00029  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00030  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  * Shogun specific adjustments (w) 2006-2009 Soeren Sonnenburg
00034  */
00035 
00036 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00037 
00038 #ifndef _LIBSVM_H
00039 #define _LIBSVM_H
00040 
00041 #include <shogun/kernel/Kernel.h>
00042 
00043 namespace shogun
00044 {
00046 struct svm_node
00047 {
00049     int32_t index;
00050 };
00051 
00053 struct svm_problem
00054 {
00055 
00056 
00057 public:
00058 
00060     svm_problem() {
00061         y = NULL;
00062         x = NULL;
00063         C = NULL;
00064         pv = NULL;
00065     }
00066 
00067 
00069     int32_t l;
00071     float64_t *y;
00073     struct svm_node **x;
00075     float64_t *C;
00077     float64_t *pv;
00078 
00079 };
00080 
00081 enum { C_SVC=1, NU_SVC=2, NU_MULTICLASS_SVC=3, ONE_CLASS=4, EPSILON_SVR=5, NU_SVR=6 };  /* svm_type */
00082 enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
00083 
00085 struct svm_parameter
00086 {
00088     int32_t svm_type;
00090     int32_t kernel_type;
00092     shogun::CKernel* kernel;
00094     int32_t degree;
00096     float64_t gamma;
00098     float64_t coef0;
00099 
00100     /* these are for training only */
00102     float64_t cache_size;
00104     float64_t max_train_time;
00106     float64_t eps;
00108     float64_t C;
00110     int32_t nr_class;
00112     int32_t nr_weight;
00114     int32_t *weight_label;
00116     float64_t* weight;
00118     float64_t nu;
00120     float64_t p;
00122     int32_t shrinking;
00124     bool use_bias;
00125 };
00126 
00128 struct svm_model
00129 {
00131     svm_parameter param;
00133     int32_t nr_class;
00135     int32_t l;
00137     svm_node **SV;
00139     float64_t **sv_coef;
00141     float64_t *rho;
00143     float64_t *normwcw;
00144 
00145     // for classification only
00146 
00148     int32_t *label;
00152     int32_t *nSV;
00153     // XXX
00157     int32_t free_sv;
00159     float64_t objective;
00160 };
00161 
00162 
00163 
00164 struct svm_model *svm_train(
00165     const struct svm_problem *prob, const struct svm_parameter *param);
00166 
00167 float64_t svm_predict(const struct svm_model *model, const struct svm_node *x);
00168 
00169 void svm_destroy_model(struct svm_model *model);
00170 
00171 const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
00172 }
00173 #endif /* _LIBSVM_H */
00174 
00175 #endif // DOXYGEN_SHOULD_SKIP_THIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation