svm_model.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef __LIBSVM_MODEL_H__
  2. #define __LIBSVM_MODEL_H__
  3. #include <stdint.h>
  4. #define FEATURE_SIZE 200
  5. #define NR_CLASS 2
  6. #define TOTAL_SV 3033
  7. #define NR_CLASSIFER(nc) (nc*(nc-1)/2)
  8. typedef struct {
  9. uint8_t kernel_type;
  10. //-- for polynomial kernel -->
  11. uint8_t degree;
  12. float gamma;
  13. float coef0;
  14. //<---------------------------
  15. uint8_t nr_class; /* number of classes, = 2 in regression/one class svm */
  16. uint32_t total_sv; /* total #SV */
  17. float* rhos; /* constants in decision functions (rho[k*(k-1)/2]) */
  18. int32_t* label; /* label of each class (label[k]) */
  19. float* probA; /* pariwise probability information */
  20. float* probB;
  21. float (*coefs)[TOTAL_SV]; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
  22. uint32_t vec_dim;
  23. float* SVs; /* SVs (SV[l]) */
  24. int32_t* nr_sv; /* number of SVs for each class (nSV[k]) */
  25. /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
  26. } Model;
  27. /**
  28. * init svm params, must be invoked before predict
  29. */
  30. void init_svm_params(Model *svm_model);
  31. /**
  32. * two-class only
  33. */
  34. float predict(const Model *svm_model, const float* x, int len);
  35. /**
  36. * two-class only
  37. */
  38. float predict_probability(const Model *svm_model, const float* x, int len);
  39. /**
  40. * @brief predict multiclasses
  41. *
  42. * @param svm_model SVM model
  43. * @param x input x feature
  44. * @param len x length
  45. * @return int32_t return label
  46. */
  47. int32_t multi_predict(const Model* svm_model, const float* x, int len);
  48. /**
  49. * predict multi classes
  50. * @param[in] svm_model SVM model
  51. * @param[in] x input x feature
  52. * @param[in] len x length
  53. * @param[out] scores_buf probability of each score
  54. * @param[in] scores_buf_len length of scores buf
  55. */
  56. int32_t multi_predict_probability(const Model *svm_model, const float* x, int len, float* scores_buf, int scores_buf_len);
  57. #endif