|
FreeLing
3.0
|
00001 // 00002 // ======= This file is part of libsvm-3.0 ======== 00003 // 00004 // Copyright (c) 2000-2010 Chih-Chung Chang and Chih-Jen Lin 00005 // All rights reserved. 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions 00009 // are met: 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 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 // 3. Neither name of copyright holders nor the names of its contributors 00016 // may be used to endorse or promote products derived from this software 00017 // without specific prior written permission. 00018 // 00019 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 // ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 00023 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00024 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00025 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 #ifndef _LIBSVM_H 00032 #define _LIBSVM_H 00033 00034 #define LIBSVM_VERSION 300 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 extern int libsvm_version; 00041 00042 struct svm_node 00043 { 00044 int index; 00045 double value; 00046 }; 00047 00048 struct svm_problem 00049 { 00050 int l; 00051 double *y; 00052 struct svm_node **x; 00053 }; 00054 00055 enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */ 00056 enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */ 00057 00058 struct svm_parameter 00059 { 00060 int svm_type; 00061 int kernel_type; 00062 int degree; /* for poly */ 00063 double gamma; /* for poly/rbf/sigmoid */ 00064 double coef0; /* for poly/sigmoid */ 00065 00066 /* these are for training only */ 00067 double cache_size; /* in MB */ 00068 double eps; /* stopping criteria */ 00069 double C; /* for C_SVC, EPSILON_SVR and NU_SVR */ 00070 int nr_weight; /* for C_SVC */ 00071 int *weight_label; /* for C_SVC */ 00072 double* weight; /* for C_SVC */ 00073 double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */ 00074 double p; /* for EPSILON_SVR */ 00075 int shrinking; /* use the shrinking heuristics */ 00076 int probability; /* do probability estimates */ 00077 }; 00078 00079 // 00080 // svm_model 00081 // 00082 struct svm_model 00083 { 00084 struct svm_parameter param; /* parameter */ 00085 int nr_class; /* number of classes, = 2 in regression/one class svm */ 00086 int l; /* total #SV */ 00087 struct svm_node **SV; /* SVs (SV[l]) */ 00088 double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */ 00089 double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */ 00090 double *probA; /* pariwise probability information */ 00091 double *probB; 00092 00093 /* for classification only */ 00094 00095 int *label; /* label of each class (label[k]) */ 00096 int *nSV; /* number of SVs for each class (nSV[k]) */ 00097 /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */ 00098 /* XXX */ 00099 int free_sv; /* 1 if svm_model is created by svm_load_model*/ 00100 /* 0 if svm_model is created by svm_train */ 00101 }; 00102 00103 struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param); 00104 void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target); 00105 00106 int svm_save_model(const char *model_file_name, const struct svm_model *model); 00107 struct svm_model *svm_load_model(const char *model_file_name); 00108 00109 int svm_get_svm_type(const struct svm_model *model); 00110 int svm_get_nr_class(const struct svm_model *model); 00111 void svm_get_labels(const struct svm_model *model, int *label); 00112 double svm_get_svr_probability(const struct svm_model *model); 00113 00114 double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values); 00115 double svm_predict(const struct svm_model *model, const struct svm_node *x); 00116 double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates); 00117 00118 void svm_free_model_content(struct svm_model *model_ptr); 00119 void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr); 00120 void svm_destroy_param(struct svm_parameter *param); 00121 00122 const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param); 00123 int svm_check_probability_model(const struct svm_model *model); 00124 00125 void svm_set_print_string_function(void (*print_func)(const char *)); 00126 00127 // deprecated 00128 // this function will be removed in future release 00129 void svm_destroy_model(struct svm_model *model_ptr); 00130 00131 #ifdef __cplusplus 00132 } 00133 #endif 00134 00135 #endif /* _LIBSVM_H */
1.7.6.1