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