comparison m-toolbox/classes/@pest/setDyForParameter.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 % SETDYFORPARAMETER Sets the according dy-error for the specified parameter.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETDYFORPARAMETER Sets the according dy-error for the
5 % specified parameter.
6 %
7 % CALL: obj = obj.setDyForParameter('a', 2);
8 % obj = obj.setDyForParameter('a', 2, 'b', 2);
9 % obj = obj.setDyForParameter(plist('errors', [2 2],
10 % 'params' {'a', 'b'}))
11 %
12 % INPUTS: obj - one pest model.
13 % pl - parameter list
14 %
15 % <a href="matlab:utils.helper.displayMethodInfo('pest', 'setDyForParameter')">Parameters Description</a>
16 %
17 % VERSION: $Id: setDyForParameter.m,v 1.7 2011/04/08 08:56:25 hewitson Exp $
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 function varargout = setDyForParameter(varargin)
22
23 % Check if this is a call from a class method
24 callerIsMethod = utils.helper.callerIsMethod;
25
26 if callerIsMethod
27
28 %%% make sure that the parameters and errors are cell-arrays
29 obj = varargin{1};
30 params = cellstr(varargin{2});
31 errs = varargin{3};
32 if ~iscell(errs)
33 errs = num2cell(errs);
34 end
35 else
36 % Check if this is a call for parameters
37 if utils.helper.isinfocall(varargin{:})
38 varargout{1} = getInfo(varargin{3});
39 return
40 end
41
42 %%% Collect input variable names
43 in_names = cell(size(varargin));
44 for ii = 1:nargin,in_names{ii} = inputname(ii);end
45
46 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), '', in_names);
47 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
48
49 params = {};
50 errs = {};
51 %%% If pls contains only one plist with the two keys 'params' and
52 %%% 'errors' then set the property with a plist.
53 if length(pls) == 1 && isa(pls, 'plist') && nparams(pls) == 2 && isparam(pls, 'errors')
54 params = cellstr(find(pls, 'params'));
55 errs = find(pls, 'errors');
56 if ~iscell(errs)
57 errs = num2cell(errs);
58 end
59 end
60
61 while numel(rest) >= 2
62 params = [params cellstr(rest{1})];
63 if ~iscell(rest{2})
64 errs = [errs num2cell(rest{2})];
65 else
66 errs = [errs rest{2}];
67 end
68 rest(2) = [];
69 rest(1) = [];
70 end
71
72 %%% Combine plists
73 pls = combine(pls, plist('params', params, 'errors', errs));
74
75 if numel(params) ~= numel(errs)
76 error('### Please specify one error per parameter.');
77 end
78
79 end % callerIsMethod
80
81 %%% decide whether we modify the input pest object, or create a new one.
82 objs = copy(objs, nargout);
83
84 for objLoop = 1:numel(objs)
85
86 for ll=1:numel(params)
87 pname = params{ll};
88 % get index of this param
89 idx = find(strcmp(objs(objLoop).names, pname));
90 if isempty(idx)
91 objs(objLoop).names = [objs(objLoop).names {pname}];
92 objs(objLoop).dy = [objs(objLoop).dy; errs{ll}];
93 else
94 objs(objLoop).dy(idx) = errs{ll};
95 end
96 end
97
98 if ~callerIsMethod
99 % set output history
100 objs(objLoop).addHistory(getInfo('None'), pls, obj_invars(objLoop), objs(objLoop).hist);
101 end
102 end
103
104 %%% Set output
105 if nargout == numel(objs)
106 % List of outputs
107 for ii = 1:numel(objs)
108 varargout{ii} = objs(ii);
109 end
110 else
111 % Single output
112 varargout{1} = objs;
113 end
114
115 end
116
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 % Local Functions %
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 %
123 % FUNCTION: getInfo
124 %
125 % DESCRIPTION: Get Info Object
126 %
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
129 function ii = getInfo(varargin)
130 if nargin == 1 && strcmpi(varargin{1}, 'None')
131 sets = {};
132 pl = [];
133 else
134 sets = {'Default'};
135 pl = getDefaultPlist;
136 end
137 % Build info object
138 ii = minfo(mfilename, 'pest', 'ltpda', utils.const.categories.helper, '$Id: setDyForParameter.m,v 1.7 2011/04/08 08:56:25 hewitson Exp $', sets, pl);
139 end
140
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 %
143 % FUNCTION: getDefaultPlist
144 %
145 % DESCRIPTION: Get Default Plist
146 %
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 function plout = getDefaultPlist()
150 persistent pl;
151 if exist('pl', 'var')==0 || isempty(pl)
152 pl = buildplist();
153 end
154 plout = pl;
155 end
156
157 function pl = buildplist()
158
159 pl = plist();
160
161 % Params
162 p = param({'params', 'A cell-array of parameter names.'}, {1, {'{}'}, paramValue.OPTIONAL});
163 pl.append(p);
164
165 % Error
166 p = param({'errors', 'A cell-array of errors, one for each parameter to set.'}, {1, {'{}'}, paramValue.OPTIONAL});
167 pl.append(p);
168
169 end
170