Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_linfit.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_AO_LINFIT tests the linfit method of the AO class. | |
2 % | |
3 % M Hueller 02-03-10 | |
4 % | |
5 % $Id: test_ao_linfit.m,v 1.6 2011/05/15 22:52:57 mauro Exp $ | |
6 % | |
7 % function test_ao_linfit() | |
8 | |
9 | |
10 %% Make fake AO from polyval | |
11 nsecs = 100; | |
12 fs = 10; | |
13 | |
14 unit_list = unit.supportedUnits; | |
15 u1 = unit(cell2mat(utils.math.randelement(unit_list,1))); | |
16 u2 = unit(cell2mat(utils.math.randelement(unit_list,1))); | |
17 | |
18 pl1 = plist('nsecs', nsecs, 'fs', fs, ... | |
19 'tsfcn', 'polyval([10 1], t) + randn(size(t))', ... | |
20 'xunits', 's', 'yunits', u1); | |
21 | |
22 pl2 = plist('nsecs', nsecs, 'fs', fs, ... | |
23 'tsfcn', 'polyval([-5 0.2], t) + randn(size(t))', ... | |
24 'xunits', 's', 'yunits', u2); | |
25 | |
26 a1 = ao(pl1); | |
27 a2 = ao(pl2); | |
28 a = scatterData(a1, a2); | |
29 | |
30 %% Fit with a straight line | |
31 | |
32 p11 = linfit(a1, plist(... | |
33 )); | |
34 p12 = linfit(a1, plist(... | |
35 'dy', 0.1)); | |
36 p22 = linfit(a1, plist(... | |
37 'dx', 0.1, 'dy', 0.1, 'P0', [0 0])); | |
38 p13 = linfit(a1, plist(... | |
39 'dy', 0.1*ones(size(a1.y)))); | |
40 p23 = linfit(a1, plist(... | |
41 'dx', 0.1*ones(size(a1.x)), 'dy', 0.1*ones(size(a1.y)), 'P0', [0 0])); | |
42 p14 = linfit(a1, plist(... | |
43 'dy', ao(0.1, plist('yunits', a1.yunits)))); | |
44 p24 = linfit(a1, plist(... | |
45 'dx', ao(0.1, plist(... | |
46 'yunits', a1.xunits)), 'dy', ao(0.1, plist('yunits', a1.yunits)), 'P0', [0 0])); | |
47 p15 = linfit(a1, plist(... | |
48 'dy', ao(0.1*ones(size(a1.y)), plist('yunits', a1.yunits)))); | |
49 p25 = linfit(a1, plist(... | |
50 'dx', ao(0.1*ones(size(a1.x)), plist('yunits', a1.xunits)), 'dy', ao(0.1*ones(size(a1.y)), plist('yunits', a1.yunits)), 'P0', [0 0])); | |
51 p26 = linfit(a1, plist(... | |
52 'dx', 0.1, 'dy', 0.1, 'P0', ao([0 0]))); | |
53 p27 = linfit(a1, plist(... | |
54 'dx', 0.1, 'dy', 0.1, 'P0', p11)); | |
55 | |
56 %% Compute fit: evaluating pest | |
57 | |
58 b11 = p11.eval(plist('type', 'tsdata', 'XData', a1, 'xfield', 'x')); | |
59 b12 = p12.eval(plist('XData', a1, 'xfield', 'x')); | |
60 b22 = p22.eval(a1, plist('xfield', 'x')); | |
61 b13 = p13.eval(plist('XData', a1, 'xfield', 'x')); | |
62 b23 = p23.eval(a1, plist('type', 'tsdata', 'xfield', 'x')); | |
63 b14 = p14.eval(plist('XData', a1, 'xfield', 'x')); | |
64 b24 = p24.eval(a1, plist('type', 'tsdata', 'xfield', 'x')); | |
65 b15 = p15.eval(a1, plist('xfield', 'x')); | |
66 b25 = p25.eval(plist('XData', a1, 'xfield', 'x')); | |
67 b26 = p26.eval(plist('type', 'tsdata', 'XData', a1.x)); | |
68 b27 = p27.eval(plist('type', 'tsdata', 'XData', a1.x)); | |
69 | |
70 %% Plot fit | |
71 iplot(a1, b11, b12, b13, b14, b15, b26, b27, ... | |
72 b22, b23, b24, b25, ... | |
73 plist('LineStyles', {'', '--'})); | |
74 | |
75 %% Remove linear trend | |
76 c = a1-b11; | |
77 iplot(c) | |
78 | |
79 plot(c.hist) | |
80 | |
81 %% Reproduce from history | |
82 disp('Try rebuilding') | |
83 a_out = rebuild(c); | |
84 iplot(a_out) | |
85 plot(a_out.hist) | |
86 | |
87 %% Fit with a straight line | |
88 | |
89 p = linfit(a, plist(... | |
90 )); | |
91 | |
92 %% Compute fit: evaluating pest | |
93 | |
94 b1 = p.eval(plist('XData', a, 'xfield', 'x')); | |
95 b2 = p.eval(a, plist('xfield', 'x')); | |
96 b3 = p.eval(plist('type', 'xydata', 'XData', a.x, 'xunits', a.xunits)); | |
97 b4 = p.eval(plist('XData', a.x, 'xunits', a.xunits)); | |
98 | |
99 %% Plot fit | |
100 iplot(a, b1, b2, b3, b4, ... | |
101 plist('LineStyles', {'', '--'})); | |
102 | |
103 %% Fit with a straight line | |
104 | |
105 p11 = linfit(a1, a2, plist(... | |
106 )); | |
107 p12 = linfit(a1, a2, plist(... | |
108 'dy', 0.1)); | |
109 p22 = linfit(a1, a2, plist(... | |
110 'dx', 0.1, 'dy', 0.1, 'P0', [0 0])); | |
111 p13 = linfit(a1, a2, plist(... | |
112 'dy', 0.1*ones(size(a1.x)))); | |
113 p23 = linfit(a1, a2, plist(... | |
114 'dx', 0.1*ones(size(a1.x)), 'dy', 0.1*ones(size(a1.x)), 'P0', [0 0])); | |
115 p14 = linfit(a1, a2, plist(... | |
116 'dy', ao(0.1, plist('yunits', a2.yunits)))); | |
117 p24 = linfit(a1, a2, plist(... | |
118 'dx', ao(0.1, plist('yunits', a1.yunits)), 'dy', ao(0.1, plist('yunits', a2.yunits)), 'P0', [0 0])); | |
119 p15 = linfit(a1, a2, plist(... | |
120 'dy', ao(0.1*ones(size(a2.y)), plist('yunits', a2.yunits)))); | |
121 p25 = linfit(a1, a2, plist(... | |
122 'dx', ao(0.1*ones(size(a1.y)), plist('yunits', a1.yunits)), 'dy', ao(0.1*ones(size(a2.y)), plist('yunits', a2.yunits)), 'P0', [0 0])); | |
123 p26 = linfit(a1, a2, plist(... | |
124 'dx', 0.1, 'dy', 0.1, 'P0', ao([0 0]))); | |
125 p27 = linfit(a1, a2, plist(... | |
126 'dx', 0.1, 'dy', 0.1, 'P0', p11)); | |
127 | |
128 %% Compute fit: evaluating pest | |
129 | |
130 b11 = p11.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits)); | |
131 b12 = p12.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits)); | |
132 b22 = p22.eval(a1, plist('type', 'xydata')); | |
133 b13 = p13.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits)); | |
134 b23 = p23.eval(a1, plist('type', 'xydata')); | |
135 b14 = p14.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits)); | |
136 b24 = p24.eval(a1, plist('type', 'xydata')); | |
137 b15 = p15.eval(a1, plist('type', 'xydata')); | |
138 b25 = p25.eval(plist('type', 'xydata', 'XData', a1.y)); | |
139 b26 = p26.eval(plist('type', 'xydata', 'XData', a1.y)); | |
140 b27 = p27.eval(plist('type', 'xydata', 'XData', a1.y)); | |
141 | |
142 % Build reference object | |
143 a12 = ao(plist('xvals', a1.y, 'yvals', a2.y, ... | |
144 'xunits', a1.yunits, 'yunits', a2.yunits)); | |
145 %% Plot fit | |
146 iplot(b22, b23, b24, b15, ... | |
147 b12, b13, b14, b11, ... | |
148 plist('LineStyles', {'', '--'})); | |
149 | |
150 %% Plot fit | |
151 iplot(b25, b26, b27, ... | |
152 plist('LineStyles', {'', '--'})); | |
153 | |
154 %% Remove linear trend | |
155 c = a12-b27; | |
156 iplot(c) | |
157 | |
158 plot(c.hist) | |
159 | |
160 %% Reproduce from history | |
161 disp('Try rebuilding') | |
162 a_out = rebuild(c); | |
163 iplot(a_out) | |
164 plot(a_out.hist) | |
165 | |
166 % end | |
167 % END |