ms-sbvar: replace state with regime

time-shift
Houtan Bastani 2011-12-16 17:31:10 +01:00
parent 16e11d49df
commit 3ff704d36d
6 changed files with 17 additions and 17 deletions

View File

@ -52,7 +52,7 @@ function ms_write_markov_file(fname, options)
%//=====================================================//
fprintf(fh,'//== Number of states for state_variable[%d] ==//\n', ...
i_chain);
n_states = length(options.ms.ms_chain(i_chain).state);
n_states = length(options.ms.ms_chain(i_chain).regime);
fprintf(fh,'%d\n\n',n_states);
%//== 03/15/06: DW TVBVAR code reads the data below and overwrite the prior data read somewhere else if any.
@ -64,7 +64,7 @@ function ms_write_markov_file(fname, options)
i_chain);
Alpha = ones(n_states,n_states);
for i_state = 1:n_states
p = 1-1/options.ms.ms_chain(i_chain).state(i_state).duration;
p = 1-1/options.ms.ms_chain(i_chain).regime(i_state).duration;
Alpha(i_state,i_state) = p*(n_states-1)/(1-p);
fprintf(fh,'%22.16f',Alpha(i_state,:));
fprintf(fh,'\n');

View File

@ -31,7 +31,7 @@ function plot_ms_probabilities(computed_probabilities, options_)
[T,num_grand_regimes] = size(computed_probabilities);
num_chains = length(options_.ms.ms_chain);
for i=1:num_chains
chains(i).num_regimes = length(options_.ms.ms_chain(i).state);
chains(i).num_regimes = length(options_.ms.ms_chain(i).regime);
chains(i).probabilities = zeros([T,chains(i).num_regimes]);
end

View File

@ -1359,7 +1359,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(const OptionsList &options_li
void
MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename) const
{
OptionsList::num_options_t::const_iterator itChain, itState, itNOR, itDuration;
OptionsList::num_options_t::const_iterator itChain, itRegime, itNOR, itDuration;
itChain = options_list.num_options.find("ms.chain");
if (itChain == options_list.num_options.end())
@ -1375,15 +1375,15 @@ MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename) c
exit(EXIT_FAILURE);
}
itState = options_list.num_options.find("ms.state");
itRegime = options_list.num_options.find("ms.regime");
itNOR = options_list.num_options.find("ms.number_of_regimes");
if (itState != options_list.num_options.end()
if (itRegime != options_list.num_options.end()
&& itNOR == options_list.num_options.end())
output << "options_.ms.ms_chain(" << itChain->second << ").state(" << itState->second << ").duration = " << itDuration->second << ";" << endl;
else if (itState == options_list.num_options.end()
output << "options_.ms.ms_chain(" << itChain->second << ").regime(" << itRegime->second << ").duration = " << itDuration->second << ";" << endl;
else if (itRegime == options_list.num_options.end()
&& itNOR != options_list.num_options.end())
for (int i = 0; i < atoi(itNOR->second.c_str()); i++)
output << "options_.ms.ms_chain(" << itChain->second << ").state(" << i+1 << ").duration = " << itDuration->second << ";" << endl;
output << "options_.ms.ms_chain(" << itChain->second << ").regime(" << i+1 << ").duration = " << itDuration->second << ";" << endl;
else
{
cerr << "MarkovSwitchingStatement::writeOutput() Should not arrive here (3). Please report this to the Dynare Team." << endl;

View File

@ -156,7 +156,7 @@ class ParsingDriver;
%token SBVAR TREND_VAR DEFLATOR GROWTH_FACTOR MS_IRF MS_VARIANCE_DECOMPOSITION
%token MS_ESTIMATION MS_SIMULATION MS_COMPUTE_MDD MS_COMPUTE_PROBABILITIES MS_FORECAST
%token SVAR_IDENTIFICATION EQUATION EXCLUSION LAG UPPER_CHOLESKY LOWER_CHOLESKY MONTHLY QUARTERLY
%token MARKOV_SWITCHING CHAIN STATE DURATION NUMBER_OF_REGIMES
%token MARKOV_SWITCHING CHAIN REGIME DURATION NUMBER_OF_REGIMES
%token SVAR COEFF COEFFICIENTS VARIANCES CONSTANTS EQUATIONS
%token EXTERNAL_FUNCTION EXT_FUNC_NAME EXT_FUNC_NARGS FIRST_DERIV_PROVIDED SECOND_DERIV_PROVIDED
%token SELECTED_VARIABLES_ONLY COVA_COMPUTE SIMULATION_FILE_TAG FILE_TAG
@ -740,7 +740,7 @@ ms_options_list : ms_options_list COMMA ms_options
;
ms_options : o_chain
| o_state
| o_regime
| o_duration
| o_number_of_regimes
;
@ -2220,7 +2220,7 @@ o_cnum : CNUM EQUAL INT_NUMBER {driver.option_num("ms.cnum",$3); };
o_k_order_solver : K_ORDER_SOLVER {driver.option_num("k_order_solver","1"); };
o_pruning : PRUNING { driver.option_num("pruning", "1"); };
o_chain : CHAIN EQUAL INT_NUMBER { driver.option_num("ms.chain",$3); };
o_state : STATE EQUAL INT_NUMBER { driver.option_num("ms.state",$3); };
o_regime : REGIME EQUAL INT_NUMBER { driver.option_num("ms.regime",$3); };
o_duration : DURATION EQUAL non_negative_number
{ driver.option_num("ms.duration",$3); }
| DURATION EQUAL INF_CONSTANT

View File

@ -504,7 +504,7 @@ string eofbuff;
<DYNARE_STATEMENT,DYNARE_BLOCK>upper_cholesky {return token::UPPER_CHOLESKY;}
<DYNARE_STATEMENT,DYNARE_BLOCK>lower_cholesky {return token::LOWER_CHOLESKY;}
<DYNARE_STATEMENT>chain {return token::CHAIN;}
<DYNARE_STATEMENT>state {return token::STATE;}
<DYNARE_STATEMENT>regime {return token::REGIME;}
<DYNARE_STATEMENT>number_of_regimes {return token::NUMBER_OF_REGIMES;}
<DYNARE_STATEMENT>duration {return token::DURATION;}
<DYNARE_STATEMENT>coefficients {return token::COEFFICIENTS;}

View File

@ -1746,19 +1746,19 @@ ParsingDriver::markov_switching()
else if (atoi(it0->second.c_str()) <= 0)
error("The value passed to the chain option must be greater than zero.");
it0 = options_list.num_options.find("ms.state");
it0 = options_list.num_options.find("ms.regime");
it1 = options_list.num_options.find("ms.number_of_regimes");
if ((it0 == options_list.num_options.end())
&& (it1 == options_list.num_options.end()))
error("Either a state option or a number_of_regimes option must be passed to the markov_switching statement.");
error("Either a regime option or a number_of_regimes option must be passed to the markov_switching statement.");
if ((it0 != options_list.num_options.end())
&& (it1 != options_list.num_options.end()))
error("You cannot pass both a state option and a number_of_regimes option to the markov_switching statement.");
error("You cannot pass both a regime option and a number_of_regimes option to the markov_switching statement.");
if (it0 != options_list.num_options.end())
if (atoi(it0->second.c_str()) <= 0)
error("The value passed to the state option must be greater than zero.");
error("The value passed to the regime option must be greater than zero.");
if (it1 != options_list.num_options.end())
if (atoi(it1->second.c_str()) <= 0)