svm.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef _LIBSVM_H
  2. #define _LIBSVM_H
  3. #define LIBSVM_VERSION 332
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. extern int libsvm_version;
  8. // /*�����ṹ������*/
  9. // typedef struct {
  10. // double realPart;
  11. // double imaginaryPart;
  12. // }complexNumber;
  13. // void fastFourierOperation(complexNumber* x, complexNumber* W);//���ٸ���Ҷ�任�㷨
  14. // //void initRotationFactor(complexNumber* W); //������ת��������
  15. // void changePosition(complexNumber* x); //ż��任�㷨
  16. // //void outputArray(); //�����������
  17. // void add(complexNumber, complexNumber, complexNumber*); //�����ӷ�
  18. // void mul(complexNumber, complexNumber, complexNumber*); //�����˷�
  19. // void sub(complexNumber, complexNumber, complexNumber*); //��������
  20. // double* calculateMagnitude(complexNumber* x);
  21. // double* get_feature(double* arr, int win, int hold, int count);
  22. struct svm_node
  23. {
  24. int index;
  25. double value;
  26. };
  27. struct svm_problem
  28. {
  29. int l;
  30. double *y;
  31. struct svm_node **x;
  32. };
  33. enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */
  34. enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
  35. struct svm_parameter
  36. {
  37. int svm_type;
  38. int kernel_type;
  39. int degree; /* for poly */
  40. double gamma; /* for poly/rbf/sigmoid */
  41. double coef0; /* for poly/sigmoid */
  42. /* these are for training only */
  43. double cache_size; /* in MB */
  44. double eps; /* stopping criteria */
  45. double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
  46. int nr_weight; /* for C_SVC */
  47. int *weight_label; /* for C_SVC */
  48. double* weight; /* for C_SVC */
  49. double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
  50. double p; /* for EPSILON_SVR */
  51. int shrinking; /* use the shrinking heuristics */
  52. int probability; /* do probability estimates */
  53. };
  54. //
  55. // svm_model
  56. //
  57. struct svm_model
  58. {
  59. struct svm_parameter param; /* parameter */
  60. int nr_class; /* number of classes, = 2 in regression/one class svm */
  61. int l; /* total #SV */
  62. struct svm_node **SV; /* SVs (SV[l]) */
  63. double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
  64. double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
  65. double *probA; /* pariwise probability information */
  66. double *probB;
  67. double *prob_density_marks; /* probability information for ONE_CLASS */
  68. int *sv_indices; /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
  69. /* for classification only */
  70. int *label; /* label of each class (label[k]) */
  71. int *nSV; /* number of SVs for each class (nSV[k]) */
  72. /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
  73. /* XXX */
  74. int free_sv; /* 1 if svm_model is created by svm_load_model*/
  75. /* 0 if svm_model is created by svm_train */
  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. int svm_save_model(const char *model_file_name, const struct svm_model *model);
  80. struct svm_model *svm_load_model(const char *model_file_name);
  81. int svm_get_svm_type(const struct svm_model *model);
  82. int svm_get_nr_class(const struct svm_model *model);
  83. void svm_get_labels(const struct svm_model *model, int *label);
  84. void svm_get_sv_indices(const struct svm_model *model, int *sv_indices);
  85. int svm_get_nr_sv(const struct svm_model *model);
  86. double svm_get_svr_probability(const struct svm_model *model);
  87. double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
  88. double svm_predict(const struct svm_model *model, const struct svm_node *x);
  89. double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
  90. void svm_free_model_content(struct svm_model *model_ptr);
  91. void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
  92. void svm_destroy_param(struct svm_parameter *param);
  93. const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
  94. int svm_check_probability_model(const struct svm_model *model);
  95. void svm_set_print_string_function(void (*print_func)(const char *));
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /* _LIBSVM_H */