BayesF16.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "BayesF16.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "Test.h"
  5. #define REL_ERROR ((float16_t)3e-3)
  6. void BayesF16::test_gaussian_naive_bayes_predict_f16()
  7. {
  8. const float16_t *inp = input.ptr();
  9. float16_t *bufp = outputProbas.ptr();
  10. int16_t *p = outputPredicts.ptr();
  11. for(int i=0; i < this->nbPatterns ; i ++)
  12. {
  13. *p = arm_gaussian_naive_bayes_predict_f16(&bayes,
  14. inp,
  15. bufp);
  16. inp += this->vecDim;
  17. bufp += this->classNb;
  18. p++;
  19. }
  20. ASSERT_REL_ERROR(outputProbas,probas,REL_ERROR);
  21. ASSERT_EQ(outputPredicts,predicts);
  22. }
  23. void BayesF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  24. {
  25. (void)paramsArgs;
  26. switch(id)
  27. {
  28. case BayesF16::TEST_GAUSSIAN_NAIVE_BAYES_PREDICT_F16_1:
  29. input.reload(BayesF16::INPUTS1_F16_ID,mgr);
  30. params.reload(BayesF16::PARAMS1_F16_ID,mgr);
  31. dims.reload(BayesF16::DIMS1_S16_ID,mgr);
  32. const int16_t *dimsp=dims.ptr();
  33. const float16_t *paramsp = params.ptr();
  34. this->nbPatterns=dimsp[0];
  35. this->classNb=dimsp[1];
  36. this->vecDim=dimsp[2];
  37. this->theta=paramsp;
  38. this->sigma=paramsp + (this->classNb * this->vecDim);
  39. this->classPrior=paramsp + 2*(this->classNb * this->vecDim);
  40. this->epsilon=paramsp[this->classNb + 2*(this->classNb * this->vecDim)];
  41. //printf("%f %f %f\n",this->theta[0],this->sigma[0],this->classPrior[0]);
  42. // Reference patterns are not loaded when we are in dump mode
  43. probas.reload(BayesF16::PROBAS1_F16_ID,mgr);
  44. predicts.reload(BayesF16::PREDICTS1_S16_ID,mgr);
  45. outputProbas.create(this->nbPatterns*this->classNb,BayesF16::OUT_PROBA_F16_ID,mgr);
  46. outputPredicts.create(this->nbPatterns,BayesF16::OUT_PREDICT_S16_ID,mgr);
  47. bayes.vectorDimension=this->vecDim;
  48. bayes.numberOfClasses=this->classNb;
  49. bayes.theta=this->theta;
  50. bayes.sigma=this->sigma;
  51. bayes.classPriors=this->classPrior;
  52. bayes.epsilon=this->epsilon;
  53. break;
  54. }
  55. }
  56. void BayesF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  57. {
  58. (void)id;
  59. outputProbas.dump(mgr);
  60. outputPredicts.dump(mgr);
  61. }