| 1 |
#ifndef _LIBSVM_H |
| 2 |
#define _LIBSVM_H |
| 3 |
|
| 4 |
#define LIBSVM_VERSION 312 |
| 5 |
|
| 6 |
#include <vector> |
| 7 |
#include <string> |
| 8 |
#include <map> |
| 9 |
#ifdef __cplusplus |
| 10 |
extern "C" { |
| 11 |
#endif |
| 12 |
|
| 13 |
extern int libsvm_version; |
| 14 |
|
| 15 |
struct svm_node |
| 16 |
{ |
| 17 |
int index; |
| 18 |
double value; |
| 19 |
}; |
| 20 |
|
| 21 |
struct svm_problem |
| 22 |
{ |
| 23 |
int l; |
| 24 |
double *y; |
| 25 |
struct svm_node **x; |
| 26 |
}; |
| 27 |
|
| 28 |
enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; |
| 29 |
enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; |
| 30 |
|
| 31 |
struct svm_parameter |
| 32 |
{ |
| 33 |
int svm_type; |
| 34 |
int kernel_type; |
| 35 |
int degree; |
| 36 |
double gamma; |
| 37 |
double coef0; |
| 38 |
|
| 39 |
|
| 40 |
double cache_size; |
| 41 |
double eps; |
| 42 |
double C; |
| 43 |
int nr_weight; |
| 44 |
int *weight_label; |
| 45 |
double* weight; |
| 46 |
double nu; |
| 47 |
double p; |
| 48 |
int shrinking; |
| 49 |
int probability; |
| 50 |
bool verbose; |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
struct svm_model |
| 57 |
{ |
| 58 |
struct svm_parameter param; |
| 59 |
int nr_class; |
| 60 |
int l; |
| 61 |
struct svm_node **SV; |
| 62 |
double **sv_coef; |
| 63 |
double *rho; |
| 64 |
double *probA; |
| 65 |
double *probB; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
int *label; |
| 70 |
int *nSV; |
| 71 |
|
| 72 |
|
| 73 |
int free_sv; |
| 74 |
|
| 75 |
}; |
| 76 |
|
| 77 |
struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param); |
| 78 |
void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target); |
| 79 |
|
| 80 |
int svm_save_model(const std::string &model_file_name, const struct svm_model *model, const std::vector<double> &offset, const std::vector<double> &scale, const std::map<std::string,short> &classValueMap, const std::vector<std::string> &nameVector, const std::vector<std::string> &bandNames=std::vector<std::string>()); |
| 81 |
int svm_serialize_model(std::ostream &outputStream, const struct svm_model *model, const std::vector<double> &offset, const std::vector<double> &scale, const std::map<std::string,short> &classValueMap, const std::vector<std::string> &nameVector, const std::vector<std::string> &bandNames); |
| 82 |
|
| 83 |
int svm_save_model_old(const char *model_file_name, const struct svm_model *model); |
| 84 |
struct svm_model *svm_load_model(const std::string &model_file_name, std::vector<double> &offset, std::vector<double> &scale, std::map<std::string,short> &classValueMap, std::vector<std::string> &nameVector, std::vector<std::string> &bandNames); |
| 85 |
|
| 86 |
int svm_get_svm_type(const struct svm_model *model); |
| 87 |
int svm_get_nr_class(const struct svm_model *model); |
| 88 |
void svm_get_labels(const struct svm_model *model, int *label); |
| 89 |
double svm_get_svr_probability(const struct svm_model *model); |
| 90 |
|
| 91 |
double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values); |
| 92 |
double svm_predict(const struct svm_model *model, const struct svm_node *x); |
| 93 |
double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates); |
| 94 |
|
| 95 |
void svm_free_model_content(struct svm_model *model_ptr); |
| 96 |
void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr); |
| 97 |
void svm_destroy_param(struct svm_parameter *param); |
| 98 |
|
| 99 |
const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param); |
| 100 |
int svm_check_probability_model(const struct svm_model *model); |
| 101 |
|
| 102 |
void svm_set_print_string_function(void (*print_func)(const char *)); |
| 103 |
|
| 104 |
#ifdef __cplusplus |
| 105 |
} |
| 106 |
#endif |
| 107 |
|
| 108 |
#endif |