Mercurial > hg > ltpda
comparison m-toolbox/test/test_smodel_double.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % test_smodel_double tests the double method of the SMODEL class. | |
2 % | |
3 % M Hueller 02-05-2011 | |
4 % | |
5 % $Id: test_smodel_double.m,v 1.2 2011/05/05 21:04:13 mauro Exp $ | |
6 % | |
7 function results = test_smodel_double(varargin) | |
8 | |
9 %% List of runs | |
10 if nargin == 1 | |
11 list = varargin{1}; | |
12 if isa(list, 'cell') | |
13 list = list{:}; | |
14 end | |
15 else | |
16 list = []; | |
17 end | |
18 | |
19 if isempty(list) | |
20 list = [10 11 20 21 30 31 40 41 50 51]; | |
21 end | |
22 | |
23 %% Run tests | |
24 results = []; | |
25 | |
26 %% 10 Oscillator step, default values | |
27 test = 10; | |
28 if any(ismember(list, test)) | |
29 | |
30 % Pick the model | |
31 model_def = 'oscillator_step'; | |
32 | |
33 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
34 TOL = 0; | |
35 | |
36 % Set parameters: duration and rate | |
37 nsecs = 100; | |
38 fs = 1; | |
39 | |
40 % Extract the information from the ao model default plist | |
41 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
42 pl = ao_mdl_info.plists; | |
43 | |
44 F0 = find(pl, 'F0'); | |
45 toff = find(pl, 'toff'); | |
46 m = find(pl, 'm'); | |
47 k = find(pl, 'k'); | |
48 tau = find(pl, 'tau'); | |
49 x0 = find(pl, 'x0'); | |
50 v0 = find(pl, 'v0'); | |
51 | |
52 % Build the ao model | |
53 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
54 | |
55 % Build the smodel model | |
56 smodel_mdl = smodel(plist('built-in', model_def)); | |
57 | |
58 % Set smodel parameters | |
59 smodel_mdl.setParameters({'m','k','tau','F0','x0','v0','toff'}, {m,k,tau,F0,x0,v0,toff}); | |
60 | |
61 % Set smodel xvals | |
62 smodel_mdl.setXvals(ao_mdl.x); | |
63 | |
64 % Eval the smodel | |
65 d = smodel_mdl.double(); | |
66 | |
67 % Compare the numbers | |
68 results = [results; test check_correctness(d, ao_mdl.y, plist('tolerance', TOL))]; | |
69 end | |
70 | |
71 %% 11 Oscillator step, high fs and high nsecs | |
72 test = 11; | |
73 if any(ismember(list, test)) | |
74 | |
75 % Pick the model | |
76 model_def = 'oscillator_step'; | |
77 | |
78 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
79 TOL = 0; | |
80 | |
81 % Set parameters: duration and rate | |
82 nsecs = 10000; | |
83 fs = 1000; | |
84 | |
85 % Extract the information from the ao model default plist | |
86 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
87 pl = ao_mdl_info.plists; | |
88 | |
89 F0 = find(pl, 'F0'); | |
90 toff = find(pl, 'toff'); | |
91 m = find(pl, 'm'); | |
92 k = find(pl, 'k'); | |
93 tau = find(pl, 'tau'); | |
94 x0 = find(pl, 'x0'); | |
95 v0 = find(pl, 'v0'); | |
96 | |
97 % Build the ao model | |
98 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
99 | |
100 % Build the smodel model | |
101 smodel_mdl = smodel(plist('built-in', model_def)); | |
102 | |
103 % Set smodel parameters | |
104 smodel_mdl.setParameters({'m','k','tau','F0','x0','v0','toff'}, {m,k,tau,F0,x0,v0,toff}); | |
105 | |
106 % Set smodel xvals | |
107 smodel_mdl.setXvals(ao_mdl.x); | |
108 | |
109 % Eval the smodel | |
110 d = smodel_mdl.double(); | |
111 | |
112 % Compare the numbers | |
113 results = [results; test check_correctness(d, ao_mdl.y, plist('tolerance', TOL))]; | |
114 end | |
115 | |
116 %% 20 Oscillator sine, default values | |
117 test = 20; | |
118 if any(ismember(list, test)) | |
119 | |
120 % Pick the model | |
121 model_def = 'oscillator_sine'; | |
122 | |
123 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
124 TOL = 0e-13; | |
125 | |
126 % Set parameters: duration and rate | |
127 nsecs = 100; | |
128 fs = 1; | |
129 | |
130 % Extract the information from the ao model default plist | |
131 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
132 pl = ao_mdl_info.plists; | |
133 | |
134 F0 = find(pl, 'F0'); | |
135 toff = find(pl, 'toff'); | |
136 phi = find(pl, 'phi'); | |
137 phi = 0.0; | |
138 f = find(pl, 'f'); | |
139 m = find(pl, 'm'); | |
140 k = find(pl, 'k'); | |
141 tau = find(pl, 'tau'); | |
142 x0 = find(pl, 'x0'); | |
143 x0 = 0.0; | |
144 v0 = find(pl, 'v0'); | |
145 | |
146 % Build the ao model | |
147 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs, 'x0', x0, 'phi', phi)); | |
148 | |
149 % Build the smodel model | |
150 smodel_mdl = smodel(plist('built-in', model_def)); | |
151 | |
152 % Set smodel parameters | |
153 smodel_mdl.setParameters({'m','k','tau','F0','f','phi','x0','v0','toff'}, {m,k,tau,F0,f,phi,x0,v0,toff}); | |
154 | |
155 % Set smodel xvals | |
156 smodel_mdl.setXvals(ao_mdl.x); | |
157 | |
158 % Eval the smodel | |
159 d = smodel_mdl.double(); | |
160 | |
161 % Compare the numbers | |
162 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
163 end | |
164 | |
165 %% 21 Oscillator sine, high fs and high nsecs | |
166 test = 21; | |
167 if any(ismember(list, test)) | |
168 | |
169 % Pick the model | |
170 model_def = 'oscillator_sine'; | |
171 | |
172 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
173 TOL = 1e-12; | |
174 | |
175 % Set parameters: duration and rate | |
176 nsecs = 10000; | |
177 fs = 1000; | |
178 | |
179 % Extract the information from the ao model default plist | |
180 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
181 pl = ao_mdl_info.plists; | |
182 | |
183 F0 = find(pl, 'F0'); | |
184 toff = find(pl, 'toff'); | |
185 phi = find(pl, 'phi'); | |
186 f = find(pl, 'f'); | |
187 m = find(pl, 'm'); | |
188 k = find(pl, 'k'); | |
189 tau = find(pl, 'tau'); | |
190 x0 = find(pl, 'x0'); | |
191 v0 = find(pl, 'v0'); | |
192 | |
193 % Build the ao model | |
194 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
195 | |
196 % Build the smodel model | |
197 smodel_mdl = smodel(plist('built-in', model_def)); | |
198 | |
199 % Set smodel parameters | |
200 smodel_mdl.setParameters({'m','k','tau','F0','f','phi','x0','v0','toff'}, {m,k,tau,F0,f,phi,x0,v0,toff}); | |
201 | |
202 % Set smodel xvals | |
203 smodel_mdl.setXvals(ao_mdl.x); | |
204 | |
205 % Eval the smodel | |
206 d = smodel_mdl.double(); | |
207 | |
208 % Compare the numbers | |
209 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
210 end | |
211 | |
212 %% 30 Sinewave, default values | |
213 test = 30; | |
214 if any(ismember(list, test)) | |
215 | |
216 % Pick the model | |
217 model_def = 'sinewave'; | |
218 | |
219 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
220 TOL = 0; | |
221 | |
222 % Set parameters: duration and rate | |
223 nsecs = 100; | |
224 fs = 1; | |
225 | |
226 % Extract the information from the ao model default plist | |
227 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
228 pl = ao_mdl_info.plists; | |
229 | |
230 A = find(pl, 'A'); | |
231 phi = find(pl, 'phi'); | |
232 f = find(pl, 'f'); | |
233 | |
234 % Build the ao model | |
235 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
236 | |
237 % Build the smodel model | |
238 smodel_mdl = smodel(plist('built-in', model_def)); | |
239 | |
240 % Set smodel parameters | |
241 smodel_mdl.setParameters({'A','f','phi'}, {A,f,phi}); | |
242 | |
243 % Set smodel yunits | |
244 smodel_mdl.setYunits(ao_mdl.yunits); | |
245 | |
246 % Set smodel xvals | |
247 smodel_mdl.setXvals(ao_mdl.x); | |
248 | |
249 % Eval the smodel | |
250 d = smodel_mdl.double(); | |
251 | |
252 % Compare the numbers | |
253 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
254 end | |
255 | |
256 %% 31 Sinewave, high fs and high nsecs | |
257 test = 31; | |
258 if any(ismember(list, test)) | |
259 | |
260 % Pick the model | |
261 model_def = 'sinewave'; | |
262 | |
263 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
264 TOL = 0; | |
265 | |
266 % Set parameters: duration and rate | |
267 nsecs = 10000; | |
268 fs = 1000; | |
269 | |
270 % Extract the information from the ao model default plist | |
271 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
272 pl = ao_mdl_info.plists; | |
273 | |
274 A = find(pl, 'A'); | |
275 phi = find(pl, 'phi'); | |
276 f = find(pl, 'f'); | |
277 | |
278 % Build the ao model | |
279 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
280 | |
281 % Build the smodel model | |
282 smodel_mdl = smodel(plist('built-in', model_def)); | |
283 | |
284 % Set smodel parameters | |
285 smodel_mdl.setParameters({'A','f','phi'}, {A,f,phi}); | |
286 | |
287 % Set smodel yunits | |
288 smodel_mdl.setYunits(ao_mdl.yunits); | |
289 | |
290 % Set smodel xvals | |
291 smodel_mdl.setXvals(ao_mdl.x); | |
292 | |
293 % Eval the smodel | |
294 d = smodel_mdl.double(); | |
295 | |
296 % Compare the numbers | |
297 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
298 end | |
299 | |
300 %% 40 Squarewave, default values | |
301 test = 40; | |
302 if any(ismember(list, test)) | |
303 | |
304 % Pick the model | |
305 model_def = 'squarewave'; | |
306 | |
307 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
308 TOL = 0; | |
309 | |
310 % Set parameters: duration and rate | |
311 nsecs = 100; | |
312 fs = 1; | |
313 | |
314 % Extract the information from the ao model default plist | |
315 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
316 pl = ao_mdl_info.plists; | |
317 | |
318 phi = find(pl, 'phi'); | |
319 f = find(pl, 'f'); | |
320 | |
321 % Build the ao model | |
322 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
323 | |
324 % Build the smodel model | |
325 smodel_mdl = smodel(plist('built-in', model_def)); | |
326 | |
327 % Set smodel parameters | |
328 smodel_mdl.setParameters({'f','phi'}, {f,phi}); | |
329 | |
330 % Set smodel yunits | |
331 smodel_mdl.setYunits(ao_mdl.yunits); | |
332 | |
333 % Set smodel xvals | |
334 smodel_mdl.setXvals(ao_mdl.x); | |
335 | |
336 % Eval the smodel | |
337 d = smodel_mdl.double(); | |
338 | |
339 % Compare the numbers | |
340 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
341 end | |
342 | |
343 %% 41 Squarewave, high fs and high nsecs | |
344 test = 41; | |
345 if any(ismember(list, test)) | |
346 | |
347 % Pick the model | |
348 model_def = 'squarewave'; | |
349 | |
350 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
351 TOL = 0; | |
352 | |
353 % Set parameters: duration and rate | |
354 nsecs = 10000; | |
355 fs = 1000; | |
356 | |
357 % Extract the information from the ao model default plist | |
358 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
359 pl = ao_mdl_info.plists; | |
360 | |
361 phi = find(pl, 'phi'); | |
362 f = find(pl, 'f'); | |
363 | |
364 % Build the ao model | |
365 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
366 | |
367 % Build the smodel model | |
368 smodel_mdl = smodel(plist('built-in', model_def)); | |
369 | |
370 % Set smodel parameters | |
371 smodel_mdl.setParameters({'f','phi'}, {f,phi}); | |
372 | |
373 % Set smodel yunits | |
374 smodel_mdl.setYunits(ao_mdl.yunits); | |
375 | |
376 % Set smodel xvals | |
377 smodel_mdl.setXvals(ao_mdl.x); | |
378 | |
379 % Eval the smodel | |
380 d = smodel_mdl.double(); | |
381 | |
382 % Compare the numbers | |
383 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
384 end | |
385 | |
386 %% 50 Step, default values | |
387 test = 50; | |
388 if any(ismember(list, test)) | |
389 | |
390 % Pick the model | |
391 model_def = 'step'; | |
392 | |
393 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
394 TOL = 0; | |
395 | |
396 % Set parameters: duration and rate | |
397 nsecs = 100; | |
398 fs = 1; | |
399 | |
400 % Extract the information from the ao model default plist | |
401 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
402 pl = ao_mdl_info.plists; | |
403 | |
404 A = find(pl, 'A'); | |
405 toff = find(pl, 'toff'); | |
406 | |
407 % Build the ao model | |
408 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
409 | |
410 % Build the smodel model | |
411 smodel_mdl = smodel(plist('built-in', model_def)); | |
412 | |
413 % Set smodel parameters | |
414 smodel_mdl.setParameters({'A','toff'}, {A,toff}); | |
415 | |
416 % Set smodel yunits | |
417 smodel_mdl.setYunits(ao_mdl.yunits); | |
418 | |
419 % Set smodel xvals | |
420 smodel_mdl.setXvals(ao_mdl.x); | |
421 | |
422 % Eval the smodel | |
423 d = smodel_mdl.double(); | |
424 | |
425 % Compare the numbers | |
426 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
427 end | |
428 | |
429 %% 51 Step, high fs and high nsecs | |
430 test = 51; | |
431 if any(ismember(list, test)) | |
432 | |
433 % Pick the model | |
434 model_def = 'step'; | |
435 | |
436 % Decide the tolerance of the test ([] or 0 for no tolerance) | |
437 TOL = 0; | |
438 | |
439 % Set parameters: duration and rate | |
440 nsecs = 10000; | |
441 fs = 1000; | |
442 | |
443 % Extract the information from the ao model default plist | |
444 ao_mdl_info = eval(['ao_model_' model_def '(''info'')']); | |
445 pl = ao_mdl_info.plists; | |
446 | |
447 A = find(pl, 'A'); | |
448 toff = find(pl, 'toff'); | |
449 | |
450 % Build the ao model | |
451 ao_mdl = ao(plist('built-in', model_def, 'nsecs', nsecs, 'fs', fs)); | |
452 | |
453 % Build the smodel model | |
454 smodel_mdl = smodel(plist('built-in', model_def)); | |
455 | |
456 % Set smodel parameters | |
457 smodel_mdl.setParameters({'A','toff'}, {A,toff}); | |
458 | |
459 % Set smodel yunits | |
460 smodel_mdl.setYunits(ao_mdl.yunits); | |
461 | |
462 % Set smodel xvals | |
463 smodel_mdl.setXvals(ao_mdl.x); | |
464 | |
465 % Eval the smodel | |
466 d = smodel_mdl.double(); | |
467 | |
468 % Compare the numbers | |
469 results = [results; test check_correctness(d, ao_mdl.y, plist('tol', TOL))]; | |
470 end | |
471 | |
472 end | |
473 | |
474 function atest = check_correctness(smodel_y, ao_y, pl) | |
475 | |
476 % Exceptions plist for ao/eq | |
477 ple = plist('Exceptions', ... | |
478 {'created', 'proctime', 'UUID', 'param/desc', 'name', 'methodInvars', 'version'}); | |
479 | |
480 % Start testing | |
481 atest = true; | |
482 | |
483 % Strict check or with tolerance? | |
484 tol = mfind(pl, 'tolerance', 'tol'); | |
485 if ~isempty(tol) && tol > 0 | |
486 % Check within tolerance | |
487 if any(abs(smodel_y - ao_y) ./ max(abs(smodel_y)) >= tol) | |
488 atest = false; | |
489 end | |
490 else | |
491 % Strict check on the values | |
492 if ~isequal(smodel_y, ao_y) | |
493 atest = false; | |
494 end | |
495 end | |
496 | |
497 end |