#include <math.h>#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <float.h>#include <string.h>#include <stdarg.h>#include "libsvm.h"
Go to the source code of this file.
Classes | |
| class | Cache |
| struct | Cache::head_t |
| class | QMatrix |
| class | Kernel |
| class | Solver |
| struct | Solver::SolutionInfo |
| class | Solver_NU |
| class | SVC_Q |
| class | ONE_CLASS_Q |
| class | SVR_Q |
| struct | decision_function |
Defines | |
| #define | INF HUGE_VAL |
| #define | TAU 1e-12 |
| #define | Malloc(type, n) (type *)malloc((n)*sizeof(type)) |
Typedefs | |
| typedef float | Qfloat |
| typedef signed char | schar |
Functions | |
| template<class T > | |
| static T | min (T x, T y) |
| template<class T > | |
| static T | max (T x, T y) |
| template<class T > | |
| static void | swap (T &x, T &y) |
| template<class S , class T > | |
| static void | clone (T *&dst, S *src, int n) |
| static double | powi (double base, int times) |
| static void | print_string_stdout (const char *s) |
| static void | info (const char *fmt,...) |
| static void | solve_c_svc (const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si, double Cp, double Cn) |
| static void | solve_nu_svc (const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si) |
| static void | solve_one_class (const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si) |
| static void | solve_epsilon_svr (const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si) |
| static void | solve_nu_svr (const svm_problem *prob, const svm_parameter *param, double *alpha, Solver::SolutionInfo *si) |
| static decision_function | svm_train_one (const svm_problem *prob, const svm_parameter *param, double Cp, double Cn) |
| static void | sigmoid_train (int l, const double *dec_values, const double *labels, double &A, double &B) |
| static double | sigmoid_predict (double decision_value, double A, double B) |
| static void | multiclass_probability (int k, double **r, double *p) |
| static void | svm_binary_svc_probability (const svm_problem *prob, const svm_parameter *param, double Cp, double Cn, double &probA, double &probB) |
| static double | svm_svr_probability (const svm_problem *prob, const svm_parameter *param) |
| static void | svm_group_classes (const svm_problem *prob, int *nr_class_ret, int **label_ret, int **start_ret, int **count_ret, int *perm) |
| svm_model * | svm_train (const svm_problem *prob, const svm_parameter *param) |
| void | svm_cross_validation (const svm_problem *prob, const svm_parameter *param, int nr_fold, double *target) |
| int | svm_get_svm_type (const svm_model *model) |
| int | svm_get_nr_class (const svm_model *model) |
| void | svm_get_labels (const svm_model *model, int *label) |
| double | svm_get_svr_probability (const svm_model *model) |
| double | svm_predict_values (const svm_model *model, const svm_node *x, double *dec_values) |
| double | svm_predict (const svm_model *model, const svm_node *x) |
| double | svm_predict_probability (const svm_model *model, const svm_node *x, double *prob_estimates) |
| int | svm_save_model (const char *model_file_name, const svm_model *model) |
| static char * | readline (FILE *input) |
| svm_model * | svm_load_model (const char *model_file_name) |
| void | svm_free_model_content (svm_model *model_ptr) |
| void | svm_free_and_destroy_model (svm_model **model_ptr_ptr) |
| void | svm_destroy_model (svm_model *model_ptr) |
| void | svm_destroy_param (svm_parameter *param) |
| const char * | svm_check_parameter (const svm_problem *prob, const svm_parameter *param) |
| int | svm_check_probability_model (const svm_model *model) |
| void | svm_set_print_string_function (void(*print_func)(const char *)) |
Variables | |
| int | libsvm_version = LIBSVM_VERSION |
| static void(* | svm_print_string )(const char *) = &print_string_stdout |
| static const char * | svm_type_table [] |
| static const char * | kernel_type_table [] |
| static char * | line = NULL |
| static int | max_line_len |
| #define INF HUGE_VAL |
Definition at line 37 of file libsvm.cpp.
Referenced by Solver_NU::calculate_rho(), Solver::calculate_rho(), Solver_NU::do_shrinking(), Solver::do_shrinking(), Solver_NU::select_working_set(), and Solver::select_working_set().
| #define Malloc | ( | type, | |
| n | |||
| ) | (type *)malloc((n)*sizeof(type)) |
Definition at line 39 of file libsvm.cpp.
Referenced by multiclass_probability(), sigmoid_train(), svm_binary_svc_probability(), svm_check_parameter(), svm_cross_validation(), svm_group_classes(), svm_load_model(), svm_predict(), svm_predict_probability(), svm_predict_values(), svm_svr_probability(), svm_train(), and svm_train_one().
| #define TAU 1e-12 |
Definition at line 38 of file libsvm.cpp.
Referenced by Solver_NU::select_working_set(), Solver::select_working_set(), and Solver::Solve().
| typedef float Qfloat |
Definition at line 12 of file libsvm.cpp.
| typedef signed char schar |
Definition at line 13 of file libsvm.cpp.
| static void clone | ( | T *& | dst, |
| S * | src, | ||
| int | n | ||
| ) | [inline, static] |
Definition at line 21 of file libsvm.cpp.
Referenced by Kernel::Kernel(), Solver::Solve(), and SVC_Q::SVC_Q().
| static void info | ( | const char * | fmt, |
| ... | |||
| ) | [static] |
Definition at line 48 of file libsvm.cpp.
Referenced by Solver::do_shrinking(), multiclass_probability(), Solver::reconstruct_gradient(), sigmoid_train(), Solver::Solve(), solve_c_svc(), solve_epsilon_svr(), solve_nu_svc(), solve_nu_svr(), svm_svr_probability(), svm_train(), and svm_train_one().
| static T max | ( | T | x, |
| T | y | ||
| ) | [inline, static] |
Definition at line 18 of file libsvm.cpp.
Referenced by Cache::Cache(), Solver_NU::calculate_rho(), Solver::calculate_rho(), cohortMaxLikelihood(), computeNAPChannelEffect(), Solver_NU::do_shrinking(), main(), multiclass_probability(), Solver_NU::select_working_set(), and svm_predict_probability().
| static T min | ( | T | x, |
| T | y | ||
| ) | [inline, static] |
Definition at line 15 of file libsvm.cpp.
Referenced by Solver_NU::calculate_rho(), Solver::calculate_rho(), main(), Solver::Solve(), solve_nu_svc(), solve_nu_svr(), svm_check_parameter(), and svm_predict_probability().
| static void multiclass_probability | ( | int | k, |
| double ** | r, | ||
| double * | p | ||
| ) | [static] |
Definition at line 1815 of file libsvm.cpp.
References eps, info(), Malloc, and max().
Referenced by svm_predict_probability().
| static double powi | ( | double | base, |
| int | times | ||
| ) | [inline, static] |
Definition at line 26 of file libsvm.cpp.
Referenced by Kernel::k_function(), and Kernel::kernel_poly().
| static void print_string_stdout | ( | const char * | s ) | [static] |
Definition at line 41 of file libsvm.cpp.
Referenced by svm_set_print_string_function().
| static char* readline | ( | FILE * | input ) | [static] |
Definition at line 2672 of file libsvm.cpp.
References line, and max_line_len.
Referenced by svm_load_model().
| static double sigmoid_predict | ( | double | decision_value, |
| double | A, | ||
| double | B | ||
| ) | [static] |
Definition at line 1805 of file libsvm.cpp.
Referenced by svm_predict_probability().
| static void sigmoid_train | ( | int | l, |
| const double * | dec_values, | ||
| const double * | labels, | ||
| double & | A, | ||
| double & | B | ||
| ) | [static] |
Definition at line 1692 of file libsvm.cpp.
References eps, info(), and Malloc.
Referenced by svm_binary_svc_probability().
| static void solve_c_svc | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| double * | alpha, | ||
| Solver::SolutionInfo * | si, | ||
| double | Cp, | ||
| double | Cn | ||
| ) | [static] |
Definition at line 1427 of file libsvm.cpp.
References svm_parameter::eps, info(), svm_problem::l, svm_parameter::shrinking, Solver::Solve(), and svm_problem::y.
Referenced by svm_train_one().
| static void solve_epsilon_svr | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| double * | alpha, | ||
| Solver::SolutionInfo * | si | ||
| ) | [static] |
Definition at line 1549 of file libsvm.cpp.
References svm_parameter::C, svm_parameter::eps, info(), svm_problem::l, svm_parameter::p, svm_parameter::shrinking, Solver::Solve(), and svm_problem::y.
Referenced by svm_train_one().
| static void solve_nu_svc | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| double * | alpha, | ||
| Solver::SolutionInfo * | si | ||
| ) | [static] |
Definition at line 1462 of file libsvm.cpp.
References svm_parameter::eps, info(), svm_problem::l, min(), svm_parameter::nu, Solver::SolutionInfo::obj, Solver::SolutionInfo::r, Solver::SolutionInfo::rho, svm_parameter::shrinking, Solver_NU::Solve(), Solver::SolutionInfo::upper_bound_n, Solver::SolutionInfo::upper_bound_p, and svm_problem::y.
Referenced by svm_train_one().
| static void solve_nu_svr | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| double * | alpha, | ||
| Solver::SolutionInfo * | si | ||
| ) | [static] |
Definition at line 1587 of file libsvm.cpp.
References svm_parameter::C, svm_parameter::eps, info(), svm_problem::l, min(), svm_parameter::nu, Solver::SolutionInfo::r, svm_parameter::shrinking, Solver_NU::Solve(), and svm_problem::y.
Referenced by svm_train_one().
| static void solve_one_class | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| double * | alpha, | ||
| Solver::SolutionInfo * | si | ||
| ) | [static] |
Definition at line 1517 of file libsvm.cpp.
References svm_parameter::eps, svm_problem::l, svm_parameter::nu, svm_parameter::shrinking, and Solver::Solve().
Referenced by svm_train_one().
| static void svm_binary_svc_probability | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| double | Cp, | ||
| double | Cn, | ||
| double & | probA, | ||
| double & | probB | ||
| ) | [static] |
Definition at line 1879 of file libsvm.cpp.
References svm_parameter::C, svm_problem::l, svm_model::label, Malloc, svm_parameter::nr_weight, svm_parameter::probability, sigmoid_train(), svm_destroy_param(), svm_free_and_destroy_model(), svm_predict_values(), svm_train(), swap(), svm_parameter::weight, svm_parameter::weight_label, svm_problem::x, and svm_problem::y.
Referenced by svm_train().
| const char* svm_check_parameter | ( | const svm_problem * | prob, |
| const svm_parameter * | param | ||
| ) |
Definition at line 2927 of file libsvm.cpp.
References svm_parameter::C, C_SVC, svm_parameter::cache_size, svm_parameter::degree, svm_parameter::eps, EPSILON_SVR, svm_parameter::gamma, svm_parameter::kernel_type, svm_problem::l, svm_model::l, svm_model::label, LINEAR, Malloc, min(), svm_model::nr_class, svm_parameter::nu, NU_SVC, NU_SVR, ONE_CLASS, svm_parameter::p, POLY, PRECOMPUTED, svm_parameter::probability, RBF, svm_parameter::shrinking, SIGMOID, svm_parameter::svm_type, and svm_problem::y.
| int svm_check_probability_model | ( | const svm_model * | model ) |
Definition at line 3048 of file libsvm.cpp.
References C_SVC, EPSILON_SVR, NU_SVC, NU_SVR, svm_model::param, svm_model::probA, svm_model::probB, and svm_parameter::svm_type.
| void svm_cross_validation | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| int | nr_fold, | ||
| double * | target | ||
| ) |
Definition at line 2297 of file libsvm.cpp.
References C_SVC, svm_problem::l, svm_model::l, svm_model::label, Malloc, svm_model::nr_class, NU_SVC, svm_parameter::probability, svm_free_and_destroy_model(), svm_get_nr_class(), svm_group_classes(), svm_predict(), svm_predict_probability(), svm_train(), svm_parameter::svm_type, swap(), svm_problem::x, and svm_problem::y.
| void svm_destroy_model | ( | svm_model * | model_ptr ) |
Definition at line 2915 of file libsvm.cpp.
References svm_free_and_destroy_model().
Referenced by svmTrain().
| void svm_destroy_param | ( | svm_parameter * | param ) |
Definition at line 2921 of file libsvm.cpp.
References svm_parameter::weight, and svm_parameter::weight_label.
Referenced by svm_binary_svc_probability(), and svmTrain().
| void svm_free_and_destroy_model | ( | svm_model ** | model_ptr_ptr ) |
Definition at line 2905 of file libsvm.cpp.
References svm_free_model_content().
Referenced by svm_binary_svc_probability(), svm_cross_validation(), and svm_destroy_model().
| void svm_free_model_content | ( | svm_model * | model_ptr ) |
Definition at line 2890 of file libsvm.cpp.
References svm_model::free_sv, svm_model::l, svm_model::label, svm_model::nr_class, svm_model::nSV, svm_model::probA, svm_model::probB, svm_model::rho, svm_model::SV, and svm_model::sv_coef.
Referenced by svm_free_and_destroy_model().
| void svm_get_labels | ( | const svm_model * | model, |
| int * | label | ||
| ) |
Definition at line 2423 of file libsvm.cpp.
References svm_model::label, and svm_model::nr_class.
| int svm_get_nr_class | ( | const svm_model * | model ) |
Definition at line 2418 of file libsvm.cpp.
References svm_model::nr_class.
| int svm_get_svm_type | ( | const svm_model * | model ) |
Definition at line 2413 of file libsvm.cpp.
References svm_model::param, and svm_parameter::svm_type.
| double svm_get_svr_probability | ( | const svm_model * | model ) |
Definition at line 2430 of file libsvm.cpp.
References EPSILON_SVR, NU_SVR, svm_model::param, svm_model::probA, and svm_parameter::svm_type.
| static void svm_group_classes | ( | const svm_problem * | prob, |
| int * | nr_class_ret, | ||
| int ** | label_ret, | ||
| int ** | start_ret, | ||
| int ** | count_ret, | ||
| int * | perm | ||
| ) | [static] |
Definition at line 2000 of file libsvm.cpp.
References svm_problem::l, svm_model::l, svm_model::label, Malloc, svm_model::nr_class, and svm_problem::y.
Referenced by svm_cross_validation(), and svm_train().
| svm_model* svm_load_model | ( | const char * | model_file_name ) | [read] |
Definition at line 2690 of file libsvm.cpp.
References svm_parameter::coef0, svm_parameter::degree, svm_model::free_sv, svm_parameter::gamma, svm_node::index, svm_parameter::kernel_type, kernel_type_table, svm_model::l, svm_model::label, line, Malloc, max_line_len, svm_model::nr_class, svm_model::nSV, svm_model::param, svm_model::probA, svm_model::probB, readline(), svm_model::rho, svm_model::SV, svm_model::sv_coef, svm_parameter::svm_type, svm_type_table, and svm_node::value.
Definition at line 2518 of file libsvm.cpp.
References EPSILON_SVR, Malloc, svm_model::nr_class, NU_SVR, ONE_CLASS, svm_model::param, svm_predict_values(), and svm_parameter::svm_type.
| double svm_predict_probability | ( | const svm_model * | model, |
| const svm_node * | x, | ||
| double * | prob_estimates | ||
| ) |
Definition at line 2533 of file libsvm.cpp.
References C_SVC, svm_model::label, Malloc, max(), min(), multiclass_probability(), svm_model::nr_class, NU_SVC, svm_model::param, svm_model::probA, svm_model::probB, sigmoid_predict(), svm_predict(), svm_predict_values(), and svm_parameter::svm_type.
Definition at line 2442 of file libsvm.cpp.
References EPSILON_SVR, Kernel::k_function(), svm_model::l, svm_model::label, Malloc, svm_model::nr_class, svm_model::nSV, NU_SVR, ONE_CLASS, svm_model::param, svm_model::rho, svm_model::SV, svm_model::sv_coef, and svm_parameter::svm_type.
| int svm_save_model | ( | const char * | model_file_name, |
| const svm_model * | model | ||
| ) |
Definition at line 2582 of file libsvm.cpp.
References svm_parameter::coef0, svm_parameter::degree, svm_parameter::gamma, svm_node::index, svm_parameter::kernel_type, kernel_type_table, svm_model::l, svm_model::label, svm_model::nr_class, svm_model::nSV, svm_model::param, POLY, PRECOMPUTED, svm_model::probA, svm_model::probB, RBF, svm_model::rho, SIGMOID, svm_model::SV, svm_model::sv_coef, svm_parameter::svm_type, svm_type_table, and svm_node::value.
| void svm_set_print_string_function | ( | void(*)(const char *) | print_func ) |
Definition at line 3056 of file libsvm.cpp.
References print_string_stdout(), and svm_print_string.
| static double svm_svr_probability | ( | const svm_problem * | prob, |
| const svm_parameter * | param | ||
| ) | [static] |
Definition at line 1966 of file libsvm.cpp.
References info(), svm_problem::l, Malloc, svm_model::param, svm_parameter::probability, svm_cross_validation(), and svm_problem::y.
Referenced by svm_train().
| svm_model* svm_train | ( | const svm_problem * | prob, |
| const svm_parameter * | param | ||
| ) |
Definition at line 2060 of file libsvm.cpp.
References decision_function::alpha, svm_parameter::C, EPSILON_SVR, svm_model::free_sv, info(), svm_model::l, svm_problem::l, svm_model::label, Malloc, svm_model::nr_class, svm_model::nSV, NU_SVR, ONE_CLASS, svm_model::param, svm_model::probA, svm_parameter::probability, svm_model::probB, decision_function::rho, svm_model::rho, svm_model::SV, svm_model::sv_coef, svm_binary_svc_probability(), svm_group_classes(), svm_svr_probability(), svm_train_one(), svm_parameter::svm_type, svm_parameter::weight, svm_parameter::weight_label, svm_problem::x, and svm_problem::y.
| static decision_function svm_train_one | ( | const svm_problem * | prob, |
| const svm_parameter * | param, | ||
| double | Cp, | ||
| double | Cn | ||
| ) | [static] |
Definition at line 1634 of file libsvm.cpp.
References decision_function::alpha, C_SVC, EPSILON_SVR, info(), svm_problem::l, Malloc, NU_SVC, NU_SVR, Solver::SolutionInfo::obj, ONE_CLASS, decision_function::rho, Solver::SolutionInfo::rho, solve_c_svc(), solve_epsilon_svr(), solve_nu_svc(), solve_nu_svr(), solve_one_class(), svm_parameter::svm_type, Solver::SolutionInfo::upper_bound_n, Solver::SolutionInfo::upper_bound_p, and svm_problem::y.
Referenced by svm_train().
| static void swap | ( | T & | x, |
| T & | y | ||
| ) | [inline, static] |
Definition at line 20 of file libsvm.cpp.
Referenced by Cache::get_data(), svm_binary_svc_probability(), svm_cross_validation(), SVR_Q::swap_index(), ONE_CLASS_Q::swap_index(), SVC_Q::swap_index(), Solver::swap_index(), Kernel::swap_index(), and Cache::swap_index().
const char* kernel_type_table[] [static] |
{
"linear","polynomial","rbf","sigmoid","precomputed",NULL
}
Definition at line 2577 of file libsvm.cpp.
Referenced by svm_load_model(), and svm_save_model().
| int libsvm_version = LIBSVM_VERSION |
Definition at line 11 of file libsvm.cpp.
char* line = NULL [static] |
Definition at line 2669 of file libsvm.cpp.
Referenced by computeAdaptedTnorm(), computeAndStoreZnormParam(), computeLLRmatrix(), learnEMimpostorModels(), learnMAPimpostorModels(), loadTnormParam(), Oracle(), readline(), searchLLRFromResFile(), selectNearestTarModel(), svdLoadSparseTextHBFile(), and svm_load_model().
int max_line_len [static] |
Definition at line 2670 of file libsvm.cpp.
Referenced by readline(), and svm_load_model().
void(* svm_print_string)(const char *) = &print_string_stdout [static] |
Definition at line 46 of file libsvm.cpp.
Referenced by svm_set_print_string_function().
const char* svm_type_table[] [static] |
{
"c_svc","nu_svc","one_class","epsilon_svr","nu_svr",NULL
}
Definition at line 2572 of file libsvm.cpp.
Referenced by svm_load_model(), and svm_save_model().
1.7.2