Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_zDomainFit.m @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_AO_ZDOMAINFIT a set of UTPs for the ao/zDomainFit method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_zDomainFit.m,v 1.8 2010/01/27 18:10:25 luigi Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The zDomainFit method of the ao class fit a model (miir filter) to | |
11 % fsdata. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_zDomainFit(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'zDomainFit'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test AOs | |
30 % [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao; | |
31 | |
32 % Exception list for the UTPs: | |
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
34 | |
35 % Build test objects | |
36 pl_data1 = plist('fsfcn', '0.01./(0.01+f)', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
37 a1 = ao(pl_data1); | |
38 | |
39 pl_data2 = plist('fsfcn', '0.001./(0.1+f)', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
40 a2 = ao(pl_data2); | |
41 | |
42 pl_data3 = plist('fsfcn', '(1e-3./(f).^2 + 1e3./(0.001+f)).*1e-9', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
43 a3 = ao(pl_data3); | |
44 | |
45 pl_data4 = plist('fsfcn', '(1e-4./(f).^2 + 1e3./(0.01+f)).*1e-10', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
46 a4 = ao(pl_data4); | |
47 | |
48 pl_data5 = plist('fsfcn', '(1e5.*f.^2 + 1e3./(0.01+f)).*1e-8', 'f1', 1e-6, 'f2', 5, 'nf', 100); | |
49 a5 = ao(pl_data5); | |
50 | |
51 a1.setName; | |
52 a2.setName; | |
53 a3.setName; | |
54 a4.setName; | |
55 a5.setName; | |
56 | |
57 av = [a1 a2 a3]; | |
58 am = [a1 a2; a3 a4]; | |
59 | |
60 % ----- Building a simple test model | |
61 f = logspace(-6,log10(5),30); | |
62 fs = 10; | |
63 res = [0.7 0.2+0.01i 0.2-0.01i]; | |
64 poles = [0.5 0.1+0.07i 0.1-0.07i]; | |
65 tmod(3,1) = miir; | |
66 for ii = 1:3 | |
67 tmod(ii,1) = miir(res(ii),[1 -poles(ii)],fs); | |
68 end | |
69 rtmod = resp(tmod,plist('bank','parallel','f',f.')); | |
70 | |
71 % ----- Buildin a standard plist | |
72 fs = 10; | |
73 tol = 1e-3; | |
74 plstd = plist('FS',fs,... | |
75 'AutoSearch','on',... | |
76 'StartPoles',[],... | |
77 'StartPolesOpt','clin',... | |
78 'maxiter',60,... | |
79 'minorder',3,... | |
80 'maxorder',45,... | |
81 'weights',[],... | |
82 'weightparam','abs',... | |
83 'CONDTYPE','MSE',... | |
84 'FITTOL',1e-3,... | |
85 'MSEVARTOL',1e-2,... | |
86 'Plot','off',... | |
87 'ForceStability','off',... | |
88 'CheckProgress','off'); | |
89 | |
90 % Run the tests | |
91 results = [results utp_01]; % getInfo call | |
92 results = [results utp_02]; % Vector input | |
93 results = [results utp_03]; % Matrix input | |
94 results = [results utp_04]; % List input | |
95 results = [results utp_05]; % Test with mixed input | |
96 results = [results utp_06]; % Test history is working | |
97 results = [results utp_07]; % Test the modify call does not work | |
98 % results = [results utp_08]; % Test input data shape == output data | |
99 % shape does not apply | |
100 results = [results utp_09]; % Test output of the data | |
101 results = [results utp_10]; % Test the fit give the correct coefficients | |
102 | |
103 disp('Done.'); | |
104 disp('******************************************************'); | |
105 | |
106 elseif nargin == 1 % Check for UTP functions | |
107 if strcmp(varargin{1}, 'isutp') | |
108 results = 1; | |
109 else | |
110 results = 0; | |
111 end | |
112 else | |
113 error('### Incorrect inputs') | |
114 end | |
115 | |
116 %% UTP_01 | |
117 | |
118 % <TestDescription> | |
119 % | |
120 % Tests that the getInfo call works for this method. | |
121 % | |
122 % </TestDescription> | |
123 function result = utp_01 | |
124 | |
125 | |
126 % <SyntaxDescription> | |
127 % | |
128 % Test that the getInfo call works for no sets, all sets, and each set | |
129 % individually. | |
130 % | |
131 % </SyntaxDescription> | |
132 | |
133 try | |
134 % <SyntaxCode> | |
135 % Call for no sets | |
136 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
137 % Call for all sets | |
138 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
139 % Call for each set | |
140 for kk=1:numel(io(2).sets) | |
141 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
142 end | |
143 % </SyntaxCode> | |
144 stest = true; | |
145 catch err | |
146 disp(err.message) | |
147 stest = false; | |
148 end | |
149 | |
150 % <AlgoDescription> | |
151 % | |
152 % 1) Check that getInfo call returned an minfo object in all cases. | |
153 % 2) Check that all plists have the correct parameters. | |
154 % | |
155 % </AlgoDescription> | |
156 | |
157 atest = true; | |
158 if stest | |
159 % <AlgoCode> | |
160 % check we have minfo objects | |
161 if isa(io, 'minfo') | |
162 %%% SET 'None' | |
163 if ~isempty(io(1).sets), atest = false; end | |
164 if ~isempty(io(1).plists), atest = false; end | |
165 %%% Check all Sets | |
166 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
167 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
168 %%%%%%%%%% SET 'Default' | |
169 if io(3).plists.nparams ~= 14, atest = false; end | |
170 % Check key | |
171 if ~io(3).plists.isparam('autosearch'), atest = false; end | |
172 if ~io(3).plists.isparam('startpoles'), atest = false; end | |
173 if ~io(3).plists.isparam('startpolesopt'), atest = false; end | |
174 if ~io(3).plists.isparam('maxiter'), atest = false; end | |
175 if ~io(3).plists.isparam('minorder'), atest = false; end | |
176 if ~io(3).plists.isparam('maxorder'), atest = false; end | |
177 if ~io(3).plists.isparam('weights'), atest = false; end | |
178 if ~io(3).plists.isparam('weightparam'), atest = false; end | |
179 if ~io(3).plists.isparam('condtype'), atest = false; end | |
180 if ~io(3).plists.isparam('fittol'), atest = false; end | |
181 if ~io(3).plists.isparam('msevartol'), atest = false; end | |
182 if ~io(3).plists.isparam('plot'), atest = false; end | |
183 if ~io(3).plists.isparam('forcestability'), atest = false; end | |
184 if ~io(3).plists.isparam('checkprogress'), atest = false; end | |
185 % Check default value | |
186 if ~isequal(io(3).plists.find('autosearch'), 'on'), atest = false; end | |
187 if ~isEmptyDouble(io(3).plists.find('startpoles')), atest = false; end | |
188 if ~isequal(io(3).plists.find('startpolesopt'), 'clog'), atest = false; end | |
189 if ~isequal(io(3).plists.find('maxiter'), 50), atest = false; end | |
190 if ~isequal(io(3).plists.find('minorder'), 2), atest = false; end | |
191 if ~isequal(io(3).plists.find('maxorder'), 20), atest = false; end | |
192 if ~isEmptyDouble(io(3).plists.find('weights')), atest = false; end | |
193 if ~isequal(io(3).plists.find('weightparam'), 'abs'), atest = false; end | |
194 if ~isequal(io(3).plists.find('condtype'), 'MSE'), atest = false; end | |
195 if ~isequal(io(3).plists.find('fittol'), .001), atest = false; end | |
196 if ~isequal(io(3).plists.find('msevartol'), .01), atest = false; end | |
197 if ~isequal(io(3).plists.find('plot'), 'off'), atest = false; end | |
198 if ~isequal(io(3).plists.find('forcestability'), 'off'), atest = false; end | |
199 if ~isequal(io(3).plists.find('checkprogress'), 'off'), atest = false; end | |
200 % Check options | |
201 if ~isequal(io(3).plists.getOptionsForParam('autosearch'), {'on', 'off'}), atest = false; end | |
202 if ~isequal(io(3).plists.getOptionsForParam('startpoles'), {[]}), atest = false; end | |
203 if ~isequal(io(3).plists.getOptionsForParam('startpolesopt'), {'real', 'clog', 'clin'}), atest = false; end | |
204 if ~isequal(io(3).plists.getOptionsForParam('maxiter'), {50}), atest = false; end | |
205 if ~isequal(io(3).plists.getOptionsForParam('minorder'), {2}), atest = false; end | |
206 if ~isequal(io(3).plists.getOptionsForParam('maxorder'), {20}), atest = false; end | |
207 if ~isequal(io(3).plists.getOptionsForParam('weights'), {[]}), atest = false; end | |
208 if ~isequal(io(3).plists.getOptionsForParam('weightparam'), {'ones', 'abs', 'sqrt'}), atest = false; end | |
209 if ~isequal(io(3).plists.getOptionsForParam('condtype'), {'MSE', 'RLD', 'RSF'}), atest = false; end | |
210 if ~isequal(io(3).plists.getOptionsForParam('fittol'), {.001}), atest = false; end | |
211 if ~isequal(io(3).plists.getOptionsForParam('msevartol'), {.01}), atest = false; end | |
212 if ~isequal(io(3).plists.getOptionsForParam('plot'), {'on', 'off'}), atest = false; end | |
213 if ~isequal(io(3).plists.getOptionsForParam('forcestability'), {'on', 'off'}), atest = false; end | |
214 if ~isequal(io(3).plists.getOptionsForParam('checkprogress'), {'on', 'off'}), atest = false; end | |
215 end | |
216 % </AlgoCode> | |
217 else | |
218 atest = false; | |
219 end | |
220 | |
221 % Return a result structure | |
222 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
223 end % END UTP_01 | |
224 | |
225 %% UTP_02 | |
226 | |
227 % <TestDescription> | |
228 % | |
229 % Tests that the zDomainFit method works with a vector of AOs as input. | |
230 % | |
231 % </TestDescription> | |
232 function result = utp_02 | |
233 | |
234 % <SyntaxDescription> | |
235 % | |
236 % Test that the zDomainFit method works for a vector of AOs as input. | |
237 % | |
238 % </SyntaxDescription> | |
239 | |
240 try | |
241 % <SyntaxCode> | |
242 | |
243 out = zDomainFit(av, plstd); | |
244 % </SyntaxCode> | |
245 stest = true; | |
246 catch err | |
247 disp(err.message) | |
248 stest = false; | |
249 end | |
250 | |
251 % <AlgoDescription> | |
252 % | |
253 % 1) Check that the number of elements in 'out' is the same as in 'av' | |
254 % 2) Check that each output AO contains the correct data. | |
255 % | |
256 % </AlgoDescription> | |
257 | |
258 atest = true; | |
259 if stest | |
260 % <AlgoCode> | |
261 % Check we have the correct number of outputs | |
262 if ~isequal(numel(out.objs), numel(av)), atest = false; end | |
263 % Check each output against the absolute value of the input | |
264 for kk=1:numel(out.objs) | |
265 % Check the fitted ao(fsdata) objects | |
266 if isa(av(kk).data, 'fsdata') | |
267 % check that the output data responses are accurate to the | |
268 % prescribed accuracy | |
269 mse = out.objs(kk).procinfo.find('FIT_MSE'); | |
270 if mse.y>tol, atest = false; end | |
271 else | |
272 % Check the other objects (they must be empty) | |
273 if ~isempty([out.objs(kk).filters.a]), atest = false; end | |
274 if ~isempty([out.objs(kk).filters.b]), atest = false; end | |
275 end | |
276 end | |
277 % </AlgoCode> | |
278 else | |
279 atest = false; | |
280 end | |
281 | |
282 % Return a result structure | |
283 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
284 end % END UTP_02 | |
285 | |
286 %% UTP_03 | |
287 | |
288 % <TestDescription> | |
289 % | |
290 % Tests that the zDomainFit method works with a matrix of AOs as input. | |
291 % | |
292 % </TestDescription> | |
293 function result = utp_03 | |
294 | |
295 % <SyntaxDescription> | |
296 % | |
297 % Test that the zDomainFit method works for a matrix of AOs as input. | |
298 % | |
299 % </SyntaxDescription> | |
300 | |
301 try | |
302 % <SyntaxCode> | |
303 out = zDomainFit(am, plstd); | |
304 % </SyntaxCode> | |
305 stest = true; | |
306 catch err | |
307 disp(err.message) | |
308 stest = false; | |
309 end | |
310 | |
311 % <AlgoDescription> | |
312 % | |
313 % 1) Check that the number of elements in 'out' is the same as in 'am' | |
314 % 2) Check that each output AO contains the correct data. | |
315 % | |
316 % </AlgoDescription> | |
317 | |
318 atest = true; | |
319 if stest | |
320 % <AlgoCode> | |
321 % Check we have the correct number of outputs | |
322 if ~isequal(numel(out.objs), numel(am)), atest = false; end | |
323 % Check each output against the absolute value of the input | |
324 for kk=1:numel(out.objs) | |
325 % Check the fitted ao(fsdata) objects | |
326 if isa(am(kk).data, 'fsdata') | |
327 % check that the output data responses are accurate to the | |
328 % prescribed accuracy | |
329 mse = out.objs(kk).procinfo.find('FIT_MSE'); | |
330 if mse(end)>tol, atest = false; end | |
331 else | |
332 % Check the other objects (they must be empty) | |
333 if ~isempty([out.objs(kk).filters.a]), atest = false; end | |
334 if ~isempty([out.objs(kk).filters.b]), atest = false; end | |
335 end | |
336 end | |
337 % </AlgoCode> | |
338 else | |
339 atest = false; | |
340 end | |
341 | |
342 % Return a result structure | |
343 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
344 end % END UTP_03 | |
345 | |
346 %% UTP_04 | |
347 | |
348 % <TestDescription> | |
349 % | |
350 % Tests that the zDomainFit method works with a list of AOs as input. | |
351 % | |
352 % </TestDescription> | |
353 function result = utp_04 | |
354 | |
355 % <SyntaxDescription> | |
356 % | |
357 % Test that the zDomainFit method works for a list of AOs as input. | |
358 % | |
359 % </SyntaxDescription> | |
360 | |
361 try | |
362 % <SyntaxCode> | |
363 out = zDomainFit(a1,a2,a3, plstd); | |
364 % </SyntaxCode> | |
365 stest = true; | |
366 catch err | |
367 disp(err.message) | |
368 stest = false; | |
369 end | |
370 | |
371 % <AlgoDescription> | |
372 % | |
373 % 1) Check that the number of elements in 'out' is the same as in | |
374 % input. | |
375 % 2) Check that each output AO contains the correct data. | |
376 % | |
377 % </AlgoDescription> | |
378 | |
379 atest = true; | |
380 aoin = [a1,a2,a3]; | |
381 if stest | |
382 % <AlgoCode> | |
383 % Check we have the correct number of outputs | |
384 if ~isequal(numel(out.objs), numel(aoin)), atest = false; end | |
385 % Check each output against the absolute value of the input | |
386 for kk=1:numel(out.objs) | |
387 % Check the fitted ao(fsdata) objects | |
388 if isa(aoin(kk).data, 'fsdata') | |
389 % check that the output data responses are accurate to the | |
390 % prescribed accuracy | |
391 mse = out.objs(kk).procinfo.find('FIT_MSE'); | |
392 if mse(end)>tol, atest = false; end | |
393 else | |
394 % Check the other objects (they must be empty) | |
395 if ~isempty([out.objs(kk).filters.a]), atest = false; end | |
396 if ~isempty([out.objs(kk).filters.b]), atest = false; end | |
397 end | |
398 end | |
399 % </AlgoCode> | |
400 else | |
401 atest = false; | |
402 end | |
403 | |
404 % Return a result structure | |
405 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
406 end % END UTP_04 | |
407 | |
408 %% UTP_05 | |
409 | |
410 % <TestDescription> | |
411 % | |
412 % Tests that the zDomainFit method works with a mix of different shaped AOs as | |
413 % input. | |
414 % | |
415 % </TestDescription> | |
416 function result = utp_05 | |
417 | |
418 % <SyntaxDescription> | |
419 % | |
420 % Test that the zDomainFit method works with an input of matrices and vectors | |
421 % and single AOs. | |
422 % | |
423 % </SyntaxDescription> | |
424 | |
425 try | |
426 % <SyntaxCode> | |
427 out = zDomainFit(a5,[a1 a2;a3 a4],plstd); | |
428 % </SyntaxCode> | |
429 stest = true; | |
430 catch err | |
431 disp(err.message) | |
432 stest = false; | |
433 end | |
434 | |
435 % <AlgoDescription> | |
436 % | |
437 % 1) Check that the number of elements in 'out' is the same as in | |
438 % input. | |
439 % 2) Check that each output AO contains the correct data. | |
440 % | |
441 % </AlgoDescription> | |
442 | |
443 atest = true; | |
444 aoin = [a5,reshape([a1 a2;a3 a4],1,[])]; | |
445 if stest | |
446 % <AlgoCode> | |
447 % Check we have the correct number of outputs | |
448 if ~isequal(numel(out.objs), numel(aoin)), atest = false; end | |
449 % Check each output against the absolute value of the input | |
450 for kk=1:numel(out.objs) | |
451 % Check the fitted ao(fsdata) objects | |
452 if isa(aoin(kk).data, 'fsdata') | |
453 % check that the output data responses are accurate to the | |
454 % prescribed accuracy | |
455 mse = out.objs(kk).procinfo.find('FIT_MSE'); | |
456 if mse(end)>tol, atest = false; end | |
457 else | |
458 % Check the other objects (they must be empty) | |
459 if ~isempty([out.objs(kk).filters.a]), atest = false; end | |
460 if ~isempty([out.objs(kk).filters.b]), atest = false; end | |
461 end | |
462 end | |
463 % </AlgoCode> | |
464 else | |
465 atest = false; | |
466 end | |
467 | |
468 % Return a result structure | |
469 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
470 end % END UTP_05 | |
471 | |
472 %% UTP_06 | |
473 | |
474 % <TestDescription> | |
475 % | |
476 % Tests that the zDomainFit method properly applies history. | |
477 % | |
478 % </TestDescription> | |
479 function result = utp_06 | |
480 | |
481 % <SyntaxDescription> | |
482 % | |
483 % Test that the result of applying the zDomainFit method can be processed back. | |
484 % | |
485 % </SyntaxDescription> | |
486 | |
487 try | |
488 % <SyntaxCode> | |
489 out = zDomainFit(a1,plstd); | |
490 mout = rebuild(out); | |
491 % </SyntaxCode> | |
492 stest = true; | |
493 catch err | |
494 disp(err.message) | |
495 stest = false; | |
496 end | |
497 | |
498 % <AlgoDescription> | |
499 % | |
500 % 1) Check that the last entry in the history of 'out' corresponds to | |
501 % 'zDomainFit'. | |
502 % 2) Check that the re-built object is the same object as the input. | |
503 % | |
504 % </AlgoDescription> | |
505 | |
506 atest = true; | |
507 if stest | |
508 % <AlgoCode> | |
509 % Check the last step in the history of 'out' | |
510 if ~strcmp(out.hist.methodInfo.mname, 'zDomainFit'), atest = false; end | |
511 % Check the re-built object | |
512 if ~eq(mout, out, ple2), atest = false; end | |
513 % </AlgoCode> | |
514 else | |
515 atest = false; | |
516 end | |
517 | |
518 % Return a result structure | |
519 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
520 end % END UTP_06 | |
521 | |
522 %% UTP_07 | |
523 | |
524 % <TestDescription> | |
525 % | |
526 % zDomainFit cannot modify the input AO. | |
527 % | |
528 % </TestDescription> | |
529 function result = utp_07 | |
530 | |
531 % <SyntaxDescription> | |
532 % | |
533 % Test that the sDomainFit method can modify the input AO by calling with no | |
534 % output and that the method doesn't change the input of the function | |
535 % notation (with a equal sign). | |
536 % | |
537 % </SyntaxDescription> | |
538 | |
539 try | |
540 % <SyntaxCode> | |
541 % copy a3 to work with | |
542 amodi = ao(a3); | |
543 aeq = ao(a3); | |
544 amodi.zDomainFit(plstd); | |
545 out = aeq.zDomainFit(plstd); | |
546 % </SyntaxCode> | |
547 stest = false; | |
548 catch err | |
549 disp(err.message) | |
550 stest = true; | |
551 end | |
552 | |
553 % <AlgoDescription> | |
554 % | |
555 % 1) Nothing to do. | |
556 % | |
557 % </AlgoDescription> | |
558 | |
559 atest = true; | |
560 if stest | |
561 % <AlgoCode> | |
562 % </AlgoCode> | |
563 else | |
564 atest = false; | |
565 end | |
566 | |
567 % Return a result structure | |
568 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
569 end % END UTP_07 | |
570 | |
571 % %% UTP_08 | |
572 % | |
573 % % <TestDescription> | |
574 % % | |
575 % % Test the shape of the output. - Does not make sense for zDomainFit | |
576 % % becauses the output are miir filters | |
577 % % | |
578 % % </TestDescription> | |
579 % function result = utp_08 | |
580 % | |
581 % % <SyntaxDescription> | |
582 % % | |
583 % % Test that the zDomainFit method keeps the data shape of the input object. The | |
584 % % input AO must be an AO with row data and an AO with column data. | |
585 % % | |
586 % % </SyntaxDescription> | |
587 % | |
588 % try | |
589 % % <SyntaxCode> | |
590 % out1 = zDomainFit(a2,plstd); | |
591 % out2 = zDomainFit(a1,plstd); | |
592 % % </SyntaxCode> | |
593 % stest = true; | |
594 % catch err | |
595 % disp(err.message) | |
596 % stest = false; | |
597 % end | |
598 % | |
599 % % <AlgoDescription> | |
600 % % | |
601 % % 1) Check that the shape of the data doesn't change. | |
602 % % | |
603 % % </AlgoDescription> | |
604 % | |
605 % atest = true; | |
606 % if stest | |
607 % % <AlgoCode> | |
608 % % Check the shape of the output data | |
609 % if size(out1.data.x) ~= size(at5.data.x), atest = false; end | |
610 % if size(out1.data.y) ~= size(at5.data.y), atest = false; end | |
611 % if size(out2.data.x) ~= size(at6.data.x), atest = false; end | |
612 % if size(out2.data.y) ~= size(at6.data.y), atest = false; end | |
613 % % </AlgoCode> | |
614 % else | |
615 % atest = false; | |
616 % end | |
617 % | |
618 % % Return a result structure | |
619 % result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
620 % end % END UTP_08 | |
621 | |
622 %% UTP_09 | |
623 | |
624 % <TestDescription> | |
625 % | |
626 % Check that the zDomainFit method pass back the output objects to a | |
627 % single variable correctly. | |
628 % | |
629 % </TestDescription> | |
630 function result = utp_09 | |
631 | |
632 % <SyntaxDescription> | |
633 % | |
634 % Call the method with a list of output variables and with a single output | |
635 % variable. Additionaly check that the rebuild method works on the output. | |
636 % | |
637 % </SyntaxDescription> | |
638 | |
639 try | |
640 % <SyntaxCode> | |
641 % [o1, o2] = zDomainFit(a1, a2, plstd); | |
642 o3 = zDomainFit(a1, a2, plstd); | |
643 % mout1 = rebuild(o1); | |
644 % mout2 = rebuild(o2); | |
645 mout3 = rebuild(o3); | |
646 % o31 = o3(1:size(o3,1),1); | |
647 % o32 = o3(1:size(o3,1),2); | |
648 % mout31 = rebuild(o31); | |
649 % mout32 = rebuild(o32); | |
650 % </SyntaxCode> | |
651 stest = true; | |
652 catch err | |
653 disp(err.message) | |
654 stest = false; | |
655 end | |
656 | |
657 % <AlgoDescription> | |
658 % | |
659 % 1) Check that the output contains the right number of objects | |
660 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
661 % | |
662 % </AlgoDescription> | |
663 | |
664 atest = true; | |
665 if stest | |
666 % <AlgoCode> | |
667 % Check the number of outputs | |
668 % if numel(o1) ~=1, atest = false; end | |
669 % if numel(o2) ~=1, atest = false; end | |
670 % if numel(o3) ~=2, atest = false; end | |
671 % Check the rebuilding of the object | |
672 % if ~eq(o1, mout1, ple2), atest = false; end | |
673 % if ~eq(o2, mout2, ple2), atest = false; end | |
674 % if ~eq(o3(1), mout3(1), ple2), atest = false; end | |
675 % if ~eq(o3(2), mout3(2), ple2), atest = false; end | |
676 % if ~eq(o3(:,1), mout3(:,1), ple2), atest = false; end | |
677 % if ~eq(o3(:,2), mout3(:,2), ple2), atest = false; end | |
678 if ~eq(o3, mout3, ple2), atest = false; end | |
679 % </AlgoCode> | |
680 else | |
681 atest = false; | |
682 end | |
683 | |
684 % Return a result structure | |
685 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
686 end % END UTP_09 | |
687 | |
688 %% UTP_10 | |
689 | |
690 % <TestDescription> | |
691 % | |
692 % Tests that the zDomainFit method return the correct coefficients | |
693 % | |
694 % </TestDescription> | |
695 function result = utp_10 | |
696 | |
697 % <SyntaxDescription> | |
698 % | |
699 % Test that the zDomainFit method works with an input of matrices and vectors | |
700 % and single AOs. | |
701 % | |
702 % </SyntaxDescription> | |
703 | |
704 try | |
705 % <SyntaxCode> | |
706 fs = 10; | |
707 tol = 0.5; | |
708 plstd2 = plist('FS',fs,... | |
709 'AutoSearch','off',... | |
710 'StartPoles',[],... | |
711 'StartPolesOpt','clin',... | |
712 'maxiter',60,... | |
713 'minorder',3,... | |
714 'maxorder',3,... | |
715 'weights',[],... | |
716 'weightparam','abs',... | |
717 'CONDTYPE','MSE',... | |
718 'FITTOL',1e-3,... | |
719 'MSEVARTOL',1e-2,... | |
720 'Plot','off',... | |
721 'ForceStability','off',... | |
722 'CheckProgress','off'); | |
723 out = zDomainFit(rtmod,plstd2); | |
724 % </SyntaxCode> | |
725 stest = true; | |
726 catch err | |
727 disp(err.message) | |
728 stest = false; | |
729 end | |
730 | |
731 % <AlgoDescription> | |
732 % | |
733 % 1) Check that the number of elements in 'out' is the same as in | |
734 % input. | |
735 % 2) Check that output contains the correct coefficients. | |
736 % | |
737 % </AlgoDescription> | |
738 | |
739 atest = true; | |
740 if stest | |
741 % <AlgoCode> | |
742 % Check we have the correct number of outputs | |
743 if ~isequal(numel(out), numel(rtmod)), atest = false; end | |
744 % Check each output against the absolute value of the input | |
745 for kk=1:numel(out.filters) | |
746 % Check the fitted ao(fsdata) objects | |
747 if isa(rtmod.data, 'fsdata') | |
748 % check that fit coefficients corresponds to real coefficients | |
749 % within a tolerance | |
750 if any(abs(tmod(kk).a - out.filters(kk).a)>1e-4), atest = false; end | |
751 if any(abs(tmod(kk).b - out.filters(kk).b)>1e-4), atest = false; end | |
752 else | |
753 % Check the other objects (they must be empty) | |
754 if ~isempty(out.filters(kk).a), atest = false; end | |
755 if ~isempty(out.filters(kk).b), atest = false; end | |
756 end | |
757 end | |
758 % </AlgoCode> | |
759 else | |
760 atest = false; | |
761 end | |
762 | |
763 % Return a result structure | |
764 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
765 end % END UTP_10 | |
766 | |
767 end |