1 #include "SVMF32.h"
2 #include <stdio.h>
3 #include "Error.h"
4 
5 
test_svm_linear_predict_f32()6 void SVMF32::test_svm_linear_predict_f32()
7 {
8       int32_t result;
9 
10       arm_svm_linear_predict_f32(&this->linear,inp,&result);
11 
12 
13 }
14 
15 
test_svm_polynomial_predict_f32()16 void SVMF32::test_svm_polynomial_predict_f32()
17 {
18       int32_t result;
19 
20       arm_svm_polynomial_predict_f32(&this->poly,inp,&result);
21 
22 
23 }
24 
test_svm_rbf_predict_f32()25 void SVMF32::test_svm_rbf_predict_f32()
26 {
27       int32_t result;
28 
29       arm_svm_rbf_predict_f32(&this->rbf,inp,&result);
30 
31 
32 }
33 
test_svm_sigmoid_predict_f32()34 void SVMF32::test_svm_sigmoid_predict_f32()
35 {
36       int32_t result;
37 
38       arm_svm_sigmoid_predict_f32(&this->sigmoid,inp,&result);
39 
40 
41 }
42 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & testparams,Client::PatternMgr * mgr)43 void SVMF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& testparams,Client::PatternMgr *mgr)
44 {
45 
46       int kind;
47       int nbp,nbi;
48       const float32_t *paramsp;
49 
50       std::vector<Testing::param_t>::iterator it = testparams.begin();
51       this->vecDim = *it++;
52       this->nbSupportVectors = *it++;
53 
54       switch(id)
55       {
56           case SVMF32::TEST_SVM_LINEAR_PREDICT_F32_1:
57           {
58 
59              samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
60              params.reload(SVMF32::PARAMS_LINEAR_F32_ID,mgr);
61              dims.reload(SVMF32::DIMS_LINEAR_S16_ID,mgr);
62 
63              int16_t *dimsp=dims.ptr();
64 
65              nbi = dimsp[2*this->nbLinear];
66              nbp = dimsp[2*this->nbLinear + 1];
67 
68              paramsp = params.ptr() + nbp;
69 
70              inp=samples.ptr() + nbi;
71 
72              kind = SVMF32::LINEAR;
73 
74 
75           }
76           break;
77 
78           case SVMF32::TEST_SVM_POLYNOMIAL_PREDICT_F32_2:
79           {
80 
81              samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
82              params.reload(SVMF32::PARAMS_POLY_F32_ID,mgr);
83              dims.reload(SVMF32::DIMS_POLY_S16_ID,mgr);
84 
85              int16_t *dimsp=dims.ptr();
86 
87              nbi = dimsp[2*this->nbPoly];
88              nbp = dimsp[2*this->nbPoly + 1];
89 
90              paramsp = params.ptr() + nbp;
91 
92              inp=samples.ptr() + nbi;
93 
94              kind = SVMF32::POLY;
95           }
96           break;
97 
98           case SVMF32::TEST_SVM_RBF_PREDICT_F32_3:
99           {
100 
101              samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
102              params.reload(SVMF32::PARAMS_RBF_F32_ID,mgr);
103              dims.reload(SVMF32::DIMS_RBF_S16_ID,mgr);
104 
105              int16_t *dimsp=dims.ptr();
106 
107              nbi = dimsp[2*this->nbRBF];
108              nbp = dimsp[2*this->nbRBF + 1];
109 
110              paramsp = params.ptr() + nbp;
111 
112              inp=samples.ptr() + nbi;
113 
114              kind = SVMF32::RBF;
115           }
116           break;
117 
118           case SVMF32::TEST_SVM_SIGMOID_PREDICT_F32_4:
119           {
120              samples.reload(SVMF32::INPUT_F32_ID,mgr,this->vecDim);
121              params.reload(SVMF32::PARAMS_SIGMOID_F32_ID,mgr);
122              dims.reload(SVMF32::DIMS_SIGMOID_S16_ID,mgr);
123 
124              int16_t *dimsp=dims.ptr();
125 
126              nbi = dimsp[2*this->nbSigmoid];
127              nbp = dimsp[2*this->nbSigmoid + 1];
128 
129              paramsp = params.ptr() + nbp;
130 
131              inp=samples.ptr() + nbi;
132 
133              kind = SVMF32::SIGMOID;
134           }
135           break;
136 
137 
138       }
139 
140 
141 
142 
143       this->classes[0] = 0;
144       this->classes[1] = 1;
145       this->intercept=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors];
146       this->supportVectors=paramsp;
147       this->dualCoefs=paramsp + (this->vecDim*this->nbSupportVectors);
148 
149       switch(kind)
150       {
151 
152 
153          case SVMF32::POLY:
154              this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
155              this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
156              this->degree=(int)paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 3];
157 
158          break;
159 
160          case SVMF32::RBF:
161              this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1];
162          break;
163 
164          case SVMF32::SIGMOID:
165              this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
166              this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
167          break;
168       }
169 
170 
171        switch(id)
172        {
173           case SVMF32::TEST_SVM_LINEAR_PREDICT_F32_1:
174           {
175 
176              arm_svm_linear_init_f32(&linear,
177                  this->nbSupportVectors,
178                  this->vecDim,
179                  this->intercept,
180                  this->dualCoefs,
181                  this->supportVectors,
182                  this->classes);
183           }
184           break;
185 
186           case SVMF32::TEST_SVM_POLYNOMIAL_PREDICT_F32_2:
187           {
188 
189              arm_svm_polynomial_init_f32(&poly,
190                  this->nbSupportVectors,
191                  this->vecDim,
192                  this->intercept,
193                  this->dualCoefs,
194                  this->supportVectors,
195                  this->classes,
196                  this->degree,
197                  this->coef0,
198                  this->gamma
199                  );
200           }
201           break;
202 
203           case SVMF32::TEST_SVM_RBF_PREDICT_F32_3:
204           {
205 
206              arm_svm_rbf_init_f32(&rbf,
207                  this->nbSupportVectors,
208                  this->vecDim,
209                  this->intercept,
210                  this->dualCoefs,
211                  this->supportVectors,
212                  this->classes,
213                  this->gamma
214                  );
215           }
216           break;
217 
218           case SVMF32::TEST_SVM_SIGMOID_PREDICT_F32_4:
219           {
220 
221              arm_svm_sigmoid_init_f32(&sigmoid,
222                  this->nbSupportVectors,
223                  this->vecDim,
224                  this->intercept,
225                  this->dualCoefs,
226                  this->supportVectors,
227                  this->classes,
228                  this->coef0,
229                  this->gamma
230                  );
231           }
232           break;
233        }
234 
235 
236 
237 }
238 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)239 void SVMF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
240 {
241         switch(id)
242         {
243              case SVMF32::TEST_SVM_LINEAR_PREDICT_F32_1:
244               nbLinear++;
245              break;
246 
247              case SVMF32::TEST_SVM_POLYNOMIAL_PREDICT_F32_2:
248               nbPoly++;
249              break;
250 
251              case SVMF32::TEST_SVM_RBF_PREDICT_F32_3:
252               nbRBF++;
253              break;
254 
255              case SVMF32::TEST_SVM_SIGMOID_PREDICT_F32_4:
256               nbSigmoid++;
257              break;
258         }
259 }
260 
261 
262 
263