Commit da8638cc authored by stepan's avatar stepan
Browse files

* Added the possibility to use the matlab's simplex routine for

minimizing the objective function.
* Added a test for the platform (parellelized version of SMM is 
only implemented for linux).
* Added upper and lower bounds for the estimated parameters. A 
penalty is defined when a vector of parameters does not satisfy 
the upper and lower bounds.
* Cosmetic changes.



git-svn-id: https://www.dynare.org/svn/dynare/trunk@3342 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 5dbb4fa1
......@@ -52,14 +52,18 @@ param = [];
% Set up parallel mode if needed.
if nargin>3
[junk,hostname] = unix('hostname --fqdn');
if ~isunix
error('The parallel version of SMM estimation is not implemented for non unix platforms!')
end
disp(' ')
disp('Master talks to its slaves...')
disp(' ')
[junk,hostname] = unix('hostname --fqdn');
hostname = deblank(hostname);
% Save the workspace.
save('master_variables.mat','options_','M_','oo_');
% Send the workspace to each remote computer.
for i=1:3
disp(' ')
end
disp('')
for i = 1:length(parallel)
if ~strcmpi(hostname,parallel(i).machine)
unix(['scp master_variables.mat ' , parallel(i).login , '@' , parallel(i).machine , ':' parallel(i).folder]);
......@@ -130,33 +134,43 @@ if nargin>3
end
end
end
disp(' ')
disp('... And slaves do as ordered.')
disp(' ')
if exist('intermediary_results_from_master_and_slaves','dir')
unix('rm -rf intermediary_results_from_master_and_slaves');
end
unix('mkdir intermediary_results_from_master_and_slaves');
unix('chmod -R u+x intermediary_results_from_master_and_slaves');
end
if exist('intermediary_results_from_master_and_slaves','dir')
unix('rm -rf intermediary_results_from_master_and_slaves');
end
unix('mkdir intermediary_results_from_master_and_slaves');
unix('chmod -R u+x intermediary_results_from_master_and_slaves');
% Set options for csminwel.
H0 = 1e-4*eye(options.estimated_parameters.nb);
ct = 1e-4;
it = 1000;
vb = 2;
% Minimization of the objective function.
if nargin==3
[fval,param,grad,hessian_csminwel,itct,fcount,retcodehat] = ...
csminwel('smm_objective',xparam,H0,[],ct,it,2,options_.gradient_epsilon,sample_moments,weighting_matrix,options);
elseif nargin>3
[fval,param,grad,hessian_csminwel,itct,fcount,retcodehat] = ...
csminwel('smm_objective',xparam,H0,[],ct,it,2,options_.gradient_epsilon,sample_moments,weighting_matrix,options,parallel);
disp('');
if options.optimization_routine==1
% Set options for csminwel.
H0 = 1e-4*eye(options.estimated_parameters.nb);
ct = 1e-4;
it = 1000;
vb = 2;
% Minimization of the objective function.
if nargin==3
[fval,param,grad,hessian_csminwel,itct,fcount,retcodehat] = ...
csminwel('smm_objective',xparam,H0,[],ct,it,2,options_.gradient_epsilon,sample_moments,weighting_matrix,options);
elseif nargin>3
[fval,param,grad,hessian_csminwel,itct,fcount,retcodehat] = ...
csminwel('smm_objective',xparam,H0,[],ct,it,2,options_.gradient_epsilon,sample_moments,weighting_matrix,options,parallel);
end
elseif options.optimization_routine==2
optim_options = optimset('display','iter','MaxFunEvals',1000000,'MaxIter',6000,'TolFun',1e-4,'TolX',1e-4);
if isfield(options_,'optim_opt')
eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']);
end
if nargin==3
[param,fval,exitflag] = fminsearch('smm_objective',xparam,optim_options,sample_moments,weighting_matrix,options);
else
[param,fval,exitflag] = fminsearch('smm_objective',xparam,optim_options,sample_moments,weighting_matrix,options,parallel);
end
end
function write_job(hostname, remotename, dynare_path, sample_size, number_of_moments, observed_variables_idx, parameters_idx, burn_in_periods, moments_file_name, number_of_simulations,threads_per_job, slave_number, job_number)
......
......@@ -51,6 +51,22 @@ if isempty(priorObjectiveValue)
priorObjectiveValue = Inf;
end
penalty = 0;
for i=1:options.estimated_parameters.nb
if ~isnan(options.estimated_parameters.upper_bound(i)) && xparams(i)>options.estimated_parameters.upper_bound(i)
penalty = penalty + (xparams(i)-options.estimated_parameters.upper_bound(i))^2;
end
if ~isnan(options.estimated_parameters.lower_bound(i)) && xparams(i)<options.estimated_parameters.lower_bound(i)
penalty = penalty + (xparams(i)-options.estimated_parameters.lower_bound(i))^2;
end
end
if penalty>0
flag = 0;
r = priorObjectiveValue + penalty;
return;
end
save('estimated_parameters.mat','xparams');
% Check for local determinacy of the deterministic steady state.
......@@ -76,6 +92,9 @@ if nargin<5
simulated_moments = simulated_moments / options.number_of_simulated_sample;
end
else% parallel mode.
if ~isunix
error('The parallel version of SMM estimation is not implemented for non unix platforms!')
end
[Junk,hostname] = unix('hostname --fqdn');
hostname = deblank(hostname);
job_number = 0;
......@@ -91,7 +110,7 @@ else% parallel mode.
% Send the new values of the estimated parameters to the slave.
if j==1 && ~strcmpi(hostname,parallel(i).machine)
% The slave is on a remote computer.
unix(['scp estimated_parameters.mat ' , parallel(i).login , '@' , parallel(i).machine , ':' parallel(i).folder]);
unix(['scp estimated_parameters.mat ' , parallel(i).login , '@' , parallel(i).machine , ':' parallel(i).folder ' > /dev/null']);
elseif j==2 && strcmpi(hostname,parallel(i).machine) && ~strcmpi(pwd,parallel(i).folder)
% The slave is on this computer but not in the same directory as the master.
unix(['cp estimated_parameters.mat ' , parallel(i).folder]);
......
Supports Markdown
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