pac.estimate.nls: clean up code: remove unused variables, unused output arguments, no need for otherwise in switch

time-shift
Houtan Bastani 2019-03-07 11:59:59 +01:00
parent b844bc53a0
commit 1190caba61
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
1 changed files with 11 additions and 15 deletions

View File

@ -63,17 +63,13 @@ global M_ oo_ options_
is_gauss_newton = false; is_gauss_newton = false;
is_lsqnonlin = false; is_lsqnonlin = false;
objective = 'ssr_';
if nargin>4 && (isequal(optimizer, 'GaussNewton') || isequal(optimizer, 'lsqnonlin')) if nargin>4 && (isequal(optimizer, 'GaussNewton') || isequal(optimizer, 'lsqnonlin'))
switch optimizer switch optimizer
case 'GaussNewton' case 'GaussNewton'
is_gauss_newton = true; is_gauss_newton = true;
case 'lsqnonlin' case 'lsqnonlin'
is_lsqnonlin = true; is_lsqnonlin = true;
otherwise
% Cannot happen.
end end
objective = 'r_';
end end
[pacmodl, lhs, rhs, pnames, enames, xnames, ~, pid, eid, xid, ~, ipnames_, params, data, islaggedvariables, eqtag] = ... [pacmodl, lhs, rhs, pnames, enames, xnames, ~, pid, eid, xid, ~, ipnames_, params, data, islaggedvariables, eqtag] = ...
@ -284,23 +280,23 @@ if nargin<5
end end
if is_gauss_newton if is_gauss_newton
[params1, SSR, exitflag] = gauss_newton(resfun, params0); [params1, SSR] = gauss_newton(resfun, params0);
elseif is_lsqnonlin elseif is_lsqnonlin
if ismember('levenberg-marquardt', varargin) if ismember('levenberg-marquardt', varargin)
% Levenberg Marquardt does not handle boundary constraints. % Levenberg Marquardt does not handle boundary constraints.
[params1, SSR, ~, exitflag] = lsqnonlin(resfun, params0, [], [], optimset(varargin{:})); [params1, SSR] = lsqnonlin(resfun, params0, [], [], optimset(varargin{:}));
else else
[params1, SSR, ~, exitflag] = lsqnonlin(resfun, params0, bounds(:,1), bounds(:,2), optimset(varargin{:})); [params1, SSR] = lsqnonlin(resfun, params0, bounds(:,1), bounds(:,2), optimset(varargin{:}));
end end
else else
% Estimate the parameters by minimizing the sum of squared residuals. % Estimate the parameters by minimizing the sum of squared residuals.
[params1, SSR, exitflag] = dynare_minimize_objective(ssrfun, params0, ... [params1, SSR] = dynare_minimize_objective(ssrfun, params0, ...
minalgo, ... minalgo, ...
options_, ... options_, ...
bounds, ... bounds, ...
parameter_names, ... parameter_names, ...
[], ... [], ...
[]); []);
end end
% Revert local modifications to the options. % Revert local modifications to the options.
@ -329,4 +325,4 @@ oo_.pac.(pacmodl).equations.(eqtag).student = params1./(sqrt(diag(C)));
% Also save estimated parameters in M_ % Also save estimated parameters in M_
M_.params(ipnames_) = params1; M_.params(ipnames_) = params1;
M_ = pac.update.parameters(pacmodl, M_, oo_, false); M_ = pac.update.parameters(pacmodl, M_, oo_, false);