comparison m-toolbox/classes/@smodel/linearize.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 % LINEARIZE output the derivatives of the model relative to the parameters.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: LINEARIZE output the derivatives of the model relative to
5 % the parameters. Output is a collection of models corresponding to the
6 % derivative of input model for each parameter
7 %
8 % CALL: dmod = linearize(imod)
9 %
10 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'linearize')">Parameters Description</a>
11 %
12 % VERSION: $Id: linearize.m,v 1.9 2011/04/08 08:56:30 hewitson Exp $
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 function varargout = linearize(varargin)
16
17 % Check if this is a call for parameters
18 if utils.helper.isinfocall(varargin{:})
19 varargout{1} = getInfo(varargin{3});
20 return
21 end
22
23 % Check if the method was called by another method
24 callerIsMethod = utils.helper.callerIsMethod;
25
26 % Collect input variable names
27 in_names = cell(size(varargin));
28 for ii = 1:nargin,in_names{ii} = inputname(ii);end
29
30 % Collect all smodels and plists
31 [as, smodel_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names);
32 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
33
34 % Combine input plists and default plist
35 pl = parse(pl, getDefaultPlist());
36
37 % run over input smodels
38 dmod(numel(as),1) = collection;
39 for jj = 1:numel(as)
40 imod = as(jj);
41 [mpars,idx] = sort(imod.params);
42 mvals = imod.values(idx);
43 imod.setParams(mpars, mvals);
44
45 pars = imod.params;
46
47 for ii = 1:numel(pars)
48 tmod = diff(imod, pars{ii}); % do symbolic derivative for smodel
49 % set the name of the parameter to the matrix, this is important to
50 % identify automatically to what derivatives we are referring
51 tmod.setName(pars{ii});
52 dmod(jj).addObjects(tmod);
53 end
54 dmod(jj).setName(sprintf('linearize(%s)', imod.name));
55 end
56
57 if ~callerIsMethod
58 % Add history
59 dmod.addHistory(getInfo('None'), pl, smodel_invars, [as(:).hist]);
60 end
61
62 if nargout == 1
63 varargout{1} = dmod;
64 elseif nargout == numel(as)
65 % List of outputs
66 for jj = 1:numel(as)
67 varargout{jj} = dmod.index(jj);
68 end
69 else
70 error('Set at least one output value')
71 end
72
73 end
74
75 %--------------------------------------------------------------------------
76 % Get Info Object
77 %--------------------------------------------------------------------------
78 function ii = getInfo(varargin)
79
80 if nargin == 1 && strcmpi(varargin{1}, 'None')
81 sets = {};
82 pls = [];
83 else
84 sets = {'Default'};
85 pls = getDefaultPlist;
86 end
87 % Build info object
88 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.op, '$Id: linearize.m,v 1.9 2011/04/08 08:56:30 hewitson Exp $', sets, pls);
89 ii.setModifier(false);
90 end
91
92 %--------------------------------------------------------------------------
93 % Get Default Plist
94 %--------------------------------------------------------------------------
95 function plout = getDefaultPlist()
96 persistent pl;
97 if ~exist('pl', 'var') || isempty(pl)
98 pl = buildplist();
99 end
100 plout = pl;
101 end
102
103 function pl = buildplist()
104 pl = plist.EMPTY_PLIST;
105 end