comparison m-toolbox/html_help/help/ug/ltpda_training_topic_5_4.html @ 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 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
3
4 <html lang="en">
5 <head>
6 <meta name="generator" content=
7 "HTML Tidy for Mac OS X (vers 1st December 2004), see www.w3.org">
8 <meta http-equiv="Content-Type" content=
9 "text/html; charset=us-ascii">
10
11 <title>Non-linear least squares fitting of time series (LTPDA Toolbox)</title>
12 <link rel="stylesheet" href="docstyle.css" type="text/css">
13 <meta name="generator" content="DocBook XSL Stylesheets V1.52.2">
14 <meta name="description" content=
15 "Presents an overview of the features, system requirements, and starting the toolbox.">
16 </head>
17
18 <body>
19 <a name="top_of_page" id="top_of_page"></a>
20
21 <p style="font-size:1px;">&nbsp;</p>
22
23 <table class="nav" summary="Navigation aid" border="0" width=
24 "100%" cellpadding="0" cellspacing="0">
25 <tr>
26 <td valign="baseline"><b>LTPDA Toolbox</b></td><td><a href="../helptoc.html">contents</a></td>
27
28 <td valign="baseline" align="right"><a href=
29 "ltpda_training_topic_5_3.html"><img src="b_prev.gif" border="0" align=
30 "bottom" alt="Fitting time series with polynomials"></a>&nbsp;&nbsp;&nbsp;<a href=
31 "ltpda_training_topic_5_5.html"><img src="b_next.gif" border="0" align=
32 "bottom" alt="IFO/Temperature Example - signal subtraction"></a></td>
33 </tr>
34 </table>
35
36 <h1 class="title"><a name="f3-12899" id="f3-12899"></a>Non-linear least squares fitting of time series</h1>
37 <hr>
38
39 <p>
40
41 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
42 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
43
44 <html lang="en">
45 <head>
46 <meta name="generator" content=
47 "HTML Tidy for Mac OS X (vers 1st December 2004), see www.w3.org">
48 <meta http-equiv="Content-Type" content=
49 "text/html; charset=us-ascii">
50
51 <title>Non-linear least squares fitting of time series (LTPDA Toolbox)</title>
52 <link rel="stylesheet" href="docstyle.css" type="text/css">
53 <meta name="generator" content="DocBook XSL Stylesheets V1.52.2">
54 <meta name="description" content=
55 "Presents an overview of the features, system requirements, and starting the toolbox.">
56
57 </head>
58
59 <body>
60 <a name="top_of_page" id="top_of_page"></a>
61
62 <p style="font-size:1px;">&nbsp;</p>
63
64 <table class="nav" summary="Navigation aid" border="0" width=
65 "100%" cellpadding="0" cellspacing="0">
66 <tr>
67 <td valign="baseline"><b>LTPDA Toolbox</b></td><td><a href="../helptoc.html">contents</a></td>
68
69 <td valign="baseline" align="right"><a href=
70 "ltpda_training_topic_5_3.html"><img src="b_prev.gif" border="0" align=
71 "bottom" alt="Fitting time series with polynomials"></a>&nbsp;&nbsp;&nbsp;<a href=
72 "ltpda_training_topic_5_5.html"><img src="b_next.gif" border="0" align=
73 "bottom" alt="IFO/Temperature Example - signal subtraction"></a></td>
74 </tr>
75 </table>
76
77 <h1 class="title"><a name="f3-12899" id="f3-12899"></a>Non-linear least squares fitting of time series</h1>
78 <hr>
79
80 <p>
81
82
83 <p>
84
85 Non-linear least square fitting of time-series exploits the function <tt>ao/xfit</tt>.
86 </p>
87
88 <h2> Non-linear least square fitting of time series </h2>
89
90 <p>
91 During this exercise we will:
92 <ol>
93 <li> Load time series data
94 <li> Fit data with <tt>ao/xfit</tt>
95 <li> Check results
96 <li> Refine the fit with a Monte Carlo search
97 </ol>
98 </p>
99
100 <p>
101 Let us open a new editor window and load test data.
102 </p>
103
104 <div class="fragment"><pre>
105 a = ao(plist(<span class="string">'filename'</span>, <span class="string">'topic5/T5_Ex05_TestNoise.xml'</span>));
106 a.setName(<span class="string">'data'</span>);
107 iplot(a)
108
109 </pre></div>
110
111 <p>
112 As can be seen this is a chirped sine wave with some noise.
113 <div align="center">
114 <IMG src="images/ltpda_training_1/topic5/ltpda_training_5_4_1.png" align="center" border="0">
115 </div>
116 We could now try the fit. The first parameter to pass to <tt>xfit</tt>
117 is a fit model. In this case we assume that we are dealing with a linearly
118 chirped sine wave according to the equation: <br/>
119
120 <br/>
121 <div align="center">
122 <IMG src="images/ltpda_training_1/topic5/ex4_chirpsine.gif" align="center" border="0">
123 </div>
124 <br/>
125 The previous function can be stored within a <tt>smodel</tt> analysis object to pass to the fitting machinery:
126 <div class="fragment"><pre>
127 mdl = smodel(plist(<span class="string">'Name'</span>, <span class="string">'chirp'</span>, ...
128 <span class="string">'expression'</span>, <span class="string">'A.*sin(2*pi*(f + f0.*t).*t + p) + c'</span>, ...
129 <span class="string">'params'</span>, <span class="string">{'A','f','f0','p','c'}</span>, ...
130 <span class="string">'xvar'</span>, <span class="string">'t'</span>, ...
131 <span class="string">'xunits'</span>, <span class="string">'s'</span>, <span class="string">'yunits'</span>, <span class="string">'m'</span>));
132
133 </pre></div>
134
135 We need to specify a starting guess for the model parameters.
136 The output of <tt>ao/xfit</tt> is a <tt>pest</tt> analysis objects containing fit parameters.
137
138 </p>
139
140 <div class="fragment"><pre>
141 plfit1 = plist(<span class="string">'Function'</span>, <span class="string">mdl</span>, ...
142 <span class="string">'P0'</span>, [5,9e-5,9e-6,0,5]);
143
144 params1 = xfit(a, plfit1);
145
146 </pre></div>
147
148 <p>
149 Once the fit is done. We can evaluate our model to check fit results.
150 </p>
151
152 <div class="fragment"><pre>
153 b = eval(params1, plist(<span class="string">'xdata'</span>, a, <span class="string">'xfield'</span>, <span class="string">'x'</span>));
154 b.setName;
155 iplot(a,b)
156
157 </pre></div>
158
159 <p>
160 As you can see, the fit is not accurate. One of the great problems of
161 non-linear least square methods is that they easily find a local minimum of
162 the chi square function and stop there without finding the global minimum.
163 There are two possibile solutions to such kind of problems: the first one is
164 to refine step by step the fit by looking at the data; the second one is to
165 perform a Monte Carlo search in the parameter space. This way, the fitting machinery
166 extracts the number of points you define in the <tt>'Npoints'</tt>
167 key, evaluates the chi square at those points, reoders by ascending chi square, selects
168 the first guesses and fit starting from them.
169 </p>
170
171 <div class="fragment"><pre>
172 plfit2 = plist(<span class="string">'Function'</span>, <span class="string">mdl</span>, ...
173 <span class="string">'MonteCarlo'</span>, <span class="string">'yes'</span>, ...
174 <span class="string">'Npoints'</span>, 1000, ...
175 <span class="string">'LB'</span>, [1,5e-5,5e-6,0,2], ...
176 <span class="string">'UB'</span>, [10,5e-4,5e-5,2*pi,7]);
177
178 params2 = xfit(a, plfit2);
179
180 c = eval(params2, plist(<span class="string">'xdata'</span>, a, <span class="string">'xfield'</span>, <span class="string">'x'</span>));
181 c.setName;
182 iplot(a,c)
183
184 </pre></div>
185
186 <p>
187 The fit now looks like better...
188 <div align="center">
189 <IMG src="images/ltpda_training_1/topic5/ltpda_training_5_4_3.png" align="center" border="0">
190 </div>
191
192 Let us compare fit results with nominal parameters. <br/>
193 Data were generated with the following set of parameters:
194 </p>
195
196 <div class="fragment"><pre>
197 A = 3
198 f = 1e-4
199 f0 = 1e-5
200 p = 0.3
201 c = 5
202 </pre></div>
203
204 <p>
205
206 Fitted parameters are instead:
207 </p>
208
209 <div class="fragment"><pre>
210 A = 3.02 +/- 0.05
211 f = (7 +/- 3)e-5
212 f0 = (1.003 +/- 0.003)e-5
213 p = 0.33 +/- 0.04
214 c = 4.97 +/- 0.03
215 </pre></div>
216 <p>
217 The correlation matrix of the parameters, the chi square, the degree of freedom, the covariance matrix are
218 store in the output <tt>pest</tt>. Other useful information are stored in the <tt>procinfo</tt> (processing information)
219 field. This field is a <tt>plist</tt> and is used to additional information that can be
220 returned from algorithms. For example, to extract the chi square, we write:
221 </p>
222
223 <div class="fragment"><pre>
224 params2.chi2
225 1.0253740840052
226 </pre></div>
227 <p>
228 And to know the correlation matrix:
229 </p>
230
231 <div class="fragment"><pre>
232 params2.corr
233 Columns 1 through 3
234
235 1 0.120986348157139 -0.0970894969803509
236 0.120986348157139 1 -0.966114904879414
237 -0.0970894969803509 -0.966114904879414 1
238 -0.156801230958825 -0.848296014553159 0.717376893765734
239 -0.0994358284166703 0.187645552903433 -0.169496082635319
240
241 Columns 4 through 5
242
243 -0.156801230958825 -0.0994358284166703
244 -0.848296014553159 0.187645552903433
245 0.717376893765734 -0.169496082635319
246 1 -0.199286767157984
247 -0.199286767157984 1
248 </pre></div>
249
250 <p>
251 Not so bad!
252 </p>
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272 </p>
273
274 <br>
275 <br>
276 <table class="nav" summary="Navigation aid" border="0" width=
277 "100%" cellpadding="0" cellspacing="0">
278 <tr valign="top">
279
280 <td align="left" width="20"><a href="ltpda_training_topic_5_3.html"><img src=
281 "b_prev.gif" border="0" align="bottom" alt=
282 "Fitting time series with polynomials"></a>&nbsp;</td>
283
284 <td align="left">Fitting time series with polynomials</td>
285
286 <td>&nbsp;</td>
287
288 <td align="right">IFO/Temperature Example - signal subtraction</td>
289
290 <td align="right" width="20"><a href=
291 "ltpda_training_topic_5_5.html"><img src="b_next.gif" border="0" align=
292 "bottom" alt="IFO/Temperature Example - signal subtraction"></a></td>
293 </tr>
294
295 </table><br>
296
297 <p class="copy">&copy;LTP Team</p>
298 </body>
299 </html>
300
301 </p>
302
303 <br>
304 <br>
305 <table class="nav" summary="Navigation aid" border="0" width=
306 "100%" cellpadding="0" cellspacing="0">
307 <tr valign="top">
308 <td align="left" width="20"><a href="ltpda_training_topic_5_3.html"><img src=
309 "b_prev.gif" border="0" align="bottom" alt=
310 "Fitting time series with polynomials"></a>&nbsp;</td>
311
312 <td align="left">Fitting time series with polynomials</td>
313
314 <td>&nbsp;</td>
315
316 <td align="right">IFO/Temperature Example - signal subtraction</td>
317
318 <td align="right" width="20"><a href=
319 "ltpda_training_topic_5_5.html"><img src="b_next.gif" border="0" align=
320 "bottom" alt="IFO/Temperature Example - signal subtraction"></a></td>
321 </tr>
322 </table><br>
323
324 <p class="copy">&copy;LTP Team</p>
325 </body>
326 </html>