svm.h

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2000-2014 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 */
00034 #ifndef _LIBSVM_H
00035 #define _LIBSVM_H
00036 
00037 #define LIBSVM_VERSION 320
00038 
00039 namespace celeste
00040 {
00041 
00042 extern int libsvm_version;
00043 
00044 struct svm_node
00045 {
00046         int index;
00047         double value;
00048 };
00049 
00050 struct svm_problem
00051 {
00052         int l;
00053         double *y;
00054         struct svm_node **x;
00055 };
00056 
00057 enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */
00058 enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
00059 
00060 struct svm_parameter
00061 {
00062         int svm_type;
00063         int kernel_type;
00064         int degree;     /* for poly */
00065         double gamma;   /* for poly/rbf/sigmoid */
00066         double coef0;   /* for poly/sigmoid */
00067 
00068         /* these are for training only */
00069         double cache_size; /* in MB */
00070         double eps;     /* stopping criteria */
00071         double C;       /* for C_SVC, EPSILON_SVR and NU_SVR */
00072         int nr_weight;          /* for C_SVC */
00073         int *weight_label;      /* for C_SVC */
00074         double* weight;         /* for C_SVC */
00075         double nu;      /* for NU_SVC, ONE_CLASS, and NU_SVR */
00076         double p;       /* for EPSILON_SVR */
00077         int shrinking;  /* use the shrinking heuristics */
00078         int probability; /* do probability estimates */
00079 };
00080 
00081 //
00082 // svm_model
00083 // 
00084 struct svm_model
00085 {
00086         struct svm_parameter param;     /* parameter */
00087         int nr_class;           /* number of classes, = 2 in regression/one class svm */
00088         int l;                  /* total #SV */
00089         struct svm_node **SV;           /* SVs (SV[l]) */
00090         double **sv_coef;       /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
00091         double *rho;            /* constants in decision functions (rho[k*(k-1)/2]) */
00092         double *probA;          /* pariwise probability information */
00093         double *probB;
00094         int *sv_indices;        /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
00095 
00096         /* for classification only */
00097 
00098         int *label;             /* label of each class (label[k]) */
00099         int *nSV;               /* number of SVs for each class (nSV[k]) */
00100                                 /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
00101         /* XXX */
00102         int free_sv;            /* 1 if svm_model is created by svm_load_model*/
00103                                 /* 0 if svm_model is created by svm_train */
00104 };
00105 
00106 struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);
00107 void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);
00108 
00109 int svm_save_model(const char *model_file_name, const struct svm_model *model);
00110 struct svm_model *svm_load_model(const char *model_file_name);
00111 
00112 int svm_get_svm_type(const struct svm_model *model);
00113 int svm_get_nr_class(const struct svm_model *model);
00114 void svm_get_labels(const struct svm_model *model, int *label);
00115 void svm_get_sv_indices(const struct svm_model *model, int *sv_indices);
00116 int svm_get_nr_sv(const struct svm_model *model);
00117 double svm_get_svr_probability(const struct svm_model *model);
00118 
00119 double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
00120 double svm_predict(const struct svm_model *model, const struct svm_node *x);
00121 double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
00122 
00123 void svm_free_model_content(struct svm_model *model_ptr);
00124 void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
00125 void svm_destroy_param(struct svm_parameter *param);
00126 
00127 const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
00128 int svm_check_probability_model(const struct svm_model *model);
00129 
00130 void svm_set_print_string_function(void (*print_func)(const char *));
00131 
00132 };  //namespace
00133 #endif /* _LIBSVM_H */

Generated on 4 Aug 2015 for Hugintrunk by  doxygen 1.4.7