comparison m-toolbox/classes/+utils/@math/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: [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(H1,...,HN,Y);
21 % [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(H1,...,HN,Y,errthres);
22 % [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linlsqsvd(H1,...,HN,Y,errthres,knwpars);
23 %
24 % If the experiment is 1 then H1,...,HN and Y are aos.
25 % If the experiments are M, then H1,...,HN and Y are Mx1 matrix objects
26 % with the aos relating to the given experiment in the proper position.
27 %
28 % INPUT:
29 % - Hi represent the columns of H
30 % - Y represent the measurement set
31 % - sThreshold it's a threshold for singular values. It is a
32 % number, typically 1. It will remove singular values larger
33 % than sThreshold which corresponds to removing svd parameters estimated
34 % with an error larger than sThreshold.
35 % - knwpars A struct array with the fields:
36 % pos - a number indicating the corresponding position of
37 % the parameter (corresponding column of H)
38 % value - the value for the parameter
39 % err - the uncertainty associated to the parameter
40 %
41 % OUTPUT:
42 % a: params values
43 % Ca: fit covariance matrix for A
44 % Corra: fit correlation matrix for A
45 % Vu: is the complete conversion matrix
46 % Cbu: is the new variables covariance matrix
47 % Fbu: is the information matrix for the new variable
48 % mse: is the fit Mean Square Error
49 % dof: degrees of freedom for the global estimation
50 % ppm: number of svd parameters per measurements, provides also the
51 % number of independent combinations of parameters per each singular
52 % measurement. The coefficients of the combinations are then stored in Vu
53 %
54 % 09-11-2010 L Ferraioli
55 % CREATION
56 %
57 % <a href="matlab:utils.helper.displayMethodInfo('matrix', 'linfitsvd')">Parameter Sets</a>
58 %
59 % VERSION: $Id: linlsqsvd.m,v 1.2 2011/03/11 09:28:26 luigi Exp $
60 %
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62
63 function [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = linlsqsvd(varargin)
64
65
66
67 %%% get input params
68 if isstruct(varargin{end})
69 kwnpars = varargin{end};
70 if isnumeric(varargin{end-1})
71 sThreshold = varargin{end-1};
72 A = varargin{1:end-2};
73 else
74 A = varargin{1:end-1};
75 sThreshold = [];
76 end
77 else
78 kwnpars = [];
79 if isnumeric(varargin{end})
80 sThreshold = varargin{end};
81 A = varargin{1:end-1};
82 else
83 A = varargin{:};
84 sThreshold = [];
85 end
86 end
87
88
89 %%% sort between one or multiple experiments
90 exps = struct;
91
92 if isa(A(1),'ao') % one experiment
93 % Build matrices for lscov
94 C = A(1:end-1);
95 Y = A(end);
96
97 H = C(:).y;
98 y = Y.y;
99 exps.fitbasis = H;
100 exps.fitdata = y;
101 elseif isa(A(1),'matrix') % multiple experiments
102 % run over input objects and experiments
103 for jj=1:numel(A(1).objs)
104 C = [];
105 for ii=1:numel(A)-1
106 D = A(ii).objs(jj).y;
107 % willing to work with columns
108 if size(D,1)<size(D,2)
109 D = D.';
110 end
111 C = [C D];
112 end
113 y = A(end).objs(jj).y;
114 exps(jj).fitbasis = C;
115 exps(jj).fitdata = y;
116 end
117 else
118 error('Unknown input data type!')
119 end
120
121 %%% do fit
122 if ~isempty(kwnpars) && isfield(kwnpars,'pos')
123 if ~isempty(sThreshold)
124 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linfitsvd(exps,kwnpars,sThreshold);
125 else
126 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linfitsvd(exps,kwnpars);
127 end
128 else
129 if ~isempty(sThreshold)
130 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linfitsvd(exps,sThreshold);
131 else
132 [a,Ca,Corra,Vu,bu,Cbu,Fbu,mse,dof,ppm] = utils.math.linfitsvd(exps);
133 end
134 end
135
136
137
138
139 end
140