Commit ff427807 authored by Johannes Pfeifer 's avatar Johannes Pfeifer

dynare_minimize_objective.m: replace optimset by optimoptions to allow for...

dynare_minimize_objective.m: replace optimset by optimoptions to allow for both Pre and post R2016a option names
parent d2a55d1e
...@@ -70,24 +70,21 @@ switch minimizer_algorithm ...@@ -70,24 +70,21 @@ switch minimizer_algorithm
error('Optimization algorithm 1 requires the Optimization Toolbox') error('Optimization algorithm 1 requires the Optimization Toolbox')
end end
% Set default optimization options for fmincon. % Set default optimization options for fmincon.
optim_options = optimset('display','iter', 'MaxFunEvals',100000, 'TolFun',1e-8, 'TolX',1e-6); optim_options = optimoptions('fmincon','display','iter', 'MaxFunEvals',100000, 'TolFun',1e-8, 'TolX',1e-6);
if ~isoctave
optim_options = optimset(optim_options, 'LargeScale','off');
end
if isoctave if isoctave
% Under Octave, use the active-set (i.e. octave_sqp of nonlin_min) % Under Octave, use the active-set (i.e. octave_sqp of nonlin_min)
% algorithm. On a simple example (fs2000.mod), the default algorithm % algorithm. On a simple example (fs2000.mod), the default algorithm
% is not able to even move away from the initial point. % is not able to even move away from the initial point.
optim_options = optimset(optim_options, 'Algorithm','active-set'); optim_options = optimoptions(optim_options, 'Algorithm','active-set');
end end
if ~isempty(options_.optim_opt) if ~isempty(options_.optim_opt)
eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); eval(['optim_options = optimoptions(optim_options,' options_.optim_opt ');']);
end end
if options_.silent_optimizer if options_.silent_optimizer
optim_options = optimset(optim_options,'display','off'); optim_options = optimoptions(optim_options,'display','off');
end end
if options_.analytic_derivation if options_.analytic_derivation
optim_options = optimset(optim_options,'GradObj','on','TolX',1e-7); optim_options = optimoptions(optim_options,'GradObj','on','TolX',1e-7); %alter default TolX
end end
if ~isoctave if ~isoctave
[opt_par_values,fval,exitflag,output,lamdba,grad,hessian_mat] = ... [opt_par_values,fval,exitflag,output,lamdba,grad,hessian_mat] = ...
...@@ -99,6 +96,7 @@ switch minimizer_algorithm ...@@ -99,6 +96,7 @@ switch minimizer_algorithm
[opt_par_values,fval,exitflag,output] = ... [opt_par_values,fval,exitflag,output] = ...
fmincon(func,start_par_value,[],[],[],[],bounds(:,1),bounds(:,2),[],optim_options); fmincon(func,start_par_value,[],[],[],[],bounds(:,1),bounds(:,2),[],optim_options);
end end
case 2 case 2
%simulating annealing %simulating annealing
sa_options = options_.saopt; sa_options = options_.saopt;
...@@ -157,15 +155,15 @@ switch minimizer_algorithm ...@@ -157,15 +155,15 @@ switch minimizer_algorithm
error('Optimization algorithm 3 requires the Optimization Toolbox') error('Optimization algorithm 3 requires the Optimization Toolbox')
end end
% Set default optimization options for fminunc. % Set default optimization options for fminunc.
optim_options = optimset('display','iter','MaxFunEvals',100000,'TolFun',1e-8,'TolX',1e-6); optim_options = optimoptions('fminunc','display','iter','MaxFunEvals',100000,'TolFun',1e-8,'TolX',1e-6);
if ~isempty(options_.optim_opt) if ~isempty(options_.optim_opt)
eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); eval(['optim_options = optimoptions(optim_options,' options_.optim_opt ');']);
end end
if options_.analytic_derivation if options_.analytic_derivation
optim_options = optimset(optim_options,'GradObj','on'); optim_options = optimoptions(optim_options,'GradObj','on');
end end
if options_.silent_optimizer if options_.silent_optimizer
optim_options = optimset(optim_options,'display','off'); optim_options = optimoptions(optim_options,'display','off');
end end
if ~isoctave if ~isoctave
[opt_par_values,fval,exitflag] = fminunc(objective_function,start_par_value,optim_options,varargin{:}); [opt_par_values,fval,exitflag] = fminunc(objective_function,start_par_value,optim_options,varargin{:});
...@@ -174,6 +172,7 @@ switch minimizer_algorithm ...@@ -174,6 +172,7 @@ switch minimizer_algorithm
func = @(x) objective_function(x,varargin{:}); func = @(x) objective_function(x,varargin{:});
[opt_par_values,fval,exitflag] = fminunc(func,start_par_value,optim_options); [opt_par_values,fval,exitflag] = fminunc(func,start_par_value,optim_options);
end end
case 4 case 4
% Set default options. % Set default options.
H0 = 1e-4*eye(n_params); H0 = 1e-4*eye(n_params);
...@@ -514,12 +513,12 @@ switch minimizer_algorithm ...@@ -514,12 +513,12 @@ switch minimizer_algorithm
error('Optimization algorithm 2 requires the Global Optimization Toolbox') error('Optimization algorithm 2 requires the Global Optimization Toolbox')
end end
% Set default optimization options for simulannealbnd. % Set default optimization options for simulannealbnd.
optim_options = saoptimset('display','iter','TolFun',1e-8); optim_options = optimoptions('simulannealbnd','display','iter','TolFun',1e-8);
if ~isempty(options_.optim_opt) if ~isempty(options_.optim_opt)
eval(['optim_options = saoptimset(optim_options,' options_.optim_opt ');']); eval(['optim_options = optimoptions(optim_options,' options_.optim_opt ');']);
end end
if options_.silent_optimizer if options_.silent_optimizer
optim_options = optimset(optim_options,'display','off'); optim_options = optimoptions(optim_options,'display','off');
end end
func = @(x)objective_function(x,varargin{:}); func = @(x)objective_function(x,varargin{:});
[opt_par_values,fval,exitflag,output] = simulannealbnd(func,start_par_value,bounds(:,1),bounds(:,2),optim_options); [opt_par_values,fval,exitflag,output] = simulannealbnd(func,start_par_value,bounds(:,1),bounds(:,2),optim_options);
...@@ -530,20 +529,20 @@ switch minimizer_algorithm ...@@ -530,20 +529,20 @@ switch minimizer_algorithm
elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox') elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox')
error('Option mode_compute=13 requires the Optimization Toolbox') error('Option mode_compute=13 requires the Optimization Toolbox')
end end
optim_options = optimset('display','iter','MaxFunEvals',5000,'MaxIter',5000,'TolFun',1e-6,'TolX',1e-6); optim_options = optimoptions('lsqnonlin','display','iter','MaxFunEvals',5000,'MaxIter',5000,'TolFun',1e-6,'TolX',1e-6);
if ~isempty(options_.optim_opt) if ~isempty(options_.optim_opt)
eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); eval(['optim_options = optimoptions(optim_options,' options_.optim_opt ');']);
end end
if options_.silent_optimizer if options_.silent_optimizer
optim_options = optimset(optim_options,'display','off'); optim_options = optimoptions(optim_options,'Display','off');
end end
if ~isoctave if ~isoctave
[opt_par_values,Resnorm,fval,exitflag,OUTPUT,LAMBDA,JACOB] = lsqnonlin(objective_function,start_par_value,bounds(:,1),bounds(:,2),optim_options,varargin{:}); [opt_par_values,Resnorm,fval,exitflag,OUTPUT,LAMBDA,JACOB] = lsqnonlin(objective_function,start_par_value,bounds(:,1),bounds(:,2),optim_options,varargin{:});
else else
% Under Octave, use a wrapper, since lsqnonlin() does not have a 6th arg % Under Octave, use a wrapper, since lsqnonlin() does not have a 6th arg
func = @(x)objective_function(x,varargin{:}); func = @(x)objective_function(x,varargin{:});
[opt_par_values,Resnorm,fval,exitflag,OUTPUT,LAMBDA,JACOB] = lsqnonlin(func,start_par_value,bounds(:,1),bounds(:,2),optim_options); [opt_par_values,Resnorm,fval,exitflag,OUTPUT,LAMBDA,JACOB] = lsqnonlin(func,start_par_value,bounds(:,1),bounds(:,2),optim_options);
end end
otherwise otherwise
if ischar(minimizer_algorithm) if ischar(minimizer_algorithm)
if exist(minimizer_algorithm) if exist(minimizer_algorithm)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment