1 #include "BayesF32.h"
2 #include <stdio.h>
3 #include "Error.h"
4 #include "Test.h"
5 
6 
7 
test_gaussian_naive_bayes_predict_f32()8     void BayesF32::test_gaussian_naive_bayes_predict_f32()
9     {
10        const float32_t *inp = input.ptr();
11 
12        float32_t *bufp = outputProbas.ptr();
13        float32_t *tempp = temp.ptr();
14        int16_t *p = outputPredicts.ptr();
15 
16 
17        for(int i=0; i < this->nbPatterns ; i ++)
18        {
19           *p = arm_gaussian_naive_bayes_predict_f32(&bayes,
20                 inp,
21                 bufp,tempp);
22 
23           inp += this->vecDim;
24           bufp += this->classNb;
25           p++;
26        }
27 
28         ASSERT_REL_ERROR(outputProbas,probas,(float32_t)5e-6);
29         ASSERT_EQ(outputPredicts,predicts);
30     }
31 
32 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)33     void BayesF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
34     {
35 
36 
37        (void)paramsArgs;
38 
39        switch(id)
40        {
41           case BayesF32::TEST_GAUSSIAN_NAIVE_BAYES_PREDICT_F32_1:
42 
43 
44             input.reload(BayesF32::INPUTS1_F32_ID,mgr);
45             params.reload(BayesF32::PARAMS1_F32_ID,mgr);
46             dims.reload(BayesF32::DIMS1_S16_ID,mgr);
47 
48             const int16_t *dimsp=dims.ptr();
49             const float32_t *paramsp = params.ptr();
50 
51             this->nbPatterns=dimsp[0];
52             this->classNb=dimsp[1];
53             this->vecDim=dimsp[2];
54 
55             this->theta=paramsp;
56             this->sigma=paramsp + (this->classNb * this->vecDim);
57             this->classPrior=paramsp + 2*(this->classNb * this->vecDim);
58             this->epsilon=paramsp[this->classNb + 2*(this->classNb * this->vecDim)];
59             //printf("%f %f %f\n",this->theta[0],this->sigma[0],this->classPrior[0]);
60 
61             // Reference patterns are not loaded when we are in dump mode
62             probas.reload(BayesF32::PROBAS1_F32_ID,mgr);
63             predicts.reload(BayesF32::PREDICTS1_S16_ID,mgr);
64 
65             outputProbas.create(this->nbPatterns*this->classNb,BayesF32::OUT_PROBA_F32_ID,mgr);
66             temp.create(this->nbPatterns*this->classNb,BayesF32::OUT_PROBA_F32_ID,mgr);
67 
68             outputPredicts.create(this->nbPatterns,BayesF32::OUT_PREDICT_S16_ID,mgr);
69 
70             bayes.vectorDimension=this->vecDim;
71             bayes.numberOfClasses=this->classNb;
72             bayes.theta=this->theta;
73             bayes.sigma=this->sigma;
74             bayes.classPriors=this->classPrior;
75             bayes.epsilon=this->epsilon;
76 
77           break;
78 
79        }
80 
81 
82 
83     }
84 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)85     void BayesF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
86     {
87         (void)id;
88         outputProbas.dump(mgr);
89         outputPredicts.dump(mgr);
90     }
91