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