SVMF16.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #include "SVMF16.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. void SVMF16::test_svm_linear_predict_f16()
  5. {
  6. int32_t result;
  7. arm_svm_linear_predict_f16(&this->linear,inp,&result);
  8. }
  9. void SVMF16::test_svm_polynomial_predict_f16()
  10. {
  11. int32_t result;
  12. arm_svm_polynomial_predict_f16(&this->poly,inp,&result);
  13. }
  14. void SVMF16::test_svm_rbf_predict_f16()
  15. {
  16. int32_t result;
  17. arm_svm_rbf_predict_f16(&this->rbf,inp,&result);
  18. }
  19. void SVMF16::test_svm_sigmoid_predict_f16()
  20. {
  21. int32_t result;
  22. arm_svm_sigmoid_predict_f16(&this->sigmoid,inp,&result);
  23. }
  24. void SVMF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& testparams,Client::PatternMgr *mgr)
  25. {
  26. int kind;
  27. int nbp,nbi;
  28. const float16_t *paramsp;
  29. std::vector<Testing::param_t>::iterator it = testparams.begin();
  30. this->vecDim = *it++;
  31. this->nbSupportVectors = *it++;
  32. switch(id)
  33. {
  34. case SVMF16::TEST_SVM_LINEAR_PREDICT_F16_1:
  35. {
  36. samples.reload(SVMF16::INPUT_F16_ID,mgr,this->vecDim);
  37. params.reload(SVMF16::PARAMS_LINEAR_F16_ID,mgr);
  38. dims.reload(SVMF16::DIMS_LINEAR_S16_ID,mgr);
  39. int16_t *dimsp=dims.ptr();
  40. nbi = dimsp[2*this->nbLinear];
  41. nbp = dimsp[2*this->nbLinear + 1];
  42. paramsp = params.ptr() + nbp;
  43. inp=samples.ptr() + nbi;
  44. kind = SVMF16::LINEAR;
  45. }
  46. break;
  47. case SVMF16::TEST_SVM_POLYNOMIAL_PREDICT_F16_2:
  48. {
  49. samples.reload(SVMF16::INPUT_F16_ID,mgr,this->vecDim);
  50. params.reload(SVMF16::PARAMS_POLY_F16_ID,mgr);
  51. dims.reload(SVMF16::DIMS_POLY_S16_ID,mgr);
  52. int16_t *dimsp=dims.ptr();
  53. nbi = dimsp[2*this->nbPoly];
  54. nbp = dimsp[2*this->nbPoly + 1];
  55. paramsp = params.ptr() + nbp;
  56. inp=samples.ptr() + nbi;
  57. kind = SVMF16::POLY;
  58. }
  59. break;
  60. case SVMF16::TEST_SVM_RBF_PREDICT_F16_3:
  61. {
  62. samples.reload(SVMF16::INPUT_F16_ID,mgr,this->vecDim);
  63. params.reload(SVMF16::PARAMS_RBF_F16_ID,mgr);
  64. dims.reload(SVMF16::DIMS_RBF_S16_ID,mgr);
  65. int16_t *dimsp=dims.ptr();
  66. nbi = dimsp[2*this->nbRBF];
  67. nbp = dimsp[2*this->nbRBF + 1];
  68. paramsp = params.ptr() + nbp;
  69. inp=samples.ptr() + nbi;
  70. kind = SVMF16::RBF;
  71. }
  72. break;
  73. case SVMF16::TEST_SVM_SIGMOID_PREDICT_F16_4:
  74. {
  75. samples.reload(SVMF16::INPUT_F16_ID,mgr,this->vecDim);
  76. params.reload(SVMF16::PARAMS_SIGMOID_F16_ID,mgr);
  77. dims.reload(SVMF16::DIMS_SIGMOID_S16_ID,mgr);
  78. int16_t *dimsp=dims.ptr();
  79. nbi = dimsp[2*this->nbSigmoid];
  80. nbp = dimsp[2*this->nbSigmoid + 1];
  81. paramsp = params.ptr() + nbp;
  82. inp=samples.ptr() + nbi;
  83. kind = SVMF16::SIGMOID;
  84. }
  85. break;
  86. }
  87. this->classes[0] = 0;
  88. this->classes[1] = 1;
  89. this->intercept=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors];
  90. this->supportVectors=paramsp;
  91. this->dualCoefs=paramsp + (this->vecDim*this->nbSupportVectors);
  92. switch(kind)
  93. {
  94. case SVMF16::POLY:
  95. this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
  96. this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
  97. this->degree=(int)paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 3];
  98. break;
  99. case SVMF16::RBF:
  100. this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1];
  101. break;
  102. case SVMF16::SIGMOID:
  103. this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
  104. this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
  105. break;
  106. }
  107. switch(id)
  108. {
  109. case SVMF16::TEST_SVM_LINEAR_PREDICT_F16_1:
  110. {
  111. arm_svm_linear_init_f16(&linear,
  112. this->nbSupportVectors,
  113. this->vecDim,
  114. this->intercept,
  115. this->dualCoefs,
  116. this->supportVectors,
  117. this->classes);
  118. }
  119. break;
  120. case SVMF16::TEST_SVM_POLYNOMIAL_PREDICT_F16_2:
  121. {
  122. arm_svm_polynomial_init_f16(&poly,
  123. this->nbSupportVectors,
  124. this->vecDim,
  125. this->intercept,
  126. this->dualCoefs,
  127. this->supportVectors,
  128. this->classes,
  129. this->degree,
  130. this->coef0,
  131. this->gamma
  132. );
  133. }
  134. break;
  135. case SVMF16::TEST_SVM_RBF_PREDICT_F16_3:
  136. {
  137. arm_svm_rbf_init_f16(&rbf,
  138. this->nbSupportVectors,
  139. this->vecDim,
  140. this->intercept,
  141. this->dualCoefs,
  142. this->supportVectors,
  143. this->classes,
  144. this->gamma
  145. );
  146. }
  147. break;
  148. case SVMF16::TEST_SVM_SIGMOID_PREDICT_F16_4:
  149. {
  150. arm_svm_sigmoid_init_f16(&sigmoid,
  151. this->nbSupportVectors,
  152. this->vecDim,
  153. this->intercept,
  154. this->dualCoefs,
  155. this->supportVectors,
  156. this->classes,
  157. this->coef0,
  158. this->gamma
  159. );
  160. }
  161. break;
  162. }
  163. }
  164. void SVMF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  165. {
  166. (void)mgr;
  167. switch(id)
  168. {
  169. case SVMF16::TEST_SVM_LINEAR_PREDICT_F16_1:
  170. nbLinear++;
  171. break;
  172. case SVMF16::TEST_SVM_POLYNOMIAL_PREDICT_F16_2:
  173. nbPoly++;
  174. break;
  175. case SVMF16::TEST_SVM_RBF_PREDICT_F16_3:
  176. nbRBF++;
  177. break;
  178. case SVMF16::TEST_SVM_SIGMOID_PREDICT_F16_4:
  179. nbSigmoid++;
  180. break;
  181. }
  182. }