Mercurial > hg > ltpda
comparison m-toolbox/classes/@matrix/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.9 2011/05/02 14:18:19 luigi 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 [mtxs, mtxs_invars] = utils.helper.collect_objects(varargin(:), 'matrix', in_names); | |
61 [pl, invars] = utils.helper.collect_objects(varargin(:), 'plist'); | |
62 | |
63 | |
64 inhists = [mtxs(:).hist]; | |
65 | |
66 | |
67 %%% combine plists | |
68 pl = parse(pl, getDefaultPlist()); | |
69 | |
70 %%% collect inputs names | |
71 argsname = mtxs(end).name; | |
72 | |
73 %%% get input params | |
74 kwnpars = find(pl,'KnownParams'); | |
75 sThreshold = find(pl,'sThreshold'); | |
76 | |
77 | |
78 %%% do fit | |
79 % if ~isempty(kwnpars) && isfield(kwnpars,'pos') | |
80 % [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(mtxs,kwnpars); | |
81 % else | |
82 % [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(mtxs); | |
83 % end | |
84 | |
85 if ~isempty(kwnpars) && isfield(kwnpars,'pos') | |
86 if ~isempty(sThreshold) | |
87 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(mtxs,sThreshold,kwnpars); | |
88 else | |
89 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(mtxs,kwnpars); | |
90 end | |
91 else | |
92 if ~isempty(sThreshold) | |
93 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(mtxs,sThreshold); | |
94 else | |
95 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(mtxs); | |
96 end | |
97 end | |
98 | |
99 fitparams = cell(1,numel(a)); | |
100 nmstr = ''; | |
101 for kk=1:numel(a) | |
102 fitparams{kk} = sprintf('a%s',num2str(kk)); | |
103 units{kk} = mtxs(end).objs(1).yunits / mtxs(kk).objs(1).yunits; | |
104 units{kk}.simplify; | |
105 if isempty(nmstr) | |
106 nmstr = sprintf('%s*%s',fitparams{kk},mtxs(kk).name); | |
107 else | |
108 nmstr = [nmstr '+' sprintf('%s*%s',fitparams{kk},mtxs(kk).name)]; | |
109 end | |
110 end | |
111 | |
112 pe = pest(); | |
113 pe.setY(a); | |
114 pe.setDy(sqrt(diag(Ca))); | |
115 pe.setCov(Ca); | |
116 pe.setChi2(mse); | |
117 pe.setNames(fitparams); | |
118 pe.setDof(dof); | |
119 pe.setYunits(units{:}); | |
120 pe.name = nmstr; | |
121 pe.setModels(mtxs(1:end-1)); | |
122 | |
123 % set History | |
124 pe.addHistory(getInfo('None'), pl, [mtxs_invars(:)], [inhists(:)]); | |
125 | |
126 | |
127 if nargout == 1 | |
128 varargout{1} = pe; | |
129 elseif nargout == 11 | |
130 varargout{1} = pe; | |
131 varargout{2} = a; | |
132 varargout{3} = Ca; | |
133 varargout{4} = Corra; | |
134 varargout{5} = Vu; | |
135 varargout{6} = bu; | |
136 varargout{7} = Cbu; | |
137 varargout{8} = Fbu; | |
138 varargout{9} = mse; | |
139 varargout{10} = dof; | |
140 varargout{11} = ppm; | |
141 else | |
142 error('invalid number of outputs!') | |
143 end | |
144 | |
145 end | |
146 | |
147 | |
148 %-------------------------------------------------------------------------- | |
149 % Get Info Object | |
150 %-------------------------------------------------------------------------- | |
151 function ii = getInfo(varargin) | |
152 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
153 sets = {}; | |
154 pl = []; | |
155 else | |
156 sets = {'Default'}; | |
157 pl = getDefaultPlist; | |
158 end | |
159 % Build info object | |
160 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: linlsqsvd.m,v 1.9 2011/05/02 14:18:19 luigi Exp $', sets, pl); | |
161 ii.setArgsmin(2); | |
162 ii.setOutmin(1); | |
163 % ii.setOutmax(1); | |
164 ii.setModifier(false); | |
165 end | |
166 | |
167 %-------------------------------------------------------------------------- | |
168 % Get Default Plist | |
169 %-------------------------------------------------------------------------- | |
170 function plout = getDefaultPlist() | |
171 persistent pl; | |
172 if exist('pl', 'var')==0 || isempty(pl) | |
173 pl = buildplist(); | |
174 end | |
175 plout = pl; | |
176 end | |
177 | |
178 function pl = buildplist() | |
179 | |
180 pl = plist(); | |
181 | |
182 p = param({'KnownParams', ['Known Parameters. A struct array with the fields:<ul>'... | |
183 '<li> pos - a number indicating the corresponding position of the parameter (corresponding column of H)</li>'... | |
184 '<li> value - the value for the parameter</li>'... | |
185 '<li> err - the uncertainty associated to the parameter</li>'... | |
186 '</ul>']}, paramValue.EMPTY_CELL); | |
187 pl.append(p); | |
188 | |
189 p = param({'sThreshold',['Fix upper treshold for singular values.'... | |
190 'Singular values larger than the value will be ignored.'... | |
191 'This correspon to consider only parameters combinations with error lower then the value']},... | |
192 paramValue.EMPTY_DOUBLE); | |
193 pl.append(p); | |
194 | |
195 | |
196 end |