Kentarou Shimatani
/
Theremi
action recognizer with theremin
svm/svm.h@0:b9ac53c439ed, 2011-09-14 (annotated)
- Committer:
- peccu
- Date:
- Wed Sep 14 13:42:46 2011 +0000
- Revision:
- 0:b9ac53c439ed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peccu | 0:b9ac53c439ed | 1 | #ifndef _LIBSVM_H |
peccu | 0:b9ac53c439ed | 2 | #define _LIBSVM_H |
peccu | 0:b9ac53c439ed | 3 | |
peccu | 0:b9ac53c439ed | 4 | #define LIBSVM_VERSION 300 |
peccu | 0:b9ac53c439ed | 5 | |
peccu | 0:b9ac53c439ed | 6 | #ifdef __cplusplus |
peccu | 0:b9ac53c439ed | 7 | extern "C" { |
peccu | 0:b9ac53c439ed | 8 | #endif |
peccu | 0:b9ac53c439ed | 9 | |
peccu | 0:b9ac53c439ed | 10 | extern int libsvm_version; |
peccu | 0:b9ac53c439ed | 11 | |
peccu | 0:b9ac53c439ed | 12 | struct svm_node |
peccu | 0:b9ac53c439ed | 13 | { |
peccu | 0:b9ac53c439ed | 14 | int index; |
peccu | 0:b9ac53c439ed | 15 | double value; |
peccu | 0:b9ac53c439ed | 16 | }; |
peccu | 0:b9ac53c439ed | 17 | |
peccu | 0:b9ac53c439ed | 18 | struct svm_problem |
peccu | 0:b9ac53c439ed | 19 | { |
peccu | 0:b9ac53c439ed | 20 | int l; |
peccu | 0:b9ac53c439ed | 21 | double *y; |
peccu | 0:b9ac53c439ed | 22 | struct svm_node **x; |
peccu | 0:b9ac53c439ed | 23 | }; |
peccu | 0:b9ac53c439ed | 24 | |
peccu | 0:b9ac53c439ed | 25 | enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */ |
peccu | 0:b9ac53c439ed | 26 | enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */ |
peccu | 0:b9ac53c439ed | 27 | |
peccu | 0:b9ac53c439ed | 28 | struct svm_parameter |
peccu | 0:b9ac53c439ed | 29 | { |
peccu | 0:b9ac53c439ed | 30 | int svm_type; |
peccu | 0:b9ac53c439ed | 31 | int kernel_type; |
peccu | 0:b9ac53c439ed | 32 | int degree; /* for poly */ |
peccu | 0:b9ac53c439ed | 33 | double gamma; /* for poly/rbf/sigmoid */ |
peccu | 0:b9ac53c439ed | 34 | double coef0; /* for poly/sigmoid */ |
peccu | 0:b9ac53c439ed | 35 | |
peccu | 0:b9ac53c439ed | 36 | /* these are for training only */ |
peccu | 0:b9ac53c439ed | 37 | double cache_size; /* in MB */ |
peccu | 0:b9ac53c439ed | 38 | double eps; /* stopping criteria */ |
peccu | 0:b9ac53c439ed | 39 | double C; /* for C_SVC, EPSILON_SVR and NU_SVR */ |
peccu | 0:b9ac53c439ed | 40 | int nr_weight; /* for C_SVC */ |
peccu | 0:b9ac53c439ed | 41 | int *weight_label; /* for C_SVC */ |
peccu | 0:b9ac53c439ed | 42 | double* weight; /* for C_SVC */ |
peccu | 0:b9ac53c439ed | 43 | double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */ |
peccu | 0:b9ac53c439ed | 44 | double p; /* for EPSILON_SVR */ |
peccu | 0:b9ac53c439ed | 45 | int shrinking; /* use the shrinking heuristics */ |
peccu | 0:b9ac53c439ed | 46 | int probability; /* do probability estimates */ |
peccu | 0:b9ac53c439ed | 47 | }; |
peccu | 0:b9ac53c439ed | 48 | |
peccu | 0:b9ac53c439ed | 49 | // |
peccu | 0:b9ac53c439ed | 50 | // svm_model |
peccu | 0:b9ac53c439ed | 51 | // |
peccu | 0:b9ac53c439ed | 52 | struct svm_model |
peccu | 0:b9ac53c439ed | 53 | { |
peccu | 0:b9ac53c439ed | 54 | struct svm_parameter param; /* parameter */ |
peccu | 0:b9ac53c439ed | 55 | int nr_class; /* number of classes, = 2 in regression/one class svm */ |
peccu | 0:b9ac53c439ed | 56 | int l; /* total #SV */ |
peccu | 0:b9ac53c439ed | 57 | struct svm_node **SV; /* SVs (SV[l]) */ |
peccu | 0:b9ac53c439ed | 58 | double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */ |
peccu | 0:b9ac53c439ed | 59 | double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */ |
peccu | 0:b9ac53c439ed | 60 | double *probA; /* pariwise probability information */ |
peccu | 0:b9ac53c439ed | 61 | double *probB; |
peccu | 0:b9ac53c439ed | 62 | |
peccu | 0:b9ac53c439ed | 63 | /* for classification only */ |
peccu | 0:b9ac53c439ed | 64 | |
peccu | 0:b9ac53c439ed | 65 | int *label; /* label of each class (label[k]) */ |
peccu | 0:b9ac53c439ed | 66 | int *nSV; /* number of SVs for each class (nSV[k]) */ |
peccu | 0:b9ac53c439ed | 67 | /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */ |
peccu | 0:b9ac53c439ed | 68 | /* XXX */ |
peccu | 0:b9ac53c439ed | 69 | int free_sv; /* 1 if svm_model is created by svm_load_model*/ |
peccu | 0:b9ac53c439ed | 70 | /* 0 if svm_model is created by svm_train */ |
peccu | 0:b9ac53c439ed | 71 | }; |
peccu | 0:b9ac53c439ed | 72 | |
peccu | 0:b9ac53c439ed | 73 | struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param); |
peccu | 0:b9ac53c439ed | 74 | void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target); |
peccu | 0:b9ac53c439ed | 75 | |
peccu | 0:b9ac53c439ed | 76 | int svm_save_model(const char *model_file_name, const struct svm_model *model); |
peccu | 0:b9ac53c439ed | 77 | struct svm_model *svm_load_model(const char *model_file_name); |
peccu | 0:b9ac53c439ed | 78 | struct svm_model *svm_load_model_fp(FILE *fp); |
peccu | 0:b9ac53c439ed | 79 | |
peccu | 0:b9ac53c439ed | 80 | int svm_get_svm_type(const struct svm_model *model); |
peccu | 0:b9ac53c439ed | 81 | int svm_get_nr_class(const struct svm_model *model); |
peccu | 0:b9ac53c439ed | 82 | void svm_get_labels(const struct svm_model *model, int *label); |
peccu | 0:b9ac53c439ed | 83 | double svm_get_svr_probability(const struct svm_model *model); |
peccu | 0:b9ac53c439ed | 84 | |
peccu | 0:b9ac53c439ed | 85 | double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values); |
peccu | 0:b9ac53c439ed | 86 | double svm_predict(const struct svm_model *model, const struct svm_node *x); |
peccu | 0:b9ac53c439ed | 87 | double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates); |
peccu | 0:b9ac53c439ed | 88 | |
peccu | 0:b9ac53c439ed | 89 | void svm_free_model_content(struct svm_model *model_ptr); |
peccu | 0:b9ac53c439ed | 90 | void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr); |
peccu | 0:b9ac53c439ed | 91 | void svm_destroy_param(struct svm_parameter *param); |
peccu | 0:b9ac53c439ed | 92 | |
peccu | 0:b9ac53c439ed | 93 | const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param); |
peccu | 0:b9ac53c439ed | 94 | int svm_check_probability_model(const struct svm_model *model); |
peccu | 0:b9ac53c439ed | 95 | |
peccu | 0:b9ac53c439ed | 96 | void svm_set_print_string_function(void (*print_func)(const char *)); |
peccu | 0:b9ac53c439ed | 97 | |
peccu | 0:b9ac53c439ed | 98 | // deprecated |
peccu | 0:b9ac53c439ed | 99 | // this function will be removed in future release |
peccu | 0:b9ac53c439ed | 100 | void svm_destroy_model(struct svm_model *model_ptr); |
peccu | 0:b9ac53c439ed | 101 | |
peccu | 0:b9ac53c439ed | 102 | #ifdef __cplusplus |
peccu | 0:b9ac53c439ed | 103 | } |
peccu | 0:b9ac53c439ed | 104 | #endif |
peccu | 0:b9ac53c439ed | 105 | |
peccu | 0:b9ac53c439ed | 106 | #endif /* _LIBSVM_H */ |