comparison m-toolbox/classes/@smodel/double.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 % DOUBLE Returns the numeric result of the model.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Returns the numeric result of the model.
5 %
6 % CALL: num = obj.double
7 %
8 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'double')">Parameters Description</a>
9 %
10 % VERSION: $Id: double.m,v 1.21 2011/05/28 05:42:02 mauro Exp $
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13
14 function d = double(varargin)
15
16 % Check if the method was called by another method
17 callerIsMethod = utils.helper.callerIsMethod;
18
19 if callerIsMethod
20 else
21 % Check if this is a call for parameters
22 if utils.helper.isinfocall(varargin{:})
23 d = getInfo(varargin{3});
24 return
25 end
26 end
27
28 mdl = varargin{1};
29
30 % check the model is valid
31 fld = check_model_fields(mdl);
32 if ~isempty(fld)
33 error(['### The field ' fld ' cannot be empty!']);
34 end
35
36 % Check 'params' and 'values' have the same length
37 if numel(mdl.params) ~= numel(mdl.values)
38 error('### The number of parameter names and parameter values must match');
39 end
40
41 % Check 'aliasNames' and 'aliasValues' have the same length
42 if numel(mdl.aliasNames) ~= numel(mdl.aliasValues)
43 error('### The number of aliase names and alias values must match');
44 end
45
46 % Assign locally values for any remaining parameters
47 getVariables(mdl.params, mdl.values);
48
49 % Assign locally alias names to alias values
50 getVariables(mdl.aliasNames, mdl.aliasValues);
51
52 % Recover the mapping factor from xvals and xvar
53 trans = mdl.trans;
54
55 if ~isempty(trans)
56 warning('The usage of the ''trans'' option is deprecated and will be removed soon. Please use an alias instead!');
57 end
58
59 % I need to shape it as the xvar field
60 oo = ones(size(mdl.xvar));
61 if isempty(trans)
62 scale = 1.0 * oo;
63 else
64 for kk = 1:numel(trans)
65 scale(kk) = eval(trans{kk});
66 end
67 scale = scale .* oo;
68 end
69
70 % Set local values for the X vector
71 for kk = 1:numel(mdl.xvar)
72 if ~isempty(mdl.xvals)
73 eval(sprintf('%s = scale(%d).*mdl.xvals{%d};', mdl.xvar{kk}, kk, kk));
74 else
75 eval(sprintf('%s = [];', mdl.xvar{kk}));
76 end
77 end
78
79 % The actual evaluation
80 d = eval(mdl.expr.s);
81
82 % Support the case of a constant model
83 if numel(d) == 1
84 % Multiple X variables, choose the first
85 d = d .* ones(size(mdl.xvals{1}));
86 end
87
88 if any(isnan(d))
89 warning('!!! Data contain y values equal to NaN');
90 end
91 if any(isinf(d))
92 warning('!!! Data contain y values equal to Inf');
93 end
94
95 end
96
97 %--------------------------------------------------------------------------
98 % Check Model Fields are correct
99 %--------------------------------------------------------------------------
100 function fld = check_model_fields(mdl)
101
102 fld = [];
103
104 % Check 'expr'
105 if isempty(mdl.expr) || isempty(mdl.expr.s)
106 fld = 'expr';
107 return
108 end
109
110 % Check 'xvar'
111 if isempty(mdl.xvar)
112 fld = 'xvar';
113 return
114 end
115
116 end
117
118 %--------------------------------------------------------------------------
119 % Assign Variables Values
120 %--------------------------------------------------------------------------
121 function getVariables(nms, vals)
122 for kk = 1:numel(nms)
123 assignin('caller', nms{kk}, vals{kk});
124 end
125 end
126
127 %--------------------------------------------------------------------------
128 % Get Info Object
129 %--------------------------------------------------------------------------
130 function ii = getInfo(varargin)
131
132 if nargin == 1 && strcmpi(varargin{1}, 'None')
133 sets = {};
134 pl = [];
135 else
136 sets = {'Default'};
137 pl = getDefaultPlist();
138 end
139 % Build info object
140 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.helper, '$Id: double.m,v 1.21 2011/05/28 05:42:02 mauro Exp $', sets, pl);
141 end
142
143 %--------------------------------------------------------------------------
144 % Get Default Plist
145 %--------------------------------------------------------------------------
146
147 function plout = getDefaultPlist()
148 persistent pl;
149 if ~exist('pl', 'var') || isempty(pl)
150 pl = buildplist();
151 end
152 plout = pl;
153 end
154
155 function pl = buildplist()
156 pl = plist.EMPTY_PLIST;
157 end
158