You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

svm.h 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef _LIBSVM_H
  2. #define _LIBSVM_H
  3. #define LIBSVM_VERSION 322
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. extern int libsvm_version;
  8. struct svm_node
  9. {
  10. int index;
  11. double value;
  12. };
  13. struct svm_problem
  14. {
  15. int l;
  16. double *y;
  17. struct svm_node **x;
  18. };
  19. enum { C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR }; /* svm_type */
  20. enum { LINEAR, POLY, RBF, SIGMOID, PRECOMPUTED }; /* kernel_type */
  21. struct svm_parameter
  22. {
  23. int svm_type;
  24. int kernel_type;
  25. int degree; /* for poly */
  26. double gamma; /* for poly/rbf/sigmoid */
  27. double coef0; /* for poly/sigmoid */
  28. /* these are for training only */
  29. double cache_size; /* in MB */
  30. double eps; /* stopping criteria */
  31. double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
  32. int nr_weight; /* for C_SVC */
  33. int *weight_label; /* for C_SVC */
  34. double* weight; /* for C_SVC */
  35. double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
  36. double p; /* for EPSILON_SVR */
  37. int shrinking; /* use the shrinking heuristics */
  38. int probability; /* do probability estimates */
  39. };
  40. //
  41. // svm_model
  42. //
  43. struct svm_model
  44. {
  45. struct svm_parameter param; /* parameter */
  46. int nr_class; /* number of classes, = 2 in regression/one class svm */
  47. int l; /* total #SV */
  48. struct svm_node **SV; /* SVs (SV[l]) */
  49. double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
  50. double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
  51. double *probA; /* pariwise probability information */
  52. double *probB;
  53. int *sv_indices; /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
  54. /* for classification only */
  55. int *label; /* label of each class (label[k]) */
  56. int *nSV; /* number of SVs for each class (nSV[k]) */
  57. /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
  58. /* XXX */
  59. int free_sv; /* 1 if svm_model is created by svm_load_model*/
  60. /* 0 if svm_model is created by svm_train */
  61. };
  62. struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param);
  63. void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);
  64. int svm_save_model(const char *model_file_name, const struct svm_model *model);
  65. struct svm_model *svm_load_model(const char *model_file_name);
  66. int svm_get_svm_type(const struct svm_model *model);
  67. int svm_get_nr_class(const struct svm_model *model);
  68. void svm_get_labels(const struct svm_model *model, int *label);
  69. void svm_get_sv_indices(const struct svm_model *model, int *sv_indices);
  70. int svm_get_nr_sv(const struct svm_model *model);
  71. double svm_get_svr_probability(const struct svm_model *model);
  72. double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
  73. double svm_predict(const struct svm_model *model, const struct svm_node *x);
  74. double svm_predict_probability(const struct svm_model *model, const struct svm_node *x, double* prob_estimates);
  75. void svm_free_model_content(struct svm_model *model_ptr);
  76. void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
  77. void svm_destroy_param(struct svm_parameter *param);
  78. const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
  79. int svm_check_probability_model(const struct svm_model *model);
  80. void svm_set_print_string_function(void (*print_func)(const char *));
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif /* _LIBSVM_H */

A Python package for graph kernels, graph edit distances and graph pre-image problem.