Do not systematically throw an errror message if the parameters in the provided mode_file does not exactly match the set of estimated parameters.
If some parameters are missing in the provided mode_file and if mode_compute>0, use the prior mean as an initial condition.time-shift
parent
4afcf8fdaf
commit
f16689e76f
|
@ -134,10 +134,14 @@ if ~isempty(estim_params_) && ~isempty(options_.mode_file) && ~options_.mh_poste
|
||||||
skipline()
|
skipline()
|
||||||
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
|
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
|
||||||
disp(['Your mode file contains estimates for ' int2str(length(mode_file.xparam1)) ' parameters, while you are attempting to estimate ' int2str(number_of_estimated_parameters) ' parameters:'])
|
disp(['Your mode file contains estimates for ' int2str(length(mode_file.xparam1)) ' parameters, while you are attempting to estimate ' int2str(number_of_estimated_parameters) ' parameters:'])
|
||||||
|
md = []; xd = [];
|
||||||
for i=1:number_of_estimated_parameters
|
for i=1:number_of_estimated_parameters
|
||||||
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
|
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
|
||||||
if isempty(id)
|
if isempty(id)
|
||||||
disp(['--> Estimated parameter ' bayestopt_.name{i} ' is not present in the loaded mode file.'])
|
disp(['--> Estimated parameter ' bayestopt_.name{i} ' is not present in the loaded mode file (prior mean will be used, if possible).'])
|
||||||
|
else
|
||||||
|
xd = [xd; i];
|
||||||
|
md = [md; id];
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=1:length(mode_file.xparam1)
|
for i=1:length(mode_file.xparam1)
|
||||||
|
@ -146,21 +150,30 @@ if ~isempty(estim_params_) && ~isempty(options_.mode_file) && ~options_.mh_poste
|
||||||
disp(['--> Parameter ' mode_file.parameter_names{i} ' is not estimated according to the current mod file.'])
|
disp(['--> Parameter ' mode_file.parameter_names{i} ' is not estimated according to the current mod file.'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
error('Please change the mode_file option or the list of estimated parameters.')
|
if ~options_.mode_compute
|
||||||
|
% The posterior mode is not estimated.
|
||||||
|
error('Please change the mode_file option, the list of estimated parameters or set mode_compute>0.')
|
||||||
|
else
|
||||||
|
% The posterior mode is estimated, the Hessian evaluated at the mode is not needed so we set values for the parameters missing in the mode file using the prior mean.
|
||||||
|
if ~isempty(xd)
|
||||||
|
xparam1(xd) = mode_file.xparam1(md);
|
||||||
|
else
|
||||||
|
error('Please remove the mode_file option.')
|
||||||
|
end
|
||||||
|
end
|
||||||
elseif number_of_estimated_parameters<length(mode_file.xparam1)
|
elseif number_of_estimated_parameters<length(mode_file.xparam1)
|
||||||
% Less estimated parameters than parameters in the mode file.
|
% Less estimated parameters than parameters in the mode file.
|
||||||
skipline()
|
skipline()
|
||||||
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
|
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
|
||||||
disp(['Your mode file contains estimates for ' int2str(length(mode_file.xparam1)) ' parameters, while you are attempting to estimate only ' int2str(number_of_estimated_parameters) ' parameters:'])
|
disp(['Your mode file contains estimates for ' int2str(length(mode_file.xparam1)) ' parameters, while you are attempting to estimate only ' int2str(number_of_estimated_parameters) ' parameters:'])
|
||||||
Id = [];
|
md = []; xd = [];
|
||||||
for i=1:number_of_estimated_parameters
|
for i=1:number_of_estimated_parameters
|
||||||
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
|
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
|
||||||
if isempty(id)
|
if isempty(id)
|
||||||
disp(['--> Estimated parameter ' deblank(bayestopt_.name(i,:)) ' is not present in the loaded mode file.'])
|
disp(['--> Estimated parameter ' deblank(bayestopt_.name(i,:)) ' is not present in the loaded mode file (prior mean will be used, if possible).'])
|
||||||
Id = [];
|
|
||||||
break
|
|
||||||
else
|
else
|
||||||
Id = [Id; id];
|
xd = [xd; i];
|
||||||
|
md = [md; id];
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=1:length(mode_file.xparam1)
|
for i=1:length(mode_file.xparam1)
|
||||||
|
@ -169,60 +182,73 @@ if ~isempty(estim_params_) && ~isempty(options_.mode_file) && ~options_.mh_poste
|
||||||
disp(['--> Parameter ' mode_file.parameter_names{i} ' is not estimated according to the current mod file.'])
|
disp(['--> Parameter ' mode_file.parameter_names{i} ' is not estimated according to the current mod file.'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if isempty(Id)
|
if ~options_.mode_compute
|
||||||
% None of the estimated parameters are present in the mode_file.
|
% The posterior mode is not estimated. If possible, fix the mode_file.
|
||||||
error('Please change the mode_file option or the list of estimated parameters.')
|
if isequal(length(xd),number_of_estimated_parameters)
|
||||||
else
|
|
||||||
% If possible, fix the mode_file.
|
|
||||||
if isequal(length(Id),number_of_estimated_parameters)
|
|
||||||
disp('==> Fix mode file (remove unused parameters).')
|
disp('==> Fix mode file (remove unused parameters).')
|
||||||
mode_file.parameter_names = mode_file.parameter_names(Id,:);
|
xparam1 = mode_file.xparam1(md);
|
||||||
mode_file.xparam1 = mode_file.xparam1(Id);
|
|
||||||
if isfield(mode_file,'hh')
|
if isfield(mode_file,'hh')
|
||||||
mode_file.hh = mode_file.hh(Id,Id);
|
hh = mode_file.hh(md,md);
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
error('Please change the mode_file option, the list of estimated parameters or set mode_compute>0.')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
% The posterior mode is estimated, the Hessian evaluated at the mode is not needed so we set values for the parameters missing in the mode file using the prior mean.
|
||||||
|
if ~isempty(xd)
|
||||||
|
xparam1(xd) = mode_file.xparam1(md);
|
||||||
|
else
|
||||||
|
% None of the estimated parameters are present in the mode_file.
|
||||||
|
error('Please remove the mode_file option.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
% The number of declared estimated parameters match the number of parameters in the mode file.
|
% The number of declared estimated parameters match the number of parameters in the mode file.
|
||||||
% Check that the parameters in the mode file and according to the current mod file are identical.
|
% Check that the parameters in the mode file and according to the current mod file are identical.
|
||||||
if isequal(mode_file.parameter_names, bayestopt_.name)
|
if isequal(mode_file.parameter_names, bayestopt_.name)
|
||||||
% Ok! Nothing to do here.
|
xparam1 = mode_file.xparam1;
|
||||||
|
if isfield(mode_file,'hh')
|
||||||
|
hh = mode_file.hh;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
skipline()
|
skipline()
|
||||||
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
|
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
|
||||||
% Check if this only an ordering issue.
|
% Check if this only an ordering issue or if the missing parameters can be initialized with the prior mean.
|
||||||
Id = [];
|
md = []; xd = [];
|
||||||
for i=1:number_of_estimated_parameters
|
for i=1:number_of_estimated_parameters
|
||||||
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
|
id = strmatch(deblank(bayestopt_.name(i,:)), mode_file.parameter_names,'exact');
|
||||||
if isempty(id)
|
if isempty(id)
|
||||||
disp(['--> Estimated parameter ' bayestopt_.name{i} ' is not present in the loaded mode file.'])
|
disp(['--> Estimated parameter ' bayestopt_.name{i} ' is not present in the loaded mode file.'])
|
||||||
Id = [];
|
|
||||||
break
|
|
||||||
else
|
else
|
||||||
Id = [Id; id];
|
xd = [xd; i];
|
||||||
|
md = [md; id];
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if isempty(Id)
|
if ~options_.mode_compute
|
||||||
% None of the estimated parameters are present in the mode_file.
|
% The posterior mode is not estimated
|
||||||
error('Please change the mode_file option or the list of estimated parameters.')
|
if isequal(length(xd), number_of_estimated_parameters)
|
||||||
else
|
% This is an ordering issue.
|
||||||
% If possible, fix the mode_file.
|
xparam1 = mode_file.xparam1(md);
|
||||||
if isequal(length(Id),number_of_estimated_parameters)
|
|
||||||
disp('==> Fix mode file (reorder the parameters).')
|
|
||||||
mode_file.parameter_names = mode_file.parameter_names(Id,:);
|
|
||||||
mode_file.xparam1 = mode_file.xparam1(Id);
|
|
||||||
if isfield(mode_file,'hh')
|
if isfield(mode_file,'hh')
|
||||||
mode_file.hh = mode_file.hh(Id,Id);
|
hh = mode_file.hh(md,md);
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
error('Please change the mode_file option, the list of estimated parameters or set mode_compute>0.')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
% The posterior mode is estimated, the Hessian evaluated at the mode is not needed so we set values for the parameters missing in the mode file using the prior mean.
|
||||||
|
if ~isempty(xd)
|
||||||
|
xparam1(xd) = mode_file.xparam1(md);
|
||||||
|
if isfield(mode_file,'hh')
|
||||||
|
hh(xd,xd) = mode_file.hh(md,md);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
% None of the estimated parameters are present in the mode_file.
|
||||||
|
error('Please remove the mode_file option.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
xparam1 = mode_file.xparam1;
|
|
||||||
if isfield(mode_file,'hh')
|
|
||||||
hh = mode_file.hh;
|
|
||||||
end
|
|
||||||
skipline()
|
skipline()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue