Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@math/stopfit.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 % STOPFIT verify fit accuracy checking for specified condition. | |
2 % | |
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4 % DESCRIPTION: | |
5 % | |
6 % Verify fit accuracy checking for a specified condition. Available | |
7 % conditions are: | |
8 % | |
9 % Log Residuals difference | |
10 % Check if the minimum of the logarithmic difference between data and | |
11 % residuals is larger than a specified value. ie. if the conditioning | |
12 % value is 2, the function ensures that the difference between data and | |
13 % residuals is at lest 2 order of magnitude lower than data itsleves. | |
14 % Checking algorithm is: | |
15 % lsr = log10(abs(y))-log10(abs(rdl)); | |
16 % min(lsr) > lrscond; | |
17 % | |
18 % Log Residuals difference and Root Mean Squared Error | |
19 % Check if the log difference between data and residuals is in | |
20 % larger than the value indicated in lsrcond and that the variation of | |
21 % the root mean squared error is lower than 10^(-1*msevar). | |
22 % Checking algorithm is: | |
23 % lsr = log10(abs(y))-log10(abs(rdl)); | |
24 % (lsr > lrscond) && (mse < 10^(-1*lrsvarcond)); | |
25 % | |
26 % CALL: | |
27 % | |
28 % [ext,msg] = stopfit(y,rdl,mse,ctp,lrscond,msevar) | |
29 % | |
30 % INPUTS: | |
31 % | |
32 % - y are the fitting data (in case of 'lrs' and 'lrsmse') or the | |
33 % fitted model (in case of 'rft' and 'rftmse') | |
34 % - rdl are the fit residuals | |
35 % - mse is a vector storing the values of root mean squared errors | |
36 % difference for the present and previuos iterations | |
37 % - order is the model order | |
38 % - ctp defines the conditioning type. Admitted values are: | |
39 % 1) 'chival' check if the value of the Mean Squared Error is lower | |
40 % than 10^(-1*lsrcond). | |
41 % 2) 'chivar' check if the value of the Mean Squared Error is lower | |
42 % than 10^(-1*lsrcond) and if the relative variation of mean squared error is | |
43 % lower than 10^(-1*msevar). | |
44 % 3) 'lrs' check if the log difference between data and residuals is | |
45 % point by point larger than the value indicated in lsrcond. This | |
46 % mean that residuals are lsrcond order of magnitudes lower than | |
47 % data. | |
48 % 4) 'lrsmse' check if the log difference between data and | |
49 % residuals is larger than the value indicated in lsrcond and if the | |
50 % relative variation of root mean squared error is lower than | |
51 % 10^(-1*msevar). | |
52 % 5) 'rft' check if the spectral flatness coefficient for the | |
53 % rersiduals is larger than the value passed in lrscond. In this case | |
54 % only values 0 < lrscond < 1 are allowed. | |
55 % 6) 'rftmse' check if the spectral flatness coefficient for the | |
56 % rersiduals is larger than the value passed in lrscond and if the | |
57 % relative variation of root mean squared error is lower than 10^(-1*msevar). | |
58 % In this case only values 0 < lrscond < 1 are allowed. | |
59 % | |
60 % OUTPUT: | |
61 % | |
62 % - ext is 1 if the specified condition is satisfied or 0 if not | |
63 % - msg is a string containing a messagge | |
64 % | |
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
66 % VERSION: $Id: stopfit.m,v 1.8 2009/04/20 14:25:50 luigi Exp $ | |
67 % | |
68 % HISTORY: 09-10-2008 L Ferraioli | |
69 % Creation | |
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
71 | |
72 function [ext,msg] = stopfit(y,rdl,mse,ctp,lrscond,msevar) | |
73 | |
74 % switching between conditions | |
75 switch ctp | |
76 case 'chival' | |
77 if isempty(lrscond) | |
78 lrscond = 2; % Default value | |
79 end | |
80 | |
81 hh = length(mse); | |
82 lsr = -1*log10(mse(hh)); | |
83 if lsr > lrscond | |
84 msg = 'Reached tolerance for Mean Squared Error Value'; | |
85 ext = true; | |
86 else | |
87 ext = false; | |
88 msg = ''; | |
89 end | |
90 | |
91 case 'chivar' | |
92 | |
93 if isempty(lrscond) | |
94 a = 2; % Default value | |
95 else | |
96 a = lrscond; | |
97 end | |
98 if isempty(msevar) | |
99 b = 2; % Default value | |
100 else | |
101 b = msevar; | |
102 end | |
103 | |
104 hh = length(mse); | |
105 tlsr = -1*log10(mse(hh)); | |
106 if hh == 1 | |
107 stc = 1; | |
108 else | |
109 stc = diff(mse(hh-1:hh))/mse(hh-1); | |
110 end | |
111 if all(tlsr > a) && (abs(stc) < 10^(-1*b)) | |
112 msg = 'Reached tolerance for Mean Squared Error Value and Variation'; | |
113 ext = true; | |
114 else | |
115 ext = false; | |
116 msg = ''; | |
117 end | |
118 | |
119 case 'lrs' | |
120 if isempty(lrscond) | |
121 lrscond = 2; % Default value | |
122 end | |
123 | |
124 lsr = log10(abs(y))-log10(abs(rdl)); | |
125 if min(lsr) > lrscond | |
126 msg = 'Reached tolerance for Log residuals'; | |
127 ext = true; | |
128 else | |
129 ext = false; | |
130 msg = ''; | |
131 end | |
132 | |
133 case 'lrsmse' | |
134 | |
135 if isempty(lrscond) | |
136 a = 2; % Default value | |
137 else | |
138 a = lrscond; | |
139 end | |
140 if isempty(msevar) | |
141 b = 2; % Default value | |
142 else | |
143 b = msevar; | |
144 end | |
145 | |
146 tlsr = log10(abs(y))-log10(abs(rdl)); | |
147 hh = length(mse); | |
148 if hh == 1 | |
149 stc = 1; | |
150 else | |
151 stc = diff(mse(hh-1:hh))/mse(hh-1); | |
152 end | |
153 if all(tlsr > a) && (abs(stc) < 10^(-1*b)) | |
154 msg = 'Reached tolerance for Log Residuals and Mean Squared Error variation'; | |
155 ext = true; | |
156 else | |
157 ext = false; | |
158 msg = ''; | |
159 end | |
160 | |
161 case 'rft' % Check that residuals flatness is larger than a certain value | |
162 % Calculate residual flatness | |
163 rf = utils.math.spflat(abs(rdl)); | |
164 | |
165 % Checking that lrscond has the correct value | |
166 a = lrscond; | |
167 if (a >= 1) || (a < 0) | |
168 a = 0.5; | |
169 end | |
170 if rf > a | |
171 msg = 'Reached tolerance for residuals spectral flatness'; | |
172 ext = true; | |
173 else | |
174 ext = false; | |
175 msg = ''; | |
176 end | |
177 | |
178 case 'rftmse' | |
179 | |
180 % Calculate residual flatness | |
181 rf = utils.math.spflat(abs(rdl)); | |
182 | |
183 % Checking that lrscond has the correct value | |
184 a = lrscond; | |
185 if (a >= 1) || (a < 0) | |
186 a = 0.5; | |
187 end | |
188 | |
189 if isempty(msevar) | |
190 b = 2; % Default value | |
191 else | |
192 b = msevar; | |
193 end | |
194 | |
195 hh = length(mse); | |
196 if hh == 1 | |
197 stc = 1; | |
198 else | |
199 stc = diff(mse(hh-1:hh))/mse(hh-1); | |
200 end | |
201 if (rf > a) && (abs(stc) < 10^(-1*b)) | |
202 msg = 'Reached tolerance for residuals spectral flatness and Mean Squared Error variation'; | |
203 ext = true; | |
204 else | |
205 ext = false; | |
206 msg = ''; | |
207 end | |
208 | |
209 | |
210 | |
211 end | |
212 |