1 #include "BayesF16.h"
2 #include <stdio.h>
3 #include "Error.h"
4 #include "Test.h"
5 
6 #define REL_ERROR ((float16_t)3e-3)
7 
test_gaussian_naive_bayes_predict_f16()8     void BayesF16::test_gaussian_naive_bayes_predict_f16()
9     {
10        const float16_t *inp = input.ptr();
11 
12        float16_t *bufp = outputProbas.ptr();
13        float16_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_f16(&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,REL_ERROR);
29         ASSERT_EQ(outputPredicts,predicts);
30     }
31 
32 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)33     void BayesF16::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 BayesF16::TEST_GAUSSIAN_NAIVE_BAYES_PREDICT_F16_1:
42 
43 
44             input.reload(BayesF16::INPUTS1_F16_ID,mgr);
45             params.reload(BayesF16::PARAMS1_F16_ID,mgr);
46             dims.reload(BayesF16::DIMS1_S16_ID,mgr);
47 
48             const int16_t *dimsp=dims.ptr();
49             const float16_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(BayesF16::PROBAS1_F16_ID,mgr);
63             predicts.reload(BayesF16::PREDICTS1_S16_ID,mgr);
64 
65             outputProbas.create(this->nbPatterns*this->classNb,BayesF16::OUT_PROBA_F16_ID,mgr);
66             temp.create(this->nbPatterns*this->classNb,BayesF16::OUT_PROBA_F16_ID,mgr);
67             outputPredicts.create(this->nbPatterns,BayesF16::OUT_PREDICT_S16_ID,mgr);
68 
69             bayes.vectorDimension=this->vecDim;
70             bayes.numberOfClasses=this->classNb;
71             bayes.theta=this->theta;
72             bayes.sigma=this->sigma;
73             bayes.classPriors=this->classPrior;
74             bayes.epsilon=this->epsilon;
75 
76           break;
77 
78        }
79 
80 
81 
82     }
83 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)84     void BayesF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
85     {
86         (void)id;
87         outputProbas.dump(mgr);
88         outputPredicts.dump(mgr);
89     }
90