Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_confint.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_CONFINT a set of UTPs for the ao/confint method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_confint.m,v 1.2 2011/05/22 21:35:42 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The confint method of the ao class computes the confidence intervals for spectral estimate. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_confint(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 addpath(fullfile(fileparts(which(mfilename)), 'reference_files')) | |
20 | |
21 % Some keywords | |
22 class = 'ao'; | |
23 mthd = 'confint'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 % Test AOs | |
31 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]); | |
32 | |
33 % reference psd for rebuild | |
34 rsp = psd(at5); | |
35 | |
36 % Exception list for the UTPs: | |
37 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
38 | |
39 % reference confs | |
40 rconf = [5.7 16.0]; | |
41 | |
42 % reference ao for dof test | |
43 plrefdata = plist('fs', 1, 'nsecs', 1024, ... | |
44 'tsfcn', 'randn(size(t))'); | |
45 refdata = ao(plrefdata); | |
46 | |
47 | |
48 | |
49 % Run the tests | |
50 results = [results utp_01]; % getInfo call | |
51 results = [results utp_06]; % Test history is working | |
52 results = [results utp_07]; % Test against reference data | |
53 results = [results utp_08]; % Test the data shape | |
54 | |
55 | |
56 disp('Done.'); | |
57 disp('******************************************************'); | |
58 | |
59 elseif nargin == 1 % Check for UTP functions | |
60 if strcmp(varargin{1}, 'isutp') | |
61 results = 1; | |
62 else | |
63 results = 0; | |
64 end | |
65 else | |
66 error('### Incorrect inputs') | |
67 end | |
68 | |
69 | |
70 %% UTP_01 | |
71 | |
72 % <TestDescription> | |
73 % | |
74 % Tests that the getInfo call works for this method. | |
75 % | |
76 % </TestDescription> | |
77 function result = utp_01 | |
78 | |
79 | |
80 % <SyntaxDescription> | |
81 % | |
82 % Test that the getInfo call works for no sets, all sets, and each set | |
83 % individually. | |
84 % | |
85 % </SyntaxDescription> | |
86 | |
87 % <SyntaxCode> | |
88 try | |
89 % Call for no sets | |
90 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
91 % Call for all sets | |
92 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
93 % Call for each set | |
94 for kk=1:numel(io(2).sets) | |
95 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
96 end | |
97 stest = true; | |
98 catch err | |
99 disp(err.message) | |
100 stest = false; | |
101 end | |
102 % </SyntaxCode> | |
103 | |
104 % <AlgoDescription> | |
105 % | |
106 % 1) Check that getInfo call returned an minfo object in all cases. | |
107 % 2) Check that all plists have the correct parameters. | |
108 % | |
109 % </AlgoDescription> | |
110 | |
111 % <AlgoCode> | |
112 atest = true; | |
113 if stest | |
114 % check we have minfo objects | |
115 if isa(io, 'minfo') | |
116 | |
117 %%% SET 'None' | |
118 if ~isempty(io(1).sets), atest = false; end | |
119 if ~isempty(io(1).plists), atest = false; end | |
120 %%% Check all Sets | |
121 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
122 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
123 %%%%%%%%%% Default PList | |
124 if io(3).plists.nparams ~= 4, atest = false; end | |
125 % Check key | |
126 if ~io(3).plists.isparam('method'), atest = false; end | |
127 if ~io(3).plists.isparam('DataLength'), atest = false; end | |
128 if ~io(3).plists.isparam('Conf'), atest = false; end | |
129 if ~io(3).plists.isparam('dof'), atest = false; end | |
130 % Check default value | |
131 if ~isequal(io(3).plists.find('method'), 'psd'), atest = false; end | |
132 if ~isequal(io(3).plists.find('DataLength'), paramValue.EMPTY_DOUBLE), atest = false; end | |
133 if ~isequal(io(3).plists.find('Conf'), 95), atest = false; end | |
134 if ~isequal(io(3).plists.find('dof'), paramValue.EMPTY_DOUBLE), atest = false; end | |
135 % Check options | |
136 if ~isequal(io(3).plists.getOptionsForParam('method'), {'psd','lpsd','mscohere','mslcohere'}), atest = false; end | |
137 if ~isequal(io(3).plists.getOptionsForParam('DataLength'), {paramValue.EMPTY_DOUBLE}), atest = false; end | |
138 if ~isequal(io(3).plists.getOptionsForParam('Conf'), {95}), atest = false; end | |
139 if ~isequal(io(3).plists.getOptionsForParam('dof'), {paramValue.EMPTY_DOUBLE}), atest = false; end | |
140 end | |
141 else | |
142 atest = false; | |
143 end | |
144 % </AlgoCode> | |
145 | |
146 % Return a result structure | |
147 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
148 end % END UTP_01 | |
149 | |
150 %% UTP_06 | |
151 | |
152 % <TestDescription> | |
153 % | |
154 % Tests that the confint method properly applies history. | |
155 % | |
156 % </TestDescription> | |
157 function result = utp_06 | |
158 | |
159 % <SyntaxDescription> | |
160 % | |
161 % Test that the result of applying the confint method can be processed back | |
162 % to an m-file. | |
163 % | |
164 % </SyntaxDescription> | |
165 | |
166 % <SyntaxCode> | |
167 try | |
168 out = confint(rsp); | |
169 mout = rebuild(out); | |
170 stest = true; | |
171 catch err | |
172 disp(err.message) | |
173 stest = false; | |
174 end | |
175 % </SyntaxCode> | |
176 | |
177 % <AlgoDescription> | |
178 % | |
179 % 1) Check that the last entry in the history of 'out' corresponds to | |
180 % 'confint'. | |
181 % 2) Check that the re-built object is the same object as 'out'. | |
182 % | |
183 % </AlgoDescription> | |
184 | |
185 % <AlgoCode> | |
186 atest = true; | |
187 if stest | |
188 % Check the last step in the history of 'out' | |
189 if ~strcmp(out.hist.methodInfo.mname, 'confint'), atest = false; end | |
190 % Check the re-built object | |
191 if ~eq(mout, out, ple2), atest = false; end | |
192 else | |
193 atest = false; | |
194 end | |
195 % </AlgoCode> | |
196 | |
197 % Return a result structure | |
198 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
199 end % END UTP_06 | |
200 | |
201 %% UTP_07 | |
202 | |
203 % <TestDescription> | |
204 % | |
205 % Tests that the confint method provides correct values for spectra | |
206 % confidence intervals. | |
207 % Reference on D B Percival and A T Walden, Spectral Analysis for | |
208 % Physical Applications, pg. 299 | |
209 % | |
210 % </TestDescription> | |
211 function result = utp_07 | |
212 | |
213 % <SyntaxDescription> | |
214 % | |
215 % Test that the applying psd works on a single AO. | |
216 % | |
217 % </SyntaxDescription> | |
218 | |
219 % <SyntaxCode> | |
220 try | |
221 | |
222 plsp = plist('win','BH92','order',1,'navs',1); | |
223 axx = psd(refdata,plsp); | |
224 plconf = plist('method','psd',... | |
225 'DataLength',numel(refdata.y),... | |
226 'Conf',95); | |
227 cf = confint(axx,plconf); | |
228 | |
229 llcf = 10*log10(cf.objs{1}.y); | |
230 laxx = 10*log10(axx.y); | |
231 lucf = 10*log10(cf.objs{2}.y); | |
232 | |
233 dcf = [(laxx-llcf) (lucf-laxx)]; | |
234 | |
235 | |
236 stest = true; | |
237 catch err | |
238 disp(err.message) | |
239 stest = false; | |
240 end | |
241 % </SyntaxCode> | |
242 | |
243 % <AlgoDescription> | |
244 % | |
245 % 1) Check that output agrees with the reference values. | |
246 % | |
247 % </AlgoDescription> | |
248 | |
249 % <AlgoCode> | |
250 atest = true; | |
251 TOL = 0.01; | |
252 | |
253 if stest | |
254 for jj=1:size(dcf,1) | |
255 if any((abs(dcf(jj,:) - rconf) ./ rconf) >= TOL) | |
256 atest = false; | |
257 end | |
258 end | |
259 else | |
260 atest = false; | |
261 end | |
262 % </AlgoCode> | |
263 | |
264 % Return a result structure | |
265 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
266 end % END UTP_07 | |
267 | |
268 %% UTP_08 | |
269 | |
270 % <TestDescription> | |
271 % | |
272 % Tests that the confint method keeps the data shape of the input object. | |
273 % | |
274 % </TestDescription> | |
275 function result = utp_08 | |
276 | |
277 % <SyntaxDescription> | |
278 % | |
279 % Test that the confint method keeps the data shape of the input object. The | |
280 % input AO must be an AO with row data and an AO with column data. | |
281 % | |
282 % </SyntaxDescription> | |
283 | |
284 try | |
285 % <SyntaxCode> | |
286 aa1 = at5.psd; | |
287 aa2 = at6.psd; | |
288 out1obj = confint(aa1); | |
289 out1_1 = out1obj.getObjectAtIndex(1); | |
290 out1_2 = out1obj.getObjectAtIndex(2); | |
291 out1_3 = out1obj.getObjectAtIndex(3); | |
292 out2obj = confint(aa2); | |
293 out2_1 = out2obj.getObjectAtIndex(1); | |
294 out2_2 = out2obj.getObjectAtIndex(2); | |
295 out2_3 = out2obj.getObjectAtIndex(3); | |
296 % </SyntaxCode> | |
297 stest = true; | |
298 catch err | |
299 disp(err.message) | |
300 stest = false; | |
301 end | |
302 | |
303 % <AlgoDescription> | |
304 % | |
305 % 1) Check that the shpe of the data doesn't change. | |
306 % | |
307 % </AlgoDescription> | |
308 | |
309 atest = true; | |
310 if stest | |
311 % <AlgoCode> | |
312 % Check the shape of the output data | |
313 if size(out1_1.data.y,1) == 1, atest = false; end | |
314 if size(out1_2.data.y,1) == 1, atest = false; end | |
315 if size(out1_3.data.y,1) == 1, atest = false; end | |
316 if size(out2_1.data.y,2) == 2, atest = false; end | |
317 if size(out2_2.data.y,2) == 2, atest = false; end | |
318 if size(out2_3.data.y,2) == 2, atest = false; end | |
319 % </AlgoCode> | |
320 else | |
321 atest = false; | |
322 end | |
323 | |
324 % Return a result structure | |
325 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
326 end % END UTP_08 | |
327 | |
328 | |
329 | |
330 | |
331 | |
332 | |
333 end |