Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/evaluateModel.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 % EVALUATEMODEL evaluate a curvefit model. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: EVALUATEMODEL evaluate a curvefit model. | |
5 % | |
6 % CALL: b = evaluateModel(a, pl) | |
7 % | |
8 % INPUTS: a - input AO(s) containing parameter values. The parameter | |
9 % values are collected from the Y data of all input cdata | |
10 % AOs. The most common approach would be one AO per | |
11 % parameter, or a single AO with all parameters in. | |
12 % pl - parameter list (see below) | |
13 % | |
14 % OUTPUTs: b - an AO containing the model evaluated at the give X | |
15 % values, with the given parameter values. | |
16 % | |
17 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'evaluateModel')">Parameters Description</a> | |
18 % | |
19 % VERSION: $Id: evaluateModel.m,v 1.14 2011/04/08 08:56:13 hewitson Exp $ | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 function varargout = evaluateModel(varargin) | |
24 | |
25 % Check if this is a call for parameters | |
26 if utils.helper.isinfocall(varargin{:}) | |
27 varargout{1} = getInfo(varargin{3}); | |
28 return | |
29 end | |
30 | |
31 import utils.const.* | |
32 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
33 | |
34 warning(['The method ''ao/curvefit'' and ''ao/evaluateModel'' have been replaced by ''ao/xfit'' and ''pest/eval''.' ... | |
35 'They are no longer maintained and will be removed from future releases of LTPDA Toolbox.']); | |
36 | |
37 % Collect input variable names | |
38 in_names = cell(size(varargin)); | |
39 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
40 | |
41 % Collect all AOs and plists | |
42 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
43 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
44 | |
45 %%% Decide on a deep copy or a modify | |
46 bs = copy(as, nargout); | |
47 | |
48 % Each of the input AOs should be a cdata AO; from these we get the | |
49 % parameter values | |
50 P = []; | |
51 for kk=1:numel(bs) | |
52 if isa(bs(kk).data, 'cdata') | |
53 P = [P; bs(kk).data.y(:)]; | |
54 else | |
55 warning('!!! AO %s is not a cdata AO. Not using for parameter values.', bs(kk).name); | |
56 end | |
57 end | |
58 | |
59 % combine plists | |
60 pl = parse(pl, getDefaultPlist()); | |
61 | |
62 % Extract necessary parameters | |
63 targetFcn = find(pl, 'Function'); | |
64 ADDP = find(pl, 'ADDP'); | |
65 dtype = find(pl, 'dtype'); | |
66 Xdata = find(pl, 'Xdata'); | |
67 if isa(Xdata, 'ao') | |
68 Xdata = Xdata.x; | |
69 end | |
70 | |
71 | |
72 if ~iscell(ADDP) | |
73 ADDP = {ADDP}; | |
74 end | |
75 | |
76 % Check parameters | |
77 if isempty(targetFcn) | |
78 error('### Please specify a target function'); | |
79 end | |
80 if isempty(P) | |
81 error('### Please give values for the parameters'); | |
82 end | |
83 | |
84 % Make an anonymous function of the target function | |
85 cmd = sprintf('tfunc = @(P,Xdata,ADDP)(%s);', targetFcn); | |
86 eval(cmd); | |
87 % Evaluate function at best fit | |
88 Y = tfunc(P, Xdata, ADDP); | |
89 if isa(Y, 'ao') | |
90 Y = Y.y; | |
91 end | |
92 | |
93 % Make new output AO | |
94 switch lower(dtype) | |
95 case 'tsdata' | |
96 out = ao(tsdata(Xdata,Y)); | |
97 out.data.setXunits('s'); | |
98 case 'fsdata' | |
99 out = ao(fsdata(Xdata,Y)); | |
100 out.data.setXunits('Hz'); | |
101 case 'xydata' | |
102 out = ao(xydata(Xdata,Y)); | |
103 otherwise | |
104 error('### Unknown data type specified. Choose from xydata, fsdata, or tsdata'); | |
105 end | |
106 | |
107 % Set output AO name | |
108 name = sprintf('eval(%s,', targetFcn); | |
109 for kk=1:numel(bs) | |
110 name = [name bs(kk).name ',']; | |
111 end | |
112 name = [name(1:end-1) ')']; | |
113 out.name = name; | |
114 % Add history | |
115 out.addHistory(getInfo('None'), pl, ao_invars, [bs(:).hist]); | |
116 | |
117 % Set outputs | |
118 if nargout > 0 | |
119 varargout{1} = out; | |
120 end | |
121 end | |
122 | |
123 | |
124 %-------------------------------------------------------------------------- | |
125 % Get Info Object | |
126 %-------------------------------------------------------------------------- | |
127 function ii = getInfo(varargin) | |
128 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
129 sets = {}; | |
130 pl = []; | |
131 else | |
132 sets = {'Default'}; | |
133 pl = getDefaultPlist; | |
134 end | |
135 % Build info object | |
136 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: evaluateModel.m,v 1.14 2011/04/08 08:56:13 hewitson Exp $', sets, pl); | |
137 end | |
138 | |
139 %-------------------------------------------------------------------------- | |
140 % Get Default Plist | |
141 %-------------------------------------------------------------------------- | |
142 function plout = getDefaultPlist() | |
143 persistent pl; | |
144 if exist('pl', 'var')==0 || isempty(pl) | |
145 pl = buildplist(); | |
146 end | |
147 plout = pl; | |
148 end | |
149 | |
150 function pl = buildplist() | |
151 | |
152 pl = plist(); | |
153 | |
154 % Function | |
155 p = param({'Function', ['The function to evaluate. <br>'... | |
156 'The function should be parameterized by the vector of '... | |
157 'parameters P, the cell-array ADDP, and the '... | |
158 'x-vector Xdata.'... | |
159 ]}, paramValue.EMPTY_STRING); | |
160 pl.append(p); | |
161 | |
162 % ADDP | |
163 p = param({'ADDP', 'A cell-array of additional parameters to pass to the target function'}, ... | |
164 {1, {{}}, paramValue.OPTIONAL}); | |
165 pl.append(p); | |
166 | |
167 % DTYPE | |
168 p = param({'dtype', 'The data type to interpret this model as.'}, {1, {'xydata', 'fsdata', 'tsdata'}, paramValue.SINGLE}); | |
169 pl.append(p); | |
170 | |
171 % XDATA | |
172 p = param({'Xdata', ['The X values to evaluate the model at.<br>'... | |
173 'This can be a vector or an AO (from which the Xdata will '... | |
174 'be extracted).']}, paramValue.EMPTY_DOUBLE); | |
175 pl.append(p); | |
176 | |
177 | |
178 end | |
179 % END |