comparison m-toolbox/classes/@ao/linlsqsvd.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 % LINLSQSVD Linear least squares with singular value decomposition
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Linear least square problem with singular value
5 % decomposition
6 %
7 % ALGORITHM: % It solves the problem
8 %
9 % Y = HX
10 %
11 % where X are the parameters, Y the measurements, and H the linear
12 % equations relating the two.
13 % It is able to perform linear identification of the parameters of a
14 % multichannel systems. The results of different experiments on the same
15 % system can be passed as input. The algorithm, thanks to the singular
16 % value decomposition, extract the maximum amount of information from each
17 % single channel and for each experiment. Total information is then
18 % combined to get the final result.
19 %
20 % CALL: pars = linfitsvd(H1,...,HN,Y,pl);
21 %
22 % If the experiment is 1 then H1,...,HN and Y are aos.
23 % If the experiments are M, then H1,...,HN and Y are Mx1 matrix objects
24 % with the aos relating to the given experiment in the proper position.
25 %
26 % INPUT:
27 % - Hi represent the columns of H
28 % - Y represent the measurement set
29 %
30 % OUTPUT:
31 % - pars: a pest object containing parameter estimation
32 %
33 % 09-11-2010 L Ferraioli
34 % CREATION
35 %
36 % <a href="matlab:utils.helper.displayMethodInfo('matrix', 'linfitsvd')">Parameters Description</a>
37 %
38 % VERSION: $Id: linlsqsvd.m,v 1.8 2011/04/08 08:56:13 hewitson Exp $
39 %
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
42 function varargout = linlsqsvd(varargin)
43
44 %%% LTPDA stufs and get data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45
46 % Check if this is a call for parameters
47 if utils.helper.isinfocall(varargin{:})
48 varargout{1} = getInfo(varargin{3});
49 return
50 end
51
52 import utils.const.*
53 utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
54
55 % Collect input variable names
56 in_names = cell(size(varargin));
57 for ii = 1:nargin,in_names{ii} = inputname(ii);end
58
59 % Collect all ltpdauoh objects
60 [A, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
61 [pl, invars] = utils.helper.collect_objects(varargin(:), 'plist');
62
63 inhists = [A(:).hist];
64
65 %%% combine plists
66 pl = parse(pl, getDefaultPlist());
67
68
69 %%% get input params
70 kwnpars = find(pl,'KnownParams');
71 sThreshold = find(pl,'sThreshold');
72
73
74 %%% do fit
75 % if ~isempty(kwnpars) && isfield(groundexps,'pos')
76 % [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(A,kwnpars);
77 % else
78 % [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(A);
79 % end
80
81 if ~isempty(kwnpars) && isfield(kwnpars,'pos')
82 if ~isempty(sThreshold)
83 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(A,sThreshold,kwnpars);
84 else
85 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(A,kwnpars);
86 end
87 else
88 if ~isempty(sThreshold)
89 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(A,sThreshold);
90 else
91 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(A);
92 end
93 end
94
95
96 fitparams = cell(1,numel(a));
97 nmstr = '';
98 for kk=1:numel(a)
99 fitparams{kk} = sprintf('a%s',num2str(kk));
100 units{kk} = A(end).yunits / A(kk).yunits;
101 if isempty(nmstr)
102 nmstr = sprintf('%s*%s',fitparams{kk},A(kk).name);
103 else
104 nmstr = [nmstr '+' sprintf('%s*%s',fitparams{kk},A(kk).name)];
105 end
106 end
107
108 pe = pest();
109 pe.setY(a);
110 pe.setDy(sqrt(diag(Ca)));
111 pe.setCov(Ca);
112 pe.setCorr(Corra);
113 pe.setChi2(mse);
114 pe.setNames(fitparams);
115 pe.setDof(dof);
116
117 pe.setModels(A(1:end-1));
118 pe.setYunits(units{:});
119 pe.name = nmstr;
120 pe.addHistory(getInfo('None'), pl, [ao_invars(:)], [inhists(:)]);
121
122
123
124 if nargout == 1
125 varargout{1} = pe;
126 elseif nargout == 10
127 varargout{1} = pe;
128 varargout{2} = a;
129 varargout{3} = Ca;
130 varargout{4} = Corra;
131 varargout{5} = Vu;
132 varargout{6} = bu;
133 varargout{7} = Cbu;
134 varargout{8} = Fbu;
135 varargout{9} = mse;
136 varargout{10} = dof;
137 varargout{11} = ppm;
138 else
139 error('invalid number of outputs!')
140 end
141
142 end
143
144
145 %--------------------------------------------------------------------------
146 % Get Info Object
147 %--------------------------------------------------------------------------
148 function ii = getInfo(varargin)
149 if nargin == 1 && strcmpi(varargin{1}, 'None')
150 sets = {};
151 pl = [];
152 else
153 sets = {'Default'};
154 pl = getDefaultPlist;
155 end
156 % Build info object
157 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: linlsqsvd.m,v 1.8 2011/04/08 08:56:13 hewitson Exp $', sets, pl);
158 ii.setArgsmin(2);
159 ii.setOutmin(1);
160 % ii.setOutmax(1);
161 ii.setModifier(false);
162 end
163
164 %--------------------------------------------------------------------------
165 % Get Default Plist
166 %--------------------------------------------------------------------------
167 function plout = getDefaultPlist()
168 persistent pl;
169 if exist('pl', 'var')==0 || isempty(pl)
170 pl = buildplist();
171 end
172 plout = pl;
173 end
174
175 function pl = buildplist()
176
177 pl = plist();
178
179 p = param({'KnownParams', ['Known Parameters. A struct array with the fields:<ul>'...
180 '<li> pos - a number indicating the corresponding position of the parameter (corresponding column of H)</li>'...
181 '<li> value - the value for the parameter</li>'...
182 '<li> err - the uncertainty associated to the parameter</li>'...
183 '</ul>']}, paramValue.EMPTY_CELL);
184 pl.append(p);
185
186 p = param({'sThreshold',['Fix upper treshold for singular values.'...
187 'Singular values larger than the value will be ignored.'...
188 'This correspon to consider only parameters combinations with error lower then the value']},...
189 paramValue.EMPTY_DOUBLE);
190 pl.append(p);
191
192
193 end