svm.h

00001 /*
00002 Copyright (c) 2000-2007 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 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 struct svm_node
00042 {
00043         int index;
00044         double value;
00045 };
00046 
00047 struct svm_problem
00048 {
00049         int l;
00050         double *y;
00051         struct svm_node **x;
00052 };
00053 
00054 enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR };        /* svm_type */
00055 enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
00056 
00057 struct svm_parameter
00058 {
00059         int svm_type;
00060         int kernel_type;
00061         int degree;        /* for poly */
00062         double gamma;        /* for poly/rbf/sigmoid */
00063         double coef0;        /* for poly/sigmoid */
00064 
00065         /* these are for training only */
00066         double cache_size; /* in MB */
00067         double eps;        /* stopping criteria */
00068         double C;        /* for C_SVC, EPSILON_SVR and NU_SVR */
00069         int nr_weight;                /* for C_SVC */
00070         int *weight_label;        /* for C_SVC */
00071         double* weight;                /* for C_SVC */
00072         double nu;        /* for NU_SVC, ONE_CLASS, and NU_SVR */
00073         double p;        /* for EPSILON_SVR */
00074         int shrinking;        /* use the shrinking heuristics */
00075         int probability; /* do probability estimates */
00076 };
00077 
00078 struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);
00079 void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);
00080 
00081 int svm_save_model(const char *model_file_name, const struct svm_model *model);
00082 struct svm_model *svm_load_model(const char *model_file_name);
00083 
00084 int svm_get_svm_type(const struct svm_model *model);
00085 int svm_get_nr_class(const struct svm_model *model);
00086 void svm_get_labels(const struct svm_model *model, int *label);
00087 double svm_get_svr_probability(const struct svm_model *model);
00088 
00089 void svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
00090 double svm_predict(const struct svm_model *model, const struct svm_node *x);
00091 double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
00092 
00093 void svm_destroy_model(struct svm_model *model);
00094 void svm_destroy_param(struct svm_parameter *param);
00095 
00096 const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
00097 int svm_check_probability_model(const struct svm_model *model);
00098 
00099 #ifdef __cplusplus
00100 }
00101 #endif
00102 
00103 #endif /* _LIBSVM_H */
Generated on Sun May 8 08:05:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3