1 #ifndef _LIBLINEAR_H 2 #define _LIBLINEAR_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include "_cython_blas_helpers.h" 9 10 struct feature_node 11 { 12 int index; 13 double value; 14 }; 15 16 struct problem 17 { 18 int l, n; 19 double *y; 20 struct feature_node **x; 21 double bias; /* < 0 if no bias term */ 22 double *W; 23 }; 24 25 enum { L2R_LR, L2R_L2LOSS_SVC_DUAL, L2R_L2LOSS_SVC, L2R_L1LOSS_SVC_DUAL, MCSVM_CS, L1R_L2LOSS_SVC, L1R_LR, L2R_LR_DUAL, L2R_L2LOSS_SVR = 11, L2R_L2LOSS_SVR_DUAL, L2R_L1LOSS_SVR_DUAL }; /* solver_type */ 26 27 struct parameter 28 { 29 int solver_type; 30 31 /* these are for training only */ 32 double eps; /* stopping criteria */ 33 double C; 34 int nr_weight; 35 int *weight_label; 36 double* weight; 37 int max_iter; 38 double p; 39 }; 40 41 struct model 42 { 43 struct parameter param; 44 int nr_class; /* number of classes */ 45 int nr_feature; 46 double *w; 47 int *label; /* label of each class */ 48 double bias; 49 int *n_iter; /* no. of iterations of each class */ 50 }; 51 52 void set_seed(unsigned seed); 53 54 struct model* train(const struct problem *prob, const struct parameter *param, BlasFunctions *blas_functions); 55 void cross_validation(const struct problem *prob, const struct parameter *param, int nr_fold, double *target); 56 57 double predict_values(const struct model *model_, const struct feature_node *x, double* dec_values); 58 double predict(const struct model *model_, const struct feature_node *x); 59 double predict_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates); 60 61 int save_model(const char *model_file_name, const struct model *model_); 62 struct model *load_model(const char *model_file_name); 63 64 int get_nr_feature(const struct model *model_); 65 int get_nr_class(const struct model *model_); 66 void get_labels(const struct model *model_, int* label); 67 void get_n_iter(const struct model *model_, int* n_iter); 68 #if 0 69 double get_decfun_coef(const struct model *model_, int feat_idx, int label_idx); 70 double get_decfun_bias(const struct model *model_, int label_idx); 71 #endif 72 73 void free_model_content(struct model *model_ptr); 74 void free_and_destroy_model(struct model **model_ptr_ptr); 75 void destroy_param(struct parameter *param); 76 77 const char *check_parameter(const struct problem *prob, const struct parameter *param); 78 int check_probability_model(const struct model *model); 79 int check_regression_model(const struct model *model); 80 void set_print_string_function(void (*print_func) (const char*)); 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif /* _LIBLINEAR_H */ 87 88