Compare commits
82 Commits
8d8176fc30
...
e03c29189c
Author | SHA1 | Date |
---|---|---|
Stéphane Adjemian (Guts) | e03c29189c | |
Sébastien Villemot | 9225e6b6df | |
Sébastien Villemot | d8f1e49221 | |
Sébastien Villemot | 1239842909 | |
Marco Ratto | 281f01f29e | |
Johannes Pfeifer | 8710ce0898 | |
Johannes Pfeifer | 74ac072549 | |
Marco Ratto | 8ddd35ddd8 | |
Marco Ratto | 3ee963c908 | |
Johannes Pfeifer | d25d95b3b5 | |
Marco Ratto | 2898407764 | |
Marco Ratto | 3931451250 | |
Marco Ratto | e1e79d3177 | |
Sébastien Villemot | d94e5bd7b9 | |
Sébastien Villemot | 66bc9fd9c2 | |
Sébastien Villemot | 19dcd4a0f2 | |
Johannes Pfeifer | f05a2de89e | |
Johannes Pfeifer | c3268c0279 | |
Johannes Pfeifer | 2e73856f5a | |
Sébastien Villemot | 565667c6b7 | |
Johannes Pfeifer | 75cd1042c8 | |
Sébastien Villemot | fd0d93ba13 | |
Sébastien Villemot | 668f6de5df | |
Johannes Pfeifer | 0c07460f3b | |
Stéphane Adjemian (Guts) | 1983dc13a3 | |
Johannes Pfeifer | 162813225d | |
Johannes Pfeifer | 1b2e1d2856 | |
Sébastien Villemot | 81cd0f1cb5 | |
Sébastien Villemot | 441ef7e102 | |
Johannes Pfeifer | 2df08f88c7 | |
Marco Ratto | f102a992aa | |
Marco Ratto | 53b57da8ba | |
Marco Ratto | aad5c36081 | |
Marco Ratto | de152a3de3 | |
Marco Ratto | 8f73564634 | |
Marco Ratto | 0c4b59b19e | |
Marco Ratto | 9b71845b87 | |
Marco Ratto | 91a2cd2496 | |
Sébastien Villemot | 858b534c22 | |
Johannes Pfeifer | e17bf15042 | |
Sébastien Villemot | ea28fcb4b4 | |
Sébastien Villemot | a7f5fd571d | |
Sébastien Villemot | 05cb10f8f7 | |
Sébastien Villemot | 594facdb03 | |
Sébastien Villemot | 7ba1fc1c63 | |
Sébastien Villemot | 63d5569cf4 | |
Sébastien Villemot | 00434c595d | |
Stéphane Adjemian (Ryûk) | 60c0ed0180 | |
Johannes Pfeifer | 42fc1ec40a | |
Johannes Pfeifer | 1b4fb46c75 | |
Stéphane Adjemian (Ryûk) | 2fbbe66c0a | |
Stéphane Adjemian (Ryûk) | 61498e644a | |
Stéphane Adjemian (Ryûk) | 3606b10f05 | |
Stéphane Adjemian (Ryûk) | 5077969aad | |
Stéphane Adjemian (Ryûk) | 3d50844ae4 | |
Stéphane Adjemian (Ryûk) | 3c3353b7ed | |
Stéphane Adjemian (Ryûk) | 03a68ddb89 | |
Sébastien Villemot | b1aa88e8da | |
Sébastien Villemot | d3aac5e2d7 | |
Sébastien Villemot | 62b31aa279 | |
Sébastien Villemot | 9d6a25e368 | |
Sébastien Villemot | 43b24facb9 | |
Sébastien Villemot | cc15281b1f | |
Sébastien Villemot | c99230825f | |
Sébastien Villemot | b7805cc667 | |
Johannes Pfeifer | ec76bda254 | |
Johannes Pfeifer | 021b9dbb25 | |
Johannes Pfeifer | daecd1f720 | |
Johannes Pfeifer | 5a3d545db2 | |
Johannes Pfeifer | ed80c4ff3f | |
Johannes Pfeifer | 678bd7aca9 | |
Johannes Pfeifer | 97f6a4219b | |
Johannes Pfeifer | 31c91080e1 | |
Johannes Pfeifer | 62e8b275a0 | |
Johannes Pfeifer | 435b103cf5 | |
Sébastien Villemot | d844043877 | |
Sébastien Villemot | a31c76403d | |
Sébastien Villemot | 4ef9245a95 | |
Sébastien Villemot | 91c677ca7f | |
Sébastien Villemot | 56289c72d0 | |
Sébastien Villemot | 1f5f668313 | |
Johannes Pfeifer | 54c4e9df09 |
|
@ -0,0 +1,8 @@
|
|||
# NB: to use clang-tidy on the MEX source code, make sure that you have
|
||||
# libomp-dev installed (the LLVM implementation of OpenMP)
|
||||
|
||||
# TODO: add the following check families:
|
||||
# - bugprone-*
|
||||
# - cppcoreguidelines-
|
||||
|
||||
Checks: 'performance-*,modernize-*,-modernize-use-trailing-return-type,-clang-diagnostic-unqualified-std-cast-call'
|
|
@ -479,7 +479,7 @@ If you want a certain version (e.g. 5.x) , then add `--single-branch --branch 5.
|
|||
```sh
|
||||
export BUILDDIR=build-matlab
|
||||
export MATLABPATH=/Applications/MATLAB_R2023b.app
|
||||
arch -$ARCH meson setup --native-file scripts/homebrew-native-$ARCH.ini -Dmatlab_path=$MATLABPATH -Dbuildtype=debugoptimized -Dfortran_args="['-B','$DYNAREDIR/slicot/lib']" $BUILDDIR
|
||||
arch -$ARCH meson setup --native-file macOS/homebrew-native-$ARCH.ini -Dmatlab_path=$MATLABPATH -Dbuildtype=debugoptimized -Dfortran_args="['-B','$DYNAREDIR/slicot/lib']" $BUILDDIR
|
||||
```
|
||||
where you need to adapt the path to MATLAB.
|
||||
Similarly, if you want to compile for Octave, replace the `-Dmatlab_path` option by `-Dbuild_for=octave`, and change the build directory to `build-octave`.
|
||||
|
@ -514,4 +514,4 @@ e.g. by adding this to your mod file. Alternatively, you can create a `startup.m
|
|||
## Docker
|
||||
We offer a variety of pre-configured Docker containers for Dynare, pre-configured with Octave and MATLAB including all recommended toolboxes.
|
||||
These are readily available for your convenience on [Docker Hub](https://hub.docker.com/r/dynare/dynare).
|
||||
The docker folder contains [information and instructions](docker/README.md) to interact, built and customize the containers.
|
||||
The `scripts/docker` folder contains [information and instructions](scripts/docker/README.md) to interact, built and customize the containers.
|
||||
|
|
|
@ -47,6 +47,7 @@ Bibliography
|
|||
* Hansen, Lars P. (1982): “Large sample properties of generalized method of moments estimators,” Econometrica, 50(4), 1029–1054.
|
||||
* Hansen, Nikolaus and Stefan Kern (2004): “Evaluating the CMA Evolution Strategy on Multimodal Test Functions”. In: *Eighth International Conference on Parallel Problem Solving from Nature PPSN VIII*, Proceedings, Berlin: Springer, 282–291.
|
||||
* Harvey, Andrew C. and Garry D.A. Phillips (1979): “Maximum likelihood estimation of regression models with autoregressive-moving average disturbances,” *Biometrika*, 66(1), 49–58.
|
||||
* Herbst, Edward and Schorfheide, Frank (2014): "Sequential monte-carlo sampling for DSGE models," *Journal of Applied Econometrics*, 29, 1073-1098.
|
||||
* Herbst, Edward (2015): “Using the “Chandrasekhar Recursions” for Likelihood Evaluation of DSGE Models,” *Computational Economics*, 45(4), 693–705.
|
||||
* Ireland, Peter (2004): “A Method for Taking Models to the Data,” *Journal of Economic Dynamics and Control*, 28, 1205–26.
|
||||
* Iskrev, Nikolay (2010): “Local identification in DSGE models,” *Journal of Monetary Economics*, 57(2), 189–202.
|
||||
|
|
|
@ -15,11 +15,16 @@ related to the model (and hence not placed in the model file). At the
|
|||
moment, it is only used when using Dynare to run parallel
|
||||
computations.
|
||||
|
||||
On Linux and macOS, the default location of the configuration file is
|
||||
``$HOME/.dynare``, while on Windows it is ``%APPDATA%\dynare.ini``
|
||||
(typically ``c:\Users\USERNAME\AppData\dynare.ini``). You
|
||||
can specify a non standard location using the ``conffile`` option of
|
||||
the ``dynare`` command (see :ref:`dyn-invoc`).
|
||||
On Linux and macOS, the configuration file is searched by default under
|
||||
``dynare/dynare.ini`` in the configuration directories defined by the XDG
|
||||
specification (typically ``$HOME/.config/dynare/dynare.ini`` for the
|
||||
user-specific configuration and ``/etc/xdg/dynare/dynare.ini`` for the
|
||||
system-wide configuration, the former having precedence over the latter). Under
|
||||
Windows, the configuration file is searched by default in
|
||||
``%APPDATA%\dynare\dynare.ini`` (typically
|
||||
``c:\Users\USERNAME\AppData\Roaming\dynare\dynare.ini``). You can specify a non
|
||||
standard location using the ``conffile`` option of the ``dynare`` command (see
|
||||
:ref:`dyn-invoc`).
|
||||
|
||||
The parsing of the configuration file is case-sensitive and it should
|
||||
take the following form, with each option/choice pair placed on a
|
||||
|
@ -76,8 +81,15 @@ processing. Currently, there is only one option available.
|
|||
|
||||
.. option:: GlobalInitFile = PATH_AND_FILE
|
||||
|
||||
The location of the global initialization file to be run at
|
||||
the end of ``global_initialization.m``.
|
||||
The location of a global initialization file that can be used to
|
||||
customize some Dynare internals (typically default option values). This
|
||||
is a MATLAB/Octave script.
|
||||
|
||||
If this option is not specified, Dynare will look for a
|
||||
``global_init.m`` file in its configuration directory (typically
|
||||
``$HOME/.config/dynare/global_init.m`` under Linux and macOS, and
|
||||
``c:\Users\USERNAME\AppData\Roaming\dynare\global_init.m`` under
|
||||
Windows).
|
||||
|
||||
*Example*
|
||||
|
||||
|
|
|
@ -4787,31 +4787,6 @@ Computing the stochastic solution
|
|||
and this option has no effect. More references can be found
|
||||
`here <https://archives.dynare.org/DynareWiki/PartialInformation>`__ .
|
||||
|
||||
.. option:: sylvester = OPTION
|
||||
|
||||
Determines the algorithm used to solve the Sylvester equation
|
||||
for block decomposed model. Possible values for OPTION are:
|
||||
|
||||
``default``
|
||||
|
||||
Uses the default solver for Sylvester equations
|
||||
(``gensylv``) based on Ondra Kamenik’s algorithm (see
|
||||
`here
|
||||
<https://www.dynare.org/assets/team-presentations/sylvester.pdf>`__
|
||||
for more information).
|
||||
|
||||
``fixed_point``
|
||||
|
||||
Uses a fixed point algorithm to solve the Sylvester
|
||||
equation (``gensylv_fp``). This method is faster than
|
||||
the default one for large scale models.
|
||||
|
||||
|br| Default value is ``default``.
|
||||
|
||||
.. option:: sylvester_fixed_point_tol = DOUBLE
|
||||
|
||||
The convergence criterion used in the fixed point
|
||||
Sylvester solver. Its default value is ``1e-12``.
|
||||
|
||||
.. option:: dr = OPTION
|
||||
|
||||
|
@ -7146,6 +7121,18 @@ observed variables.
|
|||
Stopping criteria. Default: ``1e-5`` for numerical
|
||||
derivatives, ``1e-7`` for analytic derivatives.
|
||||
|
||||
``'robust'``
|
||||
|
||||
Trigger more robust but computationally more expensive line search. Default: ``false``.
|
||||
|
||||
``'TolGstep'``
|
||||
|
||||
Tolerance parameter used for tuning gradient step. Default: same value as ``TolFun``.
|
||||
|
||||
``'TolGstepRel'``
|
||||
|
||||
Parameter used for tuning gradient step, governing the tolerance relative to the functions value. Default: not triggered.
|
||||
|
||||
``'verbosity'``
|
||||
|
||||
Controls verbosity of display during
|
||||
|
@ -7479,6 +7466,18 @@ observed variables.
|
|||
Chain draws than the MH-algorithm. Its relative (in)efficiency can be investigated via
|
||||
the reported inefficiency factors.
|
||||
|
||||
``'hssmc'``
|
||||
|
||||
Instructs Dynare to use the *Herbst and Schorfheide (2014)*
|
||||
version of the Sequential Monte-Carlo sampler instead of the
|
||||
standard Random-Walk Metropolis-Hastings.
|
||||
|
||||
``'dsmh'``
|
||||
|
||||
Instructs Dynare to use the Dynamic Striated Metropolis Hastings
|
||||
sampler proposed by *Waggoner, Wu and Zha (2016)* instead of the
|
||||
standard Random-Walk Metropolis-Hastings.
|
||||
|
||||
.. option:: posterior_sampler_options = (NAME, VALUE, ...)
|
||||
|
||||
A list of NAME and VALUE pairs. Can be used to set options for
|
||||
|
@ -7491,141 +7490,173 @@ observed variables.
|
|||
|
||||
Available options are:
|
||||
|
||||
.. _prop_distrib:
|
||||
.. _prop_distrib:
|
||||
|
||||
``'proposal_distribution'``
|
||||
``'proposal_distribution'``
|
||||
|
||||
Specifies the statistical distribution used for the
|
||||
proposal density.
|
||||
Specifies the statistical distribution used for the
|
||||
proposal density.
|
||||
|
||||
``'rand_multivariate_normal'``
|
||||
``'rand_multivariate_normal'``
|
||||
|
||||
Use a multivariate normal distribution. This is the default.
|
||||
Use a multivariate normal distribution. This is the default.
|
||||
|
||||
``'rand_multivariate_student'``
|
||||
``'rand_multivariate_student'``
|
||||
|
||||
Use a multivariate student distribution.
|
||||
Use a multivariate student distribution.
|
||||
|
||||
``'student_degrees_of_freedom'``
|
||||
``'student_degrees_of_freedom'``
|
||||
|
||||
Specifies the degrees of freedom to be used with the
|
||||
multivariate student distribution. Default: ``3``.
|
||||
Specifies the degrees of freedom to be used with the
|
||||
multivariate student distribution. Default: ``3``.
|
||||
|
||||
.. _usemhcov:
|
||||
.. _usemhcov:
|
||||
|
||||
``'use_mh_covariance_matrix'``
|
||||
``'use_mh_covariance_matrix'``
|
||||
|
||||
Indicates to use the covariance matrix of the draws
|
||||
from a previous MCMC run to define the covariance of
|
||||
the proposal distribution. Requires the
|
||||
:opt:`load_mh_file` option to be specified. Default:
|
||||
``0``.
|
||||
Indicates to use the covariance matrix of the draws
|
||||
from a previous MCMC run to define the covariance of
|
||||
the proposal distribution. Requires the
|
||||
:opt:`load_mh_file` option to be specified. Default: ``0``.
|
||||
|
||||
.. _scale-file:
|
||||
.. _scale-file:
|
||||
|
||||
``'scale_file'``
|
||||
``'scale_file'``
|
||||
|
||||
Provides the name of a ``_mh_scale.mat`` file storing
|
||||
the tuned scale factor from a previous run of
|
||||
``mode_compute=6``.
|
||||
Provides the name of a ``_mh_scale.mat`` file storing
|
||||
the tuned scale factor from a previous run of
|
||||
``mode_compute=6``.
|
||||
|
||||
.. _savetmp:
|
||||
.. _savetmp:
|
||||
|
||||
``'save_tmp_file'``
|
||||
``'save_tmp_file'``
|
||||
|
||||
Save the MCMC draws into a ``_mh_tmp_blck`` file at the
|
||||
refresh rate of the status bar instead of just saving
|
||||
the draws when the current ``_mh*_blck`` file is
|
||||
full. Default: ``0``
|
||||
Save the MCMC draws into a ``_mh_tmp_blck`` file at the
|
||||
refresh rate of the status bar instead of just saving
|
||||
the draws when the current ``_mh*_blck`` file is
|
||||
full. Default: ``0``
|
||||
|
||||
``'independent_metropolis_hastings'``
|
||||
|
||||
Takes the same options as in the case of
|
||||
``random_walk_metropolis_hastings``.
|
||||
Takes the same options as in the case of ``random_walk_metropolis_hastings``.
|
||||
|
||||
``'slice'``
|
||||
|
||||
``'rotated'``
|
||||
Available options are:
|
||||
|
||||
Triggers rotated slice iterations using a covariance
|
||||
matrix from initial burn-in iterations. Requires either
|
||||
``use_mh_covariance_matrix`` or
|
||||
``slice_initialize_with_mode``. Default: ``0``.
|
||||
``'rotated'``
|
||||
|
||||
``'mode_files'``
|
||||
Triggers rotated slice iterations using a covariance
|
||||
matrix from initial burn-in iterations. Requires either
|
||||
``use_mh_covariance_matrix`` or
|
||||
``slice_initialize_with_mode``. Default: ``0``.
|
||||
|
||||
For multimodal posteriors, provide the name of a file
|
||||
containing a ``nparam`` by ``nmodes`` variable called
|
||||
``xparams`` storing the different modes. This array
|
||||
must have one column vector per mode and the estimated
|
||||
parameters along the row dimension. With this info, the
|
||||
code will automatically trigger the ``rotated`` and
|
||||
``mode`` options. Default: ``[]``.
|
||||
``'mode_files'``
|
||||
|
||||
``'slice_initialize_with_mode'``
|
||||
For multimodal posteriors, provide the name of a file
|
||||
containing a ``nparam`` by ``nmodes`` variable called
|
||||
``xparams`` storing the different modes. This array
|
||||
must have one column vector per mode and the estimated
|
||||
parameters along the row dimension. With this info, the
|
||||
code will automatically trigger the ``rotated`` and
|
||||
``mode`` options. Default: ``[]``.
|
||||
|
||||
The default for slice is to set ``mode_compute=0`` and
|
||||
start the chain(s) from a random location in the prior
|
||||
space. This option first runs the mode-finder and then
|
||||
starts the chain from the mode. Together with
|
||||
``rotated``, it will use the inverse Hessian from the
|
||||
mode to perform rotated slice iterations. Default:
|
||||
``0``.
|
||||
``'slice_initialize_with_mode'``
|
||||
|
||||
``'initial_step_size'``
|
||||
The default for slice is to set ``mode_compute=0`` and
|
||||
start the chain(s) from a random location in the prior
|
||||
space. This option first runs the mode-finder and then
|
||||
starts the chain from the mode. Together with
|
||||
``rotated``, it will use the inverse Hessian from the
|
||||
mode to perform rotated slice iterations. Default:
|
||||
``0``.
|
||||
|
||||
Sets the initial size of the interval in the
|
||||
stepping-out procedure as fraction of the prior
|
||||
support, i.e. the size will be ``initial_step_size *
|
||||
(UB-LB)``. ``initial_step_size`` must be a real number
|
||||
in the interval ``[0,1]``. Default: ``0.8``.
|
||||
``'initial_step_size'``
|
||||
|
||||
``'use_mh_covariance_matrix'``
|
||||
Sets the initial size of the interval in the
|
||||
stepping-out procedure as fraction of the prior
|
||||
support, i.e. the size will be ``initial_step_size *
|
||||
(UB-LB)``. ``initial_step_size`` must be a real number
|
||||
in the interval ``[0,1]``. Default: ``0.8``.
|
||||
|
||||
See :ref:`use_mh_covariance_matrix <usemhcov>`. Must be
|
||||
used with ``'rotated'``. Default: ``0``.
|
||||
``'use_mh_covariance_matrix'``
|
||||
|
||||
``'save_tmp_file'``
|
||||
See :ref:`use_mh_covariance_matrix <usemhcov>`. Must be
|
||||
used with ``'rotated'``. Default: ``0``.
|
||||
|
||||
See :ref:`save_tmp_file <savetmp>`. Default: ``1``.
|
||||
``'save_tmp_file'``
|
||||
|
||||
See :ref:`save_tmp_file <savetmp>`. Default: ``1``.
|
||||
|
||||
``'tailored_random_block_metropolis_hastings'``
|
||||
|
||||
``'proposal_distribution'``
|
||||
Available options are:
|
||||
|
||||
``'proposal_distribution'``
|
||||
|
||||
Specifies the statistical distribution used for the
|
||||
proposal density. See :ref:`proposal_distribution <prop_distrib>`.
|
||||
Specifies the statistical distribution used for the
|
||||
proposal density. See :ref:`proposal_distribution <prop_distrib>`.
|
||||
|
||||
``new_block_probability = DOUBLE``
|
||||
``new_block_probability = DOUBLE``
|
||||
|
||||
Specifies the probability of the next parameter
|
||||
belonging to a new block when the random blocking in
|
||||
the TaRB Metropolis-Hastings algorithm is
|
||||
conducted. The higher this number, the smaller is the
|
||||
average block size and the more random blocks are
|
||||
formed during each parameter sweep. Default: ``0.25``.
|
||||
Specifies the probability of the next parameter
|
||||
belonging to a new block when the random blocking in
|
||||
the TaRB Metropolis-Hastings algorithm is
|
||||
conducted. The higher this number, the smaller is the
|
||||
average block size and the more random blocks are
|
||||
formed during each parameter sweep. Default: ``0.25``.
|
||||
|
||||
``mode_compute = INTEGER``
|
||||
``mode_compute = INTEGER``
|
||||
|
||||
Specifies the mode-finder run in every iteration for
|
||||
every block of the TaRB Metropolis-Hastings
|
||||
algorithm. See :opt:`mode_compute <mode_compute =
|
||||
INTEGER | FUNCTION_NAME>`. Default: ``4``.
|
||||
Specifies the mode-finder run in every iteration for
|
||||
every block of the TaRB Metropolis-Hastings
|
||||
algorithm. See :opt:`mode_compute <mode_compute =
|
||||
INTEGER | FUNCTION_NAME>`. Default: ``4``.
|
||||
|
||||
``optim = (NAME, VALUE,...)``
|
||||
``optim = (NAME, VALUE,...)``
|
||||
|
||||
Specifies the options for the mode-finder used in the
|
||||
TaRB Metropolis-Hastings algorithm. See :opt:`optim
|
||||
<optim = (NAME, VALUE, ...)>`.
|
||||
Specifies the options for the mode-finder used in the
|
||||
TaRB Metropolis-Hastings algorithm. See :opt:`optim
|
||||
<optim = (NAME, VALUE, ...)>`.
|
||||
|
||||
``'scale_file'``
|
||||
``'scale_file'``
|
||||
|
||||
See :ref:`scale_file <scale-file>`..
|
||||
See :ref:`scale_file <scale-file>`..
|
||||
|
||||
``'save_tmp_file'``
|
||||
``'save_tmp_file'``
|
||||
|
||||
See :ref:`save_tmp_file <savetmp>`. Default: ``1``.
|
||||
See :ref:`save_tmp_file <savetmp>`. Default: ``1``.
|
||||
|
||||
``'hssmc'``
|
||||
|
||||
Available options are:
|
||||
|
||||
``'particles'``
|
||||
|
||||
Number of particles. Default value is: 20000.
|
||||
|
||||
``'steps'``
|
||||
|
||||
Number of weights :math:`\phi_i\in[0,1]` on the likelihood function used to define a sequence of tempered likelihoods. This parameter is denoted :math:`N_{\phi}` in *Herbst and Schorfheide (2014)*, and we have :math:`\phi_1=0` and :math:`\phi_{N_\phi}=1`. Default value is: 25.
|
||||
|
||||
``'lambda'``
|
||||
|
||||
Positive parameter controling the sequence of weights :math:`\phi_i`, Default value is: 2. Weights are defined by:
|
||||
|
||||
.. math::
|
||||
|
||||
\phi_i = \left(\frac{i-1}{N_{\phi}-1}\right)^{\lambda}
|
||||
|
||||
for :math:`i=1,\ldots,N_{\phi}`. Usually we set :math:`\lambda>1`, so that :math:`\Delta \phi_i = \phi_i-\phi_{i-1}` is increasing with :math:`i`.
|
||||
|
||||
``'target'``
|
||||
|
||||
Acceptance rate target. Default value is: .25.
|
||||
|
||||
``'scale'``
|
||||
|
||||
Scale parameter in the mutation step (on the proposal covariance matrix of the MH iteration). Default value is: .5.
|
||||
|
||||
.. option:: moments_varendo
|
||||
|
||||
Triggers the computation of the posterior distribution of the
|
||||
|
@ -7923,15 +7954,6 @@ observed variables.
|
|||
|
||||
See :opt:`aim_solver`.
|
||||
|
||||
.. option:: sylvester = OPTION
|
||||
|
||||
See :opt:`sylvester <sylvester = OPTION>`.
|
||||
|
||||
.. option:: sylvester_fixed_point_tol = DOUBLE
|
||||
|
||||
See :opt:`sylvester_fixed_point_tol <sylvester_fixed_point_tol
|
||||
= DOUBLE>` .
|
||||
|
||||
.. option:: lyapunov = OPTION
|
||||
|
||||
Determines the algorithm used to solve the Lyapunov equation to
|
||||
|
@ -9475,16 +9497,6 @@ adding prior information comes at the cost of a loss in efficiency of the estima
|
|||
See :opt:`lyapunov_doubling_tol <lyapunov_doubling_tol = DOUBLE>`.
|
||||
Default: ``1e-16``.
|
||||
|
||||
.. option:: sylvester = OPTION
|
||||
|
||||
See :opt:`sylvester <sylvester = OPTION>`.
|
||||
Default: ``default``, i.e. uses ``gensylv``.
|
||||
|
||||
.. option:: sylvester_fixed_point_tol = DOUBLE
|
||||
|
||||
See :opt:`sylvester_fixed_point_tol <sylvester_fixed_point_tol = DOUBLE>`.
|
||||
Default: ``1e-12``.
|
||||
|
||||
.. option:: qz_criterium = DOUBLE
|
||||
|
||||
See :opt:`qz_criterium <qz_criterium = DOUBLE>`.
|
||||
|
@ -11755,8 +11767,8 @@ estimation environment is set up.
|
|||
Performing sensitivity analysis
|
||||
-------------------------------
|
||||
|
||||
.. command:: dynare_sensitivity ;
|
||||
dynare_sensitivity(OPTIONS...);
|
||||
.. command:: sensitivity ;
|
||||
sensitivity(OPTIONS...);
|
||||
|
||||
|br| This command triggers sensitivity analysis on a DSGE model.
|
||||
|
||||
|
@ -12040,6 +12052,12 @@ Performing sensitivity analysis
|
|||
|
||||
See :opt:`diffuse_filter`.
|
||||
|
||||
.. command:: dynare_sensitivity ;
|
||||
dynare_sensitivity(OPTIONS...);
|
||||
|
||||
|br| This is a deprecated alias for the ``sensitivity`` command.
|
||||
|
||||
|
||||
.. _irf-momcal:
|
||||
|
||||
IRF/Moment calibration
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
Assuming that the dynare++ binary is in your PATH, you can run the example by using the following command
|
||||
in a Command Prompt Window:
|
||||
|
||||
... > dynare++ example1.mod
|
||||
|
||||
Please, read the manual (doc\dynare++\dynare++-tutorial.pdf) for a description of the generated output.
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* This Dynare++ mod-file implements the RBC model with time-to-build
|
||||
* described in Kamenik (2011): "DSGE Models with Dynare++. A Tutorial."
|
||||
* Note that Dynare++ uses the same stock-at-the-end-of-period timing convention
|
||||
* as the regular Dynare
|
||||
*/
|
||||
|
||||
var Y, C, K, A, H, B;
|
||||
|
||||
varexo EPS, NU;
|
||||
|
||||
parameters beta, rho, alpha, delta, theta, psi, tau;
|
||||
|
||||
alpha = 0.36;
|
||||
rho = 0.95;
|
||||
tau = 0.025;
|
||||
beta = 1/(1.03^0.25);
|
||||
delta = 0.025;
|
||||
psi = 0;
|
||||
theta = 2.95;
|
||||
|
||||
model;
|
||||
C*theta*H^(1+psi) = (1-alpha)*Y;
|
||||
beta*exp(B)*C/exp(B(1))/C(1)*
|
||||
(exp(B(1))*alpha*Y(1)/K(1)+1-delta) = 1;
|
||||
Y = exp(A)*K^alpha*H^(1-alpha);
|
||||
K = exp(B(-1))*(Y(-1)-C(-1)) + (1-delta)*K(-1);
|
||||
A = rho*A(-1) + tau*B(-1) + EPS;
|
||||
B = tau*A(-1) + rho*B(-1) + NU;
|
||||
end;
|
||||
|
||||
initval;
|
||||
A = 0;
|
||||
B = 0;
|
||||
H = ((1-alpha)/(theta*(1-(delta*alpha)/(1/beta-1+delta))))^(1/(1+psi));
|
||||
Y = (alpha/(1/beta-1+delta))^(alpha/(1-alpha))*H;
|
||||
K = alpha/(1/beta-1+delta)*Y;
|
||||
C = Y - delta*K;
|
||||
end;
|
||||
|
||||
vcov = [0.0002 0.00005;
|
||||
0.00005 0.0001
|
||||
];
|
||||
|
||||
order = 7;
|
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
* This file replicates the estimation of the cash in advance model (termed M1
|
||||
* in the paper) described in Frank Schorfheide (2000): "Loss function-based
|
||||
* This file replicates the estimation of the cash in advance model (termed M1
|
||||
* in the paper) described in Frank Schorfheide (2000): "Loss function-based
|
||||
* evaluation of DSGE models", Journal of Applied Econometrics, 15(6), 645-670.
|
||||
*
|
||||
* The data are in file "fsdat_simul.m", and have been artificially generated.
|
||||
* They are therefore different from the original dataset used by Schorfheide.
|
||||
* The data are taken from the replication package at
|
||||
* http://dx.doi.org/10.15456/jae.2022314.0708799949
|
||||
*
|
||||
* The prior distribution follows the one originally specified in Schorfheide's
|
||||
* paper, except for parameter rho. In the paper, the elicited beta prior for rho
|
||||
* paper. Note that the elicited beta prior for rho in the paper
|
||||
* implies an asymptote and corresponding prior mode at 0. It is generally
|
||||
* recommended to avoid this extreme type of prior. Some optimizers, for instance
|
||||
* mode_compute=12 (Mathworks' particleswarm algorithm) may find a posterior mode
|
||||
* with rho equal to zero. We lowered the value of the prior standard deviation
|
||||
* (changing .223 to .100) to remove the asymptote.
|
||||
* recommended to avoid this extreme type of prior.
|
||||
*
|
||||
* Because the data are already logged and we use the loglinear option to conduct
|
||||
* a full log-linearization, we need to use the logdata option.
|
||||
*
|
||||
* The equations are taken from J. Nason and T. Cogley (1994): "Testing the
|
||||
* implications of long-run neutrality for monetary business cycle models",
|
||||
* Journal of Applied Econometrics, 9, S37-S70.
|
||||
* Journal of Applied Econometrics, 9, S37-S70, NC in the following.
|
||||
* Note that there is an initial minus sign missing in equation (A1), p. S63.
|
||||
*
|
||||
* This implementation was originally written by Michel Juillard. Please note that the
|
||||
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright © 2004-2017 Dynare Team
|
||||
* Copyright © 2004-2023 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -43,33 +43,71 @@
|
|||
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var m P c e W R k d n l gy_obs gp_obs y dA;
|
||||
varexo e_a e_m;
|
||||
var m ${m}$ (long_name='money growth')
|
||||
P ${P}$ (long_name='Price level')
|
||||
c ${c}$ (long_name='consumption')
|
||||
e ${e}$ (long_name='capital stock')
|
||||
W ${W}$ (long_name='Wage rate')
|
||||
R ${R}$ (long_name='interest rate')
|
||||
k ${k}$ (long_name='capital stock')
|
||||
d ${d}$ (long_name='dividends')
|
||||
n ${n}$ (long_name='labor')
|
||||
l ${l}$ (long_name='loans')
|
||||
gy_obs ${\Delta \ln GDP}$ (long_name='detrended capital stock')
|
||||
gp_obs ${\Delta \ln P}$ (long_name='detrended capital stock')
|
||||
y ${y}$ (long_name='detrended output')
|
||||
dA ${\Delta A}$ (long_name='TFP growth')
|
||||
;
|
||||
varexo e_a ${\epsilon_A}$ (long_name='TFP shock')
|
||||
e_m ${\epsilon_M}$ (long_name='Money growth shock')
|
||||
;
|
||||
|
||||
parameters alp bet gam mst rho psi del;
|
||||
parameters alp ${\alpha}$ (long_name='capital share')
|
||||
bet ${\beta}$ (long_name='discount factor')
|
||||
gam ${\gamma}$ (long_name='long-run TFP growth')
|
||||
logmst ${\log(m^*)}$ (long_name='long-run money growth')
|
||||
rho ${\rho}$ (long_name='autocorrelation money growth')
|
||||
phi ${\phi}$ (long_name='labor weight in consumption')
|
||||
del ${\delta}$ (long_name='depreciation rate')
|
||||
;
|
||||
|
||||
% roughly picked values to allow simulating the model before estimation
|
||||
alp = 0.33;
|
||||
bet = 0.99;
|
||||
gam = 0.003;
|
||||
mst = 1.011;
|
||||
logmst = log(1.011);
|
||||
rho = 0.7;
|
||||
psi = 0.787;
|
||||
phi = 0.787;
|
||||
del = 0.02;
|
||||
|
||||
model;
|
||||
[name='NC before eq. (1), TFP growth equation']
|
||||
dA = exp(gam+e_a);
|
||||
log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
|
||||
[name='NC eq. (2), money growth rate']
|
||||
log(m) = (1-rho)*logmst + rho*log(m(-1))+e_m;
|
||||
[name='NC eq. (A1), Euler equation']
|
||||
-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
|
||||
[name='NC below eq. (A1), firm borrowing constraint']
|
||||
W = l/n;
|
||||
-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
|
||||
[name='NC eq. (A2), intratemporal labour market condition']
|
||||
-(phi/(1-phi))*(c*P/(1-n))+l/n = 0;
|
||||
[name='NC below eq. (A2), credit market clearing']
|
||||
R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
|
||||
[name='NC eq. (A3), credit market optimality']
|
||||
1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
|
||||
[name='NC eq. (18), aggregate resource constraint']
|
||||
c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
|
||||
[name='NC eq. (19), money market condition']
|
||||
P*c = m;
|
||||
[name='NC eq. (20), credit market equilibrium condition']
|
||||
m-1+d = l;
|
||||
[name='Definition TFP shock']
|
||||
e = exp(e_a);
|
||||
[name='Implied by NC eq. (18), production function']
|
||||
y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
|
||||
[name='Observation equation GDP growth']
|
||||
gy_obs = dA*y/y(-1);
|
||||
[name='Observation equation price level']
|
||||
gp_obs = (P/P(-1))*m(-1)/dA;
|
||||
end;
|
||||
|
||||
|
@ -81,40 +119,41 @@ end;
|
|||
steady_state_model;
|
||||
dA = exp(gam);
|
||||
gst = 1/dA;
|
||||
m = mst;
|
||||
m = exp(logmst);
|
||||
khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
|
||||
xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
|
||||
nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
|
||||
xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/m )^(-1);
|
||||
nust = phi*m^2/( (1-alp)*(1-phi)*bet*gst^alp*khst^alp );
|
||||
n = xist/(nust+xist);
|
||||
P = xist + nust;
|
||||
k = khst*n;
|
||||
|
||||
l = psi*mst*n/( (1-psi)*(1-n) );
|
||||
c = mst/P;
|
||||
d = l - mst + 1;
|
||||
l = phi*m*n/( (1-phi)*(1-n) );
|
||||
c = m/P;
|
||||
d = l - m + 1;
|
||||
y = k^alp*n^(1-alp)*gst^alp;
|
||||
R = mst/bet;
|
||||
R = m/bet;
|
||||
W = l/n;
|
||||
ist = y-c;
|
||||
q = 1 - d;
|
||||
|
||||
e = 1;
|
||||
|
||||
|
||||
gp_obs = m/dA;
|
||||
gy_obs = dA;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
steady;
|
||||
check;
|
||||
|
||||
% Table 1 of Schorfheide (2000)
|
||||
estimated_params;
|
||||
alp, beta_pdf, 0.356, 0.02;
|
||||
bet, beta_pdf, 0.993, 0.002;
|
||||
gam, normal_pdf, 0.0085, 0.003;
|
||||
mst, normal_pdf, 1.0002, 0.007;
|
||||
rho, beta_pdf, 0.129, 0.100;
|
||||
psi, beta_pdf, 0.65, 0.05;
|
||||
logmst, normal_pdf, 0.0002, 0.007;
|
||||
rho, beta_pdf, 0.129, 0.223;
|
||||
phi, beta_pdf, 0.65, 0.05;
|
||||
del, beta_pdf, 0.01, 0.005;
|
||||
stderr e_a, inv_gamma_pdf, 0.035449, inf;
|
||||
stderr e_m, inv_gamma_pdf, 0.008862, inf;
|
||||
|
@ -122,14 +161,8 @@ end;
|
|||
|
||||
varobs gp_obs gy_obs;
|
||||
|
||||
estimation(order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8, mode_check);
|
||||
estimation(order=1, datafile=fs2000_data, loglinear,logdata, mode_compute=4, mh_replic=20000, nodiagnostic, mh_nblocks=2, mh_jscale=0.8, mode_check);
|
||||
|
||||
|
||||
/*
|
||||
* The following lines were used to generate the data file. If you want to
|
||||
* generate another random data file, comment the "estimation" line and uncomment
|
||||
* the following lines.
|
||||
*/
|
||||
|
||||
//stoch_simul(periods=200, order=1);
|
||||
//datatomfile('fsdat_simul', {'gy_obs', 'gp_obs'});
|
||||
%uncomment the following lines to generate LaTeX-code of the model equations
|
||||
%write_latex_original_model(write_equation_tags);
|
||||
%collect_latex_files;
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
%This file is a direct Matlab implementation of the loaddata.g and data.prn files
|
||||
%of Schorfheide, Frank (2000): Loss function-based evaluation of DSGE models
|
||||
%(replication data). Version: 1. Journal of Applied Econometrics. Dataset.
|
||||
%http://dx.doi.org/10.15456/jae.2022314.0708799949
|
||||
% Copyright: 2000-2022 Frank Schorfheide
|
||||
% Copyright: 2023 Dynare Team
|
||||
|
||||
% License: CC BY 4.0
|
||||
% (https://creativecommons.org/licenses/by/4.0/legalcode)
|
||||
|
||||
% Time series, extracted 05/04/00
|
||||
% columms are quarterly data from 1949:IV to 1997:IV
|
||||
% 1: GDPD = GROSS DOMESTIC PRODUCT:IMPLICIT PRICE DEFLATOR (INDEX,92=100)(T7.1)
|
||||
% 2: GDPQ = GROSS DOMESTIC PRODUCT
|
||||
% 3: GPOP = POPULATION, NIPA basis (THOUS.,NSA)
|
||||
|
||||
data_q=[18.02 1474.5 150.2
|
||||
17.94 1538.2 150.9
|
||||
18.01 1584.5 151.4
|
||||
18.42 1644.1 152
|
||||
18.73 1678.6 152.7
|
||||
19.46 1693.1 153.3
|
||||
19.55 1724 153.9
|
||||
19.56 1758.2 154.7
|
||||
19.79 1760.6 155.4
|
||||
19.77 1779.2 156
|
||||
19.82 1778.8 156.6
|
||||
20.03 1790.9 157.3
|
||||
20.12 1846 158
|
||||
20.1 1882.6 158.6
|
||||
20.14 1897.3 159.2
|
||||
20.22 1887.4 160
|
||||
20.27 1858.2 160.7
|
||||
20.34 1849.9 161.4
|
||||
20.39 1848.5 162
|
||||
20.42 1868.9 162.8
|
||||
20.47 1905.6 163.6
|
||||
20.56 1959.6 164.3
|
||||
20.62 1994.4 164.9
|
||||
20.78 2020.1 165.7
|
||||
21 2030.5 166.5
|
||||
21.2 2023.6 167.2
|
||||
21.33 2037.7 167.9
|
||||
21.62 2033.4 168.7
|
||||
21.71 2066.2 169.5
|
||||
22.01 2077.5 170.2
|
||||
22.15 2071.9 170.9
|
||||
22.27 2094 171.7
|
||||
22.29 2070.8 172.5
|
||||
22.56 2012.6 173.1
|
||||
22.64 2024.7 173.8
|
||||
22.77 2072.3 174.5
|
||||
22.88 2120.6 175.3
|
||||
22.92 2165 176.045
|
||||
22.91 2223.3 176.727
|
||||
22.94 2221.4 177.481
|
||||
23.03 2230.95 178.268
|
||||
23.13 2279.22 179.694
|
||||
23.22 2265.48 180.335
|
||||
23.32 2268.29 181.094
|
||||
23.4 2238.57 181.915
|
||||
23.45 2251.68 182.634
|
||||
23.51 2292.02 183.337
|
||||
23.56 2332.61 184.103
|
||||
23.63 2381.01 184.894
|
||||
23.75 2422.59 185.553
|
||||
23.81 2448.01 186.203
|
||||
23.87 2471.86 186.926
|
||||
23.94 2476.67 187.68
|
||||
24 2508.7 188.299
|
||||
24.07 2538.05 188.906
|
||||
24.12 2586.26 189.631
|
||||
24.29 2604.62 190.362
|
||||
24.35 2666.69 190.954
|
||||
24.41 2697.54 191.56
|
||||
24.52 2729.63 192.256
|
||||
24.64 2739.75 192.938
|
||||
24.77 2808.88 193.467
|
||||
24.88 2846.34 193.994
|
||||
25.01 2898.79 194.647
|
||||
25.17 2970.48 195.279
|
||||
25.32 3042.35 195.763
|
||||
25.53 3055.53 196.277
|
||||
25.79 3076.51 196.877
|
||||
26.02 3102.36 197.481
|
||||
26.14 3127.15 197.967
|
||||
26.31 3129.53 198.455
|
||||
26.6 3154.19 199.012
|
||||
26.9 3177.98 199.572
|
||||
27.21 3236.18 199.995
|
||||
27.49 3292.07 200.452
|
||||
27.75 3316.11 200.997
|
||||
28.12 3331.22 201.538
|
||||
28.39 3381.86 201.955
|
||||
28.73 3390.23 202.419
|
||||
29.14 3409.65 202.986
|
||||
29.51 3392.6 203.584
|
||||
29.94 3386.49 204.086
|
||||
30.36 3391.61 204.721
|
||||
30.61 3422.95 205.419
|
||||
31.02 3389.36 206.13
|
||||
31.5 3481.4 206.763
|
||||
31.93 3500.95 207.362
|
||||
32.27 3523.8 208
|
||||
32.54 3533.79 208.642
|
||||
33.02 3604.73 209.142
|
||||
33.2 3687.9 209.637
|
||||
33.49 3726.18 210.181
|
||||
33.95 3790.44 210.737
|
||||
34.36 3892.22 211.192
|
||||
34.94 3919.01 211.663
|
||||
35.61 3907.08 212.191
|
||||
36.29 3947.11 212.708
|
||||
37.01 3908.15 213.144
|
||||
37.79 3922.57 213.602
|
||||
38.96 3879.98 214.147
|
||||
40.13 3854.13 214.7
|
||||
41.05 3800.93 215.135
|
||||
41.66 3835.21 215.652
|
||||
42.41 3907.02 216.289
|
||||
43.19 3952.48 216.848
|
||||
43.69 4044.59 217.314
|
||||
44.15 4072.19 217.776
|
||||
44.77 4088.49 218.338
|
||||
45.57 4126.39 218.917
|
||||
46.32 4176.28 219.427
|
||||
47.07 4260.08 219.956
|
||||
47.66 4329.46 220.573
|
||||
48.63 4328.33 221.201
|
||||
49.42 4345.51 221.719
|
||||
50.41 4510.73 222.281
|
||||
51.27 4552.14 222.933
|
||||
52.35 4603.65 223.583
|
||||
53.51 4605.65 224.152
|
||||
54.65 4615.64 224.737
|
||||
55.82 4644.93 225.418
|
||||
56.92 4656.23 226.117
|
||||
58.18 4678.96 226.754
|
||||
59.55 4566.62 227.389
|
||||
61.01 4562.25 228.07
|
||||
62.59 4651.86 228.689
|
||||
64.15 4739.16 229.155
|
||||
65.37 4696.82 229.674
|
||||
66.65 4753.02 230.301
|
||||
67.87 4693.76 230.903
|
||||
68.86 4615.89 231.395
|
||||
69.72 4634.88 231.906
|
||||
70.66 4612.08 232.498
|
||||
71.44 4618.26 233.074
|
||||
72.08 4662.97 233.546
|
||||
72.83 4763.57 234.028
|
||||
73.48 4849 234.603
|
||||
74.19 4939.23 235.153
|
||||
75.02 5053.56 235.605
|
||||
75.58 5132.87 236.082
|
||||
76.25 5170.34 236.657
|
||||
76.81 5203.68 237.232
|
||||
77.63 5257.26 237.673
|
||||
78.25 5283.73 238.176
|
||||
78.76 5359.6 238.789
|
||||
79.45 5393.57 239.387
|
||||
79.81 5460.83 239.861
|
||||
80.22 5466.95 240.368
|
||||
80.84 5496.29 240.962
|
||||
81.45 5526.77 241.539
|
||||
82.09 5561.8 242.009
|
||||
82.68 5618 242.52
|
||||
83.33 5667.39 243.12
|
||||
84.09 5750.57 243.721
|
||||
84.67 5785.29 244.208
|
||||
85.56 5844.05 244.716
|
||||
86.66 5878.7 245.354
|
||||
87.44 5952.83 245.966
|
||||
88.45 6010.96 246.46
|
||||
89.39 6055.61 247.017
|
||||
90.13 6087.96 247.698
|
||||
90.88 6093.51 248.374
|
||||
92 6152.59 248.928
|
||||
93.18 6171.57 249.564
|
||||
94.14 6142.1 250.299
|
||||
95.11 6078.96 251.031
|
||||
96.27 6047.49 251.65
|
||||
97 6074.66 252.295
|
||||
97.7 6090.14 253.033
|
||||
98.31 6105.25 253.743
|
||||
99.13 6175.69 254.338
|
||||
99.79 6214.22 255.032
|
||||
100.17 6260.74 255.815
|
||||
100.88 6327.12 256.543
|
||||
101.84 6327.93 257.151
|
||||
102.35 6359.9 257.785
|
||||
102.83 6393.5 258.516
|
||||
103.51 6476.86 259.191
|
||||
104.13 6524.5 259.738
|
||||
104.71 6600.31 260.351
|
||||
105.39 6629.47 261.04
|
||||
106.09 6688.61 261.692
|
||||
106.75 6717.46 262.236
|
||||
107.24 6724.2 262.847
|
||||
107.75 6779.53 263.527
|
||||
108.29 6825.8 264.169
|
||||
108.91 6882 264.681
|
||||
109.24 6983.91 265.258
|
||||
109.74 7020 265.887
|
||||
110.23 7093.12 266.491
|
||||
111 7166.68 266.987
|
||||
111.43 7236.5 267.545
|
||||
111.76 7311.24 268.171
|
||||
112.08 7364.63 268.815];
|
||||
|
||||
%Compute growth rates: from 1950:I to 1997:IV
|
||||
gy_obs=1000*data_q(:,2)./data_q(:,3); %real GDP per capita
|
||||
gy_obs=diff(log(gy_obs));
|
||||
|
||||
gp_obs = diff(log(data_q(:,1))); %GDP deflator inflation
|
57
license.txt
57
license.txt
|
@ -113,7 +113,7 @@ Copyright: 1995 E.G.Tsionas
|
|||
2015-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/endogenous_prior.m
|
||||
Files: matlab/estimation/endogenous_prior.m
|
||||
Copyright: 2011 Lawrence J. Christiano, Mathias Trabandt and Karl Walentin
|
||||
2013-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -128,7 +128,7 @@ Copyright: 2016 Benjamin Born and Johannes Pfeifer
|
|||
2016-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/commutation.m matlab/duplication.m
|
||||
Files: matlab/+pruned_SS/commutation.m matlab/+pruned_SS/duplication.m
|
||||
Copyright: 1997 Tom Minka <minka@microsoft.com>
|
||||
2019-2020 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -141,7 +141,7 @@ Comment: The original author gave authorization to change
|
|||
the license from BSD-2-clause to GPL-3+ and redistribute
|
||||
it under GPL-3+ with Dynare.
|
||||
|
||||
Files: matlab/uperm.m
|
||||
Files: matlab/+pruned_SS/uperm.m
|
||||
Copyright: 2014 Bruno Luong <brunoluong@yahoo.com>
|
||||
2020 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -149,7 +149,7 @@ Comment: The original author gave authorization to change
|
|||
the license from BSD-2-clause to GPL-3+ and redistribute
|
||||
it under GPL-3+ with Dynare.
|
||||
|
||||
Files: matlab/prodmom.m matlab/bivmom.m
|
||||
Files: matlab/+pruned_SS/prodmom.m matlab/+pruned_SS/bivmom.m
|
||||
Copyright: 2008-2015 Raymond Kan <kan@chass.utoronto.ca>
|
||||
2019-2020 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -161,33 +161,33 @@ Comment: The author gave authorization to redistribute
|
|||
Journal of Multivariate Analysis, 2008, vol. 99, issue 3,
|
||||
pages 542-554.
|
||||
|
||||
Files: matlab/gsa/Morris_Measure_Groups.m
|
||||
matlab/gsa/Sampling_Function_2.m
|
||||
Files: matlab/+gsa/Morris_Measure_Groups.m
|
||||
matlab/+gsa/Sampling_Function_2.m
|
||||
Copyright: 2005 European Commission
|
||||
2012-2017 Dynare Team
|
||||
2012-2013 Dynare Team
|
||||
License: GPL-3+
|
||||
Comment: Written by Jessica Cariboni and Francesca Campolongo
|
||||
Joint Research Centre, The European Commission,
|
||||
|
||||
Files: matlab/gsa/cumplot.m
|
||||
matlab/gsa/filt_mc_.m
|
||||
matlab/gsa/gsa_skewness.m
|
||||
matlab/gsa/log_trans_.m
|
||||
matlab/gsa/map_calibration.m
|
||||
matlab/gsa/map_ident_.m
|
||||
matlab/gsa/mcf_analysis.m
|
||||
matlab/gsa/myboxplot.m
|
||||
matlab/gsa/prior_draw_gsa.m
|
||||
matlab/gsa/redform_map.m
|
||||
matlab/gsa/redform_screen.m
|
||||
matlab/gsa/scatter_mcf.m
|
||||
matlab/gsa/smirnov.m
|
||||
matlab/gsa/stab_map_.m
|
||||
matlab/gsa/stab_map_1.m
|
||||
matlab/gsa/stab_map_2.m
|
||||
matlab/gsa/stand_.m
|
||||
matlab/gsa/tcrit.m
|
||||
matlab/gsa/teff.m
|
||||
Files: matlab/+gsa/cumplot.m
|
||||
matlab/+gsa/monte_carlo_filtering.m
|
||||
matlab/+gsa/skewness.m
|
||||
matlab/+gsa/log_trans_.m
|
||||
matlab/+gsa/map_calibration.m
|
||||
matlab/+gsa/map_identification.m
|
||||
matlab/+gsa/monte_carlo_filtering_analysis.m
|
||||
matlab/+gsa/boxplot.m
|
||||
matlab/+gsa/prior_draw.m
|
||||
matlab/+gsa/reduced_form_mapping.m
|
||||
matlab/+gsa/reduced_form_screening.m
|
||||
matlab/+gsa/scatter_mcf.m
|
||||
matlab/+gsa/smirnov_test.m
|
||||
matlab/+gsa/stability_mapping.m
|
||||
matlab/+gsa/stability_mapping_univariate.m
|
||||
matlab/+gsa/stability_mapping_bivariate.m
|
||||
matlab/+gsa/standardize_columns.m
|
||||
matlab/+gsa/tcrit.m
|
||||
matlab/+gsa/teff.m
|
||||
Copyright: 2011-2018 European Commission
|
||||
2011-2023 Dynare Team
|
||||
License: GPL-3+
|
||||
|
@ -245,6 +245,11 @@ Copyright: 2005-2010 Pascal Getreuer
|
|||
2017 Dynare Team
|
||||
License: BSD-2-clause
|
||||
|
||||
Files: examples/fs2000_data.m
|
||||
Copyright: 2000-2022 Frank Schorfheide
|
||||
Copyright: 2023 Dynare Team
|
||||
License: CC-BY-SA-4.0
|
||||
|
||||
Files: doc/*.rst doc/*.tex doc/*.svg doc/*.pdf doc/*.bib
|
||||
Copyright: 1996-2022 Dynare Team
|
||||
License: GFDL-NIV-1.3+
|
||||
|
|
|
@ -54,7 +54,7 @@ LIB64="$ROOTDIR"/macOS/deps/"$PKG_ARCH"/lib64
|
|||
## - the macOS linker is different from GNU ld and does not have the equivalent of -Bstatic/-Bdynamic
|
||||
## - libgfortran.spec does not include --as-needed on macOS, hence it will link the library anyways
|
||||
## Also, it does not seem possible to override libgfortran.spec with the --specs option.
|
||||
GCC_VERSION=$(sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" "$ROOTDIR"/scripts/homebrew-native-"$PKG_ARCH".ini)
|
||||
GCC_VERSION=$(sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" "$ROOTDIR"/macOS/homebrew-native-"$PKG_ARCH".ini)
|
||||
|
||||
QUADMATH_DIR=$(mktemp -d)
|
||||
ln -s "$BREWDIR"/opt/gcc/lib/gcc/"$GCC_VERSION"/libquadmath.a "$QUADMATH_DIR"
|
||||
|
@ -67,7 +67,7 @@ cd "$ROOTDIR"
|
|||
# NB: the addition of -Wl,-ld_classic is a workaround for https://github.com/mesonbuild/meson/issues/12282 (see also the native file)
|
||||
common_meson_opts=(-Dbuild_for=matlab -Dbuildtype=release -Dprefer_static=true -Dfortran_args="[ '-B', '$LIB64/Slicot/' ]" \
|
||||
-Dc_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dcpp_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dfortran_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" \
|
||||
--native-file scripts/homebrew-native-$PKG_ARCH.ini)
|
||||
--native-file macOS/homebrew-native-$PKG_ARCH.ini)
|
||||
|
||||
# Build for MATLAB ⩾ R2018b (x86_64) and MATLAB ⩾ R2023b (arm64)
|
||||
arch -"$PKG_ARCH" meson setup "${common_meson_opts[@]}" -Dmatlab_path="$MATLAB_PATH" build-matlab --wipe
|
||||
|
|
|
@ -22,7 +22,7 @@ DEPS_ARCH ?= x86_64 # use x86_64 by default
|
|||
|
||||
BREWDIR := $(if $(filter arm64,$(DEPS_ARCH)),/opt/homebrew,/usr/local)
|
||||
|
||||
GCC_VERSION = $(shell sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" ../../scripts/homebrew-native-$(DEPS_ARCH).ini)
|
||||
GCC_VERSION = $(shell sed -En "/^c[[:space:]]*=/s/c[[:space:]]*=[[:space:]]*'.*gcc-([0-9]+)'/\1/p" ../homebrew-native-$(DEPS_ARCH).ini)
|
||||
|
||||
ROOT_PATH = $(realpath .)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function [forcs, e] = mcforecast3(cL, H, mcValue, shocks, forcs, T, R, mv, mu)
|
||||
% [forcs, e] = mcforecast3(cL, H, mcValue, shocks, forcs, T, R, mv, mu)
|
||||
function [forcs, e] = get_shock_paths(cL, H, mcValue, shocks, forcs, T, R, mv, mu)
|
||||
% [forcs, e] = get_shock_paths(cL, H, mcValue, shocks, forcs, T, R, mv, mu)
|
||||
% Computes the shock values for constrained forecasts necessary to keep
|
||||
% endogenous variables at their constrained paths
|
||||
%
|
|
@ -1,4 +1,5 @@
|
|||
function plot_icforecast(Variables,periods,options_,oo_)
|
||||
function plot(Variables,periods,options_,oo_)
|
||||
% plot(Variables,periods,options_,oo_)
|
||||
% Build plots for the conditional forecasts.
|
||||
%
|
||||
% INPUTS
|
||||
|
@ -11,7 +12,7 @@ function plot_icforecast(Variables,periods,options_,oo_)
|
|||
% None.
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% This routine has to be called after imcforecast.m.
|
||||
% This routine has to be called after conditional_forecasts.run
|
||||
|
||||
% Copyright © 2006-2023 Dynare Team
|
||||
%
|
||||
|
@ -44,7 +45,7 @@ else
|
|||
end
|
||||
|
||||
if periods>forecast_periods
|
||||
fprintf('\nplot_icforecast:: Number of periods for plotting exceeds forecast horizon. Setting periods to %d.\n',forecast_periods-1)
|
||||
fprintf('\nconditional_forecasts.plot:: Number of periods for plotting exceeds forecast horizon. Setting periods to %d.\n',forecast_periods-1)
|
||||
periods=forecast_periods;
|
||||
end
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
|
||||
|
||||
function forecasts=run(M_,options_,oo_,bayestopt_,estim_params_,constrained_paths, constrained_vars, options_cond_fcst)
|
||||
% run(constrained_paths, constrained_vars, options_cond_fcst)
|
||||
% Computes conditional forecasts.
|
||||
%
|
||||
% INPUTS
|
||||
% - constrained_paths [double] m*p array, where m is the number of constrained endogenous variables and p is the number of constrained periods.
|
||||
% - constrained_vars [integer] m*1 array, indices in M_.endo_names of the constrained variables.
|
||||
% - options_cond_fcst [structure] containing the options. The fields are:
|
||||
% M_ [structure] describing the model
|
||||
% options_ [structure] describing the options
|
||||
% oo_: [structure] storing the results
|
||||
% bayestopt_ [structure] describing the priors
|
||||
% estim_params_ [structure] characterizing parameters to be estimated
|
||||
% - constrained_paths [double] m*p array, where m is the number of constrained endogenous variables and p is the number of constrained periods.
|
||||
% - constrained_vars [integer] m*1 array, indices in M_.endo_names of the constrained variables.
|
||||
% - options_cond_fcst [structure] containing the options. The fields are:
|
||||
%
|
||||
% + replic [integer] scalar, number of monte carlo simulations.
|
||||
% + parameter_set [char] values of the estimated parameters:
|
||||
|
@ -19,16 +24,16 @@ function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
|
|||
% + conf_sig [double] scalar in [0,1], probability mass covered by the confidence bands.
|
||||
%
|
||||
% OUTPUTS
|
||||
% None.
|
||||
% - forecasts [structure] results of the conditional forecast exercise
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% This routine has to be called after an estimation statement or an estimated_params block.
|
||||
%
|
||||
% REMARKS
|
||||
% [1] Results are stored in oo_.conditional_forecast.
|
||||
% [2] Use the function plot_icforecast to plot the results.
|
||||
% [2] Use the function conditional_forecasts.plot to plot the results.
|
||||
|
||||
% Copyright © 2006-2020 Dynare Team
|
||||
% Copyright © 2006-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -45,8 +50,6 @@ function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global options_ oo_ M_ bayestopt_ estim_params_
|
||||
|
||||
if ~isfield(options_cond_fcst,'parameter_set') || isempty(options_cond_fcst.parameter_set)
|
||||
if isfield(oo_,'posterior_mode')
|
||||
options_cond_fcst.parameter_set = 'posterior_mode';
|
||||
|
@ -123,7 +126,6 @@ if estimated_model
|
|||
missing_value = dataset_info.missing.state;
|
||||
|
||||
%store qz_criterium
|
||||
qz_criterium_old=options_.qz_criterium;
|
||||
options_=select_qz_criterium_value(options_);
|
||||
options_smoothed_state_uncertainty_old = options_.smoothed_state_uncertainty;
|
||||
[atT, ~, ~, ~,ys, ~, ~, ~, ~, ~, ~, ~, ~, ~,oo_,bayestopt_] = ...
|
||||
|
@ -155,7 +157,6 @@ if estimated_model
|
|||
trend = constant(oo_.dr.order_var,:);
|
||||
InitState(:,1) = atT(:,end);
|
||||
else
|
||||
qz_criterium_old=options_.qz_criterium;
|
||||
if isempty(options_.qz_criterium)
|
||||
options_.qz_criterium = 1+1e-6;
|
||||
end
|
||||
|
@ -246,7 +247,7 @@ FORCS1_shocks = zeros(n1,cL,options_cond_fcst.replic);
|
|||
for b=1:options_cond_fcst.replic %conditional forecast using cL set to constrained values
|
||||
shocks = sQ*randn(ExoSize,options_cond_fcst.periods);
|
||||
shocks(controlled_varexo,:) = zeros(n1, options_cond_fcst.periods);
|
||||
[FORCS1(:,:,b), FORCS1_shocks(:,:,b)] = mcforecast3(cL,options_cond_fcst.periods,constrained_paths,shocks,FORCS1(:,:,b),T,R,mv, mu);
|
||||
[FORCS1(:,:,b), FORCS1_shocks(:,:,b)] = conditional_forecasts.get_shock_paths(cL,options_cond_fcst.periods,constrained_paths,shocks,FORCS1(:,:,b),T,R,mv, mu);
|
||||
FORCS1(:,:,b)=FORCS1(:,:,b)+trend; %add trend
|
||||
end
|
||||
if max(max(max(abs(bsxfun(@minus,FORCS1(constrained_vars,1+1:1+cL,:),trend(constrained_vars,1:cL)+constrained_paths)))))>1e-4
|
||||
|
@ -292,7 +293,7 @@ FORCS2(:,1,:) = repmat(InitState,1,options_cond_fcst.replic); %set initial stead
|
|||
for b=1:options_cond_fcst.replic %conditional forecast using cL set to 0
|
||||
shocks = sQ*randn(ExoSize,options_cond_fcst.periods);
|
||||
shocks(controlled_varexo,:) = zeros(n1, options_cond_fcst.periods);
|
||||
FORCS2(:,:,b) = mcforecast3(0,options_cond_fcst.periods,constrained_paths,shocks,FORCS2(:,:,b),T,R,mv, mu)+trend;
|
||||
FORCS2(:,:,b) = conditional_forecasts.get_shock_paths(0,options_cond_fcst.periods,constrained_paths,shocks,FORCS2(:,:,b),T,R,mv, mu)+trend;
|
||||
end
|
||||
|
||||
mFORCS2 = mean(FORCS2,3);
|
||||
|
@ -307,8 +308,4 @@ for i = 1:EndoSize
|
|||
forecasts.uncond.ci.(M_.endo_names{oo_.dr.order_var(i)}) = [tmp(t1,:)' ,tmp(t2,:)' ]';
|
||||
end
|
||||
forecasts.graph.title = graph_title;
|
||||
forecasts.graph.fname = M_.fname;
|
||||
|
||||
%reset qz_criterium
|
||||
options_.qz_criterium=qz_criterium_old;
|
||||
oo_.conditional_forecast = forecasts;
|
||||
forecasts.graph.fname = M_.fname;
|
|
@ -1,5 +1,5 @@
|
|||
function sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
% sout = myboxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
function sout = boxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
% sout = boxplot (data,notched,symbol,vertical,maxwhisker)
|
||||
% Creates a box plot
|
||||
|
||||
% Copyright © 2010-2023 Dynare Team
|
|
@ -1,5 +1,5 @@
|
|||
function [yy, xdir, isig, lam]=log_trans_(y0,xdir0,isig,lam)
|
||||
% [yy, xdir, isig, lam]=log_trans_(y0,xdir0,isig,lam)
|
||||
function [yy, xdir, isig, lam]=log_transform(y0,xdir0,isig,lam)
|
||||
% [yy, xdir, isig, lam]=log_transform(y0,xdir0,isig,lam)
|
||||
% Conduct automatic log transformation lam(yy/isig+lam)
|
||||
% Inputs:
|
||||
% - y0 [double] series to transform
|
||||
|
@ -56,10 +56,10 @@ end
|
|||
if nargin==1
|
||||
xdir0='';
|
||||
end
|
||||
f=@(lam,y)gsa_skewness(log(y+lam));
|
||||
f=@(lam,y)gsa.skewness(log(y+lam));
|
||||
isig=1;
|
||||
if ~(max(y0)<0 || min(y0)>0)
|
||||
if gsa_skewness(y0)<0
|
||||
if gsa.skewness(y0)<0
|
||||
isig=-1;
|
||||
y0=-y0;
|
||||
end
|
|
@ -229,7 +229,7 @@ if ~isempty(indx_irf)
|
|||
if ~options_.nograph && length(time_matrix{plot_indx(ij)})==1
|
||||
set(0,'currentfigure',h1),
|
||||
subplot(nrow,ncol, plot_indx(ij)),
|
||||
hc = cumplot(mat_irf{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_irf{ij}(:,ik));
|
||||
a=axis;
|
||||
delete(hc);
|
||||
x1val=max(endo_prior_restrictions.irf{ij,4}(1),a(1));
|
||||
|
@ -237,7 +237,7 @@ if ~isempty(indx_irf)
|
|||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
hold all,
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hc = cumplot(mat_irf{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_irf{ij}(:,ik));
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off,
|
||||
% hold off,
|
||||
|
@ -259,7 +259,7 @@ if ~isempty(indx_irf)
|
|||
end
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
end
|
||||
for ij=1:nbr_irf_couples
|
||||
|
@ -316,7 +316,7 @@ if ~isempty(indx_irf)
|
|||
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -434,7 +434,7 @@ if ~isempty(indx_moment)
|
|||
if ~options_.nograph && length(time_matrix{plot_indx(ij)})==1
|
||||
set(0,'currentfigure',h2);
|
||||
subplot(nrow,ncol,plot_indx(ij)),
|
||||
hc = cumplot(mat_moment{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_moment{ij}(:,ik));
|
||||
a=axis; delete(hc),
|
||||
% hist(mat_moment{ij}),
|
||||
x1val=max(endo_prior_restrictions.moment{ij,4}(1),a(1));
|
||||
|
@ -442,7 +442,7 @@ if ~isempty(indx_moment)
|
|||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hold all
|
||||
hc = cumplot(mat_moment{ij}(:,ik));
|
||||
hc = gsa.cumplot(mat_moment{ij}(:,ik));
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off
|
||||
title([endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2},'(',leg,')'],'interpreter','none'),
|
||||
|
@ -463,7 +463,7 @@ if ~isempty(indx_moment)
|
|||
end
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat, indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat, indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
end
|
||||
for ij=1:nbr_moment_couples
|
||||
|
@ -520,7 +520,7 @@ if ~isempty(indx_moment)
|
|||
end
|
||||
options_mcf.title = atitle0;
|
||||
if ~isempty(indx1) && ~isempty(indx2)
|
||||
mcf_analysis(xmat, indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(xmat, indx1, indx2, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function map_ident_(OutputDirectoryName,opt_gsa,M_,oo_,options_,estim_params_,bayestopt_)
|
||||
% map_ident_(OutputDirectoryName,opt_gsa,M_,oo_,options_,estim_params_,bayestopt_)
|
||||
function map_identification(OutputDirectoryName,opt_gsa,M_,oo_,options_,estim_params_,bayestopt_)
|
||||
% map_identification(OutputDirectoryName,opt_gsa,M_,oo_,options_,estim_params_,bayestopt_)
|
||||
% Inputs
|
||||
% - OutputDirectoryName [string] name of the output directory
|
||||
% - opt_gsa [structure] GSA options structure
|
||||
|
@ -58,16 +58,16 @@ fname_ = M_.fname;
|
|||
|
||||
if opt_gsa.load_ident_files==0
|
||||
mss = yys(bayestopt_.mfys,:);
|
||||
mss = teff(mss(:,istable),Nsam,istable);
|
||||
yys = teff(yys(dr.order_var,istable),Nsam,istable);
|
||||
mss = gsa.teff(mss(:,istable),Nsam,istable);
|
||||
yys = gsa.teff(yys(dr.order_var,istable),Nsam,istable);
|
||||
if exist('T','var')
|
||||
[vdec, cc, ac] = mc_moments(T, lpmatx, dr, M_, options_, estim_params_);
|
||||
[vdec, cc, ac] = gsa.monte_carlo_moments(T, lpmatx, dr, M_, options_, estim_params_);
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
if opt_gsa.morris==2
|
||||
pdraws = dynare_identification(M_,oo_,options_,bayestopt_,estim_params_,options_.options_ident,[lpmatx lpmat(istable,:)]);
|
||||
pdraws = identification.run(M_,oo_,options_,bayestopt_,estim_params_,options_.options_ident,[lpmatx lpmat(istable,:)]);
|
||||
if ~isempty(pdraws) && max(max(abs(pdraws-[lpmatx lpmat(istable,:)])))==0
|
||||
disp(['Sample check OK. Largest difference: ', num2str(max(max(abs(pdraws-[lpmatx lpmat(istable,:)]))))]),
|
||||
clear pdraws;
|
||||
|
@ -84,7 +84,7 @@ if opt_gsa.load_ident_files==0
|
|||
end
|
||||
iplo=iplo+1;
|
||||
subplot(2,3,iplo)
|
||||
myboxplot(squeeze(vdec(:,j,:))',[],'.',[],10)
|
||||
gsa.boxplot(squeeze(vdec(:,j,:))',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:size(options_.varobs,1))
|
||||
set(gca,'xlim',[0.5 size(options_.varobs,1)+0.5])
|
||||
set(gca,'ylim',[-2 102])
|
||||
|
@ -105,11 +105,11 @@ if opt_gsa.load_ident_files==0
|
|||
end
|
||||
end
|
||||
for j=1:size(cc,1)
|
||||
cc(j,j,:)=stand_(squeeze(log(cc(j,j,:))))./2;
|
||||
cc(j,j,:)=gsa.standardize_columns(squeeze(log(cc(j,j,:))))./2;
|
||||
end
|
||||
[vdec, ~, ir_vdec, ic_vdec] = teff(vdec,Nsam,istable);
|
||||
[cc, ~, ir_cc, ic_cc] = teff(cc,Nsam,istable);
|
||||
[ac, ~, ir_ac, ic_ac] = teff(ac,Nsam,istable);
|
||||
[vdec, ~, ir_vdec, ic_vdec] = gsa.teff(vdec,Nsam,istable);
|
||||
[cc, ~, ir_cc, ic_cc] = gsa.teff(cc,Nsam,istable);
|
||||
[ac, ~, ir_ac, ic_ac] = gsa.teff(ac,Nsam,istable);
|
||||
|
||||
nc1= size(T,2);
|
||||
endo_nbr = M_.endo_nbr;
|
||||
|
@ -123,7 +123,7 @@ if opt_gsa.load_ident_files==0
|
|||
[Aa,Bb] = kalman_transition_matrix(dr,iv,ic);
|
||||
A = zeros(size(Aa,1),size(Aa,2)+size(Aa,1),length(istable));
|
||||
if ~isempty(lpmatx)
|
||||
M_=set_shocks_param(M_,estim_params_,lpmatx(1,:));
|
||||
M_=gsa.set_shocks_param(M_,estim_params_,lpmatx(1,:));
|
||||
end
|
||||
A(:,:,1)=[Aa, triu(Bb*M_.Sigma_e*Bb')];
|
||||
for j=2:length(istable)
|
||||
|
@ -131,14 +131,14 @@ if opt_gsa.load_ident_files==0
|
|||
dr.ghu = T(:, (nc1-M_.exo_nbr+1):end, j);
|
||||
[Aa,Bb] = kalman_transition_matrix(dr, iv, ic);
|
||||
if ~isempty(lpmatx)
|
||||
M_=set_shocks_param(M_,estim_params_,lpmatx(j,:));
|
||||
M_=gsa.set_shocks_param(M_,estim_params_,lpmatx(j,:));
|
||||
end
|
||||
A(:,:,j)=[Aa, triu(Bb*M_.Sigma_e*Bb')];
|
||||
end
|
||||
clear T
|
||||
clear lpmatx
|
||||
|
||||
[yt, j0]=teff(A,Nsam,istable);
|
||||
[yt, j0]=gsa.teff(A,Nsam,istable);
|
||||
yt = [yys yt];
|
||||
if opt_gsa.morris==2
|
||||
clear TAU A
|
||||
|
@ -155,7 +155,7 @@ if opt_gsa.morris==1
|
|||
if opt_gsa.load_ident_files==0
|
||||
SAMorris=NaN(npT,3,size(vdec,2));
|
||||
for i=1:size(vdec,2)
|
||||
[~, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv);
|
||||
[~, SAMorris(:,:,i)] = gsa.Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv);
|
||||
end
|
||||
SAvdec = squeeze(SAMorris(:,1,:))';
|
||||
save([OutputDirectoryName,'/',fname_,'_morris_IDE.mat'],'SAvdec','vdec','ir_vdec','ic_vdec')
|
||||
|
@ -164,7 +164,7 @@ if opt_gsa.morris==1
|
|||
end
|
||||
|
||||
hh_fig = dyn_figure(options_.nodisplay,'name','Screening identification: variance decomposition');
|
||||
myboxplot(SAvdec,[],'.',[],10)
|
||||
gsa.boxplot(SAvdec,[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:npT)
|
||||
set(gca,'xlim',[0.5 npT+0.5])
|
||||
ydum = get(gca,'ylim');
|
||||
|
@ -190,7 +190,7 @@ if opt_gsa.morris==1
|
|||
ccac = [mss cc ac];
|
||||
SAMorris=NaN(npT,3,size(ccac,2));
|
||||
for i=1:size(ccac,2)
|
||||
[~, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv);
|
||||
[~, SAMorris(:,:,i)] = gsa.Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv);
|
||||
end
|
||||
SAcc = squeeze(SAMorris(:,1,:))';
|
||||
SAcc = SAcc./(max(SAcc,[],2)*ones(1,npT));
|
||||
|
@ -202,7 +202,7 @@ if opt_gsa.morris==1
|
|||
end
|
||||
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Screening identification: theoretical moments');
|
||||
myboxplot(SAcc,[],'.',[],10)
|
||||
gsa.boxplot(SAcc,[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:npT)
|
||||
set(gca,'xlim',[0.5 npT+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
|
@ -223,7 +223,7 @@ if opt_gsa.morris==1
|
|||
if opt_gsa.load_ident_files==0
|
||||
SAMorris=NaN(npT,3,j0);
|
||||
for j=1:j0
|
||||
[~, SAMorris(:,:,j)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv);
|
||||
[~, SAMorris(:,:,j)] = gsa.Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv);
|
||||
end
|
||||
|
||||
SAM = squeeze(SAMorris(1:end,1,:));
|
||||
|
@ -249,7 +249,7 @@ if opt_gsa.morris==1
|
|||
load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm')
|
||||
end
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Screening identification: model');
|
||||
myboxplot(SAnorm',[],'.',[],10)
|
||||
gsa.boxplot(SAnorm',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:npT)
|
||||
set(gca,'xlim',[0.5 npT+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
|
@ -297,7 +297,7 @@ else % main effects analysis
|
|||
catch
|
||||
EET=[];
|
||||
end
|
||||
ccac = stand_([mss cc ac]);
|
||||
ccac = gsa.standardize_columns([mss cc ac]);
|
||||
[pcc, dd] = eig(cov(ccac(istable,:)));
|
||||
[latent, isort] = sort(-diag(dd));
|
||||
latent = -latent;
|
||||
|
@ -314,7 +314,7 @@ else % main effects analysis
|
|||
if itrans==0
|
||||
y0 = ccac(istable,j);
|
||||
elseif itrans==1
|
||||
y0 = log_trans_(ccac(istable,j));
|
||||
y0 = gsa.log_transform(ccac(istable,j));
|
||||
else
|
||||
y0 = trank(ccac(istable,j));
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function [rmse_MC, ixx] = filt_mc_(OutDir,options_gsa_,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% [rmse_MC, ixx] = filt_mc_(OutDir,options_gsa_,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_
|
||||
function [rmse_MC, ixx] = monte_carlo_filtering(OutDir,options_gsa_,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% [rmse_MC, ixx] = monte_carlo_filtering(OutDir,options_gsa_,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_
|
||||
% Inputs:
|
||||
% - OutputDirectoryName [string] name of the output directory
|
||||
% - options_gsa_ [structure] GSA options
|
||||
|
@ -288,7 +288,7 @@ options_scatter.OutputDirectoryName = OutDir;
|
|||
options_scatter.amcf_name = asname;
|
||||
options_scatter.amcf_title = atitle;
|
||||
options_scatter.title = tmp_title;
|
||||
scatter_analysis(r2_MC, x,options_scatter, options_);
|
||||
gsa.scatter_analysis(r2_MC, x,options_scatter, options_);
|
||||
% end of visual scatter analysis
|
||||
|
||||
if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only
|
||||
|
@ -320,7 +320,7 @@ if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only
|
|||
options_mcf.nobeha_title_latex = 'worse posterior kernel';
|
||||
end
|
||||
|
||||
mcf_analysis(x, ipost(1:nfilt), ipost(nfilt+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(x, ipost(1:nfilt), ipost(nfilt+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
if options_.opt_gsa.pprior
|
||||
anam = 'rmse_prior_lik';
|
||||
atitle = 'RMSE prior: Log Likelihood Kernel';
|
||||
|
@ -338,7 +338,7 @@ if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only
|
|||
options_mcf.nobeha_title_latex = 'worse likelihood';
|
||||
end
|
||||
|
||||
mcf_analysis(x, ilik(1:nfilt), ilik(nfilt+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(x, ilik(1:nfilt), ilik(nfilt+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
else
|
||||
if options_.opt_gsa.ppost
|
||||
|
@ -367,9 +367,9 @@ else
|
|||
SS = zeros(npar+nshock, length(vvarvecm));
|
||||
for j = 1:npar+nshock
|
||||
for i = 1:length(vvarvecm)
|
||||
[~, P] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j), alpha);
|
||||
[H1] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,1);
|
||||
[H2] = smirnov(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,-1);
|
||||
[~, P] = gsa.smirnov_test(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j), alpha);
|
||||
[H1] = gsa.smirnov_test(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,1);
|
||||
[H2] = gsa.smirnov_test(x(ixx(nfilt0(i)+1:end,i),j),x(ixx(1:nfilt0(i),i),j),alpha,-1);
|
||||
if H1==0 && H2==0
|
||||
SS(j,i)=1;
|
||||
elseif H1==0
|
||||
|
@ -382,7 +382,7 @@ else
|
|||
for i = 1:length(vvarvecm)
|
||||
for l = 1:length(vvarvecm)
|
||||
if l~=i && PP(j,i)<alpha && PP(j,l)<alpha
|
||||
[~,P] = smirnov(x(ixx(1:nfilt0(i),i),j),x(ixx(1:nfilt0(l),l),j), alpha);
|
||||
[~,P] = gsa.smirnov_test(x(ixx(1:nfilt0(i),i),j),x(ixx(1:nfilt0(l),l),j), alpha);
|
||||
PPV(i,l,j) = P;
|
||||
elseif l==i
|
||||
PPV(i,l,j) = PP(j,i);
|
||||
|
@ -407,11 +407,11 @@ else
|
|||
hh_fig=dyn_figure(options_.nodisplay,'name',[temp_name,' ',int2str(ifig)]);
|
||||
end
|
||||
subplot(3,3,i-9*(ifig-1))
|
||||
h=cumplot(lnprior(ixx(1:nfilt0(i),i)));
|
||||
h=gsa.cumplot(lnprior(ixx(1:nfilt0(i),i)));
|
||||
set(h,'color','blue','linewidth',2)
|
||||
hold on, h=cumplot(lnprior);
|
||||
hold on, h=gsa.cumplot(lnprior);
|
||||
set(h,'color','k','linewidth',1)
|
||||
h=cumplot(lnprior(ixx(nfilt0(i)+1:end,i)));
|
||||
h=gsa.cumplot(lnprior(ixx(nfilt0(i)+1:end,i)));
|
||||
set(h,'color','red','linewidth',2)
|
||||
if options_.TeX
|
||||
title(vvarvecm_tex{i},'interpreter','latex')
|
||||
|
@ -459,11 +459,11 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'Name',[temp_name,' ',int2str(ifig)]);
|
||||
end
|
||||
subplot(3,3,i-9*(ifig-1))
|
||||
h=cumplot(likelihood(ixx(1:nfilt0(i),i)));
|
||||
h=gsa.cumplot(likelihood(ixx(1:nfilt0(i),i)));
|
||||
set(h,'color','blue','linewidth',2)
|
||||
hold on, h=cumplot(likelihood);
|
||||
hold on, h=gsa.cumplot(likelihood);
|
||||
set(h,'color','k','linewidth',1)
|
||||
h=cumplot(likelihood(ixx(nfilt0(i)+1:end,i)));
|
||||
h=gsa.cumplot(likelihood(ixx(nfilt0(i)+1:end,i)));
|
||||
set(h,'color','red','linewidth',2)
|
||||
if options_.TeX
|
||||
title(vvarvecm_tex{i},'interpreter','latex')
|
||||
|
@ -514,11 +514,11 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'Name',[temp_name,' ',int2str(ifig)]);
|
||||
end
|
||||
subplot(3,3,i-9*(ifig-1))
|
||||
h=cumplot(logpo2(ixx(1:nfilt0(i),i)));
|
||||
h=gsa.cumplot(logpo2(ixx(1:nfilt0(i),i)));
|
||||
set(h,'color','blue','linewidth',2)
|
||||
hold on, h=cumplot(logpo2);
|
||||
hold on, h=gsa.cumplot(logpo2);
|
||||
set(h,'color','k','linewidth',1)
|
||||
h=cumplot(logpo2(ixx(nfilt0(i)+1:end,i)));
|
||||
h=gsa.cumplot(logpo2(ixx(nfilt0(i)+1:end,i)));
|
||||
set(h,'color','red','linewidth',2)
|
||||
if options_.TeX
|
||||
title(vvarvecm_tex{i},'interpreter','latex')
|
||||
|
@ -756,7 +756,7 @@ else
|
|||
options_mcf.nobeha_title_latex = ['worse fit of ' vvarvecm_tex{iy}];
|
||||
end
|
||||
options_mcf.title = ['the fit of ' vvarvecm{iy}];
|
||||
mcf_analysis(x, ixx(1:nfilt0(iy),iy), ixx(nfilt0(iy)+1:end,iy), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(x, ixx(1:nfilt0(iy),iy), ixx(nfilt0(iy)+1:end,iy), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
for iy = 1:length(vvarvecm)
|
||||
ipar = find(any(squeeze(PPV(iy,:,:))<alpha));
|
||||
|
@ -764,20 +764,20 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'name',[temp_name,' observed variable ', vvarvecm{iy}]);
|
||||
for j=1+5*(ix-1):min(length(ipar),5*ix)
|
||||
subplot(2,3,j-5*(ix-1))
|
||||
h0=cumplot(x(:,ipar(j)));
|
||||
h0=gsa.cumplot(x(:,ipar(j)));
|
||||
set(h0,'color',[0 0 0])
|
||||
hold on,
|
||||
iobs=find(squeeze(PPV(iy,:,ipar(j)))<alpha);
|
||||
for i = 1:length(vvarvecm)
|
||||
if any(iobs==i) || i==iy
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),ipar(j)));
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),ipar(j)));
|
||||
if ~isoctave
|
||||
hcmenu = uicontextmenu;
|
||||
uimenu(hcmenu,'Label',vvarvecm{i});
|
||||
set(h0,'uicontextmenu',hcmenu)
|
||||
end
|
||||
else
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),ipar(j))*NaN);
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),ipar(j))*NaN);
|
||||
end
|
||||
set(h0,'color',a00(i,:),'linewidth',2)
|
||||
end
|
||||
|
@ -829,15 +829,15 @@ else
|
|||
hh_fig = dyn_figure(options_.nodisplay,'name',[temp_name,' estimated params and shocks ',int2str(ix)]);
|
||||
for j=1+5*(ix-1):min(size(snam2,1),5*ix)
|
||||
subplot(2,3,j-5*(ix-1))
|
||||
h0=cumplot(x(:,nsnam(j)));
|
||||
h0=gsa.cumplot(x(:,nsnam(j)));
|
||||
set(h0,'color',[0 0 0])
|
||||
hold on,
|
||||
npx=find(SP(nsnam(j),:)==0);
|
||||
for i = 1:length(vvarvecm)
|
||||
if any(npx==i)
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),nsnam(j))*NaN);
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),nsnam(j))*NaN);
|
||||
else
|
||||
h0=cumplot(x(ixx(1:nfilt0(i),i),nsnam(j)));
|
||||
h0=gsa.cumplot(x(ixx(1:nfilt0(i),i),nsnam(j)));
|
||||
if ~isoctave
|
||||
hcmenu = uicontextmenu;
|
||||
uimenu(hcmenu,'Label', vvarvecm{i});
|
|
@ -1,5 +1,5 @@
|
|||
function indmcf = mcf_analysis(lpmat, ibeha, inobeha, options_mcf, M_, options_, bayestopt_, estim_params_)
|
||||
% indmcf = mcf_analysis(lpmat, ibeha, inobeha, options_mcf, M_, options_, bayestopt_, estim_params_)
|
||||
function indmcf = monte_carlo_filtering_analysis(lpmat, ibeha, inobeha, options_mcf, M_, options_, bayestopt_, estim_params_)
|
||||
% indmcf = monte_carlo_filtering_analysis(lpmat, ibeha, inobeha, options_mcf, M_, options_, bayestopt_, estim_params_)
|
||||
% Inputs:
|
||||
% - lpmat [double] Monte Carlo matrix
|
||||
% - ibeha [integer] index of behavioural runs
|
||||
|
@ -66,7 +66,7 @@ if isfield(options_mcf,'xparam1')
|
|||
end
|
||||
OutputDirectoryName = options_mcf.OutputDirectoryName;
|
||||
|
||||
[proba, dproba] = stab_map_1(lpmat, ibeha, inobeha, [],fname_, options_, bayestopt_.name, estim_params_,0);
|
||||
[proba, dproba] = gsa.stability_mapping_univariate(lpmat, ibeha, inobeha, [],fname_, options_, bayestopt_.name, estim_params_,0);
|
||||
indmcf=find(proba<pvalue_ks);
|
||||
[~,jtmp] = sort(proba(indmcf),1,'ascend');
|
||||
indmcf = indmcf(jtmp);
|
||||
|
@ -87,11 +87,11 @@ end
|
|||
|
||||
if length(ibeha)>10 && length(inobeha)>10
|
||||
if options_.TeX
|
||||
indcorr1 = stab_map_2(lpmat(ibeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, beha_title, beha_title_latex);
|
||||
indcorr2 = stab_map_2(lpmat(inobeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, nobeha_title, nobeha_title_latex);
|
||||
indcorr1 = gsa.stability_mapping_bivariate(lpmat(ibeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, beha_title, beha_title_latex);
|
||||
indcorr2 = gsa.stability_mapping_bivariate(lpmat(inobeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, nobeha_title, nobeha_title_latex);
|
||||
else
|
||||
indcorr1 = stab_map_2(lpmat(ibeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, beha_title);
|
||||
indcorr2 = stab_map_2(lpmat(inobeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, nobeha_title);
|
||||
indcorr1 = gsa.stability_mapping_bivariate(lpmat(ibeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, beha_title);
|
||||
indcorr2 = gsa.stability_mapping_bivariate(lpmat(inobeha,:),alpha2, pvalue_corr, M_, options_, bayestopt_, estim_params_, nobeha_title);
|
||||
end
|
||||
indcorr = union(indcorr1(:), indcorr2(:));
|
||||
indcorr = indcorr(~ismember(indcorr(:),indmcf));
|
||||
|
@ -104,11 +104,11 @@ if ~isempty(indmcf) && ~options_.nograph
|
|||
xx=xparam1(indmcf);
|
||||
end
|
||||
if options_.TeX
|
||||
scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names_tex(indmcf), ...
|
||||
gsa.scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names_tex(indmcf), ...
|
||||
'.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,xx, options_, ...
|
||||
beha_title, nobeha_title, beha_title_latex, nobeha_title_latex)
|
||||
else
|
||||
scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names_tex(indmcf), ...
|
||||
gsa.scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names_tex(indmcf), ...
|
||||
'.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,xx, options_, ...
|
||||
beha_title, nobeha_title)
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function [vdec, cc, ac] = mc_moments(mm, ss, dr, M_, options_, estim_params_)
|
||||
% [vdec, cc, ac] = mc_moments(mm, ss, dr, M_, options_,estim_params_)
|
||||
function [vdec, cc, ac] = monte_carlo_moments(mm, ss, dr, M_, options_, estim_params_)
|
||||
% [vdec, cc, ac] = monte_carlo_moments(mm, ss, dr, M_, options_,estim_params_)
|
||||
% Conduct Monte Carlo simulation of second moments for GSA
|
||||
% Inputs:
|
||||
% - dr [structure] decision rules
|
||||
|
@ -32,7 +32,7 @@ function [vdec, cc, ac] = mc_moments(mm, ss, dr, M_, options_, estim_params_)
|
|||
|
||||
[~, nc1, nsam] = size(mm);
|
||||
nobs=length(options_.varobs);
|
||||
disp('mc_moments: Computing theoretical moments ...')
|
||||
disp('monte_carlo_moments: Computing theoretical moments ...')
|
||||
h = dyn_waitbar(0,'Theoretical moments ...');
|
||||
vdec = zeros(nobs,M_.exo_nbr,nsam);
|
||||
cc = zeros(nobs,nobs,nsam);
|
||||
|
@ -42,9 +42,9 @@ for j=1:nsam
|
|||
dr.ghx = mm(:, 1:(nc1-M_.exo_nbr),j);
|
||||
dr.ghu = mm(:, (nc1-M_.exo_nbr+1):end, j);
|
||||
if ~isempty(ss)
|
||||
M_=set_shocks_param(M_,estim_params_,ss(j,:));
|
||||
M_=gsa.set_shocks_param(M_,estim_params_,ss(j,:));
|
||||
end
|
||||
[vdec(:,:,j), corr, autocorr] = th_moments(dr,options_,M_);
|
||||
[vdec(:,:,j), corr, autocorr] = gsa.th_moments(dr,options_,M_);
|
||||
cc(:,:,j)=triu(corr);
|
||||
dum=NaN(nobs,nobs*options_.ar);
|
||||
for i=1:options_.ar
|
|
@ -1,4 +1,5 @@
|
|||
function pdraw = prior_draw_gsa(M_,bayestopt_,options_,estim_params_,init,rdraw)
|
||||
function pdraw = prior_draw(M_,bayestopt_,options_,estim_params_,init,rdraw)
|
||||
% pdraw = prior_draw(M_,bayestopt_,options_,estim_params_,init,rdraw)
|
||||
% Draws from the prior distributions for use with Sensitivity Toolbox for DYNARE
|
||||
%
|
||||
% INPUTS
|
|
@ -1,5 +1,5 @@
|
|||
function redform_map(dirname,options_gsa_,M_,estim_params_,options_,bayestopt_,oo_)
|
||||
% redform_map(dirname,options_gsa_,M_,estim_params_,options_,bayestopt_,oo_)
|
||||
function reduced_form_mapping(dirname,options_gsa_,M_,estim_params_,options_,bayestopt_,oo_)
|
||||
% reduced_form_mapping(dirname,options_gsa_,M_,estim_params_,options_,bayestopt_,oo_)
|
||||
% Inputs:
|
||||
% - dirname [string] name of the output directory
|
||||
% - options_gsa_ [structure] GSA options_
|
||||
|
@ -85,7 +85,7 @@ options_mcf.fname_ = M_.fname;
|
|||
options_mcf.OutputDirectoryName = adir;
|
||||
|
||||
if ~exist('T','var')
|
||||
stab_map_(dirname,options_gsa_,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
gsa.stability_mapping(dirname,options_gsa_,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
if pprior
|
||||
load([dirname,filesep,M_.fname,'_prior'],'T');
|
||||
else
|
||||
|
@ -182,14 +182,14 @@ for j = 1:length(anamendo)
|
|||
end
|
||||
if ~options_.nograph
|
||||
hf=dyn_figure(options_.nodisplay,'name',['Reduced Form Mapping (Monte Carlo Filtering): ',namendo,' vs ', namexo]);
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
a=axis; delete(hc);
|
||||
x1val=max(threshold(1),a(1));
|
||||
x2val=min(threshold(2),a(2));
|
||||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hold all,
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off,
|
||||
if options_.TeX
|
||||
|
@ -218,7 +218,7 @@ for j = 1:length(anamendo)
|
|||
options_mcf.OutputDirectoryName = xdir;
|
||||
if ~isempty(iy) && ~isempty(iyc)
|
||||
fprintf(['%4.1f%% of the ',type,' support matches ',atitle0,'\n'],length(iy)/length(y0)*100)
|
||||
icheck = mcf_analysis(x0, iy, iyc, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
icheck = gsa.monte_carlo_filtering_analysis(x0, iy, iyc, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
lpmat=x0(iy,:);
|
||||
if nshocks
|
||||
|
@ -349,14 +349,14 @@ for j = 1:length(anamendo)
|
|||
end
|
||||
if ~options_.nograph
|
||||
hf=dyn_figure(options_.nodisplay,'name',['Reduced Form Mapping (Monte Carlo Filtering): ',namendo,' vs lagged ', namlagendo]);
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
a=axis; delete(hc);
|
||||
x1val=max(threshold(1),a(1));
|
||||
x2val=min(threshold(2),a(2));
|
||||
hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
|
||||
set(hp,'FaceColor', [0.7 0.8 1])
|
||||
hold all,
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
set(hc,'color','k','linewidth',2)
|
||||
hold off
|
||||
if options_.TeX
|
||||
|
@ -387,7 +387,7 @@ for j = 1:length(anamendo)
|
|||
if ~isempty(iy) && ~isempty(iyc)
|
||||
|
||||
fprintf(['%4.1f%% of the ',type,' support matches ',atitle0,'\n'],length(iy)/length(y0)*100)
|
||||
icheck = mcf_analysis(x0, iy, iyc, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
icheck = gsa.monte_carlo_filtering_analysis(x0, iy, iyc, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
lpmat=x0(iy,:);
|
||||
if nshocks
|
||||
|
@ -476,9 +476,9 @@ end
|
|||
if isempty(threshold) && ~options_.nograph
|
||||
hh_fig=dyn_figure(options_.nodisplay,'name','Reduced Form GSA');
|
||||
if ilog==0
|
||||
myboxplot(si',[],'.',[],10)
|
||||
gsa.boxplot(si',[],'.',[],10)
|
||||
else
|
||||
myboxplot(silog',[],'.',[],10)
|
||||
gsa.boxplot(silog',[],'.',[],10)
|
||||
end
|
||||
xlabel(' ')
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:np)
|
||||
|
@ -513,7 +513,7 @@ if options_map.prior_range
|
|||
x0(:,j)=(x0(:,j)-pd(j,3))./(pd(j,4)-pd(j,3));
|
||||
end
|
||||
else
|
||||
x0=priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4));
|
||||
x0=gsa.priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4));
|
||||
end
|
||||
|
||||
if ilog
|
||||
|
@ -549,7 +549,7 @@ if iload==0
|
|||
ipred = setdiff(1:nrun,ifit);
|
||||
|
||||
if ilog
|
||||
[~, ~, isig, lam] = log_trans_(y0(iest));
|
||||
[~, ~, isig, lam] = gsa.log_transform(y0(iest));
|
||||
y1 = log(y0*isig+lam);
|
||||
end
|
||||
if ~options_.nograph
|
||||
|
@ -571,9 +571,9 @@ if iload==0
|
|||
title(options_map.title,'interpreter','none')
|
||||
subplot(222)
|
||||
if ilog
|
||||
hc = cumplot(y1);
|
||||
hc = gsa.cumplot(y1);
|
||||
else
|
||||
hc = cumplot(y0);
|
||||
hc = gsa.cumplot(y0);
|
||||
end
|
||||
set(hc,'color','k','linewidth',2)
|
||||
title([options_map.title ' CDF'],'interpreter','none')
|
||||
|
@ -620,7 +620,7 @@ if iload==0
|
|||
if nfit<nrun
|
||||
if ilog
|
||||
yf = ss_anova_fcast(x0(ipred,:), gsa1);
|
||||
yf = log_trans_(yf,'',isig,lam)+ss_anova_fcast(x0(ipred,:), gsax);
|
||||
yf = gsa.log_transform(yf,'',isig,lam)+ss_anova_fcast(x0(ipred,:), gsax);
|
||||
else
|
||||
yf = ss_anova_fcast(x0(ipred,:), gsa_);
|
||||
end
|
||||
|
@ -657,7 +657,7 @@ function gsa2 = log2level_map(gsa1, isig, lam)
|
|||
nest=length(gsa1.y);
|
||||
np = size(gsa1.x0,2);
|
||||
gsa2=gsa1;
|
||||
gsa2.y = log_trans_(gsa1.y,'',isig,lam);
|
||||
gsa2.y = gsa.log_transform(gsa1.y,'',isig,lam);
|
||||
gsa2.fit = (exp(gsa1.fit)-lam)*isig;
|
||||
gsa2.f0 = mean(gsa2.fit);
|
||||
gsa2.out.SSE = sum((gsa2.fit-gsa2.y).^2);
|
||||
|
@ -727,7 +727,7 @@ for jt=1:10
|
|||
indy{jt}=find( (y0>post_deciles(jt)) & (y0<=post_deciles(jt+1)));
|
||||
leg{jt}=[int2str(jt) '-dec'];
|
||||
end
|
||||
[proba] = stab_map_1(x0, indy{1}, indy{end}, [], fname, options_, parnames, estim_params_,0);
|
||||
[proba] = gsa.stability_mapping_univariate(x0, indy{1}, indy{end}, [], fname, options_, parnames, estim_params_,0);
|
||||
indmcf=find(proba<options_mcf.pvalue_ks);
|
||||
if isempty(indmcf)
|
||||
[~,jtmp] = sort(proba,1,'ascend');
|
||||
|
@ -747,7 +747,7 @@ for jx=1:nbr_par
|
|||
subplot(nrow,ncol,jx)
|
||||
hold off
|
||||
for jt=1:10
|
||||
h=cumplot(x0(indy{jt},indmcf(jx)));
|
||||
h=gsa.cumplot(x0(indy{jt},indmcf(jx)));
|
||||
set(h,'color', cmap(jt,:), 'linewidth', 2)
|
||||
hold all
|
||||
end
|
||||
|
@ -782,7 +782,7 @@ if nargin<5
|
|||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([figpath '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by redform_map.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by reduced_form_mapping.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
|
@ -1,5 +1,5 @@
|
|||
function redform_screen(dirname, options_gsa_, estim_params_, M_, dr, options_, bayestopt_)
|
||||
% redform_screen(dirname, options_gsa_, estim_params_, M_, dr, options_, bayestopt_)
|
||||
function reduced_form_screening(dirname, options_gsa_, estim_params_, M_, dr, options_, bayestopt_)
|
||||
% reduced_form_screening(dirname, options_gsa_, estim_params_, M_, dr, options_, bayestopt_)
|
||||
% Conduct reduced form screening
|
||||
% Inputs:
|
||||
% - dirname [string] name of the output directory
|
||||
|
@ -72,7 +72,7 @@ for j=1:size(anamendo,1)
|
|||
namexo_tex = anamexo_tex{jx};
|
||||
iexo = strmatch(namexo, M_.exo_names, 'exact');
|
||||
if ~isempty(iexo)
|
||||
y0=teff(T(iendo,iexo+nspred,:), kn, istable);
|
||||
y0=gsa.teff(T(iendo,iexo+nspred,:), kn, istable);
|
||||
if ~isempty(y0)
|
||||
if mod(iplo,9)==0
|
||||
ifig = ifig+1;
|
||||
|
@ -82,7 +82,7 @@ for j=1:size(anamendo,1)
|
|||
iplo = iplo+1;
|
||||
js = js+1;
|
||||
subplot(3, 3, iplo)
|
||||
[~, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0, nliv);
|
||||
[~, SAMorris] = gsa.Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0, nliv);
|
||||
SAM = squeeze(SAMorris(nshock+1:end,1));
|
||||
SA(:,js) = SAM./(max(SAM)+eps);
|
||||
[~, iso] = sort(-SA(:,js));
|
||||
|
@ -122,7 +122,7 @@ for j=1:size(anamendo,1)
|
|||
ilagendo=strmatch(namlagendo, M_.endo_names(dr.order_var(M_.nstatic+1:M_.nstatic+nsok)), 'exact');
|
||||
|
||||
if ~isempty(ilagendo)
|
||||
y0=teff(T(iendo,ilagendo,:),kn,istable);
|
||||
y0=gsa.teff(T(iendo,ilagendo,:),kn,istable);
|
||||
if ~isempty(y0)
|
||||
if mod(iplo,9)==0
|
||||
ifig=ifig+1;
|
||||
|
@ -132,7 +132,7 @@ for j=1:size(anamendo,1)
|
|||
iplo=iplo+1;
|
||||
js=js+1;
|
||||
subplot(3,3,iplo),
|
||||
[~, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
|
||||
[~, SAMorris] = gsa.Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv);
|
||||
SAM = squeeze(SAMorris(nshock+1:end,1));
|
||||
SA(:,js)=SAM./(max(SAM)+eps);
|
||||
[~, iso] = sort(-SA(:,js));
|
||||
|
@ -166,7 +166,7 @@ for j=1:size(anamendo,1)
|
|||
end
|
||||
|
||||
hh_fig=dyn_figure(options_.nodisplay,'Name','Reduced form screening');
|
||||
myboxplot(SA',[],'.',[],10)
|
||||
gsa.boxplot(SA',[],'.',[],10)
|
||||
set(gca,'xticklabel',' ','fontsize',10,'xtick',1:np)
|
||||
set(gca,'xlim',[0.5 np+0.5])
|
||||
set(gca,'ylim',[0 1])
|
||||
|
@ -191,7 +191,7 @@ if nargin<6
|
|||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([figpath '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by redform_screen.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by reduced_form_screening.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
|
@ -1,5 +1,5 @@
|
|||
function x0=dynare_sensitivity(M_,oo_,options_,bayestopt_,estim_params_,options_gsa)
|
||||
% x0=dynare_sensitivity(M_,oo_,options_,bayestopt_,estim_params_,options_gsa)
|
||||
function x0=run(M_,oo_,options_,bayestopt_,estim_params_,options_gsa)
|
||||
% x0=run(M_,oo_,options_,bayestopt_,estim_params_,options_gsa)
|
||||
% Frontend to the Sensitivity Analysis Toolbox for DYNARE
|
||||
% Inputs:
|
||||
% - M_ [structure] Matlab's structure describing the model
|
||||
|
@ -306,7 +306,7 @@ if (options_gsa.load_stab || options_gsa.load_rmse || options_gsa.load_redform)
|
|||
end
|
||||
|
||||
if options_gsa.stab && ~options_gsa.ppost
|
||||
x0 = stab_map_(OutputDirectoryName,options_gsa,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
x0 = gsa.stability_mapping(OutputDirectoryName,options_gsa,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
if isempty(x0)
|
||||
skipline()
|
||||
disp('Sensitivity computations stopped: no parameter set provided a unique solution')
|
||||
|
@ -316,11 +316,11 @@ end
|
|||
|
||||
options_.opt_gsa = options_gsa;
|
||||
if ~isempty(options_gsa.moment_calibration) || ~isempty(options_gsa.irf_calibration)
|
||||
map_calibration(OutputDirectoryName, M_, options_, oo_, estim_params_,bayestopt_);
|
||||
gsa.map_calibration(OutputDirectoryName, M_, options_, oo_, estim_params_,bayestopt_);
|
||||
end
|
||||
|
||||
if options_gsa.identification
|
||||
map_ident_(OutputDirectoryName,options_gsa,M_,oo_,options_,estim_params_,bayestopt_);
|
||||
gsa.map_identification(OutputDirectoryName,options_gsa,M_,oo_,options_,estim_params_,bayestopt_);
|
||||
end
|
||||
|
||||
if options_gsa.redform && ~isempty(options_gsa.namendo)
|
||||
|
@ -346,10 +346,10 @@ if options_gsa.redform && ~isempty(options_gsa.namendo)
|
|||
save([OutputDirectoryName filesep M_.fname '_mc.mat'],'lpmat','lpmat0','istable','iunstable','iwrong','iindeterm')
|
||||
options_gsa.load_stab=1;
|
||||
|
||||
x0 = stab_map_(OutputDirectoryName,options_gsa,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
x0 = gsa.stability_mapping(OutputDirectoryName,options_gsa,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
end
|
||||
if options_gsa.morris==1
|
||||
redform_screen(OutputDirectoryName,options_gsa, estim_params_, M_, oo_.dr, options_, bayestopt_);
|
||||
gsa.reduced_form_screening(OutputDirectoryName,options_gsa, estim_params_, M_, oo_.dr, options_, bayestopt_);
|
||||
else
|
||||
% check existence of the SS_ANOVA toolbox
|
||||
if isempty(options_gsa.threshold_redform) && ~(exist('gsa_sdp','file')==6 || exist('gsa_sdp','file')==2)
|
||||
|
@ -360,7 +360,7 @@ if options_gsa.redform && ~isempty(options_gsa.namendo)
|
|||
fprintf('After obtaining the files, you need to unpack them and set a Matlab Path to those files.\n')
|
||||
error('SS-ANOVA-R Toolbox missing!')
|
||||
end
|
||||
redform_map(OutputDirectoryName,options_gsa,M_,estim_params_,options_,bayestopt_,oo_);
|
||||
gsa.reduced_form_mapping(OutputDirectoryName,options_gsa,M_,estim_params_,options_,bayestopt_,oo_);
|
||||
end
|
||||
end
|
||||
% RMSE mapping
|
||||
|
@ -415,7 +415,7 @@ if options_gsa.rmse
|
|||
end
|
||||
end
|
||||
clear a;
|
||||
filt_mc_(OutputDirectoryName,options_gsa,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
gsa.monte_carlo_filtering(OutputDirectoryName,options_gsa,dataset_,dataset_info,M_,oo_,options_,bayestopt_,estim_params_);
|
||||
end
|
||||
options_.opt_gsa = options_gsa;
|
||||
|
|
@ -50,8 +50,8 @@ if ~options_.nograph
|
|||
xx=xparam1;
|
||||
end
|
||||
if options_.TeX
|
||||
scatter_plots(lpmat, xdata, param_names_tex, '.', [fname_, '_', amcf_name], OutputDirectoryName, amcf_title, xx, options_)
|
||||
gsa.scatter_plots(lpmat, xdata, param_names_tex, '.', [fname_, '_', amcf_name], OutputDirectoryName, amcf_title, xx, options_)
|
||||
else
|
||||
scatter_plots(lpmat, xdata, param_names, '.', [fname_, '_', amcf_name], OutputDirectoryName, amcf_title, xx, options_)
|
||||
gsa.scatter_plots(lpmat, xdata, param_names, '.', [fname_, '_', amcf_name], OutputDirectoryName, amcf_title, xx, options_)
|
||||
end
|
||||
end
|
|
@ -96,10 +96,10 @@ for i = 1:p
|
|||
for j = 1:p
|
||||
h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]);
|
||||
if i==j
|
||||
h1=cumplot(X(:,j));
|
||||
h1=gsa.cumplot(X(:,j));
|
||||
set(h1,'color',[0 0 1],'LineWidth',1.5)
|
||||
hold on,
|
||||
h2=cumplot(Y(:,j));
|
||||
h2=gsa.cumplot(Y(:,j));
|
||||
set(h2,'color',[1 0 0],'LineWidth',1.5)
|
||||
if ~isempty(xparam1)
|
||||
hold on, plot(xparam1([j j]),[0 1],'k--')
|
|
@ -86,7 +86,7 @@ for i = 1:p
|
|||
for j = 1:p
|
||||
h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]);
|
||||
if i==j
|
||||
h1=cumplot(X(:,j));
|
||||
h1=gsa.cumplot(X(:,j));
|
||||
set(h,'Tag','cumplot')
|
||||
set(h1,'color',[0 0 1],'LineWidth',1.5)
|
||||
if ~isempty(xparam1)
|
|
@ -1,5 +1,5 @@
|
|||
function s=gsa_skewness(y)
|
||||
% s=gsa_skewness(y)
|
||||
function s=skewness(y)
|
||||
% s=skewness(y)
|
||||
% Compute normalized skewness of y
|
||||
% Inputs:
|
||||
% - y [double] input vector
|
|
@ -1,7 +1,7 @@
|
|||
function [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
|
||||
function [H,prob,d] = smirnov_test(x1 , x2 , alpha, iflag )
|
||||
% [H,prob,d] = smirnov_test(x1 , x2 , alpha, iflag )
|
||||
% Smirnov test for 2 distributions
|
||||
% [H,prob,d] = smirnov(x1 , x2 , alpha, iflag )
|
||||
%
|
||||
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
% marco.ratto@ec.europa.eu
|
||||
|
@ -34,11 +34,16 @@ end
|
|||
% empirical cdfs.
|
||||
xmix= [x1;x2];
|
||||
bin = [-inf ; sort(xmix) ; inf];
|
||||
|
||||
ncount1 = histc (x1 , bin);
|
||||
ncount1 = ncount1(:);
|
||||
ncount2 = histc (x2 , bin);
|
||||
ncount2 = ncount2(:);
|
||||
if isoctave
|
||||
ncount1 = histc(x1 , bin);
|
||||
else
|
||||
ncount1 = histcounts(x1 , bin);
|
||||
end
|
||||
if isoctave
|
||||
ncount2 = histc(x2 , bin);
|
||||
else
|
||||
ncount2 = histcounts(x2 , bin);
|
||||
end
|
||||
|
||||
cum1 = cumsum(ncount1)./sum(ncount1);
|
||||
cum1 = cum1(1:end-1);
|
|
@ -1,5 +1,5 @@
|
|||
function x0 = stab_map_(OutputDirectoryName,opt_gsa,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% x0 = stab_map_(OutputDirectoryName,opt_gsa,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
function x0 = stability_mapping(OutputDirectoryName,opt_gsa,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% x0 = stability_mapping(OutputDirectoryName,opt_gsa,M_,oo_,options_,bayestopt_,estim_params_)
|
||||
% Mapping of stability regions in the prior ranges applying
|
||||
% Monte Carlo filtering techniques.
|
||||
%
|
||||
|
@ -37,7 +37,7 @@ function x0 = stab_map_(OutputDirectoryName,opt_gsa,M_,oo_,options_,bayestopt_,e
|
|||
% 3) Bivariate plots of significant correlation patterns
|
||||
% ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets
|
||||
%
|
||||
% USES qmc_sequence, stab_map_1, stab_map_2
|
||||
% USES qmc_sequence, gsa.stability_mapping_univariate, gsa.stability_mapping_bivariate
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -147,7 +147,7 @@ if fload==0 %run new MC
|
|||
yys=zeros(length(dr_.ys),Nsam);
|
||||
|
||||
if opt_gsa.morris == 1
|
||||
[lpmat] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []);
|
||||
[lpmat] = gsa.Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []);
|
||||
lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2;
|
||||
Nsam=size(lpmat,1);
|
||||
lpmat0 = lpmat(:,1:nshock);
|
||||
|
@ -167,7 +167,7 @@ if fload==0 %run new MC
|
|||
end
|
||||
end
|
||||
end
|
||||
prior_draw_gsa(M_,bayestopt_,options_,estim_params_,1); %initialize
|
||||
gsa.prior_draw(M_,bayestopt_,options_,estim_params_,1); %initialize
|
||||
if pprior
|
||||
for j=1:nshock
|
||||
if opt_gsa.morris~=1
|
||||
|
@ -184,7 +184,7 @@ if fload==0 %run new MC
|
|||
lpmat(:,j)=lpmat(:,j).*(upper_bound-lower_bound)+lower_bound;
|
||||
end
|
||||
else
|
||||
xx=prior_draw_gsa(M_,bayestopt_,options_,estim_params_,0,[lpmat0 lpmat]);
|
||||
xx=gsa.prior_draw(M_,bayestopt_,options_,estim_params_,0,[lpmat0 lpmat]);
|
||||
lpmat0=xx(:,1:nshock);
|
||||
lpmat=xx(:,nshock+1:end);
|
||||
clear xx;
|
||||
|
@ -500,7 +500,7 @@ if ~isempty(iunstable) || ~isempty(iwrong)
|
|||
options_mcf.nobeha_title_latex = 'NO unique Stable Saddle-Path';
|
||||
end
|
||||
options_mcf.title = 'unique solution';
|
||||
mcf_analysis(lpmat, istable, itmp, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, istable, itmp, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
if ~isempty(iindeterm)
|
||||
itmp = isolve(~ismember(isolve,iindeterm));
|
||||
|
@ -513,7 +513,7 @@ if ~isempty(iunstable) || ~isempty(iwrong)
|
|||
options_mcf.nobeha_title_latex = 'indeterminacy';
|
||||
end
|
||||
options_mcf.title = 'indeterminacy';
|
||||
mcf_analysis(lpmat, itmp, iindeterm, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, itmp, iindeterm, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
if ~isempty(ixun)
|
||||
|
@ -527,7 +527,7 @@ if ~isempty(iunstable) || ~isempty(iwrong)
|
|||
options_mcf.nobeha_title_latex = 'explosive solution';
|
||||
end
|
||||
options_mcf.title = 'instability';
|
||||
mcf_analysis(lpmat, itmp, ixun, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, itmp, ixun, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
inorestriction = istable(~ismember(istable,irestriction)); % violation of prior restrictions
|
||||
|
@ -543,7 +543,7 @@ if ~isempty(iunstable) || ~isempty(iwrong)
|
|||
options_mcf.nobeha_title_latex = 'inability to find a solution';
|
||||
end
|
||||
options_mcf.title = 'inability to find a solution';
|
||||
mcf_analysis(lpmat, itmp, iwrong, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(lpmat, itmp, iwrong, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
end
|
||||
|
||||
if ~isempty(irestriction)
|
||||
|
@ -576,7 +576,7 @@ if ~isempty(iunstable) || ~isempty(iwrong)
|
|||
options_mcf.nobeha_title_latex = 'NO prior IRF/moment calibration';
|
||||
end
|
||||
options_mcf.title = 'prior restrictions';
|
||||
mcf_analysis([lpmat0 lpmat], irestriction, inorestriction, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis([lpmat0 lpmat], irestriction, inorestriction, options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
iok = irestriction(1);
|
||||
x0 = [lpmat0(iok,:)'; lpmat(iok,:)'];
|
||||
else
|
|
@ -1,5 +1,5 @@
|
|||
function indcorr = stab_map_2(x,alpha2, pvalue_crit, M_,options_,bayestopt_,estim_params_, case_name_plain, case_name_latex, dirname,xparam1,figtitle,fig_caption_latex)
|
||||
% indcorr = stab_map_2(x,alpha2, pvalue_crit, M_,options_,bayestopt_,estim_params_, fnam, fnam_latex, dirname,xparam1,figtitle,fig_caption_latex)
|
||||
function indcorr = stability_mapping_bivariate(x,alpha2, pvalue_crit, M_,options_,bayestopt_,estim_params_, case_name_plain, case_name_latex, dirname,xparam1,figtitle,fig_caption_latex)
|
||||
% indcorr = stability_mapping_bivariate(x,alpha2, pvalue_crit, M_,options_,bayestopt_,estim_params_, fnam, fnam_latex, dirname,xparam1,figtitle,fig_caption_latex)
|
||||
% Inputs:
|
||||
% - x
|
||||
% - alpha2
|
|
@ -1,5 +1,5 @@
|
|||
function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, fname_, options_, parnames, estim_params_, iplot, ipar, dirname, pcrit, atitle)
|
||||
% [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, fname_, options_, parnames, estim_params_, iplot, ipar, dirname, pcrit, atitle)
|
||||
function [proba, dproba] = stability_mapping_univariate(lpmat, ibehaviour, inonbehaviour, aname, fname_, options_, parnames, estim_params_, iplot, ipar, dirname, pcrit, atitle)
|
||||
% [proba, dproba] = stability_mapping_univariate(lpmat, ibehaviour, inonbehaviour, aname, fname_, options_, parnames, estim_params_, iplot, ipar, dirname, pcrit, atitle)
|
||||
% Inputs:
|
||||
% - lpmat [double] Monte Carlo matrix
|
||||
% - ibehaviour [integer] index of behavioural runs
|
||||
|
@ -18,7 +18,7 @@ function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, f
|
|||
%
|
||||
% Plots: dotted lines for BEHAVIOURAL
|
||||
% solid lines for NON BEHAVIOURAL
|
||||
% USES smirnov
|
||||
% USES gsa.smirnov_test.m
|
||||
%
|
||||
% Written by Marco Ratto
|
||||
% Joint Research Centre, The European Commission,
|
||||
|
@ -71,7 +71,7 @@ end
|
|||
proba=NaN(npar,1);
|
||||
dproba=NaN(npar,1);
|
||||
for j=1:npar
|
||||
[~,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j));
|
||||
[~,P,KSSTAT] = gsa.smirnov_test(lpmat(ibehaviour,j),lpmat(inonbehaviour,j));
|
||||
proba(j)=P;
|
||||
dproba(j)=KSSTAT;
|
||||
end
|
||||
|
@ -88,12 +88,12 @@ if iplot && ~options_.nograph
|
|||
for j=1+12*(i-1):min(nparplot,12*i)
|
||||
subplot(3,4,j-12*(i-1))
|
||||
if ~isempty(ibehaviour)
|
||||
h=cumplot(lpmat(ibehaviour,j));
|
||||
h=gsa.cumplot(lpmat(ibehaviour,j));
|
||||
set(h,'color',[0 0 1], 'linestyle',':','LineWidth',1.5)
|
||||
end
|
||||
hold on
|
||||
if ~isempty(inonbehaviour)
|
||||
h=cumplot(lpmat(inonbehaviour,j));
|
||||
h=gsa.cumplot(lpmat(inonbehaviour,j));
|
||||
set(h,'color',[0 0 0],'LineWidth',1.5)
|
||||
end
|
||||
title([ftit{j},'. p-value ', num2str(proba(ipar(j)),2)],'interpreter','none')
|
||||
|
@ -102,7 +102,7 @@ if iplot && ~options_.nograph
|
|||
dyn_saveas(hh_fig,[dirname,filesep,fname_,'_',aname,'_SA_',int2str(i)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([dirname,filesep,fname_,'_',aname,'_SA_',int2str(i) '.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_1.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by gsa.stability_mapping_univariate.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -117,7 +117,7 @@ if iplot && ~options_.nograph
|
|||
dyn_saveas(hh_fig,[dirname,filesep,fname_,'_',aname,'_SA'],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([dirname,filesep,fname_,'_',aname,'_SA.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by stab_map_1.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by gsa.stability_mapping_univariate.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
|
@ -1,5 +1,5 @@
|
|||
function [y, meany, stdy] = stand_(x)
|
||||
% [y, meany, stdy] = stand_(x)
|
||||
function [y, meany, stdy] = standardize_columns(x)
|
||||
% [y, meany, stdy] = standardize_columns(x)
|
||||
% Standardise a matrix by columns
|
||||
%
|
||||
% [x,my,sy]=stand(y)
|
|
@ -1,5 +1,5 @@
|
|||
function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
% [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
% [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, derivatives_info, info, error_indicator] = analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, init)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function wraps all identification analysis, i.e. it
|
||||
% (1) wraps functions for the theoretical identification analysis based on moments (Iskrev, 2010),
|
||||
|
@ -58,18 +58,18 @@ function [ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide
|
|||
% indicator on problems
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * dynare_identification.m
|
||||
% * identification.run
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * [M_.fname,'.dynamic']
|
||||
% * dseries
|
||||
% * dsge_likelihood.m
|
||||
% * dyn_vech
|
||||
% * ident_bruteforce
|
||||
% * identification_checks
|
||||
% * identification_checks_via_subsets
|
||||
% * identification.bruteforce
|
||||
% * identification.checks
|
||||
% * identification.checks_via_subsets
|
||||
% * isoctave
|
||||
% * get_identification_jacobians (previously getJJ)
|
||||
% * identification.get_jacobians (previously getJJ)
|
||||
% * matlab_ver_less_than
|
||||
% * prior_bounds
|
||||
% * resol
|
||||
|
@ -120,7 +120,7 @@ if ~isempty(estim_params_)
|
|||
M_ = set_all_parameters(params,estim_params_,M_);
|
||||
end
|
||||
|
||||
%get options (see dynare_identification.m for description of options)
|
||||
%get options (see identification.run.m for description of options)
|
||||
nlags = options_ident.ar;
|
||||
advanced = options_ident.advanced;
|
||||
replic = options_ident.replic;
|
||||
|
@ -142,7 +142,7 @@ error_indicator.identification_spectrum=0;
|
|||
|
||||
if info(1) == 0 %no errors in solution
|
||||
% Compute parameter Jacobians for identification analysis
|
||||
[~, ~, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_identification_jacobians(estim_params_, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
[~, ~, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = identification.get_jacobians(estim_params_, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
if isempty(dMINIMAL)
|
||||
% Komunjer and Ng is not computed if (1) minimality conditions are not fullfilled or (2) there are more shocks and measurement errors than observables, so we need to reset options
|
||||
error_indicator.identification_minimal = 1;
|
||||
|
@ -206,7 +206,7 @@ if info(1) == 0 %no errors in solution
|
|||
options_ident_local.no_identification_spectrum = 1; %do not recompute dSPECTRUM
|
||||
options_ident_local.ar = nlags; %store new lag number
|
||||
options_.ar = nlags; %store new lag number
|
||||
[~, ~, ~, ~, ~, ~, MOMENTS, dMOMENTS, ~, ~, ~, ~] = get_identification_jacobians(estim_params_, M_, options_, options_ident_local, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
[~, ~, ~, ~, ~, ~, MOMENTS, dMOMENTS, ~, ~, ~, ~] = identification.get_jacobians(estim_params_, M_, options_, options_ident_local, indpmodel, indpstderr, indpcorr, indvobs, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
|
||||
ind_dMOMENTS = (find(max(abs(dMOMENTS'),[],1) > tol_deriv)); %new index with non-zero rows
|
||||
end
|
||||
|
@ -305,7 +305,7 @@ if info(1) == 0 %no errors in solution
|
|||
options_.analytic_derivation = analytic_derivation; %reset option
|
||||
AHess = -AHess; %take negative of hessian
|
||||
if min(eig(AHess))<-tol_rank
|
||||
error('identification_analysis: Analytic Hessian is not positive semi-definite!')
|
||||
error('identification.analysis: Analytic Hessian is not positive semi-definite!')
|
||||
end
|
||||
ide_hess.AHess = AHess; %store asymptotic Hessian
|
||||
%normalize asymptotic hessian
|
||||
|
@ -313,9 +313,9 @@ if info(1) == 0 %no errors in solution
|
|||
iflag = any((deltaM.*deltaM)==0); %check if all second-order derivatives wrt to a single parameter are nonzero
|
||||
tildaM = AHess./((deltaM)*(deltaM')); %this normalization is for numerical purposes
|
||||
if iflag || rank(AHess)>rank(tildaM)
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(AHess, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(AHess, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
else %use normalized version if possible
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
indok = find(max(ide_hess.indno,[],1)==0);
|
||||
ide_uncert_unnormaliz(indok) = sqrt(diag(inv(AHess(indok,indok))))';
|
||||
|
@ -325,7 +325,7 @@ if info(1) == 0 %no errors in solution
|
|||
diag_chh = sum(si_dREDUCEDFORM(:,ind1)'.*temp1)';
|
||||
ind1 = ind1(ind1>stderrparam_nbr+corrparam_nbr);
|
||||
cdynamic = si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)*((AHess(ind1,ind1))\si_dDYNAMIC(:,ind1-stderrparam_nbr-corrparam_nbr)');
|
||||
flag_score = 1; %this is used for the title in plot_identification.m
|
||||
flag_score = 1; %this is used for the title in identification.plot.m
|
||||
catch
|
||||
%Asymptotic Hessian via simulation
|
||||
if options_.order > 1
|
||||
|
@ -336,7 +336,7 @@ if info(1) == 0 %no errors in solution
|
|||
options_.periods = periods+100;
|
||||
end
|
||||
replic = max([replic, length(ind_dMOMENTS)*3]);
|
||||
cmm = simulated_moment_uncertainty(ind_dMOMENTS, periods, replic,options_,M_,oo_); %covariance matrix of moments
|
||||
cmm = identification.simulated_moment_uncertainty(ind_dMOMENTS, periods, replic,options_,M_,oo_); %covariance matrix of moments
|
||||
sd = sqrt(diag(cmm));
|
||||
cc = cmm./(sd*sd');
|
||||
[VV,DD,WW] = eig(cc);
|
||||
|
@ -350,9 +350,9 @@ if info(1) == 0 %no errors in solution
|
|||
iflag = any((deltaM.*deltaM)==0);
|
||||
tildaM = MIM./((deltaM)*(deltaM'));
|
||||
if iflag || rank(MIM)>rank(tildaM)
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(MIM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(MIM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
else %use normalized version if possible
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification_checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
[ide_hess.cond, ide_hess.rank, ide_hess.ind0, ide_hess.indno, ide_hess.ino, ide_hess.Mco, ide_hess.Pco] = identification.checks(tildaM, 0, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
indok = find(max(ide_hess.indno,[],1)==0);
|
||||
ind1 = find(ide_hess.ind0);
|
||||
|
@ -363,7 +363,7 @@ if info(1) == 0 %no errors in solution
|
|||
if ~isempty(indok)
|
||||
ide_uncert_unnormaliz(indok) = (sqrt(diag(inv(tildaM(indok,indok))))./deltaM(indok))'; %sqrt(diag(inv(MIM(indok,indok))))';
|
||||
end
|
||||
flag_score = 0; %this is used for the title in plot_identification.m
|
||||
flag_score = 0; %this is used for the title in identification.plot.m
|
||||
end % end of computing sample information matrix for identification strength measure
|
||||
|
||||
ide_strength_dMOMENTS(indok) = (1./(ide_uncert_unnormaliz(indok)'./abs(params(indok)'))); %this is s_i in Ratto and Iskrev (2011, p.13)
|
||||
|
@ -375,7 +375,7 @@ if info(1) == 0 %no errors in solution
|
|||
if size(quant,1)==1
|
||||
si_dMOMENTSnorm = abs(quant).*normaliz_prior_std;
|
||||
else
|
||||
si_dMOMENTSnorm = vnorm(quant).*normaliz_prior_std;
|
||||
si_dMOMENTSnorm = identification.vnorm(quant).*normaliz_prior_std;
|
||||
end
|
||||
iy = find(diag_chh);
|
||||
ind_dREDUCEDFORM = ind_dREDUCEDFORM(iy);
|
||||
|
@ -385,7 +385,7 @@ if info(1) == 0 %no errors in solution
|
|||
if size(quant,1)==1
|
||||
si_dREDUCEDFORMnorm = abs(quant).*normaliz_prior_std;
|
||||
else
|
||||
si_dREDUCEDFORMnorm = vnorm(quant).*normaliz_prior_std;
|
||||
si_dREDUCEDFORMnorm = identification.vnorm(quant).*normaliz_prior_std;
|
||||
end
|
||||
else
|
||||
si_dREDUCEDFORMnorm = [];
|
||||
|
@ -399,7 +399,7 @@ if info(1) == 0 %no errors in solution
|
|||
if size(quant,1)==1
|
||||
si_dDYNAMICnorm = abs(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
|
||||
else
|
||||
si_dDYNAMICnorm = vnorm(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
|
||||
si_dDYNAMICnorm = identification.vnorm(quant).*normaliz_prior_std(stderrparam_nbr+corrparam_nbr+1:end);
|
||||
end
|
||||
else
|
||||
si_dDYNAMICnorm=[];
|
||||
|
@ -465,11 +465,11 @@ if info(1) == 0 %no errors in solution
|
|||
ide_moments.MOMENTS = MOMENTS;
|
||||
|
||||
if advanced
|
||||
% here we do not normalize (i.e. we set norm_dMOMENTS=1) as the OLS in ident_bruteforce is very sensitive to norm_dMOMENTS
|
||||
[ide_moments.pars, ide_moments.cosndMOMENTS] = ident_bruteforce(M_.dname,M_.fname,dMOMENTS(ind_dMOMENTS,:), max_dim_cova_group, options_.TeX, options_ident.name_tex, options_ident.tittxt, tol_deriv);
|
||||
% here we do not normalize (i.e. we set norm_dMOMENTS=1) as the OLS in identification.bruteforce is very sensitive to norm_dMOMENTS
|
||||
[ide_moments.pars, ide_moments.cosndMOMENTS] = identification.bruteforce(M_.dname,M_.fname,dMOMENTS(ind_dMOMENTS,:), max_dim_cova_group, options_.TeX, options_ident.name_tex, options_ident.tittxt, tol_deriv);
|
||||
end
|
||||
|
||||
%here we focus on the unnormalized S and V, which is then used in plot_identification.m and for prior_mc > 1
|
||||
%here we focus on the unnormalized S and V, which is then used in identification.plot.m and for prior_mc > 1
|
||||
[~, S, V] = svd(dMOMENTS(ind_dMOMENTS,:),0);
|
||||
if size(S,1) == 1
|
||||
S = S(1); % edge case that S is not a matrix but a row vector
|
||||
|
@ -522,9 +522,9 @@ if info(1) == 0 %no errors in solution
|
|||
|
||||
%% Perform identification checks, i.e. find out which parameters are involved
|
||||
if checks_via_subsets
|
||||
% identification_checks_via_subsets is only for debugging
|
||||
% identification.checks_via_subsets is only for debugging
|
||||
[ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = ...
|
||||
identification_checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident, error_indicator);
|
||||
identification.checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident, error_indicator);
|
||||
if ~error_indicator.identification_minimal
|
||||
ide_minimal.minimal_state_space=1;
|
||||
else
|
||||
|
@ -532,19 +532,19 @@ if info(1) == 0 %no errors in solution
|
|||
end
|
||||
else
|
||||
[ide_dynamic.cond, ide_dynamic.rank, ide_dynamic.ind0, ide_dynamic.indno, ide_dynamic.ino, ide_dynamic.Mco, ide_dynamic.Pco, ide_dynamic.jweak, ide_dynamic.jweak_pair] = ...
|
||||
identification_checks(dDYNAMIC(ind_dDYNAMIC,:)./norm_dDYNAMIC, 1, tol_rank, tol_sv, modparam_nbr);
|
||||
identification.checks(dDYNAMIC(ind_dDYNAMIC,:)./norm_dDYNAMIC, 1, tol_rank, tol_sv, modparam_nbr);
|
||||
if ~options_ident.no_identification_reducedform && ~error_indicator.identification_reducedform
|
||||
[ide_reducedform.cond, ide_reducedform.rank, ide_reducedform.ind0, ide_reducedform.indno, ide_reducedform.ino, ide_reducedform.Mco, ide_reducedform.Pco, ide_reducedform.jweak, ide_reducedform.jweak_pair] = ...
|
||||
identification_checks(dREDUCEDFORM(ind_dREDUCEDFORM,:)./norm_dREDUCEDFORM, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(dREDUCEDFORM(ind_dREDUCEDFORM,:)./norm_dREDUCEDFORM, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
if ~options_ident.no_identification_moments && ~error_indicator.identification_moments
|
||||
[ide_moments.cond, ide_moments.rank, ide_moments.ind0, ide_moments.indno, ide_moments.ino, ide_moments.Mco, ide_moments.Pco, ide_moments.jweak, ide_moments.jweak_pair] = ...
|
||||
identification_checks(dMOMENTS(ind_dMOMENTS,:)./norm_dMOMENTS, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(dMOMENTS(ind_dMOMENTS,:)./norm_dMOMENTS, 1, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
if ~options_ident.no_identification_minimal
|
||||
if ~error_indicator.identification_minimal
|
||||
[ide_minimal.cond, ide_minimal.rank, ide_minimal.ind0, ide_minimal.indno, ide_minimal.ino, ide_minimal.Mco, ide_minimal.Pco, ide_minimal.jweak, ide_minimal.jweak_pair] = ...
|
||||
identification_checks(dMINIMAL(ind_dMINIMAL,:)./norm_dMINIMAL, 2, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(dMINIMAL(ind_dMINIMAL,:)./norm_dMINIMAL, 2, tol_rank, tol_sv, totparam_nbr);
|
||||
ide_minimal.minimal_state_space=1;
|
||||
else
|
||||
ide_minimal.minimal_state_space=0;
|
||||
|
@ -552,7 +552,7 @@ if info(1) == 0 %no errors in solution
|
|||
end
|
||||
if ~options_ident.no_identification_spectrum && ~error_indicator.identification_spectrum
|
||||
[ide_spectrum.cond, ide_spectrum.rank, ide_spectrum.ind0, ide_spectrum.indno, ide_spectrum.ino, ide_spectrum.Mco, ide_spectrum.Pco, ide_spectrum.jweak, ide_spectrum.jweak_pair] = ...
|
||||
identification_checks(tilda_dSPECTRUM, 3, tol_rank, tol_sv, totparam_nbr);
|
||||
identification.checks(tilda_dSPECTRUM, 3, tol_rank, tol_sv, totparam_nbr);
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,7 +18,7 @@ function [pars, cosnJ] = ident_bruteforce(dname,fname,J, max_dim_cova_group, TeX
|
|||
% cosnJ : cosn of each column with the selected group of columns
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% =========================================================================
|
||||
% Copyright © 2009-2023 Dynare Team
|
||||
%
|
||||
|
@ -67,7 +67,7 @@ for ll = 1:max_dim_cova_group
|
|||
cosnJ2=zeros(size(tmp2,1),1);
|
||||
b=[];
|
||||
for jj = 1:size(tmp2,1)
|
||||
[cosnJ2(jj,1), b(:,jj)] = cosn([J(:,ii),J(:,tmp2(jj,:))]);
|
||||
[cosnJ2(jj,1), b(:,jj)] = identification.cosn([J(:,ii),J(:,tmp2(jj,:))]);
|
||||
end
|
||||
cosnJ(ii,ll) = max(cosnJ2(:,1));
|
||||
if cosnJ(ii,ll)>tol_deriv
|
|
@ -1,5 +1,5 @@
|
|||
function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = identification_checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
% function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = identification_checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
% function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = checks(X, test_flag, tol_rank, tol_sv, param_nbr)
|
||||
% -------------------------------------------------------------------------
|
||||
% Checks rank criteria of identification tests and finds out parameter sets
|
||||
% that are not identifiable via the nullspace, pairwise correlation
|
||||
|
@ -24,10 +24,10 @@ function [condX, rankX, ind0, indno, ixno, Mco, Pco, jweak, jweak_pair] = identi
|
|||
% * jweak_pair [(vech) matrix] gives 1 if a couple parameters has Pco=1 (with tolerance tol_rank)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * cosn
|
||||
% * identification.cosn
|
||||
% * dyn_vech
|
||||
% * vnorm
|
||||
% =========================================================================
|
||||
|
@ -75,7 +75,7 @@ end
|
|||
|
||||
% find non-zero columns at machine precision
|
||||
if size(Xpar,1) > 1
|
||||
ind1 = find(vnorm(Xpar) >= eps);
|
||||
ind1 = find(identification.vnorm(Xpar) >= eps);
|
||||
else
|
||||
ind1 = find(abs(Xpar) >= eps); % if only one parameter
|
||||
end
|
||||
|
@ -141,7 +141,7 @@ if test_flag == 0 || test_flag == 3 % G is a Gram matrix and hence should be a c
|
|||
else
|
||||
Mco = NaN(param_nbr,1);
|
||||
for ii = 1:size(Xparnonzero,2)
|
||||
Mco(ind1(ii),:) = cosn([Xparnonzero(:,ii) , Xparnonzero(:,find([1:1:size(Xparnonzero,2)]~=ii)), Xrest]);
|
||||
Mco(ind1(ii),:) = identification.cosn([Xparnonzero(:,ii) , Xparnonzero(:,find([1:1:size(Xparnonzero,2)]~=ii)), Xrest]);
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -170,13 +170,13 @@ end
|
|||
jweak = zeros(1,param_nbr);
|
||||
jweak_pair = zeros(param_nbr,param_nbr);
|
||||
|
||||
if test_flag ~= 0 || test_flag ~= 0
|
||||
if test_flag ~= 0
|
||||
% these tests only apply to Jacobians, not to Gram matrices, i.e. Hessian-type or 'covariance' matrices
|
||||
Pco = NaN(param_nbr,param_nbr);
|
||||
for ii = 1:size(Xparnonzero,2)
|
||||
Pco(ind1(ii),ind1(ii)) = 1;
|
||||
for jj = ii+1:size(Xparnonzero,2)
|
||||
Pco(ind1(ii),ind1(jj)) = cosn([Xparnonzero(:,ii),Xparnonzero(:,jj),Xrest]);
|
||||
Pco(ind1(ii),ind1(jj)) = identification.cosn([Xparnonzero(:,ii),Xparnonzero(:,jj),Xrest]);
|
||||
Pco(ind1(jj),ind1(ii)) = Pco(ind1(ii),ind1(jj));
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function [ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = identification_checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
%[ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = identification_checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
function [ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
%[ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal] = checks_via_subsets(ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, totparam_nbr, modparam_nbr, options_ident,error_indicator)
|
||||
% -------------------------------------------------------------------------
|
||||
% Finds problematic sets of paramters via checking the necessary rank condition
|
||||
% of the Jacobians for all possible combinations of parameters. The rank is
|
||||
|
@ -50,7 +50,7 @@ function [ide_dynamic, ide_reducedform, ide_moments, ide_spectrum, ide_minimal]
|
|||
% * rank: [integer] rank of Jacobian
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% =========================================================================
|
||||
% Copyright © 2019-2021 Dynare Team
|
||||
%
|
||||
|
@ -161,7 +161,7 @@ end
|
|||
|
||||
% initialize for spectrum criteria
|
||||
if ~no_identification_spectrum && ~error_indicator.identification_spectrum
|
||||
dSPECTRUM = ide_spectrum.tilda_dSPECTRUM; %tilda dSPECTRUM is normalized dSPECTRUM matrix in identification_analysis.m
|
||||
dSPECTRUM = ide_spectrum.tilda_dSPECTRUM; %tilda dSPECTRUM is normalized dSPECTRUM matrix in identification.analysis.m
|
||||
%alternative normalization
|
||||
%dSPECTRUM = ide_spectrum.dSPECTRUM;
|
||||
%dSPECTRUM(ide_spectrum.ind_dSPECTRUM,:) = dSPECTRUM(ide_spectrum.ind_dSPECTRUM,:)./ide_spectrum.norm_dSPECTRUM; %normalize
|
|
@ -17,7 +17,7 @@ function [co, b, yhat] = cosn(H)
|
|||
% * y [n by 1] predicted endogenous values given ols estimation
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_checks.m
|
||||
% * identification.checks.m
|
||||
% * ident_bruteforce.m
|
||||
% =========================================================================
|
||||
% Copyright © 2008-2019 Dynare Team
|
|
@ -1,5 +1,5 @@
|
|||
function disp_identification(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
% disp_identification(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
function display(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
% display(pdraws, ide_reducedform, ide_moments, ide_spectrum, ide_minimal, name, options_ident)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function displays all identification analysis to the command line
|
||||
% =========================================================================
|
||||
|
@ -26,7 +26,7 @@ function disp_identification(pdraws, ide_reducedform, ide_moments, ide_spectrum,
|
|||
% * all output is printed on the command line
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * dynare_identification.m
|
||||
% * identification.run
|
||||
% =========================================================================
|
||||
% Copyright © 2010-2021 Dynare Team
|
||||
%
|
||||
|
@ -207,7 +207,7 @@ for jide = 1:4
|
|||
end
|
||||
end
|
||||
|
||||
%% display problematic parameters computed by identification_checks_via_subsets
|
||||
%% display problematic parameters computed by identification.checks_via_subsets
|
||||
elseif checks_via_subsets
|
||||
if ide.rank < size(Jacob,2)
|
||||
no_warning_message_display = 0;
|
|
@ -30,7 +30,7 @@ function fjac = fjaco(f,x,varargin)
|
|||
ff=feval(f,x,varargin{:});
|
||||
|
||||
tol = eps.^(1/3); %some default value
|
||||
if strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification_numerical_objective')
|
||||
if strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective')
|
||||
tol= varargin{4}.dynatol.x;
|
||||
end
|
||||
h = tol.*max(abs(x),1);
|
||||
|
@ -40,12 +40,12 @@ fjac = NaN(length(ff),length(x));
|
|||
for j=1:length(x)
|
||||
xx = x;
|
||||
xx(j) = xh1(j); f1=feval(f,xx,varargin{:});
|
||||
if isempty(f1) && (strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification_numerical_objective') )
|
||||
if isempty(f1) && (strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') )
|
||||
[~,info]=feval(f,xx,varargin{:});
|
||||
disp_info_error_identification_perturbation(info,j);
|
||||
end
|
||||
xx(j) = xh0(j); f0=feval(f,xx,varargin{:});
|
||||
if isempty(f0) && (strcmp(func2str(f),'get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification_numerical_objective') )
|
||||
if isempty(f0) && (strcmp(func2str(f),'identification.get_perturbation_params_derivs_numerical_objective') || strcmp(func2str(f),'identification.numerical_objective') )
|
||||
[~,info]=feval(f,xx,varargin{:});
|
||||
disp_info_error_identification_perturbation(info,j)
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_identification_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_identification_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dMOMENTS, dSPECTRUM, dSPECTRUM_NO_MEAN, dMINIMAL, derivatives_info] = get_jacobians(estim_params, M_, options_, options_ident, indpmodel, indpstderr, indpcorr, indvobs, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% previously getJJ.m in Dynare 4.5
|
||||
% Sets up the Jacobians needed for identification analysis
|
||||
% =========================================================================
|
||||
|
@ -84,7 +84,7 @@ function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dM
|
|||
%
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * identification_analysis.m
|
||||
% * identification.analysis.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * commutation
|
||||
|
@ -94,7 +94,7 @@ function [MEAN, dMEAN, REDUCEDFORM, dREDUCEDFORM, DYNAMIC, dDYNAMIC, MOMENTS, dM
|
|||
% * fjaco
|
||||
% * get_perturbation_params_derivs (previously getH)
|
||||
% * get_all_parameters
|
||||
% * identification_numerical_objective (previously thet2tau)
|
||||
% * identification.numerical_objective (previously thet2tau)
|
||||
% * pruned_state_space_system
|
||||
% * vec
|
||||
% =========================================================================
|
||||
|
@ -153,7 +153,7 @@ obs_nbr = length(indvobs);
|
|||
d2flag = 0; % do not compute second parameter derivatives
|
||||
|
||||
% Get Jacobians (wrt selected params) of steady state, dynamic model derivatives and perturbation solution matrices for all endogenous variables
|
||||
dr.derivs = get_perturbation_params_derivs(M_, options_, estim_params, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag);
|
||||
dr.derivs = identification.get_perturbation_params_derivs(M_, options_, estim_params, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, indpmodel, indpstderr, indpcorr, d2flag);
|
||||
|
||||
[I,~] = find(lead_lag_incidence'); %I is used to select nonzero columns of the Jacobian of endogenous variables in dynamic model files
|
||||
yy0 = dr.ys(I); %steady state of dynamic (endogenous and auxiliary variables) in lead_lag_incidence order
|
||||
|
@ -230,7 +230,7 @@ elseif order == 3
|
|||
end
|
||||
|
||||
% Get (pruned) state space representation:
|
||||
pruned = pruned_state_space_system(M_, options_, dr, indvobs, nlags, useautocorr, 1);
|
||||
pruned = pruned_SS.pruned_state_space_system(M_, options_, dr, indvobs, nlags, useautocorr, 1);
|
||||
MEAN = pruned.E_y;
|
||||
dMEAN = pruned.dE_y;
|
||||
%storage for Jacobians used in dsge_likelihood.m for analytical Gradient and Hession of likelihood (only at order=1)
|
||||
|
@ -258,7 +258,7 @@ if ~no_identification_moments
|
|||
|
||||
if kronflag == -1
|
||||
%numerical derivative of autocovariogram
|
||||
dMOMENTS = fjaco(str2func('identification_numerical_objective'), xparam1, 1, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=1]
|
||||
dMOMENTS = identification.fjaco(str2func('identification.numerical_objective'), xparam1, 1, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=1]
|
||||
dMOMENTS = [dMEAN; dMOMENTS]; %add Jacobian of steady state of VAROBS variables
|
||||
else
|
||||
dMOMENTS = zeros(obs_nbr + obs_nbr*(obs_nbr+1)/2 + nlags*obs_nbr^2 , totparam_nbr);
|
||||
|
@ -315,7 +315,7 @@ if ~no_identification_spectrum
|
|||
IA = eye(size(pruned.A,1));
|
||||
if kronflag == -1
|
||||
%numerical derivative of spectral density
|
||||
dOmega_tmp = fjaco(str2func('identification_numerical_objective'), xparam1, 2, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=2]
|
||||
dOmega_tmp = identification.fjaco(str2func('identification.numerical_objective'), xparam1, 2, estim_params, M_, options_, indpmodel, indpstderr, indvobs, useautocorr, nlags, grid_nbr, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); %[outputflag=2]
|
||||
kk = 0;
|
||||
for ig = 1:length(freqs)
|
||||
kk = kk+1;
|
||||
|
@ -333,7 +333,7 @@ if ~no_identification_spectrum
|
|||
dC = reshape(pruned.dC,size(pruned.dC,1)*size(pruned.dC,2),size(pruned.dC,3));
|
||||
dD = reshape(pruned.dD,size(pruned.dD,1)*size(pruned.dD,2),size(pruned.dD,3));
|
||||
dVarinov = reshape(pruned.dVarinov,size(pruned.dVarinov,1)*size(pruned.dVarinov,2),size(pruned.dVarinov,3));
|
||||
K_obs_exo = commutation(obs_nbr,size(pruned.Varinov,1));
|
||||
K_obs_exo = pruned_SS.commutation(obs_nbr,size(pruned.Varinov,1));
|
||||
for ig=1:length(freqs)
|
||||
z = tneg(ig);
|
||||
zIminusA = (z*IA - pruned.A);
|
||||
|
@ -400,7 +400,7 @@ if ~no_identification_minimal
|
|||
SYS.dC = dr.derivs.dghx(pruned.indy,:,:);
|
||||
SYS.D = dr.ghu(pruned.indy,:);
|
||||
SYS.dD = dr.derivs.dghu(pruned.indy,:,:);
|
||||
[CheckCO,minnx,SYS] = get_minimal_state_representation(SYS,1);
|
||||
[CheckCO,minnx,SYS] = identification.get_minimal_state_representation(SYS,1);
|
||||
|
||||
if CheckCO == 0
|
||||
warning_KomunjerNg = 'WARNING: Komunjer and Ng (2011) failed:\n';
|
||||
|
@ -423,7 +423,7 @@ if ~no_identification_minimal
|
|||
dvechSig = dvechSig(indvechSig,:);
|
||||
Inx = eye(minnx);
|
||||
Inu = eye(exo_nbr);
|
||||
[~,Enu] = duplication(exo_nbr);
|
||||
[~,Enu] = pruned_SS.duplication(exo_nbr);
|
||||
KomunjerNg_DL = [dminA; dminB; dminC; dminD; dvechSig];
|
||||
KomunjerNg_DT = [kron(transpose(minA),Inx) - kron(Inx,minA);
|
||||
kron(transpose(minB),Inx);
|
|
@ -53,7 +53,7 @@ function [CheckCO,minns,minSYS] = get_minimal_state_representation(SYS, derivs_f
|
|||
% Jacobian (wrt to all parameters) of measurement matrix minD
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * get_identification_jacobians.m (previously getJJ.m)
|
||||
% * identification.get_jacobians.m (previously getJJ.m)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * check_minimality (embedded)
|
|
@ -88,7 +88,7 @@ function DERIVS = get_perturbation_params_derivs(M_, options_, estim_params_, dr
|
|||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * dsge_likelihood.m
|
||||
% * get_identification_jacobians.m
|
||||
% * identification.get_jacobians.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * [fname,'.dynamic']
|
||||
|
@ -191,7 +191,7 @@ if order > 1 && analytic_derivation_mode == 1
|
|||
analytic_derivation_mode = 0; fprintf('As order > 1, reset ''analytic_derivation_mode'' to 0\n');
|
||||
end
|
||||
|
||||
numerical_objective_fname = str2func('get_perturbation_params_derivs_numerical_objective');
|
||||
numerical_objective_fname = str2func('identification.get_perturbation_params_derivs_numerical_objective');
|
||||
idx_states = nstatic+(1:nspred); %index for state variables, in DR order
|
||||
modparam_nbr = length(indpmodel); %number of selected model parameters
|
||||
stderrparam_nbr = length(indpstderr); %number of selected stderr parameters
|
||||
|
@ -295,7 +295,7 @@ if analytic_derivation_mode == -1
|
|||
% - perturbation solution matrices: dghx, dghu, dghxx, dghxu, dghuu, dghs2, dghxxx, dghxxu, dghxuu, dghuuu, dghxss, dghuss
|
||||
|
||||
%Parameter Jacobian of covariance matrix and solution matrices (wrt selected stderr, corr and model paramters)
|
||||
dSig_gh = fjaco(numerical_objective_fname, xparam1, 'perturbation_solution', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
dSig_gh = identification.fjaco(numerical_objective_fname, xparam1, 'perturbation_solution', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
ind_Sigma_e = (1:exo_nbr^2);
|
||||
ind_ghx = ind_Sigma_e(end) + (1:endo_nbr*nspred);
|
||||
ind_ghu = ind_ghx(end) + (1:endo_nbr*exo_nbr);
|
||||
|
@ -348,7 +348,7 @@ if analytic_derivation_mode == -1
|
|||
end
|
||||
|
||||
%Parameter Jacobian of dynamic model derivatives (wrt selected model parameters only)
|
||||
dYss_g = fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
dYss_g = identification.fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
ind_Yss = 1:endo_nbr;
|
||||
if options_.discretionary_policy || options_.ramsey_policy
|
||||
ind_g1 = ind_Yss(end) + (1:M_.eq_nbr*yy0ex0_nbr);
|
||||
|
@ -374,7 +374,7 @@ if analytic_derivation_mode == -1
|
|||
% Hessian (wrt paramters) of steady state and first-order solution matrices ghx and Om
|
||||
% note that hessian_sparse.m (contrary to hessian.m) does not take symmetry into account, but focuses already on unique values
|
||||
options_.order = 1; %make sure only first order
|
||||
d2Yss_KalmanA_Om = hessian_sparse(numerical_objective_fname, xparam1, gstep, 'Kalman_Transition', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
d2Yss_KalmanA_Om = identification.hessian_sparse(numerical_objective_fname, xparam1, gstep, 'Kalman_Transition', estim_params_, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
options_.order = order; %make sure to set back
|
||||
ind_KalmanA = ind_Yss(end) + (1:endo_nbr^2);
|
||||
DERIVS.d2KalmanA = d2Yss_KalmanA_Om(ind_KalmanA, indp2tottot2); %only unique elements
|
||||
|
@ -394,7 +394,7 @@ if analytic_derivation_mode == -2
|
|||
% The parameter derivatives of perturbation solution matrices are computed analytically below (analytic_derivation_mode=0)
|
||||
if order == 3
|
||||
[~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1);
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr);
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr);
|
||||
elseif order == 2
|
||||
[~, g1, g2] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1);
|
||||
elseif order == 1
|
||||
|
@ -405,7 +405,7 @@ if analytic_derivation_mode == -2
|
|||
% computation of d2Yss and d2g1
|
||||
% note that hessian_sparse does not take symmetry into account, i.e. compare hessian_sparse.m to hessian.m, but focuses already on unique values, which are duplicated below
|
||||
options_.order = 1; %d2flag requires only first order
|
||||
d2Yss_g1 = hessian_sparse(numerical_objective_fname, modparam1, gstep, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); % d2flag requires only first-order
|
||||
d2Yss_g1 = identification.hessian_sparse(numerical_objective_fname, modparam1, gstep, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state); % d2flag requires only first-order
|
||||
options_.order = order; %make sure to set back the order
|
||||
d2Yss = reshape(full(d2Yss_g1(1:endo_nbr,:)), [endo_nbr modparam_nbr modparam_nbr]); %put into tensor notation
|
||||
for j=1:endo_nbr
|
||||
|
@ -431,7 +431,7 @@ if analytic_derivation_mode == -2
|
|||
end
|
||||
|
||||
%Parameter Jacobian of dynamic model derivatives (wrt selected model parameters only)
|
||||
dYss_g = fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
dYss_g = identification.fjaco(numerical_objective_fname, modparam1, 'dynamic_model', estim_params_model, M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state);
|
||||
ind_Yss = 1:endo_nbr;
|
||||
ind_g1 = ind_Yss(end) + (1:endo_nbr*yy0ex0_nbr);
|
||||
dYss = dYss_g(ind_Yss,:); %in tensor notation, wrt selected model parameters only
|
||||
|
@ -447,20 +447,22 @@ if analytic_derivation_mode == -2
|
|||
clear dYss_g
|
||||
|
||||
elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1)
|
||||
%% Analytical computation of Jacobian and Hessian (wrt selected model parameters) of steady state, i.e. dYss and d2Yss
|
||||
[~, g1_static] = feval([fname,'.static'], ys, exo_steady_state', params); %g1_static is [endo_nbr by endo_nbr] first-derivative (wrt all endogenous variables) of static model equations f, i.e. df/dys, in declaration order
|
||||
try
|
||||
rp_static = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params); %rp_static is [endo_nbr by param_nbr] first-derivative (wrt all model parameters) of static model equations f, i.e. df/dparams, in declaration order
|
||||
catch
|
||||
if ~exist(['+' fname filesep 'static_params_derivs.m'],'file')
|
||||
error('For analytical parameter derivatives ''static_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
if ~exist(['+' fname filesep 'dynamic_params_derivs.m'],'file')
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
%% Analytical computation of Jacobian and Hessian (wrt selected model parameters) of steady state, i.e. dYss and d2Yss
|
||||
[~, g1_static] = feval([fname,'.static'], ys, exo_steady_state', params); %g1_static is [endo_nbr by endo_nbr] first-derivative (wrt all endogenous variables) of static model equations f, i.e. df/dys, in declaration order
|
||||
rp_static = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params); %rp_static is [endo_nbr by param_nbr] first-derivative (wrt all model parameters) of static model equations f, i.e. df/dparams, in declaration order
|
||||
dys = -g1_static\rp_static; %use implicit function theorem (equation 5 of Ratto and Iskrev (2012) to compute [endo_nbr by param_nbr] first-derivative (wrt all model parameters) of steady state for all endogenous variables analytically, note that dys is in declaration order
|
||||
d2ys = zeros(endo_nbr, param_nbr, param_nbr); %initialize in tensor notation, note that d2ys is only needed for d2flag, i.e. for g1pp
|
||||
if d2flag
|
||||
[~, ~, g2_static] = feval([fname,'.static'], ys, exo_steady_state', params); %g2_static is [endo_nbr by endo_nbr^2] second derivative (wrt all endogenous variables) of static model equations f, i.e. d(df/dys)/dys, in declaration order
|
||||
if order < 3
|
||||
[~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); %note that g3 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
else
|
||||
T = NaN(sum(dynamic_tmp_nbr(1:5)));
|
||||
T = feval([fname, '.dynamic_g4_tt'], T, ys(I), exo_steady_state', params, ys, 1);
|
||||
|
@ -468,20 +470,16 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1)
|
|||
g2 = feval([fname, '.dynamic_g2'], T, ys(I), exo_steady_state', params, ys, 1, false); %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = feval([fname, '.dynamic_g3'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g3 does not contain symmetric elements
|
||||
g4 = feval([fname, '.dynamic_g4'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g4 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = identification.unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
end
|
||||
%g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
try
|
||||
[~, g1p_static, rpp_static] = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params);
|
||||
%g1p_static is [endo_nbr by endo_nbr by param_nbr] first derivative (wrt all model parameters) of first-derivative (wrt all endogenous variables) of static model equations f, i.e. (df/dys)/dparams, in declaration order
|
||||
%rpp_static is [#second_order_residual_terms by 4] and contains nonzero values and corresponding indices of second derivatives (wrt all model parameters) of static model equations f, i.e. d(df/dparams)/dparams, in declaration order, where
|
||||
% column 1 contains equation number; column 2 contains first parameter; column 3 contains second parameter; column 4 contains value of derivative
|
||||
catch
|
||||
error('For analytical parameter derivatives ''static_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p_static, rpp_static] = feval([fname,'.static_params_derivs'], ys, exo_steady_state', params);
|
||||
%g1p_static is [endo_nbr by endo_nbr by param_nbr] first derivative (wrt all model parameters) of first-derivative (wrt all endogenous variables) of static model equations f, i.e. (df/dys)/dparams, in declaration order
|
||||
%rpp_static is [#second_order_residual_terms by 4] and contains nonzero values and corresponding indices of second derivatives (wrt all model parameters) of static model equations f, i.e. d(df/dparams)/dparams, in declaration order, where
|
||||
% column 1 contains equation number; column 2 contains first parameter; column 3 contains second parameter; column 4 contains value of derivative
|
||||
rpp_static = get_all_resid_2nd_derivs(rpp_static, endo_nbr, param_nbr); %make full matrix out of nonzero values and corresponding indices
|
||||
%rpp_static is [endo_nbr by param_nbr by param_nbr] second derivatives (wrt all model parameters) of static model equations, i.e. d(df/dparams)/dparams, in declaration order
|
||||
if isempty(find(g2_static))
|
||||
|
@ -525,58 +523,42 @@ elseif (analytic_derivation_mode == 0 || analytic_derivation_mode == 1)
|
|||
end
|
||||
|
||||
if d2flag
|
||||
try
|
||||
if order < 3
|
||||
[~, g1p, ~, g1pp, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
else
|
||||
[~, g1p, ~, g1pp, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
end
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
if order < 3
|
||||
[~, g1p, ~, g1pp, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
else
|
||||
[~, g1p, ~, g1pp, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
end
|
||||
%g1pp are nonzero values and corresponding indices of second-derivatives (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dparam)/dparam, rows are in declaration order, first column in declaration order
|
||||
d2Yss = d2ys(order_var,indpmodel,indpmodel); %[endo_nbr by mod_param_nbr by mod_param_nbr], put into DR order and focus only on selected model parameters
|
||||
else
|
||||
if order == 1
|
||||
try
|
||||
[~, g1p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
[~, g1, g2 ] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1);
|
||||
%g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g2 is [endo_nbr by yy0ex0_nbr^2] second derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
elseif order == 2
|
||||
try
|
||||
[~, g1p, ~, ~, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p, ~, ~, g2p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
[~, g1, g2, g3] = feval([fname,'.dynamic'], ys(I), exo_steady_state', params, ys, 1); %note that g3 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3
|
||||
%g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
%g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
elseif order == 3
|
||||
try
|
||||
[~, g1p, ~, ~, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
%g3p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of third-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first, second and third column in declaration order
|
||||
catch
|
||||
error('For analytical parameter derivatives ''dynamic_params_derivs.m'' file is needed, this can be created by putting identification(order=%d) into your mod file.',order)
|
||||
end
|
||||
[~, g1p, ~, ~, g2p, g3p] = feval([fname,'.dynamic_params_derivs'], ys(I), exo_steady_state', params, ys, 1, dys, d2ys);
|
||||
%g1p is [endo_nbr by yy0ex0_nbr by param_nbr] first-derivative (wrt all model parameters) of first-derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dparam, rows are in declaration order, column in lead_lag_incidence order
|
||||
%g2p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of second-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(df/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first and second column in declaration order
|
||||
%g3p are nonzero values and corresponding indices of first-derivative (wrt all model parameters) of third-derivatives (wrt all dynamic variables) of dynamic model equations, i.e. d(d(d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dparam, rows are in declaration order, first, second and third column in declaration order
|
||||
T = NaN(sum(dynamic_tmp_nbr(1:5)));
|
||||
T = feval([fname, '.dynamic_g4_tt'], T, ys(I), exo_steady_state', params, ys, 1);
|
||||
g1 = feval([fname, '.dynamic_g1'], T, ys(I), exo_steady_state', params, ys, 1, false); %g1 is [endo_nbr by yy0ex0_nbr first derivative (wrt all dynamic variables) of dynamic model equations, i.e. df/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g2 = feval([fname, '.dynamic_g2'], T, ys(I), exo_steady_state', params, ys, 1, false); %g2 is [endo_nbr by yy0ex0_nbr^2] second derivative (wrt all dynamic variables) of dynamic model equations, i.e. d(df/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = feval([fname, '.dynamic_g3'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g3 does not contain symmetric elements
|
||||
g4 = feval([fname, '.dynamic_g4'], T, ys(I), exo_steady_state', params, ys, 1, false); %note that g4 does not contain symmetric elements
|
||||
g3 = unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g3 = identification.unfold_g3(g3, yy0ex0_nbr); %add symmetric elements to g3, %g3 is [endo_nbr by yy0ex0_nbr^3] third-derivative (wrt all dynamic variables) of dynamic model equations, i.e. (d(df/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
g4 = identification.unfold_g4(g4, yy0ex0_nbr); %add symmetric elements to g4, %g4 is [endo_nbr by yy0ex0_nbr^4] fourth-derivative (wrt all dynamic variables) of dynamic model equations, i.e. ((d(df/dyy0ex0)/dyy0ex0)/dyy0ex0)/dyy0ex0, rows are in declaration order, columns in lead_lag_incidence order
|
||||
end
|
||||
end
|
||||
% Parameter Jacobian of steady state in different orderings, note dys is in declaration order
|
||||
|
@ -801,7 +783,7 @@ if analytic_derivation_mode == 1
|
|||
dghu = [zeros(endo_nbr*exo_nbr, stderrparam_nbr+corrparam_nbr) dghu];
|
||||
|
||||
% Compute dOm = dvec(ghu*Sigma_e*ghu') from expressions 34 in Iskrev (2010) Appendix A
|
||||
dOm = kron(I_endo,ghu*Sigma_e)*(commutation(endo_nbr, exo_nbr)*dghu)...
|
||||
dOm = kron(I_endo,ghu*Sigma_e)*(pruned_SS.commutation(endo_nbr, exo_nbr)*dghu)...
|
||||
+ kron(ghu,ghu)*reshape(dSigma_e, exo_nbr^2, totparam_nbr) + kron(ghu*Sigma_e,I_endo)*dghu;
|
||||
|
||||
% Put into tensor notation
|
|
@ -95,7 +95,7 @@ if strcmp(outputflag,'dynamic_model')
|
|||
out = [Yss; g1(:); g2(:)];
|
||||
elseif options_.order == 3
|
||||
[~, g1, g2, g3] = feval([M_.fname,'.dynamic'], ys(I), exo_steady_state', M_.params, ys, 1);
|
||||
g3 = unfold_g3(g3, length(ys(I))+M_.exo_nbr);
|
||||
g3 = identification.unfold_g3(g3, length(ys(I))+M_.exo_nbr);
|
||||
out = [Yss; g1(:); g2(:); g3(:)];
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
function out = identification_numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% out = identification_numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
function out = numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% out = numerical_objective(params, outputflag, estim_params_, M_, options_, indpmodel, indpstderr, indvar, useautocorr, nlags, grid_nbr, dr, steady_state, exo_steady_state, exo_det_steady_state)
|
||||
% -------------------------------------------------------------------------
|
||||
% Objective function to compute numerically the Jacobians used for identification analysis
|
||||
% Previously this function was called thet2tau.m
|
||||
|
@ -22,7 +22,7 @@ function out = identification_numerical_objective(params, outputflag, estim_para
|
|||
% OUTPUTS
|
||||
% out: dependent on outputflag
|
||||
% * 0: out = [Yss; vec(A); vec(B); dyn_vech(Sig_e)]; of indvar variables only, in DR order. This is needed to compute dTAU and Komunjer and Ng's D.
|
||||
% Note that Jacobian of Om is computed in get_identification_Jacobians.m (previously getJJ.m) or get_first_order_solution_params_deriv.m (previously getH.m) from Jacobian of B and Sigma_e, because this is more efficient due to some testing with analytical derivatives from An and Schorfheide model
|
||||
% Note that Jacobian of Om is computed in identification.get_jacobians.m (previously getJJ.m) or get_first_order_solution_params_deriv.m (previously getH.m) from Jacobian of B and Sigma_e, because this is more efficient due to some testing with analytical derivatives from An and Schorfheide model
|
||||
% * 1: out = [vech(cov(Y_t,Y_t)); vec(cov(Y_t,Y_{t-1}); ...; vec(cov(Y_t,Y_{t-nlags})] of indvar variables, in DR order. This is needed to compute Iskrev's J.
|
||||
% * 2: out = vec(spectral density) with dimension [var_nbr^2*grid_nbr,1] Spectral density of indvar variables evaluated at (grid_nbr/2+1) discretized points in the interval [0;pi]. This is needed for Qu and Tkachenko's G.
|
||||
% * -1: out = g1(:); of all variables, in DR order. This is needed to compute dLRE.
|
||||
|
@ -32,7 +32,7 @@ function out = identification_numerical_objective(params, outputflag, estim_para
|
|||
% Jacobian of the dynamic model equations, and Y_t selected variables
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * get_identification_jacobians.m (previously getJJ.m)
|
||||
% * identification.get_jacobians.m (previously getJJ.m)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * [M_.fname,'.dynamic']
|
||||
|
@ -80,7 +80,7 @@ end
|
|||
%% compute Kalman transition matrices and steady state with updated parameters
|
||||
[dr,info,M_.params] = compute_decision_rules(M_,options_,dr, steady_state, exo_steady_state, exo_det_steady_state);
|
||||
options_ = rmfield(options_,'options_ident');
|
||||
pruned = pruned_state_space_system(M_, options_, dr, indvar, nlags, useautocorr, 0);
|
||||
pruned = pruned_SS.pruned_state_space_system(M_, options_, dr, indvar, nlags, useautocorr, 0);
|
||||
|
||||
%% out = [vech(cov(Y_t,Y_t)); vec(cov(Y_t,Y_{t-1}); ...; vec(cov(Y_t,Y_{t-nlags})] of indvar variables, in DR order. This is Iskrev (2010)'s J matrix.
|
||||
if outputflag == 1
|
|
@ -1,5 +1,5 @@
|
|||
function plot_identification(M_, params, idemoments, idehess, idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, fname, options_, estim_params_, bayestopt_, tit_TeX, name_tex)
|
||||
% plot_identification(M_, params,idemoments,idehess,idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, fname, options_, estim_params_, bayestopt_, tit_TeX, name_tex)
|
||||
function plot(M_, params, idemoments, idehess, idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, fname, options_, estim_params_, bayestopt_, tit_TeX, name_tex)
|
||||
% plot(M_, params,idemoments,idehess,idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, fname, options_, estim_params_, bayestopt_, tit_TeX, name_tex)
|
||||
%
|
||||
% INPUTS
|
||||
% o M_ [structure] model
|
||||
|
@ -156,7 +156,7 @@ if SampleSize == 1
|
|||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([IdentifDirectoryName '/' fname '_ident_strength_' tittxt1,'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -203,7 +203,7 @@ if SampleSize == 1
|
|||
dyn_saveas(hh_fig,[IdentifDirectoryName '/' fname '_sensitivity_' tittxt1 ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([IdentifDirectoryName '/' fname '_sensitivity_' tittxt1,'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -262,7 +262,7 @@ if SampleSize == 1
|
|||
dyn_saveas(hh_fig,[ IdentifDirectoryName '/' fname '_ident_collinearity_' tittxt1 '_' int2str(j) ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_ident_collinearity_' tittxt1 '_' int2str(j),'.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -329,7 +329,7 @@ if SampleSize == 1
|
|||
dyn_saveas(f1,[ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_1' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_1','.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -344,7 +344,7 @@ if SampleSize == 1
|
|||
dyn_saveas(f2,[ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_2' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_ident_pattern_' tittxt1 '_2.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -392,7 +392,7 @@ else
|
|||
dyn_saveas(hh_fig,[ IdentifDirectoryName '/' fname '_MC_sensitivity' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_MC_sensitivity.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -450,17 +450,17 @@ else
|
|||
options_mcf.title = 'MC Highest Condition Number LRE Model';
|
||||
ncut=floor(SampleSize/10*9);
|
||||
[~,is]=sort(idelre.cond);
|
||||
mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
options_mcf.amcf_name = 'MC_HighestCondNumberModel';
|
||||
options_mcf.amcf_title = 'MC Highest Condition Number Model Solution';
|
||||
options_mcf.title = 'MC Highest Condition Number Model Solution';
|
||||
[~,is]=sort(idemodel.cond);
|
||||
mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
options_mcf.amcf_name = 'MC_HighestCondNumberMoments';
|
||||
options_mcf.amcf_title = 'MC Highest Condition Number Model Moments';
|
||||
options_mcf.title = 'MC Highest Condition Number Model Moments';
|
||||
[~,is]=sort(idemoments.cond);
|
||||
mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
gsa.monte_carlo_filtering_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, M_, options_, bayestopt_, estim_params_);
|
||||
|
||||
if nparam<5
|
||||
f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - MC Identification patterns (moments): HIGHEST SV']);
|
||||
|
@ -514,7 +514,7 @@ else
|
|||
dyn_saveas(f1,[IdentifDirectoryName '/' fname '_MC_ident_pattern_1' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([IdentifDirectoryName '/' fname '_MC_ident_pattern_1.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
|
@ -529,7 +529,7 @@ else
|
|||
dyn_saveas(f2,[ IdentifDirectoryName '/' fname '_MC_ident_pattern_2' ],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([ IdentifDirectoryName '/' fname '_MC_ident_pattern_2.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by identification.plot.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
|
@ -1,5 +1,5 @@
|
|||
function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = dynare_identification(M_,oo_,options_,bayestopt_,estim_params_,options_ident, pdraws0)
|
||||
% [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = dynare_identification(options_ident, pdraws0)
|
||||
function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = run(M_,oo_,options_,bayestopt_,estim_params_,options_ident, pdraws0)
|
||||
% [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, STO_si_dREDUCEDFORM, STO_si_dMOMENTS, STO_dSPECTRUM, STO_dMINIMAL] = run(options_ident, pdraws0)
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called, when the user specifies identification(...); in the mod file. It prepares all identification analysis:
|
||||
% (1) set options, local and persistent variables for a new identification
|
||||
|
@ -32,19 +32,19 @@ function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, ST
|
|||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * driver.m
|
||||
% * map_ident_.m
|
||||
% * gsa.map_identification.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * checkpath
|
||||
% * disp_identification
|
||||
% * identification.display
|
||||
% * dyn_waitbar
|
||||
% * dyn_waitbar_close
|
||||
% * get_all_parameters
|
||||
% * get_posterior_parameters
|
||||
% * get_the_name
|
||||
% * identification_analysis
|
||||
% * identification.analysis
|
||||
% * isoctave
|
||||
% * plot_identification
|
||||
% * identification.plot
|
||||
% * dprior.draw
|
||||
% * set_default_option
|
||||
% * set_prior
|
||||
|
@ -95,7 +95,7 @@ end
|
|||
options_ident = set_default_option(options_ident,'gsa_sample_file',0);
|
||||
% 0: do not use sample file
|
||||
% 1: triggers gsa prior sample
|
||||
% 2: triggers gsa Monte-Carlo sample (i.e. loads a sample corresponding to pprior=0 and ppost=0 in dynare_sensitivity options)
|
||||
% 2: triggers gsa Monte-Carlo sample (i.e. loads a sample corresponding to pprior=0 and ppost=0 in sensitivity.run options)
|
||||
% FILENAME: use sample file in provided path
|
||||
options_ident = set_default_option(options_ident,'parameter_set','prior_mean');
|
||||
% 'calibration': use values in M_.params and M_.Sigma_e to update estimated stderr, corr and model parameters (get_all_parameters)
|
||||
|
@ -140,7 +140,7 @@ options_ident = set_default_option(options_ident,'tol_rank','robust');
|
|||
options_ident = set_default_option(options_ident,'tol_deriv',1.e-8);
|
||||
% tolerance level for selecting columns of non-zero derivatives
|
||||
options_ident = set_default_option(options_ident,'tol_sv',1.e-3);
|
||||
% tolerance level for selecting non-zero singular values in identification_checks.m
|
||||
% tolerance level for selecting non-zero singular values in identification.checks.m
|
||||
options_ident = set_default_option(options_ident,'schur_vec_tol',1e-11);
|
||||
% tolerance level used to find nonstationary variables in Schur decomposition of the transition matrix.
|
||||
|
||||
|
@ -181,7 +181,7 @@ if (isfield(options_ident,'no_identification_strength') && options_ident.no_ide
|
|||
options_ident.no_identification_moments = 0;
|
||||
end
|
||||
|
||||
%overwrite setting, as dynare_sensitivity does not make use of spectrum and minimal system
|
||||
%overwrite setting, as sensitivity.run does not make use of spectrum and minimal system
|
||||
if isfield(options_,'opt_gsa') && isfield(options_.opt_gsa,'identification') && options_.opt_gsa.identification == 1
|
||||
options_ident.no_identification_minimal = 1;
|
||||
options_ident.no_identification_spectrum = 1;
|
||||
|
@ -308,12 +308,12 @@ options_.options_ident = [];
|
|||
options_ident = set_default_option(options_ident,'analytic_derivation_mode', options_.analytic_derivation_mode); % if not set by user, inherit default global one
|
||||
% 0: efficient sylvester equation method to compute analytical derivatives as in Ratto & Iskrev (2012)
|
||||
% 1: kronecker products method to compute analytical derivatives as in Iskrev (2010) (only for order=1)
|
||||
% -1: numerical two-sided finite difference method to compute numerical derivatives of all identification Jacobians using function identification_numerical_objective.m (previously thet2tau.m)
|
||||
% -1: numerical two-sided finite difference method to compute numerical derivatives of all identification Jacobians using function identification.numerical_objective.m (previously thet2tau.m)
|
||||
% -2: numerical two-sided finite difference method to compute numerically dYss, dg1, dg2, dg3, d2Yss and d2g1, the identification Jacobians are then computed analytically as with 0
|
||||
|
||||
if options_.discretionary_policy || options_.ramsey_policy
|
||||
if options_ident.analytic_derivation_mode~=-1
|
||||
fprintf('dynare_identification: discretionary_policy and ramsey_policy require analytic_derivation_mode=-1. Resetting the option.')
|
||||
fprintf('identification.run: discretionary_policy and ramsey_policy require analytic_derivation_mode=-1. Resetting the option.')
|
||||
options_ident.analytic_derivation_mode=-1;
|
||||
end
|
||||
end
|
||||
|
@ -384,7 +384,7 @@ else % no estimated_params block, choose all model parameters and all stderr par
|
|||
name_tex = cellfun(@(x) horzcat('$ SE_{', x, '} $'), M_.exo_names_tex, 'UniformOutput', false);
|
||||
name_tex = vertcat(name_tex, cellfun(@(x) horzcat('$ ', x, ' $'), M_.param_names_tex, 'UniformOutput', false));
|
||||
if ~isequal(M_.H,0)
|
||||
fprintf('\ndynare_identification:: Identification does not support measurement errors (yet) and will ignore them in the following. To test their identifiability, instead define them explicitly as varexo and provide measurement equations in the model definition.\n')
|
||||
fprintf('\nidentification.run:: Identification does not support measurement errors (yet) and will ignore them in the following. To test their identifiability, instead define them explicitly as varexo and provide measurement equations in the model definition.\n')
|
||||
end
|
||||
end
|
||||
options_ident.name_tex = name_tex;
|
||||
|
@ -402,13 +402,13 @@ end
|
|||
% settings dependent on number of parameters
|
||||
options_ident = set_default_option(options_ident,'max_dim_cova_group',min([2,totparam_nbr-1]));
|
||||
options_ident.max_dim_cova_group = min([options_ident.max_dim_cova_group,totparam_nbr-1]);
|
||||
% In brute force search (ident_bruteforce.m) when advanced=1 this option sets the maximum dimension of groups of parameters that best reproduce the behavior of each single model parameter
|
||||
% In brute force search (identification.bruteforce.m) when advanced=1 this option sets the maximum dimension of groups of parameters that best reproduce the behavior of each single model parameter
|
||||
|
||||
options_ident = set_default_option(options_ident,'checks_via_subsets',0);
|
||||
% 1: uses identification_checks_via_subsets.m to compute problematic parameter combinations
|
||||
% 0: uses identification_checks.m to compute problematic parameter combinations [default]
|
||||
% 1: uses identification.checks_via_subsets.m to compute problematic parameter combinations
|
||||
% 0: uses identification.checks.m to compute problematic parameter combinations [default]
|
||||
options_ident = set_default_option(options_ident,'max_dim_subsets_groups',min([4,totparam_nbr-1]));
|
||||
% In identification_checks_via_subsets.m, when checks_via_subsets=1, this option sets the maximum dimension of groups of parameters for which the corresponding rank criteria is checked
|
||||
% In identification.checks_via_subsets.m, when checks_via_subsets=1, this option sets the maximum dimension of groups of parameters for which the corresponding rank criteria is checked
|
||||
|
||||
|
||||
% store identification options
|
||||
|
@ -471,7 +471,7 @@ if iload <=0
|
|||
options_ident.tittxt = parameters; %title text for graphs and figures
|
||||
% perform identification analysis for single point
|
||||
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, derivatives_info_point, info, error_indicator_point] = ...
|
||||
identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end implies initialization of persistent variables
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end implies initialization of persistent variables
|
||||
if info(1)~=0
|
||||
% there are errors in the solution algorithm
|
||||
message = get_error_message(info,options_);
|
||||
|
@ -488,7 +488,7 @@ if iload <=0
|
|||
options_ident.tittxt = 'Random_prior_params'; %title text for graphs and figures
|
||||
% perform identification analysis
|
||||
[ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, derivatives_info_point, info, error_indicator_point] = ...
|
||||
identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
end
|
||||
end
|
||||
if info(1)
|
||||
|
@ -513,10 +513,10 @@ if iload <=0
|
|||
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_hess_point', 'ide_reducedform_point', 'ide_dynamic_point', 'store_options_ident');
|
||||
save([IdentifDirectoryName '/' fname '_' parameters '_identif.mat'], 'ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_hess_point', 'ide_reducedform_point', 'ide_dynamic_point', 'store_options_ident');
|
||||
% display results of identification analysis
|
||||
disp_identification(params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
identification.display(params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
if ~options_ident.no_identification_strength && ~options_.nograph && ~error_indicator_point.identification_strength && ~error_indicator_point.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the moment information matrix and (ii) plot advanced analysis graphs
|
||||
plot_identification(M_,params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
|
||||
identification.plot(M_,params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, parameters_TeX, name_tex);
|
||||
end
|
||||
|
||||
|
@ -529,7 +529,7 @@ if iload <=0
|
|||
file_index = 0; % initialize counter for files (if options_.MaxNumberOfBytes is reached, we store results in files)
|
||||
options_MC = options_ident; %store options structure for Monte Carlo analysis
|
||||
options_MC.advanced = 0; %do not run advanced checking in a Monte Carlo analysis
|
||||
options_ident.checks_via_subsets = 0; % for Monte Carlo analysis currently only identification_checks and not identification_checks_via_subsets is supported
|
||||
options_ident.checks_via_subsets = 0; % for Monte Carlo analysis currently only identification.checks and not identification.checks_via_subsets is supported
|
||||
else
|
||||
iteration = 1; % iteration equals SampleSize and we are finished
|
||||
pdraws = []; % to have output object otherwise map_ident.m may crash
|
||||
|
@ -543,7 +543,7 @@ if iload <=0
|
|||
options_ident.tittxt = []; % clear title text for graphs and figures
|
||||
% run identification analysis
|
||||
[ide_moments, ide_spectrum, ide_minimal, ide_hess, ide_reducedform, ide_dynamic, ide_derivatives_info, info, error_indicator] = ...
|
||||
identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_MC, dataset_info, prior_exist, 0); % the 0 implies that we do not initialize persistent variables anymore
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,params, indpmodel, indpstderr, indpcorr, options_MC, dataset_info, prior_exist, 0); % the 0 implies that we do not initialize persistent variables anymore
|
||||
|
||||
if iteration==0 && info(1)==0 % preallocate storage in the first admissable run
|
||||
delete([IdentifDirectoryName '/' fname '_identif_*.mat']) % delete previously saved results
|
||||
|
@ -801,26 +801,26 @@ if iload <=0
|
|||
end
|
||||
for irun=1:max([maxrun_dDYNAMIC, maxrun_dREDUCEDFORM, maxrun_dMOMENTS, maxrun_dSPECTRUM, maxrun_dMINIMAL])
|
||||
iter=iter+1;
|
||||
% note that this is not the same si_dDYNAMICnorm as computed in identification_analysis
|
||||
% note that this is not the same si_dDYNAMICnorm as computed in identification.analysis
|
||||
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
|
||||
si_dDYNAMICnorm(iter,:) = vnorm(STO_si_dDYNAMIC(:,:,irun)./repmat(normalize_STO_DYNAMIC,1,totparam_nbr-(stderrparam_nbr+corrparam_nbr))).*normaliz1((stderrparam_nbr+corrparam_nbr)+1:end);
|
||||
si_dDYNAMICnorm(iter,:) = identification.vnorm(STO_si_dDYNAMIC(:,:,irun)./repmat(normalize_STO_DYNAMIC,1,totparam_nbr-(stderrparam_nbr+corrparam_nbr))).*normaliz1((stderrparam_nbr+corrparam_nbr)+1:end);
|
||||
if ~options_MC.no_identification_reducedform && ~isempty(STO_si_dREDUCEDFORM)
|
||||
% note that this is not the same si_dREDUCEDFORMnorm as computed in identification_analysis
|
||||
% note that this is not the same si_dREDUCEDFORMnorm as computed in identification.analysis
|
||||
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
|
||||
si_dREDUCEDFORMnorm(iter,:) = vnorm(STO_si_dREDUCEDFORM(:,:,irun)./repmat(normalize_STO_REDUCEDFORM,1,totparam_nbr)).*normaliz1;
|
||||
si_dREDUCEDFORMnorm(iter,:) = identification.vnorm(STO_si_dREDUCEDFORM(:,:,irun)./repmat(normalize_STO_REDUCEDFORM,1,totparam_nbr)).*normaliz1;
|
||||
end
|
||||
if ~options_MC.no_identification_moments && ~isempty(STO_si_dMOMENTS)
|
||||
% note that this is not the same si_dMOMENTSnorm as computed in identification_analysis
|
||||
% note that this is not the same si_dMOMENTSnorm as computed in identification.analysis
|
||||
% given that we have the MC sample of the Jacobians, we also normalize by the std of the sample of Jacobian entries, to get a fully standardized sensitivity measure
|
||||
si_dMOMENTSnorm(iter,:) = vnorm(STO_si_dMOMENTS(:,:,irun)./repmat(normalize_STO_MOMENTS,1,totparam_nbr)).*normaliz1;
|
||||
si_dMOMENTSnorm(iter,:) = identification.vnorm(STO_si_dMOMENTS(:,:,irun)./repmat(normalize_STO_MOMENTS,1,totparam_nbr)).*normaliz1;
|
||||
end
|
||||
if ~options_MC.no_identification_spectrum && ~isempty(STO_dSPECTRUM)
|
||||
% note that this is not the same dSPECTRUMnorm as computed in identification_analysis
|
||||
dSPECTRUMnorm(iter,:) = vnorm(STO_dSPECTRUM(:,:,irun)); %not yet used
|
||||
% note that this is not the same dSPECTRUMnorm as computed in identification.analysis
|
||||
dSPECTRUMnorm(iter,:) = identification.vnorm(STO_dSPECTRUM(:,:,irun)); %not yet used
|
||||
end
|
||||
if ~options_MC.no_identification_minimal && ~isempty(STO_dMINIMAL)
|
||||
% note that this is not the same dMINIMALnorm as computed in identification_analysis
|
||||
dMINIMALnorm(iter,:) = vnorm(STO_dMINIMAL(:,:,irun)); %not yet used
|
||||
% note that this is not the same dMINIMALnorm as computed in identification.analysis
|
||||
dMINIMALnorm(iter,:) = identification.vnorm(STO_dMINIMAL(:,:,irun)); %not yet used
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -847,7 +847,7 @@ else
|
|||
options_.options_ident = options_ident;
|
||||
end
|
||||
|
||||
%% if dynare_identification is called as it own function (not through identification command) and if we load files
|
||||
%% if identification.run is called as it own function (not through identification command) and if we load files
|
||||
if nargout>3 && iload
|
||||
filnam = dir([IdentifDirectoryName '/' fname '_identif_*.mat']);
|
||||
STO_si_dDYNAMIC = [];
|
||||
|
@ -876,10 +876,10 @@ end
|
|||
if iload
|
||||
%if previous analysis is loaded
|
||||
fprintf(['Testing %s\n',parameters]);
|
||||
disp_identification(ide_hess_point.params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
identification.display(ide_hess_point.params, ide_reducedform_point, ide_moments_point, ide_spectrum_point, ide_minimal_point, name, options_ident);
|
||||
if ~options_.nograph && ~error_indicator_point.identification_strength && ~error_indicator_point.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(M_,ide_hess_point.params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
|
||||
identification.plot(M_,ide_hess_point.params, ide_moments_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, options_ident.advanced, parameters, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, [], name_tex);
|
||||
end
|
||||
end
|
||||
|
@ -890,11 +890,11 @@ if SampleSize > 1
|
|||
%print results to console but make sure advanced=0
|
||||
advanced0 = options_ident.advanced;
|
||||
options_ident.advanced = 0;
|
||||
disp_identification(pdraws, IDE_REDUCEDFORM, IDE_MOMENTS, IDE_SPECTRUM, IDE_MINIMAL, name, options_ident);
|
||||
identification.display(pdraws, IDE_REDUCEDFORM, IDE_MOMENTS, IDE_SPECTRUM, IDE_MINIMAL, name, options_ident);
|
||||
options_ident.advanced = advanced0; % reset advanced setting
|
||||
if ~options_.nograph && isfield(ide_hess_point,'ide_strength_dMOMENTS')
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(M_, pdraws, IDE_MOMENTS, ide_hess_point, IDE_REDUCEDFORM, IDE_DYNAMIC, options_ident.advanced, 'MC sample ', name, ...
|
||||
identification.plot(M_, pdraws, IDE_MOMENTS, ide_hess_point, IDE_REDUCEDFORM, IDE_DYNAMIC, options_ident.advanced, 'MC sample ', name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, [], name_tex);
|
||||
end
|
||||
%advanced display and plots for MC Sample, i.e. look at draws with highest/lowest condition number
|
||||
|
@ -912,15 +912,15 @@ if SampleSize > 1
|
|||
if ~iload
|
||||
options_ident.tittxt = tittxt; %title text for graphs and figures
|
||||
[ide_moments_max, ide_spectrum_max, ide_minimal_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, derivatives_info_max, info_max, error_indicator_max] = ...
|
||||
identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmax,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes some persistent variables
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmax,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes some persistent variables
|
||||
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_hess_max', 'ide_moments_max', 'ide_spectrum_max', 'ide_minimal_max','ide_reducedform_max', 'ide_dynamic_max', 'jmax', '-append');
|
||||
end
|
||||
advanced0 = options_ident.advanced; options_ident.advanced = 1; % make sure advanced setting is on
|
||||
disp_identification(pdraws(jmax,:), ide_reducedform_max, ide_moments_max, ide_spectrum_max, ide_minimal_max, name, options_ident);
|
||||
identification.display(pdraws(jmax,:), ide_reducedform_max, ide_moments_max, ide_spectrum_max, ide_minimal_max, name, options_ident);
|
||||
options_ident.advanced = advanced0; %reset advanced setting
|
||||
if ~options_.nograph && ~error_indicator_max.identification_strength && ~error_indicator_max.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(M_, pdraws(jmax,:), ide_moments_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, 1, tittxt, name, ...
|
||||
identification.plot(M_, pdraws(jmax,:), ide_moments_max, ide_hess_max, ide_reducedform_max, ide_dynamic_max, 1, tittxt, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt, name_tex);
|
||||
end
|
||||
|
||||
|
@ -931,15 +931,15 @@ if SampleSize > 1
|
|||
if ~iload
|
||||
options_ident.tittxt = tittxt; %title text for graphs and figures
|
||||
[ide_moments_min, ide_spectrum_min, ide_minimal_min, ide_hess_min, ide_reducedform_min, ide_dynamic_min, ~, ~, error_indicator_min] = ...
|
||||
identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmin,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes persistent variables
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jmin,:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end initializes persistent variables
|
||||
save([IdentifDirectoryName '/' fname '_identif.mat'], 'ide_hess_min', 'ide_moments_min','ide_spectrum_min','ide_minimal_min','ide_reducedform_min', 'ide_dynamic_min', 'jmin', '-append');
|
||||
end
|
||||
advanced0 = options_ident.advanced; options_ident.advanced = 1; % make sure advanced setting is on
|
||||
disp_identification(pdraws(jmin,:), ide_reducedform_min, ide_moments_min, ide_spectrum_min, ide_minimal_min, name, options_ident);
|
||||
identification.display(pdraws(jmin,:), ide_reducedform_min, ide_moments_min, ide_spectrum_min, ide_minimal_min, name, options_ident);
|
||||
options_ident.advanced = advanced0; %reset advanced setting
|
||||
if ~options_.nograph && ~error_indicator_min.identification_strength && ~error_indicator_min.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(M_, pdraws(jmin,:),ide_moments_min,ide_hess_min,ide_reducedform_min,ide_dynamic_min,1,tittxt,name,...
|
||||
identification.plot(M_, pdraws(jmin,:),ide_moments_min,ide_hess_min,ide_reducedform_min,ide_dynamic_min,1,tittxt,name,...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt,name_tex);
|
||||
end
|
||||
% reset nodisplay option
|
||||
|
@ -954,14 +954,14 @@ if SampleSize > 1
|
|||
if ~iload
|
||||
options_ident.tittxt = tittxt; %title text for graphs and figures
|
||||
[ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), derivatives_info_(j), info_resolve, error_indicator_j] = ...
|
||||
identification_analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jcrit(j),:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
identification.analysis(M_,options_,oo_,bayestopt_,estim_params_,pdraws(jcrit(j),:), indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1);
|
||||
end
|
||||
advanced0 = options_ident.advanced; options_ident.advanced = 1; %make sure advanced setting is on
|
||||
disp_identification(pdraws(jcrit(j),:), ide_reducedform_(j), ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), name, options_ident);
|
||||
identification.display(pdraws(jcrit(j),:), ide_reducedform_(j), ide_moments_(j), ide_spectrum_(j), ide_minimal_(j), name, options_ident);
|
||||
options_ident.advanced = advanced0; % reset advanced
|
||||
if ~options_.nograph && ~error_indicator_j.identification_strength && ~error_indicator_j.identification_moments
|
||||
% plot (i) identification strength and sensitivity measure based on the sample information matrix and (ii) advanced analysis graphs
|
||||
plot_identification(M_, pdraws(jcrit(j),:), ide_moments_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), 1, tittxt, name, ...
|
||||
identification.plot(M_, pdraws(jcrit(j),:), ide_moments_(j), ide_hess_(j), ide_reducedform_(j), ide_dynamic_(j), 1, tittxt, name, ...
|
||||
IdentifDirectoryName, M_.fname, options_, estim_params_, bayestopt_, tittxt, name_tex);
|
||||
end
|
||||
end
|
|
@ -160,8 +160,6 @@ options_mom_ = set_default_option(options_mom_,'lyapunov_srs',false);
|
|||
options_mom_ = set_default_option(options_mom_,'lyapunov_complex_threshold',1e-15); % complex block threshold for the upper triangular matrix in symmetric Lyapunov equation solver
|
||||
options_mom_ = set_default_option(options_mom_,'lyapunov_fixed_point_tol',1e-10); % convergence criterion used in the fixed point Lyapunov solver
|
||||
options_mom_ = set_default_option(options_mom_,'lyapunov_doubling_tol',1e-16); % convergence criterion used in the doubling algorithm
|
||||
options_mom_ = set_default_option(options_mom_,'sylvester_fp',false); % determines whether to use fixed point algorihtm to solve Sylvester equation (gensylv_fp), faster for large scale models
|
||||
options_mom_ = set_default_option(options_mom_,'sylvester_fixed_point_tol',1e-12); % convergence criterion used in the fixed point Sylvester solver
|
||||
|
||||
% mode check plot
|
||||
options_mom_.mode_check.nolik = false; % we don't do likelihood (also this initializes mode_check substructure)
|
||||
|
|
|
@ -150,11 +150,11 @@ if strcmp(options_mom_.mom.mom_method,'GMM')
|
|||
stderrparam_nbr = estim_params_.nvx; % number of stderr parameters
|
||||
corrparam_nbr = estim_params_.ncx; % number of corr parameters
|
||||
totparam_nbr = stderrparam_nbr+corrparam_nbr+modparam_nbr;
|
||||
oo_.dr.derivs = get_perturbation_params_derivs(M_, options_mom_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, 0); %analytic derivatives of perturbation matrices
|
||||
oo_.dr.derivs = identification.get_perturbation_params_derivs(M_, options_mom_, estim_params_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, indpmodel, indpstderr, indpcorr, 0); %analytic derivatives of perturbation matrices
|
||||
oo_.mom.model_moments_params_derivs = NaN(options_mom_.mom.mom_nbr,totparam_nbr);
|
||||
pruned_state_space = pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 1);
|
||||
pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 1);
|
||||
else
|
||||
pruned_state_space = pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 0);
|
||||
pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_mom_, oo_.dr, oo_.mom.obs_var, options_mom_.ar, 0, 0);
|
||||
end
|
||||
oo_.mom.model_moments = NaN(options_mom_.mom.mom_nbr,1);
|
||||
for jm = 1:size(M_.matched_moments,1)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function [alphahat,etahat,epsilonhat,ahat0,SteadyState,trend_coeff,aKK,T0,R0,P,PKK,decomp,Trend,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0] = DSGE_smoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,dataset_, dataset_info)
|
||||
%function [alphahat,etahat,epsilonhat,ahat0,SteadyState,trend_coeff,aKK,T0,R0,P,PKK,decomp,Trend,state_uncertainty,M_,oo_,bayestopt_] = DSGE_smoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,dataset_, dataset_info)
|
||||
% [alphahat,etahat,epsilonhat,ahat0,SteadyState,trend_coeff,aKK,T0,R0,P,PKK,decomp,Trend,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0] = DSGE_smoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,dataset_, dataset_info)
|
||||
% Runs a DSGE smoother with occasionally binding constraints
|
||||
%
|
||||
% INPUTS
|
||||
|
@ -112,8 +112,6 @@ opts_simul.max_check_ahead_periods = options_.occbin.smoother.max_check_ahead_pe
|
|||
opts_simul.periodic_solution = options_.occbin.smoother.periodic_solution;
|
||||
opts_simul.full_output = options_.occbin.smoother.full_output;
|
||||
opts_simul.piecewise_only = options_.occbin.smoother.piecewise_only;
|
||||
% init_mode = options_.occbin.smoother.init_mode; % 0 = standard; 1 = unconditional frcsts zero shocks+smoothed states in each period
|
||||
% init_mode = 0;
|
||||
occbin_options = struct();
|
||||
|
||||
occbin_options.first_period_occbin_update = options_.occbin.smoother.first_period_occbin_update;
|
||||
|
@ -156,15 +154,10 @@ if options_.smoother_redux
|
|||
[T0,R0] = dynare_resolve(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
oo_.occbin.linear_smoother.T0=T0;
|
||||
oo_.occbin.linear_smoother.R0=R0;
|
||||
% oo_.occbin.linear_smoother.T0=ss.T(oo_.dr.order_var,oo_.dr.order_var,1);
|
||||
% oo_.occbin.linear_smoother.R0=ss.R(oo_.dr.order_var,:,1);
|
||||
end
|
||||
TT = ss.T(oo_.dr.order_var,oo_.dr.order_var,:);
|
||||
RR = ss.R(oo_.dr.order_var,:,:);
|
||||
CC = ss.C(oo_.dr.order_var,:);
|
||||
% TT = cat(3,TT(:,:,1),TT);
|
||||
% RR = cat(3,RR(:,:,1),RR);
|
||||
% CC = cat(2,CC(:,1),CC);
|
||||
|
||||
opts_regime.regime_history = regime_history;
|
||||
opts_regime.binding_indicator = [];
|
||||
|
@ -186,6 +179,7 @@ sto_etahat={etahat};
|
|||
sto_CC = CC;
|
||||
sto_RR = RR;
|
||||
sto_TT = TT;
|
||||
sto_eee=NaN(size(TT,1),size(TT,3));
|
||||
for k=1:size(TT,3)
|
||||
sto_eee(:,k) = eig(TT(:,:,k));
|
||||
end
|
||||
|
@ -195,11 +189,12 @@ while is_changed && maxiter>iter && ~is_periodic
|
|||
iter=iter+1;
|
||||
fprintf('Occbin smoother iteration %u.\n', iter)
|
||||
occbin_options.opts_regime.regime_history=regime_history;
|
||||
[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T0,R0,P,PK,decomp,Trend,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0, diffuse_steps] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,occbin_options,TT,RR,CC);% T1=TT;
|
||||
[alphahat,etahat,epsilonhat,~,SteadyState,trend_coeff,~,T0,R0,P,~,decomp,Trend,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0]...
|
||||
= DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,occbin_options,TT,RR,CC);
|
||||
sto_etahat(iter)={etahat};
|
||||
regime_history0(iter,:) = regime_history;
|
||||
if occbin_smoother_debug
|
||||
save('info1','regime_history0');
|
||||
save('Occbin_smoother_debug_regime_history','regime_history0');
|
||||
end
|
||||
|
||||
sto_CC = CC;
|
||||
|
@ -220,13 +215,13 @@ while is_changed && maxiter>iter && ~is_periodic
|
|||
TT = ss.T(oo_.dr.order_var,oo_.dr.order_var,:);
|
||||
RR = ss.R(oo_.dr.order_var,:,:);
|
||||
CC = ss.C(oo_.dr.order_var,:);
|
||||
% TT = cat(3,TT(:,:,1),TT);
|
||||
% RR = cat(3,RR(:,:,1),RR);
|
||||
% CC = cat(2,CC(:,1),CC);
|
||||
|
||||
opts_regime.regime_history = regime_history;
|
||||
[TT, RR, CC, regime_history] = occbin.check_regimes(TT, RR, CC, opts_regime, M_, options_ , oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
||||
is_changed = ~isequal(regime_history0(iter,:),regime_history);
|
||||
isdiff_regime=NaN(size(regime_history0,2),M_.occbin.constraint_nbr);
|
||||
isdiff_start=NaN(size(isdiff_regime));
|
||||
isdiff_=NaN(size(isdiff_regime));
|
||||
if M_.occbin.constraint_nbr==2
|
||||
for k=1:size(regime_history0,2)
|
||||
isdiff_regime(k,1) = ~isequal(regime_history0(end,k).regime1,regime_history(k).regime1);
|
||||
|
@ -236,16 +231,16 @@ while is_changed && maxiter>iter && ~is_periodic
|
|||
isdiff_start(k,2) = ~isequal(regime_history0(end,k).regimestart2,regime_history(k).regimestart2);
|
||||
isdiff_(k,2) = isdiff_regime(k,2) || isdiff_start(k,2);
|
||||
end
|
||||
is_changed_regime = ~isempty(find(isdiff_regime(:,1))) || ~isempty(find(isdiff_regime(:,2)));
|
||||
is_changed_start = ~isempty(find(isdiff_start(:,1))) || ~isempty(find(isdiff_start(:,2)));
|
||||
is_changed_regime = any(isdiff_regime(:,1)) || any(isdiff_regime(:,2));
|
||||
is_changed_start = any(isdiff_start(:,1)) || any(isdiff_start(:,2));
|
||||
else
|
||||
for k=1:size(regime_history0,2)
|
||||
isdiff_regime(k,1) = ~isequal(regime_history0(end,k).regime,regime_history(k).regime);
|
||||
isdiff_start(k,1) = ~isequal(regime_history0(end,k).regimestart,regime_history(k).regimestart);
|
||||
isdiff_(k,1) = isdiff_regime(k,1) || isdiff_start(k,1);
|
||||
end
|
||||
is_changed_regime = ~isempty(find(isdiff_regime(:,1)));
|
||||
is_changed_start = ~isempty(find(isdiff_start(:,1)));
|
||||
is_changed_regime = any(isdiff_regime(:,1));
|
||||
is_changed_start = any(isdiff_start(:,1));
|
||||
end
|
||||
if occbin_smoother_fast
|
||||
is_changed = is_changed_regime;
|
||||
|
@ -261,15 +256,18 @@ while is_changed && maxiter>iter && ~is_periodic
|
|||
end
|
||||
|
||||
if is_changed
|
||||
eee=NaN(size(TT,1),size(TT,3));
|
||||
for k=1:size(TT,3)
|
||||
eee(:,k) = eig(TT(:,:,k));
|
||||
end
|
||||
err_eig(iter-1) = max(max(abs(sort(eee)-sort(sto_eee))));
|
||||
err_alphahat(iter-1) = max(max(max(abs(alphahat-sto_alphahat))));
|
||||
err_etahat(iter-1) = max(max(max(abs(etahat-sto_etahat{iter-1}))));
|
||||
err_CC(iter-1) = max(max(max(abs(CC-sto_CC))));
|
||||
err_RR(iter-1) = max(max(max(abs(RR-sto_RR))));
|
||||
err_TT(iter-1) = max(max(max(abs(TT-sto_TT))));
|
||||
if options_.debug
|
||||
err_eig(iter-1) = max(max(abs(sort(eee)-sort(sto_eee))));
|
||||
err_alphahat(iter-1) = max(max(max(abs(alphahat-sto_alphahat))));
|
||||
err_etahat(iter-1) = max(max(max(abs(etahat-sto_etahat{iter-1}))));
|
||||
err_CC(iter-1) = max(max(max(abs(CC-sto_CC))));
|
||||
err_RR(iter-1) = max(max(max(abs(RR-sto_RR))));
|
||||
err_TT(iter-1) = max(max(max(abs(TT-sto_TT))));
|
||||
end
|
||||
end
|
||||
|
||||
if occbin_smoother_debug || is_periodic
|
||||
|
@ -350,7 +348,7 @@ regime_history0(max(iter+1,1),:) = regime_history;
|
|||
oo_.occbin.smoother.regime_history=regime_history0(end,:);
|
||||
oo_.occbin.smoother.regime_history_iter=regime_history0;
|
||||
if occbin_smoother_debug
|
||||
save('info1','regime_history0')
|
||||
save('Occbin_smoother_debug_regime_history','regime_history0')
|
||||
end
|
||||
|
||||
if (maxiter==iter && is_changed) || is_periodic
|
||||
|
@ -395,6 +393,14 @@ if (~is_changed || occbin_smoother_debug) && nargin==12
|
|||
oo_.occbin.smoother.C0=CC;
|
||||
if options_.occbin.smoother.plot
|
||||
GraphDirectoryName = CheckPath('graphs',M_.fname);
|
||||
latexFolder = CheckPath('latex',M_.dname);
|
||||
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fidTeX = fopen([latexFolder filesep M_.fname '_OccBin_smoother_plots.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by occbin.DSGE_smoother.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
j1=0;
|
||||
ifig=0;
|
||||
for j=1:M_.exo_nbr
|
||||
|
@ -414,23 +420,49 @@ if (~is_changed || occbin_smoother_debug) && nargin==12
|
|||
plot(oo_.occbin.smoother.etahat(j,:)','r--','linewidth',2)
|
||||
hold on, plot([0 options_.nobs],[0 0],'k--')
|
||||
set(gca,'xlim',[0 options_.nobs])
|
||||
title(deblank(M_.exo_names(j,:)),'interpreter','none')
|
||||
if options_.TeX
|
||||
title(['$' M_.exo_names_tex{j,:} '$'],'interpreter','latex')
|
||||
else
|
||||
title(M_.exo_names{j,:},'interpreter','none')
|
||||
end
|
||||
|
||||
if mod(j1,9)==0
|
||||
if options_.occbin.smoother.linear_smoother
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', 'Linear','Color','Blue','horizontalalignment','center','interpreter','none');
|
||||
end
|
||||
annotation('textbox', [0.55,0,0.35,0.05],'String', 'Piecewise','Color','Red','horizontalalignment','center','interpreter','none');
|
||||
dyn_saveas(gcf,[GraphDirectoryName filesep M_.fname,'_smoothedshocks_occbin',int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
% TeX eps loader file
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_smoothedshocks_occbin%s}\n',options_.figures.textwidth*min(j1/3,1),[GraphDirectoryName '/' M_.fname],int2str(ifig)); % don't use filesep as it will create issues with LaTeX on Windows
|
||||
fprintf(fidTeX,'\\caption{Check plots.}');
|
||||
fprintf(fidTeX,'\\label{Fig:smoothedshocks_occbin:%s}\n',int2str(ifig));
|
||||
fprintf(fidTeX,'\\end{figure}\n');
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if mod(j1,9)~=0 && j==M_.exo_nbr
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', 'Linear','Color','Blue','horizontalalignment','center','interpreter','none');
|
||||
annotation('textbox', [0.55,0,0.35,0.05],'String', 'Piecewise','Color','Red','horizontalalignment','center','interpreter','none');
|
||||
dyn_saveas(hh_fig,[GraphDirectoryName filesep M_.fname,'_smoothedshocks_occbin',int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
if mod(j1,9)~=0 && j==M_.exo_nbr
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', 'Linear','Color','Blue','horizontalalignment','center','interpreter','none');
|
||||
annotation('textbox', [0.55,0,0.35,0.05],'String', 'Piecewise','Color','Red','horizontalalignment','center','interpreter','none');
|
||||
dyn_saveas(hh_fig,[GraphDirectoryName filesep M_.fname,'_smoothedshocks_occbin',int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
% TeX eps loader file
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_smoothedshocks_occbin%s}\n',options_.figures.textwidth*min(j1/3,1),[GraphDirectoryName '/' M_.fname],int2str(ifig)); % don't use filesep as it will create issues with LaTeX on Windows
|
||||
fprintf(fidTeX,'\\caption{Check plots.}');
|
||||
fprintf(fidTeX,'\\label{Fig:smoothedshocks_occbin:%s}\n',int2str(ifig));
|
||||
fprintf(fidTeX,'\\end{figure}\n');
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
end
|
||||
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
fclose(fidTeX);
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
function [oo_, error_flag] = forecast(options_,M_,oo_,forecast) %,hist_period)
|
||||
%function oo_ = forecast(options_,M_,oo_,forecast)
|
||||
% forecast
|
||||
|
||||
opts = options_.occbin.forecast;
|
||||
|
||||
options_.occbin.simul.maxit = opts.maxit;
|
||||
options_.occbin.simul.check_ahead_periods = opts.check_ahead_periods;
|
||||
options_.occbin.simul.periods = forecast;
|
||||
SHOCKS0 = opts.SHOCKS0;
|
||||
if ~isempty(SHOCKS0)
|
||||
if iscell(SHOCKS0)
|
||||
for j=1:length(SHOCKS0)
|
||||
sname = SHOCKS0{j}{1};
|
||||
inds(j)=strmatch(sname,M_.exo_names);
|
||||
SHOCKS1(j,:)=SHOCKS0{j}{2};
|
||||
end
|
||||
elseif isreal(SHOCKS0)
|
||||
SHOCKS1=SHOCKS0;
|
||||
inds = 1:M_.exo_nbr;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if opts.replic
|
||||
h = dyn_waitbar(0,'Please wait occbin forecast replic ...');
|
||||
ishock = find(sqrt(diag((M_.Sigma_e))));
|
||||
effective_exo_nbr= length(ishock);
|
||||
effective_exo_names = M_.exo_names(ishock);
|
||||
effective_Sigma_e = M_.Sigma_e(ishock,ishock);
|
||||
[U,S,V] = svd(effective_Sigma_e);
|
||||
if opts.qmc
|
||||
opts.replic =2^(round(log2(opts.replic+1)))-1;
|
||||
SHOCKS_ant = qmc_sequence(forecast*effective_exo_nbr, int64(1), 1, opts.replic)';
|
||||
else
|
||||
SHOCKS_ant = randn(forecast*effective_exo_nbr,opts.replic)';
|
||||
end
|
||||
zlin0=zeros(forecast,M_.endo_nbr,opts.replic);
|
||||
zpiece0=zeros(forecast,M_.endo_nbr,opts.replic);
|
||||
for iter=1:opts.replic
|
||||
|
||||
if ~isempty(SHOCKS0)
|
||||
for j=1:length(SHOCKS0)
|
||||
SHOCKS(:,inds(j))=SHOCKS1(j,:);
|
||||
end
|
||||
end
|
||||
|
||||
error_flagx=1;
|
||||
% while error_flagx,
|
||||
% SHOCKS=transpose(sqrt(diag(diag(effective_Sigma_e)))*(reshape(SHOCKS_ant(iter,:),forecast,effective_exo_nbr))');
|
||||
SHOCKS=transpose(U*sqrt(S)*(reshape(SHOCKS_ant(iter,:),forecast,effective_exo_nbr))');
|
||||
% SHOCKS=transpose(U*sqrt(S)*randn(forecast,M_.exo_nbr)'); %realized shocks
|
||||
options_.occbin.simul.endo_init = M_.endo_histval(:,1)-oo_.steady_state;
|
||||
options_.occbin.simul.init_regime = opts.frcst_regimes;
|
||||
options_.occbin.simul.init_binding_indicator = [];
|
||||
options_.occbin.simul.exo_pos=ishock;
|
||||
options_.occbin.simul.SHOCKS = SHOCKS;
|
||||
options_.occbin.simul.waitbar=0;
|
||||
[~, out] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
zlin0(:,:,iter)=out.linear;
|
||||
zpiece0(:,:,iter)=out.piecewise;
|
||||
ys=out.ys;
|
||||
frcst_regime_history(iter,:)=out.regime_history;
|
||||
error_flag(iter)=out.error_flag;
|
||||
error_flagx = error_flag(iter);
|
||||
% end
|
||||
simul_SHOCKS(:,:,iter) = SHOCKS;
|
||||
|
||||
if error_flag(iter) && debug_flag
|
||||
% display('no solution')
|
||||
|
||||
% keyboard;
|
||||
save no_solution SHOCKS zlin0 zpiece0 iter frcst_regime_history
|
||||
end
|
||||
dyn_waitbar(iter/opts.replic,h,['OccBin MC forecast replic ',int2str(iter),'/',int2str(opts.replic)])
|
||||
end
|
||||
dyn_waitbar_close(h);
|
||||
save temp zlin0 zpiece0 simul_SHOCKS error_flag
|
||||
inx=find(error_flag==0);
|
||||
zlin0=zlin0(:,:,inx);
|
||||
zpiece0=zpiece0(:,:,inx);
|
||||
zlin = mean(zlin0,3);
|
||||
zpiece = mean(zpiece0,3);
|
||||
zpiecemin = min(zpiece0,[],3);
|
||||
zpiecemax = max(zpiece0,[],3);
|
||||
zlinmin = min(zlin0,[],3);
|
||||
zlinmax = max(zlin0,[],3);
|
||||
|
||||
for i=1:M_.endo_nbr
|
||||
for j=1:forecast
|
||||
[post_mean(j,1), post_median(j,1), post_var(j,1), hpd_interval(j,:), post_deciles(j,:)] = posterior_moments(squeeze(zlin0(j,i,:)),1,options_.forecasts.conf_sig);
|
||||
end
|
||||
oo_.occbin.linear_forecast.Mean.(M_.endo_names{i})=post_mean;
|
||||
oo_.occbin.linear_forecast.Median.(M_.endo_names{i})=post_median;
|
||||
oo_.occbin.linear_forecast.Var.(M_.endo_names{i})=post_var;
|
||||
oo_.occbin.linear_forecast.HPDinf.(M_.endo_names{i})=hpd_interval(:,1);
|
||||
oo_.occbin.linear_forecast.HPDsup.(M_.endo_names{i})=hpd_interval(:,2);
|
||||
oo_.occbin.linear_forecast.Deciles.(M_.endo_names{i})=post_deciles;
|
||||
oo_.occbin.linear_forecast.Min.(M_.endo_names{i})=zlinmin(:,i);
|
||||
oo_.occbin.linear_forecast.Max.(M_.endo_names{i})=zlinmax(:,i);
|
||||
for j=1:forecast
|
||||
[post_mean(j,1), post_median(j,1), post_var(j,1), hpd_interval(j,:), post_deciles(j,:)] = posterior_moments(squeeze(zpiece0(j,i,:)),1,options_.forecasts.conf_sig);
|
||||
end
|
||||
oo_.occbin.forecast.Mean.(M_.endo_names{i})=post_mean;
|
||||
oo_.occbin.forecast.Median.(M_.endo_names{i})=post_median;
|
||||
oo_.occbin.forecast.Var.(M_.endo_names{i})=post_var;
|
||||
oo_.occbin.forecast.HPDinf.(M_.endo_names{i})=hpd_interval(:,1);
|
||||
oo_.occbin.forecast.HPDsup.(M_.endo_names{i})=hpd_interval(:,2);
|
||||
oo_.occbin.forecast.Deciles.(M_.endo_names{i})=post_deciles;
|
||||
oo_.occbin.forecast.Min.(M_.endo_names{i})=zpiecemin(:,i);
|
||||
oo_.occbin.forecast.Max.(M_.endo_names{i})=zpiecemax(:,i);
|
||||
% eval([M_.endo_names{i},'_ss=zdatass(i);']);
|
||||
end
|
||||
|
||||
else
|
||||
SHOCKS = zeros(forecast,M_.exo_nbr);
|
||||
if ~isempty(SHOCKS0)
|
||||
for j=1:length(SHOCKS0)
|
||||
SHOCKS(:,inds(j))=SHOCKS1(j,:);
|
||||
end
|
||||
end
|
||||
options_.occbin.simul.endo_init = M_.endo_histval(:,1)-oo_.steady_state;
|
||||
options_.occbin.simul.init_regime = opts.frcst_regimes;
|
||||
options_.occbin.simul.init_violvecbool = [];
|
||||
options_.occbin.simul.irfshock = M_.exo_names;
|
||||
options_.occbin.simul.SHOCKS = SHOCKS;
|
||||
[~, out] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
|
||||
zlin=out.linear;
|
||||
zpiece=out.piecewise;
|
||||
frcst_regime_history=out.regime_history;
|
||||
error_flag=out.error_flag;
|
||||
for i=1:M_.endo_nbr
|
||||
oo_.occbin.linear_forecast.Mean.(M_.endo_names{i})= zlin(:,i);
|
||||
oo_.occbin.forecast.Mean.(M_.endo_names{i})= zpiece(:,i);
|
||||
oo_.occbin.forecast.HPDinf.(M_.endo_names{i})= nan;
|
||||
oo_.occbin.forecast.HPDsup.(M_.endo_names{i})= nan;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
oo_.occbin.forecast.regimes=frcst_regime_history;
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
function [oo_] = irf(M_,oo_,options_)
|
||||
|
||||
shocknames = options_.occbin.irf.exo_names;
|
||||
shocksigns = options_.occbin.irf.shocksigns;
|
||||
shocksize = options_.occbin.irf.shocksize;
|
||||
t0 = options_.occbin.irf.t0;
|
||||
options_.occbin.simul.init_regime = options_.occbin.irf.init_regime;
|
||||
options_.occbin.simul.check_ahead_periods = options_.occbin.irf.check_ahead_periods;
|
||||
options_.occbin.simul.maxit = options_.occbin.irf.maxit;
|
||||
options_.occbin.simul.periods = options_.irf;
|
||||
|
||||
% Run inital conditions + other shocks
|
||||
if t0 == 0
|
||||
shocks0= zeros(options_.occbin.simul.periods+1,M_.exo_nbr);
|
||||
options_.occbin.simul.endo_init = [];
|
||||
else
|
||||
% girf conditional to smoothed states in t0 and shocks in t0+1
|
||||
shocks0= [oo_.occbin.smoother.etahat(:,t0+1)'; zeros(options_.occbin.simul.periods,M_.exo_nbr)];
|
||||
options_.occbin.simul.SHOCKS=shocks0;
|
||||
options_.occbin.simul.endo_init = oo_.occbin.smoother.alphahat(oo_.dr.inv_order_var,t0);
|
||||
end
|
||||
options_.occbin.simul.SHOCKS=shocks0;
|
||||
[~, out0] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
zlin0 = out0.linear;
|
||||
zpiece0 = out0.piecewise;
|
||||
|
||||
% Select shocks of interest
|
||||
jexo_all =zeros(size(shocknames,1),1);
|
||||
|
||||
for i=1:length(shocknames)
|
||||
jexo_all(i) = strmatch(shocknames{i},M_.exo_names,'exact');
|
||||
end
|
||||
|
||||
oo_.occbin.linear_irfs = struct();
|
||||
oo_.occbin.irfs = struct();
|
||||
% Set shock size
|
||||
if isempty(shocksize)
|
||||
% if isfield(oo_.posterior_mode.shocks_std,M_.exo_names{jexo})
|
||||
shocksize = sqrt(diag(M_.Sigma_e(jexo_all,jexo_all))); %oo_.posterior_mode.shocks_std.(M_.exo_names{jexo});
|
||||
if any(shocksize < 1.e-9)
|
||||
shocksize(shocksize < 1.e-9) = 0.01;
|
||||
end
|
||||
end
|
||||
if numel(shocksize)==1
|
||||
shocksize=repmat(shocksize,[length(shocknames),1]);
|
||||
end
|
||||
|
||||
% Run IRFs
|
||||
for counter = 1:length(jexo_all)
|
||||
|
||||
jexo = jexo_all(counter);
|
||||
|
||||
if ~options_.noprint
|
||||
fprintf('Producing GIRFs for shock %s. Simulation %d out of %d. \n',M_.exo_names{jexo},counter,size(jexo_all,1));
|
||||
end
|
||||
|
||||
if ismember('pos',shocksigns)
|
||||
% (+) shock
|
||||
shocks1=shocks0;
|
||||
shocks1(1,jexo)=shocks0(1,jexo)+shocksize(counter);
|
||||
if t0 == 0
|
||||
options_.occbin.simul.SHOCKS=shocks1;
|
||||
options_.occbin.simul.endo_init = [];
|
||||
[~, out_pos] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
else
|
||||
options_.occbin.simul.SHOCKS=shocks1;
|
||||
options_.occbin.simul.endo_init = oo_.occbin.smoother.alphahat(oo_.dr.inv_order_var,t0);
|
||||
[~, out_pos] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
end
|
||||
if out_pos.error_flag
|
||||
warning('Occbin error.')
|
||||
return
|
||||
end
|
||||
zlin_pos = out_pos.linear;
|
||||
zpiece_pos = out_pos.piecewise;
|
||||
% Substract inital conditions + other shocks
|
||||
zlin_pos_diff = zlin_pos-zlin0;
|
||||
zpiece_pos_diff = zpiece_pos-zpiece0;
|
||||
end
|
||||
|
||||
if ismember('neg',shocksigns)
|
||||
% (-) shock
|
||||
shocks_1=shocks0;
|
||||
shocks_1(1,jexo)=shocks0(1,jexo)-shocksize(counter);
|
||||
if t0 == 0
|
||||
options_.occbin.simul.SHOCKS=shocks_1;
|
||||
options_.occbin.simul.endo_init = [];
|
||||
[~, out_neg] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
else
|
||||
options_.occbin.simul.SHOCKS=shocks_1;
|
||||
options_.occbin.simul.endo_init = oo_.occbin.smoother.alphahat(oo_.dr.inv_order_var,t0);
|
||||
[~, out_neg] = occbin.solver(M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
|
||||
end
|
||||
if out_neg.error_flag
|
||||
warning('Occbin error.')
|
||||
return
|
||||
end
|
||||
zlin_neg = out_neg.linear;
|
||||
zpiece_neg = out_neg.piecewise;
|
||||
zlin_neg_diff = zlin_neg-zlin0;
|
||||
zpiece_neg_diff = zpiece_neg-zpiece0;
|
||||
end
|
||||
|
||||
% Save
|
||||
if ~isfield(oo_.occbin,'linear_irfs')
|
||||
oo_.occbin.linear_irfs = struct();
|
||||
end
|
||||
if ~isfield(oo_.occbin,'irfs')
|
||||
oo_.occbin.irfs = struct();
|
||||
end
|
||||
|
||||
for jendo=1:M_.endo_nbr
|
||||
% oo_.occbin.irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '1']) = zpiece_pos (:,jendo);
|
||||
% oo_.occbin.irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_1']) = zpiece_neg (:,jendo);
|
||||
% oo_.occbin.linear_irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '1']) = zlin_pos (:,jendo);
|
||||
% oo_.occbin.linear_irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_1']) = zlin_neg(:,jendo);
|
||||
|
||||
if ismember('pos',shocksigns)
|
||||
oo_.occbin.irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_pos']) = zpiece_pos_diff (:,jendo);
|
||||
oo_.occbin.linear_irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_pos']) = zlin_pos_diff (:,jendo);
|
||||
end
|
||||
|
||||
if ismember('neg',shocksigns)
|
||||
oo_.occbin.irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_neg']) = zpiece_neg_diff (:,jendo);
|
||||
oo_.occbin.linear_irfs.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_neg']) = zlin_neg_diff (:,jendo);
|
||||
end
|
||||
|
||||
% %
|
||||
% oo_.occbin.irfs0.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '1']) = zpiece0(:,jendo);
|
||||
% oo_.occbin.linear_irfs0.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '1']) = zlin0(:,jendo);
|
||||
% oo_.occbin.irfs0.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_1']) = zpiece0(:,jendo);
|
||||
% oo_.occbin.linear_irfs0.([M_.endo_names{jendo} '_' M_.exo_names{jexo} '_1']) = zlin0(:,jendo);
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
function plot_irfs(M_,oo_,options_,irf3,irf4)
|
||||
|
||||
shocknames = options_.occbin.plot_irf.exo_names;
|
||||
simulname = options_.occbin.plot_irf.simulname;
|
||||
if isempty(simulname)
|
||||
simulname_ = simulname;
|
||||
else
|
||||
simulname_ = [ simulname '_' ];
|
||||
end
|
||||
vars_irf = options_.occbin.plot_irf.endo_names;
|
||||
endo_names_long = options_.occbin.plot_irf.endo_names_long;
|
||||
endo_scaling_factor = options_.occbin.plot_irf.endo_scaling_factor;
|
||||
length_irf = options_.occbin.plot_irf.tplot;
|
||||
if isempty(length_irf)
|
||||
length_irf = options_.irf;
|
||||
end
|
||||
|
||||
irflocation_lin = oo_.occbin.linear_irfs;
|
||||
irflocation_piece = oo_.occbin.irfs;
|
||||
|
||||
|
||||
steps_irf = 1;
|
||||
warning('off','all')
|
||||
|
||||
DirectoryName = CheckPath('graphs',M_.dname);
|
||||
|
||||
iexo=[];
|
||||
for i=1:size(shocknames,1)
|
||||
itemp = strmatch(shocknames{i},M_.exo_names,'exact');
|
||||
if isempty(itemp)
|
||||
error(['Shock ',shocknames{i},' is not defined!'])
|
||||
else
|
||||
iexo=[iexo, itemp];
|
||||
end
|
||||
end
|
||||
|
||||
ncols = options_.occbin.plot_irf.ncols;
|
||||
nrows = options_.occbin.plot_irf.nrows;
|
||||
npan = ncols*nrows;
|
||||
|
||||
plot_grid = options_.occbin.plot_irf.grid;
|
||||
shocksigns = options_.occbin.plot_irf.shocksigns;
|
||||
threshold = options_.occbin.plot_irf.threshold;
|
||||
|
||||
% Add steady_state
|
||||
if options_.occbin.plot_irf.add_steadystate
|
||||
add_stst = options_.occbin.plot_irf.add_steadystate;
|
||||
else
|
||||
add_stst = 0;
|
||||
end
|
||||
for sss = 1:numel(shocksigns)
|
||||
|
||||
shocksign = shocksigns{sss};
|
||||
|
||||
for j=1:size(shocknames,1)
|
||||
%shocknames = M_.exo_names{j};
|
||||
|
||||
j1 = 0;
|
||||
isub = 0;
|
||||
ifig = 0;
|
||||
|
||||
% Variables
|
||||
% ----------------------
|
||||
for i = 1:length(vars_irf)
|
||||
|
||||
j1=j1+1;
|
||||
if mod(j1,npan)==1
|
||||
% vector corresponds to [left bottom width height]. 680 and 678 for the left and bottom elements correspond to the default values used by MATLAB while creating a figure and width, .
|
||||
hfig = dyn_figure(options_.nodisplay,'name',['OccbinIRFs ' shocknames{j} ' ' simulname ' ' shocksign],'PaperPositionMode', 'auto','PaperType','A4','PaperOrientation','portrait','renderermode','auto','position',[10 10 950 650]);
|
||||
ifig=ifig+1;
|
||||
isub=0;
|
||||
end
|
||||
isub=isub+1;
|
||||
|
||||
if isempty(endo_scaling_factor)
|
||||
exofactor = 1;
|
||||
else
|
||||
exofactor = endo_scaling_factor{i};
|
||||
end
|
||||
|
||||
subplot(nrows,ncols,isub)
|
||||
irf_field = strcat(vars_irf{i,1},'_',shocknames{j},'_',shocksign);
|
||||
|
||||
irfvalues = irflocation_lin.(irf_field);
|
||||
if add_stst
|
||||
irfvalues = irfvalues + get_mean(vars_irf{i,1});
|
||||
end
|
||||
|
||||
irfvalues(abs(irfvalues) <threshold) = 0;
|
||||
|
||||
plot(irfvalues(1:steps_irf:length_irf)*exofactor,'linewidth',2);
|
||||
hold on
|
||||
|
||||
irfvalues = irflocation_piece.(irf_field);
|
||||
if add_stst
|
||||
irfvalues = irfvalues + get_mean(vars_irf{i,1});
|
||||
end
|
||||
irfvalues(abs(irfvalues) <threshold) = 0;
|
||||
plot(irfvalues(1:steps_irf:length_irf)*exofactor,'r--','linewidth',2);
|
||||
|
||||
hold on
|
||||
plot(irfvalues(1:steps_irf:length_irf)*0,'k-','linewidth',1.5);
|
||||
% Optional additional IRFs
|
||||
if nargin > 10
|
||||
irfvalues = irf3.(irf_field) ;
|
||||
irfvalues(abs(irfvalues) <threshold) = 0;
|
||||
plot(irfvalues(1:steps_irf:length_irf)*exofactor,'k:','linewidth',2);
|
||||
end
|
||||
if nargin > 11
|
||||
irfvalues = irf4.(irf_field) ;
|
||||
irfvalues(abs(irfvalues) <threshold) = 0;
|
||||
plot(irfvalues(1:steps_irf:length_irf)*exofactor,'g-.','linewidth',2);
|
||||
end
|
||||
|
||||
|
||||
if plot_grid
|
||||
grid on
|
||||
end
|
||||
|
||||
xlim([1 (length_irf/steps_irf)]);
|
||||
|
||||
% title
|
||||
if isempty(endo_names_long)
|
||||
title(regexprep(vars_irf{i},'_',' '))
|
||||
else
|
||||
title(endo_names_long{i})
|
||||
end
|
||||
|
||||
% Annotation Box + save figure
|
||||
% ----------------------
|
||||
if mod(j1,npan)==0 || (mod(j1,npan)~=0 && i==length(vars_irf))
|
||||
annotation('textbox', [0.1,0,0.35,0.05],'String', 'Linear','Color','Blue','horizontalalignment','center','interpreter','none');
|
||||
annotation('textbox', [0.55,0,0.35,0.05],'String', 'Piecewise','Color','Red','horizontalalignment','center','interpreter','none');
|
||||
dyn_saveas(hfig,[DirectoryName,filesep,M_.fname,'_irf_occbin_',simulname_,shocknames{j},'_',shocksign,'_',int2str(ifig)],options_.nodisplay,options_.graph_format);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
warning('on','all')
|
||||
end
|
|
@ -0,0 +1,47 @@
|
|||
function plot_regimes(regimes,M_,options_)
|
||||
|
||||
nperiods = size(regimes,2);
|
||||
nconstr = length(fieldnames(regimes(1)))/2;
|
||||
if nconstr ==1
|
||||
regime(1) = {'regime'};
|
||||
regimestart(1) = {'regimestart'};
|
||||
else
|
||||
regime(1) = {'regime1'};
|
||||
regimestart(1) = {'regimestart1'};
|
||||
regime(2) = {'regime2'};
|
||||
regimestart(2) = {'regimestart2'};
|
||||
end
|
||||
|
||||
GraphDirectoryName = CheckPath('graphs',M_.dname);
|
||||
|
||||
fhandle = dyn_figure(options_.nodisplay,'Name',[M_.fname ' occbin regimes']);
|
||||
|
||||
|
||||
for k=1:nconstr
|
||||
subplot(nconstr,1,k)
|
||||
for t=1:nperiods
|
||||
nregimes_in_t = length(regimes(t).(regime{k}));
|
||||
start_periods = regimes(t).(regimestart{k});
|
||||
start_periods = [start_periods max(start_periods)];
|
||||
for r=1:nregimes_in_t
|
||||
isconstrained = regimes(t).(regime{k})(r);
|
||||
if isconstrained
|
||||
plot(t,start_periods(r),'*r')
|
||||
hold all,
|
||||
plot([t t],start_periods(r:r+1),'-r')
|
||||
else
|
||||
plot(t,start_periods(r),'ob')
|
||||
hold all,
|
||||
plot([t t],start_periods(r:r+1),'-b')
|
||||
end
|
||||
end
|
||||
end
|
||||
title(['regime ' int2str(k)])
|
||||
xlabel('historic period')
|
||||
ylabel('regime expected start')
|
||||
end
|
||||
annotation('textbox',[.25,0,.15,.05],'String','Unbinding','Color','blue');
|
||||
annotation('textbox',[.65,0,.15,.05],'String','Binding','Color','red');
|
||||
|
||||
|
||||
dyn_saveas(fhandle,[GraphDirectoryName, filesep, M_.fname '_occbin_regimes'],options_.nodisplay,options_.graph_format);
|
|
@ -46,23 +46,26 @@ if ismember(flag,{'filter','all'})
|
|||
end
|
||||
|
||||
if ismember(flag,{'forecast','all'})
|
||||
options_occbin_.forecast.check_ahead_periods=30;
|
||||
options_occbin_.forecast.debug_flag=false;
|
||||
options_occbin_.forecast.frcst_regimes=[];
|
||||
options_occbin_.forecast.maxit=30;
|
||||
options_occbin_.forecast.periods=30;
|
||||
options_occbin_.forecast.qmc=0;
|
||||
options_occbin_.forecast.replic=0;
|
||||
options_occbin_.forecast.sepath=0;
|
||||
options_occbin_.forecast.SHOCKS0=[];
|
||||
options_occbin_.forecast.treepath=1; % number of branches
|
||||
end
|
||||
|
||||
if ismember(flag,{'irf','all'})
|
||||
if ismember(flag,{'irf','all'})
|
||||
options_occbin_.irf.check_ahead_periods=30;
|
||||
options_occbin_.irf.exo_names=M_.exo_names;
|
||||
options_occbin_.irf.init_regime=[];
|
||||
options_occbin_.irf.maxit=30;
|
||||
options_occbin_.irf.threshold = 10^-6;
|
||||
% options_occbin_.irf.periods=options_.irf;
|
||||
options_occbin_.irf.shocksize=[];
|
||||
options_occbin_.irf.shocksigns = {'1','_1'};
|
||||
options_occbin_.irf.shocksigns = {'pos','neg'};
|
||||
options_occbin_.irf.t0=0;
|
||||
end
|
||||
|
||||
if ismember(flag,{'likelihood','all'})
|
||||
|
@ -87,6 +90,21 @@ if ismember(flag,{'likelihood','all'})
|
|||
options_occbin_.likelihood.waitbar=false;
|
||||
end
|
||||
|
||||
if ismember(flag,{'plot_irf','all'})
|
||||
options_occbin_.plot_irf.add_steadystate = 0;
|
||||
options_occbin_.plot_irf.exo_names = [];
|
||||
options_occbin_.plot_irf.endo_names = M_.endo_names;
|
||||
options_occbin_.plot_irf.endo_names_long = [];
|
||||
options_occbin_.plot_irf.endo_scaling_factor = [];
|
||||
options_occbin_.plot_irf.grid = true;
|
||||
options_occbin_.plot_irf.ncols = 3;
|
||||
options_occbin_.plot_irf.nrows = 3;
|
||||
options_occbin_.plot_irf.shocksigns = {'pos','neg'};
|
||||
options_occbin_.plot_irf.simulname='';
|
||||
options_occbin_.plot_irf.threshold = 10^-6;
|
||||
options_occbin_.plot_irf.tplot = [];
|
||||
end
|
||||
|
||||
if ismember(flag,{'plot_shock_decomp','all'})
|
||||
options_occbin_.plot_shock_decomp.add_steadystate = false;
|
||||
options_occbin_.plot_shock_decomp.add_zero_line = false;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
function [oo_,options_] = squeeze_shock_decomposition(M_,oo_,options_, sd_vlist)
|
||||
|
||||
if isstruct(options_.plot_shock_decomp.q2a)
|
||||
|
||||
avname=char({options_.plot_shock_decomp.q2a.qname});
|
||||
sda = options_.plot_shock_decomp.q2a(ismember(avname,sd_vlist,'rows'));
|
||||
for k=1:length(sda)
|
||||
if isstruct(sda(k).aux)
|
||||
sd_vlist = [sd_vlist; cellstr(sda(k).aux.y)];
|
||||
end
|
||||
end
|
||||
end
|
||||
i_var = varlist_indices(sd_vlist,M_.endo_names);
|
||||
sd_vlist = M_.endo_names(i_var);
|
||||
% first we squeeze usual fields
|
||||
oo_ = squeeze_shock_decomposition(M_,oo_,options_,sd_vlist);
|
||||
i_var = oo_.shock_decomposition_info.i_var;
|
||||
sd_vlist = M_.endo_names(i_var);
|
||||
|
||||
% now we check for occbin SDs
|
||||
options_.occbin.shock_decomp.i_var = i_var;
|
||||
if isfield (oo_.occbin.smoother,'decomp')
|
||||
oo_.occbin.smoother.decomp = oo_.occbin.smoother.decomp(i_var,:,:);
|
||||
oo_.occbin.smoother.wdecomp = oo_.occbin.smoother.wdecomp(i_var,:,:);
|
||||
end
|
||||
|
||||
if isfield(oo_.occbin,'shock_decomp')
|
||||
fnames = fieldnames(oo_.occbin.shock_decomp);
|
||||
for k=1:length(fnames)
|
||||
nendo = numel(oo_.occbin.shock_decomp.(fnames{k}).vname);
|
||||
tmp_i_var = varlist_indices(sd_vlist,char(oo_.occbin.shock_decomp.(fnames{k}).vname));
|
||||
oo_.occbin.shock_decomp.(fnames{k}).vname = cellstr(sd_vlist);
|
||||
tmpnames = fieldnames(oo_.occbin.shock_decomp.(fnames{k}));
|
||||
for t=1:length(tmpnames)
|
||||
if size(oo_.occbin.shock_decomp.(fnames{k}).(tmpnames{t}),3)==nendo
|
||||
oo_.occbin.shock_decomp.(fnames{k}).(tmpnames{t})= oo_.occbin.shock_decomp.(fnames{k}).(tmpnames{t})(:,:,tmp_i_var);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -64,9 +64,9 @@ if ~options_.analytic_derivation
|
|||
loss = full(weights(:)'*vx(:));
|
||||
else
|
||||
totparam_nbr=length(i_params);
|
||||
oo_.dr.derivs = get_perturbation_params_derivs(M_, options_, [], oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, i_params, [], [], 0); %analytic derivatives of perturbation matrices
|
||||
oo_.dr.derivs = identification.get_perturbation_params_derivs(M_, options_, [], oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state, i_params, [], [], 0); %analytic derivatives of perturbation matrices
|
||||
|
||||
pruned_state_space = pruned_state_space_system(M_, options_, oo_.dr, i_var, 0, 0, 1);
|
||||
pruned_state_space = pruned_SS.pruned_state_space_system(M_, options_, oo_.dr, i_var, 0, 0, 1);
|
||||
vx = pruned_state_space.Var_y + pruned_state_space.E_y*pruned_state_space.E_y';
|
||||
dE_yy = pruned_state_space.dVar_y;
|
||||
for jp=1:length(i_params)
|
||||
|
|
|
@ -49,7 +49,7 @@ for i1=1:p
|
|||
for i4=i3:p
|
||||
for i5=i4:p
|
||||
for i6=i5:p
|
||||
idx = uperm([i6 i5 i4 i3 i2 i1]);
|
||||
idx = pruned_SS.uperm([i6 i5 i4 i3 i2 i1]);
|
||||
for r = 1:size(idx,1)
|
||||
ii1 = idx(r,1); ii2= idx(r,2); ii3=idx(r,3); ii4=idx(r,4); ii5=idx(r,5); ii6=idx(r,6);
|
||||
n = ii1 + (ii2-1)*p + (ii3-1)*p^2 + (ii4-1)*p^3 + (ii5-1)*p^4 + (ii6-1)*p^5;
|
||||
|
|
|
@ -14,7 +14,7 @@ function k = commutation(n, m, sparseflag)
|
|||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * get_perturbation_params_derivs.m (previously getH.m)
|
||||
% * get_identification_jacobians.m (previously getJJ.m)
|
||||
% * identification.get_jacobians.m (previously getJJ.m)
|
||||
% * pruned_state_space_system.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
|
@ -11,7 +11,7 @@ function [Dp,DpMPinv] = duplication(p)
|
|||
% DpMPinv: Moore-Penroze inverse of Dp
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * get_identification_jacobians.m (previously getJJ.m)
|
||||
% * identification.get_jacobians.m (previously getJJ.m)
|
||||
% =========================================================================
|
||||
% Copyright © 1997 Tom Minka <minka@microsoft.com>
|
||||
% Copyright © 2019 Dynare Team
|
|
@ -80,8 +80,8 @@ function pruned_state_space = pruned_state_space_system(M_, options_, dr, indy,
|
|||
% parameter Jacobian of E_y
|
||||
% -------------------------------------------------------------------------
|
||||
% This function is called by
|
||||
% * get_identification_jacobians.m
|
||||
% * identification_numerical_objective.m
|
||||
% * identification.get_jacobians.m
|
||||
% * identification.numerical_objective.m
|
||||
% -------------------------------------------------------------------------
|
||||
% This function calls
|
||||
% * allVL1.m
|
||||
|
@ -418,7 +418,7 @@ if order > 1
|
|||
hx_hu = kron(hx,hu);
|
||||
hu_hu = kron(hu,hu);
|
||||
I_xx = eye(x_nbr^2);
|
||||
K_x_x = commutation(x_nbr,x_nbr,1);
|
||||
K_x_x = pruned_SS.commutation(x_nbr,x_nbr,1);
|
||||
invIx_hx = (eye(x_nbr)-hx)\eye(x_nbr);
|
||||
|
||||
%Compute unique fourth order product moments of u, i.e. unique(E[kron(kron(kron(u,u),u),u)],'stable')
|
||||
|
@ -596,9 +596,9 @@ if order > 1
|
|||
if order > 2
|
||||
% Some common and useful objects for order > 2
|
||||
if isempty(K_u_xx)
|
||||
K_u_xx = commutation(u_nbr,x_nbr^2,1);
|
||||
K_u_ux = commutation(u_nbr,u_nbr*x_nbr,1);
|
||||
K_xx_x = commutation(x_nbr^2,x_nbr);
|
||||
K_u_xx = pruned_SS.commutation(u_nbr,x_nbr^2,1);
|
||||
K_u_ux = pruned_SS.commutation(u_nbr,u_nbr*x_nbr,1);
|
||||
K_xx_x = pruned_SS.commutation(x_nbr^2,x_nbr);
|
||||
end
|
||||
hx_hss2 = kron(hx,1/2*hss);
|
||||
hu_hss2 = kron(hu,1/2*hss);
|
||||
|
@ -627,7 +627,7 @@ if order > 1
|
|||
E_xf_xfxs = Var_z(id_z3_xf_xf, id_z2_xs ) + E_xfxf(:)*E_xs'; %this is E[kron(xf,xf)*xs']
|
||||
E_xf_xfxf_xf = Var_z(id_z3_xf_xf, id_z3_xf_xf) + E_xfxf(:)*E_xfxf(:)'; %this is E[kron(xf,xf)*kron(xf,xf)']
|
||||
E_xrdxf = reshape(invIxx_hx_hx*vec(...
|
||||
hxx*reshape( commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx'...
|
||||
hxx*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx'...
|
||||
+ hxu*kron(E_xs,E_uu)*hu'...
|
||||
+ 1/6*hxxx*reshape(E_xf_xfxf_xf,x_nbr^3,x_nbr)*hx'...
|
||||
+ 1/6*huuu*reshape(QPu*E_u_u_u_u,u_nbr^3,u_nbr)*hu'...
|
||||
|
@ -655,7 +655,7 @@ if order > 1
|
|||
dE_xf_xfxf_xf(:,:,jp2) = dVar_z(id_z3_xf_xf , id_z3_xf_xf , jp2) + vec(dE_xfxf(:,:,jp2))*E_xfxf(:)' + E_xfxf(:)*vec(dE_xfxf(:,:,jp2))';
|
||||
dE_xrdxf(:,:,jp2) = reshape(invIxx_hx_hx*vec(...
|
||||
dhx(:,:,jp2)*E_xrdxf*hx' + hx*E_xrdxf*dhx(:,:,jp2)'...
|
||||
+ dhxx(:,:,jp2)*reshape( commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx' + hxx*reshape( commutation(x_nbr^2,x_nbr,1)*vec(dE_xf_xfxs(:,:,jp2)), x_nbr^2,x_nbr)*hx' + hxx*reshape( commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*dhx(:,:,jp2)'...
|
||||
+ dhxx(:,:,jp2)*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*hx' + hxx*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*vec(dE_xf_xfxs(:,:,jp2)), x_nbr^2,x_nbr)*hx' + hxx*reshape( pruned_SS.commutation(x_nbr^2,x_nbr,1)*E_xf_xfxs(:), x_nbr^2,x_nbr)*dhx(:,:,jp2)'...
|
||||
+ dhxu(:,:,jp2)*kron(E_xs,E_uu)*hu' + hxu*kron(dE_xs(:,jp2),E_uu)*hu' + hxu*kron(E_xs,dE_uu(:,:,jp2))*hu' + hxu*kron(E_xs,E_uu)*dhu(:,:,jp2)'...
|
||||
+ 1/6*dhxxx(:,:,jp2)*reshape(E_xf_xfxf_xf,x_nbr^3,x_nbr)*hx' + 1/6*hxxx*reshape(dE_xf_xfxf_xf(:,:,jp2),x_nbr^3,x_nbr)*hx' + 1/6*hxxx*reshape(E_xf_xfxf_xf,x_nbr^3,x_nbr)*dhx(:,:,jp2)'...
|
||||
+ 1/6*dhuuu(:,:,jp2)*reshape(QPu*E_u_u_u_u,u_nbr^3,u_nbr)*hu' + 1/6*huuu*reshape(dE_u_u_u_u_jp2,u_nbr^3,u_nbr)*hu' + 1/6*huuu*reshape(QPu*E_u_u_u_u,u_nbr^3,u_nbr)*dhu(:,:,jp2)'...
|
|
@ -49,7 +49,7 @@ for l=1:p
|
|||
for k=l:p
|
||||
for j=k:p
|
||||
for i=j:p
|
||||
idx = uperm([i j k l]);
|
||||
idx = pruned_SS.uperm([i j k l]);
|
||||
for r = 1:size(idx,1)
|
||||
ii = idx(r,1); jj= idx(r,2); kk=idx(r,3); ll=idx(r,4);
|
||||
n = ii + (jj-1)*p + (kk-1)*p^2 + (ll-1)*p^3;
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
function p = uperm(a)
|
||||
% Return all unique permutations of possibly-repeating array elements
|
||||
% =========================================================================
|
||||
% Copyright © 2014 Bruno Luong <brunoluong@yahoo.com>
|
||||
% Copyright © 2020 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
% Original author: Bruno Luong <brunoluong@yahoo.com>, April 20, 2014
|
||||
% https://groups.google.com/d/msg/comp.soft-sys.matlab/yQKVPTYrv6Q/gw1MzNd9sYkJ
|
||||
% https://stackoverflow.com/a/42810388
|
||||
|
||||
[u, ~, J] = unique(a);
|
||||
p = u(up(J, length(a)));
|
||||
|
||||
function p = up(J, n)
|
||||
ktab = histc(J,1:max(J));
|
||||
l = n;
|
||||
p = zeros(1, n);
|
||||
s = 1;
|
||||
for i=1:length(ktab)
|
||||
k = ktab(i);
|
||||
c = nchoosek(1:l, k);
|
||||
m = size(c,1);
|
||||
[t, ~] = find(~p.');
|
||||
t = reshape(t, [], s);
|
||||
c = t(c,:)';
|
||||
s = s*m;
|
||||
r = repmat((1:s)',[1 k]);
|
||||
q = accumarray([r(:) c(:)], i, [s n]);
|
||||
p = repmat(p, [m 1]) + q;
|
||||
l = l - k;
|
||||
end
|
||||
end
|
||||
|
||||
function p = uperm(a)
|
||||
% Return all unique permutations of possibly-repeating array elements
|
||||
% =========================================================================
|
||||
% Copyright © 2014 Bruno Luong <brunoluong@yahoo.com>
|
||||
% Copyright © 2020 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
% =========================================================================
|
||||
% Original author: Bruno Luong <brunoluong@yahoo.com>, April 20, 2014
|
||||
% https://groups.google.com/d/msg/comp.soft-sys.matlab/yQKVPTYrv6Q/gw1MzNd9sYkJ
|
||||
% https://stackoverflow.com/a/42810388
|
||||
|
||||
[u, ~, J] = unique(a);
|
||||
p = u(up(J, length(a)));
|
||||
|
||||
function p = up(J, n)
|
||||
ktab = histc(J,1:max(J));
|
||||
l = n;
|
||||
p = zeros(1, n);
|
||||
s = 1;
|
||||
for i=1:length(ktab)
|
||||
k = ktab(i);
|
||||
c = nchoosek(1:l, k);
|
||||
m = size(c,1);
|
||||
[t, ~] = find(~p.');
|
||||
t = reshape(t, [], s);
|
||||
c = t(c,:)';
|
||||
s = s*m;
|
||||
r = repmat((1:s)',[1 k]);
|
||||
q = accumarray([r(:) c(:)], i, [s n]);
|
||||
p = repmat(p, [m 1]) + q;
|
||||
l = l - k;
|
||||
end
|
||||
end
|
||||
|
||||
end % uperm
|
|
@ -0,0 +1,146 @@
|
|||
function b = admissible(o, d)
|
||||
|
||||
% Return true iff d is an admissible draw in a distribution characterized by o.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior] Distribution specification for a n×1 vector of independent continuous random variables
|
||||
% - d [double] n×1 vector.
|
||||
%
|
||||
% OUTPUTS
|
||||
% - b [logical] scalar.
|
||||
%
|
||||
% REMARKS
|
||||
% None.
|
||||
%
|
||||
% EXAMPLE
|
||||
%
|
||||
% >> Prior = dprior(bayestopt_, options_.prior_trunc);
|
||||
% >> d = Prior.draw()
|
||||
% >> Prior.admissible(d)
|
||||
% ans =
|
||||
%
|
||||
% logical
|
||||
%
|
||||
% 1
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
b = false;
|
||||
|
||||
if ~isequal(length(d), length(o.lb))
|
||||
return
|
||||
end
|
||||
|
||||
if all(d>=o.lb & d<=o.ub)
|
||||
b = true;
|
||||
end
|
||||
|
||||
return % --*-- Unit tests --*--
|
||||
|
||||
%@test:1
|
||||
% Fill global structures with required fields...
|
||||
prior_trunc = 1e-10;
|
||||
p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
|
||||
p1 = .4*ones(14,1); % Prior mean
|
||||
p2 = .2*ones(14,1); % Prior std.
|
||||
p3 = NaN(14,1);
|
||||
p4 = NaN(14,1);
|
||||
p5 = NaN(14,1);
|
||||
p6 = NaN(14,1);
|
||||
p7 = NaN(14,1);
|
||||
|
||||
for i=1:14
|
||||
switch p0(i)
|
||||
case 1
|
||||
% Beta distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = 1;
|
||||
[p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
|
||||
case 2
|
||||
% Gamma distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
|
||||
case 3
|
||||
% Normal distribution
|
||||
p3(i) = -Inf;
|
||||
p4(i) = Inf;
|
||||
p6(i) = p1(i);
|
||||
p7(i) = p2(i);
|
||||
p5(i) = p1(i);
|
||||
case 4
|
||||
% Inverse Gamma (type I) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
|
||||
case 5
|
||||
% Uniform distribution
|
||||
[p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
|
||||
p3(i) = p6(i);
|
||||
p4(i) = p7(i);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
|
||||
case 6
|
||||
% Inverse Gamma (type II) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
|
||||
case 8
|
||||
% Weibull distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
|
||||
otherwise
|
||||
error('This density is not implemented!')
|
||||
end
|
||||
end
|
||||
|
||||
BayesInfo.pshape = p0;
|
||||
BayesInfo.p1 = p1;
|
||||
BayesInfo.p2 = p2;
|
||||
BayesInfo.p3 = p3;
|
||||
BayesInfo.p4 = p4;
|
||||
BayesInfo.p5 = p5;
|
||||
BayesInfo.p6 = p6;
|
||||
BayesInfo.p7 = p7;
|
||||
|
||||
ndraws = 10;
|
||||
|
||||
% Call the tested routine
|
||||
try
|
||||
% Instantiate dprior object
|
||||
o = dprior(BayesInfo, prior_trunc, false);
|
||||
% Do simulations in a loop and estimate recursively the mean and the variance.
|
||||
for i = 1:ndraws
|
||||
draw = o.draw();
|
||||
if ~o.admissible(draw)
|
||||
error()
|
||||
end
|
||||
end
|
||||
t(1) = true;
|
||||
catch
|
||||
t(1) = false;
|
||||
end
|
||||
|
||||
T = all(t);
|
||||
|
||||
%@eof:1
|
|
@ -1,18 +1,15 @@
|
|||
function acf = dyn_autocorr(y, ar)
|
||||
% function acf = dyn_autocorr(y, ar)
|
||||
% autocorrelation function of y
|
||||
function lpd = densities(o, X)
|
||||
|
||||
% Evaluate the logged prior densities at X (for each column).
|
||||
%
|
||||
% INPUTS
|
||||
% y: time series
|
||||
% ar: # of lags
|
||||
% - o [dprior]
|
||||
% - X [double] m×n matrix, n points where the prior density is evaluated.
|
||||
%
|
||||
% OUTPUTS
|
||||
% acf: autocorrelation for lags 1 to ar
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% none
|
||||
% - lpd [double] 1×n, values of the logged prior density at X.
|
||||
|
||||
% Copyright © 2015-16 Dynare Team
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -29,12 +26,10 @@ function acf = dyn_autocorr(y, ar)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
n = columns(X);
|
||||
|
||||
y=y(:);
|
||||
acf = NaN(ar+1,1);
|
||||
acf(1)=1;
|
||||
m = mean(y);
|
||||
sd = std(y,1);
|
||||
for i=1:ar
|
||||
acf(i+1) = (y(i+1:end)-m)'*(y(1:end-i)-m)./((size(y,1))*sd^2);
|
||||
lpd = NaN(1, n);
|
||||
|
||||
parfor i=1:n
|
||||
lpd(i) = density(o, X(:,i));
|
||||
end
|
|
@ -0,0 +1,384 @@
|
|||
function [lpd, dlpd, d2lpd, info] = density(o, x)
|
||||
|
||||
% Evaluate the logged prior density at x.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
% - x [double] m×1 vector, point where the prior density is evaluated.
|
||||
%
|
||||
% OUTPUTS
|
||||
% - lpd [double] scalar, value of the logged prior density at x.
|
||||
% - dlpd [double] m×1 vector, first order derivatives.
|
||||
% - d2lpd [double] m×1 vector, second order derivatives.
|
||||
%
|
||||
% REMARKS
|
||||
% Second order derivatives holder, d2lpd, has the same rank and shape than dlpd because the priors are
|
||||
% independent (we would have to use a matrix if non orthogonal priors were allowed in Dynare).
|
||||
%
|
||||
% EXAMPLE
|
||||
%
|
||||
% >> Prior = dprior(bayestopt_, options_.prior_trunc);
|
||||
% >> lpd = Prior.dsensity(x)
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
lpd = 0.0;
|
||||
if nargout>1
|
||||
dlpd = zeros(1, length(x));
|
||||
if nargout>2
|
||||
d2lpd = dlpd;
|
||||
if nargout>3
|
||||
info = [];
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isuniform
|
||||
if any(x(o.iduniform)-o.p3(o.iduniform)<0) || any(x(o.iduniform)-o.p4(o.iduniform)>0)
|
||||
lpd = -Inf ;
|
||||
if nargout==4
|
||||
info = o.iduniform((x(o.iduniform)-o.p3(o.iduniform)<0) || (x(o.iduniform)-o.p4(o.iduniform)>0));
|
||||
end
|
||||
return
|
||||
end
|
||||
lpd = lpd - sum(log(o.p4(o.iduniform)-o.p3(o.iduniform))) ;
|
||||
if nargout>1
|
||||
dlpd(o.iduniform) = zeros(length(o.iduniform), 1);
|
||||
if nargout>2
|
||||
d2lpd(o.iduniform) = zeros(length(o.iduniform), 1);
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isgaussian
|
||||
switch nargout
|
||||
case 1
|
||||
lpd = lpd + sum(lpdfnorm(x(o.idgaussian), o.p6(o.idgaussian), o.p7(o.idgaussian)));
|
||||
case 2
|
||||
[tmp, dlpd(o.idgaussian)] = lpdfnorm(x(o.idgaussian), o.p6(o.idgaussian), o.p7(o.idgaussian));
|
||||
lpd = lpd + sum(tmp);
|
||||
case {3,4}
|
||||
[tmp, dlpd(o.idgaussian), d2lpd(o.idgaussian)] = lpdfnorm(x(o.idgaussian), o.p6(o.idgaussian), o.p7(o.idgaussian));
|
||||
lpd = lpd + sum(tmp);
|
||||
end
|
||||
end
|
||||
if o.isgamma
|
||||
switch nargout
|
||||
case 1
|
||||
lpd = lpd + sum(lpdfgam(x(o.idgamma)-o.p3(o.idgamma), o.p6(o.idgamma), o.p7(o.idgamma)));
|
||||
if isinf(lpd), return, end
|
||||
case 2
|
||||
[tmp, dlpd(o.idgamma)] = lpdfgam(x(o.idgamma)-o.p3(o.idgamma), o.p6(o.idgamma), o.p7(o.idgamma));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 3
|
||||
[tmp, dlpd(o.idgamma), d2lpd(o.idgamma)] = lpdfgam(x(o.idgamma)-o.p3(o.idgamma), o.p6(o.idgamma), o.p7(o.idgamma));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 4
|
||||
[tmp, dlpd(o.idgamma), d2lpd(o.idgamma)] = lpdfgam(x(o.idgamma)-o.p3(o.idgamma), o.p6(o.idgamma), o.p7(o.idgamma));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd)
|
||||
info = o.idgamma(isinf(tmp));
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isbeta
|
||||
switch nargout
|
||||
case 1
|
||||
lpd = lpd + sum(lpdfgbeta(x(o.idbeta), o.p6(o.idbeta), o.p7(o.idbeta), o.p3(o.idbeta), o.p4(o.idbeta)));
|
||||
if isinf(lpd), return, end
|
||||
case 2
|
||||
[tmp, dlpd(o.idbeta)] = lpdfgbeta(x(o.idbeta), o.p6(o.idbeta), o.p7(o.idbeta), o.p3(o.idbeta), o.p4(o.idbeta));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 3
|
||||
[tmp, dlpd(o.idbeta), d2lpd(o.idbeta)] = lpdfgbeta(x(o.idbeta), o.p6(o.idbeta), o.p7(o.idbeta), o.p3(o.idbeta), o.p4(o.idbeta));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 4
|
||||
[tmp, dlpd(o.idbeta), d2lpd(o.idbeta)] = lpdfgbeta(x(o.idbeta), o.p6(o.idbeta), o.p7(o.idbeta), o.p3(o.idbeta), o.p4(o.idbeta));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd)
|
||||
info = o.idbeta(isinf(tmp));
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isinvgamma1
|
||||
switch nargout
|
||||
case 1
|
||||
lpd = lpd + sum(lpdfig1(x(o.idinvgamma1)-o.p3(o.idinvgamma1), o.p6(o.idinvgamma1), o.p7(o.idinvgamma1)));
|
||||
if isinf(lpd), return, end
|
||||
case 2
|
||||
[tmp, dlpd(o.idinvgamma1)] = lpdfig1(x(o.idinvgamma1)-o.p3(o.idinvgamma1), o.p6(o.idinvgamma1), o.p7(o.idinvgamma1));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 3
|
||||
[tmp, dlpd(o.idinvgamma1), d2lpd(o.idinvgamma1)] = lpdfig1(x(o.idinvgamma1)-o.p3(o.idinvgamma1), o.p6(o.idinvgamma1), o.p7(o.idinvgamma1));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 4
|
||||
[tmp, dlpd(o.idinvgamma1), d2lpd(o.idinvgamma1)] = lpdfig1(x(o.idinvgamma1)-o.p3(o.idinvgamma1), o.p6(o.idinvgamma1), o.p7(o.idinvgamma1));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd)
|
||||
info = o.idinvgamma1(isinf(tmp));
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isinvgamma2
|
||||
switch nargout
|
||||
case 1
|
||||
lpd = lpd + sum(lpdfig2(x(o.idinvgamma2)-o.p3(o.idinvgamma2), o.p6(o.idinvgamma2), o.p7(o.idinvgamma2)));
|
||||
if isinf(lpd), return, end
|
||||
case 2
|
||||
[tmp, dlpd(o.idinvgamma2)] = lpdfig2(x(o.idinvgamma2)-o.p3(o.idinvgamma2), o.p6(o.idinvgamma2), o.p7(o.idinvgamma2));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 3
|
||||
[tmp, dlpd(o.idinvgamma2), d2lpd(o.idinvgamma2)] = lpdfig2(x(o.idinvgamma2)-o.p3(o.idinvgamma2), o.p6(o.idinvgamma2), o.p7(o.idinvgamma2));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 4
|
||||
[tmp, dlpd(o.idinvgamma2), d2lpd(o.idinvgamma2)] = lpdfig2(x(o.idinvgamma2)-o.p3(o.idinvgamma2), o.p6(o.idinvgamma2), o.p7(o.idinvgamma2));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd)
|
||||
info = o.idinvgamma2(isinf(tmp));
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isweibull
|
||||
switch nargout
|
||||
case 1
|
||||
lpd = lpd + sum(lpdfgweibull(x(o.idweibull), o.p6(o.idweibull), o.p7(o.idweibull)));
|
||||
if isinf(lpd), return, end
|
||||
case 2
|
||||
[tmp, dlpd(o.idweibull)] = lpdfgweibull(x(o.idweibull), o.p6(o.idweibull), o.p7(o.idweibull));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 3
|
||||
[tmp, dlpd(o.idweibull), d2lpd(o.idweibull)] = lpdfgweibull(x(o.idweibull), o.p6(o.idweibull), o.p7(o.idweibull));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd), return, end
|
||||
case 4
|
||||
[tmp, dlpd(o.idweibull), d2lpd(o.idweibull)] = lpdfgweibull(x(o.idweibull), o.p6(o.idweibull), o.p7(o.idweibull));
|
||||
lpd = lpd + sum(tmp);
|
||||
if isinf(lpd)
|
||||
info = o.idweibull(isinf(tmp));
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return % --*-- Unit tests --*--
|
||||
|
||||
%@test:1
|
||||
% Fill global structures with required fields...
|
||||
prior_trunc = 1e-10;
|
||||
p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
|
||||
p1 = .4*ones(14,1); % Prior mean
|
||||
p2 = .2*ones(14,1); % Prior std.
|
||||
p3 = NaN(14,1);
|
||||
p4 = NaN(14,1);
|
||||
p5 = NaN(14,1);
|
||||
p6 = NaN(14,1);
|
||||
p7 = NaN(14,1);
|
||||
|
||||
for i=1:14
|
||||
switch p0(i)
|
||||
case 1
|
||||
% Beta distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = 1;
|
||||
[p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
|
||||
case 2
|
||||
% Gamma distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
|
||||
case 3
|
||||
% Normal distribution
|
||||
p3(i) = -Inf;
|
||||
p4(i) = Inf;
|
||||
p6(i) = p1(i);
|
||||
p7(i) = p2(i);
|
||||
p5(i) = p1(i);
|
||||
case 4
|
||||
% Inverse Gamma (type I) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
|
||||
case 5
|
||||
% Uniform distribution
|
||||
[p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
|
||||
p3(i) = p6(i);
|
||||
p4(i) = p7(i);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
|
||||
case 6
|
||||
% Inverse Gamma (type II) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
|
||||
case 8
|
||||
% Weibull distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
|
||||
otherwise
|
||||
error('This density is not implemented!')
|
||||
end
|
||||
end
|
||||
|
||||
BayesInfo.pshape = p0;
|
||||
BayesInfo.p1 = p1;
|
||||
BayesInfo.p2 = p2;
|
||||
BayesInfo.p3 = p3;
|
||||
BayesInfo.p4 = p4;
|
||||
BayesInfo.p5 = p5;
|
||||
BayesInfo.p6 = p6;
|
||||
BayesInfo.p7 = p7;
|
||||
|
||||
% Call the tested routine
|
||||
try
|
||||
Prior = dprior(BayesInfo, prior_trunc, false);
|
||||
|
||||
% Compute density at the prior mode
|
||||
lpdstar = Prior.density(p5);
|
||||
|
||||
% Draw random deviates in a loop and evaluate the density.
|
||||
LPD = NaN(10000,1);
|
||||
parfor i = 1:10000
|
||||
x = Prior.draw();
|
||||
LPD(i) = Prior.density(x);
|
||||
end
|
||||
t(1) = true;
|
||||
catch
|
||||
t(1) = false;
|
||||
end
|
||||
|
||||
if t(1)
|
||||
t(2) = all(LPD<=lpdstar);
|
||||
end
|
||||
T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
% Fill global structures with required fields...
|
||||
prior_trunc = 1e-10;
|
||||
p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
|
||||
p1 = .4*ones(14,1); % Prior mean
|
||||
p2 = .2*ones(14,1); % Prior std.
|
||||
p3 = NaN(14,1);
|
||||
p4 = NaN(14,1);
|
||||
p5 = NaN(14,1);
|
||||
p6 = NaN(14,1);
|
||||
p7 = NaN(14,1);
|
||||
|
||||
for i=1:14
|
||||
switch p0(i)
|
||||
case 1
|
||||
% Beta distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = 1;
|
||||
[p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
|
||||
case 2
|
||||
% Gamma distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
|
||||
case 3
|
||||
% Normal distribution
|
||||
p3(i) = -Inf;
|
||||
p4(i) = Inf;
|
||||
p6(i) = p1(i);
|
||||
p7(i) = p2(i);
|
||||
p5(i) = p1(i);
|
||||
case 4
|
||||
% Inverse Gamma (type I) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
|
||||
case 5
|
||||
% Uniform distribution
|
||||
[p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
|
||||
p3(i) = p6(i);
|
||||
p4(i) = p7(i);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
|
||||
case 6
|
||||
% Inverse Gamma (type II) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
|
||||
case 8
|
||||
% Weibull distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
|
||||
otherwise
|
||||
error('This density is not implemented!')
|
||||
end
|
||||
end
|
||||
|
||||
BayesInfo.pshape = p0;
|
||||
BayesInfo.p1 = p1;
|
||||
BayesInfo.p2 = p2;
|
||||
BayesInfo.p3 = p3;
|
||||
BayesInfo.p4 = p4;
|
||||
BayesInfo.p5 = p5;
|
||||
BayesInfo.p6 = p6;
|
||||
BayesInfo.p7 = p7;
|
||||
|
||||
% Call the tested routine
|
||||
try
|
||||
Prior = dprior(BayesInfo, prior_trunc, false);
|
||||
mu = NaN(14,1);
|
||||
std = NaN(14,1);
|
||||
|
||||
for i=1:14
|
||||
% Define conditional density (it's also a marginal since priors are orthogonal)
|
||||
f = @(x) exp(Prior.densities(substitute(p5, i, x)));
|
||||
% TODO: Check the version of Octave we use (integral is available as a compatibility wrapper in latest Octave version)
|
||||
m = integral(f, p3(i), p4(i));
|
||||
density = @(x) f(x)/m; % rescaling is required since the probability mass depends on the conditioning.
|
||||
% Compute the conditional expectation
|
||||
mu(i) = integral(@(x) x.*density(x), p3(i), p4(i));
|
||||
std(i) = sqrt(integral(@(x) ((x-mu(i)).^2).*density(x), p3(i), p4(i)));
|
||||
end
|
||||
|
||||
t(1) = true;
|
||||
catch
|
||||
t(1) = false;
|
||||
end
|
||||
|
||||
if t(1)
|
||||
t(2) = all(abs(mu-.4)<1e-6);
|
||||
t(3) = all(abs(std-.2)<1e-6);
|
||||
end
|
||||
T = all(t);
|
||||
%@eof:2
|
|
@ -1,26 +1,48 @@
|
|||
classdef dprior
|
||||
classdef dprior < handle
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
properties
|
||||
p6 = []; % Prior first hyperparameter.
|
||||
p7 = []; % Prior second hyperparameter.
|
||||
p1 = []; % Prior mean.
|
||||
p2 = []; % Prior stddev.
|
||||
p3 = []; % Lower bound of the prior support.
|
||||
p4 = []; % Upper bound of the prior support.
|
||||
p5 = []; % Prior mode.
|
||||
p6 = []; % Prior first hyperparameter.
|
||||
p7 = []; % Prior second hyperparameter.
|
||||
p11 = []; % Prior median
|
||||
lb = []; % Truncated prior lower bound.
|
||||
ub = []; % Truncated prior upper bound.
|
||||
uniform_index = []; % Index for the uniform priors.
|
||||
gaussian_index = []; % Index for the gaussian priors.
|
||||
gamma_index = []; % Index for the gamma priors.
|
||||
beta_index = []; % Index for the beta priors.
|
||||
inverse_gamma_1_index = []; % Index for the inverse gamma type 1 priors.
|
||||
inverse_gamma_2_index = []; % Index for the inverse gamma type 2 priors.
|
||||
weibull_index = []; % Index for the weibull priors.
|
||||
uniform_draws = false;
|
||||
gaussian_draws = false;
|
||||
gamma_draws = false;
|
||||
beta_draws = false;
|
||||
inverse_gamma_1_draws = false;
|
||||
inverse_gamma_2_draws = false;
|
||||
weibull_draws = false;
|
||||
name = {}; % Name of the parameter
|
||||
iduniform = []; % Index for the uniform priors.
|
||||
idgaussian = []; % Index for the gaussian priors.
|
||||
idgamma = []; % Index for the gamma priors.
|
||||
idbeta = []; % Index for the beta priors.
|
||||
idinvgamma1 = []; % Index for the inverse gamma type 1 priors.
|
||||
idinvgamma2 = []; % Index for the inverse gamma type 2 priors.
|
||||
idweibull = []; % Index for the weibull priors.
|
||||
isuniform = false;
|
||||
isgaussian = false;
|
||||
isgamma = false;
|
||||
isbeta = false;
|
||||
isinvgamma1 = false;
|
||||
isinvgamma2 = false;
|
||||
isweibull = false;
|
||||
end
|
||||
|
||||
methods
|
||||
|
@ -38,10 +60,17 @@ classdef dprior
|
|||
%
|
||||
% REQUIREMENTS
|
||||
% None.
|
||||
o.p6 = bayestopt_.p6;
|
||||
o.p7 = bayestopt_.p7;
|
||||
o.p3 = bayestopt_.p3;
|
||||
o.p4 = bayestopt_.p4;
|
||||
if ~nargin % Empty object
|
||||
return
|
||||
end
|
||||
if isfield(bayestopt_, 'p1'), o.p1 = bayestopt_.p1; end
|
||||
if isfield(bayestopt_, 'p2'), o.p2 = bayestopt_.p2; end
|
||||
if isfield(bayestopt_, 'p3'), o.p3 = bayestopt_.p3; end
|
||||
if isfield(bayestopt_, 'p4'), o.p4 = bayestopt_.p4; end
|
||||
if isfield(bayestopt_, 'p5'), o.p5 = bayestopt_.p5; end
|
||||
if isfield(bayestopt_, 'p6'), o.p6 = bayestopt_.p6; end
|
||||
if isfield(bayestopt_, 'p7'), o.p7 = bayestopt_.p7; end
|
||||
if isfield(bayestopt_, 'p11'), o.p11 = bayestopt_.p11; end
|
||||
bounds = prior_bounds(bayestopt_, PriorTrunc);
|
||||
o.lb = bounds.lb;
|
||||
o.ub = bounds.ub;
|
||||
|
@ -50,138 +79,38 @@ classdef dprior
|
|||
else
|
||||
prior_shape = bayestopt_.pshape;
|
||||
end
|
||||
o.beta_index = find(prior_shape==1);
|
||||
if ~isempty(o.beta_index)
|
||||
o.beta_draws = true;
|
||||
o.idbeta = find(prior_shape==1);
|
||||
if ~isempty(o.idbeta)
|
||||
o.isbeta = true;
|
||||
end
|
||||
o.gamma_index = find(prior_shape==2);
|
||||
if ~isempty(o.gamma_index)
|
||||
o.gamma_draws = true;
|
||||
o.idgamma = find(prior_shape==2);
|
||||
if ~isempty(o.idgamma)
|
||||
o.isgamma = true;
|
||||
end
|
||||
o.gaussian_index = find(prior_shape==3);
|
||||
if ~isempty(o.gaussian_index)
|
||||
o.gaussian_draws = true;
|
||||
o.idgaussian = find(prior_shape==3);
|
||||
if ~isempty(o.idgaussian)
|
||||
o.isgaussian = true;
|
||||
end
|
||||
o.inverse_gamma_1_index = find(prior_shape==4);
|
||||
if ~isempty(o.inverse_gamma_1_index)
|
||||
o.inverse_gamma_1_draws = true;
|
||||
o.idinvgamma1 = find(prior_shape==4);
|
||||
if ~isempty(o.idinvgamma1)
|
||||
o.isinvgamma1 = true;
|
||||
end
|
||||
o.uniform_index = find(prior_shape==5);
|
||||
if ~isempty(o.uniform_index)
|
||||
o.uniform_draws = true;
|
||||
o.iduniform = find(prior_shape==5);
|
||||
if ~isempty(o.iduniform)
|
||||
o.isuniform = true;
|
||||
end
|
||||
o.inverse_gamma_2_index = find(prior_shape==6);
|
||||
if ~isempty(o.inverse_gamma_2_index)
|
||||
o.inverse_gamma_2_draws = true;
|
||||
o.idinvgamma2 = find(prior_shape==6);
|
||||
if ~isempty(o.idinvgamma2)
|
||||
o.isinvgamma2 = true;
|
||||
end
|
||||
o.weibull_index = find(prior_shape==8);
|
||||
if ~isempty(o.weibull_index)
|
||||
o.weibull_draws = true;
|
||||
o.idweibull = find(prior_shape==8);
|
||||
if ~isempty(o.idweibull)
|
||||
o.isweibull = true;
|
||||
end
|
||||
end
|
||||
|
||||
function p = draw(o)
|
||||
% Return a random draw from the prior distribution.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
%
|
||||
% OUTPUTS
|
||||
% - p [double] m×1 vector, random draw from the prior distribution (m is the number of estimated parameters).
|
||||
%
|
||||
% REMARKS
|
||||
% None.
|
||||
%
|
||||
% EXAMPLE
|
||||
%
|
||||
% >> Prior = dprior(bayestopt_, options_.prior_trunc);
|
||||
% >> d = Prior.draw()
|
||||
p = NaN(rows(o.lb), 1);
|
||||
if o.uniform_draws
|
||||
p(o.uniform_index) = rand(length(o.uniform_index),1).*(o.p4(o.uniform_index)-o.p3(o.uniform_index)) + o.p3(o.uniform_index);
|
||||
out_of_bound = find( (p(o.uniform_index)>o.ub(o.uniform_index)) | (p(o.uniform_index)<o.lb(o.uniform_index)));
|
||||
while ~isempty(out_of_bound)
|
||||
p(o.uniform_index) = rand(length(o.uniform_index), 1).*(o.p4(o.uniform_index)-o.p3(o.uniform_index)) + o.p3(o.uniform_index);
|
||||
out_of_bound = find( (p(o.uniform_index)>o.ub(o.uniform_index)) | (p(o.uniform_index)<o.lb(o.uniform_index)));
|
||||
end
|
||||
end
|
||||
if o.gaussian_draws
|
||||
p(o.gaussian_index) = randn(length(o.gaussian_index), 1).*o.p7(o.gaussian_index) + o.p6(o.gaussian_index);
|
||||
out_of_bound = find( (p(o.gaussian_index)>o.ub(o.gaussian_index)) | (p(o.gaussian_index)<o.lb(o.gaussian_index)));
|
||||
while ~isempty(out_of_bound)
|
||||
p(o.gaussian_index(out_of_bound)) = randn(length(o.gaussian_index(out_of_bound)), 1).*o.p7(o.gaussian_index(out_of_bound)) + o.p6(o.gaussian_index(out_of_bound));
|
||||
out_of_bound = find( (p(o.gaussian_index)>o.ub(o.gaussian_index)) | (p(o.gaussian_index)<o.lb(o.gaussian_index)));
|
||||
end
|
||||
end
|
||||
if o.gamma_draws
|
||||
p(o.gamma_index) = gamrnd(o.p6(o.gamma_index), o.p7(o.gamma_index))+o.p3(o.gamma_index);
|
||||
out_of_bound = find( (p(o.gamma_index)>o.ub(o.gamma_index)) | (p(o.gamma_index)<o.lb(o.gamma_index)));
|
||||
while ~isempty(out_of_bound)
|
||||
p(o.gamma_index(out_of_bound)) = gamrnd(o.p6(o.gamma_index(out_of_bound)), o.p7(o.gamma_index(out_of_bound)))+o.p3(o.gamma_index(out_of_bound));
|
||||
out_of_bound = find( (p(o.gamma_index)>o.ub(o.gamma_index)) | (p(o.gamma_index)<o.lb(o.gamma_index)));
|
||||
end
|
||||
end
|
||||
if o.beta_draws
|
||||
p(o.beta_index) = (o.p4(o.beta_index)-o.p3(o.beta_index)).*betarnd(o.p6(o.beta_index), o.p7(o.beta_index))+o.p3(o.beta_index);
|
||||
out_of_bound = find( (p(o.beta_index)>o.ub(o.beta_index)) | (p(o.beta_index)<o.lb(o.beta_index)));
|
||||
while ~isempty(out_of_bound)
|
||||
p(o.beta_index(out_of_bound)) = (o.p4(o.beta_index(out_of_bound))-o.p3(o.beta_index(out_of_bound))).*betarnd(o.p6(o.beta_index(out_of_bound)), o.p7(o.beta_index(out_of_bound)))+o.p3(o.beta_index(out_of_bound));
|
||||
out_of_bound = find( (p(o.beta_index)>o.ub(o.beta_index)) | (p(o.beta_index)<o.lb(o.beta_index)));
|
||||
end
|
||||
end
|
||||
if o.inverse_gamma_1_draws
|
||||
p(o.inverse_gamma_1_index) = ...
|
||||
sqrt(1./gamrnd(o.p7(o.inverse_gamma_1_index)/2, 2./o.p6(o.inverse_gamma_1_index)))+o.p3(o.inverse_gamma_1_index);
|
||||
out_of_bound = find( (p(o.inverse_gamma_1_index)>o.ub(o.inverse_gamma_1_index)) | (p(o.inverse_gamma_1_index)<o.lb(o.inverse_gamma_1_index)));
|
||||
while ~isempty(out_of_bound)
|
||||
p(o.inverse_gamma_1_index(out_of_bound)) = ...
|
||||
sqrt(1./gamrnd(o.p7(o.inverse_gamma_1_index(out_of_bound))/2, 2./o.p6(o.inverse_gamma_1_index(out_of_bound))))+o.p3(o.inverse_gamma_1_index(out_of_bound));
|
||||
out_of_bound = find( (p(o.inverse_gamma_1_index)>o.ub(o.inverse_gamma_1_index)) | (p(o.inverse_gamma_1_index)<o.lb(o.inverse_gamma_1_index)));
|
||||
end
|
||||
end
|
||||
if o.inverse_gamma_2_draws
|
||||
p(o.inverse_gamma_2_index) = ...
|
||||
1./gamrnd(o.p7(o.inverse_gamma_2_index)/2, 2./o.p6(o.inverse_gamma_2_index))+o.p3(o.inverse_gamma_2_index);
|
||||
out_of_bound = find( (p(o.inverse_gamma_2_index)>o.ub(o.inverse_gamma_2_index)) | (p(o.inverse_gamma_2_index)<o.lb(o.inverse_gamma_2_index)));
|
||||
while ~isempty(out_of_bound)
|
||||
p(o.inverse_gamma_2_index(out_of_bound)) = ...
|
||||
1./gamrnd(o.p7(o.inverse_gamma_2_index(out_of_bound))/2, 2./o.p6(o.inverse_gamma_2_index(out_of_bound)))+o.p3(o.inverse_gamma_2_index(out_of_bound));
|
||||
out_of_bound = find( (p(o.inverse_gamma_2_index)>o.ub(o.inverse_gamma_2_index)) | (p(o.inverse_gamma_2_index)<o.lb(o.inverse_gamma_2_index)));
|
||||
end
|
||||
end
|
||||
if o.weibull_draws
|
||||
p(o.weibull_index) = wblrnd(o.p7(o.weibull_index), o.p6(o.weibull_index)) + o.p3(o.weibull_index);
|
||||
out_of_bound = find( (p(o.weibull_index)>o.ub(o.weibull_index)) | (p(o.weibull_index)<o.lb(o.weibull_index)));
|
||||
while ~isempty(out_of_bound)
|
||||
p(o.weibull_index(out_of_bound)) = wblrnd(o.p7(o.weibull_index(out_of_bound)), o.p6(o.weibull_index(out_of_bound)))+o.p3(o.weibull_index(out_of_bound));
|
||||
out_of_bound = find( (p(o.weibull_index)>o.ub(o.weibull_index)) | (p(o.weibull_index)<o.lb(o.weibull_index)));
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function P = draws(o, n)
|
||||
% Return n independent random draws from the prior distribution.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
%
|
||||
% OUTPUTS
|
||||
% - P [double] m×n matrix, random draw from the prior distribution.
|
||||
%
|
||||
% REMARKS
|
||||
% If the Parallel Computing Toolbox is available, the main loop is run in parallel.
|
||||
%
|
||||
% EXAMPLE
|
||||
%
|
||||
% >> Prior = dprior(bayestopt_, options_.prior_trunc);
|
||||
% >> Prior.draws(1e6)
|
||||
P = NaN(rows(o.lb), 1);
|
||||
parfor i=1:n
|
||||
P(:,i) = draw(o);
|
||||
end
|
||||
end
|
||||
end % dprior (constructor)
|
||||
|
||||
end % methods
|
||||
|
||||
end % classdef --*-- Unit tests --*--
|
||||
|
||||
%@test:1
|
||||
|
@ -263,114 +192,22 @@ end % classdef --*-- Unit tests --*--
|
|||
%$ try
|
||||
%$ % Instantiate dprior object
|
||||
%$ o = dprior(bayestopt_, prior_trunc, false);
|
||||
%$ % Do simulations in a loop and estimate recursively the mean and the variance.
|
||||
%$ for i = 1:ndraws
|
||||
%$ draw = o.draw();
|
||||
%$ m1 = m0 + (draw-m0)/i;
|
||||
%$ m2 = m1*m1';
|
||||
%$ v0 = v0 + ((draw*draw'-m2-v0) + (i-1)*(m0*m0'-m2'))/i;
|
||||
%$ m0 = m1;
|
||||
%$ end
|
||||
%$ t(1) = true;
|
||||
%$ catch
|
||||
%$ t(1) = false;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = all(abs(m0-bayestopt_.p1)<3e-3);
|
||||
%$ t(3) = all(all(abs(v0-diag(bayestopt_.p2.^2))<5e-3));
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Fill global structures with required fields...
|
||||
%$ prior_trunc = 1e-10;
|
||||
%$ p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
|
||||
%$ p1 = .4*ones(14,1); % Prior mean
|
||||
%$ p2 = .2*ones(14,1); % Prior std.
|
||||
%$ p3 = NaN(14,1);
|
||||
%$ p4 = NaN(14,1);
|
||||
%$ p5 = NaN(14,1);
|
||||
%$ p6 = NaN(14,1);
|
||||
%$ p7 = NaN(14,1);
|
||||
%$
|
||||
%$ for i=1:14
|
||||
%$ switch p0(i)
|
||||
%$ case 1
|
||||
%$ % Beta distribution
|
||||
%$ p3(i) = 0;
|
||||
%$ p4(i) = 1;
|
||||
%$ [p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
|
||||
%$ case 2
|
||||
%$ % Gamma distribution
|
||||
%$ p3(i) = 0;
|
||||
%$ p4(i) = Inf;
|
||||
%$ [p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
|
||||
%$ case 3
|
||||
%$ % Normal distribution
|
||||
%$ p3(i) = -Inf;
|
||||
%$ p4(i) = Inf;
|
||||
%$ p6(i) = p1(i);
|
||||
%$ p7(i) = p2(i);
|
||||
%$ p5(i) = p1(i);
|
||||
%$ case 4
|
||||
%$ % Inverse Gamma (type I) distribution
|
||||
%$ p3(i) = 0;
|
||||
%$ p4(i) = Inf;
|
||||
%$ [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
|
||||
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
|
||||
%$ case 5
|
||||
%$ % Uniform distribution
|
||||
%$ [p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
|
||||
%$ p3(i) = p6(i);
|
||||
%$ p4(i) = p7(i);
|
||||
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
|
||||
%$ case 6
|
||||
%$ % Inverse Gamma (type II) distribution
|
||||
%$ p3(i) = 0;
|
||||
%$ p4(i) = Inf;
|
||||
%$ [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
|
||||
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
|
||||
%$ case 8
|
||||
%$ % Weibull distribution
|
||||
%$ p3(i) = 0;
|
||||
%$ p4(i) = Inf;
|
||||
%$ [p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
|
||||
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
|
||||
%$ otherwise
|
||||
%$ error('This density is not implemented!')
|
||||
%$ end
|
||||
%$ end
|
||||
%$
|
||||
%$ bayestopt_.pshape = p0;
|
||||
%$ bayestopt_.p1 = p1;
|
||||
%$ bayestopt_.p2 = p2;
|
||||
%$ bayestopt_.p3 = p3;
|
||||
%$ bayestopt_.p4 = p4;
|
||||
%$ bayestopt_.p5 = p5;
|
||||
%$ bayestopt_.p6 = p6;
|
||||
%$ bayestopt_.p7 = p7;
|
||||
%$
|
||||
%$ ndraws = 1e5;
|
||||
%$
|
||||
%$ % Call the tested routine
|
||||
%$ try
|
||||
%$ % Instantiate dprior object.
|
||||
%$ o = dprior(bayestopt_, prior_trunc, false);
|
||||
%$ X = o.draws(ndraws);
|
||||
%$ m = mean(X, 2);
|
||||
%$ v = var(X, 0, 2);
|
||||
%$ % Instantiate dprior object
|
||||
%$ o = dprior();
|
||||
%$ t(1) = true;
|
||||
%$ catch
|
||||
%$ t(1) = false;
|
||||
%$ end
|
||||
%$
|
||||
%$ if t(1)
|
||||
%$ t(2) = all(abs(m-bayestopt_.p1)<3e-3);
|
||||
%$ t(3) = all(all(abs(v-bayestopt_.p2.^2)<5e-3));
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
|
|
@ -0,0 +1,197 @@
|
|||
function p = draw(o)
|
||||
|
||||
% Return a random draw from the prior distribution.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
%
|
||||
% OUTPUTS
|
||||
% - p [double] m×1 vector, random draw from the prior distribution (m is the number of estimated parameters).
|
||||
%
|
||||
% REMARKS
|
||||
% None.
|
||||
%
|
||||
% EXAMPLE
|
||||
%
|
||||
% >> Prior = dprior(bayestopt_, options_.prior_trunc);
|
||||
% >> d = Prior.draw()
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
p = NaN(rows(o.lb), 1);
|
||||
if o.isuniform
|
||||
p(o.iduniform) = rand(length(o.iduniform),1).*(o.p4(o.iduniform)-o.p3(o.iduniform)) + o.p3(o.iduniform);
|
||||
oob = find( (p(o.iduniform)>o.ub(o.iduniform)) | (p(o.iduniform)<o.lb(o.iduniform)));
|
||||
while ~isempty(oob)
|
||||
p(o.iduniform) = rand(length(o.iduniform), 1).*(o.p4(o.iduniform)-o.p3(o.iduniform)) + o.p3(o.iduniform);
|
||||
oob = find( (p(o.iduniform)>o.ub(o.iduniform)) | (p(o.iduniform)<o.lb(o.iduniform)));
|
||||
end
|
||||
end
|
||||
if o.isgaussian
|
||||
p(o.idgaussian) = randn(length(o.idgaussian), 1).*o.p7(o.idgaussian) + o.p6(o.idgaussian);
|
||||
oob = find( (p(o.idgaussian)>o.ub(o.idgaussian)) | (p(o.idgaussian)<o.lb(o.idgaussian)));
|
||||
while ~isempty(oob)
|
||||
p(o.idgaussian(oob)) = randn(length(o.idgaussian(oob)), 1).*o.p7(o.idgaussian(oob)) + o.p6(o.idgaussian(oob));
|
||||
oob = find( (p(o.idgaussian)>o.ub(o.idgaussian)) | (p(o.idgaussian)<o.lb(o.idgaussian)));
|
||||
end
|
||||
end
|
||||
if o.isgamma
|
||||
p(o.idgamma) = gamrnd(o.p6(o.idgamma), o.p7(o.idgamma))+o.p3(o.idgamma);
|
||||
oob = find( (p(o.idgamma)>o.ub(o.idgamma)) | (p(o.idgamma)<o.lb(o.idgamma)));
|
||||
while ~isempty(oob)
|
||||
p(o.idgamma(oob)) = gamrnd(o.p6(o.idgamma(oob)), o.p7(o.idgamma(oob)))+o.p3(o.idgamma(oob));
|
||||
oob = find( (p(o.idgamma)>o.ub(o.idgamma)) | (p(o.idgamma)<o.lb(o.idgamma)));
|
||||
end
|
||||
end
|
||||
if o.isbeta
|
||||
p(o.idbeta) = (o.p4(o.idbeta)-o.p3(o.idbeta)).*betarnd(o.p6(o.idbeta), o.p7(o.idbeta))+o.p3(o.idbeta);
|
||||
oob = find( (p(o.idbeta)>o.ub(o.idbeta)) | (p(o.idbeta)<o.lb(o.idbeta)));
|
||||
while ~isempty(oob)
|
||||
p(o.idbeta(oob)) = (o.p4(o.idbeta(oob))-o.p3(o.idbeta(oob))).*betarnd(o.p6(o.idbeta(oob)), o.p7(o.idbeta(oob)))+o.p3(o.idbeta(oob));
|
||||
oob = find( (p(o.idbeta)>o.ub(o.idbeta)) | (p(o.idbeta)<o.lb(o.idbeta)));
|
||||
end
|
||||
end
|
||||
if o.isinvgamma1
|
||||
p(o.idinvgamma1) = ...
|
||||
sqrt(1./gamrnd(o.p7(o.idinvgamma1)/2, 2./o.p6(o.idinvgamma1)))+o.p3(o.idinvgamma1);
|
||||
oob = find( (p(o.idinvgamma1)>o.ub(o.idinvgamma1)) | (p(o.idinvgamma1)<o.lb(o.idinvgamma1)));
|
||||
while ~isempty(oob)
|
||||
p(o.idinvgamma1(oob)) = ...
|
||||
sqrt(1./gamrnd(o.p7(o.idinvgamma1(oob))/2, 2./o.p6(o.idinvgamma1(oob))))+o.p3(o.idinvgamma1(oob));
|
||||
oob = find( (p(o.idinvgamma1)>o.ub(o.idinvgamma1)) | (p(o.idinvgamma1)<o.lb(o.idinvgamma1)));
|
||||
end
|
||||
end
|
||||
if o.isinvgamma2
|
||||
p(o.idinvgamma2) = ...
|
||||
1./gamrnd(o.p7(o.idinvgamma2)/2, 2./o.p6(o.idinvgamma2))+o.p3(o.idinvgamma2);
|
||||
oob = find( (p(o.idinvgamma2)>o.ub(o.idinvgamma2)) | (p(o.idinvgamma2)<o.lb(o.idinvgamma2)));
|
||||
while ~isempty(oob)
|
||||
p(o.idinvgamma2(oob)) = ...
|
||||
1./gamrnd(o.p7(o.idinvgamma2(oob))/2, 2./o.p6(o.idinvgamma2(oob)))+o.p3(o.idinvgamma2(oob));
|
||||
oob = find( (p(o.idinvgamma2)>o.ub(o.idinvgamma2)) | (p(o.idinvgamma2)<o.lb(o.idinvgamma2)));
|
||||
end
|
||||
end
|
||||
if o.isweibull
|
||||
p(o.idweibull) = wblrnd(o.p7(o.idweibull), o.p6(o.idweibull)) + o.p3(o.idweibull);
|
||||
oob = find( (p(o.idweibull)>o.ub(o.idweibull)) | (p(o.idweibull)<o.lb(o.idweibull)));
|
||||
while ~isempty(oob)
|
||||
p(o.idweibull(oob)) = wblrnd(o.p7(o.idweibull(oob)), o.p6(o.idweibull(oob)))+o.p3(o.idweibull(oob));
|
||||
oob = find( (p(o.idweibull)>o.ub(o.idweibull)) | (p(o.idweibull)<o.lb(o.idweibull)));
|
||||
end
|
||||
end
|
||||
|
||||
return % --*-- Unit tests --*--
|
||||
|
||||
%@test:1
|
||||
% Fill global structures with required fields...
|
||||
prior_trunc = 1e-10;
|
||||
p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
|
||||
p1 = .4*ones(14,1); % Prior mean
|
||||
p2 = .2*ones(14,1); % Prior std.
|
||||
p3 = NaN(14,1);
|
||||
p4 = NaN(14,1);
|
||||
p5 = NaN(14,1);
|
||||
p6 = NaN(14,1);
|
||||
p7 = NaN(14,1);
|
||||
|
||||
for i=1:14
|
||||
switch p0(i)
|
||||
case 1
|
||||
% Beta distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = 1;
|
||||
[p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
|
||||
case 2
|
||||
% Gamma distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
|
||||
case 3
|
||||
% Normal distribution
|
||||
p3(i) = -Inf;
|
||||
p4(i) = Inf;
|
||||
p6(i) = p1(i);
|
||||
p7(i) = p2(i);
|
||||
p5(i) = p1(i);
|
||||
case 4
|
||||
% Inverse Gamma (type I) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
|
||||
case 5
|
||||
% Uniform distribution
|
||||
[p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
|
||||
p3(i) = p6(i);
|
||||
p4(i) = p7(i);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
|
||||
case 6
|
||||
% Inverse Gamma (type II) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
|
||||
case 8
|
||||
% Weibull distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
|
||||
otherwise
|
||||
error('This density is not implemented!')
|
||||
end
|
||||
end
|
||||
|
||||
BayesInfo.pshape = p0;
|
||||
BayesInfo.p1 = p1;
|
||||
BayesInfo.p2 = p2;
|
||||
BayesInfo.p3 = p3;
|
||||
BayesInfo.p4 = p4;
|
||||
BayesInfo.p5 = p5;
|
||||
BayesInfo.p6 = p6;
|
||||
BayesInfo.p7 = p7;
|
||||
|
||||
ndraws = 1e5;
|
||||
m0 = BayesInfo.p1; %zeros(14,1);
|
||||
v0 = diag(BayesInfo.p2.^2); %zeros(14);
|
||||
|
||||
% Call the tested routine
|
||||
try
|
||||
% Instantiate dprior object
|
||||
o = dprior(BayesInfo, prior_trunc, false);
|
||||
% Do simulations in a loop and estimate recursively the mean and the variance.
|
||||
for i = 1:ndraws
|
||||
draw = o.draw();
|
||||
m1 = m0 + (draw-m0)/i;
|
||||
m2 = m1*m1';
|
||||
v0 = v0 + ((draw*draw'-m2-v0) + (i-1)*(m0*m0'-m2'))/i;
|
||||
m0 = m1;
|
||||
end
|
||||
t(1) = true;
|
||||
catch
|
||||
t(1) = false;
|
||||
end
|
||||
|
||||
if t(1)
|
||||
t(2) = all(abs(m0-BayesInfo.p1)<3e-3);
|
||||
t(3) = all(all(abs(v0-diag(BayesInfo.p2.^2))<5e-3));
|
||||
end
|
||||
T = all(t);
|
||||
%@eof:1
|
|
@ -0,0 +1,133 @@
|
|||
function P = draws(o, n)
|
||||
|
||||
% Return n independent random draws from the prior distribution.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
%
|
||||
% OUTPUTS
|
||||
% - P [double] m×n matrix, random draw from the prior distribution.
|
||||
%
|
||||
% REMARKS
|
||||
% If the Parallel Computing Toolbox is available, the main loop is run in parallel.
|
||||
%
|
||||
% EXAMPLE
|
||||
%
|
||||
% >> Prior = dprior(bayestopt_, options_.prior_trunc);
|
||||
% >> Prior.draws(1e6)
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
P = NaN(rows(o.lb), 1);
|
||||
parfor i=1:n
|
||||
P(:,i) = draw(o);
|
||||
end
|
||||
|
||||
return % --*-- Unit tests --*--
|
||||
|
||||
%@test:1
|
||||
% Fill global structures with required fields...
|
||||
prior_trunc = 1e-10;
|
||||
p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
|
||||
p1 = .4*ones(14,1); % Prior mean
|
||||
p2 = .2*ones(14,1); % Prior std.
|
||||
p3 = NaN(14,1);
|
||||
p4 = NaN(14,1);
|
||||
p5 = NaN(14,1);
|
||||
p6 = NaN(14,1);
|
||||
p7 = NaN(14,1);
|
||||
|
||||
for i=1:14
|
||||
switch p0(i)
|
||||
case 1
|
||||
% Beta distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = 1;
|
||||
[p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
|
||||
case 2
|
||||
% Gamma distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
|
||||
case 3
|
||||
% Normal distribution
|
||||
p3(i) = -Inf;
|
||||
p4(i) = Inf;
|
||||
p6(i) = p1(i);
|
||||
p7(i) = p2(i);
|
||||
p5(i) = p1(i);
|
||||
case 4
|
||||
% Inverse Gamma (type I) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
|
||||
case 5
|
||||
% Uniform distribution
|
||||
[p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
|
||||
p3(i) = p6(i);
|
||||
p4(i) = p7(i);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
|
||||
case 6
|
||||
% Inverse Gamma (type II) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
|
||||
case 8
|
||||
% Weibull distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
|
||||
otherwise
|
||||
error('This density is not implemented!')
|
||||
end
|
||||
end
|
||||
|
||||
BayesInfo.pshape = p0;
|
||||
BayesInfo.p1 = p1;
|
||||
BayesInfo.p2 = p2;
|
||||
BayesInfo.p3 = p3;
|
||||
BayesInfo.p4 = p4;
|
||||
BayesInfo.p5 = p5;
|
||||
BayesInfo.p6 = p6;
|
||||
BayesInfo.p7 = p7;
|
||||
|
||||
ndraws = 1e5;
|
||||
|
||||
% Call the tested routine
|
||||
try
|
||||
% Instantiate dprior object.
|
||||
o = dprior(BayesInfo, prior_trunc, false);
|
||||
X = o.draws(ndraws);
|
||||
m = mean(X, 2);
|
||||
v = var(X, 0, 2);
|
||||
t(1) = true;
|
||||
catch
|
||||
t(1) = false;
|
||||
end
|
||||
|
||||
if t(1)
|
||||
t(2) = all(abs(m-BayesInfo.p1)<3e-3);
|
||||
t(3) = all(all(abs(v-BayesInfo.p2.^2)<5e-3));
|
||||
end
|
||||
T = all(t);
|
||||
%@eof:1
|
|
@ -1,14 +1,17 @@
|
|||
function d = dyn_diag_vech(Vector)
|
||||
% This function returns the diagonal elements of a symmetric matrix
|
||||
% stored in vech form
|
||||
function n = length(o)
|
||||
|
||||
% Return the dimension of the random vector.
|
||||
%
|
||||
% INPUTS
|
||||
% Vector [double] a m*1 vector.
|
||||
% - o [dprior] Distribution specification for a n×1 vector of independent continuous random variables
|
||||
%
|
||||
% OUTPUTS
|
||||
% d [double] a n*1 vector, where n solves n*(n+1)/2=m.
|
||||
% - n [integer] scalar.
|
||||
%
|
||||
% REMARKS
|
||||
% None.
|
||||
|
||||
% Copyright © 2010-2017 Dynare Team
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -25,7 +28,4 @@ function d = dyn_diag_vech(Vector)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
m = length(Vector);
|
||||
n = (sqrt(1+8*m)-1)/2;
|
||||
k = cumsum(1:n);
|
||||
d = Vector(k);
|
||||
n = length(o.lb);
|
|
@ -1,17 +1,15 @@
|
|||
function moments=compute_model_moments(dr,M_,options_)
|
||||
function m = mean(o, resetmoments)
|
||||
|
||||
% Return the prior mean.
|
||||
%
|
||||
% INPUTS
|
||||
% dr: structure describing model solution
|
||||
% M_: structure of Dynare options
|
||||
% options_
|
||||
% - o [dprior]
|
||||
% - resetmoments [logical] Force the computation of the prior mean
|
||||
%
|
||||
% OUTPUTS
|
||||
% moments: a cell array containing requested moments
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% none
|
||||
% - m [double] n×1 vector, prior mean
|
||||
|
||||
% Copyright © 2008-2017 Dynare Team
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -28,5 +26,17 @@ function moments=compute_model_moments(dr,M_,options_)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
[ivar,vartan,options_] = get_variables_list(options_,M_);
|
||||
moments = th_autocovariances(dr,ivar,M_,options_,options_.nodecomposition);
|
||||
if nargin<2
|
||||
resetmoments = false;
|
||||
end
|
||||
|
||||
if any(isnan(o.p1))
|
||||
resetmoments = true;
|
||||
end
|
||||
|
||||
if resetmoments
|
||||
o.p1 = NaN(size(o.p1));
|
||||
o.moments('mean');
|
||||
end
|
||||
|
||||
m = o.p1;
|
|
@ -0,0 +1,42 @@
|
|||
function m = median(o, resetmoments)
|
||||
|
||||
% Return the prior median.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
% - resetmoments [logical] Force the computation of the prior median
|
||||
%
|
||||
% OUTPUTS
|
||||
% - m [double] n×1 vector, prior median
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
if nargin<2
|
||||
resetmoments = false;
|
||||
end
|
||||
|
||||
if any(isnan(o.p11))
|
||||
resetmoments = true;
|
||||
end
|
||||
|
||||
if resetmoments
|
||||
o.p11 = NaN(size(o.p11));
|
||||
o.moments('median');
|
||||
end
|
||||
|
||||
m = o.p11;
|
|
@ -1,20 +1,15 @@
|
|||
function save_results(x,s_name,names)
|
||||
function m = mode(o, resetmoments)
|
||||
|
||||
% function save_results(x,s_name,names)
|
||||
% save results in appropriate structure
|
||||
% Return the prior mode.
|
||||
%
|
||||
% INPUT
|
||||
% x: matrix to be saved column by column
|
||||
% s_name: name of the structure where to save the results
|
||||
% names: names of the individual series
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
% - resetmoments [logical] Force the computation of the prior mode
|
||||
%
|
||||
% OUTPUT
|
||||
% none
|
||||
%
|
||||
% SPECIAL REQUIREMENT
|
||||
% none
|
||||
% OUTPUTS
|
||||
% - m [double] n×1 vector, prior mode
|
||||
|
||||
% Copyright © 2006-2009 Dynare Team
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -31,8 +26,17 @@ function save_results(x,s_name,names)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
global oo_
|
||||
if nargin<2
|
||||
resetmoments = false;
|
||||
end
|
||||
|
||||
for i=1:size(x,2)
|
||||
eval([s_name deblank(names(i,:)) '= x(:,i);']);
|
||||
end
|
||||
if any(isnan(o.p5))
|
||||
resetmoments = true;
|
||||
end
|
||||
|
||||
if resetmoments
|
||||
o.p5 = NaN(size(o.p5));
|
||||
o.moments('mode');
|
||||
end
|
||||
|
||||
m = o.p5;
|
|
@ -0,0 +1,291 @@
|
|||
function o = moments(o, name)
|
||||
|
||||
% Compute the prior moments.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
%
|
||||
% OUTPUTS
|
||||
% - o [dprior]
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
switch name
|
||||
case 'mean'
|
||||
m = o.p1;
|
||||
case 'median'
|
||||
m = o.p11;
|
||||
case 'std'
|
||||
m = o.p2;
|
||||
case 'mode'
|
||||
m = o.p5;
|
||||
otherwise
|
||||
error('%s is not an implemented moemnt.', name)
|
||||
end
|
||||
id = isnan(m);
|
||||
if any(id)
|
||||
% For some parameters the prior mean is not defined.
|
||||
% We compute the first order moment from the
|
||||
% hyperparameters, if the hyperparameters are not
|
||||
% available an error is thrown.
|
||||
if o.isuniform
|
||||
jd = intersect(o.iduniform, find(id));
|
||||
if ~isempty(jd)
|
||||
if any(isnan(o.p3(jd))) || any(isnan(o.p4(jd)))
|
||||
error('dprior::mean: Some hyperparameters are missing (uniform distribution).')
|
||||
end
|
||||
switch name
|
||||
case 'mean'
|
||||
m(jd) = o.p3(jd) + .5*(o.p4(jd)-o.p3(jd));
|
||||
case 'median'
|
||||
m(jd) = o.p3(jd) + .5*(o.p4(jd)-o.p3(jd));
|
||||
case 'std'
|
||||
m(jd) = (o.p4(jd)-o.p3(jd))/sqrt(12);
|
||||
case 'mode' % Actually we have a continuum of modes with the uniform distribution.
|
||||
m(jd) = o.p3(jd) + .5*(o.p4(jd)-o.p3(jd));
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isgaussian
|
||||
jd = intersect(o.idgaussian, find(id));
|
||||
if ~isempty(jd)
|
||||
if any(isnan(o.p6(jd))) || any(isnan(o.p7(jd)))
|
||||
error('dprior::mean: Some hyperparameters are missing (gaussian distribution).')
|
||||
end
|
||||
switch name
|
||||
case 'mean'
|
||||
m(jd) = o.p6(jd);
|
||||
case 'median'
|
||||
m(jd) = o.p6(jd);
|
||||
case 'std'
|
||||
m(jd) = o.p7(jd);
|
||||
case 'mode' % Actually we have a continuum of modes with the uniform distribution.
|
||||
m(jd) = o.p6(jd);
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isgamma
|
||||
jd = intersect(o.idgamma, find(id));
|
||||
if ~isempty(jd)
|
||||
if any(isnan(o.p6(jd))) || any(isnan(o.p7(jd))) || any(isnan(o.p3(jd)))
|
||||
error('dprior::mean: Some hyperparameters are missing (gamma distribution).')
|
||||
end
|
||||
% α → o.p6, β → o.p7
|
||||
switch name
|
||||
case 'mean'
|
||||
m(jd) = o.p3(jd) + o.p6(jd).*o.p7(jd);
|
||||
case 'median'
|
||||
m(jd) = o.p3(jd) + gaminv(.5, o.p6(jd), o.p7(jda));
|
||||
case 'std'
|
||||
m(jd) = sqrt(o.p6(jd)).*o.p7(jd);
|
||||
case 'mode'
|
||||
m(jd) = 0;
|
||||
hd = o.p6(jd)>1;
|
||||
m(jd(hd)) = (o.p6(jd(hd))-1).*o.p7(jd(hd));
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isbeta
|
||||
jd = intersect(o.idbeta, find(id));
|
||||
if ~isempty(jd)
|
||||
if any(isnan(o.p6(jd))) || any(isnan(o.p7(jd))) || any(isnan(o.p3(jd))) || any(isnan(o.p4(jd)))
|
||||
error('dprior::mean: Some hyperparameters are missing (beta distribution).')
|
||||
end
|
||||
% α → o.p6, β → o.p7
|
||||
switch name
|
||||
case 'mean'
|
||||
m(jd) = o.p3(jd) + (o.p6(jd)./(o.p6(jd)+o.p7(jd))).*(o.p4(jd)-o.p3(jd));
|
||||
case 'median'
|
||||
m(jd) = o.p3(jd) + betainv(.5, o.p6(jd), o.p7(jd)).*(o.p4(jd)-o.p3(jd));
|
||||
case 'std'
|
||||
m(jd) = (o.p4(jd)-o.p3(jd)).*sqrt(o.p6(jd).*o.p7(jd)./((o.p6(jd)+o.p7(jd)).^2.*(o.p6(jd)+o.p7(jd)+1)));
|
||||
case 'mode'
|
||||
h0 = true(jd, 1);
|
||||
h1 = o.p6(jd)<=1 & o.p7(jd)>1; h0 = h0 & ~h1;
|
||||
h2 = o.p7(jd)<=1 & o.p6(jd)>1; h0 = h0 & ~h2;
|
||||
h3 = o.p6(jd)<1 & o.p7(jd)<1; h0 = h0 & ~h3;
|
||||
h4 = ismembertol(o.p6(jd), 1) & ismembertol(o.p7(jd),1); h0 = h0 & ~h4;
|
||||
m(jd(h1)) = o.p3(jd(h1)); % Standard β has a mode at 0
|
||||
m(jd(h2)) = o.p4(jd(h2)); % Standard β has a mode at 1
|
||||
m(jd(h3)) = o.p3(jd(h3)); % Standard β is bimodal, we pick the lowest mode (0)
|
||||
m(jd(h4)) = o.p3(jd(h4)) + .5*(o.p4(jd(h4))-o.p3(jd(h4))); % Standard β is the uniform distribution (continuum of modes), we pick the mean as the mode
|
||||
m(jd(h0)) = o.p3(jd(h0))+(o.p4(jd(h0))-o.p3(jd(h0))).*((o.p6(jd(h0))-1)./(o.p6(jd(h0))+o.p7(jd(h0))-2)); % β distribution is concave and has a unique interior mode.
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isinvgamma1
|
||||
jd = intersect(o.idinvgamma1, find(id));
|
||||
if ~isempty(jd)
|
||||
if any(isnan(o.p6(jd))) || any(isnan(o.p7(jd))) || any(isnan(o.p3(jd)))
|
||||
error('dprior::mean: Some hyperparameters are missing (inverse gamma type 1 distribution).')
|
||||
end
|
||||
% s → o.p6, ν → o.p7
|
||||
switch name
|
||||
case 'mean'
|
||||
m(jd) = o.p3(jd) + sqrt(.5*o.p6(jd)) .*(gamma(.5*(o.p7(jd)-1))./gamma(.5*o.p7(jd)));
|
||||
case 'median'
|
||||
m(jd) = o.p3(jd) + 1.0/sqrt(gaminv(.5, o.p7(jd)/2.0, 2.0/o.p6(jd)));
|
||||
case 'std'
|
||||
m(jd) = sqrt( o.p6(jd)./(o.p7(jd)-2)-(.5*o.p6(jd)).*(gamma(.5*(o.p7(jd)-1))./gamma(.5*o.p7(jd))).^2);
|
||||
case 'mode'
|
||||
m(jd) = sqrt((o.p7(jd)-1)./o.p6(jd));
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isinvgamma2
|
||||
jd = intersect(o.idinvgamma2, find(id));
|
||||
if ~isempty(jd)
|
||||
if any(isnan(o.p6(jd))) || any(isnan(o.p7(jd))) || any(isnan(o.p3(jd)))
|
||||
error('dprior::mean: Some hyperparameters are missing (inverse gamma type 2 distribution).')
|
||||
end
|
||||
% s → o.p6, ν → o.p7
|
||||
switch name
|
||||
case 'mean'
|
||||
m(jd) = o.p3(jd) + o.p6(jd)./(o.p7(jd)-2);
|
||||
case 'median'
|
||||
m(jd) = o.p3(jd) + 1.0/gaminv(.5, o.p7(jd)/2.0, 2.0/o.p6(jd));
|
||||
case 'std'
|
||||
m(jd) = sqrt(2./(o.p7(jd)-4)).*o.p6(jd)./(o.p7(jd)-2);
|
||||
case 'mode'
|
||||
m(jd) = o.p6(jd)./(o.p7(jd)+2);
|
||||
end
|
||||
end
|
||||
end
|
||||
if o.isweibull
|
||||
jd = intersect(o.idweibull, find(id));
|
||||
if ~isempty(jd)
|
||||
if any(isnan(o.p6(jd))) || any(isnan(o.p7(jd))) || any(isnan(o.p3(jd)))
|
||||
error('dprior::mean: Some hyperparameters are missing (weibull distribution).')
|
||||
end
|
||||
% k → o.p6 (shape parameter), λ → o.p7 (scale parameter)
|
||||
% See https://en.wikipedia.org/wiki/Weibull_distribution
|
||||
switch name
|
||||
case 'mean'
|
||||
m(jd) = o.p3(jd) + o.p7(jd).*gamma(1+1./o.p6(jd));
|
||||
case 'median'
|
||||
m(jd) = o.p3(jd) + o.p7(jd).*log(2).^(1./o.p6(jd));
|
||||
case 'std'
|
||||
m(jd) = o.p7(jd).*sqrt(gamma(1+2./o.p6(jd))-gamma(1+1./o.p6(jd)).^2);
|
||||
case 'mode'
|
||||
m(jd) = 0;
|
||||
hd = o.p6(jd)>1;
|
||||
m(jd(hd)) = o.p3(jd(hd)) + o.p7(jd(hd)).*((o.p6(jd(hd))-1)./o.p6(jd(hd))).^(1./o.p6(jd(hd)));
|
||||
end
|
||||
end
|
||||
end
|
||||
switch name
|
||||
case 'mean'
|
||||
o.p1 = m;
|
||||
case 'median'
|
||||
o.p11 = m;
|
||||
case 'std'
|
||||
o.p2 = m;
|
||||
case 'mode'
|
||||
o.p5 = m;
|
||||
end
|
||||
end
|
||||
|
||||
return % --*-- Unit tests --*--
|
||||
|
||||
%@test:5
|
||||
% Fill global structures with required fields...
|
||||
prior_trunc = 1e-10;
|
||||
p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
|
||||
p1 = .4*ones(14,1); % Prior mean
|
||||
p2 = .2*ones(14,1); % Prior std.
|
||||
p3 = NaN(14,1);
|
||||
p4 = NaN(14,1);
|
||||
p5 = NaN(14,1);
|
||||
p6 = NaN(14,1);
|
||||
p7 = NaN(14,1);
|
||||
|
||||
for i=1:14
|
||||
switch p0(i)
|
||||
case 1
|
||||
% Beta distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = 1;
|
||||
[p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
|
||||
case 2
|
||||
% Gamma distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
|
||||
case 3
|
||||
% Normal distribution
|
||||
p3(i) = -Inf;
|
||||
p4(i) = Inf;
|
||||
p6(i) = p1(i);
|
||||
p7(i) = p2(i);
|
||||
p5(i) = p1(i);
|
||||
case 4
|
||||
% Inverse Gamma (type I) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
|
||||
case 5
|
||||
% Uniform distribution
|
||||
[p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
|
||||
p3(i) = p6(i);
|
||||
p4(i) = p7(i);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
|
||||
case 6
|
||||
% Inverse Gamma (type II) distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
|
||||
case 8
|
||||
% Weibull distribution
|
||||
p3(i) = 0;
|
||||
p4(i) = Inf;
|
||||
[p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
|
||||
p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
|
||||
otherwise
|
||||
error('This density is not implemented!')
|
||||
end
|
||||
end
|
||||
|
||||
BayesInfo.pshape = p0;
|
||||
BayesInfo.p1 = p1;
|
||||
BayesInfo.p2 = p2;
|
||||
BayesInfo.p3 = p3;
|
||||
BayesInfo.p4 = p4;
|
||||
BayesInfo.p5 = p5;
|
||||
BayesInfo.p6 = p6;
|
||||
BayesInfo.p7 = p7;
|
||||
|
||||
% Call the tested routine
|
||||
try
|
||||
Prior = dprior(BayesInfo, prior_trunc, false);
|
||||
t(1) = true;
|
||||
catch
|
||||
t(1) = false;
|
||||
end
|
||||
|
||||
if t(1)
|
||||
t(2) = all(Prior.mean()==.4);
|
||||
t(3) = all(ismembertol(Prior.mean(true),.4));
|
||||
t(4) = all(ismembertol(Prior.variance(),.04));
|
||||
t(5) = all(ismembertol(Prior.variance(true),.04));
|
||||
end
|
||||
T = all(t);
|
||||
%@eof:5
|
|
@ -0,0 +1,41 @@
|
|||
function p = subsref(o, S)
|
||||
|
||||
% Overload subsref method.
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
switch S(1).type
|
||||
case '.'
|
||||
if ismember(S(1).subs, {'p1','p2','p3','p4','p5','p6','p7','lb','ub'})
|
||||
p = builtin('subsref', o, S(1));
|
||||
elseif ismember(S(1).subs, {'draw','length'})
|
||||
p = feval(S(1).subs, o);
|
||||
elseif ismember(S(1).subs, {'draws', 'density', 'densities', 'moments', 'admissible'})
|
||||
p = feval(S(1).subs, o , S(2).subs{:});
|
||||
elseif ismember(S(1).subs, {'mean', 'median', 'variance', 'mode'})
|
||||
if (length(S)==2 && isempty(S(2).subs)) || length(S)==1
|
||||
p = feval(S(1).subs, o);
|
||||
else
|
||||
p = feval(S(1).subs, o , S(2).subs{:});
|
||||
end
|
||||
else
|
||||
error('dprior::subsref: unknown method (%s).', S(1).subs)
|
||||
end
|
||||
otherwise
|
||||
error('dprior::subsref: %s indexing not implemented.', S(1).type)
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
function m = variance(o, resetmoments)
|
||||
|
||||
% Return the prior variance.
|
||||
%
|
||||
% INPUTS
|
||||
% - o [dprior]
|
||||
% - resetmoments [logical] Force the computation of the prior variance
|
||||
%
|
||||
% OUTPUTS
|
||||
% - m [double] n×1 vector, prior variance
|
||||
|
||||
% Copyright © 2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
if nargin<2
|
||||
resetmoments = false;
|
||||
end
|
||||
|
||||
if any(isnan(o.p2))
|
||||
resetmoments = true;
|
||||
end
|
||||
|
||||
if resetmoments
|
||||
o.p2 = NaN(size(o.p2));
|
||||
o.moments('std');
|
||||
end
|
||||
|
||||
m = o.p2.^2;
|
|
@ -1,152 +0,0 @@
|
|||
function [AHess, DLIK, LIK] = AHessian(T,R,Q,H,P,Y,DT,DYss,DOm,DH,DP,start,mf,kalman_tol,riccati_tol)
|
||||
% function [AHess, DLIK, LIK] = AHessian(T,R,Q,H,P,Y,DT,DYss,DOm,DH,DP,start,mf,kalman_tol,riccati_tol)
|
||||
%
|
||||
% computes the asymptotic hessian matrix of the log-likelihood function of
|
||||
% a state space model (notation as in kalman_filter.m in DYNARE
|
||||
% Thanks to Nikolai Iskrev
|
||||
%
|
||||
% NOTE: the derivative matrices (DT,DR ...) are 3-dim. arrays with last
|
||||
% dimension equal to the number of structural parameters
|
||||
|
||||
% Copyright © 2011-2017 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
k = size(DT,3); % number of structural parameters
|
||||
smpl = size(Y,2); % Sample size.
|
||||
pp = size(Y,1); % Maximum number of observed variables.
|
||||
mm = size(T,2); % Number of state variables.
|
||||
a = zeros(mm,1); % State vector.
|
||||
Om = R*Q*transpose(R); % Variance of R times the vector of structural innovations.
|
||||
t = 0; % Initialization of the time index.
|
||||
oldK = 0;
|
||||
notsteady = 1; % Steady state flag.
|
||||
F_singular = 1;
|
||||
|
||||
lik = zeros(smpl,1); % Initialization of the vector gathering the densities.
|
||||
LIK = Inf; % Default value of the log likelihood.
|
||||
if nargout > 1
|
||||
DLIK = zeros(k,1); % Initialization of the score.
|
||||
end
|
||||
AHess = zeros(k,k); % Initialization of the Hessian
|
||||
Da = zeros(mm,k); % State vector.
|
||||
Dv = zeros(length(mf),k);
|
||||
|
||||
% for ii = 1:k
|
||||
% DOm = DR(:,:,ii)*Q*transpose(R) + R*DQ(:,:,ii)*transpose(R) + R*Q*transpose(DR(:,:,ii));
|
||||
% end
|
||||
|
||||
while notsteady && t<smpl
|
||||
t = t+1;
|
||||
v = Y(:,t)-a(mf);
|
||||
F = P(mf,mf) + H;
|
||||
if rcond(F) < kalman_tol
|
||||
if ~all(abs(F(:))<kalman_tol)
|
||||
return
|
||||
else
|
||||
a = T*a;
|
||||
P = T*P*transpose(T)+Om;
|
||||
end
|
||||
else
|
||||
F_singular = 0;
|
||||
iF = inv(F);
|
||||
K = P(:,mf)*iF;
|
||||
lik(t) = log(det(F))+transpose(v)*iF*v;
|
||||
|
||||
[DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K);
|
||||
|
||||
for ii = 1:k
|
||||
Dv(:,ii) = -Da(mf,ii) - DYss(mf,ii);
|
||||
Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii));
|
||||
if t>=start && nargout > 1
|
||||
DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v;
|
||||
end
|
||||
end
|
||||
vecDPmf = reshape(DP(mf,mf,:),[],k);
|
||||
% iPmf = inv(P(mf,mf));
|
||||
if t>=start
|
||||
AHess = AHess + Dv'*iF*Dv + .5*(vecDPmf' * kron(iF,iF) * vecDPmf);
|
||||
end
|
||||
a = T*(a+K*v);
|
||||
P = T*(P-K*P(mf,:))*transpose(T)+Om;
|
||||
DP = DP1;
|
||||
end
|
||||
notsteady = max(max(abs(K-oldK))) > riccati_tol;
|
||||
oldK = K;
|
||||
end
|
||||
|
||||
if F_singular
|
||||
error('The variance of the forecast error remains singular until the end of the sample')
|
||||
end
|
||||
|
||||
|
||||
if t < smpl
|
||||
t0 = t+1;
|
||||
while t < smpl
|
||||
t = t+1;
|
||||
v = Y(:,t)-a(mf);
|
||||
for ii = 1:k
|
||||
Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii);
|
||||
Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii));
|
||||
if t>=start && nargout >1
|
||||
DLIK(ii,1) = DLIK(ii,1) + trace( iF*DF(:,:,ii) ) + 2*Dv(:,ii)'*iF*v - v'*(iF*DF(:,:,ii)*iF)*v;
|
||||
end
|
||||
end
|
||||
if t>=start
|
||||
AHess = AHess + Dv'*iF*Dv;
|
||||
end
|
||||
a = T*(a+K*v);
|
||||
lik(t) = transpose(v)*iF*v;
|
||||
end
|
||||
AHess = AHess + .5*(smpl-t0+1)*(vecDPmf' * kron(iF,iF) * vecDPmf);
|
||||
if nargout > 1
|
||||
for ii = 1:k
|
||||
% DLIK(ii,1) = DLIK(ii,1) + (smpl-t0+1)*trace( iF*DF(:,:,ii) );
|
||||
end
|
||||
end
|
||||
lik(t0:smpl) = lik(t0:smpl) + log(det(F));
|
||||
% for ii = 1:k;
|
||||
% for jj = 1:ii
|
||||
% H(ii,jj) = trace(iPmf*(.5*DP(mf,mf,ii)*iPmf*DP(mf,mf,jj) + Dv(:,ii)*Dv(:,jj)'));
|
||||
% end
|
||||
% end
|
||||
end
|
||||
|
||||
AHess = -AHess;
|
||||
if nargout > 1
|
||||
DLIK = DLIK/2;
|
||||
end
|
||||
% adding log-likelihhod constants
|
||||
lik = (lik + pp*log(2*pi))/2;
|
||||
|
||||
LIK = sum(lik(start:end)); % Minus the log-likelihood.
|
||||
% end of main function
|
||||
|
||||
function [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K)
|
||||
|
||||
k = size(DT,3);
|
||||
tmp = P-K*P(mf,:);
|
||||
|
||||
for ii = 1:k
|
||||
DF(:,:,ii) = DP(mf,mf,ii) + DH(:,:,ii);
|
||||
DiF(:,:,ii) = -iF*DF(:,:,ii)*iF;
|
||||
DK(:,:,ii) = DP(:,mf,ii)*iF + P(:,mf)*DiF(:,:,ii);
|
||||
Dtmp = DP(:,:,ii) - DK(:,:,ii)*P(mf,:) - K*DP(mf,:,ii);
|
||||
DP1(:,:,ii) = DT(:,:,ii)*tmp*T' + T*Dtmp*T' + T*tmp*DT(:,:,ii)' + DOm(:,:,ii);
|
||||
end
|
||||
|
||||
% end of computeDKalman
|
|
@ -1,90 +0,0 @@
|
|||
function Draws = GetAllPosteriorDraws(dname, fname, column, FirstMhFile, FirstLine, TotalNumberOfMhFile, NumberOfDraws, nblcks, blck)
|
||||
% function Draws = GetAllPosteriorDraws(dname, fname, column, FirstMhFile, FirstLine, TotalNumberOfMhFile, NumberOfDraws, nblcks, blck)
|
||||
% Gets all posterior draws
|
||||
%
|
||||
% INPUTS
|
||||
% dname: name of directory with results
|
||||
% fname: name of mod file
|
||||
% column: column of desired parameter in draw matrix
|
||||
% FirstMhFile: first mh file
|
||||
% FirstLine: first line
|
||||
% TotalNumberOfMhFile: total number of mh file
|
||||
% NumberOfDraws: number of draws
|
||||
% nblcks: total number of blocks
|
||||
% blck: desired block to read
|
||||
%
|
||||
% OUTPUTS
|
||||
% Draws: draws from posterior distribution
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% none
|
||||
|
||||
% Copyright © 2005-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
iline = FirstLine;
|
||||
linee = 1;
|
||||
DirectoryName = CheckPath('metropolis',dname);
|
||||
|
||||
if nblcks>1 && nargin<9
|
||||
Draws = zeros(NumberOfDraws*nblcks,1);
|
||||
iline0=iline;
|
||||
if column>0
|
||||
for blck = 1:nblcks
|
||||
iline=iline0;
|
||||
for file = FirstMhFile:TotalNumberOfMhFile
|
||||
load([DirectoryName '/' fname '_mh' int2str(file) '_blck' int2str(blck)],'x2')
|
||||
NumberOfLines = size(x2(iline:end,:),1);
|
||||
Draws(linee:linee+NumberOfLines-1) = x2(iline:end,column);
|
||||
linee = linee+NumberOfLines;
|
||||
iline = 1;
|
||||
end
|
||||
end
|
||||
else
|
||||
for blck = 1:nblcks
|
||||
iline=iline0;
|
||||
for file = FirstMhFile:TotalNumberOfMhFile
|
||||
load([DirectoryName '/' fname '_mh' int2str(file) '_blck' int2str(blck)],'logpo2')
|
||||
NumberOfLines = size(logpo2(iline:end),1);
|
||||
Draws(linee:linee+NumberOfLines-1) = logpo2(iline:end);
|
||||
linee = linee+NumberOfLines;
|
||||
iline = 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if nblcks==1
|
||||
blck=1;
|
||||
end
|
||||
if column>0
|
||||
for file = FirstMhFile:TotalNumberOfMhFile
|
||||
load([DirectoryName '/' fname '_mh' int2str(file) '_blck' int2str(blck)],'x2')
|
||||
NumberOfLines = size(x2(iline:end,:),1);
|
||||
Draws(linee:linee+NumberOfLines-1) = x2(iline:end,column);
|
||||
linee = linee+NumberOfLines;
|
||||
iline = 1;
|
||||
end
|
||||
else
|
||||
for file = FirstMhFile:TotalNumberOfMhFile
|
||||
load([DirectoryName '/' fname '_mh' int2str(file) '_blck' int2str(blck)],'logpo2')
|
||||
NumberOfLines = size(logpo2(iline:end,:),1);
|
||||
Draws(linee:linee+NumberOfLines-1) = logpo2(iline:end);
|
||||
linee = linee+NumberOfLines;
|
||||
iline = 1;
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,67 +0,0 @@
|
|||
function [mean,variance] = GetPosteriorMeanVariance(M_,drop)
|
||||
%function [mean,variance] = GetPosteriorMeanVariance(M,drop)
|
||||
% Computes the posterior mean and variance
|
||||
% (+updates of oo_ & TeX output).
|
||||
%
|
||||
% INPUTS
|
||||
% M_ [structure] Dynare model structure
|
||||
% drop [double] share of draws to drop
|
||||
%
|
||||
% OUTPUTS
|
||||
% mean [double] mean parameter vector
|
||||
% variance [double] variance
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% None.
|
||||
|
||||
% Copyright © 2012-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
MetropolisFolder = CheckPath('metropolis',M_.dname);
|
||||
FileName = M_.fname;
|
||||
BaseName = [MetropolisFolder filesep FileName];
|
||||
record=load_last_mh_history_file(MetropolisFolder, FileName);
|
||||
NbrDraws = sum(record.MhDraws(:,1));
|
||||
NbrFiles = sum(record.MhDraws(:,2));
|
||||
NbrBlocks = record.Nblck;
|
||||
mean = 0;
|
||||
variance = 0;
|
||||
|
||||
NbrKeptDraws = 0;
|
||||
for i=1:NbrBlocks
|
||||
NbrDrawsCurrentBlock = 0;
|
||||
for j=1:NbrFiles
|
||||
o = load([BaseName '_mh' int2str(j) '_blck' int2str(i),'.mat']);
|
||||
NbrDrawsCurrentFile = size(o.x2,1);
|
||||
if NbrDrawsCurrentBlock + NbrDrawsCurrentFile <= drop*NbrDraws
|
||||
NbrDrawsCurrentBlock = NbrDrawsCurrentBlock + NbrDrawsCurrentFile;
|
||||
continue
|
||||
elseif NbrDrawsCurrentBlock < drop*NbrDraws
|
||||
FirstDraw = ceil(drop*NbrDraws - NbrDrawsCurrentBlock + 1);
|
||||
x2 = o.x2(FirstDraw:end,:);
|
||||
else
|
||||
x2 = o.x2;
|
||||
end
|
||||
NbrKeptDrawsCurrentFile = size(x2,1);
|
||||
%recursively compute mean and variance
|
||||
mean = (NbrKeptDraws*mean + sum(x2)')/(NbrKeptDraws+NbrKeptDrawsCurrentFile);
|
||||
x2Demeaned = bsxfun(@minus,x2,mean');
|
||||
variance = (NbrKeptDraws*variance + x2Demeaned'*x2Demeaned)/(NbrKeptDraws+NbrKeptDrawsCurrentFile);
|
||||
NbrDrawsCurrentBlock = NbrDrawsCurrentBlock + NbrDrawsCurrentFile;
|
||||
NbrKeptDraws = NbrKeptDraws + NbrKeptDrawsCurrentFile;
|
||||
end
|
||||
end
|
|
@ -1,246 +0,0 @@
|
|||
function Herbst_Schorfheide_sampler(TargetFun,xparam1,mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_)
|
||||
% function Herbst_Schorfheide_sampler(TargetFun,xparam1,mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_)
|
||||
% SMC sampler from JAE 2014 .
|
||||
%
|
||||
% INPUTS
|
||||
% o TargetFun [char] string specifying the name of the objective
|
||||
% function (posterior kernel).
|
||||
% o xparam1 [double] (p*1) vector of parameters to be estimated (initial values).
|
||||
% o mh_bounds [double] (p*2) matrix defining lower and upper bounds for the parameters.
|
||||
% o dataset_ data structure
|
||||
% o dataset_info dataset info structure
|
||||
% o options_ options structure
|
||||
% o M_ model structure
|
||||
% o estim_params_ estimated parameters structure
|
||||
% o bayestopt_ estimation options structure
|
||||
% o oo_ outputs structure
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% None.
|
||||
%
|
||||
% PARALLEL CONTEXT
|
||||
% The most computationally intensive part of this function may be executed
|
||||
% in parallel. The code suitable to be executed in
|
||||
% parallel on multi core or cluster machine (in general a 'for' cycle)
|
||||
% has been removed from this function and been placed in the posterior_sampler_core.m funtion.
|
||||
%
|
||||
% The DYNARE parallel packages comprise a i) set of pairs of Matlab functions that can be executed in
|
||||
% parallel and called name_function.m and name_function_core.m and ii) a second set of functions used
|
||||
% to manage the parallel computations.
|
||||
%
|
||||
% This function was the first function to be parallelized. Later, other
|
||||
% functions have been parallelized using the same methodology.
|
||||
% Then the comments write here can be used for all the other pairs of
|
||||
% parallel functions and also for management functions.
|
||||
|
||||
% Copyright © 2006-2023 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
% Create the tempering schedule
|
||||
phi = bsxfun(@power,(bsxfun(@minus,1:1:options_.posterior_sampler_options.HSsmc.nphi,1)/(options_.posterior_sampler_options.HSsmc.nphi-1)),options_.posterior_sampler_options.HSsmc.lambda) ;
|
||||
% tuning for MH algorithms matrices
|
||||
zhat = 0 ; % normalization constant
|
||||
csim = zeros(options_.posterior_sampler_options.HSsmc.nphi,1) ; % scale parameter
|
||||
ESSsim = zeros(options_.posterior_sampler_options.HSsmc.nphi,1) ; % ESS
|
||||
acptsim = zeros(options_.posterior_sampler_options.HSsmc.nphi,1) ; % average acceptance rate
|
||||
% Step 0: Initialization of the sampler
|
||||
[ param, tlogpost_i, loglik, bayestopt_] = ...
|
||||
SMC_samplers_initialization(TargetFun, xparam1, mh_bounds, dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_,options_.posterior_sampler_options.HSsmc.nparticles);
|
||||
weights = ones(options_.posterior_sampler_options.HSsmc.nparticles,1)/options_.posterior_sampler_options.HSsmc.nparticles ;
|
||||
% The Herbst and Schorfheide sampler starts here
|
||||
for i=2:options_.posterior_sampler_options.HSsmc.nphi
|
||||
% (a) Correction
|
||||
% incremental weights
|
||||
incwt = exp((phi(i)-phi(i-1))*loglik) ;
|
||||
% update weights
|
||||
weights = bsxfun(@times,weights,incwt) ;
|
||||
sum_weights = sum(weights) ;
|
||||
zhat = zhat + log(sum_weights) ;
|
||||
% normalize weights
|
||||
weights = weights/sum_weights ;
|
||||
% (b) Selection
|
||||
ESSsim(i) = 1/sum(weights.^2) ;
|
||||
if (ESSsim(i) < options_.posterior_sampler_options.HSsmc.nparticles/2)
|
||||
indx_resmpl = smc_resampling(weights,rand(1,1),options_.posterior_sampler_options.HSsmc.nparticles) ;
|
||||
param = param(:,indx_resmpl) ;
|
||||
loglik = loglik(indx_resmpl) ;
|
||||
tlogpost_i = tlogpost_i(indx_resmpl) ;
|
||||
weights = ones(options_.posterior_sampler_options.HSsmc.nparticles,1)/options_.posterior_sampler_options.HSsmc.nparticles ;
|
||||
end
|
||||
% (c) Mutation
|
||||
options_.posterior_sampler_options.HSsmc.c = options_.posterior_sampler_options.HSsmc.c*modified_logit(0.95,0.1,16.0,options_.posterior_sampler_options.HSsmc.acpt-options_.posterior_sampler_options.HSsmc.trgt) ;
|
||||
% Calculate estimates of mean and variance
|
||||
mu = param*weights ;
|
||||
z = bsxfun(@minus,param,mu) ;
|
||||
R = z*(bsxfun(@times,z',weights)) ;
|
||||
Rchol = chol(R)' ;
|
||||
% Mutation
|
||||
if options_.posterior_sampler_options.HSsmc.option_mutation==1
|
||||
[param,tlogpost_i,loglik,options_.posterior_sampler_options.HSsmc.acpt] = mutation_RW(TargetFun,param,tlogpost_i,loglik,phi,i,options_.posterior_sampler_options.HSsmc.c*Rchol,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_) ;
|
||||
elseif options_.posterior_sampler_options.HSsmc.option_mutation==2
|
||||
inv_R = inv(options_.posterior_sampler_options.HSsmc.c^2*R) ;
|
||||
Rdiagchol = sqrt(diag(R)) ;
|
||||
[param,tlogpost_i,loglik,options_.posterior_sampler_options.HSsmc.acpt] = mutation_Mixture(TargetFun,param,tlogpost_i,loglik,phi,i,options_.posterior_sampler_options.HSsmc.c*Rchol,options_.posterior_sampler_options.HSsmc.c*Rdiagchol,inv_R,mu,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_) ;
|
||||
end
|
||||
acptsim(i) = options_.posterior_sampler_options.HSsmc.acpt ;
|
||||
csim(i) = options_.posterior_sampler_options.HSsmc.c ;
|
||||
% print information
|
||||
fprintf(' Iteration = %5.0f / %5.0f \n', i, options_.posterior_sampler_options.HSsmc.nphi);
|
||||
fprintf(' phi = %5.4f \n', phi(i));
|
||||
fprintf(' Neff = %5.4f \n', ESSsim(i));
|
||||
fprintf(' %accept. = %5.4f \n', acptsim(i));
|
||||
end
|
||||
indx_resmpl = smc_resampling(weights,rand(1,1),options_.posterior_sampler_options.HSsmc.nparticles);
|
||||
distrib_param = param(:,indx_resmpl);
|
||||
fprintf(' Log_lik = %5.4f \n', zhat);
|
||||
|
||||
mean_xparam = mean(distrib_param,2);
|
||||
npar = length(xparam1) ;
|
||||
%mat_var_cov = bsxfun(@minus,distrib_param,mean_xparam) ;
|
||||
%mat_var_cov = (mat_var_cov*mat_var_cov')/(options_.posterior_sampler_options.HSsmc.nparticles-1) ;
|
||||
%std_xparam = sqrt(diag(mat_var_cov)) ;
|
||||
lb95_xparam = zeros(npar,1) ;
|
||||
ub95_xparam = zeros(npar,1) ;
|
||||
for i=1:npar
|
||||
temp = sortrows(distrib_param(i,:)') ;
|
||||
lb95_xparam(i) = temp(0.025*options_.posterior_sampler_options.HSsmc.nparticles) ;
|
||||
ub95_xparam(i) = temp(0.975*options_.posterior_sampler_options.HSsmc.nparticles) ;
|
||||
end
|
||||
|
||||
TeX = options_.TeX;
|
||||
|
||||
str = sprintf(' Param. \t Lower Bound (95%%) \t Mean \t Upper Bound (95%%)');
|
||||
for l=1:npar
|
||||
[name,~] = get_the_name(l,TeX,M_,estim_params_,options_.varobs);
|
||||
str = sprintf('%s\n %s \t\t %5.4f \t\t %7.5f \t\t %5.4f', str, name, lb95_xparam(l), mean_xparam(l), ub95_xparam(l));
|
||||
end
|
||||
disp([str])
|
||||
disp('')
|
||||
|
||||
%% Plot parameters densities
|
||||
|
||||
[nbplt,nr,nc,lr,lc,nstar] = pltorg(npar);
|
||||
|
||||
if TeX
|
||||
fidTeX = fopen([M_.fname '_param_density.tex'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by DSMH.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
|
||||
number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two.
|
||||
bandwidth = 0; % Rule of thumb optimal bandwidth parameter.
|
||||
kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourier Transform approximation.
|
||||
plt = 1 ;
|
||||
%for plt = 1:nbplt,
|
||||
if TeX
|
||||
NAMES = [];
|
||||
TeXNAMES = [];
|
||||
end
|
||||
hh_fig = dyn_figure(options_.nodisplay,'Name','Parameters Densities');
|
||||
for k=1:npar %min(nstar,npar-(plt-1)*nstar)
|
||||
subplot(ceil(sqrt(npar)),floor(sqrt(npar)),k)
|
||||
%kk = (plt-1)*nstar+k;
|
||||
[name,texname] = get_the_name(k,TeX,M_,estim_params_,options_.varobs);
|
||||
optimal_bandwidth = mh_optimal_bandwidth(distrib_param(k,:)',options_.posterior_sampler_options.HSsmc.nparticles,bandwidth,kernel_function);
|
||||
[density(:,1),density(:,2)] = kernel_density_estimate(distrib_param(k,:)',number_of_grid_points,...
|
||||
options_.posterior_sampler_options.HSsmc.nparticles,optimal_bandwidth,kernel_function);
|
||||
plot(density(:,1),density(:,2));
|
||||
hold on
|
||||
if TeX
|
||||
title(texname,'interpreter','latex')
|
||||
else
|
||||
title(name,'interpreter','none')
|
||||
end
|
||||
hold off
|
||||
axis tight
|
||||
drawnow
|
||||
end
|
||||
dyn_saveas(hh_fig,[ M_.fname '_param_density' int2str(plt) ],options_.nodisplay,options_.graph_format);
|
||||
if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
||||
% TeX eps loader file
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%_param_density%s}\n',min(k/floor(sqrt(npar)),1),M_.fname,int2str(plt));
|
||||
fprintf(fidTeX,'\\caption{Parameter densities based on the Herbst/Schorfheide sampler.}');
|
||||
fprintf(fidTeX,'\\label{Fig:ParametersDensities:%s}\n',int2str(plt));
|
||||
fprintf(fidTeX,'\\end{figure}\n');
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
%end
|
||||
|
||||
function [param,tlogpost_i,loglik,acpt] = mutation_RW(TargetFun,param,tlogpost_i,loglik,phi,i,cRchol,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_)
|
||||
acpt = 0.0 ;
|
||||
tlogpost_i = tlogpost_i + (phi(i)-phi(i-1))*loglik ;
|
||||
for j=1:options_.posterior_sampler_options.HSsmc.nparticles
|
||||
validate= 0;
|
||||
while validate==0
|
||||
candidate = param(:,j) + cRchol*randn(size(param,1),1) ;
|
||||
if all(candidate(:) >= mh_bounds.lb) && all(candidate(:) <= mh_bounds.ub)
|
||||
[tlogpostx,loglikx] = tempered_likelihood(TargetFun,candidate,phi(i),dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_);
|
||||
if isfinite(loglikx) % if returned log-density is not Inf or Nan (penalized value)
|
||||
validate = 1;
|
||||
if rand(1,1)<exp(tlogpostx-tlogpost_i(j)) % accept
|
||||
acpt = acpt + 1 ;
|
||||
param(:,j) = candidate;
|
||||
loglik(j) = loglikx;
|
||||
tlogpost_i(j) = tlogpostx;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
acpt = acpt/options_.posterior_sampler_options.HSsmc.nparticles;
|
||||
|
||||
function [param,tlogpost_i,loglik,acpt] = mutation_Mixture(TargetFun,param,tlogpost_i,loglik,phi,i,cRchol,cRdiagchol,invR,mu,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_)
|
||||
acpt = 0.0 ;
|
||||
tlogpost_i = tlogpost_i + (phi(i)-phi(i-1))*loglik ;
|
||||
for j=1:options_.posterior_sampler_options.HSsmc.nparticles
|
||||
qx = 0 ;
|
||||
q0 = 0 ;
|
||||
alpind = rand(1,1) ;
|
||||
validate= 0;
|
||||
while validate==0
|
||||
if alpind<options_.posterior_sampler_options.HSsmc.alp % RW, no need to modify qx and q0
|
||||
candidate = param(:,j) + cRchol*randn(size(param,1),1);
|
||||
elseif alpind<options_.posterior_sampler_options.HSsmc.alp + (1-options_.posterior_sampler_options.HSsmc.alp/2) % random walk with diagonal cov no need to modify qx and q0
|
||||
candidate = param(:,j) + cRdiagchol*randn(size(param,1),1);
|
||||
else % Proposal densities
|
||||
candidate = mu + cRchol*randn(size(param,1),1);
|
||||
qx = -.5*(candidate-mu)'*invR*(candidate-mu) ; % no need of the constants in the acceptation rule
|
||||
q0 = -.5*(param(:,j)-mu)'*invR*(param(:,j)-mu) ;
|
||||
end
|
||||
if all(candidate(:) >= mh_bounds.lb) && all(candidate(:) <= mh_bounds.ub)
|
||||
[tlogpostx,loglikx] = tempered_likelihood(TargetFun,candidate,phi(i),dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_);
|
||||
if isfinite(loglikx) % if returned log-density is not Inf or Nan (penalized value)
|
||||
validate = 1;
|
||||
if rand(1,1)<exp((tlogpostx-qx)-(tlogpost_i(j)-q0)) % accept
|
||||
acpt = acpt + 1 ;
|
||||
param(:,j) = candidate;
|
||||
loglik(j) = loglikx;
|
||||
tlogpost_i(j) = tlogpostx;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
acpt = acpt/options_.posterior_sampler_options.HSsmc.nparticles;
|
||||
|
||||
function x = modified_logit(a,b,c,d)
|
||||
tmp = exp(c*d) ;
|
||||
x = a + b*tmp/(1 + tmp) ;
|
|
@ -1,113 +0,0 @@
|
|||
function [ ix2, temperedlogpost, loglik, bayestopt_] = ...
|
||||
SMC_samplers_initialization(TargetFun, xparam1, mh_bounds, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, oo_, NumberOfParticles)
|
||||
% function [ ix2, ilogpo2, ModelName, MetropolisFolder, FirstBlock, FirstLine, npar, NumberOfParticles, bayestopt_] = ...
|
||||
% SMC_samplers_initialization(TargetFun, xparam1, mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_,NumberOfParticles)
|
||||
% Draw in prior distribution to initialize samplers.
|
||||
%
|
||||
% INPUTS
|
||||
% o TargetFun [char] string specifying the name of the objective
|
||||
% function (tempered posterior kernel and likelihood).
|
||||
% o xparam1 [double] (p*1) vector of parameters to be estimated (initial values).
|
||||
% o mh_bounds [double] (p*2) matrix defining lower and upper bounds for the parameters.
|
||||
% o dataset_ data structure
|
||||
% o dataset_info dataset info structure
|
||||
% o options_ options structure
|
||||
% o M_ model structure
|
||||
% o estim_params_ estimated parameters structure
|
||||
% o bayestopt_ estimation options structure
|
||||
% o oo_ outputs structure
|
||||
%
|
||||
% OUTPUTS
|
||||
% o ix2 [double] (NumberOfParticles*npar) vector of starting points for different chains
|
||||
% o ilogpo2 [double] (NumberOfParticles*1) vector of initial posterior values for different chains
|
||||
% o iloglik2 [double] (NumberOfParticles*1) vector of initial likelihood values for different chains
|
||||
% o ModelName [string] name of the mod-file
|
||||
% o MetropolisFolder [string] path to the Metropolis subfolder
|
||||
% o bayestopt_ [structure] estimation options structure
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% None.
|
||||
|
||||
% Copyright © 2006-2022 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
%Initialize outputs
|
||||
ix2 = [];
|
||||
ilogpo2 = [];
|
||||
iloglik2 = [];
|
||||
ModelName = [];
|
||||
MetropolisFolder = [];
|
||||
|
||||
ModelName = M_.fname;
|
||||
if ~isempty(M_.bvar)
|
||||
ModelName = [ModelName '_bvar'];
|
||||
end
|
||||
|
||||
MetropolisFolder = CheckPath('dsmh',M_.dname);
|
||||
BaseName = [MetropolisFolder filesep ModelName];
|
||||
|
||||
npar = length(xparam1);
|
||||
|
||||
% Here we start a new DS Metropolis-Hastings, previous draws are discarded.
|
||||
disp('Estimation:: Initialization...')
|
||||
% Delete old dsmh files if any...
|
||||
files = dir([BaseName '_dsmh*_blck*.mat']);
|
||||
%if length(files)
|
||||
% delete([BaseName '_dsmh*_blck*.mat']);
|
||||
% disp('Estimation::smc: Old dsmh-files successfully erased!')
|
||||
%end
|
||||
% Delete old log file.
|
||||
file = dir([ MetropolisFolder '/dsmh.log']);
|
||||
%if length(file)
|
||||
% delete([ MetropolisFolder '/dsmh.log']);
|
||||
% disp('Estimation::dsmh: Old dsmh.log file successfully erased!')
|
||||
% disp('Estimation::dsmh: Creation of a new dsmh.log file.')
|
||||
%end
|
||||
fidlog = fopen([MetropolisFolder '/dsmh.log'],'w');
|
||||
fprintf(fidlog,'%% DSMH log file (Dynare).\n');
|
||||
fprintf(fidlog,['%% ' datestr(now,0) '.\n']);
|
||||
fprintf(fidlog,' \n\n');
|
||||
fprintf(fidlog,'%% Session 1.\n');
|
||||
fprintf(fidlog,' \n');
|
||||
prior_draw(bayestopt_,options_.prior_trunc);
|
||||
% Find initial values for the NumberOfParticles chains...
|
||||
options_=set_dynare_seed_local_options(options_,'default');
|
||||
fprintf(fidlog,[' Initial values of the parameters:\n']);
|
||||
disp('Estimation::dsmh: Searching for initial values...');
|
||||
ix2 = zeros(npar,NumberOfParticles);
|
||||
temperedlogpost = zeros(NumberOfParticles,1);
|
||||
loglik = zeros(NumberOfParticles,1);
|
||||
%stderr = sqrt(bsxfun(@power,mh_bounds.ub-mh_bounds.lb,2)/12)/10;
|
||||
for j=1:NumberOfParticles
|
||||
validate = 0;
|
||||
while validate == 0
|
||||
candidate = prior_draw()';
|
||||
% candidate = xparam1(:) + 0.001*randn(npar,1);%bsxfun(@times,stderr,randn(npar,1)) ;
|
||||
if all(candidate(:) >= mh_bounds.lb) && all(candidate(:) <= mh_bounds.ub)
|
||||
ix2(:,j) = candidate ;
|
||||
[temperedlogpost(j),loglik(j)] = tempered_likelihood(TargetFun,candidate,0.0,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_);
|
||||
if isfinite(loglik(j)) % if returned log-density is Inf or Nan (penalized value)
|
||||
validate = 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
fprintf(fidlog,' \n');
|
||||
disp('Estimation:: Initial values found!')
|
||||
skipline()
|
||||
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
function x = bseastr(s1,s2)
|
||||
|
||||
% Copyright © 2001-2017 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
m = size(s1,1) ;
|
||||
x = zeros(m,1) ;
|
||||
s1=upper(deblank(s1));
|
||||
s2=upper(deblank(s2));
|
||||
|
||||
for im = 1:m
|
||||
key = s1(im,:) ;
|
||||
h = size(s2,1) ;
|
||||
l = 1 ;
|
||||
while l <= h
|
||||
mid = round((h+l)/2) ;
|
||||
temp = s2(mid,:) ;
|
||||
if ~ strcmp(key,temp)
|
||||
for i = 1:min(length(key),length(temp))
|
||||
if temp(i) > key(i)
|
||||
h = mid - 1 ;
|
||||
break
|
||||
else
|
||||
l = mid + 1 ;
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
x(im) = mid ;
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue