BayesF32.cpp 2.4 KB

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