Commit 383b12df authored by Houtan Bastani's avatar Houtan Bastani
Browse files

ms-sbvar bugfix: change the way options are passed to irf, forecast and...

ms-sbvar bugfix: change the way options are passed to irf, forecast and variance decomposition mex functions
parent 4e8dcc1a
...@@ -68,6 +68,6 @@ mexErrCheck('ms_estimation', err); ...@@ -68,6 +68,6 @@ mexErrCheck('ms_estimation', err);
[options_, oo_] = set_ms_estimation_file(options_, oo_); [options_, oo_] = set_ms_estimation_file(options_, oo_);
[err, oo_.ms.A0, oo_.ms.Aplus, oo_.ms.Zeta, oo_.ms.Q] = ... [err, oo_.ms.A0, oo_.ms.Aplus, oo_.ms.Zeta, oo_.ms.Q] = ...
mex_ms_convert_free_parameters(options_.ms.estimation_file_tag, oo_.ms.maxparams); mex_ms_convert_free_parameters({{'file_tag',options_.ms.estimation_file_tag}}, oo_.ms.maxparams);
mexErrCheck('mex_ms_convert_free_parameters', err); mexErrCheck('mex_ms_convert_free_parameters', err);
end end
...@@ -39,30 +39,36 @@ clean_files_for_second_type_of_mex(M_, options_, 'forecast') ...@@ -39,30 +39,36 @@ clean_files_for_second_type_of_mex(M_, options_, 'forecast')
forecastdir = [options_.ms.output_file_tag filesep 'Forecast']; forecastdir = [options_.ms.output_file_tag filesep 'Forecast'];
create_dir(forecastdir); create_dir(forecastdir);
opt = {options_.ms.estimation_file_tag, ... opt = { ...
'seed', options_.DynareRandomStreams.seed, ... {'file_tag', options_.ms.estimation_file_tag}, ...
'horizon', options_.ms.horizon, ... {'seed', options_.DynareRandomStreams.seed}, ...
'number_observations',options_.ms.forecast_data_obs ... {'horizon', options_.ms.horizon}, ...
'error_bands', options_.ms.error_bands, ... {'number_observations', options_.ms.forecast_data_obs}, ...
'percentiles', options_.ms.error_band_percentiles, ... {'error_bands', options_.ms.error_bands}, ...
'thin', options_.ms.thinning_factor }; {'percentiles', options_.ms.error_band_percentiles}, ...
{'thin', options_.ms.thinning_factor}
};
[err, forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shock_draws); [err, forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks_per_parameter', options_.ms.shock_draws}}]);
mexErrCheck('mex_ms_forecast ergodic ', err); mexErrCheck('mex_ms_forecast ergodic ', err);
plot_ms_forecast(M_,options_,forecast,'Forecast',options_.graph_save_formats,options_.TeX); plot_ms_forecast(M_,options_,forecast,'Forecast',options_.graph_save_formats,options_.TeX);
[err, regime_forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shock_draws,'regimes'); [err, regime_forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks_per_parameter', options_.ms.shock_draws}, {'regimes'}}]);
mexErrCheck('mex_ms_forecast ergodic regimes', err); mexErrCheck('mex_ms_forecast ergodic regimes', err);
save([forecastdir filesep 'ergodic_forecast.mat'], 'forecast', 'regime_forecast'); save([forecastdir filesep 'ergodic_forecast.mat'], 'forecast', 'regime_forecast');
if exist(options_.ms.mh_file,'file') > 0 if exist(options_.ms.mh_file,'file') > 0
[err, forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shocks_per_parameter, ... [err, forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
'simulation_file',options_.ms.mh_file,'parameter_uncertainty'); {'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
{'simulation_file', options_.ms.mh_file}, {'parameter_uncertainty'}}]);
mexErrCheck('mex_ms_forecast bayesian ', err); mexErrCheck('mex_ms_forecast bayesian ', err);
plot_ms_forecast(M_,options_,forecast,'Forecast w/ Parameter Uncertainty',options_.graph_save_formats,options_.TeX); plot_ms_forecast(M_,options_,forecast,'Forecast w/ Parameter Uncertainty',options_.graph_save_formats,options_.TeX);
[err, regime_forecast] = mex_ms_forecast(opt{:},'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shocks_per_parameter, ... [err, regime_forecast] = mex_ms_forecast([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
'simulation_file',options_.ms.mh_file,'parameter_uncertainty','regimes'); {'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
{'simulation_file', options_.ms.mh_file}, {'parameter_uncertainty','regimes'}}]);
mexErrCheck('mex_ms_forecast bayesian regimes ', err); mexErrCheck('mex_ms_forecast bayesian regimes ', err);
save([forecastdir filesep 'bayesian_forecast.mat'], 'forecast', 'regime_forecast'); save([forecastdir filesep 'bayesian_forecast.mat'], 'forecast', 'regime_forecast');
end end
......
...@@ -40,19 +40,21 @@ clean_files_for_second_type_of_mex(M_, options_, 'irf') ...@@ -40,19 +40,21 @@ clean_files_for_second_type_of_mex(M_, options_, 'irf')
irfdir = [options_.ms.output_file_tag filesep 'IRF']; irfdir = [options_.ms.output_file_tag filesep 'IRF'];
create_dir(irfdir); create_dir(irfdir);
opt = {options_.ms.estimation_file_tag, ... opt = { ...
'seed', options_.DynareRandomStreams.seed, ... {'file_tag', options_.ms.estimation_file_tag}, ...
'horizon', options_.ms.horizon, ... {'seed', options_.DynareRandomStreams.seed}, ...
'filtered', options_.ms.filtered_probabilities, ... {'horizon', options_.ms.horizon}, ...
'error_bands', options_.ms.error_bands, ... {'filtered', options_.ms.filtered_probabilities}, ...
'percentiles', options_.ms.error_band_percentiles, ... {'error_bands', options_.ms.error_bands}, ...
'thin', options_.ms.thinning_factor }; {'percentiles', options_.ms.error_band_percentiles}, ...
{'thin', options_.ms.thinning_factor}
};
[err, irf] = mex_ms_irf(opt{:}, 'free_parameters', oo_.ms.maxparams, 'shocks_per_parameter', options_.ms.shock_draws); [err, irf] = mex_ms_irf([opt(:)', {{'free_parameters', oo_.ms.maxparams}, {'shocks_per_parameter', options_.ms.shock_draws}}]);
mexErrCheck('mex_ms_irf ergodic ', err); mexErrCheck('mex_ms_irf ergodic ', err);
plot_ms_irf(M_,options_,irf,options_.varobs,'Ergodic Impulse Responses',varlist); plot_ms_irf(M_,options_,irf,options_.varobs,'Ergodic Impulse Responses',varlist);
[err, regime_irfs] = mex_ms_irf(opt{:}, 'free_parameters',oo_.ms.maxparams,'shocks_per_parameter', options_.ms.shock_draws,'regimes'); [err, regime_irfs] = mex_ms_irf([opt(:)', {{'free_parameters',oo_.ms.maxparams}, {'shocks_per_parameter', options_.ms.shock_draws}, {'regimes'}}]);
mexErrCheck('mex_ms_irf ergodic regimes ',err); mexErrCheck('mex_ms_irf ergodic regimes ',err);
for i=1:size(regime_irfs,1) for i=1:size(regime_irfs,1)
plot_ms_irf(M_,options_,squeeze(regime_irfs(i,:,:,:)),options_.varobs,['Ergodic ' ... plot_ms_irf(M_,options_,squeeze(regime_irfs(i,:,:,:)),options_.varobs,['Ergodic ' ...
...@@ -61,13 +63,13 @@ end ...@@ -61,13 +63,13 @@ end
save([irfdir filesep 'ergodic_irf.mat'], 'irf', 'regime_irfs'); save([irfdir filesep 'ergodic_irf.mat'], 'irf', 'regime_irfs');
if exist(options_.ms.mh_file,'file') > 0 if exist(options_.ms.mh_file,'file') > 0
[err, irf] = mex_ms_irf(opt{:}, 'shocks_per_parameter', options_.ms.shocks_per_parameter, ... [err, irf] = mex_ms_irf([opt(:)', {{'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
'parameter_uncertainty','simulation_file',options_.ms.mh_file); {'parameter_uncertainty'},{'simulation_file',options_.ms.mh_file}}]);
mexErrCheck('mex_ms_irf bayesian ',err); mexErrCheck('mex_ms_irf bayesian ',err);
plot_ms_irf(M_,options_,irf,options_.varobs,'Impulse Responses with Parameter Uncertainty',varlist); plot_ms_irf(M_,options_,irf,options_.varobs,'Impulse Responses with Parameter Uncertainty',varlist);
[err, regime_irfs] = mex_ms_irf(opt{:}, 'shocks_per_parameter', options_.ms.shocks_per_parameter, ... [err, regime_irfs] = mex_ms_irf([opt(:)', {{'shocks_per_parameter', options_.ms.shocks_per_parameter}, ...
'simulation_file',options_.ms.mh_file,'parameter_uncertainty','regimes'); {'simulation_file',options_.ms.mh_file},{'parameter_uncertainty'},{'regimes'}}]);
mexErrCheck('mex_ms_irf bayesian regimes ',err); mexErrCheck('mex_ms_irf bayesian regimes ',err);
for i=1:size(regime_irfs,1) for i=1:size(regime_irfs,1)
plot_ms_irf(M_,options_,squeeze(regime_irfs(i,:,:,:)),options_.varobs,['Impulse ' ... plot_ms_irf(M_,options_,squeeze(regime_irfs(i,:,:,:)),options_.varobs,['Impulse ' ...
......
...@@ -41,28 +41,34 @@ create_dir(vddir); ...@@ -41,28 +41,34 @@ create_dir(vddir);
% NOTICE THAT VARIANCE DECOMPOSITION DEFAULTS TO USING THE MEAN, NOT MEDIAN OR BANDED % NOTICE THAT VARIANCE DECOMPOSITION DEFAULTS TO USING THE MEAN, NOT MEDIAN OR BANDED
opt = {options_.ms.estimation_file_tag, ... opt = {
'seed', options_.DynareRandomStreams.seed, ... {'file_tag', options_.ms.estimation_file_tag}, ...
'horizon', options_.ms.horizon, ... {'seed', options_.DynareRandomStreams.seed}, ...
'filtered', options_.ms.filtered_probabilities, ... {'horizon', options_.ms.horizon}, ...
'error_bands', options_.ms.error_bands, ... {'filtered', options_.ms.filtered_probabilities}, ...
'percentiles', options_.ms.error_band_percentiles, ... {'error_bands', options_.ms.error_bands}, ...
'thin', options_.ms.thinning_factor, ... {'percentiles', options_.ms.error_band_percentiles}, ...
'mean'}; {'thin', options_.ms.thinning_factor}, ...
{'mean'} ...
};
[err, vd] = mex_ms_variance_decomposition(opt{:},'free_parameters',oo_.ms.maxparams,'shocks',options_.ms.shock_draws); [err, vd] = mex_ms_variance_decomposition([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks', options_.ms.shock_draws}}]);
mexErrCheck('mex_ms_variance_decomposition ergodic ', err); mexErrCheck('mex_ms_variance_decomposition ergodic ', err);
plot_ms_variance_decomposition(M_,options_,vd, 'Ergodic Variance Decomposition',options_.graph_save_formats,options_.TeX); plot_ms_variance_decomposition(M_,options_,vd, 'Ergodic Variance Decomposition',options_.graph_save_formats,options_.TeX);
[err, regime_vd] = mex_ms_variance_decomposition(opt{:},'free_parameters',oo_.ms.maxparams,'shocks',options_.ms.shock_draws,'regimes'); [err, regime_vd] = mex_ms_variance_decomposition([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
{'shocks', options_.ms.shock_draws}, {'regimes'}}]);
mexErrCheck('mex_ms_variance_decomposition ergodic regimes', err); mexErrCheck('mex_ms_variance_decomposition ergodic regimes', err);
save([vddir filesep 'ergodic_vd.mat'], 'vd', 'regime_vd'); save([vddir filesep 'ergodic_vd.mat'], 'vd', 'regime_vd');
if exist(options_.ms.mh_file,'file') > 0 if exist(options_.ms.mh_file,'file') > 0
[err, vd] = mex_ms_variance_decomposition(opt{:},'simulation_file',options_.ms.mh_file,'shocks',options_.ms.shocks_per_parameter,'parameter_uncertainty'); [err, vd] = mex_ms_variance_decomposition([opt(:)', {{'simulation_file',options_.ms.mh_file}, ...
{'shocks', options_.ms.shocks_per_parameter}, {'parameter_uncertainty'}}]);
mexErrCheck('mex_ms_variance_decomposition bayesian ', err); mexErrCheck('mex_ms_variance_decomposition bayesian ', err);
[err, regime_vd] = mex_ms_variance_decomposition(opt{:},'simulation_file',options_.ms.mh_file,'shocks',options_.ms.shocks_per_parameter,'parameter_uncertainty','regimes'); [err, regime_vd] = mex_ms_variance_decomposition([opt(:)', {{'simulation_file',options_.ms.mh_file}, ...
{'shocks', options_.ms.shocks_per_parameter}, {'parameter_uncertainty'}, {'regimes'}}]);
mexErrCheck('mex_ms_variance_decomposition bayesian regimes ', err); mexErrCheck('mex_ms_variance_decomposition bayesian regimes ', err);
save([vddir filesep 'bayesian_vd.mat'], 'vd', 'regime_vd'); save([vddir filesep 'bayesian_vd.mat'], 'vd', 'regime_vd');
end end
......
...@@ -37,9 +37,6 @@ void ...@@ -37,9 +37,6 @@ void
mexFunction(int nlhs, mxArray *plhs[], mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) int nrhs, const mxArray *prhs[])
{ {
using namespace std;
char *input_buf;
double *free_parameters; double *free_parameters;
int nvars, npre, nstates, nfree; int nvars, npre, nstates, nfree;
double *aplus = NULL, *a0 = NULL, *zeta = NULL, *q = NULL; double *aplus = NULL, *a0 = NULL, *zeta = NULL, *q = NULL;
...@@ -48,23 +45,18 @@ mexFunction(int nlhs, mxArray *plhs[], ...@@ -48,23 +45,18 @@ mexFunction(int nlhs, mxArray *plhs[],
SbvarOption *options = NULL; SbvarOption *options = NULL;
/* input must be a string */ /* input must be a string */
if (mxIsChar(prhs[0]) != 1) if (nrhs !=2)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename."); DYN_MEX_FUNC_ERR_MSG_TXT("This function takes exactly two arguments");
if (!mxIsDouble(prhs[1])) if (!mxIsDouble(prhs[1]))
DYN_MEX_FUNC_ERR_MSG_TXT("Second argument is a vector of free parameters"); DYN_MEX_FUNC_ERR_MSG_TXT("Second argument is a vector of free parameters");
if (nlhs < 4) if (nlhs < 4)
DYN_MEX_FUNC_ERR_MSG_TXT("You must specify at least four output arguments [err,A0,Aplus,Zeta]"); DYN_MEX_FUNC_ERR_MSG_TXT("You must specify at least four output arguments [err,A0,Aplus,Zeta]");
// copy the string data from prhs[0] into a C string input_ buf. */
input_buf = mxArrayToString(prhs[0]);
if (input_buf == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("Could not convert input to string.");
// second element should be vector of free parameters */ // second element should be vector of free parameters */
free_parameters = mxGetPr(prhs[1]); free_parameters = mxGetPr(prhs[1]);
model = initialize_model_and_options(input_buf, &options, nrhs, prhs, &nstates, &nvars, &npre, &nfree); model = initialize_model_and_options(&options, prhs, &nstates, &nvars, &npre, &nfree);
if (model == NULL || options == NULL) if (model == NULL || options == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue"); DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue");
......
...@@ -36,10 +36,6 @@ void ...@@ -36,10 +36,6 @@ void
mexFunction(int nlhs, mxArray *plhs[], mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) int nrhs, const mxArray *prhs[])
{ {
using namespace std;
char *input_buf;
double *out_buf; double *out_buf;
int i, j, k, s, nfree, nstates, nvars, npre, T; int i, j, k, s, nfree, nstates, nvars, npre, T;
...@@ -52,16 +48,12 @@ mexFunction(int nlhs, mxArray *plhs[], ...@@ -52,16 +48,12 @@ mexFunction(int nlhs, mxArray *plhs[],
int type = F_FREE; int type = F_FREE;
// Check the left hand and right hand side arguments to make sure they conform // Check the left hand and right hand side arguments to make sure they conform
if (mxIsChar(prhs[0]) != 1) if (nrhs != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename."); DYN_MEX_FUNC_ERR_MSG_TXT("ms_forecast takes one cell array as an input argument.");
if (nlhs != 2) if (nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("You must specify two output arguments."); DYN_MEX_FUNC_ERR_MSG_TXT("You must specify two output arguments.");
// copy the string data from prhs[0] into a C string input_ buf. */ model = initialize_model_and_options(&options, prhs, &nstates, &nvars, &npre, &nfree);
input_buf = mxArrayToString(prhs[0]);
if (input_buf == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("Could not convert input to string.");
model = initialize_model_and_options(input_buf, &options, nrhs, prhs, &nstates, &nvars, &npre, &nfree);
if (model == NULL || options == NULL) if (model == NULL || options == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue"); DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue");
......
...@@ -36,8 +36,6 @@ void ...@@ -36,8 +36,6 @@ void
mexFunction(int nlhs, mxArray *plhs[], mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) int nrhs, const mxArray *prhs[])
{ {
char *input_buf;
double *out_buf; double *out_buf;
int i, j, k, s, nfree, nstates, nvars, npre; int i, j, k, s, nfree, nstates, nvars, npre;
...@@ -50,16 +48,13 @@ mexFunction(int nlhs, mxArray *plhs[], ...@@ -50,16 +48,13 @@ mexFunction(int nlhs, mxArray *plhs[],
int type = F_FREE, ergodic = 1; int type = F_FREE, ergodic = 1;
// Check the left hand and right hand side arguments to make sure they conform // Check the left hand and right hand side arguments to make sure they conform
if (mxIsChar(prhs[0]) != 1) if (nrhs != 1)
DYN_MEX_FUNC_ERR_MSG_TXT("First argument has to be a string to the init_filename."); DYN_MEX_FUNC_ERR_MSG_TXT("ms_irf takes one cell array as an input argument.");
if (nlhs != 2) if (nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("You must specify two output arguments."); DYN_MEX_FUNC_ERR_MSG_TXT("You must specify two output arguments.");
// copy the string data from prhs[0] into a C string input_ buf. */ // copy the string data from prhs[0] into a C string input_ buf.
input_buf = mxArrayToString(prhs[0]); model = initialize_model_and_options(&options, prhs, &nstates, &nvars, &npre, &nfree);
if (input_buf == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("Could not convert input to string.");
model = initialize_model_and_options(input_buf, &options, nrhs, prhs, &nstates, &nvars, &npre, &nfree);
if (model == NULL || options == NULL) if (model == NULL || options == NULL)
DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue"); DYN_MEX_FUNC_ERR_MSG_TXT("There was a problem initializing the model, can not continue");
......
...@@ -348,205 +348,182 @@ initialize_sbvar_options(char *file_tag) ...@@ -348,205 +348,182 @@ initialize_sbvar_options(char *file_tag)
} }
int int
set_options(SbvarOption *options, int nrhs, const mxArray *prhs[]) set_options(SbvarOption *options, const mxArray *prhs[])
{ {
if (options == NULL) if (options == NULL)
options = initialize_sbvar_options((char *) NULL); options = initialize_sbvar_options((char *) NULL);
int i, buf_len, buf_len2;
char *input_buf = NULL;
double *temp_buf; double *temp_buf;
bool shocks_passed = false; bool shocks_passed = false;
int num_options = mxGetN(prhs[0]);
/* deal with optional arguments */ for (int i = 1; i < num_options; i++)
for (i = 0; i < nrhs; i++)
{ {
if (mxIsChar(prhs[i]) == 1) mxArray *this_option = mxGetCell(prhs[0],i);
char *option_name_c = mxArrayToString(mxGetCell(this_option,0));
string option_name (option_name_c);
mxArray *this_option_value = NULL;
if (mxGetN(this_option) > 1)
this_option_value = mxGetCell(this_option,1);
if (option_name == "horizon")
if (this_option_value && mxIsNumeric(this_option_value))
{
temp_buf = (double *) mxGetData(this_option_value);
options->horizon = (int) temp_buf[0];
}
else
{
cout << "You must pass an integer after specifying the 'horizon' option" << endl;
return 1;
}
else if (option_name == "filtered")
options->filtered_probabilities = true;
else if (option_name == "error_bands")
{ {
buf_len = mxGetN(prhs[i])*sizeof(mxChar)+1; free(options->percentiles);
input_buf = (char *) mxMalloc(buf_len); options->num_percentiles = 3;
mxGetString(prhs[i], input_buf, buf_len); options->percentiles = new double[3];
options->percentiles[0] = 0.16;
if (strstr(input_buf, "horizon")) options->percentiles[1] = 0.5;
{ options->percentiles[2] = 0.84;
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
{ // Check if the user specified to turn off error bands
temp_buf = (double *) mxGetData(prhs[i+1]); if (this_option_value && mxIsNumeric(this_option_value))
options->horizon = (int) temp_buf[0];
}
else
{
printf("You must pass an integer after specifying the 'horizon' option");
return 1;
}
}
else if (strstr(input_buf, "filtered"))
options->filtered_probabilities = true;
else if (strstr(input_buf, "error_bands"))
{
free(options->percentiles);
options->num_percentiles = 3;
options->percentiles = new double[3];
options->percentiles[0] = 0.16;
options->percentiles[1] = 0.5;
options->percentiles[2] = 0.84;
// Check if the specified to turn off error bands
if (nrhs > i+1)
if (mxIsNumeric(prhs[i+1]))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
if (temp_buf[0] == 0)
{
options->num_percentiles = 1;
options->percentiles = new double[1];
options->percentiles[0] = 0.50;
}
}
}
else if (strstr(input_buf, "median"))
{
free(options->percentiles);
options->num_percentiles = 1;
options->percentiles = new double[1];
options->percentiles[0] = 0.5;
}
else if (strstr(input_buf, "percentiles"))
{
if (nrhs >= i+1)
{
options->num_percentiles = mxGetN(prhs[i+1]) > mxGetM(prhs[i+1]) ? mxGetN(prhs[i+1]) : mxGetM(prhs[i+1]);
options->percentiles = mxGetPr(prhs[i+1]);
}
else
{
printf("You must pass a vector after the 'percentiles' argument with the percentiles that you want to have computed, ex 'percentiles',[.16 .5 .84]");
return 1;
}
}
else if (strstr(input_buf, "parameter_uncertainty"))
{
options->parameter_uncertainty = true;
if (shocks_passed == false)
options->shocks = 1;
}
else if (strstr(input_buf, "shocks") || strstr(input_buf, "shocks_per_parameter"))
{
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1]))
{
temp_buf = (double *) mxGetData(prhs[i+1]);
options->shocks = (int) temp_buf[0];
shocks_passed = true;
}
else
{
printf("You must pass an integer after specifying the 'shocks' option");
return 1;
}
}
else if (strstr(input_buf, "thin"))
{ {
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1])) temp_buf = (double *) mxGetData(this_option_value);
if (temp_buf[0] == 0)
{ {
temp_buf = (double *) mxGetData(prhs[i+1]); options->num_percentiles = 1;
options->thin = (int) temp_buf[0]; options->percentiles = new double[1];
options->percentiles[0] = 0.50;
} }
else
{
printf("You must pass an integer after specifying the 'thin' option");
return 1;
}
}
else if (strstr(input_buf, "simulation_file"))
{
buf_len2 = mxGetN(prhs[i+1])*sizeof(mxChar)+1;
char *posterior_filename = (char *) mxMalloc(buf_len2);
mxGetString(prhs[i+1], posterior_filename, buf_len2);
strcpy(options->simulation_filename, posterior_filename);
if (!(options->simulation_file = fopen(posterior_filename, "rt")))
{
printf("The posterior simulation file does not exist");
return 1;
}
} }
else if (strstr(input_buf, "regimes")) }
{ else if (option_name == "median")
options->regimes = true; {
free(options->percentiles);
} options->num_percentiles = 1;
else if (strstr(input_buf, "regime")) options->percentiles = new double[1];
{ options->percentiles[0] = 0.5;
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1])) }
{ else if (option_name == "percentiles")
temp_buf = (double *) mxGetData(prhs[i+1]); if (this_option_value)
options->regime = (int) temp_buf[0]; {
} options->num_percentiles = mxGetN(this_option_value)
else > mxGetM(this_option_value) ? mxGetN(this_option_value)
{ : mxGetM(this_option_value);
printf("You must pass an integer after specifying the 'regime' option, or alternatively you can specify 'regimes'"); options->percentiles = mxGetPr(this_option_value);
return 1; }
} else
{
} cout << "You must pass a vector after the 'percentiles' argument with the "
else if (strstr(input_buf, "number_observations")) << "percentiles that you want to have computed, ex "
{ << "'percentiles',[.16 .5 .84]" << endl;
if (nrhs >= i+1 && mxIsNumeric(prhs[i+1])) return 1;
{ }
temp_buf = (double *) mxGetData(prhs[i+1]); else if (option_name == "parameter_uncertainty")
options->number_observations = (int) temp_buf[0]; {
} options->parameter_uncertainty = true;
else if (shocks_passed == false)
{ options->shocks = 1;
printf("You must pass an integer after specifying the 'regime' option, or alternatively you can specify 'regimes'"); }
return 1; else if (option_name == "shocks" || option_name == "shocks_per_parameter")
} if (this_option_value && mxIsNumeric(this_option_value))
} {
else if (strstr(input_buf, "free_parameters")) temp_buf = (double *) mxGetData(this_option_value);
{ options->shocks = (