Differences between revisions 8 and 9
Revision 8 as of 2009-09-03 09:33:28
Size: 12585
Comment:
Revision 9 as of 2009-09-03 10:30:40
Size: 13874
Comment:
Deletions are marked like this. Additions are marked like this.
Line 127: Line 127:

== Steady state computation ==

A new algorithm with sparse Gaussian elimination (see below) is available for steady state computation: use option ~+{{{solve_algo = 5}}}+~

/!\ For the moment, you can use ~+{{{solve_algo = 5}}}+~ if and only if you also use ~+{{{block}}}+~ and ~+{{{bytecode}}}+~ options.

== Deterministic simulation ==

The ~+{{{simul}}}+~ command has a new option, ~+{{{stack_solve_algo}}}+~, used to specify the resolution algorithm. This option can take integer values between 0 and 5:

    * ~+{{{stack_solve_algo=0}}}+~ (default): use the historical {{{simk.m}}} or {{{sim1.m}}} solver which takes into account the sparse structure of the stacked time system according to Laffargue (1990) and Juillard (1996).
    * ~+{{{stack_solve_algo=1}}}+~: use a Newton algorithm with a sparse LU solver at each iteration;
    * ~+{{{stack_solve_algo=2}}}+~: use a Newton algorithm with a GMRES solver at each iteration;
    * ~+{{{stack_solve_algo=3}}}+~: use a Newton algorithm with a BICGSTAB solver at each iteration;
    * ~+{{{stack_solve_algo=4}}}+~: use a Newton algorithm with a optimal path length at each iteration;
    * ~+{{{stack_solve_algo=5}}}+~: use a Newton algorithm with a sparse Gaussian elimination solver at each iteration (see below)

Dynare now incorporates new features which significantly speed-up deterministic simulation and steady state computation in middle and large scale models.

The speed-up is achieved by the combination of three new features:

  • block decomposition of the model
  • bytecode representation of the model
  • new variants of Newton algorithm

/!\ The various options in this page only work with deterministic simulation at this time: they won't work with stochastic simulation, estimation or Ramsey policy. For the very same reason, they are also not compatible with the check command.

1. Block decomposition of the model

1.1. Description of the steps of the algorithm

1.1.1. Model simplification

In a first step, to get rid of nearly zero elements in the jacobian, a threshold (cutoff) is used to determine whether a jacobian element has to be considered as null or not. If the absolute value of a jacobian element is below the threshold then it is considered as null and is discarded form the sparse representation of the jacobian. Eliminating nearly zero elements improves the sparsity of the model and hence the simulation time. Note that if the cutoff value is too high then the model properties could be strongly modified and the simulation could fail.

1.1.2. Prologue and Epilogue determination

In a second step, the equations and the variables of the model could be reordered to get purely recursive initial and final blocks. The purely recursive equations are easily found.

  • The first block, called prologue, is composed of equations involving only exogenous variables or endogenous variables determined by previous equations.
  • The last block, the epilogue, is composed of variables which are pure output in the model: they do not appear in the previous equations of the model.

1.1.3. Model normalization

To get a block decomposition of the model, each endogenous variable has to be assigned unambiguously to an equation or equivalently the model has to be normalized: this normalization is performed using the maximum cardinality matching with Edmonds’ matching algorithm (Boost-graph library). Attention has to be paid to potential singularity in the matching process (to avoid for example a normalisation where the variable $x$ is assigned to the following equation: $y+0\cdot x=2z$). The matching algorithm is applied iteratively using the normalized Jacobian matrix (each row is divided by its maximum absolute value component) with a decreasing cutoff (all the elements in the Jacobian matrix below the cutoff are set to zero) until a matching is found.

1.1.4. Equations renormalization

Once the model has been normalized, the preprocessor tries to rewrite the equations in a normalized form: for the variable $x_i$ associated to the equation $i$, the equation has of the following form $x_i = f(x_1, \ldots, x_{i-1}, x_{i+1}, \ldots, x_n)$. For equations belonging to a recursive block, the normalized equation has not to be solved but only evaluated. For equations normalized belonging to a simultaneous block, they could be simply evaluated if they belong to the recursive set of the block in the feedback variables determination.

1.1.5. Block decomposition

The simultaneous block composed of equations and endogenous variables that do not belong to the prologue or the epilogue could be split sub recursive blocks. Those sub recursive blocks form the strong component of the graph representation of the model. To find them a depth search Tarjan algorithm is used.

1.1.6. Splitting the variables of a simultaneous block in feedback and recursive variables

The simultaneous blocks computed in the previous step are rewritten in a quasi triangular form. The non normalized equations that could not be evaluated are forced to belong to the feedback variables set. In addition, for dynamic model the static variables associated with non static equation or the non static variables are imposed in the feedback variables set. The equations of the block are reordered as follow:

  • First, the equations associated to variables belonging to the recursive set, ordered in a recursive way;
  • Second, the equations associated to variables belonging to the feedback set.

1.2. Dynare syntax

1.2.1. Computing block decomposition

The block decomposition of the model is triggered by the block option of the model keyword:

model(block);
...
end;

1.2.2. Controlling the model simplification

The default value of the cutoff described in the first step of the algorithm is $10^{-15}$. It can be modified with cutoff option of the model keyword:

model(block,cutoff=1e-13);
...
end;

/!\ Note that the jacobian is evaluated considering the initial value of the parameters provided in the mod file. If the parameters value are modified (the model is estimated for example) before the simul command, some components of the jacobian could be wrongly discarded. To prevent such a result you have to set the cutoff to 0.

/!\ For the moment, if block is used without bytecode, this option is ignored for the static model: the cutoff will be zero.

1.2.3. Controlling equation renormalization and the set of feedback variables

The mfs option of the model keyword controls equation renormalization and the set of feedback variables:

  • mfs = 0: (default value) all the endogenous variables are considered as feedback variables;

  • mfs = 1: the endogenous variables assigned to equation naturally normalized (i.e. of the form $x=f(Y)$ where $x$ does not appear in $Y$) are potentially recursive variables. All the other variables are forced to belong to the set of feedback variables.

  • mfs = 2: in addition of variables with mfs = 1 the endogenous variables related to linear equation which could be normalized are potential recursive variables. All the other variables are forced to belong to the set of feedback variables.

  • mfs = 3: in addition of variables with mfs = 2 the endogenous variables related non-linear equation which could be normalized are potential recursive variables. All the other variables are forced to belong to the set of feedback variables.

Example:

model(block,mfs=2);
...
end;

/!\ For the moment, if block is used without bytecode, this option is ignored for the static model.

1.2.4. Exploring the block structure of the model

The model_info command provides information about:

  • the normalization of the model: an endogenous variable is attributed to each equation of the model;
  • the block structure of the model: for each block model_info indicates its type, the equations number and endogenous variables belonging to this block.

There are five different types of blocks depending on the simulation method used:

  • EVALUATE FORWARD: in this case the block contains only equations where endogenous variable attributed to the equation appears currently on the left hand side and where no forward looking endogenous variables appear. $y_{j,t} = f_j \left (y_t, y_{t-1}, …, y_{t-k} \right) $.

  • EVALUATE BACKWARD: the block contains only equations where endogenous variable attributed to the equation appears currently on the left hand side and where no backward looking endogenous variables appear. $y_{j,t} = f_j \left (y_t, y_{t+1}, …, y_{t+k} \right) $.

  • SOLVE FORWARD x: the block contains only equations where endogenous variable attributed to the equation does not appear currently on the left hand side and where no forward looking endogenous variables appear. $ g_j \left (y_{j,t}, y_t, y_{t-1}, …, y_{t-k} \right) =0 $. x is equal to SIMPLE if the block has only one equation. If several equation appears in the block x is equal to COMPLETE.

  • SOLVE FORWARD x: the block contains only equations where endogenous variable attributed to the equation does not appear currently on the left hand side and where no backward looking endogenous variables appear. $ g_j \left (y_{j,t}, y_t, y_{t+1}, …, y_{t+k} \right) =0 $. x is equal to SIMPLE if the block has only one equation. If several equation appears in the block x is equal to COMPLETE.

  • SOVE TWO BOUNDARIES x: the block contains equations depending on both forward and backward variables. $ g_j \left (y_{j,t}, y_t, y_{t-1}, …, y_{t-k} \ ,y_t, y_{t+1}, …, y_{t+k} \right) =0 $. x is equal to SIMPLE if the block has only one equation. If several equation appears in the block x is equal to COMPLETE.

Synopsis:

model(block);
...
end;

model_info;

2. Bytecode representation of the model

By default, the Dynare preprocessor creates two M-files (one for the static model, one for the dynamic model) which are used by the MATLAB routines of Dynare. With big models, these M-files can become huge, and consume a lot of computing ressources.

The idea is to represent the model under another form: a bytecode, i.e. a binary file containing a compact representation of all the equations. This bytecode is then read and used for evaluations from MATLAB, using a dedicaded DLL.

You can activate the bytecode representation with the bytecode option of the model keyword:

model(block, bytecode);
...
end;

/!\ For the moment, using bytecode without block is not possible.

3. New variants of Newton algorithm

3.1. Steady state computation

A new algorithm with sparse Gaussian elimination (see below) is available for steady state computation: use option solve_algo = 5

/!\ For the moment, you can use solve_algo = 5 if and only if you also use block and bytecode options.

3.2. Deterministic simulation

The simul command has a new option, stack_solve_algo, used to specify the resolution algorithm. This option can take integer values between 0 and 5:

  • stack_solve_algo=0 (default): use the historical simk.m or sim1.m solver which takes into account the sparse structure of the stacked time system according to Laffargue (1990) and Juillard (1996).

  • stack_solve_algo=1: use a Newton algorithm with a sparse LU solver at each iteration;

  • stack_solve_algo=2: use a Newton algorithm with a GMRES solver at each iteration;

  • stack_solve_algo=3: use a Newton algorithm with a BICGSTAB solver at each iteration;

  • stack_solve_algo=4: use a Newton algorithm with a optimal path length at each iteration;

  • stack_solve_algo=5: use a Newton algorithm with a sparse Gaussian elimination solver at each iteration (see below)

3.2.1. markowitz

At each iteration of the deterministic simulation, if the linear approximation of the model is solve using a sparse gaussian elimination, two criterion could be used to select the variable to substitute:

  • The maximum pivot to get the most accurate solution (quite standard in Gaussian Elimination or LU decomposition).
  • The Markowitz criterion, to prevent an excessive sparsity reduction. The number of new non-zero elements created during the variable substitution is related to the number of non zero elements in its row. In this case we select the variable associated to the minimum non-zero elements in its row.

Markowitz option

The pivot is selected according to the highest value among j=1,…,N (where N is the number of possible pivots) of the following criteria:

        \[
          \frac{\frac{\left | \lambda_j\right |}{Sup_{i} \left | \lambda_i\right |} }{\left ( \frac{ n_j }{ Sup_{i} n_i} \right )^\mu}
    \]

With:

  • $\lambda_j$: the value of jth pivot;

  • $Sup_{i} \left | \lambda_i\right |$: the highest absolute value of the pivot among the N remaining pivots ;

  • $n_j$: the number of non zeros elements in the row related to the jth pivot ;

  • $n_j$: the highest number of non zeros elements in the row related to remaining pivots ;

  • $\mu$ : the value of the Markowitz option.

As $\mu \rightarrow \infty $ the Markowitz criteria prevails. At the opposite if $\mu \rightarrow 0 $ the usual maximum pivot criteria prevails.

The default value is 0.5

model(sparse_dll,markowitz=2);
...
end;

/!\ This option is only used in conjunction with sparse_dll option.

3.3. simulate options

3.3.1. method

This option indicates which linear solver will be implemented at each step of the Newton simulation of the stacked systems formed by the simultaneous blocks containing leads and lags on the endogenous variables. There are three values for this option if the sparse option is used in model command:

  • LU: for the sparse LU decomposition (the default option);
  • GMRES: for the Generalized Minimal Residual method;
  • BICGSTAB: for the Stabilized Bi-Conjugate Gradient method.

When sparse_dll option is used only SGE (for Sparse Gaussian Elimination) is available. It is the unique and default value of method in this case.

3.3.2. datafile

If the variables of the model are not constant over time, their initial values, stored in a text file, could be loaded, using the datafile option, as initial values before a deteministic simulation.

model;
...
end;

simul(periods=80,datafile=mark3);

4. Usage restrictions

block in static not compatible with mfs and cutoff check does not always work

DynareWiki: FastDeterministicSimulationAndSteadyStateComputation (last edited 2011-03-18 09:04:48 by FerhatMihoubi)