0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % Linear fit with singular value decomposition
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % INPUT:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % - exps: is a N dimensional struct whose fields are fitdata
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % (experimental data), fitbasis (basis for the fit) and params (cell
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % array with the names of the parameters used in the experiment).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % - groundexps: a M dim struct containing results from on ground experiments.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % Fuields are: pos (parameter position number), value (on ground measurement
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % result) and err (experimental error on the on ground measurement).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % - sThreshold it's a threshold for singular values. It is a
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % number, typically 1. It will remove singular values larger
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % than sThreshold which corresponds to removing svd parameters estimated
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % with an error larger than sThreshold.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % OUTPUT:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % a: params values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % Ca: fit covariance matrix for A
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 % Corra: fit correlation matrix for A
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % Vu: is the complete conversion matrix
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % Cbu: is the new variables covariance matrix
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % Fbu: is the information matrix for the new variable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 % mse: is the fit Mean Square Error
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % dof: degrees of freedom for the global estimation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % ppm: number of svd parameters per measurements, provides also the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % number of independent combinations of parameters per each singular
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % measurement. The coefficients of the combinations are then stored in Vu
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % 21-07-2009 L Ferraioli
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % CREATION
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 % $Id: linfitsvd.m,v 1.8 2010/10/29 12:40:47 ingo Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 function [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = linfitsvd(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % get inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 if nargin == 1 % no ground experiment
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 exps = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 groundexps = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 remerr = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 elseif nargin == 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 exps = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 if isnumeric(varargin{2})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 sThreshold = varargin{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 remerr = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 groundexps = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 groundexps = varargin{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 remerr = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 elseif nargin == 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 exps = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 groundexps = varargin{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 sThreshold = varargin{3}; % admitted threshold for singular values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 remerr = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 if ~isnumeric(sThreshold)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 sThreshold = inf;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % init collect results struct
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 % init union matrices
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 Vu = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 Fbu = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 wFbu = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 bu = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 % eCbu = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 Cbu = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 ppm = []; % number of svd parameters per measurements
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 N = numel(exps);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % run over input experiments
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 for ii=1:N
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % get data of the experiments out of the input struct
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 y = exps(ii).fitdata;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 X = exps(ii).fitbasis;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 % willing to work with columns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 if size(y,1)<size(y,2)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 y = y.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 if size(X,1)<size(X,2)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 X = X.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 % get svd of X
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 [U,W,V] = svd(X,0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % removing zero singular values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 svals = diag(W);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 idx = svals==0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 svals(idx) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % removing columns of U and V corresponding to zero svalues
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 U(:,idx) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 V(:,idx) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 if remerr
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % Find params combinations with error larger than 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 idx = svals<sThreshold;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 svals(idx) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 % removing columns of U and V corresponding to params combinations with
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 % error larger than 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 U(:,idx) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 V(:,idx) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 % Sanity check
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 % if svals is empty you are going to gain no information from the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 % current data series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 if ~isempty(svals) % go with the fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 % rebuild W
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 W = diag(svals);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 % update ppm with the number of parameters for the given experiment
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 ppm = [ppm; numel(svals)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 % get new basis for the fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 K = U*W;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 % get expected covariance matrix for b, assuming white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 Fb = W*W; % information matrix for parameters b
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 % get b params with errors, mse is the mean square error, Cb is the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 % covariance matrix of fitted b. It should be equal to eCb.*mse
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 [b,stdxb,mseb,Cb] = lscov(K,y);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 % information matrix weighted for fit results Cb = inv(wFb)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 wFb = Fb./mseb;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 % add params from present experiment
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 % get union matrices
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 Vu = [Vu;V.'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 Fbu = blkdiag(Fbu,Fb);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 wFbu = blkdiag(wFbu,wFb);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 Cbu = blkdiag(Cbu,Cb);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 bu = [bu;b];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 else % no information, no fit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 % update ppm with the number of parameters for the given experiment
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 ppm = [ppm; 0];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 % insert values from on-ground measured parameters if applicable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 if nargin == 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 for jj = 1:numel(groundexps)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 % get values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 pos = groundexps(jj).pos;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 val = groundexps(jj).value;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 err = groundexps(jj).err;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 tV = zeros(1,size(Vu,2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 tV(1,pos) = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 Vu = [Vu;tV];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 bu = [bu;val];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 Cbu = blkdiag(Cbu,err^2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 Fbu = blkdiag(Fbu,1/(err^2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 wFbu = blkdiag(wFbu,1/(err^2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 ppm = [ppm; 1];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 % get results on physical parameters, solve the system with proper weights
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 a = lscov(Vu,bu,1./diag(Cbu));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 % get params covariance
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 Ca = inv(Vu'*wFbu*Vu);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 % get params correlation matrix
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 Corra = Ca;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 for tt=1:size(Corra,1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 for hh=1:size(Corra,2)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 Corra(tt,hh) = Ca(tt,hh)/(sqrt(Ca(tt,tt))*sqrt(Ca(hh,hh)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 % get chi square assuming unitary variance white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 N = numel(exps);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 mse = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 tL = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 % run over input experiments
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 for ii=1:N
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 % get data of the experiments out of the input struct
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 y = exps(ii).fitdata;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 X = exps(ii).fitbasis;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 mse = mse + sum((y - X*a).^2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 tL = tL + numel(y);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 dof = tL-numel(a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 mse = mse./dof;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213
|