diff --git a/.gitignore b/.gitignore index f3cdbd5e4f9ccfc7306e63c5866b594d0ecee657..1d868a00f9d19161547166037f991fa3a0ebc74b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # For checking that no file has been unduly ignored, run: -# $ git ls-files -i --exclude-per-directory=.gitignore +# $ git ls-files -i -c --exclude-per-directory=.gitignore # Any file that is displayed should be removed from the ignore list # (possibly by an exclusion rule beginning with an exclamation mark) @@ -75,13 +75,10 @@ doc/internals/ltxpng # DLL rules *.mex -*.oct -*.mexglx *.mexa64 -*.mexw32 *.mexw64 -*.mexmaci *.mexmaci64 +*.mexmaca64 /mex/matlab/ /mex/octave/ @@ -108,29 +105,25 @@ doc/internals/ltxpng # Windows !/windows/Makefile !/windows/deps/Makefile -windows/deps/lib32/ -windows/deps/lib64/ -windows/deps/lib32-msys2/ -windows/deps/lib64-msys2/ -windows/deps/matlab32/ -windows/deps/matlab64/ -windows/deps/mingw32/ -windows/deps/mingw64/ -windows/deps/octave32/ -windows/deps/octave64/ -windows/deps/sources32/ -windows/deps/sources64/ -windows/deps/tarballs/ -windows/exe/ -windows/7z/ -windows/zip/ +/windows/deps/lib64/ +/windows/deps/lib64-msys2/ +/windows/deps/matlab64/ +/windows/deps/mingw64/ +/windows/deps/octave64/ +/windows/deps/sources64/ +/windows/deps/tarballs/ +/windows/exe/ +/windows/7z/ +/windows/zip/ # MacOS stuff .DS_Store -macOS/pkg/ -macOS/deps/sources64/ -macOS/deps/tarballs/ -macOS/deps/lib64/ +/macOS/pkg/ +/macOS/deps/sources64/ +/macOS/deps/tarballs/ +/macOS/deps/lib64/ +!/macOS/Makefile +!/macOS/deps/Makefile # Emacs stuff scripts/dynare.elc @@ -147,9 +140,6 @@ scripts/dynare.elc *synctex.gz tests/reporting/tmpRepDir -# Julia Tests -tests/julia/rbc/rbc*.jl - # Octave variables saved when Octave crashes octave-workspace diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1086884ba49eb16c591c585d2fa7a40e0b5e7065..e1138d135ea463f43637a644b96f52cdbc272f9b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: GIT_SUBMODULE_STRATEGY: recursive TERM: linux - MATLAB_VERSION: R2022b + MATLAB_VERSION: R2023a OLD_MATLAB_VERSION: R2014a # The next stanza creates the version number used for the source tarball and the @@ -28,7 +28,7 @@ build_binaries: stage: build script: - autoreconf -si - - ./configure --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION PACKAGE_VERSION=$VERSION PACKAGE_STRING="dynare $VERSION" + - ./configure --with-matlab=/opt/MATLAB/$MATLAB_VERSION PACKAGE_VERSION=$VERSION PACKAGE_STRING="dynare $VERSION" - make -j $(nproc) LN_S="cp -p" artifacts: paths: @@ -56,7 +56,7 @@ pkg_source: - rm doc/manual/source/_static/mathjax && sed -i "/^mathjax_path *=/d" doc/manual/source/conf.py - 'for f in configure.ac preprocessor/configure.ac mex/build/matlab/configure.ac mex/build/octave/configure.ac; do sed -i "s/^AC_INIT(\[\(.*\)\],\s*\[\(.*\)\])/AC_INIT([\1], [$VERSION])/" $f; done' - autoreconf -si - - ./configure --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION + - ./configure --with-matlab=/opt/MATLAB/$MATLAB_VERSION - make dist artifacts: paths: @@ -67,16 +67,21 @@ pkg_source: pkg_windows: stage: pkg script: - - ln -s ~/tarballs windows/deps/ + - mkdir -p windows/deps/tarballs && cp /usr/lib/dynare-runner/matlab64-* windows/deps/tarballs/ - make -C windows + - rm windows/deps/tarballs/matlab64-* # No need to cache these files cache: - key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" - paths: - - windows/deps/sources64/ - - windows/deps/lib64/ - # We do not cache lib64-msys2, mingw64, octave64 and - # matlab64, because those are simply extracted from a tarball. It - # would be a waste of space and of (re-compression) time. + - key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" + paths: + - windows/deps/sources64/ + - windows/deps/lib64/ + # We do not cache lib64-msys2, mingw64, octave64 and + # matlab64, because those are simply extracted from a tarball. It + # would be a waste of space and of (re-compression) time. + - key: $CI_JOB_NAME + # This cache is shared between all branches, to save space + paths: + - windows/deps/tarballs/ artifacts: paths: - windows/exe/* @@ -118,14 +123,14 @@ test_matlab: extends: .test_matlab_template script: - autoreconf -si - - ./configure --disable-octave --with-matlab=/usr/local/MATLAB/$MATLAB_VERSION + - ./configure --disable-octave --with-matlab=/opt/MATLAB/$MATLAB_VERSION - make -j $(($(nproc) * 3 / 4)) -C tests check-matlab test_old_matlab: extends: .test_matlab_template script: - autoreconf -si - - ./configure --disable-octave --with-matlab=/usr/local/MATLAB/$OLD_MATLAB_VERSION + - ./configure --disable-octave --with-matlab=/opt/MATLAB/$OLD_MATLAB_VERSION - make -C mex/build/matlab clean - make -j $(nproc) -C mex/build/matlab - make -j $(($(nproc) * 3 / 4)) -C tests check-matlab diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5da7340488986e31ea4465bf3d13f9bdd2b9f738..6a69e5b6c5092e562a9c690d8d000cb53562b3d7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,11 +2,11 @@ ## Introduction -Hello from the Dynare Team! We're happy you're on this page because hopefully that means you're thinking of getting directly involved with the Dynare project. Herein, we outline how you can contribute to Dynare. Please read this document all the way through before contributing. +Hello from the Dynare Team! We’re happy you’re on this page because hopefully that means you’re thinking of getting directly involved with the Dynare project. Herein, we outline how you can contribute to Dynare. Please read this document all the way through before contributing. -Please follow the steps in the sections below in order. Note that, though we'd love for you to contribute code, you don't need to be a programmer to contribute to Dynare. You can report bugs, ask for enhancements, fix typos in the manual, contribute tests to the test suite, or do something we haven't thought of yet! +Please follow the steps in the sections below in order. Note that, though we’d love for you to contribute code, you don’t need to be a programmer to contribute to Dynare. You can report bugs, ask for enhancements, fix typos in the manual, contribute tests to the test suite, or do something we haven’t thought of yet! -If something is not clear, don't hesitate to ask if you can't find the answer online. You can contact us directly at [dev@dynare.org](mailto:dev@dynare.org). +If something is not clear, don’t hesitate to ask if you can’t find the answer online. You can contact us directly at [dev@dynare.org](mailto:dev@dynare.org). Please note that the repositories under the purview of this page are: @@ -20,13 +20,13 @@ Please note that the repositories under the purview of this page are: ## Making your Intentions Known -Before making changes to the codebase, it'd be helpful if you communicated your intentions with us. This will avoid double work and ensure that you don't contribute code that won't be included in Dynare for one reason or another. +Before making changes to the codebase, it’d be helpful if you communicated your intentions with us. This will avoid double work and ensure that you don’t contribute code that won’t be included in Dynare for one reason or another. ### Create your account on our GitLab instance All the development of Dynare happens in [GitLab](https://about.gitlab.com/), which is an integrated environment for storing code under git, keeping track of issues and milestones, and perform testing. The Dynare Team has its own instance of GitLab. -In order to work with us, you need to create your account on our GitLab instance on the [register page](https://git.dynare.org/users/sign_in). +In order to work with us, you need to create your account on our GitLab instance on the [register page](https://git.dynare.org/users/sign_in). Note that account requests are manually validated, so be prepared to wait for a couple of hours or days before your account is created; if your account request is rejected, do not hesitate to contact us directly. You will also need to register your SSH key in your GitLab profile if you want to contribute code. @@ -36,7 +36,7 @@ You can report bugs in both the stable and unstable versions of Dynare. Before r To report a bug in Dynare, simply open a Gitlab issue in the repository where the bug resides. For example, to report a bug in Dynare itself, go to the [Dynare repository issue page](https://git.dynare.org/Dynare/dynare/issues) and click on "New Issue." -The minimal information to add is a subject and a description of the steps needed to reproduce the bug. However, the most helpful description would also provide the code to reproduce the bug (often times a `.mod` file). The most helpful `.mod` file is a minimal, quick-running example that reproduces the bug, but we'll take anything that will help us squash a bug. +The minimal information to add is a subject and a description of the steps needed to reproduce the bug. However, the most helpful description would also provide the code to reproduce the bug (often times a `.mod` file). The most helpful `.mod` file is a minimal, quick-running example that reproduces the bug, but we’ll take anything that will help us squash a bug. To include short amounts of code, please paste it into the description box, using the appropriate [GitLab Flavored Markdown](https://docs.gitlab.com/ee/user/markdown.html) code. For larger amounds of code like `.mod` files, please create a new [GitLab snippet](https://git.dynare.org/dashboard/snippets) and provide the link in the description box. @@ -44,13 +44,13 @@ To include short amounts of code, please paste it into the description box, usin Issues are not only used to report bugs. They are also used to ask for improvements to the codebase or new features to Dynare in general. Please be descriptive when asking for improvements or new features. Links or references to papers or detailed examples are helpful. -Though our development priorities lay with those who finance Dynare and with what we think may most benefit the Dynare community, this does not mean we are closed to outside ideas for enhancements. On the contrary: we invite them! Moreover, if you are willing to program the enhancement you want, the odds of it being included in Dynare are much higher than if you needed us to do it. That said, it is best to create an issue with an enhancement idea **before** beginning the work. As stated above, this is important to avoid duplication of work and also because we wouldn't want you to take the time to work on something that would not end up being included in Dynare. +Though our development priorities lay with those who finance Dynare and with what we think may most benefit the Dynare community, this does not mean we are closed to outside ideas for enhancements. On the contrary: we invite them! Moreover, if you are willing to program the enhancement you want, the odds of it being included in Dynare are much higher than if you needed us to do it. That said, it is best to create an issue with an enhancement idea **before** beginning the work. As stated above, this is important to avoid duplication of work and also because we wouldn’t want you to take the time to work on something that would not end up being included in Dynare. ## Get to Coding! -So, now you've reported the bug or asked for an enhancemnt by creating a GitLab issue. That's already a great help. Thank you! +So, now you’ve reported the bug or asked for an enhancemnt by creating a GitLab issue. That’s already a great help. Thank you! -Now, if you want to go the extra mile, you'll volunteer to contribute code to fix the GitLab issue you created above. Once we've agreed that you'll do it, please do the following: +Now, if you want to go the extra mile, you’ll volunteer to contribute code to fix the GitLab issue you created above. Once we’ve agreed that you’ll do it, please do the following: 1. Clone the Dynare repository: * `git clone --recurse-submodules https://git.dynare.org/Dynare/dynare.git` @@ -63,7 +63,7 @@ Now, if you want to go the extra mile, you'll volunteer to contribute code to fi 1. Do your work, all the while respecting the [Dynare Coding Guidelines](https://git.dynare.org/Dynare/dynare/-/wikis/CodingGuidelines) 1. You may also want to have a look at the [coding resources](https://git.dynare.org/Dynare/dynare/-/wikis/CodingResources) -As you work, your forked repository will likely fall out of sync with the main Dynare repository as we'll be working in parallel. No matter. Follow these steps to ensure your changes will be merge-able when they're done: +As you work, your forked repository will likely fall out of sync with the main Dynare repository as we’ll be working in parallel. No matter. Follow these steps to ensure your changes will be merge-able when they’re done: 1. Get the changes from the main Dynare repository: * `git checkout master` @@ -74,7 +74,7 @@ As you work, your forked repository will likely fall out of sync with the main D * `git rebase origin/master` * This last command may cause a conflict. It is up to you to resolve this conflict. -Once you've made the changes necessary to fix the bug or add an enhancement, ensure that it has been rebased on the master branch (following the steps above), commit it, push it to your forked Dynare repository, and create a pull request: +Once you’ve made the changes necessary to fix the bug or add an enhancement, ensure that it has been rebased on the master branch (following the steps above), commit it, push it to your forked Dynare repository, and create a pull request: 1. Get the latest changes from Dynare and rebase your branch on top of them (see above) 1. Commit your changes: @@ -86,13 +86,13 @@ Once you've made the changes necessary to fix the bug or add an enhancement, ens ## Tests -The Dynare testsuite runs every time a commit is pushed, either in the official repository or in your personal repository, through [GitLab Continuous Integration](https://docs.gitlab.com/ee/ci/). It's how we quickly catch bugs that may have been introduced by changes made. +The Dynare testsuite runs every time a commit is pushed, either in the official repository or in your personal repository, through [GitLab Continuous Integration](https://docs.gitlab.com/ee/ci/). It’s how we quickly catch bugs that may have been introduced by changes made. -The output from the latest run of the test suite can be found in the `test_matlab` job associated to the [latest pipeline](https://git.dynare.org/Dynare/dynare/pipelines). This is also a good place to start fixing bugs. If you see a `.mod` file that doesn't run in the test suite and think you can fix it, create an issue and once you have the go ahead, go for it! +The output from the latest run of the test suite can be found in the `test_matlab` job associated to the [latest pipeline](https://git.dynare.org/Dynare/dynare/pipelines). This is also a good place to start fixing bugs. If you see a `.mod` file that doesn’t run in the test suite and think you can fix it, create an issue and once you have the go ahead, go for it! ### Integration tests -It's useful to contribute `.mod` files that test some aspect of Dynare that is not currently tested. A `.mod` file that runs into a bug is perfect. As the test suite currently takes several hours to run, we prefer you modify a current test to also create the bug you've found. If you can't do that, please add a new test that runs as quickly as possible. It will contain only those commands necessary to create the bug, nothing more. To contribute a test, after having made an issue and cloned and forked the repository as described above, do the following: +It’s useful to contribute `.mod` files that test some aspect of Dynare that is not currently tested. A `.mod` file that runs into a bug is perfect. As the test suite currently takes several hours to run, we prefer you modify a current test to also create the bug you’ve found. If you can’t do that, please add a new test that runs as quickly as possible. It will contain only those commands necessary to create the bug, nothing more. To contribute a test, after having made an issue and cloned and forked the repository as described above, do the following: 1. Modify the `MODFILES` variable in `tests/Makefile.am` with a line containing your test file name 1. If any ancillary files are needed to run your test, please include them in the `EXTRA_DIST` variable in `tests/Makefile.am` diff --git a/Makefile.am b/Makefile.am index ce8c90a7dc25cf245be1236e67b714146c8797ff..404e051a34851560d9ac11139237c74cc0306481 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,6 @@ ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = \ matlab \ - dynare++ \ contrib \ NEWS.md \ license.txt \ diff --git a/NEWS.md b/NEWS.md index 1a4fabe3f186383922836335ddd61b0d36c23f89..e544a56902294824a8a9423430fbb32b4d5025c8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,60 @@ +Announcement for Dynare 5.4 (on 2023-03-22) +=========================================== + +We are pleased to announce the release of Dynare 5.4. + +This maintenance release fixes various bugs. + +The Windows, macOS and source packages are already available for download at +[the Dynare website](https://www.dynare.org/download/). + +All users are strongly encouraged to upgrade. + +This release is compatible with MATLAB versions ranging from 8.3 (R2014a) to +9.14 (R2023a), and with GNU Octave version 8.1.0 (under Windows). + +Note for macOS users with an Apple Silicon processor, and who are also MATLAB +users: the official MATLAB version for use on those processors is still the +Intel version (running through Rosetta 2), so the official Dynare package for +download on our website is built for Intel only. However, since Mathworks has +released a beta version of MATLAB for Apple Silicon, we created a beta package +of Dynare that you can try with it. See this forum thread for more details: +https://forum.dynare.org/t/testers-wanted-release-of-dynare-5-x-beta-for-apple-silicon-m1-m2-chips/20499 + +Here is a list of the problems identified in version 5.3 and that have been +fixed in version 5.4: + +* Files installed through the Windows installer had too weak permissions and + could be modified by unpriviledged local users, if the default installation + location (`c:\dynare\`) had been chosen +* Estimation: + + the `load_results_after_load_mh` option would not find the location of the + results file + + the computation of prior/posterior statistics would crash if the value of + the `filter step_ahead` option was greater than 1 without requesting a + `forecast` or the `smoother` + + NaN or complex parameters returned by steady state files were not correctly + handled + + `analytical_derivation` could be triggered with `endogenous_prior` but + would not take the endogenous prior into account for the Jacobian and + Hessian +* OccBin: + + running the `calib_smoother` command with `smoother_inversion_filter` would + crash unless `likelihood_inversion_filter` was also specified + + running the piecewise Kalman smoother would crash if an error was + encountered during computation of the decision rules +* PAC equation estimation through iterative OLS would crash if the auxiliary + model contained a constant +* The variable label was incorrect for leads and lags of exogenous variables in + the display of decision rules and in the `model_info` command +* Declaring a `trend_var` variable while not having a `var(deflator=...)` + statement would cause the preprocessor to crash +* Macro processor: error messages following a `@#define`, `@#include` or + `@#includepath` directive could in some cases point to a line number off by 1 +* Perfect foresight simulations: the `debug` option would not preserve + sparsity, causing out of memory errors + + Announcement for Dynare 5.3 (on 2022-11-21) =========================================== diff --git a/README.md b/README.md index 36ea89126219aa1758f50b1d44ec5fa3c6a83fa4..2cd24b178d09aef1b6fe140f1b9d2022033b30f7 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ determine the type of your MATLAB/Octave installation, type: ```matlab >> computer ``` -at the MATLAB/Octave prompt. Under MATLAB, if it returns `PCWIN64`, `GLNX64` or -`MACI64`, then it is a 64-bit MATLAB; if it returns `PCWIN`, `MACI` or `GLNX`, +at the MATLAB/Octave prompt. Under MATLAB, if it returns `PCWIN64`, `GLNX64`, +`MACI64` or `MACA64` then it is a 64-bit MATLAB; if it returns `PCWIN`, `MACI` or `GLNX`, then it is a 32-bit MATLAB. Under Octave, if it returns a string that begins with `x86_64`, it is a 64-bit Octave; if the strings begins with `i686`, it is a 32-bit Octave. @@ -78,9 +78,9 @@ A number of tools and libraries are needed in order to recompile everything. You - [Flex](https://github.com/westes/flex), version 2.5.4 or later (only if you get the source through Git) - [Autoconf](https://www.gnu.org/software/autoconf/), version 2.62 or later (only if you get the source through Git) - [Automake](https://www.gnu.org/software/automake/), version 1.11.2 or later (only if you get the source through Git) -- [MAT File I/O library](https://sourceforge.net/projects/matio/), version 1.5 or later (if you want to compile Markov-Switching code, the estimation DLL, and the k-order DLL) +- [MAT File I/O library](https://sourceforge.net/projects/matio/), version 1.5 or later (if you want to compile Markov-Switching SBVAR code) - [SLICOT](http://www.slicot.org) (if you want to compile the Kalman steady state DLL) -- [GSL library](https://www.gnu.org/software/gsl/) (if you want to compile Markov-Switching code) +- [GSL library](https://www.gnu.org/software/gsl/) (if you want to compile Markov-Switching SBVAR code) - A decent LaTeX distribution (if you want to compile PDF documentation), ideally with Beamer - For building the reference manual: @@ -196,9 +196,11 @@ in the `tests` folder to delete files that were created by the run of the testsu All the prerequisites are packaged: -- `build-essential` (for gcc, g++ and make) +- `gcc` +- `g++` - `gfortran` -- `liboctave-dev` +- `make` +- `octave-dev` (or `liboctave-dev` on older Debian/Ubuntu releases) - `libboost-graph-dev` - `libgsl-dev` - `libmatio-dev` @@ -212,7 +214,6 @@ All the prerequisites are packaged: - `texlive-publishers` (for Econometrica bibliographic style) - `texlive-latex-extra` (for fullpage.sty) - `texlive-fonts-extra` (for ccicons) -- `texlive-latex-recommended` - `texlive-science` (for amstex) - `texlive-plain-generic` - `lmodern` (for macroprocessor PDF) @@ -225,7 +226,7 @@ All the prerequisites are packaged: You can install them all at once with: ```sh -apt install build-essential gfortran liboctave-dev libboost-graph-dev libgsl-dev libmatio-dev libslicot-dev libslicot-pic libsuitesparse-dev flex libfl-dev bison autoconf automake texlive texlive-publishers texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-plain-generic lmodern python3-sphinx tex-gyre latexmk libjs-mathjax doxygen x13as +apt install gcc g++ gfortran make octave-dev libboost-graph-dev libgsl-dev libmatio-dev libslicot-dev libslicot-pic libsuitesparse-dev flex libfl-dev bison autoconf automake texlive texlive-publishers texlive-latex-extra texlive-fonts-extra texlive-science texlive-plain-generic lmodern python3-sphinx tex-gyre latexmk libjs-mathjax doxygen x13as ``` If you use MATLAB, we strongly advise to also `apt install matlab-support` and confirm to rename the GCC libraries shipped with MATLAB to avoid possible conflicts with GCC libraries shipped by your distribution. @@ -397,84 +398,116 @@ adapted to a 32-bit MATLAB with the following modifications: currently not supported. ## macOS + Dynare supports both Intel and Apple Silicon chips and is compiled from source -using a [Homebrew](https://brew.sh/) toolchain. However, if you have a *M1*, -*M1 PRO*, *M1 MAX*, *M2* or *M2 PRO* processor, you need to make sure that you are not using the ARM -Homebrew packages. This is due to the fact that although MATLAB runs natively on -Intel, it is not yet available in an ARM version and therefore must be run with the -Intel compatibility layer called Rosetta 2. Accordingly, if you are on Apple Silicon -you need to compile Dynare under Rosetta 2 as well and use the Intel packages from -Homebrew. You can check this by e.g. running `which brew` which should point to -`/usr/local/bin/brew` and not to `/opt/homebrew/bin/brew`. In the steps below, we -create a temporary alias to ensure that `brew` points to the Intel packages. +using a [Homebrew](https://brew.sh/) toolchain. If you have an Apple silicon processor +(*M1/M2 PRO/MAX/ULTRA*), you can compile Dynare both for Intel's `x86_64` (using Rosetta 2) +as well as Apple's native `arm64` platform by using the corresponding Homebrew packages. +If you have an Intel chip you can only compile for `x86_64`. -For the following steps open Terminal.app and enter the commands listed below. +You can check the platform of your current Homebrew installation by e.g. running +`which brew` which should point to `/opt/homebrew/bin/brew` for `arm64` and to +`/usr/local/bin/brew` for `x86_64` systems. In the steps below, we +create a temporary environment variable `BREWDIR` to ensure that the correct packages are used. +The following commands install all requirements and Dynare from source. +They should be entered at the command prompt in Terminal.app. ### Preparatory work +- Install the Xcode Command Line Tools: +```sh +xcode-select --install +``` + - Install Rosetta 2 (Apple Silicon only): ```sh softwareupdate --install-rosetta --agree-to-license ``` -- Install the Xcode Command Line Tools: +- Install [Homebrew](https://brew.sh/): +Create environment variables for which platform you want to compile for, i.e. either `arm64` or `x86_64`: + +For `arm64` run the following commands: ```sh -xcode-select --install +export ARCH=arm64 +export BREWDIR=/opt/homebrew ``` -- Install [Homebrew](https://brew.sh/): +For `x86_64` run the following commands: +```sh +export ARCH=x86_64 +export BREWDIR=/usr/local +``` + +Install Homebrew using the environment variables: ```sh -arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +arch -$ARCH /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -The prefix `arch -x86_64` makes sure that you are using Rosetta 2 to install Homebrew. +The prefix `arch -arm64` or `arch -x86_64` makes sure that you are installing the correct packages. +Don't forget to run the displayed commands (**Next steps**) in the terminal to add Homebrew to your PATH. -- Apple Silicon only: Make a (temporary) alias to run `brew` under Rosetta 2: +If you have both Homebrew installations installed, make sure that you are accessing the correct packages by temporarily (!) prepending it to the path: ```sh -alias brew='arch -x86_64 /usr/local/bin/brew' -which brew -#brew: aliased to arch -x86_64 /usr/local/bin/brew +export PATH="$BREWDIR/bin:$PATH" ``` + - Install required Homebrew packages and link sphinx-doc: ```sh -brew install automake bison flex boost gcc gsl libmatio veclibfort octave sphinx-doc wget -brew link --force sphinx-doc +arch -$ARCH $BREWDIR/bin/brew install automake bison flex boost gcc gsl libmatio veclibfort octave sphinx-doc docutils wget +``` +If you want to compile the documentation, you need to link sphinx-doc: +```sh +arch -$ARCH $BREWDIR/bin/brew link --force sphinx-doc ``` +Otherwise add `--disable-doc` flag to the `configure` command below, if you want to skip this. -- Install [MacTeX](http://www.tug.org/mactex/index.html) using the universal installer. MacTeX runs natively on both ARM and Intel machines. On Apple Silicon, we need to put `pdflatex` and `bibtex` into our path: +- Install [MacTeX](http://www.tug.org/mactex/index.html) using the universal installer. MacTeX runs natively on both ARM and Intel machines. On Apple Silicon, it is advised to symlink `pdflatex` and `bibtex` into `/usr/local/bin`: ```sh -ln -s /Library/TeX/texbin/pdflatex /usr/local/bin/pdflatex -ln -s /Library/TeX/texbin/bibtex /usr/local/bin/bibtex +sudo ln -s /Library/TeX/texbin/pdflatex /usr/local/bin/pdflatex +sudo ln -s /Library/TeX/texbin/bibtex /usr/local/bin/bibtex ``` Alternatively, if you don’t want to install MacTeX, you should pass the `--disable-doc` flag to the `configure` command below. -- Install MATLAB and additional toolboxes. We recommend, but don't require, the following: Optimization, Global Optimization, Statistics and Machine Learning, Econometrics, and Control System. As there is no ARM version of MATLAB yet, Rosetta 2 will be used on Apple Silicon machines. Don't forget to run MATLAB at least once to make sure you have a valid license. +- Install MATLAB and additional toolboxes. +We recommend, but don't require, the following: Optimization, Global Optimization, Statistics and Machine Learning, Econometrics, and Control System. +For Apple Silicon: MATLAB offers a native Apple silicon version of R2022b as an open beta. You can sign up and install it (including a suitable Java 8 JRE, e.g. Amazon Corretto 8) using +[the official instructions](https://de.mathworks.com/support/apple-silicon-r2022b-beta.html). +Unfortunately, this version does not support yet the Optimization, Global Optimization and Econometrics toolboxes. +If you need these, please run the Intel version (under Rosetta 2) instead. +Don't forget to run MATLAB at least once to make sure you have a valid license. -- Compile and install SLICOT, needed for the `kalman_steady_state` MEX file. +- Create a folder for Dynare and its dependencies ```sh -mkdir -p $HOME/dynare/slicot -cd $HOME/dynare/slicot -wget https://deb.debian.org/debian/pool/main/s/slicot/slicot_5.0+20101122.orig.tar.gz +export DYNAREDIR=$HOME/dynare +``` + +- Compile and install SLICOT, needed for e.g. the `kalman_steady_state` MEX file. +```sh +mkdir -p $DYNAREDIR/slicot/lib +cd $DYNAREDIR/slicot +curl -O https://deb.debian.org/debian/pool/main/s/slicot/slicot_5.0+20101122.orig.tar.gz tar xf slicot_5.0+20101122.orig.tar.gz cd slicot-5.0+20101122 -make -j$(sysctl -n hw.ncpu) FORTRAN=gfortran OPTS="-O2" LOADER=gfortran lib -cp slicot.a /usr/local/lib/libslicot_pic.a +make -j$(sysctl -n hw.ncpu) FORTRAN=$BREWDIR/bin/gfortran OPTS="-O2" LOADER=gfortran lib +cp slicot.a $DYNAREDIR/slicot/lib/libslicot_pic.a make clean -make -j$(sysctl -n hw.ncpu) FORTRAN=gfortran OPTS="-O2 -fdefault-integer-8" LOADER=gfortran lib -cp slicot.a /usr/local/lib/libslicot64_pic.a +make -j$(sysctl -n hw.ncpu) FORTRAN=$BREWDIR/bin/gfortran OPTS="-O2 -fdefault-integer-8" LOADER=gfortran lib +cp slicot.a $DYNAREDIR/slicot/lib/libslicot64_pic.a cd $HOME/dynare ``` - Compile and install the X-13ARIMA-SEATS Seasonal Adjustment Program ```sh -mkdir -p $HOME/dynare/x13as -cd $HOME/dynare/x13as -wget https://www2.census.gov/software/x-13arima-seats/x13as/unix-linux/program-archives/x13as_asciisrc-v1-1-b59.tar.gz +mkdir -p $DYNAREDIR/x13as +cd $DYNAREDIR/x13as +curl -O https://www2.census.gov/software/x-13arima-seats/x13as/unix-linux/program-archives/x13as_asciisrc-v1-1-b59.tar.gz tar xf x13as_asciisrc-v1-1-b59.tar.gz sed -i '' 's/-static//g' makefile.gf -make -j$(sysctl -n hw.ncpu) -f makefile.gf FC=gfortran LINKER=gfortran FFLAGS="-O2 -std=legacy" PROGRAM=x13as -cp x13as /usr/local/bin/x13as +make -j$(sysctl -n hw.ncpu) -f makefile.gf FC=$BREWDIR/bin/gfortran LINKER=$BREWDIR/bin/gcc-13 FFLAGS="-O2 -std=legacy" LDFLAGS=-static-libgcc LIBS="$BREWDIR/lib/gcc/current/libgfortran.a /$BREWDIR/lib/gcc/current/libquadmath.a" PROGRAM=x13as +mkdir -p $HOME/.local/bin +cp x13as $HOME/.local/bin/x13as cd ; x13as ``` @@ -482,33 +515,52 @@ x13as ### Compile Dynare from source The following commands will download the Dynare source code and compile it. They should be entered at the command prompt in Terminal.app from the -folder where you want Dynare installed. Apple Silicon: make sure `brew` -points towards `/usr/local/bin/brew` (see above). +folder where you want Dynare installed. - Prepare the Dynare sources for the unstable version: ```sh -mkdir -p $HOME/dynare/unstable -git clone --recurse-submodules https://git.dynare.org/Dynare/dynare.git $HOME/dynare/unstable -cd $HOME/dynare/unstable -arch -x86_64 autoreconf -si +mkdir -p $DYNAREDIR/unstable +git clone --recurse-submodules https://git.dynare.org/Dynare/dynare.git $DYNAREDIR/unstable +cd $DYNAREDIR/unstable +arch -$ARCH autoreconf -si ``` You can also choose a specific version of Dynare by checking out the corresponding branch or a specific tag with git. - Configure Dynare from the source directory: ```sh -arch -x86_64 ./configure CC=gcc-12 CXX=g++-12 CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib LEX=/usr/local/opt/flex/bin/flex YACC=/usr/local/opt/bison/bin/bison --with-matlab=/Applications/MATLAB_R2021b.app +arch -$ARCH ./configure --prefix=$BREWDIR CC=gcc-13 CXX=g++-13 CPPFLAGS=-I$BREWDIR/include LDFLAGS=-L$BREWDIR/lib LEX=$BREWDIR/opt/flex/bin/flex YACC=$BREWDIR/opt/bison/bin/bison --with-slicot=$DYNAREDIR/slicot --with-matlab=/Applications/MATLAB_R2022b_Beta.app ``` -where you need to adapt the path to MATLAB. If you don’t have MATLAB, simply replace `--with-matlab=<…>` by `--disable-matlab`. Check the output of the command whether Dynare is configured for building everything except the internal docs of Dynare and M2HTML. +where you need to adapt the path to MATLAB. If you don’t have MATLAB, simply replace `--with-matlab=<…>` by `--disable-matlab`. +Similarly, if you don't want to compile for Octave add a `--disable-octave` flag. +Check the output of the command whether Dynare is configured for building everything except the internal docs of Dynare and M2HTML. - Compile: ```sh -arch -x86_64 make -j$(sysctl -n hw.ncpu) +arch -$ARCH make -j$(sysctl -n hw.ncpu) +``` +If no errors occured, you are done. Dynare is now ready to use. +If you additionally want to compile the documentation run: +```sh +arch -$ARCH make pdf +arch -$ARCH make html ``` ### Optional: pass the full PATH to MATLAB to run system commands -If you start MATLAB from a terminal, you will get the PATH inherited from the shell. However, when you click on the icon in macOS, you are not running at the terminal: the program is run by launcher, which does not go through a shell login session. You get the system default PATH which includes `/usr/bin:/bin:/usr/sbin:/sbin`, but not `/usr/local/bin` or `$HOME/.local/bin`. So if you want to use system commands like `pdflatex` or `x13as` you should either call them by their full path (e.g `/Library/TeX/texbin/pdflatex`) or append the PATH in MATLAB by running `setenv('PATH', [getenv('PATH') ':/usr/local/bin:$HOME/.local/bin:/Library/TeX/texbin']);`. Alternatively, you can create a `startup.m` file or change the system default PATH in the `/etc/paths` file. +If you start MATLAB from a terminal, you will get the PATH inherited from the shell. +However, when you click on the application icon in macOS, you are not running at the terminal level: +the program is run by launcher, which does not go through a shell login session. +In other words, you get the system default PATH which includes `/usr/bin:/bin:/usr/sbin:/sbin`, but not `/usr/local/bin` or `$HOME/.local/bin`. +So if you want to use system commands like `pdflatex` or `x13as` you should either call them by their full path (e.g `/Library/TeX/texbin/pdflatex`) +or append the PATH in MATLAB by running `setenv('PATH', [getenv('PATH') ':/usr/local/bin:$HOME/.local/bin:/Library/TeX/texbin']);`. +Alternatively, you can create a `startup.m` file or change the system default PATH in the `/etc/paths` file. -Tested on -- macOS Monterey 12.1 (Apple M1 Virtual Machine) -- macOS Monterey 12.1 (MacBook Air Intel) -- macOS Monterey 12.1 (MacBook Air M1) +### Optional: pass the full PATH to MATLAB to run system commands +If you start MATLAB from a terminal, you will get the PATH inherited from the shell. +However, when you click on the application icon in macOS, you are not running at the terminal level: +the program is run by launcher, which does not go through a shell login session. +In other words, you get the system default PATH which includes `/usr/bin:/bin:/usr/sbin:/sbin`, but not `/usr/local/bin` or `$HOME/.local/bin`. +So if you want to use system commands like `pdflatex` or `x13as` you should either call them by their full path (e.g `/Library/TeX/texbin/pdflatex`) or append the PATH in MATLAB by running `setenv('PATH', [getenv('PATH') ':/usr/local/bin:$HOME/.local/bin:/Library/TeX/texbin']);`. +Alternatively, you can create a `startup.m` file or change the system default PATH in the `/etc/paths` file. + +Last tested on: +- macOS Ventura 13.3.1 (MacBook Air M1, MacBook Pro M2 MAX, M2 Virtual Machine using Parallels, Intel Virtual Machine using Quickemu) diff --git a/configure.ac b/configure.ac index bba5730b7326be3c4135a0b9709c0fdada5a114e..2cc60101c88f6407be7ff5f361a3fa0b616616c2 100644 --- a/configure.ac +++ b/configure.ac @@ -24,34 +24,8 @@ AM_INIT_AUTOMAKE([1.11 -Wall -Wno-portability foreign no-dist-gzip dist-xz tar-p AC_CONFIG_SUBDIRS([preprocessor]) +# For setting EXEEXT, needed by top-level Makefile.am AC_PROG_CC -AC_PROG_CXX - -AC_CANONICAL_HOST -case ${host_os} in - *cygwin*) - AC_MSG_WARN([You are compiling for the Cygwin target. This means that the preprocessor will]) - AC_MSG_WARN([not run from MATLAB unless you add the Cygwin DLL to the path.]) - AC_MSG_WARN([This is probably not what you want. Consider using a MinGW cross-compiler.]) - if test -z "$F77"; then - # On Cygwin 1.7, g77 comes has version 3, and is not compatible with default gcc/g++ which has version 4 - # And by default, the AC_PROG_F77 will pick up g77 if it is present (even if gfortran is also here) - F77=gfortran - fi - ;; -esac - -# Use C++ for testing headers -AC_LANG([C++]) - -AM_CXXFLAGS="-std=gnu++20 -Wall -Wno-dangling-else -Wextra -Wno-unused-parameter -Wold-style-cast" -AC_SUBST([AM_CXXFLAGS]) - -# If default 'ar' is not available, try to find one with a host prefix (see ticket #145) -AC_CHECK_PROGS([AR], [ar ${host_alias}-ar]) - -AC_PROG_RANLIB -AM_PROG_AR AX_PROG_LN_S diff --git a/doc/Makefile.am b/doc/Makefile.am index f16874bbbb282f7cd98d3d60256c5660651831c6..925ed8cf0bcc904f315ab6149a2766f3e9014649 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = parallel internals gsa dseries-and-reporting if ENABLE_DOC SUBDIRS += manual -pdf-local: guide.pdf bvar-a-la-sims.pdf dr.pdf +pdf-local: guide.pdf bvar-a-la-sims.pdf dr.pdf sylvester.pdf tl.pdf endif EXTRA_DIST = guide.tex guide.bbl bibmad.sty bvar-a-la-sims.tex dr.tex dr.bib dynare.plots @@ -21,6 +21,14 @@ dr.pdf: dr.tex $(PDFLATEX) dr $(PDFLATEX) dr +sylvester.pdf: sylvester.tex + $(PDFLATEX) sylvester + $(PDFLATEX) sylvester + +tl.pdf: tl.tex + $(PDFLATEX) tl + $(PDFLATEX) tl + clean-local: # Do not delete guide.bbl which is not autogenerated rm -f *~ *.pdf *.log *.aux *.out *.blg dr.bbl diff --git a/doc/bvar-a-la-sims.tex b/doc/bvar-a-la-sims.tex index e8c518d1944924d847efd2a66c473196c864a6d7..df48a0b2b49b8ace387843d7ec0e4352997d1ac6 100644 --- a/doc/bvar-a-la-sims.tex +++ b/doc/bvar-a-la-sims.tex @@ -26,7 +26,7 @@ }} \author{S\'ebastien Villemot\thanks{Paris School of Economics and - CEPREMAP.} \and Johannes Pfeifer\thanks{Universität der Bundeswehr München. E-mail: \href{mailto:johannes.pfeifer@unibw.de}{\texttt{johannes.pfeifer@unibw.de}}.}} + CEPREMAP.} \and Johannes Pfeifer\thanks{University of the Bundeswehr Munich. E-mail: \href{mailto:johannes.pfeifer@unibw.de}{\texttt{johannes.pfeifer@unibw.de}}.}} \date{First version: September 2007 \hspace{1cm} This version: May 2017} \maketitle diff --git a/doc/dr.tex b/doc/dr.tex index 65559c68fbee733efe00aabdf4af179664735e5e..71abf27f38dc77e20f5247f77f241a803f7ecbb0 100644 --- a/doc/dr.tex +++ b/doc/dr.tex @@ -650,7 +650,7 @@ equation is: In the general case, this equation is a specialized Sylvester equation, which can be solved using the algorithm proposed by \citet{kamenik:2004}\footnote{This paper is distributed with Dynare, in the - \texttt{sylvester.pdf} file under the Dynare++ documentation directory.}. + \texttt{sylvester.pdf} file under the documentation directory.}. \bibliographystyle{elsarticle-harv} \bibliography{dr} diff --git a/doc/manual/source/bibliography.rst b/doc/manual/source/bibliography.rst index 9209c3942b40264fec3add3ee32473e3a5dd90a5..7591b382a0fd950856e3f552997845583a4961c0 100644 --- a/doc/manual/source/bibliography.rst +++ b/doc/manual/source/bibliography.rst @@ -82,5 +82,5 @@ Bibliography * Smets, Frank and Rafael Wouters (2003): “An Estimated Dynamic Stochastic General Equilibrium Model of the Euro Area,” *Journal of the European Economic Association*, 1(5), 1123–1175. * Stock, James H. and Mark W. Watson (1999). “Forecasting Inflation,”, *Journal of Monetary Economics*, 44(2), 293–335. * Uhlig, Harald (2001): “A Toolkit for Analysing Nonlinear Dynamic Stochastic Models Easily,” in *Computational Methods for the Study of Dynamic Economies*, Eds. Ramon Marimon and Andrew Scott, Oxford University Press, 30–61. -* U.S. Census Bureau (2017): “X-13 ARIMA-SEATS Reference Manual”. +* U.S. Census Bureau (2020): “X-13 ARIMA-SEATS Reference Manual, Version 1.1”, Center for Statistical Research and Methodology, U.S. Census Bureau, https://www.census.gov/data/software/x13as.html * Villemot, Sébastien (2011): “Solving rational expectations models at first order: what Dynare does,” *Dynare Working Papers*, 2, CEPREMAP. diff --git a/doc/manual/source/index.rst b/doc/manual/source/index.rst index f1d0edb8273e726575fad40f9dcf09636ef9dcb8..54ff1b8f68c20632570f033315cc646a8161dd49 100644 --- a/doc/manual/source/index.rst +++ b/doc/manual/source/index.rst @@ -9,7 +9,7 @@ Currently the development team of Dynare is composed of: * Frédéric Karamé (Le Mans Université, Gains and CEPREMAP) * Junior Maih (Norges Bank) * Willi Mutschler (University of Tübingen) -* Johannes Pfeifer (Universität der Bundeswehr München) +* Johannes Pfeifer (University of the Bundeswehr Munich) * Marco Ratto (European Commission, Joint Research Centre - JRC) * Normann Rion (CY Cergy Paris Université and CEPREMAP) * Sébastien Villemot (CEPREMAP) diff --git a/doc/manual/source/installation-and-configuration.rst b/doc/manual/source/installation-and-configuration.rst index f1336c3a9752990f87233d0e4cdc15055ce728e5..eab088734788eff16cbddeda5b40f8132defe021 100644 --- a/doc/manual/source/installation-and-configuration.rst +++ b/doc/manual/source/installation-and-configuration.rst @@ -14,8 +14,8 @@ compilation steps are necessary in that case. In order to run Dynare, you need one of the following: -* MATLAB, any version ranging from 8.3 (R2014a) to 9.13 (R2022b); -* GNU Octave, any version ranging from 6.2.0 to 8.1.0, with the statistics package +* MATLAB, any version ranging from 8.3 (R2014a) to 9.14 (R2023a); +* GNU Octave, any version ranging from 6.2.0 to 8.2.0, with the statistics package from `Octave-Forge`_. Note however that the Dynare installer for Windows requires a more specific version of Octave, as indicated on the download page. @@ -200,7 +200,7 @@ With Octave The compiler can be installed via Homebrew_. In a terminal, run:: - brew install gcc-12 + brew install gcc Configuration ============= diff --git a/doc/manual/source/running-dynare.rst b/doc/manual/source/running-dynare.rst index 0e0bc48390f7a0e87cceaa460661b350cdc46b56..21f87f7310af67132c0dc312823b73758f76c9a4 100644 --- a/doc/manual/source/running-dynare.rst +++ b/doc/manual/source/running-dynare.rst @@ -315,7 +315,7 @@ by the ``dynare`` command. Prevent Dynare from printing the output of the steps leading up to the preprocessor as well as the preprocessor output itself. - .. option:: mexext=mex|mexw32|mexw64|mexmaci64|mexa64 + .. option:: mexext=mex|mexw64|mexmaci64|mexmaca64|mexa64 The mex extension associated with your platform to be used when compiling output associated with :opt:`use_dll`. @@ -363,7 +363,8 @@ by the ``dynare`` command. For local execution under Windows operating system, set ``parallel_use_psexec=false`` to use ``start`` instead of ``psexec``, to properly allocate affinity when there are - more than 32 cores in the local machine. [default=true] + more than 32 cores in the local machine. This option is also helpful if + ``psexec`` cannot be executed due to missing admininstrator privileges. [default=true] .. option:: -DMACRO_VARIABLE[=MACRO_EXPRESSION] diff --git a/doc/manual/source/the-configuration-file.rst b/doc/manual/source/the-configuration-file.rst index 05ade49cb88c11cb5257601ece9943e8a51e9d85..3d2383c50d2ac2b3d1cd6475831dc04d4b511279 100644 --- a/doc/manual/source/the-configuration-file.rst +++ b/doc/manual/source/the-configuration-file.rst @@ -270,7 +270,9 @@ lines starting with a hashtag (#). .. option:: MatlabOctavePath = PATH_AND_FILE The path to the MATLAB or Octave executable. The default value - is ``matlab``. + is ``matlab`` as MATLAB's executable is typically in the %PATH% environment + variable. When using full paths on Windows, you may need to enclose the path + in quoted strings, e.g. ``MatlabOctavePath="C:\Program Files\MATLAB\R2023a\bin\matlab.exe"`` .. option:: NumberOfThreadsPerJob = INTEGER @@ -323,7 +325,9 @@ Windows Step-by-Step Guide ========================== This section outlines the steps necessary on most Windows systems to -set up Dynare for parallel execution. +set up Dynare for parallel execution. Note that the steps 3 to 6 are +required unless parallel execution is confined to a local pool +with the ``parallel_use_psexec=false`` option. 1. Write a configuration file containing the options you want. A mimimum working example setting up a cluster consisting of two diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index 1b4a76ad2e8262ff422388167bdd0ec6384a134b..999e689b21c26c36bfceb630719d3c8bd7c722fe 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -3586,9 +3586,7 @@ speed-up on large models. problem, it subsequently tries a homotopy technique (unless the ``no_homotopy`` option is given). Concretely, this technique consists in dividing the problem into smaller steps by diminishing the size of shocks - and increasing them progressively until the problem converges. Note that - the homotopy technique is not implemented for purely forward or backward - models. + and increasing them progressively until the problem converges. *Options* @@ -3625,8 +3623,9 @@ speed-up on large models. ``0`` - Newton method to solve simultaneously all the equations for - every period, using sparse matrices (Default). + Use a Newton algorithm with a direct sparse LU solver at each + iteration, applied on the stacked system of all the equations at + every period (Default). ``1`` @@ -3702,21 +3701,69 @@ speed-up on large models. This option tells Dynare to not try a homotopy technique (as described above) if the problem cannot be solved directly. - .. option:: homotopy_alt_starting_point - - When the homotopy technique is tried (as described above), Dynare first - tries to reduce the size of the shock in order to get a successful - simulation on which to build upon for simulating a shock of the true - size. However, if an ``endval`` block is present (*i.e.* if the terminal - state differs from the initial state), there are two ways of reducing - the size of the shock. By default, Dynare will perform this reduction by - computing a simulation whose initial state is closer to the target - terminal state; in other words, it will implicitly modify the contents - of the ``initval`` and ``shocks`` blocks to make them closer to the the - contents of the ``endval`` block. If this option is set, Dynare will do - the opposite: it will implicitly modify the contents of the ``endval`` - and ``shocks`` blocks to make them closer to the contents of the - ``initval`` block. + .. option:: homotopy_initial_step_size = DOUBLE + + Specifies which share of the shock should be applied in the first + iteration of the homotopy procedure. This option is useful when it is + known that immediately trying 100% of the shock will fail, so as to save + computing time. Must be between ``0`` and ``1``. Default: ``1``. + + .. option:: homotopy_min_step_size = DOUBLE + + The homotopy procedure halves the size of the step whenever there is + a failure. This option specifies the minimum step size under which the + homotopy procedure is considered to have failed. Default: ``0.001``. + + .. option:: homotopy_step_size_increase_success_count = INTEGER + + Specifies after how many consecutive successful iterations the homotopy + procedure should double the size of the step. A zero value means that + the step size should never be increased. Default: ``3``. + + .. option:: homotopy_linearization_fallback + + Whenever the homotopy procedure is not able to find a solution for 100% + of the shock, but is able to find one for a smaller share, instructs + Dynare to compute an approximate solution by rescaling the solution + obtained for a fraction of the shock, as if the reaction of the model to + the shock was a linear function of the size of that shock. More + formally, if :math:`s` is the share of the shock applied (between + :math:`0` and :math:`1`), :math:`y(s)` is the value of a given + endogenous variable at a given period as a function of :math:`s` (in + particular, :math:`y(1)` corresponds to the exact solution of the + problem), and :math:`s^*` is the greatest share of the shock for which + the homotopy procedure has been able to find a solution, then the approximate + solution returned is :math:`\frac{y(s^*)-y(0)}{s^*}`. + + .. option:: homotopy_marginal_linearization_fallback [= DOUBLE] + + Whenever the homotopy procedure is not able to find a solution for 100% + of the shock, but is able to find one for a smaller share, instructs + Dynare to compute an approximate solution obtained by rescaling the + solution obtained for a fraction of the shock, obtained as if the + reaction of the model to the shock was, at the margin, a linear function + of the size of that shock. More formally, if :math:`s` is the share of + the shock applied (between :math:`0` and :math:`1`), :math:`y(s)` is the + value of a given endogenous variable at a given period as a function of + :math:`s` (in particular, :math:`y(1)` corresponds to the exact solution + of the problem), :math:`s^*` is the greatest share of the shock for + which the homotopy procedure has been able to find a solution, and + :math:`\epsilon` is a small step size, then the approximate solution + returned is + :math:`y(s^*)+(1-s^*)\frac{y(s^*)-y(s^*-\epsilon)}{\epsilon}`. The value + of :math:`\epsilon` is ``0.01`` by default, but can be modified by + passing some other value to the option. + + .. option:: homotopy_max_completion_share = DOUBLE + + Instructs Dynare, within the homotopy procedure, to not try to compute + the solution for a greater share than the one given as the option value. + This option only makes sense when used in conjunction with either the + ``homotopy_linearization_fallback`` or the + ``homotopy_marginal_linearization_fallback`` option. It is typically + used in situations where it is known that homotopy will fail to go + beyond a certain point, so as to save computing time, while at the same + time getting an approximate solution. .. option:: markowitz = DOUBLE @@ -3822,9 +3869,56 @@ speed-up on large models. .. option:: linear_approximation Solves the linearized version of the perfect foresight - model. The model must be stationary. Only available with option + model. The model must be stationary and a steady state + needs to be provided. Linearization is conducted about the + last defined steady state, which can derive from ``initval``, + ``endval`` or a subsequent ``steady``. Only available with option ``stack_solve_algo==0`` or ``stack_solve_algo==7``. + .. option:: endval_steady + + In scenarios with a permanent shock, specifies that the terminal + condition is a steady state, even if the ``steady`` command has not been + called after the ``endval`` block. As a consequence, the + ``perfect_foresight_solver`` command will compute the terminal steady + state itself (given the value of the exogenous variables given in the + ``endval`` block). In practice, this option is useful when the permanent + shock is very large, in which case the homotopy procedure inside + ``perfect_foresight_solver`` will find both the terminal steady state + and the transitional dynamics within the same loop (which is less costly + than first computing the terminal steady state by homotopy, then + computing the transitional dynamics by homotopy). + + .. option:: steady_solve_algo = INTEGER + + See :ref:`solve_algo <solvalg>`. Used when computing the terminal steady + state when option ``endval_steady`` has been specified to the + ``perfect_foresight_setup`` command. + + .. option:: steady_tolf = DOUBLE + + See :ref:`tolf <steady_tolf>`. Used when computing the terminal steady + state when option ``endval_steady`` has been specified to the + ``perfect_foresight_setup`` command. + + .. option:: steady_tolx = DOUBLE + + See :ref:`tolx <steady_tolx>`. Used when computing the terminal steady + state when option ``endval_steady`` has been specified to the + ``perfect_foresight_setup`` command. + + .. option:: steady_maxit = INTEGER + + See :ref:`maxit <steady_maxit>`. Used when computing the terminal steady + state when option ``endval_steady`` has been specified to the + ``perfect_foresight_setup`` command. + + .. option:: steady_markowitz = DOUBLE + + See :ref:`markowitz <steady_markowitz>`. Used when computing the + terminal steady state when option ``endval_steady`` has been specified + to the ``perfect_foresight_setup`` command. + *Output* The simulated endogenous variables are available in global matrix @@ -4017,7 +4111,9 @@ and ``endval`` blocks which are given a special ``learnt_in`` option. always a steady state. Hence, it will recompute the terminal steady state as many times as the anticipation about the terminal condition changes. In particular, the information about endogenous variables that may be given in - the ``endval`` block is ignored. + the ``endval`` block is ignored. Said otherwise, the equivalent of option + ``endval_steady`` of the ``perfect_foresight_setup`` command is always + implicitly enabled. *Options* @@ -4055,33 +4151,12 @@ and ``endval`` blocks which are given a special ``learnt_in`` option. the name of the variable on the first line and ``s`` on the second line. Of course, values in cells corresponding to ``t<s`` are ignored. - .. option:: solve_algo = INTEGER - - See :ref:`solve_algo <solvalg>`. Used when computing the terminal steady state. - - .. option:: tolf = DOUBLE - - See :ref:`tolf <steady_tolf>`. Used when computing the terminal steady state. - - .. option:: tolx = DOUBLE - - See :ref:`tolx <steady_tolx>`. Used when computing the terminal steady state. - - .. option:: maxit = INTEGER - - See :ref:`maxit <steady_maxit>`. Used when computing the terminal steady state. - - .. option:: markowitz = DOUBLE - - See :ref:`markowitz <steady_markowitz>`. Used when computing the terminal steady state. - *Output* ``oo_.exo_simul`` and ``oo_.endo_simul`` are initialized before the simulation. Temporary shocks are stored in ``oo_.pfwee.shocks_info``, terminal conditions for exogenous variables are stored in - ``oo_.pfwee.terminal_info``, and terminal steady states are stored in - ``oo_.pfwee.terminal_steady_state``. + ``oo_.pfwee.terminal_info``. *Example* @@ -4170,16 +4245,7 @@ and ``endval`` blocks which are given a special ``learnt_in`` option. *Options* This command accepts all the options of :comm:`perfect_foresight_solver`, - with the same semantics, plus the following ones: - - .. option:: terminal_steady_state_as_guess_value - - By default, the initial guess for the computation of the path of - endogenous is the initial steady state (when using the information set - from period 1) or the previously simulated path (when using an - information set that is different from that of period 1). When this - option is given, the initial guess is instead the terminal steady - state. + with the same semantics, plus the following one: .. option:: constant_simulation_length @@ -4196,7 +4262,9 @@ and ``endval`` blocks which are given a special ``learnt_in`` option. *Output* The simulated paths of endogenous variables are available in - ``oo_.endo_simul``. + ``oo_.endo_simul``. The terminal steady state values corresponding to the + last period of the information set are available in ``oo_.steady_state`` + and ``oo_.exo_steady_state``. .. matvar:: oo_.pfwee.shocks_info @@ -4219,17 +4287,6 @@ and ``endval`` blocks which are given a special ``learnt_in`` option. the terminal condition for exogenous indexed ``k``, as anticipated from period ``s``, is stored in ``oo_.pfwee.terminal_info(k,s)``. -.. matvar:: oo_.pfwee.terminal_steady_state - - |br| This variable stores the terminal steady states for endogenous - variables used during perfect foresight simulations with expectation - errors, after :comm:`perfect_foresight_with_expectation_errors_setup` has - been run. It is a matrix, whose lines correspond to endogenous variables - (in declaration order), and whose columns correspond to informational time. - In other words, the terminal steady state for endogenous indexed ``k``, as - anticipated from period ``s``, is stored in - ``oo_.pfwee.terminal_steady_state(k,s)``. - .. _stoch-sol: Stochastic solution and simulation @@ -4591,7 +4648,7 @@ Computing the stochastic solution Uses the default solver for Sylvester equations (``gensylv``) based on Ondra Kamenik’s algorithm (see `here - <https://www.dynare.org/assets/dynare++/sylvester.pdf>`__ + <https://www.dynare.org/assets/team-presentations/sylvester.pdf>`__ for more information). ``fixed_point`` diff --git a/doc/manual/source/time-series.rst b/doc/manual/source/time-series.rst index 375dea32300e3a825cbef6c28160f87a06019b86..f57b524990fa2f0e92d6bf63f1970c503cdec617 100644 --- a/doc/manual/source/time-series.rst +++ b/doc/manual/source/time-series.rst @@ -15,7 +15,7 @@ class and methods for dates. Below, you will first find the class and methods used for creating and dealing with dates and then the class used for using time series. Dynare also provides an interface to the X-13 ARIMA-SEATS seasonal adjustment program produced, distributed, and -maintained by the US Census Bureau (2017). +maintained by the U.S. Census Bureau (2020). Dates @@ -717,7 +717,7 @@ The dates class |br| Overloads the MATLAB/Octave ``mtimes`` operator (``*``). ``A`` and ``B`` are respectively expected to be a - ``dseries`` object and a scalar integer. Returns ``dates`` + ``dates`` object and a scalar integer. Returns ``dates`` object ``A`` replicated ``B`` times. *Example* @@ -1025,7 +1025,7 @@ The dseries class ``.xls/.xlsx`` (Octave only supports ``.xlsx`` files and the `io <https://octave.sourceforge.io/io/>`__ package from Octave-Forge must be installed). The extension of the file - should be explicitly provided. + should be explicitly provided. A typical ``.m`` file will have the following form:: @@ -1052,10 +1052,10 @@ The dseries class typically usefull if ``INIT__`` is not provided in the data file. - If an ``.xlsx`` file is used, the first row should be a header - containing the variable names. The first column may contain date - information that must correspond to a valid date format recognized - by Dynare. If such date information is specified in the first column, + If an ``.xlsx`` file is used, the first row should be a header + containing the variable names. The first column may contain date + information that must correspond to a valid date format recognized + by Dynare. If such date information is specified in the first column, its header name must be left empty. .. construct:: dseries (DATA_MATRIX[,INITIAL_DATE[,LIST_OF_NAMES[,TEX_NAMES]]]) @@ -1963,6 +1963,13 @@ The dseries class |br| Returns the last period where all the variables in ``dseries`` object ``A`` are observed (non NaN). + .. dseriesmethod:: f = lastobservedperiods (A) + + |br| Returns for each variable the last period without missing + observations in ``dseries`` object ``A``. Output argument ``f`` is a + structure, each field name is the name of a variable in ``A``, each field + content is a singleton ``date`` object. + .. dseriesmethod:: B = lead (A[, p]) lead_ (A[, p]) @@ -2946,8 +2953,8 @@ X-13 ARIMA-SEATS interface |br| The x13 class provides a method for each X-13 command as documented in the X-13 ARIMA-SEATS reference manual (`x11`, - `automdl`, `estimate`, ...), options can then be passed by - key/value pairs. The ``x13`` class has 22 members: + `automdl`, `estimate`, ...). The respective options (see Chapter 7 of U.S. Census Bureau (2020)) + can then be passed by key/value pairs. The ``x13`` class has 22 members: :arg y: ``dseries`` object with a single variable. :arg x: ``dseries`` object with an arbitrary number of variables (to be used in the REGRESSION block). @@ -2991,7 +2998,7 @@ X-13 ARIMA-SEATS interface same time span. - The Following methods allow to set sequence of X-13 commands, write an `.spc` file and run the X-13 binary: + The following methods allow to set sequence of X-13 commands, write an `.spc` file, and run the X-13 binary: .. x13method:: A = arima (A, key, value[, key, value[, [...]]]) @@ -3026,7 +3033,10 @@ X-13 ARIMA-SEATS interface Interface to the ``transform`` command, see the X-13 ARIMA-SEATS reference manual. All the options must be passed - by key/value pairs. + by key/value pairs. For example, the key/value pair ``function,log`` + instructs the use of a multiplicative instead of an additive seasonal pattern, + while ``function,auto`` triggers an automatic selection between the two based + on their fit. .. x13method:: A = outlier (A, key, value[, key, value[, [...]]]) @@ -3134,6 +3144,11 @@ X-13 ARIMA-SEATS interface ``A.results``. When it makes sense these results are saved in ``dseries`` objects (*e.g.* for forecasts or filtered variables). + .. x13method:: clean (A) + + Removes the temporary files created by an x13 run that store the intermediate + results. This method allows keeping the main folder clean but will also + delete potentially important debugging information. *Example* @@ -3151,6 +3166,57 @@ X-13 ARIMA-SEATS interface >> o.run(); + The above example shows a run of X13 with various commands an options specified. + + + *Example* + + :: + + % 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 + y = [112 115 145 171 196 204 242 284 315 340 360 417 ... % Jan + 118 126 150 180 196 188 233 277 301 318 342 391 ... % Feb + 132 141 178 193 236 235 267 317 356 362 406 419 ... % Mar + 129 135 163 181 235 227 269 313 348 348 396 461 ... % Apr + 121 125 172 183 229 234 270 318 355 363 420 472 ... % May + 135 149 178 218 243 264 315 374 422 435 472 535 ... % Jun + 148 170 199 230 264 302 364 413 465 491 548 622 ... % Jul + 148 170 199 242 272 293 347 405 467 505 559 606 ... % Aug + 136 158 184 209 237 259 312 355 404 404 463 508 ... % Sep + 119 133 162 191 211 229 274 306 347 359 407 461 ... % Oct + 104 114 146 172 180 203 237 271 305 310 362 390 ... % Nov + 118 140 166 194 201 229 278 306 336 337 405 432 ]'; % Dec + + ts = dseries(y,'1949M1'); + o = x13(ts); + o.transform('function','auto','savelog','atr'); + o.automdl('savelog','all'); + o.x11('save','(d11 d10)'); + o.run(); + o.clean(); + + y_SA=o.results.d11; + y_seasonal_pattern=o.results.d10; + + figure('Name','Comparison raw data and SAed data'); + plot(ts.dates,log(o.y.data),ts.dates,log(y_SA.data),ts.dates,log(y_seasonal_pattern.data)) + + + The above example shows how to remove a seasonal pattern from a time series. + ``o.transform('function','auto','savelog','atr')`` instructs the subsequent + ``o.automdl()`` command to check whether an additional or a multiplicative + pattern fits the data better and to save the result. The result is saved in + `o.results.autotransform`, which in the present example indicates that a + log transformation, i.e. a multiplicative model was preferred. The ``o.automdl('savelog','all')`` automatically selects a fitting + ARIMA model and saves all relevant output to the .log-file. The ``o.x11('save','(d11, d10)')`` instructs + ``x11`` to save both the final seasonally adjusted series ``d11`` and the final seasonal factor ``d10`` + into ``dseries`` with the respective names in the output structure ``o.results``. ``o.clean()`` removes the + temporary files created by ``o.run()``. Among these are the ``.log``-file storing + summary information, the ``.err``-file storing information on problems encountered, + the ``.out``-file storing the raw output, and the `.spc`-file storing the specification for the `x11` run. + There may be further files depending on the output requested. The last part of the example reads out the + results and plots a comparison of the logged raw data and its log-additive decomposition into a + seasonal pattern and the seasonally adjusted series. Miscellaneous ============= diff --git a/dynare++/doc/sylvester.tex b/doc/sylvester.tex similarity index 100% rename from dynare++/doc/sylvester.tex rename to doc/sylvester.tex diff --git a/dynare++/doc/tl.tex b/doc/tl.tex similarity index 100% rename from dynare++/doc/tl.tex rename to doc/tl.tex diff --git a/dynare++/Makefile.am b/dynare++/Makefile.am deleted file mode 100644 index 806c55dbeb43158fadd1c82efbbfc9c4913b050d..0000000000000000000000000000000000000000 --- a/dynare++/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -SUBDIRS = utils/cc sylv parser/cc tl doc integ kord src tests - -EXTRA_DIST = dynare_simul - -install-exec-local: - $(MKDIR_P) $(DESTDIR)$(pkglibdir)/dynare++ - cp -r dynare_simul/* $(DESTDIR)$(pkglibdir)/dynare++ - -uninstall-local: - rm -rf $(DESTDIR)$(pkglibdir)/dynare++ - diff --git a/dynare++/doc/Makefile.am b/dynare++/doc/Makefile.am deleted file mode 100644 index 9d787d9b04db654e149f38f72da5645958001a86..0000000000000000000000000000000000000000 --- a/dynare++/doc/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -EXTRA_DIST = \ - dynare++-ramsey.tex \ - dynare++-tutorial.tex \ - sylvester.tex \ - tl.tex \ - changelog-old.html \ - changelog-sylv-old.html - -if ENABLE_DOC -pdf-local: dynare++-ramsey.pdf dynare++-tutorial.pdf sylvester.pdf tl.pdf -endif - -%.pdf: %.tex - $(PDFLATEX) $< - $(PDFLATEX) $< - $(PDFLATEX) $< - -CLEANFILES = *.pdf *.log *.aux *.out *.toc - - diff --git a/dynare++/doc/changelog-old.html b/dynare++/doc/changelog-old.html deleted file mode 100644 index d7a4c4923353046c03e199f6e2f86870de417790..0000000000000000000000000000000000000000 --- a/dynare++/doc/changelog-old.html +++ /dev/null @@ -1,280 +0,0 @@ -<HTML> -<TITLE> -Dynare++ Change Log -</TITLE> -<!-- $Header$ --> -<BODY> -<TABLE CELLSPACING=2 ALIGN="CENTER" BORDER=1> -<TR> -<TD BGCOLOR="#d0d0d0" WIDTH="85"> <b>Revision</b> </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="85"> <b>Version</b></TD> -<TD BGCOLOR="#d0d0d0" WIDTH="80"> <b>Date</b> </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="600"> <b>Description of changes</b></TD> -</TR> - -<TR> -<TD> -<TD>1.3.7 -<TD>2008/01/15 -<TD> - -<TR><TD><TD><TD> <TD> Corrected a serious bug in centralizing a -decision rule. This bug implies that all results based on simulations -of the decision rule were wrong. However results based on stochastic -fix points were correct. Thanks to Wouter J. den Haan and Joris de Wind! - -<TR><TD><TD><TD> <TD> Added options --centralize and --no-centralize. - -<TR><TD><TD><TD> <TD> Corrected an error of a wrong -variance-covariance matrix in real-time simulations (thanks to Pawel -Zabzcyk). - -<TR><TD><TD><TD> <TD> Corrected a bug of integer overflow in refined -faa Di Bruno formula if one of refinements is empty. This bug appeared -when solving models without forward looking variables. - -<TR><TD><TD><TD> <TD> Corrected a bug in the Sylvester equation -formerly working only for models with forward looking variables. - -<TR><TD><TD><TD> <TD> Corrected a bug in global check printout. - -<TR><TD><TD><TD> <TD> Added generating a dump file. - -<TR><TD><TD><TD> <TD> Fixed a bug of forgetting repeated assignments -(for example in parameter settings and initval). - -<TR><TD><TD><TD> <TD> Added a diff operator to the parser. - -<TR> -<TD>1539 -<TD>1.3.6 -<TD>2008/01/03 -<TD> - -<TR><TD><TD><TD> <TD> Corrected a bug of segmentation faults for long -names and path names. - -<TR><TD><TD><TD> <TD> Changed a way how random numbers are -generated. Dynare++ uses a separate instance of Mersenne twister for -each simulation, this corrects a flaw of additional randomness caused -by operating system scheduler. This also corrects a strange behaviour -of random generator on Windows, where each simulation was getting the -same sequence of random numbers. - -<TR><TD><TD><TD> <TD> Added calculation of conditional distributions -controlled by --condper and --condsim. - -<TR><TD><TD><TD> <TD> Dropped creating unfoled version of decision -rule at the end. This might consume a lot of memory. However, -simulations might be slower for some models. - -<TR> -<TD>1368 -<TD>1.3.5 -<TD>2007/07/11 -<TD> - -<TR><TD><TD><TD> <TD> Corrected a bug of useless storing all derivative -indices in a parser. This consumed a lot of memory for large models. - -<TR><TD><TD><TD> <TD> Added an option <tt>--ss-tol</tt> controlling a -tolerance used for convergence of a non-linear solver. - -<TR><TD><TD><TD> <TD> Corrected buggy interaction of optimal policy -and forward looking variables with more than one period. - -<TR><TD><TD><TD> <TD> Variance matrices can be positive -semidefinite. This corrects a bug of throwing an error if estimating -approximation errors on ellipse of the state space with a -deterministic variable. - -<TR><TD><TD><TD> <TD> Implemented simulations with statistics -calculated in real-time. Options <tt>--rtsim</tt> and <tt>--rtper</tt>. - -<TR> -<TD>1282 -<TD>1.3.4 -<TD>2007/05/15 -<TD> - -<TR><TD><TD><TD> <TD>Corrected a bug of wrong representation of NaN in generated M-files. - -<TR><TD><TD><TD> <TD>Corrected a bug of occassionaly wrong evaluation of higher order derivatives of integer powers. - -<TR><TD><TD><TD> <TD>Implemented automatic handling of terms involving multiple leads. - -<TR><TD><TD><TD> <TD>Corrected a bug in the numerical integration, i.e. checking of the precision of the solution. - -<TR> -<TD>1090 -<TD>1.3.3 -<TD>2006/11/20 -<TD> - -<TR><TD><TD><TD> <TD>Corrected a bug of non-registering an auxiliary variable in initval assignments. - -<TR> -<TD>988 -<TD>1.3.2 -<TD>2006/10/11 -<TD> - -<TR><TD><TD><TD> <TD>Corrected a few not-serious bugs: segfault on -some exception, error in parsing large files, error in parsing -matrices with comments, a bug in dynare_simul.m - -<TR><TD><TD><TD> <TD>Added posibility to specify a list of shocks for -which IRFs are calculated - -<TR><TD><TD><TD> <TD>Added --order command line switch - -<TR><TD><TD><TD> <TD>Added writing two MATLAB files for steady state -calcs - -<TR><TD><TD><TD> <TD>Implemented optimal policy using keyword -planner_objective and planner_discount - -<TR><TD><TD><TD> <TD>Implemented an R interface to Dynare++ algorithms -(Tamas Papp) - -<TR><TD><TD><TD> <TD>Highlevel code reengineered to allow for -different model inputs - -<TR> -<TD>799 -<TD>1.3.1 -<TD>2006/06/13 -<TD> - -<TR><TD><TD><TD> <TD>Corrected few bugs: in error functions, in linear algebra module. - -<TR><TD><TD><TD> <TD>Updated dynare_simul. - -<TR><TD><TD><TD> <TD>Updated the tutorial. - -<TR><TD><TD><TD> <TD>Corrected an error in summing up tensors where -setting up the decision rule derivatives. Thanks to Michel -Juillard. The previous version was making deterministic effects of -future volatility smaller than they should be. - -<TR> -<TD>766 -<TD>1.3.0 -<TD>2006/05/22 -<TD> - -<TR><TD><TD><TD> <TD>The non-linear solver replaced with a new one. - -<TR><TD><TD><TD> <TD>The parser and derivator replaced with a new -code. Now it is possible to put expressions in parameters and initval -sections. - -<TR> -<TD>752 -<TD>1.2.2 -<TD>2006/05/22 -<TD> - -<TR><TD><TD><TD> <TD>Added an option triggering/suppressing IRF calcs.. - -<TR><TD><TD><TD> <TD>Newton algortihm is now used for fix-point calculations. - -<TR><TD><TD><TD> <TD> Vertical narrowing of tensors in Faa Di Bruno -formula to avoid multiplication with zeros.. - -<TR> -<TD>436 -<TD>1.2.1 -<TD>2005/08/17 -<TD> - -<TR><TD><TD><TD> <TD>Faa Di Bruno for sparse matrices optimized. The -implementation now accommodates vertical refinement of function stack -in order to fit a corresponding slice to available memory. In -addition, zero slices are identified. For some problems, this implies -significant speedup. - -<TR><TD><TD><TD> <TD>Analytic derivator speedup. - -<TR><TD><TD><TD> <TD>Corrected a bug in the threading code. The bug -stayed concealed in Linux 2.4.* kernels, and exhibited in Linux 2.6.*, -which has a different scheduling. This correction also allows using -detached threads on Windows. - -<TR> -<TD>410 -<TD>1.2 -<TD>2005/07/29 -<TD> - -<TR><TD><TD><TD> <TD>Added Dynare++ tutorial. - -<TR><TD><TD><TD> <TD>Changed and enriched contents of MAT-4 output -file. - -<TR><TD><TD><TD> <TD>Corrected a bug of wrong variable indexation -resulting in an exception. The error occurred if a variable appeared -at time t-1 or t+1 and not at t. - -<TR><TD><TD><TD> <TD>Added MATLAB interface, which allows simulation -of a decision rule in MATLAB. - -<TR><TD><TD><TD> <TD>Got rid of Matrix Template Library. - -<TR><TD><TD><TD> <TD>Added checking of model residuals by the -numerical integration. Three methods: checking along simulation path, -checking along shocks, and on ellipse of states. - -<TR><TD><TD><TD> <TD>Corrected a bug in calculation of higher moments -of Normal dist. - -<TR><TD><TD><TD> <TD>Corrected a bug of wrong drawing from Normal dist -with non-zero covariances. - -<TR><TD><TD><TD> -<TD>Added numerical integration module. Product and Smolyak -quadratures over Gauss-Hermite and Gauss-Legendre, and quasi Monte -Carlo. - -<TR> -<TD>152 -<TD>1.1 -<TD>2005/04/22 -<TD> - -<TR><TD><TD><TD> -<TD>Added a calculation of approximation at a stochastic steady state -(still experimental). - -<TR><TD><TD><TD> -<TD>Corrected a bug in Cholesky decomposition of variance-covariance -matrix with off-diagonal elements. - -<TR> -<TD>89 -<TD>1.01 -<TD>2005/02/23 -<TD> - -<TR><TD><TD><TD> -<TD>Added version printout. - -<TR><TD><TD><TD> -<TD>Corrected the bug of multithreading support for P4 HT processors running on Win32. - -<TR><TD><TD><TD> -<TD>Enhanced Kronecker product code resulting in approx. 20% speedup. - -<TR><TD><TD><TD> -<TD>Implemented vertical stack container refinement, and another -method for sparse folded Faa Di Bruno (both not used yet). - -<TR> -<TD>5 -<TD>1.0 -<TD>2005/02/23 -<TD>The first released version. - -</TABLE> -</BODY> -</HTML> diff --git a/dynare++/doc/changelog-sylv-old.html b/dynare++/doc/changelog-sylv-old.html deleted file mode 100644 index 39571f73a6ccef8c87af1d1c474d391372a240b2..0000000000000000000000000000000000000000 --- a/dynare++/doc/changelog-sylv-old.html +++ /dev/null @@ -1,140 +0,0 @@ -<HTML> -<!-- $Header: /var/lib/cvs/dynare_cpp/sylv/change_log.html,v 1.1.1.1 2004/06/04 13:00:05 kamenik Exp $ --> -<!-- Tag $Name: $ --> -<TITLE> -Sylvester Solver Change Log -</TITLE> -<BODY> -<TABLE CELLSPACING=2 ALIGN="CENTER" BORDER=1> -<TR> -<TD BGCOLOR="#d0d0d0" WIDTH="85"> Tag </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="80"> Date </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="600"> Description/Changes</TD> -</TR> -<TR> -<TD></TD> -<TD>2003/09/10</TD> -<TD>Initial version solving triangular system put to repository</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented solution of general case.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented a memory pool (Paris).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented MEX interface to the routine (Paris).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented QuasiTriangularZero (Paris) (not fully used yet).</TD> -</TR> -<TR> -<TD>rel-1</TD> -<TD>2003/10-02</TD> -<TD>Version sent to Michel.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Inheritance streamlined, QuasiTriangular inherits from GeneralMatrix.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented block diagonalization algorithm.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Solution routines rewritten so that the output rewrites input, -considerable memory improvement.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>MEX interface now links with LAPACK library from MATLAB.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Added a hack to MEX library loading in order to avoid MATLAB crash in Wins.</TD> -</TR> -<TR> -<TD>rel-2</TD> -<TD>2003/10/15</TD> -<TD>Version sent to Michel.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>KronUtils now rewrite input by output using less memory.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Added iterative solution algorithm (doubling).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Introduced abstraction for set of parameters (SylvParams).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Algorithm enabled to solve problems with singular C.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented a class chooser chossing between QuasiTriangularZero, -and QuasiTriangular (padded with zero) depending on size of the -problem. Full use of QuasiTriangularZero.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Reimplemented QuasiTriangular::solve, offdiagonal elements are -eleiminated by gauss with partial pivoting, not by transformation of -complex eigenvalues. More stable for ill conditioned eigenvalues.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Reimplemented calculation of eliminating vectors, much more -numerically stable now.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented algorithm for ordering of eigenvalues (not used now, -no numerical improvements).</TD> -</TR> -<TR> -<TD>rel-3</TD> -<TD>2003/12/4</TD> -<TD>Version sent to Michel.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>GeneralMatrix separated for use outside, in sylv module we use -its subclass SylvMatrix. Implemented ConstGeneralMatrix (useful outside). -</TD> -</TR> -<TR> -<TD>rel-4</TD> -<TD>2004/6/4</TD> -<TD>Version, which was moved to pythie.cepremap.cnrs.fr repository.</TD> -</TR> -</TABLE> -</BODY> -</HTML> diff --git a/dynare++/doc/dynare++-ramsey.tex b/dynare++/doc/dynare++-ramsey.tex deleted file mode 100644 index 00b73ce8f44770e1112058f08f647fbc66fb9b11..0000000000000000000000000000000000000000 --- a/dynare++/doc/dynare++-ramsey.tex +++ /dev/null @@ -1,157 +0,0 @@ -\documentclass[10pt]{article} -\usepackage{array,natbib,times} -\usepackage{amsmath, amsthm, amssymb} - -%\usepackage[pdftex,colorlinks]{hyperref} - -\begin{document} - -\title{Implementation of Ramsey Optimal Policy in Dynare++, Timeless Perspective} - -\author{Ondra Kamen\'\i k} - -\date{June 2006} -\maketitle - -\textbf{Abstract:} This document provides a derivation of Ramsey -optimal policy from timeless perspective and describes its -implementation in Dynare++. - -\section{Derivation of the First Order Conditions} - -Let us start with an economy populated by agents who take a number of -variables exogenously, or given. These may include taxes or interest -rates for example. These variables can be understood as decision (or control) -variables of the timeless Ramsey policy (or social planner). The agent's -information set at time $t$ includes mass-point distributions of these -variables for all times after $t$. If $i_t$ denotes an interest rate -for example, then the information set $I_t$ includes -$i_{t|t},i_{t+1|t},\ldots,i_{t+k|t},\ldots$ as numbers. In addition -the information set includes all realizations of past exogenous -innovations $u_\tau$ for $\tau=t,t-1,\ldots$ and distibutions -$u_\tau\sim N(0,\Sigma)$ for $\tau=t+1,\ldots$. These information sets will be denoted $I_t$. - -An information set including only the information on past realizations -of $u_\tau$ and future distributions of $u_\tau\sim N(0\sigma)$ will -be denoted $J_t$. We will use the following notation for expectations -through these sets: -\begin{eqnarray*} -E^I_t[X] &=& E(X|I_t)\\ -E^J_t[X] &=& E(X|J_t) -\end{eqnarray*} - -The agents optimize taking the decision variables of the social -planner at $t$ and future as given. This means that all expectations -they form are conditioned on the set $I_t$. Let $y_t$ denote a vector -of all endogenous variables including the planer's decision -variables. Let the number of endogenous variables be $n$. The economy -can be described by $m$ equations including the first order conditions -and transition equations: -\begin{equation}\label{constr} -E_t^I\left[f(y_{t-1},y_t,y_{t+1},u_t)\right] = 0. -\end{equation} -This lefts $n-m$ -the planner's control variables. The solution of this problem is a -decision rule of the form: -\begin{equation}\label{agent_dr} -y_t=g(y_{t-1},u_t,c_{t|t},c_{t+1|t},\ldots,c_{t+k|t},\ldots), -\end{equation} -where $c$ is a vector of planner's control variables. - -Each period the social planner chooses the vector $c_t$ to maximize -his objective such that \eqref{agent_dr} holds for all times following -$t$. This would lead to $n-m$ first order conditions with respect to -$c_t$. These first order conditions would contain unknown derivatives -of endogenous variables with respect to $c$, which would have to be -retrieved from the implicit constraints \eqref{constr} since the -explicit form \eqref{agent_dr} is not known. - -The other way to proceed is to assume that the planner is so dumb that -he is not sure what are his control variables. So he optimizes with -respect to all $y_t$ given the constraints \eqref{constr}. If the -planner's objective is $b(y_{t-1},y_t,y_{t+1},u_t)$ with a discount rate -$\beta$, then the optimization problem looks as follows: -\begin{align} -\max_{\left\{y_\tau\right\}^\infty_t}&E_t^J -\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\notag\\ -&\rm{s.t.}\label{planner_optim}\\ -&\hskip1cm E^I_\tau\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]=0\quad\rm{for\ } -\tau=\ldots,t-1,t,t+1,\ldots\notag -\end{align} -Note two things: First, each constraint \eqref{constr} in -\eqref{planner_optim} is conditioned on $I_\tau$ not $I_t$. This is -very important, since the behaviour of agents at period $\tau=t+k$ is -governed by the constraint using expectations conditioned on $t+k$, -not $t$. The social planner knows that at $t+k$ the agents will use -all information available at $t+k$. Second, the constraints for the -planner's decision made at $t$ include also constraints for agent's -behaviour prior to $t$. This is because the agent's decision rules are -given in the implicit form \eqref{constr} and not in the explicit form -\eqref{agent_dr}. - -Using Lagrange multipliers, this can be rewritten as -\begin{align} -\max_{y_t}E_t^J&\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right.\notag\\ -&\left.+\sum_{\tau=-\infty}^{\infty}\beta^{\tau-t}\lambda^T_\tau E_\tau^I\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\right], -\label{planner_optim_l} -\end{align} -where $\lambda_t$ is a vector of Lagrange multipliers corresponding to -constraints \eqref{constr}. Note that the multipliers are multiplied -by powers of $\beta$ in order to make them stationary. Taking a -derivative wrt $y_t$ and putting it to zero yields the first order -conditions of the planner's problem: -\begin{align} -E^J_t\left[\vphantom{\frac{\int^(_)}{\int^(\_)}}\right.&\frac{\partial}{\partial y_t}b(y_{t-1},y_t,y_{t+1},u_t)+ -\beta L^{+1}\frac{\partial}{\partial y_{t-1}}b(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta^{-1}\lambda_{t-1}^TE^I_{t-1}\left[L^{-1}\frac{\partial}{\partial y_{t+1}}f(y_{t-1},y_t,y_{t+1},u_t)\right]\notag\\ -&+\lambda_t^TE^I_t\left[\frac{\partial}{\partial y_{t}}f(y_{t-1},y_t,y_{t+1},u_t)\right]\notag\\ -&+\beta\lambda_{t+1}^TE^I_{t+1}\left[L^{+1}\frac{\partial}{\partial y_{t-1}}f(y_{t-1},y_t,y_{t+1},u_t)\right] -\left.\vphantom{\frac{\int^(_)}{\int^(\_)}}\right] - = 0,\label{planner_optim_foc} -\end{align} -where $L^{+1}$ and $L^{-1}$ are one period lead and lag operators respectively. - -Now we have to make a few assertions concerning expectations -conditioned on the different information sets to simplify -\eqref{planner_optim_foc}. Recall the formula for integration through -information on which another expectation is conditioned, this is: -$$E\left[E\left[u|v\right]\right] = E[u],$$ -where the outer expectation integrates through $v$. Since $J_t\subset -I_t$, by easy application of the above formula we obtain -\begin{eqnarray} -E^J_t\left[E^I_t\left[X\right]\right] &=& E^J_t\left[X\right]\quad\rm{and}\notag\\ -E^J_t\left[E^I_{t-1}\left[X\right]\right] &=& E^J_t\left[X\right]\label{e_iden}\\ -E^J_t\left[E^I_{t+1}\left[X\right]\right] &=& E^J_{t+1}\left[X\right]\notag -\end{eqnarray} -Now, the last term of \eqref{planner_optim_foc} needs a special -attention. It is equal to -$E^J_t\left[\beta\lambda^T_{t+1}E^I_{t+1}[X]\right]$. If we assume -that the problem \eqref{planner_optim} has a solution, then there is a -deterministic function from $J_{t+1}$ to $\lambda_{t+1}$ and so -$\lambda_{t+1}\in J_{t+1}\subset I_{t+1}$. And the last term is equal -to $E^J_{t}\left[E^I_{t+1}[\beta\lambda^T_{t+1}X]\right]$, which is -$E^J_{t+1}\left[\beta\lambda^T_{t+1}X\right]$. This term can be -equivalently written as -$E^J_{t}\left[\beta\lambda^T_{t+1}E^J_{t+1}[X]\right]$. The reason why -we write the term in this way will be clear later. All in all, we have -\begin{align} -E^J_t\left[\vphantom{\frac{\int^(_)}{\int^(\_)}}\right.&\frac{\partial}{\partial y_t}b(y_{t-1},y_t,y_{t+1},u_t)+ -\beta L^{+1}\frac{\partial}{\partial y_{t-1}}b(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta^{-1}\lambda_{t-1}^TL^{-1}\frac{\partial}{\partial y_{t+1}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\lambda_t^T\frac{\partial}{\partial y_{t}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta\lambda_{t+1}^TE^J_{t+1}\left[L^{+1}\frac{\partial}{\partial y_{t-1}}f(y_{t-1},y_t,y_{t+1},u_t)\right] -\left.\vphantom{\frac{\int^(_)}{\int^(\_)}}\right] - = 0.\label{planner_optim_foc2} -\end{align} -Note that we have not proved that \eqref{planner_optim_foc} and -\eqref{planner_optim_foc2} are equivalent. We proved only that if -\eqref{planner_optim_foc} has a solution, then -\eqref{planner_optim_foc2} is equivalent (and has the same solution). - -%%- \section{Implementation} -%%- -%%- The user inputs $b(y_{t-1},y_t,y_{t+1},u_t)$, $\beta$, and agent's -%%- first order conditions \eqref{constr}. The algorithm has to produce -%%- \eqref{planner_optim_foc2}. -%%- -\end{document} diff --git a/dynare++/doc/dynare++-tutorial.tex b/dynare++/doc/dynare++-tutorial.tex deleted file mode 100644 index d94475a2a1da844d8e999fabdbe14604712846ae..0000000000000000000000000000000000000000 --- a/dynare++/doc/dynare++-tutorial.tex +++ /dev/null @@ -1,1512 +0,0 @@ -\documentclass[10pt]{article} -\usepackage{array,natbib} -\usepackage{amsmath, amsthm, amssymb} - -\usepackage[pdftex,colorlinks]{hyperref} - -\begin{document} - -\title{DSGE Models with Dynare++. A Tutorial.} - -\author{Ondra Kamen\'\i k} - -\date{First version: February 2011 \\ This version: September 2020} -\maketitle - -\tableofcontents - -\section{Setup} - -The Dynare++ setup procedure is pretty straightforward as Dynare++ is included in the Dynare installation -packages which can be downloaded from \url{https://www.dynare.org}. Take the following steps: -\begin{enumerate} -\item Add the {\tt dynare++} subdirectory of the root Dynare installation directory to the your -operating system path. This ensures that your OS will find the {\tt dynare++} executable. -\item If you have MATLAB and want to run custom simulations (see \ref{custom}), - then you need to add to your MATLAB path the {\tt dynare++} subdirectory of - the root Dynare installation directory, and also directory containing the - \texttt{dynare\_simul\_} MEX file (note the trailing underscore). The easiest - way to add the latter is to run Dynare once in your MATLAB session (even - without giving it any MOD file). -\end{enumerate} - -\section{Sample Session} - -As an example, let us take a simple DSGE model with time to build, whose dynamic -equilibrium is described by the following first order conditions: - -\begin{align*} -&c_t\theta h_t^{1+\psi} = (1-\alpha)y_t\cr -&\beta E_t\left[\frac{\exp(b_t)c_t}{\exp(b_{t+1})c_{t+1}} -\left(\exp(b_{t+1})\alpha\frac{y_{t+1}}{k_{t+1}}+1-\delta\right)\right]=1\cr -&y_t=\exp(a_t)k_t^\alpha h_t^{1-\alpha}\cr -&k_{t}=\exp(b_{t-1})(y_{t-1}-c_{t-1})+(1-\delta)k_{t-1}\cr -&a_t=\rho a_{t-1}+\tau b_{t-1}+\epsilon_t\cr -&b_t=\tau a_{t-1}+\rho b_{t-1}+\nu_t -\end{align*} - -\label{timing} -The convention is that the timing of a variable reflects when this variable -is decided. Dynare++ therefore uses a ``stock at the end of the -period'' notation for predetermined state variables (see the Dynare manual for details). - -The timing of this model is that the exogenous shocks $\epsilon_t$, -and $\nu_t$ are observed by agents in the beginning of period $t$ and -before the end of period $t$ all endogenous variables with index $t$ -are decided. The expectation operator $E_t$ works over the information -accumulated just before the end of the period $t$ (this includes -$\epsilon_t$, $\nu_t$ and all endogenous variables with index $t$). - -The exogenous shocks $\epsilon_t$ and $\nu_t$ are supposed to be -serially uncorrelated with zero means and time-invariant -variance-covariance matrix. In Dynare++, these variables are called -exogenous; all other variables are endogenous. Now we are prepared to -start writing a model file for Dynare++, which is an ordinary text -file and could be created with any text editor. - -The model file starts with a preamble declaring endogenous and -exogenous variables, parameters, and setting values of the -parameters. Note that one can put expression on right hand sides. The -preamble follows: - -{\small -\begin{verbatim} -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; -\end{verbatim} -} - -The section setting values of the parameters is terminated by a -beginning of the {\tt model} section, which states all the dynamic -equations. A timing convention of a Dynare++ model is the same as the -timing of our example model, so we may proceed with writing the model -equations. The time indexes of $c_{t-1}$, $c_t$, and $c_{t+1}$ are -written as {\tt C(-1)}, {\tt C}, and {\tt C(1)} resp. The {\tt model} -section looks as follows: - -{\small -\begin{verbatim} -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; -\end{verbatim} -} - -At this point, almost all information that Dynare++ needs has been -provided. Only three things remain to be specified: initial values of -endogenous variables for non-linear solver, variance-covariance matrix -of the exogenous shocks and order of the Taylor approximation. Since -the model is very simple, there is a closed form solution for the -deterministic steady state. We use it as initial values for the -non-linear solver. Note that the expressions on the right hand-sides in -{\tt initval} section can reference values previously calculated. The -remaining portion of the model file looks as follows: - -{\small -\begin{verbatim} -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; -\end{verbatim} -} - -Note that the order of rows/columns of the variance-covariance matrix -corresponds to the ordering of exogenous variables in the {\tt varexo} -declaration. Since the {\tt EPS} was declared first, its variance is -$0.0002$, and the variance of {\tt NU} is $0.0001$. - -Let the model file be saved as {\tt example1.mod}. Now we are prepared -to solve the model. At the operating system command -prompt\footnote{Under Windows it is a {\tt cmd} program, under Unix it -is any shell} we issue a command: - -{\small -\begin{verbatim} -dynare++ example1.mod -\end{verbatim} -} - -When the program is finished, it produces two output files: a journal -file {\tt example1.jnl} and a MATLAB MAT-4 {\tt example1.mat}. The -journal file contains information about time, memory and processor -resources needed for all steps of solution. The output file is more -interesting. It contains various simulation results. It can be loaded -into MATLAB or Octave and examined. - -Let us first examine the contents of the MAT file: -{\small -\begin{verbatim} ->> load example1.mat ->> who - -Your variables are: - -dyn_g_1 dyn_i_Y dyn_npred -dyn_g_2 dyn_irfm_EPS_mean dyn_nstat -dyn_g_3 dyn_irfm_EPS_var dyn_shocks -dyn_g_4 dyn_irfm_NU_mean dyn_ss -dyn_g_5 dyn_irfm_NU_var dyn_state_vars -dyn_i_A dyn_irfp_EPS_mean dyn_steady_states -dyn_i_B dyn_irfp_EPS_var dyn_vars -dyn_i_C dyn_irfp_NU_mean dyn_vcov -dyn_i_EPS dyn_irfp_NU_var dyn_vcov_exo -dyn_i_H dyn_mean -dyn_i_K dyn_nboth -dyn_i_NU dyn_nforw -\end{verbatim} -} - -All the variables coming from one MAT file have a common prefix. In -this case it is {\tt dyn}, which is Dynare++ default. The prefix can -be changed, so that the multiple results could be loaded into one MATLAB -session. - -In the default setup, Dynare++ solves the Taylor approximation to the -decision rule and calculates unconditional mean and covariance of the -endogenous variables, and generates impulse response functions. The -mean and covariance are stored in {\tt dyn\_mean} and {\tt -dyn\_vcov}. The ordering of the endogenous variables is given by {\tt -dyn\_vars}. - -In our example, the ordering is - -{\small -\begin{verbatim} ->> dyn_vars -dyn_vars = -H -A -Y -C -K -B -\end{verbatim} -} - -and unconditional mean and covariance are - -{\small -\begin{verbatim} ->> dyn_mean -dyn_mean = - 0.2924 - 0.0019 - 1.0930 - 0.8095 - 11.2549 - 0.0011 ->> dyn_vcov -dyn_vcov = - 0.0003 0.0006 0.0016 0.0004 0.0060 0.0004 - 0.0006 0.0024 0.0059 0.0026 0.0504 0.0012 - 0.0016 0.0059 0.0155 0.0069 0.1438 0.0037 - 0.0004 0.0026 0.0069 0.0040 0.0896 0.0016 - 0.0060 0.0504 0.1438 0.0896 2.1209 0.0405 - 0.0004 0.0012 0.0037 0.0016 0.0405 0.0014 -\end{verbatim} -} - -The ordering of the variables is also given by indexes starting with -{\tt dyn\_i\_}. Thus the mean of capital can be retrieved as - -{\small -\begin{verbatim} ->> dyn_mean(dyn_i_K) -ans = - 11.2549 -\end{verbatim} -} - -\noindent and covariance of labor and capital by - -{\small -\begin{verbatim} ->> dyn_vcov(dyn_i_K,dyn_i_H) -ans = - 0.0060 -\end{verbatim} -} - -The impulse response functions are stored in matrices as follows -\begin{center} -\begin{tabular}{|l|l|} -\hline -matrix& response to\\ -\hline -{\tt dyn\_irfp\_EPS\_mean}& positive impulse to {\tt EPS}\\ -{\tt dyn\_irfm\_EPS\_mean}& negative impulse to {\tt EPS}\\ -{\tt dyn\_irfp\_NU\_mean}& positive impulse to {\tt NU}\\ -{\tt dyn\_irfm\_NU\_mean}& negative impulse to {\tt NU}\\ -\hline -\end{tabular} -\end{center} -All shocks sizes are one standard error. Rows of the matrices -correspond to endogenous variables, columns correspond to -periods. Thus capital response to a positive shock to {\tt EPS} can be -plotted as - -{\small -\begin{verbatim} -plot(dyn_irfp_EPS_mean(dyn_i_K,:)); -\end{verbatim} -} - -The data is in units of the respective variables, so in order to plot -the capital response in percentage changes from the decision rule's -fix point (which is a vector {\tt dyn\_ss}), one has to issue the -commands: - -{\small -\begin{verbatim} -Kss=dyn_ss(dyn_i_K); -plot(100*dyn_irfp_EPS_mean(dyn_i_K,:)/Kss); -\end{verbatim} -} - -The plotted impulse response shows that the model is pretty persistent -and that the Dynare++ default for a number of simulated periods is not -sufficient. In addition, the model persistence puts in doubt also a -number of simulations. The Dynare++ defaults can be changed when -calling Dynare++, in operating system's command prompt, we issue a -command: - -{\small -\begin{verbatim} -dynare++ --per 300 --sim 150 example1.mod -\end{verbatim} -} - -\noindent This sets the number of simulations to $150$ and the number -of periods to $300$ for each simulation giving $45000$ total simulated -periods. - -\section{Sample Optimal Policy Session} -\label{optim_tut} - -Suppose that one wants to solve the following optimal policy problem -with timeless perspective.\footnote{See \ref{ramsey} on how to solve -Ramsey optimality problem within this framework} The following -optimization problem is how to choose capital taxes financing public -good to maximize agent's utility from consumption good and public -good. The problem takes the form: -\begin{align*} -\max_{\{\tau_t\}_{t_0}^\infty} -E_{t_0}\sum_{t=t_0}^\infty &\beta^{t-t_0}\left(u(c_t)+av(g_t)\right)\\ -\hbox{subject\ to}&\\ -u'(c_t) &= -\beta E_t\left[u'(c_{t+1})\left(1-\delta+f'(k_{t+1})(1-\alpha\tau_{t+1})\right)\right]\\ -K_t &= (1-\delta)K_{t-1} + (f(K_{t-1}) - c_{t-1} - g_{t-1})\\ -g_t &= \tau_t\alpha f(K_t),\\ -\hbox{where\ } t & = \ldots,t_0-1,t_0,t_0+1,\ldots -\end{align*} -$u(c_t)$ is utility from consuming the consumption good, $v(g_t)$ is -utility from consuming the public good, $f(K_t)$ is a production -function $f(K_t) = Z_tK_t^\alpha$. $Z_t$ is a technology shock modeled -as AR(1) process. The three constraints come from the first order -conditions of a representative agent. We suppose that it pursues a -different objective, namely lifetime utility involving only -consumption $c_t$. The representative agents chooses between -consumption and investment. It rents the capital to firms and supplies -constant amount of labour. All output is paid back to consumer in form -of wage and capital rent. Only the latter is taxed. We suppose that -the optimal choice has been taking place from infinite past and will -be taking place for ever. Further we suppose the same about the -constraints. - -Let us choose the following functional forms: -\begin{eqnarray*} -u(c_t) &=& \frac{c_t^{1-\eta}}{1-\eta}\\ -v(g_t) &=& \frac{g_t^{1-\phi}}{1-\phi}\\ -f(K_t) &=& K_t^\alpha -\end{eqnarray*} - -Then the problem can be coded into Dynare++ as follows. We start with -a preamble which states all the variables, shocks and parameters: -{\small -\begin{verbatim} -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; -\end{verbatim} -} - -Then we specify the planner's objective and the discount factor in the -objective. The objective is an expression (possibly including also -variable leads and lags), and the discount factor must be one single -declared parameter: -{\small -\begin{verbatim} -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; -\end{verbatim} -} - -The model section will contain only the constraints of the social -planner. These are capital accumulation, identity for the public -product, AR(1) process for $Z_t$ and the first order condition of the -representative agent (with different objective). -{\small -\begin{verbatim} -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -C^(-eta) = beta*C(+1)^(-eta)*(1-delta + - exp(Z(+1))*alpha*K(+1)^(alpha-1)*(1-alpha*TAU(+1))); -end; -\end{verbatim} -} - -Now we have to provide a good guess for non-linear solver calculating -the deterministic steady state. The model's steady state has a closed -form solution if the taxes are known. So we provide a guess for -taxation {\tt TAU} and then use the closed form solution for capital, -public good and consumption:\footnote{Initial guess for Lagrange -multipliers and some auxiliary variables is calculated automatically. See -\ref{opt_init} for more details.} -{\small -\begin{verbatim} -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/(alpha*(1-alpha*TAU)))^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -\end{verbatim} -} - -Finally, we have to provide the order of approximation, and the -variance-covariance matrix of the shocks (in our case we have only one -shock): -{\small -\begin{verbatim} -order = 4; - -vcov = [ - 0.01 -]; -\end{verbatim} -} - -After this model file has been run, we can load the resulting MAT-file -into the MATLAB and examine its contents: -{\small -\begin{verbatim} ->> load kp1980_2.mat ->> who - -Your variables are: - -dyn_g_1 dyn_i_MULT1 dyn_nforw -dyn_g_2 dyn_i_MULT2 dyn_npred -dyn_g_3 dyn_i_MULT3 dyn_nstat -dyn_g_4 dyn_i_TAU dyn_shocks -dyn_i_AUX_3_0_1 dyn_i_Z dyn_ss -dyn_i_AUX_4_0_1 dyn_irfm_EPS_mean dyn_state_vars -dyn_i_C dyn_irfm_EPS_var dyn_steady_states -dyn_i_EPS dyn_irfp_EPS_mean dyn_vars -dyn_i_G dyn_irfp_EPS_var dyn_vcov -dyn_i_K dyn_mean dyn_vcov_exo -dyn_i_MULT0 dyn_nboth -\end{verbatim} -} - -The data dumped into the MAT-file have the same structure as in the -previous example of this tutorial. The only difference is that -Dynare++ added a few more variables. Indeed: -{\small -\begin{verbatim} ->> dyn_vars -dyn_vars = -MULT1 -G -MULT3 -C -K -Z -TAU -AUX_3_0_1 -AUX_4_0_1 -MULT0 -MULT2 -\end{verbatim} -} -Besides the five variables declared in the model ({\tt C}, {\tt G}, -{\tt K}, {\tt TAU}, and {\tt Z}), Dy\-na\-re++ added 6 more, four as Lagrange -multipliers of the four constraints, two as auxiliary variables for -shifting in time. See \ref{aux_var} for more details. - -The structure and the logic of the MAT-file is the same as these new 6 -variables were declared in the model file and the file is examined in -the same way. - -For instance, let us examine the Lagrange multiplier of the optimal -policy associated with the consumption first order condition. Recall -that the consumers' objective is different from the policy -objective. Therefore, the constraint will be binding and the -multiplier will be non-zero. Indeed, its deterministic steady state, -fix point and mean are as follows: -{\small -\begin{verbatim} ->> dyn_steady_states(dyn_i_MULT3,1) -ans = - -1.3400 ->> dyn_ss(dyn_i_MULT3) -ans = - -1.3035 ->> dyn_mean(dyn_i_MULT3) -ans = - -1.3422 -\end{verbatim} -} - -\section{What Dynare++ Calculates} -\label{dynpp_calc} - -Dynare++ solves first order conditions of a DSGE model in the recursive form: -\begin{equation}\label{focs} -E_t[f(y^{**}_{t+1},y_t,y^*_{t-1},u_t)]=0, -\end{equation} -where $y$ is a vector of endogenous variables, and $u$ a vector of -exogenous variables. Some of elements of $y$ can occur at time $t+1$, -these are $y^{**}$. Elements of $y$ occurring at time $t-1$ are denoted -$y^*$. The exogenous shocks are supposed to be serially independent -and normally distributed $u_t\sim N(0,\Sigma)$. - -The solution of this dynamic system is a decision rule -\[ -y_t=g(y^*_{t-1},u_t) -\] -Dynare++ calculates a Taylor approximation of this decision rule of a -given order. The approximation takes into account deterministic -effects of future volatility, so a point about which the Taylor -approximation is done will be different from the fix point $y$ of the rule -yielding $y=g(y^*,0)$. - -The fix point of a rule corresponding to a model with $\Sigma=0$ is -called {\it deterministic steady state} denoted as $\bar y$. In -contrast to deterministic steady state, there is no consensus in -literature how to call a fix point of the rule corresponding to a -model with non-zero $\Sigma$. I am tempted to call it {\it stochastic - steady state}, however, it might be confused with unconditional mean -or with steady distribution. So I will use a term {\it fix point} to -avoid a confusion. - -By default, Dynare++ solves the Taylor approximation about the -deterministic steady state. Alternatively, Dynare++ can split the -uncertainty to a few steps and take smaller steps when calculating the -fix points. This is controlled by an option {\tt --steps}. For the -brief description of the second method, see \ref{multistep_alg}. - -\subsection{Decision Rule Form} -\label{dr_form} - -In case of default solution algorithm (approximation about the -deterministic steady state $\bar y$), Dynare++ calculates the higher -order derivatives of the equilibrium rule to get a decision rule of -the following form. In Einstein notation, it is: -\[ -y_t-\bar y = \sum_{i=0}^k\frac{1}{i!}\left[g_{(y^*u)^i}\right] -_{\alpha_1\ldots\alpha_i} -\prod_{j=1}^i\left[\begin{array}{c} y^*_{t-1}-\bar y^*\\ u_t \end{array}\right] -^{\alpha_j} -\] - -Note that the ergodic mean will be different from the deterministic -steady state $\bar y$ and thus deviations $y^*_{t-1}-\bar y^*$ will -not be zero in average. This implies that in average we will commit -larger round off errors than if we used the decision rule expressed in -deviations from a point closer to the ergodic mean. Therefore, by -default, Dynare++ recalculates this rule and expresses it in -deviations from the stochastic fix point $y$. -\[ -y_t-y = \sum_{i=1}^k\frac{1}{i!}\left[\tilde g_{(y^*u)^i}\right] -_{\alpha_1\ldots\alpha_i} -\prod_{j=1}^i\left[\begin{array}{c} y^*_{t-1}-y^*\\ u_t \end{array}\right] -^{\alpha_j} -\] -Note that since the rule is centralized around its fix point, the -first term (for $i=0$) drops out. - -Also note, that this rule mathematically equivalent to the rule -expressed in deviations from the deterministic steady state, and still -it is an approximation about the deterministic steady state. The fact -that it is expressed in deviations from a different point should not -be confused with the algorithm in \ref{multistep_alg}. - -This centralization can be avoided by invoking {\tt --no-centralize} -command line option. - -\subsection{Taking Steps in Volatility Dimension} -\label{multistep_alg} - -For models, where volatility of the exogenous shocks plays a big -role, the approximation about deterministic steady state can be poor, -since the equilibrium dynamics can be very different from the dynamics -in the vicinity of the perfect foresight (deterministic steady state). - -Therefore, Dynare++ has on option {\tt --steps} triggering a multistep -algorithm. The algorithm splits the volatility to a given number of -steps. Dynare++ attempts to calculate approximations about fix points -corresponding to these levels of volatility. The problem is that if we -want to calculate higher order approximations about fix points -corresponding to volatilities different from zero (as in the case of -deterministic steady state), then the derivatives of lower orders -depend on derivatives of higher orders with respect to forward looking -variables. The multistep algorithm in each step approximates the -missing higher order derivatives with extrapolations based on the -previous step. - -In this way, the approximation of the stochastic fix point and the -derivatives about this fix point are obtained. It is difficult to a -priori decide whether this algorithm yields a better decision -rule. Nothing is guaranteed, and the resulted decision rule should be -checked with a numerical integration. See \ref{checks}. - -\subsection{Simulating the Decision Rule} - -After some form of a decision rule is calculated, it is simulated to -obtain draws from ergodic (unconditional) distribution of endogenous -variables. The mean and the covariance are reported. There are two -ways how to calculate the mean and the covariance. The first one is to -store all simulated samples and calculate the sample mean and -covariance. The second one is to calculate mean and the covariance in -the real-time not storing the simulated sample. The latter case is -described below (see \ref{rt_simul}). - -The stored simulated samples are then used for impulse response -function calculations. For each shock, the realized shocks in these -simulated samples (control simulations) are taken and an impulse is -added and the new realization of shocks is simulated. Then the control -simulation is subtracted from the simulation with the impulse. This is -done for all control simulations and the results are averaged. As the -result, we get an expectation of difference between paths with impulse -and without impulse. In addition, the sample variances are -reported. They might be useful for confidence interval calculations. - -For each shock, Dynare++ calculates IRF for two impulses, positive and -negative. Size of an impulse is one standard error of a respective -shock.\footnote{Note that if the exogenous shocks are correlated, Dynare++ will - ignore the correlation when computing the IRFs, and simulate the impulse on - each shock independently of the others. Note that Dynare behaves differently - in this case, and computes IRFs after performing an orthogonalization of the - shocks (via a Cholesky decomposition of the variance-covariance matrix).} - -The rest of this subsection is divided to three parts giving account -on real-time simulations, conditional simulations, and on the way how -random numbers are generated resp. - -\subsubsection{Simulations With Real-Time Statistics} -\label{rt_simul} - -When one needs to simulate large samples to get a good estimate of -unconditional mean, simulating the decision rule with statistics -calculated in real-time comes handy. The main reason is that the -storing of all simulated samples may not fit into the available -memory. - -The real-time statistics proceed as follows: We model the ergodic -distribution as having normal distribution $y\sim N(\mu,\Sigma)$. Further, -the parameters $\mu$ and $\Sigma$ are modelled as: -\begin{eqnarray*} - \Sigma &\sim& {\rm InvWishart}_\nu(\Lambda)\\ - \mu|\Sigma &\sim& N(\bar\mu,\Sigma/\kappa) \\ -\end{eqnarray*} -This model of $p(\mu,\Sigma)$ has an advantage of conjugacy, i.e. a -prior distribution has the same form as posterior. This property is -used in the calculation of real-time estimates of $\mu$ and $\Sigma$, -since it suffices to maintain only the parameters of $p(\mu,\Sigma)$ -conditional observed draws so far. The parameters are: $\nu$, -$\Lambda$, $\kappa$, and $\bar\mu$. - -The mean of $\mu,\Sigma|Y$, where $Y$ are all the draws (simulated -periods) is reported. - -\subsubsection{Conditional Distributions} -\label{cond_dist} - -Starting with version 1.3.6, Dynare++ calculates variable -distributions $y_t$ conditional on $y_0=\bar y$, where $\bar y$ is the -deterministic steady state. If triggered, Dynare++ simulates a given -number of samples with a given number of periods all starting at -the deterministic steady state. Then for each time $t$, mean -$E[y_t|y_0=\bar y]$ and variances $E[(y_t-E[y_t|y_0=\bar -y])(y_t-E[y_t|y_0=\bar y])^T|y_0=\bar y]$ are reported. - -\subsubsection{Random Numbers} -\label{random_numbers} - -For generating of the pseudo random numbers, Dynare++ uses Mersenne -twister by Makoto Matsumoto and Takuji Nishimura. Because of the -parallel nature of Dynare++ simulations, each simulated sample gets -its own instance of the twister. Each such instance is seeded before -the simulations are started. This is to prevent additional randomness -implied by the operating system's thread scheduler to interfere with -the pseudo random numbers. - -For seeding the individual instances of the Mersenne twister assigned -to each simulated sample the system (C library) random generator is -used. These random generators do not have usually very good -properties, but we use them only to seed the Mersenne twister -instances. The user can set the initial seed of the system random -generator and in this way deterministically choose the seeds of all -instances of the Mersenne twister. - -In this way, it is guaranteed that two runs of Dynare++ -with the same seed will yield the same results regardless the -operating system's scheduler. The only difference may be caused by a -different round-off errors committed when the same set of samples are -summed in the different order (due to the operating system's scheduler). - -\subsection{Numerical Approximation Checks} -\label{checks} - -Optionally, Dynare++ can run three kinds of checks for Taylor -approximation errors. All three methods numerically calculate -the residual of the DSGE equations -\[ -E[f(g^{**}(g^*(y^*,u),u'),g(y^*,u),y^*,u)|y^*,u] -\] -which must be ideally zero for all $y^*$ and $u$. This integral is -evaluated by either product or Smolyak rule applied to one dimensional -Gauss--Hermite quadrature. The user does not need to care about the -decision. An algorithm yielding higher quadrature level and less -number of evaluations less than a user given maximum is selected. - -The three methods differ only by a set of $y^*$ and $u$ where the -residuals are evaluated. These are: -\begin{itemize} -\item The first method calculates the residuals along the shocks for -fixed $y^*$ equal to the fix point. We let all elements of $u$ be -fixed at $0$ but one element, which varies from $-\mu\sigma$ to -$\mu\sigma$, where $\sigma$ is a standard error of the element and -$\mu$ is the user given multiplier. In this way we can see how the -approximation error grows if the fix point is disturbed by a shock of -varying size. -\item The second method calculates the residuals along a simulation -path. A random simulation is run, and at each point the residuals are -reported. -\item The third method calculates the errors on an ellipse of the -state variables $y^*$. The shocks $u$ are always zero. The ellipse is -defined as -\[\{Ax|\; \Vert x\Vert_2=\mu\},\] -where $\mu$ is a user given multiplier, and $AA^T=V$ for $V$ being a -covariance of endogenous variables based on the first order -approximation. The method calculates the residuals at low discrepancy -sequence of points on the ellipse. Both the residuals and the points -are reported. -\end{itemize} - -\section{Optimal Policy with Dynare++} -\label{optim} - -Starting with version 1.3.2, Dynare++ is able to automatically -generate and then solve the first order conditions for a given -objective and (possibly) forward looking constraints. Since the -constraints can be forward looking, the use of this feature will -mainly be in optimal policy or control. - -The only extra thing which needs to be added to the model file is a -specification of the policy's objective. This is done by two keywords, -placed not before parameter settings. If the objective is to maximize -$$E_{t_0}\sum_{t=t_0}^\infty\beta^{t-t_0}\left[\frac{c_t^{1-\eta}}{1-\eta}+ -a\frac{g_t^{1-\phi}}{1-\phi}\right],$$ -then the keywords will be: -{\small -\begin{verbatim} -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; -\end{verbatim} -} - -Dynare++ parses the file and if the two keywords are present, it -automatically derives the first order conditions for the problem. The -first order conditions are put to the form \eqref{focs} and solved. In -this case, the equations in the {\tt model} section are understood as -the constraints (they might come as the first order conditions from -optimizations of other agents) and their number must be less than the -number of endogenous variables. - -This section further describes how the optimal policy first order -conditions look like, then discusses some issues with the initial -guess for deterministic steady state, and finally describes how to -simulate Ramsey policy within this framework. - -\subsection{First Order Conditions} - -Mathematically, the optimization problem looks as follows: -\begin{align} -\max_{\left\{y_\tau\right\}^\infty_t}&E_t -\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\notag\\ -&\rm{s.t.}\label{planner_optim}\\ -&\hskip1cm E^I_\tau\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]=0\quad\rm{for\ } -\tau=\ldots,t-1,t,t+1,\ldots\notag -\end{align} -where $E^I$ is an expectation operator over an information set including, -besides all the past, all future realizations of policy's control -variables and distributions of future shocks $u_t\sim -N(0,\Sigma)$. The expectation operator $E$ integrates over an -information including only distributions of $u_t$ (besides the past). - -Note that the constraints $f$ take place at all times, and they are -conditioned at the running $\tau$ since the policy knows that the -agents at time $\tau$ will use all the information available at -$\tau$. - -The maximization problem can be rewritten using Lagrange multipliers as: -\begin{align} -\max_{y_t}E_t&\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right.\notag\\ -&\left.+\sum_{\tau=-\infty}^{\infty}\beta^{\tau-t}\lambda^T_\tau E_\tau^I\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\right], -\label{planner_optim_l} -\end{align} -where $\lambda_t$ is a column vector of Lagrange multipliers. - -After some manipulations with compounded expectations over different -information sets, one gets the following first order conditions: -\begin{align} -E_t\left[\vphantom{\frac{\int^(_)}{\int^(\_)}}\right.&\frac{\partial}{\partial y_t}b(y_{t-1},y_t,y_{t+1},u_t)+ -\beta L^{+1}\frac{\partial}{\partial y_{t-1}}b(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta^{-1}\lambda_{t-1}^TL^{-1}\frac{\partial}{\partial y_{t+1}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\lambda_t^T\frac{\partial}{\partial y_{t}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta\lambda_{t+1}^TE_{t+1}\left[L^{+1}\frac{\partial}{\partial y_{t-1}}f(y_{t-1},y_t,y_{t+1},u_t)\right] -\left.\vphantom{\frac{\int^(_)}{\int^(\_)}}\right] - = 0,\label{planner_optim_foc2} -\end{align} -where $L^{+1}$ is one period lead operator, and $L^{-1}$ is one period lag operator. - -Dynare++ takes input corresponding to \eqref{planner_optim}, -introduces the Lagrange multipliers according to -\eqref{planner_optim_l}, and using its symbolic derivator it compiles -\eqref{planner_optim_foc2}. The system \eqref{planner_optim_foc2} with -the constraints from \eqref{planner_optim_l} is then solved in the -same way as the normal input \eqref{focs}. - -\subsection{Initial Guess for Deterministic Steady State} -\label{opt_init} - -Solving deterministic steady state of non-linear dynamic systems is -not trivial and the first order conditions for optimal policy add -significant complexity. The {\tt initval} section allows to input the -initial guess of the non-linear solver. It requires that all user -declared endogenous variables be initialized. However, in most cases, -we have no idea what are good initial guesses for the Lagrange -multipliers. - -For this reason, Dynare++ calculates an initial guess of Lagrange -multipliers using user provided initial guesses of all other -endogenous variables. It uses the linearity of the Lagrange -multipliers in the \eqref{planner_optim_foc2}. In its static form, -\eqref{planner_optim_foc2} looks as follows: -\begin{align} -&\frac{\partial}{\partial y_t}b(y,y,y,0)+ -\beta\frac{\partial}{\partial y_{t-1}}b(y,y,y,0)\notag\\ -&+\lambda^T\left[\beta^{-1}\frac{\partial}{\partial y_{t+1}}f(y,y,y,0) - +\frac{\partial}{\partial y_{t}}f(y,y,y,0) - +\beta\frac{\partial}{\partial y_{t-1}}f(y,y,y,0)\right] - = 0\label{planner_optim_static} -\end{align} - -The user is required to provide an initial guess of all declared -variables (all $y$). Then \eqref{planner_optim_static} becomes an -overdetermined linear system in $\lambda$, which is solved by means of -the least squares. The closer the initial guess of $y$ is to the exact -solution, the closer are the Lagrange multipliers $\lambda$. - -The calculated Lagrange multipliers by the least squares are not used, -if they are set in the {\tt initval} section. In other words, if a -multiplier has been given a value in the {\tt initval} section, then -the value is used, otherwise the calculated value is taken. - -For even more difficult problems, Dynare++ generates two MATLAB files -calculating a residual of the static system and its derivative. These -can be used in MATLAB's {\tt fsolve} or other algorithm to get an -exact solution of the deterministic steady state. See -\ref{output_matlab_scripts} for more details. - -Finally, Dynare++ might generate a few auxiliary variables. These are -simple transformations of other variables. They are initialized -automatically and the user usually does not need to care about it. - -\subsection{Optimal Ramsey Policy} -\label{ramsey} - -Dynare++ solves the optimal policy problem with timeless -perspective. This means that it assumes that the constraints in -\eqref{planner_optim} are valid from the infinite past to infinite -future. Dynare++ calculation of ergodic distribution then assumes that -the policy has been taking place from infinite past. - -If some constraints in \eqref{planner_optim} are forward looking, this -will result in some backward looking Lagrange multipliers. Such -multipliers imply possibly time inconsistent policy in the states of -the ``original'' economy, since these backward looking multipliers add -new states to the ``optimized'' economy. In this respect, the timeless -perspective means that there is no fixed initial distribution of such -multipliers, instead, their ergodic distribution is taken. - -In contrast, Ramsey optimal policy is started at $t=0$. This means -that the first order conditions at $t=0$ are different than the first -order conditions at $t\geq 1$, which are -\eqref{planner_optim_foc2}. However, it is not difficult to assert -that the first order conditions at $t=0$ are in the form of -\eqref{planner_optim_foc2} if all the backward looking Lagrange -multipliers are set to zeros at period $-1$, i.e. $\lambda_{-1}=0$. - -All in all, the solution of \eqref{planner_optim_foc2} calculated by -Dynare++ can be used as a Ramsey optimal policy solution provided that -all the backward looking Lagrange multipliers were set to zeros prior -to the first simulation period. This can be done by setting the -initial state of a simulation path in {\tt dynare\_simul.m}. If this -is applied on the example from \ref{optim_tut}, then we may do the -following in the command prompt: -{\small -\begin{verbatim} ->> load kp1980_2.mat ->> shocks = zeros(1,100); ->> ystart = dyn_ss; ->> ystart(dyn_i_MULT3) = 0; ->> r=dynare_simul('kp1980_2.mat',shocks,ystart); -\end{verbatim} -} -This will simulate the economy if the policy was introduced in the -beginning and no shocks happened. - -More information on custom simulations can be obtained by typing: -{\small -\begin{verbatim} -help dynare_simul -\end{verbatim} -} - - -\section{Running Dynare++} - -This section deals with Dynare++ input. The first subsection -\ref{dynpp_opts} provides a list of command line options, next -subsection \ref{dynpp_mod} deals with a format of Dynare++ model file, -and the last subsection discusses incompatibilities between Dynare -and Dynare++. - -\subsection{Command Line Options} -\label{dynpp_opts} - -The calling syntax of the Dynare++ is - -{\small -\begin{verbatim} -dynare++ [--help] [--version] [options] <model file> -\end{verbatim} -} - -\noindent where the model file must be given as the last token and -must include its extension. The model file may include path, in this -case, the path is taken relative to the current directory. Note that -the current directory can be different from the location of {\tt -dynare++} binary. - -The options are as follows: - -\def\desc#1{\rlap{#1}\kern4cm} - -\begin{description} -\item[\desc{\tt --help}] This prints a help message and exits. - -\item[\desc{\tt --version}] This prints a version information and -exits. - -\item[\desc{\tt --per \it num}] This sets a number of simulated -periods to {\it num} in addition to the burn-in periods. This number -is used when calculating unconditional mean and covariance and for -IRFs. Default is 100. - -\item[\desc{\tt --burn \it num}] This sets a number of initial periods -which should be ignored from the statistics. The burn-in periods are -used to eliminate the influence of the starting point when -calculating ergodic distributions or/and impulse response -functions. The number of simulated period given by {\tt --per \it - num} option does not include the number of burn-in -periods. Default is 0. - -\item[\desc{\tt --sim \it num}] This sets a number of stochastic -simulations. This number is used when calculating unconditional mean -and covariance and for IRFs. The total sample size for unconditional -mean and covariance is the number of periods times the number of -successful simulations. Note that if a simulation results in {\tt NaN} -or {\tt +-Inf}, then it is thrown away and is not considered for the -mean nor the variance. The same is valid for IRF. Default is 80. - -\item[\desc{\tt --rtsim \it num}] This sets a number of stochastic -simulations whose statistics are calculated in the real-time. This -number excludes the burn-in periods set by {\tt --burn \it num} -option. See \ref{rt_simul} for more details. Default is 0, no -simulations. - -\item[\desc{\tt --rtper \it num}] This sets a number of simulated -periods per one simulation with real-time statistics to {\it num}. See -\ref{rt_simul} for more details. Default is 0, no simulations. - -\item[\desc{\tt --condsim \it num}] This sets a number of stochastic -conditional simulations. See \ref{cond_dist} for more details. Default -is 0, no simulations. - -\item[\desc{\tt --condper \it num}] This sets a number of simulated -periods per one conditional simulation. See \ref{cond_dist} for more -details. Default is 0, no simulations. - -\item[\desc{\tt --steps \it num}] If the number {\it num} is greater -than 0, this option invokes a multi-step algorithm (see section -\ref{dynpp_calc}), which in the given number of steps calculates fix -points and approximations of the decision rule for increasing -uncertainty. Default is 0, which invokes a standard algorithm for -approximation about deterministic steady state. For more details, -see \ref{multistep_alg}. - -\item[\desc{\tt --centralize}] This option causes that the resulting -decision rule is centralized about (in other words: expressed in the -deviations from) the stochastic fix point. The centralized decision -rule is mathematically equivalent but has an advantage of yielding -less numerical errors in average than not centralized decision -rule. By default, the rule is centralized. For more details, see -\ref{dr_form}. - -\item[\desc{\tt --no-centralize}] This option causes that the -resulting decision rule is not centralized about (in other words: -expressed in the deviations from) the stochastic fix point. By -default, the rule is centralized. For more details, see -\ref{dr_form}. - -This option has no effect if the number of steps given by {\tt ---steps} is greater than 0. In this case, the rule is always -centralized. - -\item[\desc{\tt --prefix \it string}] This sets a common prefix of -variables in the output MAT file. Default is {\tt dyn}. - -\item[\desc{\tt --seed \it num}] This sets an initial seed for the -random generator providing seed to generators for each sample. See -\ref{random_numbers} for more details. Default is 934098. - -\item[\desc{\tt --order \it num}] This sets the order of approximation -and overrides the {\tt order} statement in the model file. There is no -default. - -\item[\desc{\tt --threads \it num}] This sets a number of parallel -threads. Complex evaluations of Faa Di Bruno formulas, simulations and -numerical integration can be parallelized, Dynare++ exploits this -advantage. You have to have a hardware support for this, otherwise -there is no gain from the parallelization. The default value is the number of -logical processors present on the machine, divided by 2. - -\item[\desc{\tt --ss-tol \it float}] This sets the tolerance of the -non-linear solver of deterministic steady state to {\it float}. It is -in $\Vert\cdot\Vert_\infty$ norm, i.e. the algorithm is considered as -converged when a maximum absolute residual is less than the -tolerance. Default is $10^{-13}$. - -\item[\desc{\tt --check \it pPeEsS}] This selects types of residual -checking to be performed. See section \ref{checks} for details. The -string consisting of the letters ``pPeEsS'' governs the selection. The -upper-case letters switch a check on, the lower-case letters -off. ``P'' stands for checking along a simulation path, ``E'' stands -for checking on ellipse, and finally ``S'' stands for checking along -the shocks. It is possible to choose more than one type of check. The -default behavior is that no checking is performed. - -\item[\desc{\tt --check-evals \it num}] This sets a maximum number of -evaluations per one re\-sidual. The actual value depends on the selected -algorithm for the integral evaluation. The algorithm can be either -product or Smolyak quadrature and is chosen so that the actual number -of evaluations would be minimal with maximal level of -quadrature. Default is 1000. - -\item[\desc{\tt --check-num \it num}] This sets a number of checked -points in a residual check. One input value $num$ is used for all -three types of checks in the following way: -\begin{itemize} -\item For checks along the simulation, the number of simulated periods -is $10\cdot num$ -\item For checks on ellipse, the number of points on ellipse is $10\cdot num$ -\item For checks along the shocks, the number of checked points -corresponding to shocks from $0$ to $\mu\sigma$ (see \ref{checks}) is -$num$. -\end{itemize} -Default is 10. - -\item[\desc{\tt --check-scale \it float}] This sets the scaling factor -$\mu$ for checking on ellipse to $0.5\cdot float$ and scaling factor -$\mu$ for checking along shocks to $float$. See section -\ref{checks}. Default is 2.0. - -\item[\desc{\tt --no-irfs}] This suppresses IRF calculations. Default -is to calculate IRFs for all shocks. - -\item[\desc{\tt --irfs}] This triggers IRF calculations. If there are -no shock names following the {\tt --irfs} option, then IRFs for all -shocks are calculated, otherwise see below. Default is to calculate -IRFs for all shocks. - -\item[\desc{\tt --irfs \it shocklist}] This triggers IRF calculations -only for the listed shocks. The {\it shocklist} is a space separated -list of exogenous variables for which the IRFs will be -calculated. Default is to calculate IRFs for all shocks. -\end{description} - -The following are a few examples: -{\small -\begin{verbatim} -dynare++ --sim 300 --per 50 blah.mod -dynare++ --check PE --check-num 15 --check-evals 500 blah.dyn -dynare++ --steps 5 --check S --check-scale 3 blahblah.mod -\end{verbatim} -} -The first one sets the number of periods for IRF to 50, and sets a sample -size for unconditional mean and covariance calculations to 6000. The -second one checks the decision rule along a simulation path having 150 -periods and on ellipse at 150 points performing at most 500 evaluations -per one residual. The third one solves the model in five steps and -checks the rule along all the shocks from $-3\sigma$ to $3\sigma$ in -$2*10+1$ steps (10 for negative, 10 for positive and 1 for at zero). - -\subsection{Dynare++ Model File} -\label{dynpp_mod} - -In its strictest form, Dynare++ solves the following mathematical problem: -\begin{equation}\label{basic_form} -E_t[f(y^{**}_{t+1},y_t,y^*_{t-1},u_t)]=0 -\end{equation} -This problem is input either directly, or it is an output of Dynare++ -routines calculating first order conditions of the optimal policy -problem. In either case, Dynare++ performs necessary and -mathematically correct substitutions to put the user specified problem -to the \eqref{basic_form} form, which goes to Dynare++ solver. The -following discusses a few timing issues: -\begin{itemize} -\item Endogenous variables can occur, starting from version 1.3.4, at -times after $t+1$. If so, an equation containing such occurrence is -broken to non-linear parts, and new equations and new auxiliary -variables are automatically generated only for the non-linear terms -containing the occurrence. Note that shifting such terms to time $t+1$ -may add occurrences of some other variables (involved in the terms) at -times before $t-1$ implying addition of auxiliary variables to bring -those variables to $t-1$. -\item Variables declared as shocks may occur also at arbitrary -times. If before $t$, additional endogenous variables are used to -bring them to time $t$. If after $t$, then similar method is used as -for endogenous variables occurring after $t+1$. -\item There is no constraint on variables occurring at both times -$t+1$ (or later) and $t-1$ (or earlier). Virtually, all variables can -occur at arbitrary times. -\item Endogenous variables can occur at times before $t-1$. If so, -additional endogenous variables are added for all lags between the -variable and $t-1$. -\item Dynare++ applies the operator $E_t$ to all occurrences at time -$t+1$. The realization of $u_t$ is included in the information set of -$E_t$. See an explanation of Dynare++ timing on page \pageref{timing}. -\end{itemize} - -The model equations are formulated in the same way as in -Dynare. The time indexes different from $t$ are put to round -parenthesis in this way: {\tt C(-1)}, {\tt C}, {\tt C(+1)}. - -The mathematical expressions can use the following functions and operators: -\begin{itemize} -\item binary {\tt + - * / \verb|^|} -\item unary plus and minus minus as in {\tt a = -3;} and {\tt a = +3;} resp. -\item unary mathematical functions: {\tt log exp sin cos tan -sqrt}, whe\-re the logarithm has a natural base -\item symbolic differentiation operator {\tt diff(expr,symbol)}, where -{\tt expr} is a mathematical expression and {\tt symbol} is a unary -symbol (a variable or a parameter); for example {\tt - diff(A*K(-1)\verb|^|alpha*L\verb|^|(1-alpha),K(-1))} is internally expanded as -{\tt A*alpha*K(-1)\verb|^|(alpha-1)*L\verb|^|(1-alpha)} -\item unary error function and complementary error function: {\tt erf} -and {\tt erfc} defined as -\begin{eqnarray*} -erf(x) &= \frac{2}{\sqrt{\pi}}\int_0^x e^{-t^2}{\rm d}t\\ -erfc(x)&= \frac{2}{\sqrt{\pi}}\int_x^\infty e^{-t^2}{\rm d}t -\end{eqnarray*} -\end{itemize} - -The model file can contain user comments. Their usage can be -understood from the following piece of the model file: - -{\small -\begin{verbatim} -P*C^(-gamma) = // line continues until semicolon - beta*C(+1)^(-gamma)*(P(+1)+Y(+1)); // asset price -// choose dividend process: (un)comment what you want -Y/Y_SS = (Y(-1)/Y_SS)^rho*exp(EPS); -/* -Y-Y_SS = rho*(Y(-1)-Y_SS)+EPS; -*/ -\end{verbatim} -} - -\subsection{Incompatibilities with Dynare} - -This section provides a list of incompatibilities between a model file -for Dy\-na\-re++ and for Dynare. These must be considered when a model -file for Dynare is being migrated to Dynare++. The list is the -following: -\begin{itemize} -\item There is no {\tt periods} keyword. -\item The parameters cannot be lagged or leaded; Dynare -allows it, though the semantics is the same (parameter is a -constant). -\item There are no commands like {\tt steady}, {\tt check}, {\tt -simul}, {\tt stoch\_simul}, etc. -\item There are no sections like {\tt estimated\_params}, {\tt -var\_obs}, etc. -\item The variance-covariance matrix of endogenous shocks is given by -{\tt vcov} matrix in Dynare++. An example follows. Starting from -version 1.3.5, it is possible for vcov to be positive semi-definite -matrix. -{\small -\begin{verbatim} -vcov = [ -0.05 0 0 0; -0 0.025 0 0; -0 0 0.05 0; -0 0 0 0.025 -]; -\end{verbatim} -} - -\end{itemize} - -\section{Dynare++ Output} - -There are three output files; a data file in MAT-4 format containing -the output data (\ref{matfile}), a journal text file containing an -information about the Dynare++ run (\ref{journalfile}), and a dump -file (\ref{dumpfile}). Further, Dynare++ generates two MATLAB script -files, which calculate a residual and the first derivative of the -residual of the static system (\ref{output_matlab_scripts}). These are -useful when calculating the deterministic steady state outside -Dynare++. - -Note that all output files are created in the current directory of -the Dynare++ process. This can be different from the directory where -the Dynare++ binary is located and different from the directory where -the model file is located. - -Before all, we need to understand what variables are automatically -generated in Dynare++. - -\subsection{Auxiliary Variables} -\label{aux_var} - -Besides the endogenous variables declared in {\tt var} section, -Dynare++ might automatically add the following endogenous variables: - -\halign{\vrule width0pt height14pt{\tt #}\hfil & \kern 3mm% -\vtop{\rightskip=0pt plus 5mm\noindent\hsize=9.5cm #}\cr -MULT{\it n}& A Lagrange multiplier of the optimal policy problem -associated with a constraint number {\it n} starting from zero.\cr -AUX\_{\it n1}\_{\it n2}\_{\it n3}& An auxiliary variable associated -with the last term in equation \eqref{planner_optim_foc2}. Since the -term is under $E_{t+k}$, we need the auxiliary variable be put back -in time. {\it n1} is a variable number starting from 0 in the declared -order with respect to which the term was differentiated, {\it n2} is a -number of constraint starting from 0, and finally {\it n3} is $k$ -(time shift of the term).\cr -{\it endovar}\_p{\it K}& An auxiliary variable for bringing an -endogenous variable {\it endovar} back in time by $K$ periods. The -semantics of this variables is {\tt {\it endovar}\_p{\it K} = {\it -endovar}(+{\it K})}.\cr -{\it endovar}\_m{\it K}& An auxiliary variable for bringing an -endogenous variable {\it endovar} forward in time by $K$ periods. The -semantics of this variables is {\tt {\it endovar}\_m{\it K} = {\it -endovar}(-{\it K})}.\cr -{\it exovar}\_e& An auxiliary endogenous variable made equal to the -exogenous variable to allow for a semantical occurrence of the -exogenous variable at time other than $t$. The semantics of this -variables is {\tt {\it exovar}\_e = {\it exovar}}.\cr -AUXLD\_{\it n1}\_{\it n2}\_{\it n3}& An auxiliary variable for -bringing a non-linear term containing an occurrence of a variable -after $t+1$ to time $t+1$. {\it n1} is an equation number starting -from 0, {\it n2} is the non-linear sub-term number in the equation -starting from 0. {\it n3} is a time shift. For example, if the first -equation is the following: -\begin{verbatim} -X - Y*W(+1) + W(+2)*Z(+4) = 0; -\end{verbatim} -then it will be expanded as: -\begin{verbatim} -X - Y*W(+1) + AUXLD_0_2_3(+1) = 0; -AUXLD_0_2_1 = W(-1)*Z(+1); -AUXLD_0_2_2 = AUXLD_0_2_1(+1); -AUXLD_0_2_3 = AUXLD_0_2_2(+1); -\end{verbatim} -\cr -} - -\subsection{MAT File} -\label{matfile} - -The contents of the data file is depicted below. We -assume that the prefix is {\tt dyn}. - -\halign{\vrule width0pt height14pt{\tt #}\hfil & \kern 3mm% -\vtop{\rightskip=0pt plus 5mm\noindent\hsize=7.5cm #}\cr -dyn\_nstat& Scalar. A number of static variables -(those occurring only at time $t$).\cr -dyn\_npred & Scalar. A number of variables occurring -at time $t-1$ and not at $t+1$.\cr -dyn\_nboth & Scalar. A number of variables occurring -at $t+1$ and $t-1$.\cr -dyn\_nforw & Scalar. A number of variables occurring -at $t+1$ and not at $t-1$.\cr -dyn\_vars & Column vector of endogenous variable -names in Dy\-na\-re++ internal ordering.\cr -dyn\_i\_{\it endovar} & Scalar. Index of a variable -named {\it endovar} in the {\tt dyn\_vars}.\cr -dyn\_shocks & Column vector of exogenous variable -names.\cr -dyn\_i\_{\it exovar} & Scalar. Index of a shock -named {\it exovar} in the {\tt dyn\_shocks}.\cr -dyn\_state\_vars & Column vector of state variables, -these are stacked variables counted by {\tt dyn\_\-npred}, {\tt -dyn\_\-nboth} and shocks.\cr -dyn\_vcov\_exo & Matrix $nexo\times nexo$. The -variance-covariance matrix of exogenous shocks as input in the model -file. The ordering is given by {\tt dyn\_shocks}.\cr -dyn\_mean & Column vector $nendo\times 1$. The -unconditional mean of endogenous variables. The ordering is given by -{\tt dyn\_vars}.\cr -dyn\_vcov & Matrix $nendo\times nendo$. The -unconditional covariance of endogenous variables. The ordering is given -by {\tt dyn\_vars}.\cr -dyn\_rt\_mean & Column vector $nendo\times 1$. The unconditional mean -of endogenous variables estimated in real-time. See -\ref{rt_simul}. The ordering is given by {\tt dyn\_vars}.\cr -dyn\_rt\_vcov & Matrix $nendo\times nendo$. The unconditional -covariance of endogenous variables estimated in real-time. See \ref{rt_simul}. The -ordering is given by {\tt dyn\_vars}.\cr -dyn\_cond\_mean & Matrix $nendo\times nper$. The rows correspond to -endogenous variables in the ordering of {\tt dyn\_vars}, the columns -to periods. If $t$ is a period (starting with 1), then $t$-th column -is $E[y_t|y_0=\bar y]$. See \ref{cond_dist}.\cr -dyn\_cond\_variance & Matrix $nendo\times nper$. The rows correspond -to endogenous variables in the ordering of {\tt dyn\_vars}, the -columns to periods. If $t$ is a period (starting with 1), then $t$-th -column are the variances of $y_t|y_0=\bar y$. See \ref{cond_dist}.\cr -dyn\_ss & Column vector $nendo\times 1$. The fix -point of the resulting approximation of the decision rule.\cr -dyn\_g\_{\it order} & Matrix $nendo\times ?$. A -derivative of the decision rule of the {\it order} multiplied by -$1/order!$. The rows correspond to endogenous variables in the -ordering of {\tt dyn\_vars}. The columns correspond to a -multidimensional index going through {\tt dyn\_state\_vars}. The data -is folded (all symmetrical derivatives are stored only once).\cr -dyn\_steady\_states & Matrix $nendo\times -nsteps+1$. A list of fix points at which the multi-step algorithm -calculated approximations. The rows correspond to endogenous variables -and are ordered by {\tt dyn\_vars}, the columns correspond to the -steps. The first column is always the deterministic steady state.\cr -dyn\_irfp\_{\it exovar}\_mean & Matrix -$nendo\times nper$. Positive impulse response to a shock named {\it -exovar}. The row ordering is given by {\tt dyn\_vars}. The columns -correspond to periods.\cr -dyn\_irfp\_{\it exovar}\_var & Matrix -$nendo\times nper$. The variances of positive impulse response -functions.\cr -dyn\_irfm\_{\it exovar}\_mean & Same as {\tt -dyn\_irfp\_}{\it exovar}{\tt \_mean} but for negative impulse.\cr -dyn\_irfp\_{\it exovar}\_var & Same as {\tt -dyn\_irfp\_}{\it exovar}{\tt \_var} but for negative impulse.\cr -dyn\_simul\_points & A simulation path along which the check was -done. Rows correspond to endogenous variables, columns to -periods. Appears only if {\tt --check P}.\cr -dyn\_simul\_errors & Errors along {\tt -dyn\_simul\_points}. The rows correspond to equations as stated in the -model file, the columns to the periods. Appears only if {\tt --check -P}\cr -dyn\_ellipse\_points & A set of points on the ellipse at which the -approximation was checked. Rows correspond to state endogenous -variables (the upper part of {\tt dyn\_state\_vars}, this means -without shocks), and columns correspond to periods. Appears only if -{\tt --check E}.\cr -dyn\_ellipse\_errors & Errors on the ellipse points {\tt -dyn\_ellipse\_points}. The rows correspond to the equations as stated -in the model file, columns to periods. Appears only if {\tt --check -E}.\cr -dyn\_shock\_{\it exovar}\_errors& Errors along a shock named {\it -exovar}. The rows correspond to the equations as stated in the model -file. There are $2m+1$ columns, the middle column is the error at zero -shock. The columns to the left correspond to negative values, columns -to the right to positive. Appears only if {\tt --check S}.\cr -} - -\subsection{Journal File} -\label{journalfile} - -The journal file provides information on resources usage during the -run and gives some informative messages. The journal file is a text -file, it is organized in single line records. The format of records is -documented in a header of the journal file. - -The journal file should be consulted in the following circumstances: -\begin{itemize} -\item Something goes wrong. For example, if a model is not -Blanchard--Kahn stable, then the eigenvalues are dumped to the journal -file. - -If the unconditional covariance matrix {\tt dyn\_vcov} is NaN, then -from the journal file you will know that all the simulations had to be -thrown away due to occurrence of NaN or Inf. This is caused by -non-stationarity of the resulting decision rule. - -If Dynare++ crashes, the journal file can be helpful for guessing a -point where it crashed. - -\item You are impatient. You might be looking at the journal file -during the run in order to have a better estimate about the time when -the calculations are finished. In Unix, I use a command {\tt tail -f -blah.jnl}.\footnote{This helps to develop one of the three -programmer's virtues: {\it impatience}. The other two are {\it -laziness} and {\it hubris}; according to Larry Wall.} - -\item Heavy swapping. If the physical memory is not -sufficient, an operating system starts swapping memory pages with a -disk. If this is the case, the journal file can be consulted for -information on memory consumption and swapping activity. - -\item Not sure what Dynare++ is doing. If so, read the journal file, -which contains a detailed record on what was calculated, simulated -etc. -\end{itemize} - -\subsection{Dump File} -\label{dumpfile} - -The dump file is always created with the suffix {\tt .dump}. It is a -text file which takes a form of a model file. It sets the parameter -values which were used, it has the initval section setting the values -which were finally used, and mainly it has a model section of all -equations with all substitutions and formed the first order conditions -of the planner. - -The dump file serves for debugging purposes, since it contains the -mathematical problem which is being solved by dynare++. - -\subsection{MATLAB Scripts for Steady State Calculations} -\label{output_matlab_scripts} - -This section describes two MATLAB scripts, which are useful when -calculating the deterministic steady state outside Dynare++. The -scripts are created by Dynare++ as soon as an input file is parsed, -that is before any calculations. - -The first MATLAB script having a name {\tt {\it modname}\_f.m} for -given parameters values and given all endogenous variables $y$ -calculates a residual of the static system. Supposing the model is in -the form of \eqref{focs}, the script calculates a vector: -\[ -f(y,y,y,0) -\] - -The second script having a name {\tt {\it modname}\_ff.m} calculates a matrix: -\[ -\frac{\partial}{\partial y}f(y,y,y,0) -\] - -Both scripts take two arguments. The first is a vector of parameter -values ordered in the same ordering as declared in the model file. The -second is a vector of all endogenous variables at which the evaluation -is performed. These endogenous variables also include auxiliary -variables automatically added by Dynare++ and Lagrange multipliers if -an optimal policy problem is solved. If no endogenous variable has not -been added by Dynare++, then the ordering is the same as the ordering -in declaration in the model file. If some endogenous variables have -been added, then the ordering can be read from comments close to the -top of either two files. - -For example, if we want to calculate the deterministic steady state of -the {\tt kp1980.dyn} model, we need to do the following: -\begin{enumerate} -\item Run Dynare++ with {\tt kp1980.dyn}, no matter if the calculation -has not been finished, important output are the two MATLAB scripts -created just in the beginning. -\item Consult file {\tt kp1980\_f.m}\ to get the ordering of parameters -and all endogenous variables. -\item Create a vector {\tt p} with the parameter values in the ordering -\item Create a vector {\tt init\_y} with the initial guess for the -MATLAB solver {\tt fsolve} -\item Create a simple MATLAB function called {\tt kp1980\_fsolve.m}\ -returning the residual and Jacobian: -{\small -\begin{verbatim} -function [r, J] = kp1980_fsolve(p, y) - r = kp1980_f(p, y); - J = kp1980_ff(p, y); -\end{verbatim} -} -\item In the MATLAB prompt, run the following: -{\small -\begin{verbatim} -opt=optimset('Jacobian','on','Display','iter'); -y=fsolve(@(y) kp1980_fsolve(p,y), init_y, opt); -\end{verbatim} -} -\end{enumerate} - - -\subsection{Custom Simulations} -\label{custom} - -When Dynare++ run is finished it dumps the derivatives of the -calculated decision rule to the MAT file. The derivatives can be used -for a construction of the decision rule and custom simulations can be -run. This is done by {\tt dynare\_simul.m} M-file in MATLAB. It reads -the derivatives and simulates the decision rule with provided -realization of shocks. - -All the necessary documentation can be viewed by the command: -{\small -\begin{verbatim} -help dynare_simul -\end{verbatim} -} - -\end{document} diff --git a/dynare++/dynare_simul/dynare_simul.m b/dynare++/dynare_simul/dynare_simul.m deleted file mode 100644 index 293d3a73207991edbd9f88927ab3d6fd2d7119f8..0000000000000000000000000000000000000000 --- a/dynare++/dynare_simul/dynare_simul.m +++ /dev/null @@ -1,176 +0,0 @@ -% -% SYNOPSIS -% -% r = dynare_simul(name, shocks) -% r = dynare_simul(name, prefix, shocks) -% r = dynare_simul(name, shocks, start) -% r = dynare_simul(name, prefix, shocks, start) -% -% name name of MAT-file produced by dynare++ -% prefix prefix of variables in the MAT-file -% shocks matrix of shocks -% start zero period value -% -% Note that this file requires the dynare_simul_ DLL to be in the path. -% This DLL is distributed with Dynare, under the mex/matlab or mex/octave -% subdirectory. -% -% SEMANTICS -% -% The command reads a decision rule from the MAT-file having the given -% prefix. Then it starts simulating the decision rule with zero time value -% equal to the given start. It uses the given shocks for the simulation. If -% the start is not given, the state about which the decision rule is -% centralized is taken (called fix point, or stochastic steady state, take -% your pick). -% -% prefix Use the prefix with which you called dynare++, the default -% prefix in dynare++ is 'dyn'. -% shocks Number of rows must be a number of exogenous shocks, -% number of columns gives the number of simulated -% periods. NaNs and Infs in the matrix are substitued by -% draws from the normal distribution using the covariance -% matrix given in the model file. -% start Vector of endogenous variables in the ordering given by -% <prefix>_vars. -% -% Seed for random generator is derived from calling rand(1,1). Therefore, -% seeding can be controlled with rand('state') and rand('state',some_seed). -% -% EXAMPLES -% -% All examples suppose that the prefix is 'dyn' and that your_model.mat -% has been loaded into Matlab. -% -% 1. response to permanent negative shock to the third exo var EPS3 for -% 100 periods -% -% shocks = zeros(4,100); % 4 exogenous variables in the model -% shocks(dyn_i_EPS3,:) = -0.1; % the permanent shock to EPS3 -% r = dynare_simul('your_model.mat',shocks); -% -% 2. one stochastic simulation for 100 periods -% -% shocks = zeros(4,100)./0; % put NaNs everywhere -% r = dynare_simul('your_model.mat',shocks); -% -% 3. one stochastic simulation starting at 75% undercapitalized economy -% -% shocks = zeros(4,100)./0; % put NaNs everywhere -% ystart = dyn_ss; % get copy of DR fix point -% ystart(dyn_i_K) = 0.75*dyn_ss(dyn_i_K); % scale down the capital -% r = dynare_simul('your_model.mat',shocks,ystart); -% -% -% SEE ALSO -% -% "DSGE Models with Dynare++. A Tutorial.", Ondra Kamenik, 2005 - -% Copyright © 2005-2011, Ondra Kamenik -% Copyright © 2020, Dynare Team - - -function r = dynare_simul(varargin) - -if ~exist('dynare_simul_','file') - error('Can''t find dynare_simul_ DLL in the path. The simplest way to add it is to run Dynare once in this session.') -end - -% get the file name and load data -fname = varargin{1}; -load(fname); - -% set prefix, shocks, ystart -if ischar(varargin{2}) - prefix = varargin{2}; - if length(varargin) == 3 - shocks = varargin{3}; - ystart = NaN; - elseif length(varargin) == 4 - shocks = varargin{3}; - ystart = varargin{4}; - else - error('Wrong number of parameters.'); - end -else - prefix = 'dyn'; - if length(varargin) == 2 - shocks = varargin{2}; - ystart = NaN; - elseif length(varargin) == 3 - shocks = varargin{2}; - ystart = varargin{3}; - else - error('Wrong number of parameters.'); - end -end - -% load all needed variables but prefix_g_* -if exist([prefix '_nstat'],'var') - nstat = eval([prefix '_nstat']); -else - error(['Could not find variable ' prefix '_nstat in workspace']); -end -if exist([prefix '_npred'],'var') - npred = eval([prefix '_npred']); -else - error(['Could not find variable ' prefix '_npred in workspace']); -end -if exist([prefix '_nboth'],'var') - nboth = eval([prefix '_nboth']); -else - error(['Could not find variable ' prefix '_nboth in workspace']); -end -if exist([prefix '_nforw'],'var') - nforw = eval([prefix '_nforw']); -else - error(['Could not find variable ' prefix '_nforw in workspace']); -end -if exist([prefix '_ss'],'var') - ss = eval([prefix '_ss']); -else - error(['Could not find variable ' prefix '_ss in workspace']); -end -if exist([prefix '_vcov_exo'],'var') - vcov_exo = eval([prefix '_vcov_exo']); -else - error(['Could not find variable ' prefix '_vcov_exo in workspace']); -end -nexog = size(vcov_exo,1); - -if isnan(ystart) - ystart = ss; -end - -% newer version of dynare++ doesn't return prefix_g_0, we make it here if -% it does not exist in workspace -g_zero = [prefix '_g_0']; -if ~exist(g_zero,'var') - dr.g_0=zeros(nstat+npred+nboth+nforw,1); -else - dr.g_0=eval(g_zero); -end - -% make derstr a string of comma seperated existing prefix_g_* -order = 1; -cont = 1; -while cont == 1 - g_ord = [prefix '_g_' num2str(order)]; - if exist(g_ord,'var') - dr.(['g_' num2str(order)])=eval(g_ord); - order = order + 1; - else - cont = 0; - end -end - -% set seed -seed = ceil(10000*rand(1,1)); - -% call dynare_simul_ -[err,r]=dynare_simul_(order-1,nstat,npred,nboth,nforw,... - nexog,ystart,shocks,vcov_exo,seed,ss,dr); - -if err - error('Simulation failed') -end \ No newline at end of file diff --git a/dynare++/integ/Makefile.am b/dynare++/integ/Makefile.am deleted file mode 100644 index 24104f1e7664f30ecb971eb22e2ae0a2011a2065..0000000000000000000000000000000000000000 --- a/dynare++/integ/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = cc src testing diff --git a/dynare++/integ/cc/Makefile.am b/dynare++/integ/cc/Makefile.am deleted file mode 100644 index 4e98a764017ca23283a3201d6b00ea228f30bf7c..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -noinst_LIBRARIES = libinteg.a - -libinteg_a_SOURCES = \ - quadrature.cc \ - quadrature.hh \ - quasi_mcarlo.cc \ - quasi_mcarlo.hh \ - product.cc \ - product.hh \ - smolyak.cc \ - smolyak.hh \ - vector_function.cc \ - vector_function.hh \ - precalc_quadrature.hh -libinteg_a_CPPFLAGS = -I../../sylv/cc -I../../utils/cc -I../../tl/cc -I$(top_srcdir)/mex/sources diff --git a/dynare++/integ/cc/precalc_quadrature.hh b/dynare++/integ/cc/precalc_quadrature.hh deleted file mode 100644 index fca4d80e36946e3408e39b9d84aeaaf66d4b71bb..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/precalc_quadrature.hh +++ /dev/null @@ -1,1748 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -// The file contains one dimensional quadrature points and weights for a few -// quadratures. The format of data is clear. There is a class -// OneDPrecalcQuadrature which implements an interface OneDQuadrature using the -// data of this format. - -// Gauss-Hermite quadrature; prefix gh - -// Number of levels -static const int gh_num_levels = 26; - -// Number of points in each level -static const int gh_num_points[] = - { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 30, 32, 40, 50, 60, 64 - }; - -// Weights, starting with the first level -static const double gh_weights[] = - { - // weights 1 = √π - 1.77245385090551588191942755656782537698745727539062, - // weights 2 - 0.886226925452758013649083741671e+00, - 0.886226925452758013649083741671e+00, - // weights 3 - 0.295408975150919337883027913890e+00, - 0.118163590060367735153211165556e+01, - 0.295408975150919337883027913890e+00, - // weights 4 - 0.813128354472451771430345571899e-01, - 0.804914090005512836506049184481e+00, - 0.804914090005512836506049184481e+00, - 0.813128354472451771430345571899e-01, - // weights 5 - 0.199532420590459132077434585942e-01, - 0.393619323152241159828495620852e+00, - 0.945308720482941881225689324449e+00, - 0.393619323152241159828495620852e+00, - 0.199532420590459132077434585942e-01, - // weights 6 - 0.453000990550884564085747256463e-02, - 0.157067320322856643916311563508e+00, - 0.724629595224392524091914705598e+00, - 0.724629595224392524091914705598e+00, - 0.157067320322856643916311563508e+00, - 0.453000990550884564085747256463e-02, - // weights 7 - 0.971781245099519154149424255939e-03, - 0.545155828191270305921785688417e-01, - 0.425607252610127800520317466666e+00, - 0.810264617556807326764876563813e+00, - 0.425607252610127800520317466666e+00, - 0.545155828191270305921785688417e-01, - 0.971781245099519154149424255939e-03, - // weights 8 - 0.199604072211367619206090452544e-03, - 0.170779830074134754562030564364e-01, - 0.207802325814891879543258620286e+00, - 0.661147012558241291030415974496e+00, - 0.661147012558241291030415974496e+00, - 0.207802325814891879543258620286e+00, - 0.170779830074134754562030564364e-01, - 0.199604072211367619206090452544e-03, - // weights 9 - 0.396069772632643819045862946425e-04, - 0.494362427553694721722456597763e-02, - 0.884745273943765732879751147476e-01, - 0.432651559002555750199812112956e+00, - 0.720235215606050957124334723389e+00, - 0.432651559002555750199812112956e+00, - 0.884745273943765732879751147476e-01, - 0.494362427553694721722456597763e-02, - 0.396069772632643819045862946425e-04, - // weights 10 - 0.764043285523262062915936785960e-05, - 0.134364574678123269220156558585e-02, - 0.338743944554810631361647312776e-01, - 0.240138611082314686416523295006e+00, - 0.610862633735325798783564990433e+00, - 0.610862633735325798783564990433e+00, - 0.240138611082314686416523295006e+00, - 0.338743944554810631361647312776e-01, - 0.134364574678123269220156558585e-02, - 0.764043285523262062915936785960e-05, - // weights 11 - 0.143956039371425822033088366032e-05, - 0.346819466323345510643413772940e-03, - 0.119113954449115324503874202916e-01, - 0.117227875167708503381788649308e+00, - 0.429359752356125028446073598601e+00, - 0.654759286914591779203940657627e+00, - 0.429359752356125028446073598601e+00, - 0.117227875167708503381788649308e+00, - 0.119113954449115324503874202916e-01, - 0.346819466323345510643413772940e-03, - 0.143956039371425822033088366032e-05, - // weights 12 - 0.265855168435630160602311400877e-06, - 0.857368704358785865456906323153e-04, - 0.390539058462906185999438432620e-02, - 0.516079856158839299918734423606e-01, - 0.260492310264161129233396139765e+00, - 0.570135236262479578347113482275e+00, - 0.570135236262479578347113482275e+00, - 0.260492310264161129233396139765e+00, - 0.516079856158839299918734423606e-01, - 0.390539058462906185999438432620e-02, - 0.857368704358785865456906323153e-04, - 0.265855168435630160602311400877e-06, - // weights 13 - 0.482573185007313108834997332342e-07, - 0.204303604027070731248669432937e-04, - 0.120745999271938594730924899224e-02, - 0.208627752961699392166033805050e-01, - 0.140323320687023437762792268873e+00, - 0.421616296898543221746893558568e+00, - 0.604393187921161642342099068579e+00, - 0.421616296898543221746893558568e+00, - 0.140323320687023437762792268873e+00, - 0.208627752961699392166033805050e-01, - 0.120745999271938594730924899224e-02, - 0.204303604027070731248669432937e-04, - 0.482573185007313108834997332342e-07, - // weights 14 - 0.862859116812515794532041783429e-08, - 0.471648435501891674887688950105e-05, - 0.355092613551923610483661076691e-03, - 0.785005472645794431048644334608e-02, - 0.685055342234652055387163312367e-01, - 0.273105609064246603352569187026e+00, - 0.536405909712090149794921296776e+00, - 0.536405909712090149794921296776e+00, - 0.273105609064246603352569187026e+00, - 0.685055342234652055387163312367e-01, - 0.785005472645794431048644334608e-02, - 0.355092613551923610483661076691e-03, - 0.471648435501891674887688950105e-05, - 0.862859116812515794532041783429e-08, - // weights 15 - 0.152247580425351702016062666965e-08, - 0.105911554771106663577520791055e-05, - 0.100004441232499868127296736177e-03, - 0.277806884291277589607887049229e-02, - 0.307800338725460822286814158758e-01, - 0.158488915795935746883839384960e+00, - 0.412028687498898627025891079568e+00, - 0.564100308726417532852625797340e+00, - 0.412028687498898627025891079568e+00, - 0.158488915795935746883839384960e+00, - 0.307800338725460822286814158758e-01, - 0.277806884291277589607887049229e-02, - 0.100004441232499868127296736177e-03, - 0.105911554771106663577520791055e-05, - 0.152247580425351702016062666965e-08, - // weights 16 - 0.265480747401118224470926366050e-09, - 0.232098084486521065338749423185e-06, - 0.271186009253788151201891432244e-04, - 0.932284008624180529914277305537e-03, - 0.128803115355099736834642999312e-01, - 0.838100413989858294154207349001e-01, - 0.280647458528533675369463335380e+00, - 0.507929479016613741913517341791e+00, - 0.507929479016613741913517341791e+00, - 0.280647458528533675369463335380e+00, - 0.838100413989858294154207349001e-01, - 0.128803115355099736834642999312e-01, - 0.932284008624180529914277305537e-03, - 0.271186009253788151201891432244e-04, - 0.232098084486521065338749423185e-06, - 0.265480747401118224470926366050e-09, - // weights 17 - 0.458057893079863330580889281222e-10, - 0.497707898163079405227863353715e-07, - 0.711228914002130958353327376218e-05, - 0.298643286697753041151336643059e-03, - 0.506734995762753791170069495879e-02, - 0.409200341495762798094994877854e-01, - 0.172648297670097079217645196219e+00, - 0.401826469470411956577635085257e+00, - 0.530917937624863560331883103379e+00, - 0.401826469470411956577635085257e+00, - 0.172648297670097079217645196219e+00, - 0.409200341495762798094994877854e-01, - 0.506734995762753791170069495879e-02, - 0.298643286697753041151336643059e-03, - 0.711228914002130958353327376218e-05, - 0.497707898163079405227863353715e-07, - 0.458057893079863330580889281222e-10, - // weights 18 - 0.782819977211589102925147471012e-11, - 0.104672057957920824443559608435e-07, - 0.181065448109343040959702385911e-05, - 0.918112686792940352914675407371e-04, - 0.188852263026841789438175325426e-02, - 0.186400423875446519219315221973e-01, - 0.973017476413154293308537234155e-01, - 0.284807285669979578595606820713e+00, - 0.483495694725455552876410522141e+00, - 0.483495694725455552876410522141e+00, - 0.284807285669979578595606820713e+00, - 0.973017476413154293308537234155e-01, - 0.186400423875446519219315221973e-01, - 0.188852263026841789438175325426e-02, - 0.918112686792940352914675407371e-04, - 0.181065448109343040959702385911e-05, - 0.104672057957920824443559608435e-07, - 0.782819977211589102925147471012e-11, - // weights 19 - 0.132629709449851575185289154385e-11, - 0.216305100986355475019693077221e-08, - 0.448824314722312295179447915594e-06, - 0.272091977631616257711941025214e-04, - 0.670877521407181106194696282100e-03, - 0.798886677772299020922211491861e-02, - 0.508103869090520673569908110358e-01, - 0.183632701306997074156148485766e+00, - 0.391608988613030244504042313621e+00, - 0.502974888276186530840731361096e+00, - 0.391608988613030244504042313621e+00, - 0.183632701306997074156148485766e+00, - 0.508103869090520673569908110358e-01, - 0.798886677772299020922211491861e-02, - 0.670877521407181106194696282100e-03, - 0.272091977631616257711941025214e-04, - 0.448824314722312295179447915594e-06, - 0.216305100986355475019693077221e-08, - 0.132629709449851575185289154385e-11, - // weights 20 - 0.222939364553415129252250061603e-12, - 0.439934099227318055362885145547e-09, - 0.108606937076928169399952456345e-06, - 0.780255647853206369414599199965e-05, - 0.228338636016353967257145917963e-03, - 0.324377334223786183218324713235e-02, - 0.248105208874636108821649525589e-01, - 0.109017206020023320013755033535e+00, - 0.286675505362834129719659706228e+00, - 0.462243669600610089650328639861e+00, - 0.462243669600610089650328639861e+00, - 0.286675505362834129719659706228e+00, - 0.109017206020023320013755033535e+00, - 0.248105208874636108821649525589e-01, - 0.324377334223786183218324713235e-02, - 0.228338636016353967257145917963e-03, - 0.780255647853206369414599199965e-05, - 0.108606937076928169399952456345e-06, - 0.439934099227318055362885145547e-09, - 0.222939364553415129252250061603e-12, - // weights 30 - 0.290825470013122622941102747365e-20, - 0.281033360275090370876277491534e-16, - 0.287860708054870606219239791142e-13, - 0.810618629746304420399344796173e-11, - 0.917858042437852820850075742492e-09, - 0.510852245077594627738963204403e-07, - 0.157909488732471028834638794022e-05, - 0.293872522892298764150118423412e-04, - 0.348310124318685523420995323183e-03, - 0.273792247306765846298942568953e-02, - 0.147038297048266835152773557787e-01, - 0.551441768702342511680754948183e-01, - 0.146735847540890099751693643152e+00, - 0.280130930839212667413493211293e+00, - 0.386394889541813862555601849165e+00, - 0.386394889541813862555601849165e+00, - 0.280130930839212667413493211293e+00, - 0.146735847540890099751693643152e+00, - 0.551441768702342511680754948183e-01, - 0.147038297048266835152773557787e-01, - 0.273792247306765846298942568953e-02, - 0.348310124318685523420995323183e-03, - 0.293872522892298764150118423412e-04, - 0.157909488732471028834638794022e-05, - 0.510852245077594627738963204403e-07, - 0.917858042437852820850075742492e-09, - 0.810618629746304420399344796173e-11, - 0.287860708054870606219239791142e-13, - 0.281033360275090370876277491534e-16, - 0.290825470013122622941102747365e-20, - // weights 32 - 0.731067642736e-22, - 0.923173653649e-18, - 0.119734401709e-14, - 0.421501021125e-12, - 0.593329146300e-10, - 0.409883216476e-08, - 0.157416779254e-06, - 0.365058512955e-05, - 0.541658406172e-04, - 0.536268365526e-03, - 0.365489032664e-02, - 0.175534288315e-01, - 0.604581309557e-01, - 0.151269734076e+00, - 0.277458142302e+00, - 0.375238352592e+00, - 0.375238352592e+00, - 0.277458142302e+00, - 0.151269734076e+00, - 0.604581309557e-01, - 0.175534288315e-01, - 0.365489032664e-02, - 0.536268365526e-03, - 0.541658406172e-04, - 0.365058512955e-05, - 0.157416779254e-06, - 0.409883216476e-08, - 0.593329146300e-10, - 0.421501021125e-12, - 0.119734401709e-14, - 0.923173653649e-18, - 0.731067642736e-22, - // weights 40 - 0.259104371384e-28, - 0.854405696375e-24, - 0.256759336540e-20, - 0.198918101211e-17, - 0.600835878947e-15, - 0.880570764518e-13, - 0.715652805267e-11, - 0.352562079135e-09, - 0.112123608322e-07, - 0.241114416359e-06, - 0.363157615067e-05, - 0.393693398108e-04, - 0.313853594540e-03, - 0.187149682959e-02, - 0.846088800823e-02, - 0.293125655361e-01, - 0.784746058652e-01, - 0.163378732713e+00, - 0.265728251876e+00, - 0.338643277425e+00, - 0.338643277425e+00, - 0.265728251876e+00, - 0.163378732713e+00, - 0.784746058652e-01, - 0.293125655361e-01, - 0.846088800823e-02, - 0.187149682959e-02, - 0.313853594540e-03, - 0.393693398108e-04, - 0.363157615067e-05, - 0.241114416359e-06, - 0.112123608322e-07, - 0.352562079135e-09, - 0.715652805267e-11, - 0.880570764518e-13, - 0.600835878947e-15, - 0.198918101211e-17, - 0.256759336540e-20, - 0.854405696375e-24, - 0.259104371384e-28, - // weights 50 - 0.183379404857e-36, - 0.167380166790e-31, - 0.121524412340e-27, - 0.213765830835e-24, - 0.141709359957e-21, - 0.447098436530e-19, - 0.774238295702e-17, - 0.809426189344e-15, - 0.546594403180e-13, - 0.250665552389e-11, - 0.811187736448e-10, - 0.190904054379e-08, - 0.334679340401e-07, - 0.445702996680e-06, - 0.458168270794e-05, - 0.368401905377e-04, - 0.234269892109e-03, - 0.118901178175e-02, - 0.485326382616e-02, - 0.160319410684e-01, - 0.430791591566e-01, - 0.945489354768e-01, - 0.170032455676e+00, - 0.251130856331e+00, - 0.305085129203e+00, - 0.305085129203e+00, - 0.251130856331e+00, - 0.170032455676e+00, - 0.945489354768e-01, - 0.430791591566e-01, - 0.160319410684e-01, - 0.485326382616e-02, - 0.118901178175e-02, - 0.234269892109e-03, - 0.368401905377e-04, - 0.458168270794e-05, - 0.445702996680e-06, - 0.334679340401e-07, - 0.190904054379e-08, - 0.811187736448e-10, - 0.250665552389e-11, - 0.546594403180e-13, - 0.809426189344e-15, - 0.774238295702e-17, - 0.447098436530e-19, - 0.141709359957e-21, - 0.213765830835e-24, - 0.121524412340e-27, - 0.167380166790e-31, - 0.183379404857e-36, - // weights 60 - 0.110958724796e-44, - 0.243974758810e-39, - 0.377162672698e-35, - 0.133255961176e-31, - 0.171557314767e-28, - 0.102940599693e-25, - 0.334575695574e-23, - 0.651256725748e-21, - 0.815364047300e-19, - 0.692324790956e-17, - 0.415244410968e-15, - 0.181662457614e-13, - 0.594843051597e-12, - 0.148895734905e-10, - 0.289935901280e-09, - 0.445682277521e-08, - 0.547555461926e-07, - 0.543351613419e-06, - 0.439428693625e-05, - 0.291874190415e-04, - 0.160277334681e-03, - 0.731773556963e-03, - 0.279132482894e-02, - 0.893217836028e-02, - 0.240612727660e-01, - 0.547189709320e-01, - 0.105298763697e+00, - 0.171776156918e+00, - 0.237868904958e+00, - 0.279853117522e+00, - 0.279853117522e+00, - 0.237868904958e+00, - 0.171776156918e+00, - 0.105298763697e+00, - 0.547189709320e-01, - 0.240612727660e-01, - 0.893217836028e-02, - 0.279132482894e-02, - 0.731773556963e-03, - 0.160277334681e-03, - 0.291874190415e-04, - 0.439428693625e-05, - 0.543351613419e-06, - 0.547555461926e-07, - 0.445682277521e-08, - 0.289935901280e-09, - 0.148895734905e-10, - 0.594843051597e-12, - 0.181662457614e-13, - 0.415244410968e-15, - 0.692324790956e-17, - 0.815364047300e-19, - 0.651256725748e-21, - 0.334575695574e-23, - 0.102940599693e-25, - 0.171557314767e-28, - 0.133255961176e-31, - 0.377162672698e-35, - 0.243974758810e-39, - 0.110958724796e-44, - // weights 64 - 0.553570653584e-48, - 0.167974799010e-42, - 0.342113801099e-38, - 0.155739062462e-34, - 0.254966089910e-31, - 0.192910359546e-28, - 0.786179778889e-26, - 0.191170688329e-23, - 0.298286278427e-21, - 0.315225456649e-19, - 0.235188471067e-17, - 0.128009339117e-15, - 0.521862372645e-14, - 0.162834073070e-12, - 0.395917776693e-11, - 0.761521725012e-10, - 0.117361674232e-08, - 0.146512531647e-07, - 0.149553293672e-06, - 0.125834025103e-05, - 0.878849923082e-05, - 0.512592913577e-04, - 0.250983698512e-03, - 0.103632909950e-02, - 0.362258697852e-02, - 0.107560405098e-01, - 0.272031289536e-01, - 0.587399819634e-01, - 0.108498349306e+00, - 0.171685842349e+00, - 0.232994786062e+00, - 0.271377424940e+00, - 0.271377424940e+00, - 0.232994786062e+00, - 0.171685842349e+00, - 0.108498349306e+00, - 0.587399819634e-01, - 0.272031289536e-01, - 0.107560405098e-01, - 0.362258697852e-02, - 0.103632909950e-02, - 0.250983698512e-03, - 0.512592913577e-04, - 0.878849923082e-05, - 0.125834025103e-05, - 0.149553293672e-06, - 0.146512531647e-07, - 0.117361674232e-08, - 0.761521725012e-10, - 0.395917776693e-11, - 0.162834073070e-12, - 0.521862372645e-14, - 0.128009339117e-15, - 0.235188471067e-17, - 0.315225456649e-19, - 0.298286278427e-21, - 0.191170688329e-23, - 0.786179778889e-26, - 0.192910359546e-28, - 0.254966089910e-31, - 0.155739062462e-34, - 0.342113801099e-38, - 0.167974799010e-42, - 0.553570653584e-48 - }; - -// Points, starting with the first level -static const double gh_points[] = - { - // points 1 - 0.0, - // points 2 - -0.707106781186547524400844362105e+00, - 0.707106781186547524400844362105e+00, - // points 3 - -0.122474487139158904909864203735e+01, - 0.0e+00, - 0.122474487139158904909864203735e+01, - // points 4 - -0.165068012388578455588334111112e+01, - -0.524647623275290317884060253835e+00, - 0.524647623275290317884060253835e+00, - 0.165068012388578455588334111112e+01, - // points 5 - -0.202018287045608563292872408814e+01, - -0.958572464613818507112770593893e+00, - 0.0e+00, - 0.958572464613818507112770593893e+00, - 0.202018287045608563292872408814e+01, - // points 6 - -0.235060497367449222283392198706e+01, - -0.133584907401369694971489528297e+01, - -0.436077411927616508679215948251e+00, - 0.436077411927616508679215948251e+00, - 0.133584907401369694971489528297e+01, - 0.235060497367449222283392198706e+01, - // points 7 - -0.265196135683523349244708200652e+01, - -0.167355162876747144503180139830e+01, - -0.816287882858964663038710959027e+00, - 0.0e+00, - 0.816287882858964663038710959027e+00, - 0.167355162876747144503180139830e+01, - 0.265196135683523349244708200652e+01, - // points 8 - -0.293063742025724401922350270524e+01, - -0.198165675669584292585463063977e+01, - -0.115719371244678019472076577906e+01, - -0.381186990207322116854718885584e+00, - 0.381186990207322116854718885584e+00, - 0.115719371244678019472076577906e+01, - 0.198165675669584292585463063977e+01, - 0.293063742025724401922350270524e+01, - // points 9 - -0.319099320178152760723004779538e+01, - -0.226658058453184311180209693284e+01, - -0.146855328921666793166701573925e+01, - -0.723551018752837573322639864579e+00, - 0.0e+00, - 0.723551018752837573322639864579e+00, - 0.146855328921666793166701573925e+01, - 0.226658058453184311180209693284e+01, - 0.319099320178152760723004779538e+01, - // points 10 - -0.343615911883773760332672549432e+01, - -0.253273167423278979640896079775e+01, - -0.175668364929988177345140122011e+01, - -0.103661082978951365417749191676e+01, - -0.342901327223704608789165025557e+00, - 0.342901327223704608789165025557e+00, - 0.103661082978951365417749191676e+01, - 0.175668364929988177345140122011e+01, - 0.253273167423278979640896079775e+01, - 0.343615911883773760332672549432e+01, - // points 11 - -0.366847084655958251845837146485e+01, - -0.278329009978165177083671870152e+01, - -0.202594801582575533516591283121e+01, - -0.132655708449493285594973473558e+01, - -0.656809566882099765024611575383e+00, - 0.0e+00, - 0.656809566882099765024611575383e+00, - 0.132655708449493285594973473558e+01, - 0.202594801582575533516591283121e+01, - 0.278329009978165177083671870152e+01, - 0.366847084655958251845837146485e+01, - // points 12 - -0.388972489786978191927164274724e+01, - -0.302063702512088977171067937518e+01, - -0.227950708050105990018772856942e+01, - -0.159768263515260479670966277090e+01, - -0.947788391240163743704578131060e+00, - -0.314240376254359111276611634095e+00, - 0.314240376254359111276611634095e+00, - 0.947788391240163743704578131060e+00, - 0.159768263515260479670966277090e+01, - 0.227950708050105990018772856942e+01, - 0.302063702512088977171067937518e+01, - 0.388972489786978191927164274724e+01, - // points 13 - -0.410133759617863964117891508007e+01, - -0.324660897837240998812205115236e+01, - -0.251973568567823788343040913628e+01, - -0.185310765160151214200350644316e+01, - -0.122005503659074842622205526637e+01, - -0.605763879171060113080537108602e+00, - 0.0e+00, - 0.605763879171060113080537108602e+00, - 0.122005503659074842622205526637e+01, - 0.185310765160151214200350644316e+01, - 0.251973568567823788343040913628e+01, - 0.324660897837240998812205115236e+01, - 0.410133759617863964117891508007e+01, - // points 14 - -0.430444857047363181262129810037e+01, - -0.346265693360227055020891736115e+01, - -0.274847072498540256862499852415e+01, - -0.209518325850771681573497272630e+01, - -0.147668273114114087058350654421e+01, - -0.878713787329399416114679311861e+00, - -0.291745510672562078446113075799e+00, - 0.291745510672562078446113075799e+00, - 0.878713787329399416114679311861e+00, - 0.147668273114114087058350654421e+01, - 0.209518325850771681573497272630e+01, - 0.274847072498540256862499852415e+01, - 0.346265693360227055020891736115e+01, - 0.430444857047363181262129810037e+01, - // points 15 - -0.449999070730939155366438053053e+01, - -0.366995037340445253472922383312e+01, - -0.296716692790560324848896036355e+01, - -0.232573248617385774545404479449e+01, - -0.171999257518648893241583152515e+01, - -0.113611558521092066631913490556e+01, - -0.565069583255575748526020337198e+00, - 0.0e+00, - 0.565069583255575748526020337198e+00, - 0.113611558521092066631913490556e+01, - 0.171999257518648893241583152515e+01, - 0.232573248617385774545404479449e+01, - 0.296716692790560324848896036355e+01, - 0.366995037340445253472922383312e+01, - 0.449999070730939155366438053053e+01, - // points 16 - -0.468873893930581836468849864875e+01, - -0.386944790486012269871942409801e+01, - -0.317699916197995602681399455926e+01, - -0.254620215784748136215932870545e+01, - -0.195178799091625397743465541496e+01, - -0.138025853919888079637208966969e+01, - -0.822951449144655892582454496734e+00, - -0.273481046138152452158280401965e+00, - 0.273481046138152452158280401965e+00, - 0.822951449144655892582454496734e+00, - 0.138025853919888079637208966969e+01, - 0.195178799091625397743465541496e+01, - 0.254620215784748136215932870545e+01, - 0.317699916197995602681399455926e+01, - 0.386944790486012269871942409801e+01, - 0.468873893930581836468849864875e+01, - // points 17 - -0.487134519367440308834927655662e+01, - -0.406194667587547430689245559698e+01, - -0.337893209114149408338327069289e+01, - -0.275776291570388873092640349574e+01, - -0.217350282666662081927537907149e+01, - -0.161292431422123133311288254454e+01, - -0.106764872574345055363045773799e+01, - -0.531633001342654731349086553718e+00, - 0.0e+00, - 0.531633001342654731349086553718e+00, - 0.106764872574345055363045773799e+01, - 0.161292431422123133311288254454e+01, - 0.217350282666662081927537907149e+01, - 0.275776291570388873092640349574e+01, - 0.337893209114149408338327069289e+01, - 0.406194667587547430689245559698e+01, - 0.487134519367440308834927655662e+01, - // points 18 - -0.504836400887446676837203757885e+01, - -0.424811787356812646302342016090e+01, - -0.357376906848626607950067599377e+01, - -0.296137750553160684477863254906e+01, - -0.238629908916668600026459301424e+01, - -0.183553160426162889225383944409e+01, - -0.130092085838961736566626555439e+01, - -0.776682919267411661316659462284e+00, - -0.258267750519096759258116098711e+00, - 0.258267750519096759258116098711e+00, - 0.776682919267411661316659462284e+00, - 0.130092085838961736566626555439e+01, - 0.183553160426162889225383944409e+01, - 0.238629908916668600026459301424e+01, - 0.296137750553160684477863254906e+01, - 0.357376906848626607950067599377e+01, - 0.424811787356812646302342016090e+01, - 0.504836400887446676837203757885e+01, - // points 19 - -0.522027169053748216460967142500e+01, - -0.442853280660377943723498532226e+01, - -0.376218735196402009751489394104e+01, - -0.315784881834760228184318034120e+01, - -0.259113378979454256492128084112e+01, - -0.204923170985061937575050838669e+01, - -0.152417061939353303183354859367e+01, - -0.101036838713431135136859873726e+01, - -0.503520163423888209373811765050e+00, - 0.0e+00, - 0.503520163423888209373811765050e+00, - 0.101036838713431135136859873726e+01, - 0.152417061939353303183354859367e+01, - 0.204923170985061937575050838669e+01, - 0.259113378979454256492128084112e+01, - 0.315784881834760228184318034120e+01, - 0.376218735196402009751489394104e+01, - 0.442853280660377943723498532226e+01, - 0.522027169053748216460967142500e+01, - // points 20 - -0.538748089001123286201690041068e+01, - -0.460368244955074427307767524898e+01, - -0.394476404011562521037562880052e+01, - -0.334785456738321632691492452300e+01, - -0.278880605842813048052503375640e+01, - -0.225497400208927552308233334473e+01, - -0.173853771211658620678086566214e+01, - -0.123407621539532300788581834696e+01, - -0.737473728545394358705605144252e+00, - -0.245340708300901249903836530634e+00, - 0.245340708300901249903836530634e+00, - 0.737473728545394358705605144252e+00, - 0.123407621539532300788581834696e+01, - 0.173853771211658620678086566214e+01, - 0.225497400208927552308233334473e+01, - 0.278880605842813048052503375640e+01, - 0.334785456738321632691492452300e+01, - 0.394476404011562521037562880052e+01, - 0.460368244955074427307767524898e+01, - 0.538748089001123286201690041068e+01, - // points 30 - -6.86334529352989158106110835756e+00, - -6.13827922012393462039499237854e+00, - -5.53314715156749572511833355558e+00, - -4.98891896858994394448649710633e+00, - -4.48305535709251834188703761971e+00, - -4.00390860386122881522787601332e+00, - -3.54444387315534988692540090217e+00, - -3.09997052958644174868873332237e+00, - -2.66713212453561720057110646422e+00, - -2.24339146776150407247297999483e+00, - -1.82674114360368803883588048351e+00, - -1.41552780019818851194072510555e+00, - -1.00833827104672346180498960870e+00, - -0.603921058625552307778155678757e+00, - -0.201128576548871485545763013244e+00, - 0.201128576548871485545763013244e+00, - 0.603921058625552307778155678757e+00, - 1.00833827104672346180498960870e+00, - 1.41552780019818851194072510555e+00, - 1.82674114360368803883588048351e+00, - 2.24339146776150407247297999483e+00, - 2.66713212453561720057110646422e+00, - 3.09997052958644174868873332237e+00, - 3.54444387315534988692540090217e+00, - 4.00390860386122881522787601332e+00, - 4.48305535709251834188703761971e+00, - 4.98891896858994394448649710633e+00, - 5.53314715156749572511833355558e+00, - 6.13827922012393462039499237854e+00, - 6.86334529352989158106110835756e+00, - // points 32 - -7.12581390983e+00, - -6.40949814927e+00, - -5.81222594952e+00, - -5.27555098652e+00, - -4.77716450350e+00, - -4.30554795335e+00, - -3.85375548547e+00, - -3.41716749282e+00, - -2.99249082500e+00, - -2.57724953773e+00, - -2.16949918361e+00, - -1.76765410946e+00, - -1.37037641095e+00, - -0.976500463590e+00, - -0.584978765436e+00, - -0.194840741569e+00, - 0.194840741569e+00, - 0.584978765436e+00, - 0.976500463590e+00, - 1.37037641095e+00, - 1.76765410946e+00, - 2.16949918361e+00, - 2.57724953773e+00, - 2.99249082500e+00, - 3.41716749282e+00, - 3.85375548547e+00, - 4.30554795335e+00, - 4.77716450350e+00, - 5.27555098652e+00, - 5.81222594952e+00, - 6.40949814927e+00, - 7.12581390983e+00, - // points 40 - -8.09876113925e+00, - -7.41158253149e+00, - -6.84023730525e+00, - -6.32825535122e+00, - -5.85409505603e+00, - -5.40665424797e+00, - -4.97926097855e+00, - -4.56750207284e+00, - -4.16825706683e+00, - -3.77920675344e+00, - -3.39855826586e+00, - -3.02487988390e+00, - -2.65699599844e+00, - -2.29391714188e+00, - -1.93479147228e+00, - -1.57886989493e+00, - -1.22548010905e+00, - -0.874006612357e+00, - -0.523874713832e+00, - -0.174537214598e+00, - 0.174537214598e+00, - 0.523874713832e+00, - 0.874006612357e+00, - 1.22548010905e+00, - 1.57886989493e+00, - 1.93479147228e+00, - 2.29391714188e+00, - 2.65699599844e+00, - 3.02487988390e+00, - 3.39855826586e+00, - 3.77920675344e+00, - 4.16825706683e+00, - 4.56750207284e+00, - 4.97926097855e+00, - 5.40665424797e+00, - 5.85409505603e+00, - 6.32825535122e+00, - 6.84023730525e+00, - 7.41158253149e+00, - 8.09876113925e+00, - // points 50 - -9.18240695813e+00, - -8.52277103092e+00, - -7.97562236821e+00, - -7.48640942986e+00, - -7.03432350977e+00, - -6.60864797386e+00, - -6.20295251927e+00, - -5.81299467542e+00, - -5.43578608722e+00, - -5.06911758492e+00, - -4.71129366617e+00, - -4.36097316045e+00, - -4.01706817286e+00, - -3.67867706252e+00, - -3.34503831394e+00, - -3.01549776957e+00, - -2.68948470227e+00, - -2.36649390430e+00, - -2.04607196869e+00, - -1.72780654752e+00, - -1.41131775490e+00, - -1.09625112896e+00, - -0.782271729555e+00, - -0.469059056678e+00, - -0.156302546889e+00, - 0.156302546889e+00, - 0.469059056678e+00, - 0.782271729555e+00, - 1.09625112896e+00, - 1.41131775490e+00, - 1.72780654752e+00, - 2.04607196869e+00, - 2.36649390430e+00, - 2.68948470227e+00, - 3.01549776957e+00, - 3.34503831394e+00, - 3.67867706252e+00, - 4.01706817286e+00, - 4.36097316045e+00, - 4.71129366617e+00, - 5.06911758492e+00, - 5.43578608722e+00, - 5.81299467542e+00, - 6.20295251927e+00, - 6.60864797386e+00, - 7.03432350977e+00, - 7.48640942986e+00, - 7.97562236821e+00, - 8.52277103092e+00, - 9.18240695813e+00, - // points 60 - -10.1591092462e+00, - -9.52090367701e+00, - -8.99239800140e+00, - -8.52056928412e+00, - -8.08518865425e+00, - -7.67583993750e+00, - -7.28627659440e+00, - -6.91238153219e+00, - -6.55125916706e+00, - -6.20077355799e+00, - -5.85929019639e+00, - -5.52552108614e+00, - -5.19842653458e+00, - -4.87715007747e+00, - -4.56097375794e+00, - -4.24928643596e+00, - -3.94156073393e+00, - -3.63733587617e+00, - -3.33620465355e+00, - -3.03780333823e+00, - -2.74180374807e+00, - -2.44790690231e+00, - -2.15583787123e+00, - -1.86534153123e+00, - -1.57617901198e+00, - -1.28812467487e+00, - -1.00096349956e+00, - -0.714488781673e+00, - -0.428500064221e+00, - -0.142801238703e+00, - 0.142801238703e+00, - 0.428500064221e+00, - 0.714488781673e+00, - 1.00096349956e+00, - 1.28812467487e+00, - 1.57617901198e+00, - 1.86534153123e+00, - 2.15583787123e+00, - 2.44790690231e+00, - 2.74180374807e+00, - 3.03780333823e+00, - 3.33620465355e+00, - 3.63733587617e+00, - 3.94156073393e+00, - 4.24928643596e+00, - 4.56097375794e+00, - 4.87715007747e+00, - 5.19842653458e+00, - 5.52552108614e+00, - 5.85929019639e+00, - 6.20077355799e+00, - 6.55125916706e+00, - 6.91238153219e+00, - 7.28627659440e+00, - 7.67583993750e+00, - 8.08518865425e+00, - 8.52056928412e+00, - 8.99239800140e+00, - 9.52090367701e+00, - 10.1591092462e+00, - // points 64 - -10.5261231680e+00, - -9.89528758683e+00, - -9.37315954965e+00, - -8.90724909996e+00, - -8.47752908338e+00, - -8.07368728501e+00, - -7.68954016404e+00, - -7.32101303278e+00, - -6.96524112055e+00, - -6.62011226264e+00, - -6.28401122877e+00, - -5.95566632680e+00, - -5.63405216435e+00, - -5.31832522463e+00, - -5.00777960220e+00, - -4.70181564741e+00, - -4.39991716823e+00, - -4.10163447457e+00, - -3.80657151395e+00, - -3.51437593574e+00, - -3.22473129199e+00, - -2.93735082300e+00, - -2.65197243543e+00, - -2.36835458863e+00, - -2.08627287988e+00, - -1.80551717147e+00, - -1.52588914021e+00, - -1.24720015694e+00, - -0.969269423071e+00, - -0.691922305810e+00, - -0.414988824121e+00, - -0.138302244987e+00, - 0.138302244987e+00, - 0.414988824121e+00, - 0.691922305810e+00, - 0.969269423071e+00, - 1.24720015694e+00, - 1.52588914021e+00, - 1.80551717147e+00, - 2.08627287988e+00, - 2.36835458863e+00, - 2.65197243543e+00, - 2.93735082300e+00, - 3.22473129199e+00, - 3.51437593574e+00, - 3.80657151395e+00, - 4.10163447457e+00, - 4.39991716823e+00, - 4.70181564741e+00, - 5.00777960220e+00, - 5.31832522463e+00, - 5.63405216435e+00, - 5.95566632680e+00, - 6.28401122877e+00, - 6.62011226264e+00, - 6.96524112055e+00, - 7.32101303278e+00, - 7.68954016404e+00, - 8.07368728501e+00, - 8.47752908338e+00, - 8.90724909996e+00, - 9.37315954965e+00, - 9.89528758683e+00, - 10.5261231680e+00 - }; - -// Gauss-Legendre quadrature; prefix gl - -// Number of levels -static const int gl_num_levels = 22; - -// Number of points in each level -static const int gl_num_points[] = - { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 32, 64 - }; - -// Weights, starting with the first level -static const double gl_weights[] = - { - // weight 1 - 2.0e+00, - // weights 2 - 1.0e+00, - 1.0e+00, - // weights 3 - 0.555555555555555555555555555555e+00, - 0.888888888888888888888888888888e+00, - 0.555555555555555555555555555555e+00, - // weights 4 - 0.347854845137453857373063949222e+00, - 0.652145154862546142626936050778e+00, - 0.652145154862546142626936050778e+00, - 0.347854845137453857373063949222e+00, - // weights 5 - 0.236926885056189087514264040720e+00, - 0.478628670499366468041291514836e+00, - 0.568888888888888888888888888889e+00, - 0.478628670499366468041291514836e+00, - 0.236926885056189087514264040720e+00, - // weights 6 - 0.171324492379170345040296142173e+00, - 0.360761573048138607569833513838e+00, - 0.467913934572691047389870343990e+00, - 0.467913934572691047389870343990e+00, - 0.360761573048138607569833513838e+00, - 0.171324492379170345040296142173e+00, - // weights 7 - 0.129484966168869693270611432679e+00, - 0.279705391489276667901467771424e+00, - 0.381830050505118944950369775489e+00, - 0.417959183673469387755102040816e+00, - 0.381830050505118944950369775489e+00, - 0.279705391489276667901467771424e+00, - 0.129484966168869693270611432679e+00, - // weights 8 - 0.101228536290376259152531354310e+00, - 0.222381034453374470544355994426e+00, - 0.313706645877887287337962201987e+00, - 0.362683783378361982965150449277e+00, - 0.362683783378361982965150449277e+00, - 0.313706645877887287337962201987e+00, - 0.222381034453374470544355994426e+00, - 0.101228536290376259152531354310e+00, - // weights 9 - 0.812743883615744119718921581105e-01, - 0.180648160694857404058472031243e+00, - 0.260610696402935462318742869419e+00, - 0.312347077040002840068630406584e+00, - 0.330239355001259763164525069287e+00, - 0.312347077040002840068630406584e+00, - 0.260610696402935462318742869419e+00, - 0.180648160694857404058472031243e+00, - 0.812743883615744119718921581105e-01, - // weights 10 - 0.666713443086881375935688098933e-01, - 0.149451349150580593145776339658e+00, - 0.219086362515982043995534934228e+00, - 0.269266719309996355091226921569e+00, - 0.295524224714752870173892994651e+00, - 0.295524224714752870173892994651e+00, - 0.269266719309996355091226921569e+00, - 0.219086362515982043995534934228e+00, - 0.149451349150580593145776339658e+00, - 0.666713443086881375935688098933e-01, - // weights 11 - 0.556685671161736664827537204425e-01, - 0.125580369464904624634694299224e+00, - 0.186290210927734251426097641432e+00, - 0.233193764591990479918523704843e+00, - 0.262804544510246662180688869891e+00, - 0.272925086777900630714483528336e+00, - 0.262804544510246662180688869891e+00, - 0.233193764591990479918523704843e+00, - 0.186290210927734251426097641432e+00, - 0.125580369464904624634694299224e+00, - 0.556685671161736664827537204425e-01, - // weights 12 - 0.471753363865118271946159614850e-01, - 0.106939325995318430960254718194e+00, - 0.160078328543346226334652529543e+00, - 0.203167426723065921749064455810e+00, - 0.233492536538354808760849898925e+00, - 0.249147045813402785000562436043e+00, - 0.249147045813402785000562436043e+00, - 0.233492536538354808760849898925e+00, - 0.203167426723065921749064455810e+00, - 0.160078328543346226334652529543e+00, - 0.106939325995318430960254718194e+00, - 0.471753363865118271946159614850e-01, - // weights 13 - 0.404840047653158795200215922010e-01, - 0.921214998377284479144217759538e-01, - 0.138873510219787238463601776869e+00, - 0.178145980761945738280046691996e+00, - 0.207816047536888502312523219306e+00, - 0.226283180262897238412090186040e+00, - 0.232551553230873910194589515269e+00, - 0.226283180262897238412090186040e+00, - 0.207816047536888502312523219306e+00, - 0.178145980761945738280046691996e+00, - 0.138873510219787238463601776869e+00, - 0.921214998377284479144217759538e-01, - 0.404840047653158795200215922010e-01, - // weights 14 - 0.351194603317518630318328761382e-01, - 0.801580871597602098056332770629e-01, - 0.121518570687903184689414809072e+00, - 0.157203167158193534569601938624e+00, - 0.185538397477937813741716590125e+00, - 0.205198463721295603965924065661e+00, - 0.215263853463157790195876443316e+00, - 0.215263853463157790195876443316e+00, - 0.205198463721295603965924065661e+00, - 0.185538397477937813741716590125e+00, - 0.157203167158193534569601938624e+00, - 0.121518570687903184689414809072e+00, - 0.801580871597602098056332770629e-01, - 0.351194603317518630318328761382e-01, - // weights 15 - 0.307532419961172683546283935772e-01, - 0.703660474881081247092674164507e-01, - 0.107159220467171935011869546686e+00, - 0.139570677926154314447804794511e+00, - 0.166269205816993933553200860481e+00, - 0.186161000015562211026800561866e+00, - 0.198431485327111576456118326444e+00, - 0.202578241925561272880620199968e+00, - 0.198431485327111576456118326444e+00, - 0.186161000015562211026800561866e+00, - 0.166269205816993933553200860481e+00, - 0.139570677926154314447804794511e+00, - 0.107159220467171935011869546686e+00, - 0.703660474881081247092674164507e-01, - 0.307532419961172683546283935772e-01, - // weights 16 - 0.271524594117540948517805724560e-01, - 0.622535239386478928628438369944e-01, - 0.951585116824927848099251076022e-01, - 0.124628971255533872052476282192e+00, - 0.149595988816576732081501730547e+00, - 0.169156519395002538189312079030e+00, - 0.182603415044923588866763667969e+00, - 0.189450610455068496285396723208e+00, - 0.189450610455068496285396723208e+00, - 0.182603415044923588866763667969e+00, - 0.169156519395002538189312079030e+00, - 0.149595988816576732081501730547e+00, - 0.124628971255533872052476282192e+00, - 0.951585116824927848099251076022e-01, - 0.622535239386478928628438369944e-01, - 0.271524594117540948517805724560e-01, - // weights 17 - 0.241483028685479319601100262876e-01, - 0.554595293739872011294401653582e-01, - 0.850361483171791808835353701911e-01, - 0.111883847193403971094788385626e+00, - 0.135136368468525473286319981702e+00, - 0.154045761076810288081431594802e+00, - 0.168004102156450044509970663788e+00, - 0.176562705366992646325270990113e+00, - 0.179446470356206525458265644262e+00, - 0.176562705366992646325270990113e+00, - 0.168004102156450044509970663788e+00, - 0.154045761076810288081431594802e+00, - 0.135136368468525473286319981702e+00, - 0.111883847193403971094788385626e+00, - 0.850361483171791808835353701911e-01, - 0.554595293739872011294401653582e-01, - 0.241483028685479319601100262876e-01, - // weights 18 - 0.216160135264833103133427102665e-01, - 0.497145488949697964533349462026e-01, - 0.764257302548890565291296776166e-01, - 0.100942044106287165562813984925e+00, - 0.122555206711478460184519126800e+00, - 0.140642914670650651204731303752e+00, - 0.154684675126265244925418003836e+00, - 0.164276483745832722986053776466e+00, - 0.169142382963143591840656470135e+00, - 0.169142382963143591840656470135e+00, - 0.164276483745832722986053776466e+00, - 0.154684675126265244925418003836e+00, - 0.140642914670650651204731303752e+00, - 0.122555206711478460184519126800e+00, - 0.100942044106287165562813984925e+00, - 0.764257302548890565291296776166e-01, - 0.497145488949697964533349462026e-01, - 0.216160135264833103133427102665e-01, - // weights 19 - 0.194617882297264770363120414644e-01, - 0.448142267656996003328381574020e-01, - 0.690445427376412265807082580060e-01, - 0.914900216224499994644620941238e-01, - 0.111566645547333994716023901682e+00, - 0.128753962539336227675515784857e+00, - 0.142606702173606611775746109442e+00, - 0.152766042065859666778855400898e+00, - 0.158968843393954347649956439465e+00, - 0.161054449848783695979163625321e+00, - 0.158968843393954347649956439465e+00, - 0.152766042065859666778855400898e+00, - 0.142606702173606611775746109442e+00, - 0.128753962539336227675515784857e+00, - 0.111566645547333994716023901682e+00, - 0.914900216224499994644620941238e-01, - 0.690445427376412265807082580060e-01, - 0.448142267656996003328381574020e-01, - 0.194617882297264770363120414644e-01, - // weights 20 - 0.176140071391521183118619623519e-01, - 0.406014298003869413310399522749e-01, - 0.626720483341090635695065351870e-01, - 0.832767415767047487247581432220e-01, - 0.101930119817240435036750135480e+00, - 0.118194531961518417312377377711e+00, - 0.131688638449176626898494499748e+00, - 0.142096109318382051329298325067e+00, - 0.149172986472603746787828737002e+00, - 0.152753387130725850698084331955e+00, - 0.152753387130725850698084331955e+00, - 0.149172986472603746787828737002e+00, - 0.142096109318382051329298325067e+00, - 0.131688638449176626898494499748e+00, - 0.118194531961518417312377377711e+00, - 0.101930119817240435036750135480e+00, - 0.832767415767047487247581432220e-01, - 0.626720483341090635695065351870e-01, - 0.406014298003869413310399522749e-01, - 0.176140071391521183118619623519e-01, - // weights 32 - 0.701861000947009660040706373885e-02, - 0.162743947309056706051705622064e-01, - 0.253920653092620594557525897892e-01, - 0.342738629130214331026877322524e-01, - 0.428358980222266806568786466061e-01, - 0.509980592623761761961632446895e-01, - 0.586840934785355471452836373002e-01, - 0.658222227763618468376500637069e-01, - 0.723457941088485062253993564785e-01, - 0.781938957870703064717409188283e-01, - 0.833119242269467552221990746043e-01, - 0.876520930044038111427714627518e-01, - 0.911738786957638847128685771116e-01, - 0.938443990808045656391802376681e-01, - 0.956387200792748594190820022041e-01, - 0.965400885147278005667648300636e-01, - 0.965400885147278005667648300636e-01, - 0.956387200792748594190820022041e-01, - 0.938443990808045656391802376681e-01, - 0.911738786957638847128685771116e-01, - 0.876520930044038111427714627518e-01, - 0.833119242269467552221990746043e-01, - 0.781938957870703064717409188283e-01, - 0.723457941088485062253993564785e-01, - 0.658222227763618468376500637069e-01, - 0.586840934785355471452836373002e-01, - 0.509980592623761761961632446895e-01, - 0.428358980222266806568786466061e-01, - 0.342738629130214331026877322524e-01, - 0.253920653092620594557525897892e-01, - 0.162743947309056706051705622064e-01, - 0.701861000947009660040706373885e-02, - // weights 64 - 0.178328072169643294729607914497e-02, - 0.414703326056246763528753572855e-02, - 0.650445796897836285611736039998e-02, - 0.884675982636394772303091465973e-02, - 0.111681394601311288185904930192e-01, - 0.134630478967186425980607666860e-01, - 0.157260304760247193219659952975e-01, - 0.179517157756973430850453020011e-01, - 0.201348231535302093723403167285e-01, - 0.222701738083832541592983303842e-01, - 0.243527025687108733381775504091e-01, - 0.263774697150546586716917926252e-01, - 0.283396726142594832275113052002e-01, - 0.302346570724024788679740598195e-01, - 0.320579283548515535854675043479e-01, - 0.338051618371416093915654821107e-01, - 0.354722132568823838106931467152e-01, - 0.370551285402400460404151018096e-01, - 0.385501531786156291289624969468e-01, - 0.399537411327203413866569261283e-01, - 0.412625632426235286101562974736e-01, - 0.424735151236535890073397679088e-01, - 0.435837245293234533768278609737e-01, - 0.445905581637565630601347100309e-01, - 0.454916279274181444797709969713e-01, - 0.462847965813144172959532492323e-01, - 0.469681828162100173253262857546e-01, - 0.475401657148303086622822069442e-01, - 0.479993885964583077281261798713e-01, - 0.483447622348029571697695271580e-01, - 0.485754674415034269347990667840e-01, - 0.486909570091397203833653907347e-01, - 0.486909570091397203833653907347e-01, - 0.485754674415034269347990667840e-01, - 0.483447622348029571697695271580e-01, - 0.479993885964583077281261798713e-01, - 0.475401657148303086622822069442e-01, - 0.469681828162100173253262857546e-01, - 0.462847965813144172959532492323e-01, - 0.454916279274181444797709969713e-01, - 0.445905581637565630601347100309e-01, - 0.435837245293234533768278609737e-01, - 0.424735151236535890073397679088e-01, - 0.412625632426235286101562974736e-01, - 0.399537411327203413866569261283e-01, - 0.385501531786156291289624969468e-01, - 0.370551285402400460404151018096e-01, - 0.354722132568823838106931467152e-01, - 0.338051618371416093915654821107e-01, - 0.320579283548515535854675043479e-01, - 0.302346570724024788679740598195e-01, - 0.283396726142594832275113052002e-01, - 0.263774697150546586716917926252e-01, - 0.243527025687108733381775504091e-01, - 0.222701738083832541592983303842e-01, - 0.201348231535302093723403167285e-01, - 0.179517157756973430850453020011e-01, - 0.157260304760247193219659952975e-01, - 0.134630478967186425980607666860e-01, - 0.111681394601311288185904930192e-01, - 0.884675982636394772303091465973e-02, - 0.650445796897836285611736039998e-02, - 0.414703326056246763528753572855e-02, - 0.178328072169643294729607914497e-02 - }; - -// Points, starting with the first level -static const double gl_points[] = - { - // points 1 - 0.0e+00, - // points 2 - -0.577350269189625764509148780502e+00, - 0.577350269189625764509148780502e+00, - // points 3 - -0.774596669241483377035853079956e+00, - 0.0e+00, - 0.774596669241483377035853079956e+00, - // points 4 - -0.861136311594052575223946488893e+00, - -0.339981043584856264802665759103e+00, - 0.339981043584856264802665759103e+00, - 0.861136311594052575223946488893e+00, - // points 5 - -0.906179845938663992797626878299e+00, - -0.538469310105683091036314420700e+00, - 0.0e+00, - 0.538469310105683091036314420700e+00, - 0.906179845938663992797626878299e+00, - // points 6 - -0.932469514203152027812301554494e+00, - -0.661209386466264513661399595020e+00, - -0.238619186083196908630501721681e+00, - 0.238619186083196908630501721681e+00, - 0.661209386466264513661399595020e+00, - 0.932469514203152027812301554494e+00, - // points 7 - -0.949107912342758524526189684048e+00, - -0.741531185599394439863864773281e+00, - -0.405845151377397166906606412077e+00, - 0.0e+00, - 0.405845151377397166906606412077e+00, - 0.741531185599394439863864773281e+00, - 0.949107912342758524526189684048e+00, - // points 8 - -0.960289856497536231683560868569e+00, - -0.796666477413626739591553936476e+00, - -0.525532409916328985817739049189e+00, - -0.183434642495649804939476142360e+00, - 0.183434642495649804939476142360e+00, - 0.525532409916328985817739049189e+00, - 0.796666477413626739591553936476e+00, - 0.960289856497536231683560868569e+00, - // points 9 - -0.968160239507626089835576202904e+00, - -0.836031107326635794299429788070e+00, - -0.613371432700590397308702039341e+00, - -0.324253423403808929038538014643e+00, - 0.0e+00, - 0.324253423403808929038538014643e+00, - 0.613371432700590397308702039341e+00, - 0.836031107326635794299429788070e+00, - 0.968160239507626089835576202904e+00, - // points 10 - -0.973906528517171720077964012084e+00, - -0.865063366688984510732096688423e+00, - -0.679409568299024406234327365115e+00, - -0.433395394129247190799265943166e+00, - -0.148874338981631210884826001130e+00, - 0.148874338981631210884826001130e+00, - 0.433395394129247190799265943166e+00, - 0.679409568299024406234327365115e+00, - 0.865063366688984510732096688423e+00, - 0.973906528517171720077964012084e+00, - // points 11 - -0.978228658146056992803938001123e+00, - -0.887062599768095299075157769304e+00, - -0.730152005574049324093416252031e+00, - -0.519096129206811815925725669459e+00, - -0.269543155952344972331531985401e+00, - 0.0e+00, - 0.269543155952344972331531985401e+00, - 0.519096129206811815925725669459e+00, - 0.730152005574049324093416252031e+00, - 0.887062599768095299075157769304e+00, - 0.978228658146056992803938001123e+00, - // points 12 - -0.981560634246719250690549090149e+00, - -0.904117256370474856678465866119e+00, - -0.769902674194304687036893833213e+00, - -0.587317954286617447296702418941e+00, - -0.367831498998180193752691536644e+00, - -0.125233408511468915472441369464e+00, - 0.125233408511468915472441369464e+00, - 0.367831498998180193752691536644e+00, - 0.587317954286617447296702418941e+00, - 0.769902674194304687036893833213e+00, - 0.904117256370474856678465866119e+00, - 0.981560634246719250690549090149e+00, - // points 13 - -0.984183054718588149472829448807e+00, - -0.917598399222977965206547836501e+00, - -0.801578090733309912794206489583e+00, - -0.642349339440340220643984606996e+00, - -0.448492751036446852877912852128e+00, - -0.230458315955134794065528121098e+00, - 0.0e+00, - 0.230458315955134794065528121098e+00, - 0.448492751036446852877912852128e+00, - 0.642349339440340220643984606996e+00, - 0.801578090733309912794206489583e+00, - 0.917598399222977965206547836501e+00, - 0.984183054718588149472829448807e+00, - // points 14 - -0.986283808696812338841597266704e+00, - -0.928434883663573517336391139378e+00, - -0.827201315069764993189794742650e+00, - -0.687292904811685470148019803019e+00, - -0.515248636358154091965290718551e+00, - -0.319112368927889760435671824168e+00, - -0.108054948707343662066244650220e+00, - 0.108054948707343662066244650220e+00, - 0.319112368927889760435671824168e+00, - 0.515248636358154091965290718551e+00, - 0.687292904811685470148019803019e+00, - 0.827201315069764993189794742650e+00, - 0.928434883663573517336391139378e+00, - 0.986283808696812338841597266704e+00, - // points 15 - -0.987992518020485428489565718587e+00, - -0.937273392400705904307758947710e+00, - -0.848206583410427216200648320774e+00, - -0.724417731360170047416186054614e+00, - -0.570972172608538847537226737254e+00, - -0.394151347077563369897207370981e+00, - -0.201194093997434522300628303395e+00, - 0.0e+00, - 0.201194093997434522300628303395e+00, - 0.394151347077563369897207370981e+00, - 0.570972172608538847537226737254e+00, - 0.724417731360170047416186054614e+00, - 0.848206583410427216200648320774e+00, - 0.937273392400705904307758947710e+00, - 0.987992518020485428489565718587e+00, - // points 16 - -0.989400934991649932596154173450e+00, - -0.944575023073232576077988415535e+00, - -0.865631202387831743880467897712e+00, - -0.755404408355003033895101194847e+00, - -0.617876244402643748446671764049e+00, - -0.458016777657227386342419442984e+00, - -0.281603550779258913230460501460e+00, - -0.950125098376374401853193354250e-01, - 0.950125098376374401853193354250e-01, - 0.281603550779258913230460501460e+00, - 0.458016777657227386342419442984e+00, - 0.617876244402643748446671764049e+00, - 0.755404408355003033895101194847e+00, - 0.865631202387831743880467897712e+00, - 0.944575023073232576077988415535e+00, - 0.989400934991649932596154173450e+00, - // points 17 - -0.990575475314417335675434019941e+00, - -0.950675521768767761222716957896e+00, - -0.880239153726985902122955694488e+00, - -0.781514003896801406925230055520e+00, - -0.657671159216690765850302216643e+00, - -0.512690537086476967886246568630e+00, - -0.351231763453876315297185517095e+00, - -0.178484181495847855850677493654e+00, - 0.0e+00, - 0.178484181495847855850677493654e+00, - 0.351231763453876315297185517095e+00, - 0.512690537086476967886246568630e+00, - 0.657671159216690765850302216643e+00, - 0.781514003896801406925230055520e+00, - 0.880239153726985902122955694488e+00, - 0.950675521768767761222716957896e+00, - 0.990575475314417335675434019941e+00, - // points 18 - -0.991565168420930946730016004706e+00, - -0.955823949571397755181195892930e+00, - -0.892602466497555739206060591127e+00, - -0.803704958972523115682417455015e+00, - -0.691687043060353207874891081289e+00, - -0.559770831073947534607871548525e+00, - -0.411751161462842646035931793833e+00, - -0.251886225691505509588972854878e+00, - -0.847750130417353012422618529358e-01, - 0.847750130417353012422618529358e-01, - 0.251886225691505509588972854878e+00, - 0.411751161462842646035931793833e+00, - 0.559770831073947534607871548525e+00, - 0.691687043060353207874891081289e+00, - 0.803704958972523115682417455015e+00, - 0.892602466497555739206060591127e+00, - 0.955823949571397755181195892930e+00, - 0.991565168420930946730016004706e+00, - // points 19 - -0.992406843843584403189017670253e+00, - -0.960208152134830030852778840688e+00, - -0.903155903614817901642660928532e+00, - -0.822714656537142824978922486713e+00, - -0.720966177335229378617095860824e+00, - -0.600545304661681023469638164946e+00, - -0.464570741375960945717267148104e+00, - -0.316564099963629831990117328850e+00, - -0.160358645640225375868096115741e+00, - 0.0e+00, - 0.160358645640225375868096115741e+00, - 0.316564099963629831990117328850e+00, - 0.464570741375960945717267148104e+00, - 0.600545304661681023469638164946e+00, - 0.720966177335229378617095860824e+00, - 0.822714656537142824978922486713e+00, - 0.903155903614817901642660928532e+00, - 0.960208152134830030852778840688e+00, - 0.992406843843584403189017670253e+00, - // points 20 - -0.993128599185094924786122388471e+00, - -0.963971927277913791267666131197e+00, - -0.912234428251325905867752441203e+00, - -0.839116971822218823394529061702e+00, - -0.746331906460150792614305070356e+00, - -0.636053680726515025452836696226e+00, - -0.510867001950827098004364050955e+00, - -0.373706088715419560672548177025e+00, - -0.227785851141645078080496195369e+00, - -0.765265211334973337546404093988e-01, - 0.765265211334973337546404093988e-01, - 0.227785851141645078080496195369e+00, - 0.373706088715419560672548177025e+00, - 0.510867001950827098004364050955e+00, - 0.636053680726515025452836696226e+00, - 0.746331906460150792614305070356e+00, - 0.839116971822218823394529061702e+00, - 0.912234428251325905867752441203e+00, - 0.963971927277913791267666131197e+00, - 0.993128599185094924786122388471e+00, - // points 32 - -0.997263861849481563544981128665e+00, - -0.985611511545268335400175044631e+00, - -0.964762255587506430773811928118e+00, - -0.934906075937739689170919134835e+00, - -0.896321155766052123965307243719e+00, - -0.849367613732569970133693004968e+00, - -0.794483795967942406963097298970e+00, - -0.732182118740289680387426665091e+00, - -0.663044266930215200975115168663e+00, - -0.587715757240762329040745476402e+00, - -0.506899908932229390023747474378e+00, - -0.421351276130635345364119436172e+00, - -0.331868602282127649779916805730e+00, - -0.239287362252137074544603209166e+00, - -0.144471961582796493485186373599e+00, - -0.483076656877383162348125704405e-01, - 0.483076656877383162348125704405e-01, - 0.144471961582796493485186373599e+00, - 0.239287362252137074544603209166e+00, - 0.331868602282127649779916805730e+00, - 0.421351276130635345364119436172e+00, - 0.506899908932229390023747474378e+00, - 0.587715757240762329040745476402e+00, - 0.663044266930215200975115168663e+00, - 0.732182118740289680387426665091e+00, - 0.794483795967942406963097298970e+00, - 0.849367613732569970133693004968e+00, - 0.896321155766052123965307243719e+00, - 0.934906075937739689170919134835e+00, - 0.964762255587506430773811928118e+00, - 0.985611511545268335400175044631e+00, - 0.997263861849481563544981128665e+00, - // points 64 - -0.999305041735772139456905624346e+00, - -0.996340116771955279346924500676e+00, - -0.991013371476744320739382383443e+00, - -0.983336253884625956931299302157e+00, - -0.973326827789910963741853507352e+00, - -0.961008799652053718918614121897e+00, - -0.946411374858402816062481491347e+00, - -0.929569172131939575821490154559e+00, - -0.910522137078502805756380668008e+00, - -0.889315445995114105853404038273e+00, - -0.865999398154092819760783385070e+00, - -0.840629296252580362751691544696e+00, - -0.813265315122797559741923338086e+00, - -0.783972358943341407610220525214e+00, - -0.752819907260531896611863774886e+00, - -0.719881850171610826848940217832e+00, - -0.685236313054233242563558371031e+00, - -0.648965471254657339857761231993e+00, - -0.611155355172393250248852971019e+00, - -0.571895646202634034283878116659e+00, - -0.531279464019894545658013903544e+00, - -0.489403145707052957478526307022e+00, - -0.446366017253464087984947714759e+00, - -0.402270157963991603695766771260e+00, - -0.357220158337668115950442615046e+00, - -0.311322871990210956157512698560e+00, - -0.264687162208767416373964172510e+00, - -0.217423643740007084149648748989e+00, - -0.169644420423992818037313629748e+00, - -0.121462819296120554470376463492e+00, - -0.729931217877990394495429419403e-01, - -0.243502926634244325089558428537e-01, - 0.243502926634244325089558428537e-01, - 0.729931217877990394495429419403e-01, - 0.121462819296120554470376463492e+00, - 0.169644420423992818037313629748e+00, - 0.217423643740007084149648748989e+00, - 0.264687162208767416373964172510e+00, - 0.311322871990210956157512698560e+00, - 0.357220158337668115950442615046e+00, - 0.402270157963991603695766771260e+00, - 0.446366017253464087984947714759e+00, - 0.489403145707052957478526307022e+00, - 0.531279464019894545658013903544e+00, - 0.571895646202634034283878116659e+00, - 0.611155355172393250248852971019e+00, - 0.648965471254657339857761231993e+00, - 0.685236313054233242563558371031e+00, - 0.719881850171610826848940217832e+00, - 0.752819907260531896611863774886e+00, - 0.783972358943341407610220525214e+00, - 0.813265315122797559741923338086e+00, - 0.840629296252580362751691544696e+00, - 0.865999398154092819760783385070e+00, - 0.889315445995114105853404038273e+00, - 0.910522137078502805756380668008e+00, - 0.929569172131939575821490154559e+00, - 0.946411374858402816062481491347e+00, - 0.961008799652053718918614121897e+00, - 0.973326827789910963741853507352e+00, - 0.983336253884625956931299302157e+00, - 0.991013371476744320739382383443e+00, - 0.996340116771955279346924500676e+00, - 0.999305041735772139456905624346e+00 - }; diff --git a/dynare++/integ/cc/product.cc b/dynare++/integ/cc/product.cc deleted file mode 100644 index ad9f7296dceb9b801fe7946ddbcde1b67061f48d..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/product.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "product.hh" -#include "symmetry.hh" - -#include <iostream> -#include <iomanip> - -/* This constructs a product iterator corresponding to index (j0,0,…,0). */ - -prodpit::prodpit(const ProductQuadrature &q, int j0, int l) - : prodq(q), level(l), npoints(q.uquad.numPoints(l)), - jseq(q.dimen(), 0), - end_flag(false), - sig{q.dimen()}, - p{q.dimen()} -{ - if (j0 < npoints) - { - jseq[0] = j0; - setPointAndWeight(); - } - else - end_flag = true; -} - -bool -prodpit::operator==(const prodpit &ppit) const -{ - return &prodq == &ppit.prodq && end_flag == ppit.end_flag && jseq == ppit.jseq; -} - -prodpit & -prodpit::operator++() -{ - int i = prodq.dimen()-1; - jseq[i]++; - while (i >= 0 && jseq[i] == npoints) - { - jseq[i] = 0; - i--; - if (i >= 0) - jseq[i]++; - } - sig.signalAfter(std::max(i, 0)); - - if (i == -1) - end_flag = true; - - if (!end_flag) - setPointAndWeight(); - - return *this; -} - -/* This calculates the weight and sets point coordinates from the indices. */ - -void -prodpit::setPointAndWeight() -{ - w = 1.0; - for (int i = 0; i < prodq.dimen(); i++) - { - p[i] = (prodq.uquad).point(level, jseq[i]); - w *= (prodq.uquad).weight(level, jseq[i]); - } -} - -/* Debug print. */ - -void -prodpit::print() const -{ - auto ff = std::cout.flags(); - std::cout << "j=["; - for (int i = 0; i < prodq.dimen(); i++) - std::cout << std::setw(2) << jseq[i]; - std::cout << std::showpos << std::fixed << std::setprecision(3) - << "] " << std::setw(4) << w << "*("; - for (int i = 0; i < prodq.dimen()-1; i++) - std::cout << std::setw(4) << p[i] << ' '; - std::cout << std::setw(4) << p[prodq.dimen()-1] << ')' << std::endl; - std::cout.flags(ff); -} - -ProductQuadrature::ProductQuadrature(int d, const OneDQuadrature &uq) - : QuadratureImpl<prodpit>(d), uquad(uq) -{ - // TODO: check d≥1 -} - -/* This calls prodpit constructor to return an iterator which points - approximatelly at ‘ti’-th portion out of ‘tn’ portions. First we find - out how many points are in the level, and then construct an interator - (j0,0,…,0) where j0=ti·npoints/tn. */ - -prodpit -ProductQuadrature::begin(int ti, int tn, int l) const -{ - // TODO: raise if l<dimen() - // TODO: check l ≤ uquad.numLevels() - int npoints = uquad.numPoints(l); - return prodpit(*this, ti*npoints/tn, l); -} - -/* This just starts at the first level and goes to a higher level as long as a - number of evaluations (which is nₖᵈ for k being the level) is less than the - given number of evaluations. */ - -void -ProductQuadrature::designLevelForEvals(int max_evals, int &lev, int &evals) const -{ - int last_evals; - evals = 1; - lev = 1; - do - { - lev++; - last_evals = evals; - evals = numEvals(lev); - } - while (lev < uquad.numLevels()-2 && evals < max_evals); - lev--; - evals = last_evals; -} diff --git a/dynare++/integ/cc/product.hh b/dynare++/integ/cc/product.hh deleted file mode 100644 index 840bf7045a2aa60d2eee2984f085af908fa195df..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/product.hh +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -// Product quadrature. - -/* This file defines a product multidimensional quadrature. If Qₖ$ denotes the - one dimensional quadrature, then the product quadrature Q of k level and - dimension d takes the form: - - nₖ nₖ - Qf = ∑ … ∑ w_i₁·…·w_{i_d} f(x_i₁,…,x_{i_d}) - i₁=1 i_d=1 - - which can be written in terms of the one dimensional quadrature Qₖ as - - Qf=(Qₖ⊗…⊗Qₖ)f - - Here we define the product quadrature iterator prodpit and plug it into - QuadratureImpl to obtains ProductQuadrature. */ - -#ifndef PRODUCT_H -#define PRODUCT_H - -#include "int_sequence.hh" -#include "vector_function.hh" -#include "quadrature.hh" - -/* This defines a product point iterator. We have to maintain the following: a - pointer to product quadrature in order to know the dimension and the - underlying one dimensional quadrature, then level, number of points in the - level, integer sequence of indices, signal, the coordinates of the point and - the weight. - - The point indices, signal, and point coordinates are implmented as pointers - in order to allow for empty constructor. - - The constructor prodpit(const ProductQuadrature& q, int j0, int l) - constructs an iterator pointing to (j0,0,…,0), which is used by begin() - dictated by QuadratureImpl. */ - -class ProductQuadrature; - -class prodpit -{ -protected: - const ProductQuadrature &prodq; - int level{0}; - int npoints{0}; - IntSequence jseq; - bool end_flag{true}; - ParameterSignal sig; - Vector p; - double w; -public: - prodpit() = default; - prodpit(const ProductQuadrature &q, int j0, int l); - prodpit(const prodpit &ppit) = default; - ~prodpit() = default; - bool operator==(const prodpit &ppit) const; - bool - operator!=(const prodpit &ppit) const - { - return !operator==(ppit); - } - prodpit &operator=(const prodpit &spit) = delete; - prodpit &operator++(); - const ParameterSignal & - signal() const - { - return sig; - } - const Vector & - point() const - { - return p; - } - double - weight() const - { - return w; - } - void print() const; -protected: - void setPointAndWeight(); -}; - -/* The product quadrature is just QuadratureImpl with the product iterator - plugged in. The object is constructed by just giving the underlying one - dimensional quadrature, and the dimension. The only extra method is - designLevelForEvals() which for the given maximum number of evaluations (and - dimension and underlying quadrature from the object) returns a maximum level - yeilding number of evaluations less than the given number. */ - -class ProductQuadrature : public QuadratureImpl<prodpit> -{ - friend class prodpit; - const OneDQuadrature &uquad; -public: - ProductQuadrature(int d, const OneDQuadrature &uq); - ~ProductQuadrature() override = default; - int - numEvals(int l) const override - { - int res = 1; - for (int i = 0; i < dimen(); i++) - res *= uquad.numPoints(l); - return res; - } - void designLevelForEvals(int max_eval, int &lev, int &evals) const; -protected: - prodpit begin(int ti, int tn, int level) const override; -}; - -#endif diff --git a/dynare++/integ/cc/quadrature.cc b/dynare++/integ/cc/quadrature.cc deleted file mode 100644 index 9053240e4d8c1ad71768de1a7b3ad18505f9d84d..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/quadrature.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "quadrature.hh" -#include "precalc_quadrature.hh" - -#include <cmath> - -void -OneDPrecalcQuadrature::calcOffsets() -{ - offsets[0] = 0; - for (int i = 1; i < num_levels; i++) - offsets[i] = offsets[i-1] + num_points[i-1]; -} - -GaussHermite::GaussHermite() - : OneDPrecalcQuadrature(gh_num_levels, gh_num_points, gh_weights, gh_points) -{ -} - -GaussLegendre::GaussLegendre() - : OneDPrecalcQuadrature(gl_num_levels, gl_num_points, gl_weights, gl_points) -{ -} diff --git a/dynare++/integ/cc/quadrature.hh b/dynare++/integ/cc/quadrature.hh deleted file mode 100644 index 5f1bff9fc38d10e041d2e4fc40de766b26406a38..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/quadrature.hh +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -// Quadrature. - -/* This file defines an interface for one dimensional (non-nested) quadrature - OneDQuadrature, and a parent for all multi-dimensional quadratures. This - parent class Quadrature presents a general concept of quadrature, this is - - N - ∫ f(x)dx ≃ ∑ wᵢxᵢ - ⁱ⁼¹ - - The class Quadrature just declares this concept. The concept is implemented - by class QuadratureImpl which paralelizes the summation. All implementations - therefore wishing to use the parallel implementation should inherit from - QuadratureImpl and integration is done. - - The integration concept relies on a point iterator, which goes through all - xᵢ and wᵢ for i=1,…,N. All the iterators must be able to go through only a - portion of the set i=1,…,N. This enables us to implement paralelism, for two - threads for example, one iterator goes from the beginning to the - (approximately) half, and the other goes from the half to the end. - - Besides this concept of the general quadrature, this file defines also one - dimensional quadrature, which is basically a scheme of points and weights - for different levels. The class OneDQuadrature is a parent of all such - objects, the classes GaussHermite and GaussLegendre are specific - implementations for Gauss-Hermite and Gauss-Legendre quadratures resp. */ - -#ifndef QUADRATURE_H -#define QUADRATURE_H - -#include <iostream> -#include <fstream> -#include <iomanip> - -#include "vector_function.hh" -#include "int_sequence.hh" -#include "sthread.hh" - -/* This pure virtual class represents a concept of one-dimensional (non-nested) - quadrature. So, one dimensional quadrature must return number of levels, - number of points in a given level, and then a point and a weight in a given - level and given order. */ - -class OneDQuadrature -{ -public: - virtual ~OneDQuadrature() = default; - virtual int numLevels() const = 0; - virtual int numPoints(int level) const = 0; - virtual double point(int level, int i) const = 0; - virtual double weight(int lelel, int i) const = 0; -}; - -/* This is a general concept of multidimensional quadrature. at this general - level, we maintain only a dimension, and declare virtual functions for - integration. The function take two forms; first takes a constant - VectorFunction as an argument, creates locally VectorFunctionSet and do - calculation, second one takes as an argument VectorFunctionSet. - - Part of the interface is a method returning a number of evaluations for a - specific level. Note two things: this assumes that the number of evaluations - is known apriori and thus it is not applicable for adaptive quadratures, - second for Monte Carlo type of quadrature, the level is a number of - evaluations. */ - -class Quadrature -{ -protected: - int dim; -public: - Quadrature(int d) : dim(d) - { - } - virtual ~Quadrature() = default; - int - dimen() const - { - return dim; - } - virtual void integrate(const VectorFunction &func, int level, - int tn, Vector &out) const = 0; - virtual void integrate(VectorFunctionSet &fs, int level, Vector &out) const = 0; - virtual int numEvals(int level) const = 0; -}; - -/* This is just an integration worker, which works over a given QuadratureImpl. - It also needs the function, level, a specification of the subgroup of - points, and output vector. - - See QuadratureImpl class declaration for details. */ - -template<typename _Tpit> -class QuadratureImpl; - -template<typename _Tpit> -class IntegrationWorker : public sthread::detach_thread -{ - const QuadratureImpl<_Tpit> &quad; - VectorFunction &func; - int level; - int ti; - int tn; - Vector &outvec; -public: - IntegrationWorker(const QuadratureImpl<_Tpit> &q, VectorFunction &f, int l, - int tii, int tnn, Vector &out) - : quad(q), func(f), level(l), ti(tii), tn(tnn), outvec(out) - { - } - - /* This integrates the given portion of the integral. We obtain first and - last iterators for the portion (‘beg’ and ‘end’). Then we iterate through - the portion. and finally we add the intermediate result to the result - ‘outvec’. - - This method just everything up as it is coming. This might be imply large - numerical errors, perhaps in future something smarter should be implemented. */ - - void - operator()(std::mutex &mut) override - { - _Tpit beg = quad.begin(ti, tn, level); - _Tpit end = quad.begin(ti+1, tn, level); - Vector tmpall(outvec.length()); - tmpall.zeros(); - Vector tmp(outvec.length()); - - /* Note that since ‘beg’ came from begin(), it has empty signal and first - evaluation gets no signal */ - for (_Tpit run = beg; run != end; ++run) - { - func.eval(run.point(), run.signal(), tmp); - tmpall.add(run.weight(), tmp); - } - - { - std::unique_lock<std::mutex> lk{mut}; - outvec.add(1.0, tmpall); - } - } -}; - -/* This is the class which implements the integration. The class is templated - by the iterator type. We declare a method begin() returning an iterator to - the beginnning of the ‘ti’-th portion out of total ‘tn’ portions for a given - level. - - In addition, we define a method which saves all the points to a given file. - Only for debugging purposes. */ - -template<typename _Tpit> -class QuadratureImpl : public Quadrature -{ - friend class IntegrationWorker<_Tpit>; -public: - QuadratureImpl(int d) : Quadrature(d) - { - } - - /* Just fill a thread group with workes and run it. */ - void - integrate(VectorFunctionSet &fs, int level, Vector &out) const override - { - // TODO: out.length()==func.outdim() - // TODO: dim == func.indim() - out.zeros(); - sthread::detach_thread_group gr; - for (int ti = 0; ti < fs.getNum(); ti++) - gr.insert(std::make_unique<IntegrationWorker<_Tpit>>(*this, fs.getFunc(ti), - level, ti, fs.getNum(), out)); - gr.run(); - } - void - integrate(const VectorFunction &func, - int level, int tn, Vector &out) const override - { - VectorFunctionSet fs(func, tn); - integrate(fs, level, out); - } - - /* Just for debugging. */ - void - savePoints(const std::string &fname, int level) const - { - std::ofstream fd{fname, std::ios::out | std::ios::trunc}; - if (fd.fail()) - { - // TODO: raise - std::cerr << "Cannot open file " << fname << " for writing." << std::endl; - exit(EXIT_FAILURE); - } - _Tpit beg = begin(0, 1, level); - _Tpit end = begin(1, 1, level); - fd << std::setprecision(12); - for (_Tpit run = beg; run != end; ++run) - { - fd << std::setw(16) << run.weight(); - for (int i = 0; i < dimen(); i++) - fd << '\t' << std::setw(16) << run.point()[i]; - fd << std::endl; - } - fd.close(); - } - - _Tpit - start(int level) const - { - return begin(0, 1, level); - } - _Tpit - end(int level) const - { - return begin(1, 1, level); - } -protected: - virtual _Tpit begin(int ti, int tn, int level) const = 0; -}; - -/* This is only an interface to a precalculated data in file - precalc_quadrature.hh which is basically C coded static data. It implements - OneDQuadrature. The data file is supposed to define the following data: - number of levels, array of number of points at each level, an array of - weights and array of points. The both latter array store data level by - level. An offset for a specific level is stored in ‘offsets’ integer - sequence. - - The implementing subclasses just fill the necessary data from the file, the - rest is calculated here. */ - -class OneDPrecalcQuadrature : public OneDQuadrature -{ - int num_levels; - const int *num_points; - const double *weights; - const double *points; - IntSequence offsets; -public: - OneDPrecalcQuadrature(int nlevels, const int *npoints, - const double *wts, const double *pts) - : num_levels(nlevels), num_points(npoints), - weights(wts), points(pts), offsets(num_levels) - { - calcOffsets(); - } - ~OneDPrecalcQuadrature() override = default; - int - numLevels() const override - { - return num_levels; - } - int - numPoints(int level) const override - { - return num_points[level-1]; - } - double - point(int level, int i) const override - { - return points[offsets[level-1]+i]; - } - double - weight(int level, int i) const override - { - return weights[offsets[level-1]+i]; - } -protected: - void calcOffsets(); -}; - -/* Just precalculated Gauss-Hermite quadrature. This quadrature integrates - exactly integrals - - +∞ - ∫ xᵏe^{−x²}dx - −∞ - - for level k. - - Note that if pluging this one-dimensional quadrature to product or Smolyak - rule in order to integrate a function f through normally distributed inputs, - one has to wrap f to GaussConverterFunction and apply the product or Smolyak - rule to the new function. - - Check precalc_quadrature.hh for available levels. */ - -class GaussHermite : public OneDPrecalcQuadrature -{ -public: - GaussHermite(); -}; - -/* Just precalculated Gauss-Legendre quadrature. This quadrature integrates - exactly integrals - - ₁ - ∫ xᵏdx - ⁰ - - for level k. - - Check precalc_quadrature.hh for available levels. */ - -class GaussLegendre : public OneDPrecalcQuadrature -{ -public: - GaussLegendre(); -}; - -#endif diff --git a/dynare++/integ/cc/quasi_mcarlo.cc b/dynare++/integ/cc/quasi_mcarlo.cc deleted file mode 100644 index 4cdde2ce904486420b5c52c65e10b98b216eb299..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/quasi_mcarlo.cc +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "quasi_mcarlo.hh" - -#include <cmath> -#include <iostream> -#include <iomanip> -#include <array> - -/* Here in the constructor, we have to calculate a maximum length of ‘coeff’ - array for a given ‘base’ and given maximum ‘maxn’. After allocation, we - calculate the coefficients. */ - -RadicalInverse::RadicalInverse(int n, int b, int mxn) - : num(n), base(b), maxn(mxn), - coeff(static_cast<int>(floor(log(static_cast<double>(maxn))/log(static_cast<double>(b)))+2), 0) -{ - int nr = num; - j = -1; - do - { - j++; - coeff[j] = nr % base; - nr = nr / base; - } - while (nr > 0); -} - -/* This evaluates the radical inverse. If there was no permutation, we have to - calculate: - - c₀ c₁ cⱼ - ── + ── + … + ──── - b b² bʲ⁺¹ - - which is evaluated as: - - ⎛ ⎛⎛cⱼ 1 cⱼ₋₁⎞ 1 cⱼ₋₂⎞ ⎞ 1 c₀ - ⎢…⎢⎢──·─ + ────⎥·─ + ────⎥…⎥·─ + ── - ⎝ ⎝⎝ b b b ⎠ b b ⎠ ⎠ b b - - - Now with permutation π, we have: - - ⎛ ⎛⎛π(cⱼ) 1 π(cⱼ₋₁)⎞ 1 π(cⱼ₋₂)⎞ ⎞ 1 π(c₀) - ⎢…⎢⎢─────·─ + ───────⎥·─ + ───────⎥…⎥·─ + ───── - ⎝ ⎝⎝ b b b ⎠ b b ⎠ ⎠ b b -*/ - -double -RadicalInverse::eval(const PermutationScheme &p) const -{ - double res = 0; - for (int i = j; i >= 0; i--) - { - int cper = p.permute(i, base, coeff[i]); - res = (cper + res)/base; - } - return res; -} - -/* We just add 1 to the lowest coefficient and check for overflow with respect - to the base. */ -void -RadicalInverse::increase() -{ - // TODO: raise if num+1 > maxn - num++; - int i = 0; - coeff[i]++; - while (coeff[i] == base) - { - coeff[i] = 0; - coeff[++i]++; - } - if (i > j) - j = i; -} - -/* Debug print. */ -void -RadicalInverse::print() const -{ - std::cout << "n=" << num << " b=" << base << " c="; - coeff.print(); -} - -/* Here we have the first 170 primes. This means that we are not able to - integrate dimensions greater than 170. */ - -std::array<int, 170> HaltonSequence::primes = - { - 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, - 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, - 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, - 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, - 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, - 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, - 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, - 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, - 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, - 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, - 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, - 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, - 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, - 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, - 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, - 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, - 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013 - }; - -/* This takes first ‘dim’ primes and constructs ‘dim’ radical inverses and - calls eval(). */ - -HaltonSequence::HaltonSequence(int n, int mxn, int dim, const PermutationScheme &p) - : num(n), maxn(mxn), per(p), pt(dim) -{ - // TODO: raise if dim > num_primes - // TODO: raise if n > mxn - for (int i = 0; i < dim; i++) - ri.emplace_back(num, primes[i], maxn); - eval(); -} - -/* This calls RadicalInverse::increase() for all radical inverses and calls - eval(). */ - -void -HaltonSequence::increase() -{ - for (auto &i : ri) - i.increase(); - num++; - if (num <= maxn) - eval(); -} - -/* This sets point ‘pt’ to radical inverse evaluations in each dimension. */ -void -HaltonSequence::eval() -{ - for (unsigned int i = 0; i < ri.size(); i++) - pt[i] = ri[i].eval(per); -} - -/* Debug print. */ -void -HaltonSequence::print() const -{ - auto ff = std::cout.flags(); - for (const auto &i : ri) - i.print(); - std::cout << "point=[ " - << std::fixed << std::setprecision(6); - for (unsigned int i = 0; i < ri.size(); i++) - std::cout << std::setw(7) << pt[i] << ' '; - std::cout << ']' << std::endl; - std::cout.flags(ff); -} - -qmcpit::qmcpit(const QMCSpecification &s, int n) - : spec(s), halton{n, s.level(), s.dimen(), s.getPerScheme()}, - sig{s.dimen()} -{ -} - -bool -qmcpit::operator==(const qmcpit &qpit) const -{ - return &spec == &qpit.spec && halton.getNum() == qpit.halton.getNum(); -} - -qmcpit & -qmcpit::operator++() -{ - halton.increase(); - return *this; -} - -double -qmcpit::weight() const -{ - return 1.0/spec.level(); -} - -int -WarnockPerScheme::permute(int i, int base, int c) const -{ - return (c+i) % base; -} - -int -ReversePerScheme::permute(int i, int base, int c) const -{ - return (base-c) % base; -} diff --git a/dynare++/integ/cc/quasi_mcarlo.hh b/dynare++/integ/cc/quasi_mcarlo.hh deleted file mode 100644 index 7a50e8ffed3651ec27e28096000214cbff083e27..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/quasi_mcarlo.hh +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -// Quasi Monte Carlo quadrature. - -/* This defines quasi Monte Carlo quadratures for cube and for a function - multiplied by normal density. The quadrature for a cube is named - QMCarloCubeQuadrature and integrates: - - ∫ f(x)dx - [0,1]ⁿ - - The quadrature for a function of normally distributed parameters is named - QMCarloNormalQuadrature and integrates: - - 1 - ──────── ∫ f(x)e^{−½xᵀx}dx - √{(2π)ⁿ} [−∞,+∞]ⁿ - - For a cube we define qmcpit as iterator of QMCarloCubeQuadrature, and for - the normal density multiplied function we define qmcnpit as iterator of - QMCarloNormalQuadrature. - - The quasi Monte Carlo method generates low discrepancy points with equal - weights. The one dimensional low discrepancy sequences are generated by - RadicalInverse class, the sequences are combined for higher dimensions by - HaltonSequence class. The Halton sequence can use a permutation scheme; - PermutattionScheme is an abstract class for all permutaton schemes. We have - three implementations: WarnockPerScheme, ReversePerScheme, and - IdentityPerScheme. */ - -#ifndef QUASI_MCARLO_H -#define QUASI_MCARLO_H - -#include "int_sequence.hh" -#include "quadrature.hh" - -#include "Vector.hh" - -#include <vector> - -/* This abstract class declares permute() method which permutes coefficient ‘c’ - having index of ‘i’ fro the base ‘base’ and returns the permuted coefficient - which must be in 0,…,base−1. */ - -class PermutationScheme -{ -public: - PermutationScheme() = default; - virtual ~PermutationScheme() = default; - virtual int permute(int i, int base, int c) const = 0; -}; - -/* This class represents an integer number ‘num’ as c₀+c₁b+c₂b²+…+cⱼbʲ, where b - is ‘base’ and c₀,…,cⱼ is stored in ‘coeff’. The size of IntSequence coeff - does not grow with growing ‘num’, but is fixed from the very beginning and - is set according to supplied maximum ‘maxn’. - - The basic method is eval() which evaluates the RadicalInverse with a given - permutation scheme and returns the point, and increase() which increases - ‘num’ and recalculates the coefficients. */ - -class RadicalInverse -{ - int num; - int base; - int maxn; - int j; - IntSequence coeff; -public: - RadicalInverse(int n, int b, int mxn); - RadicalInverse(const RadicalInverse &ri) = default; - RadicalInverse &operator=(const RadicalInverse &radi) = default; - double eval(const PermutationScheme &p) const; - void increase(); - void print() const; -}; - -/* This is a vector of RadicalInverses, each RadicalInverse has a different - prime as its base. The static members ‘primes’ and ‘num_primes’ define a - precalculated array of primes. The increase() method of the class increases - indices in all RadicalInverse’s and sets point ‘pt’ to contain the points in - each dimension. */ - -class HaltonSequence -{ -private: - static std::array<int, 170> primes; -protected: - int num; - int maxn; - std::vector<RadicalInverse> ri; - const PermutationScheme &per; - Vector pt; -public: - HaltonSequence(int n, int mxn, int dim, const PermutationScheme &p); - HaltonSequence(const HaltonSequence &hs) = default; - HaltonSequence &operator=(const HaltonSequence &hs) = delete; - void increase(); - const Vector & - point() const - { - return pt; - } - int - getNum() const - { - return num; - } - void print() const; -protected: - void eval(); -}; - -/* This is a specification of quasi Monte Carlo quadrature. It consists of - dimension ‘dim’, number of points (or level) ‘lev’, and the permutation - scheme. This class is common to all quasi Monte Carlo classes. */ - -class QMCSpecification -{ -protected: - int dim; - int lev; - const PermutationScheme &per_scheme; -public: - QMCSpecification(int d, int l, const PermutationScheme &p) - : dim(d), lev(l), per_scheme(p) - { - } - virtual ~QMCSpecification() = default; - int - dimen() const - { - return dim; - } - int - level() const - { - return lev; - } - const PermutationScheme & - getPerScheme() const - { - return per_scheme; - } -}; - -/* This is an iterator for quasi Monte Carlo over a cube QMCarloCubeQuadrature. - The iterator maintains HaltonSequence of the same dimension as given by the - specification. An iterator can be constructed from a given number ‘n’, or by - a copy constructor. */ - -class qmcpit -{ -protected: - const QMCSpecification &spec; - HaltonSequence halton; - ParameterSignal sig; -public: - qmcpit(const QMCSpecification &s, int n); - qmcpit(const qmcpit &qpit) = default; - virtual ~qmcpit() = default; - bool operator==(const qmcpit &qpit) const; - bool - operator!=(const qmcpit &qpit) const - { - return !operator==(qpit); - } - qmcpit &operator=(const qmcpit &qpit) = delete; - qmcpit &operator++(); - const ParameterSignal & - signal() const - { - return sig; - } - const Vector & - point() const - { - return halton.point(); - } - double weight() const; - void - print() const - { - halton.print(); - } -}; - -/* This is an easy declaration of quasi Monte Carlo quadrature for a cube. - Everything important has been done in its iterator qmcpit, so we only - inherit from general Quadrature and reimplement begin() and numEvals(). */ - -class QMCarloCubeQuadrature : public QuadratureImpl<qmcpit>, public QMCSpecification -{ -public: - QMCarloCubeQuadrature(int d, int l, const PermutationScheme &p) - : QuadratureImpl<qmcpit>(d), QMCSpecification(d, l, p) - { - } - ~QMCarloCubeQuadrature() override = default; - int - numEvals(int l) const override - { - return l; - } -protected: - qmcpit - begin(int ti, int tn, int lev) const override - { - return qmcpit(*this, ti*level()/tn + 1); - } -}; - -/* Declares Warnock permutation scheme. */ -class WarnockPerScheme : public PermutationScheme -{ -public: - int permute(int i, int base, int c) const override; -}; - -/* Declares reverse permutation scheme. */ -class ReversePerScheme : public PermutationScheme -{ -public: - int permute(int i, int base, int c) const override; -}; - -/* Declares no permutation (identity) scheme. */ -class IdentityPerScheme : public PermutationScheme -{ -public: - int - permute(int i, int base, int c) const override - { - return c; - } -}; - -#endif diff --git a/dynare++/integ/cc/smolyak.cc b/dynare++/integ/cc/smolyak.cc deleted file mode 100644 index df123785cddcdc35388afc7123f18ccbde3da45f..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/smolyak.cc +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "smolyak.hh" -#include "symmetry.hh" - -#include <iostream> -#include <iomanip> - -/* This constructs a beginning of ‘isum’ summand in ‘smolq’. We must be careful - here, since ‘isum’ can be past-the-end, so no reference to vectors in - ‘smolq’ by ‘isum’ must be done in this case. */ - -smolpit::smolpit(const SmolyakQuadrature &q, unsigned int isum) - : smolq(q), isummand(isum), - jseq(q.dimen(), 0), - sig{q.dimen()}, - p{q.dimen()} -{ - if (isummand < q.numSummands()) - setPointAndWeight(); -} - -bool -smolpit::operator==(const smolpit &spit) const -{ - return &smolq == &spit.smolq && isummand == spit.isummand && jseq == spit.jseq; -} - -/* We first try to increase index within the current summand. If we are at - maximum, we go to a subsequent summand. Note that in this case all indices - in ‘jseq’ will be zero, so no change is needed. */ - -smolpit & -smolpit::operator++() -{ - const IntSequence &levpts = smolq.levpoints[isummand]; - int i = smolq.dimen()-1; - jseq[i]++; - while (i >= 0 && jseq[i] == levpts[i]) - { - jseq[i] = 0; - i--; - if (i >= 0) - jseq[i]++; - } - sig.signalAfter(std::max(i, 0)); - - if (i < 0) - isummand++; - - if (isummand < smolq.numSummands()) - setPointAndWeight(); - - return *this; -} - -/* Here we set the point coordinates according to ‘jseq’ and - ‘isummand’. Also the weight is set here. */ - -void -smolpit::setPointAndWeight() -{ - // todo: raise if isummand ≥ smolq.numSummands() - int l = smolq.level; - int d = smolq.dimen(); - int sumk = (smolq.levels[isummand]).sum(); - int m1exp = l + d - sumk - 1; - w = (2*(m1exp/2) == m1exp) ? 1.0 : -1.0; - w *= PascalTriangle::noverk(d-1, sumk-l); - for (int i = 0; i < d; i++) - { - int ki = (smolq.levels[isummand])[i]; - p[i] = (smolq.uquad).point(ki, jseq[i]); - w *= (smolq.uquad).weight(ki, jseq[i]); - } -} - -/* Debug print. */ -void -smolpit::print() const -{ - auto ff = std::cout.flags(); - std::cout << "isum=" << std::left << std::setw(3) << isummand << std::right << ": ["; - for (int i = 0; i < smolq.dimen(); i++) - std::cout << std::setw(2) << (smolq.levels[isummand])[i] << ' '; - std::cout << "] j=["; - for (int i = 0; i < smolq.dimen(); i++) - std::cout << std::setw(2) << jseq[i] << ' '; - std::cout << std::showpos << std::fixed << std::setprecision(3) - << "] " << std::setw(4) << w << "*("; - for (int i = 0; i < smolq.dimen()-1; i++) - std::cout << std::setw(4) << p[i] << ' '; - std::cout << std::setw(4) << p[smolq.dimen()-1] << ')' << std::endl; - std::cout.flags(ff); -} - -/* Here is the constructor of SmolyakQuadrature. We have to setup ‘levels’, - ‘levpoints’ and ‘cumevals’. We have to go through all d-dimensional - sequences k, such that l≤|k|≤l+d−1 and all kᵢ are positive integers. This is - equivalent to going through all k such that l−d≤|k|≤l−1 and all kᵢ are - non-negative integers. This is equivalent to going through d+1 dimensional - sequences (k,x) such that |(k,x)|=l−1 and x=0,…,d−1. The resulting sequence - of positive integers is obtained by adding 1 to all kᵢ. */ - -SmolyakQuadrature::SmolyakQuadrature(int d, int l, const OneDQuadrature &uq) - : QuadratureImpl<smolpit>(d), level(l), uquad(uq) -{ - // TODO: check l>1, l≥d - // TODO: check l≥uquad.miLevel(), l≤uquad.maxLevel() - int cum = 0; - for (const auto &si : SymmetrySet(l-1, d+1)) - { - if (si[d] <= d-1) - { - IntSequence lev(si, 0, d); - lev.add(1); - levels.push_back(lev); - IntSequence levpts(d); - for (int i = 0; i < d; i++) - levpts[i] = uquad.numPoints(lev[i]); - levpoints.push_back(levpts); - cum += levpts.mult(); - cumevals.push_back(cum); - } - } -} - -/* Here we return a number of evalutions of the quadrature for the given level. - If the given level is the current one, we simply return the maximum - cumulative number of evaluations. Otherwise we call costly - calcNumEvaluations() method. */ - -int -SmolyakQuadrature::numEvals(int l) const -{ - if (l != level) - return calcNumEvaluations(l); - else - return cumevals[numSummands()-1]; -} - -/* This divides all the evaluations to ‘tn’ approximately equal groups, and - returns the beginning of the specified group ‘ti’. The granularity of - divisions are summands as listed by ‘levels’. */ - -smolpit -SmolyakQuadrature::begin(int ti, int tn, int l) const -{ - // TODO: raise is level≠l - if (ti == tn) - return smolpit(*this, numSummands()); - - int totevals = cumevals[numSummands()-1]; - int evals = (totevals*ti)/tn; - unsigned int isum = 0; - while (isum+1 < numSummands() && cumevals[isum+1] < evals) - isum++; - return smolpit(*this, isum); -} - -/* This is the same in a structure as SmolyakQuadrature constructor. We have to - go through all summands and calculate a number of evaluations in each - summand. */ - -int -SmolyakQuadrature::calcNumEvaluations(int lev) const -{ - int cum = 0; - for (const auto &si : SymmetrySet(lev-1, dim+1)) - { - if (si[dim] <= dim-1) - { - IntSequence lev(si, 0, dim); - lev.add(1); - IntSequence levpts(dim); - for (int i = 0; i < dim; i++) - levpts[i] = uquad.numPoints(lev[i]); - cum += levpts.mult(); - } - } - return cum; -} - -/* This returns a maximum level such that the number of evaluations is less - than the given number. */ - -void -SmolyakQuadrature::designLevelForEvals(int max_evals, int &lev, int &evals) const -{ - int last_evals; - evals = 1; - lev = 1; - do - { - lev++; - last_evals = evals; - evals = calcNumEvaluations(lev); - } - while (lev < uquad.numLevels() && evals <= max_evals); - lev--; - evals = last_evals; -} diff --git a/dynare++/integ/cc/smolyak.hh b/dynare++/integ/cc/smolyak.hh deleted file mode 100644 index 5614335935e9e49f983465a5f807a77fe081fa2a..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/smolyak.hh +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -// Smolyak quadrature. - -/* This file defines Smolyak (sparse grid) multidimensional quadrature for - non-nested underlying one dimensional quadrature. Let Q¹ₗ denote the one - dimensional quadrature of l level. Let nₗ denote a number of points in the l - level. Than the Smolyak quadrature can be defined as - - ⎛ d−1 ⎞ - Qᵈf = ∑ (−1)^{l+d−|k|−1} ⎢ ⎥ (Q¹_k₁⊗…⊗Q¹_{k_d})f - l≤|k|≤l+d−1 ⎝|k|−l⎠ - - where d is the dimension, k is d-dimensional sequence of integers, and |k| - denotes the sum of the sequence. - - Here we define smolpit as Smolyak iterator and SmolyakQuadrature. */ - -#ifndef SMOLYAK_H -#define SMOLYAK_H - -#include "int_sequence.hh" -#include "tl_static.hh" -#include "vector_function.hh" -#include "quadrature.hh" -#include "pascal_triangle.hh" - -/* Here we define the Smolyak point iterator. The Smolyak formula can be broken - to a sum of product quadratures with various combinations of levels. The - iterator follows this pattern. It maintains an index to a summand and then a - point coordinates within the summand (product quadrature). The array of - summands to which the ‘isummand’ points is maintained by the - SmolyakQuadrature class to which the object knows the pointer ‘smolq’. - - We provide a constructor which points to the beginning of the given summand. - This constructor is used in SmolyakQuadrature::begin() method which - approximately divideds all the iterators to subsets of equal size. */ - -class SmolyakQuadrature; - -class smolpit -{ -protected: - const SmolyakQuadrature &smolq; - unsigned int isummand{0}; - IntSequence jseq; - ParameterSignal sig; - Vector p; - double w; -public: - smolpit(const SmolyakQuadrature &q, unsigned int isum); - smolpit(const smolpit &spit) = default; - ~smolpit() = default; - bool operator==(const smolpit &spit) const; - bool - operator!=(const smolpit &spit) const - { - return !operator==(spit); - } - smolpit &operator=(const smolpit &spit) = delete; - smolpit &operator++(); - const ParameterSignal & - signal() const - { - return sig; - } - const Vector & - point() const - { - return p; - } - double - weight() const - { - return w; - } - void print() const; -protected: - void setPointAndWeight(); -}; - -/* Here we define the class SmolyakQuadrature. It maintains an array of - summands of the Smolyak quadrature formula: - - ⎛ d−1 ⎞ - ∑ (−1)^{l+d−|k|−1} ⎢ ⎥ (Q¹_k₁⊗…⊗Q¹_{k_d})f - l≤|k|≤l+d−1 ⎝|k|−l⎠ - - Each summand is fully specified by sequence k. The summands are here - represented (besides k) also by sequence of number of points in each level - selected by k, and also by a cummulative number of evaluations. The latter - two are added only for conveniency. - - The summands in the code are given by ‘levels’, which is a vector of - k sequences, further by ‘levpoints’ which is a vector of sequences - of nuber of points in each level, and by ‘cumevals’ which is the - cumulative number of points, this is: - - d - ∑ ∏ n_kᵢ - ᵏ ⁱ⁼¹ - - where the sum is done through all k before the current. - - The ‘levels’ and ‘levpoints’ vectors are used by smolpit. */ - -class SmolyakQuadrature : public QuadratureImpl<smolpit> -{ - friend class smolpit; - int level; - const OneDQuadrature &uquad; - std::vector<IntSequence> levels; - std::vector<IntSequence> levpoints; - std::vector<int> cumevals; -public: - SmolyakQuadrature(int d, int l, const OneDQuadrature &uq); - ~SmolyakQuadrature() override = default; - int numEvals(int level) const override; - void designLevelForEvals(int max_eval, int &lev, int &evals) const; -protected: - smolpit begin(int ti, int tn, int level) const override; - unsigned int - numSummands() const - { - return levels.size(); - } -private: - int calcNumEvaluations(int level) const; -}; - -#endif diff --git a/dynare++/integ/cc/vector_function.cc b/dynare++/integ/cc/vector_function.cc deleted file mode 100644 index b639a6a42469b834f0daf06bd1dca78d2df83c39..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/vector_function.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "vector_function.hh" - -#include <dynlapack.h> - -#include <cmath> -#include <algorithm> - -/* Just an easy constructor of sequence of booleans defaulting to change - everywhere. */ - -ParameterSignal::ParameterSignal(int n) - : data(n, true) -{ -} - -/* This sets ‘false’ (no change) before a given parameter, and ‘true’ (change) - after the given parameter (including). */ - -void -ParameterSignal::signalAfter(int l) -{ - for (size_t i = 0; i < std::min(static_cast<size_t>(l), data.size()); i++) - data[i] = false; - for (size_t i = l; i < data.size(); i++) - data[i] = true; -} - -/* This constructs a function set hardcopying also the first. */ -VectorFunctionSet::VectorFunctionSet(const VectorFunction &f, int n) - : funcs(n) -{ - for (int i = 0; i < n; i++) - { - func_copies.push_back(f.clone()); - funcs[i] = func_copies.back().get(); - } -} - -/* This constructs a function set with shallow copy in the first and hard - copies in others. */ -VectorFunctionSet::VectorFunctionSet(VectorFunction &f, int n) - : funcs(n) -{ - if (n > 0) - funcs[0] = &f; - for (int i = 1; i < n; i++) - { - func_copies.push_back(f.clone()); - funcs[i] = func_copies.back().get(); - } -} - -/* Here we construct the object from the given function f and given - variance-covariance matrix Σ=vcov. The matrix A is calculated as lower - triangular and yields Σ=AAᵀ. */ - -GaussConverterFunction::GaussConverterFunction(VectorFunction &f, const GeneralMatrix &vcov) - : VectorFunction(f), func(&f), A(vcov.nrows(), vcov.nrows()), - multiplier(calcMultiplier()) -{ - // TODO: raise if A.nrows() ≠ indim() - calcCholeskyFactor(vcov); -} - -GaussConverterFunction::GaussConverterFunction(std::unique_ptr<VectorFunction> f, const GeneralMatrix &vcov) - : VectorFunction(*f), func_storage{move(f)}, func{func_storage.get()}, A(vcov.nrows(), vcov.nrows()), - multiplier(calcMultiplier()) -{ - // TODO: raise if A.nrows() ≠ indim() - calcCholeskyFactor(vcov); -} - -GaussConverterFunction::GaussConverterFunction(const GaussConverterFunction &f) - : VectorFunction(f), func_storage{f.func->clone()}, func{func_storage.get()}, A(f.A), - multiplier(f.multiplier) -{ -} - -/* Here we evaluate the function - - g(y) = 1/√(πⁿ) f(√2·Ay). - - Since the matrix A is lower triangular, the change signal for the function f - will look like (0,…,0,1,…,1) where the first 1 is in the same position as - the first change in the given signal ‘sig’ of the input y=point. */ - -void -GaussConverterFunction::eval(const Vector &point, const ParameterSignal &sig, Vector &out) -{ - ParameterSignal s(sig); - int i = 0; - while (i < indim() && !sig[i]) - i++; - s.signalAfter(i); - - Vector x(indim()); - x.zeros(); - A.multaVec(x, point); - x.mult(sqrt(2.0)); - - func->eval(x, s, out); - - out.mult(multiplier); -} - -/* This returns 1/√(πⁿ). */ - -double -GaussConverterFunction::calcMultiplier() const -{ - return sqrt(pow(M_PI, -1*indim())); -} - -void -GaussConverterFunction::calcCholeskyFactor(const GeneralMatrix &vcov) -{ - A = vcov; - - lapack_int rows = A.nrows(), lda = A.getLD(); - for (int i = 0; i < rows; i++) - for (int j = i+1; j < rows; j++) - A.get(i, j) = 0.0; - - lapack_int info; - dpotrf("L", &rows, A.base(), &lda, &info); - // TODO: raise if info≠1 -} diff --git a/dynare++/integ/cc/vector_function.hh b/dynare++/integ/cc/vector_function.hh deleted file mode 100644 index 8beee94dca85edd56b014b269d95865701f029a4..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/vector_function.hh +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -// Vector function. - -/* This file defines interface for functions taking a vector as an input and - returning a vector (with a different size) as an output. We are also - introducing a parameter signalling; it is a boolean vector which tracks - parameters which were changed from the previous call. The VectorFunction - implementation can exploit this information and evaluate the function more - efficiently. The information can be completely ignored. - - From the signalling reason, and from other reasons, the function evaluation - is not const. */ - -#ifndef VECTOR_FUNCTION_H -#define VECTOR_FUNCTION_H - -#include "Vector.hh" -#include "GeneralMatrix.hh" - -#include <vector> -#include <memory> - -/* This is a simple class representing a vector of booleans. The items night be - retrieved or changed, or can be set ‘true’ after some point. This is useful - when we multiply the vector with lower triangular matrix. - - ‘true’ means that a parameter was changed. */ - -class ParameterSignal -{ -protected: - std::vector<bool> data; -public: - ParameterSignal(int n); - ParameterSignal(const ParameterSignal &sig) = default; - ~ParameterSignal() = default; - void signalAfter(int l); - bool - operator[](int i) const - { - return data[i]; - } - std::vector<bool>::reference - operator[](int i) - { - return data[i]; - } -}; - -/* This is the abstract class for vector function. At this level of abstraction - we only need to know size of input vector and a size of output vector. - - The important thing here is a clone method, we will need to make hard copies - of vector functions since the evaluations are not const. The hardcopies - apply for parallelization. */ - -class VectorFunction -{ -protected: - int in_dim; - int out_dim; -public: - VectorFunction(int idim, int odim) - : in_dim(idim), out_dim(odim) - { - } - VectorFunction(const VectorFunction &func) = default; - virtual ~VectorFunction() = default; - virtual std::unique_ptr<VectorFunction> clone() const = 0; - virtual void eval(const Vector &point, const ParameterSignal &sig, Vector &out) = 0; - int - indim() const - { - return in_dim; - } - int - outdim() const - { - return out_dim; - } -}; - -/* This makes ‘n’ copies of VectorFunction. The first constructor make exactly - ‘n’ new copies, the second constructor copies only the pointer to the first - and others are hard (real) copies. - - The class is useful for making a given number of copies at once, and this - set can be reused many times if we need mupliple copis of the function (for - example for paralelizing the code). */ - -class VectorFunctionSet -{ -private: - // Stores the hard copies made by the class - std::vector<std::unique_ptr<VectorFunction>> func_copies; -protected: - std::vector<VectorFunction *> funcs; -public: - VectorFunctionSet(const VectorFunction &f, int n); - VectorFunctionSet(VectorFunction &f, int n); - ~VectorFunctionSet() = default; - VectorFunction & - getFunc(int i) - { - return *(funcs[i]); - } - int - getNum() const - { - return funcs.size(); - } -}; - -/* This class wraps another VectorFunction to allow integration of a function - through normally distributed inputs. Namely, if one wants to integrate - - 1 - ─────────── ∫ f(x)e^{−½xᵀ|Σ|⁻¹x}dx - √{(2π)ⁿ|Σ|} - - then if we write Σ=AAᵀ and x=√2·Ay, we get integral - - 1 1 - ─────────── ∫ f(√2·Ay)e^{−½yᵀy} √(2ⁿ)|A|dy = ───── ∫ f(√2·Ay)e^{−½yᵀy}dy - √{(2π)ⁿ|Σ|} √(πⁿ) - - which means that a given function f we have to wrap to yield a function - - g(y) = 1/√(πⁿ) f(√2·Ay). - - This is exactly what this class is doing. This transformation is useful - since the Gauss-Hermite points and weights are defined for weighting - function e^{−y²}, so this transformation allows using Gauss-Hermite - quadratures seemlessly in a context of integration through normally - distributed inputs. - - The class maintains a pointer to the function f. When the object is - constructed by the first constructor, the f is assumed to be owned by the - caller. If the object of this class is copied, then f is copied and hence - stored in a std::unique_ptr. The second constructor takes a smart pointer to - the function and in that case the class takes ownership of f. */ - -class GaussConverterFunction : public VectorFunction -{ -private: - std::unique_ptr<VectorFunction> func_storage; -protected: - VectorFunction *func; - GeneralMatrix A; - double multiplier; -public: - GaussConverterFunction(VectorFunction &f, const GeneralMatrix &vcov); - GaussConverterFunction(std::unique_ptr<VectorFunction> f, const GeneralMatrix &vcov); - GaussConverterFunction(const GaussConverterFunction &f); - ~GaussConverterFunction() override = default; - std::unique_ptr<VectorFunction> - clone() const override - { - return std::make_unique<GaussConverterFunction>(*this); - } - void eval(const Vector &point, const ParameterSignal &sig, Vector &out) override; -private: - double calcMultiplier() const; - void calcCholeskyFactor(const GeneralMatrix &vcov); -}; - -#endif diff --git a/dynare++/integ/src/Makefile.am b/dynare++/integ/src/Makefile.am deleted file mode 100644 index 6eec5e1b4c7757c13550129215a76b31e5be735f..0000000000000000000000000000000000000000 --- a/dynare++/integ/src/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -noinst_PROGRAMS = quadrature-points - -quadrature_points_SOURCES = quadrature-points.cc -quadrature_points_CPPFLAGS = -I../.. -I../../sylv/cc -I../../integ/cc -I../../tl/cc -I../../utils/cc -quadrature_points_LDADD = ../cc/libinteg.a ../../tl/cc/libtl.a ../../parser/cc/libparser.a ../../sylv/cc/libsylv.a ../../utils/cc/libutils.a $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) diff --git a/dynare++/integ/src/quadrature-points.cc b/dynare++/integ/src/quadrature-points.cc deleted file mode 100644 index b4ed5206b578f9f40e4ffa2adc38b3b851461c8b..0000000000000000000000000000000000000000 --- a/dynare++/integ/src/quadrature-points.cc +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright © 2008-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "parser/cc/matrix_parser.hh" -#include "utils/cc/exception.hh" -#include "sylv/cc/GeneralMatrix.hh" -#include "sylv/cc/Vector.hh" -#include "sylv/cc/SymSchurDecomp.hh" -#include "sylv/cc/SylvException.hh" -#include "integ/cc/quadrature.hh" -#include "integ/cc/smolyak.hh" -#include "integ/cc/product.hh" - -#include <getopt.h> - -#include <cmath> -#include <cstdlib> -#include <iostream> -#include <fstream> -#include <sstream> -#include <memory> -#include <string> - -struct QuadParams -{ - std::string outname; - std::string vcovname; - int max_level{3}; - double discard_weight{0.0}; - QuadParams(int argc, char **argv); - void check_consistency() const; -private: - enum class opt { max_level, discard_weight, vcov }; -}; - -QuadParams::QuadParams(int argc, char **argv) -{ - if (argc == 1) - { - // Print the help and exit - std::cerr << "Usage: " << argv[0] << " [--max-level INTEGER] [--discard-weight FLOAT] [--vcov FILENAME] OUTPUT_FILENAME" << std::endl; - std::exit(EXIT_FAILURE); - } - - outname = argv[argc-1]; - argc--; - - struct option const opts[] = { - {"max-level", required_argument, nullptr, static_cast<int>(opt::max_level)}, - {"discard-weight", required_argument, nullptr, static_cast<int>(opt::discard_weight)}, - {"vcov", required_argument, nullptr, static_cast<int>(opt::vcov)}, - {nullptr, 0, nullptr, 0} - }; - - int ret; - int index; - while (-1 != (ret = getopt_long(argc, argv, "", opts, &index))) - { - if (ret == '?') - { - std::cerr << "Unknown option, ignored\n"; - continue; - } - - switch (static_cast<opt>(ret)) - { - case opt::max_level: - try - { - max_level = std::stoi(optarg); - } - catch (const std::invalid_argument &e) - { - std::cerr << "Couldn't parse integer " << optarg << ", ignored" << std::endl; - } - break; - case opt::discard_weight: - try - { - discard_weight = std::stod(optarg); - } - catch (const std::invalid_argument &e) - { - std::cerr << "Couldn't parse float " << optarg << ", ignored" << std::endl; - } - break; - case opt::vcov: - vcovname = optarg; - break; - } - } - - check_consistency(); -} - -void -QuadParams::check_consistency() const -{ - if (outname.empty()) - { - std::cerr << "Error: output name not set" << std::endl; - std::exit(EXIT_FAILURE); - } - - if (vcovname.empty()) - { - std::cerr << "Error: vcov file name not set" << std::endl; - std::exit(EXIT_FAILURE); - } -} - -int -main(int argc, char **argv) -{ - QuadParams params(argc, argv); - - // Open output file for writing - std::ofstream fout{params.outname, std::ios::out | std::ios::trunc}; - if (fout.fail()) - { - std::cerr << "Could not open " << params.outname << " for writing" << std::endl; - std::exit(EXIT_FAILURE); - } - - try - { - std::ifstream f{params.vcovname}; - std::ostringstream buffer; - buffer << f.rdbuf(); - std::string contents{buffer.str()}; - - // Parse the vcov matrix - ogp::MatrixParser mp; - mp.parse(contents); - if (mp.nrows() != mp.ncols()) - throw ogu::Exception(__FILE__, __LINE__, - "VCOV matrix not square"); - // And put to the GeneralMatrix - GeneralMatrix vcov(mp.nrows(), mp.ncols()); - vcov.zeros(); - for (ogp::MPIterator it = mp.begin(); it != mp.end(); ++it) - vcov.get(it.row(), it.col()) = *it; - - // Calculate the factor A of vcov, so that A·Aᵀ=VCOV - GeneralMatrix A(vcov.nrows(), vcov.nrows()); - SymSchurDecomp ssd(vcov); - ssd.getFactor(A); - - // Construct Gauss-Hermite quadrature - GaussHermite ghq; - // Construct Smolyak quadrature - int level = params.max_level; - SmolyakQuadrature sq(vcov.nrows(), level, ghq); - - std::cout << "Dimension: " << vcov.nrows() << std::endl - << "Maximum level: " << level << std::endl - << "Total number of nodes: " << sq.numEvals(level) << std::endl; - - // Put the points to the vector - std::vector<std::unique_ptr<Vector>> points; - for (smolpit qit = sq.start(level); qit != sq.end(level); ++qit) - points.push_back(std::make_unique<Vector>(const_cast<const Vector &>(qit.point()))); - // Sort and uniq - std::sort(points.begin(), points.end(), [](auto &a, auto &b) { return a.get() < b.get(); }); - auto new_end = std::unique(points.begin(), points.end()); - points.erase(new_end, points.end()); - - std::cout << "Duplicit nodes removed: " << static_cast<unsigned long>(sq.numEvals(level)-points.size()) - << std::endl; - - // Calculate weights and mass - double mass = 0.0; - std::vector<double> weights; - for (auto &point : points) - { - weights.push_back(std::exp(-point->dot(*point))); - mass += weights.back(); - } - - // Calculate discarded mass - double discard_mass = 0.0; - for (double weight : weights) - if (weight/mass < params.discard_weight) - discard_mass += weight; - - std::cout << "Total mass discarded: " << std::fixed << discard_mass/mass << std::endl; - - // Dump the results - int npoints = 0; - double upscale_weight = 1/(mass-discard_mass); - Vector x(vcov.nrows()); - fout << std::setprecision(16); - for (int i = 0; i < static_cast<int>(weights.size()); i++) - if (weights[i]/mass >= params.discard_weight) - { - // Print the upscaled weight - fout << std::setw(20) << upscale_weight*weights[i]; - // Multiply point with the factor A and √2 - A.multVec(0.0, x, std::sqrt(2.), *(points[i])); - // Print the coordinates - for (int j = 0; j < x.length(); j++) - fout << ' ' << std::setw(20) << x[j]; - fout << std::endl; - npoints++; - } - - std::cout << "Final number of points: " << npoints << std::endl; - - fout.close(); - } - catch (const SylvException &e) - { - e.printMessage(); - return EXIT_FAILURE; - } - catch (const ogu::Exception &e) - { - e.print(); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/dynare++/integ/testing/Makefile.am b/dynare++/integ/testing/Makefile.am deleted file mode 100644 index 2b7dcf48b5fa99b465b0dec6e77ace491a2e1355..0000000000000000000000000000000000000000 --- a/dynare++/integ/testing/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -check_PROGRAMS = tests - -tests_SOURCES = tests.cc -tests_CPPFLAGS = -I../cc -I../../tl/cc -I../../sylv/cc -I../../utils/cc -I$(top_srcdir)/mex/sources -tests_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) -tests_LDADD = ../../sylv/cc/libsylv.a ../cc/libinteg.a ../../tl/cc/libtl.a ../../utils/cc/libutils.a $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) $(LIBADD_MATIO) - -check-local: - ./tests diff --git a/dynare++/integ/testing/tests.cc b/dynare++/integ/testing/tests.cc deleted file mode 100644 index a3f7788852e0c94606b1f3775409af272e6d33a5..0000000000000000000000000000000000000000 --- a/dynare++/integ/testing/tests.cc +++ /dev/null @@ -1,550 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "GeneralMatrix.hh" -#include <dynlapack.h> -#include "SylvException.hh" - -#include "rfs_tensor.hh" -#include "normal_moments.hh" - -#include "vector_function.hh" -#include "quadrature.hh" -#include "smolyak.hh" -#include "product.hh" -#include "quasi_mcarlo.hh" - -#include <iomanip> -#include <chrono> -#include <cmath> -#include <iostream> -#include <utility> -#include <array> -#include <memory> -#include <cstdlib> - -/* Evaluates unfolded (Dx)ᵏ power, where x is a vector, D is a Cholesky factor - (lower triangular) */ -class MomentFunction : public VectorFunction -{ - GeneralMatrix D; - int k; -public: - MomentFunction(const GeneralMatrix &inD, int kk) - : VectorFunction(inD.nrows(), UFSTensor::calcMaxOffset(inD.nrows(), kk)), - D(inD), k(kk) - { - } - MomentFunction(const MomentFunction &func) = default; - - std::unique_ptr<VectorFunction> - clone() const override - { - return std::make_unique<MomentFunction>(*this); - } - void eval(const Vector &point, const ParameterSignal &sig, Vector &out) override; -}; - -void -MomentFunction::eval(const Vector &point, const ParameterSignal &sig, Vector &out) -{ - if (point.length() != indim() || out.length() != outdim()) - { - std::cerr << "Wrong length of vectors in MomentFunction::eval" << std::endl; - std::exit(EXIT_FAILURE); - } - Vector y(point); - y.zeros(); - D.multaVec(y, point); - URSingleTensor ypow(y, k); - out.zeros(); - out.add(1.0, ypow.getData()); -} - -class TensorPower : public VectorFunction -{ - int k; -public: - TensorPower(int nvar, int kk) - : VectorFunction(nvar, UFSTensor::calcMaxOffset(nvar, kk)), k(kk) - { - } - TensorPower(const TensorPower &func) = default; - - std::unique_ptr<VectorFunction> - clone() const override - { - return std::make_unique<TensorPower>(*this); - } - void eval(const Vector &point, const ParameterSignal &sig, Vector &out) override; -}; - -void -TensorPower::eval(const Vector &point, const ParameterSignal &sig, Vector &out) -{ - if (point.length() != indim() || out.length() != outdim()) - { - std::cerr << "Wrong length of vectors in TensorPower::eval" << std::endl; - std::exit(EXIT_FAILURE); - } - URSingleTensor ypow(point, k); - out.zeros(); - out.add(1.0, ypow.getData()); -} - -/* Evaluates (1+1/d)ᵈ(x₁·…·x_d)^(1/d), its integral over [0,1]ᵈ - is 1.0, and its variation grows exponentially */ -class Function1 : public VectorFunction -{ - int dim; -public: - Function1(int d) - : VectorFunction(d, 1), dim(d) - { - } - Function1(const Function1 &f) - : VectorFunction(f.indim(), f.outdim()), dim(f.dim) - { - } - std::unique_ptr<VectorFunction> - clone() const override - { - return std::make_unique<Function1>(*this); - } - void eval(const Vector &point, const ParameterSignal &sig, Vector &out) override; -}; - -void -Function1::eval(const Vector &point, const ParameterSignal &sig, Vector &out) -{ - if (point.length() != dim || out.length() != 1) - { - std::cerr << "Wrong length of vectors in Function1::eval" << std::endl; - std::exit(EXIT_FAILURE); - } - double r = 1; - for (int i = 0; i < dim; i++) - r *= point[i]; - r = pow(r, 1.0/dim); - r *= pow(1.0 + 1.0/dim, static_cast<double>(dim)); - out[0] = r; -} - -// Evaluates Function1 but with transformation xᵢ=0.5(yᵢ+1) -// This makes the new function integrate over [−1,1]ᵈ to 1.0 -class Function1Trans : public Function1 -{ -public: - Function1Trans(int d) - : Function1(d) - { - } - Function1Trans(const Function1Trans &func) = default; - - std::unique_ptr<VectorFunction> - clone() const override - { - return std::make_unique<Function1Trans>(*this); - } - void eval(const Vector &point, const ParameterSignal &sig, Vector &out) override; -}; - -void -Function1Trans::eval(const Vector &point, const ParameterSignal &sig, Vector &out) -{ - Vector p(point.length()); - for (int i = 0; i < p.length(); i++) - p[i] = 0.5*(point[i]+1); - Function1::eval(p, sig, out); - out.mult(pow(0.5, indim())); -} - -/* WallTimer class. Constructor saves the wall time, destructor cancels the - current time from the saved, and prints the message with time information */ -class WallTimer -{ - std::string mes; - std::chrono::time_point<std::chrono::high_resolution_clock> start; - bool new_line; -public: - WallTimer(std::string m, bool nl = true) - : mes{m}, start{std::chrono::high_resolution_clock::now()}, new_line{nl} - { - } - ~WallTimer() - { - auto end = std::chrono::high_resolution_clock::now(); - std::chrono::duration<double> duration = end - start; - std::cout << mes << std::setw(8) << std::setprecision(4) << duration.count(); - if (new_line) - std::cout << std::endl; - } -}; - -/****************************************************/ -/* declaration of TestRunnable class */ -/****************************************************/ -class TestRunnable -{ -public: - const std::string name; - int dim; // dimension of the solved problem - int nvar; // number of variables of the solved problem - TestRunnable(std::string name_arg, int d, int nv) - : name{move(name_arg)}, dim(d), nvar(nv) - { - } - virtual ~TestRunnable() = default; - bool test() const; - virtual bool run() const = 0; -protected: - static bool smolyak_normal_moments(const GeneralMatrix &m, int imom, int level); - static bool product_normal_moments(const GeneralMatrix &m, int imom, int level); - static bool qmc_normal_moments(const GeneralMatrix &m, int imom, int level); - static bool smolyak_product_cube(const VectorFunction &func, const Vector &res, - double tol, int level); - static bool qmc_cube(const VectorFunction &func, double res, double tol, int level); -}; - -bool -TestRunnable::test() const -{ - std::cout << "Running test <" << name << ">" << std::endl; - bool passed; - { - WallTimer tim("Wall clock time ", false); - passed = run(); - } - if (passed) - { - std::cout << "............................ passed" << std::endl << std::endl; - return passed; - } - else - { - std::cout << "............................ FAILED" << std::endl << std::endl; - return passed; - } -} - -/****************************************************/ -/* definition of TestRunnable static methods */ -/****************************************************/ -bool -TestRunnable::smolyak_normal_moments(const GeneralMatrix &m, int imom, int level) -{ - // First make m·mᵀ and then Cholesky factor - GeneralMatrix msq(m * transpose(m)); - - // Make vector function - int dim = m.nrows(); - TensorPower tp(dim, imom); - GaussConverterFunction func(tp, msq); - - // Smolyak quadrature - Vector smol_out(UFSTensor::calcMaxOffset(dim, imom)); - { - WallTimer tim("\tSmolyak quadrature time: "); - GaussHermite gs; - SmolyakQuadrature quad(dim, level, gs); - quad.integrate(func, level, sthread::detach_thread_group::max_parallel_threads, smol_out); - std::cout << "\tNumber of Smolyak evaluations: " << quad.numEvals(level) << std::endl; - } - - // Check against theoretical moments - UNormalMoments moments(imom, msq); - smol_out.add(-1.0, moments.get(Symmetry{imom}).getData()); - std::cout << "\tError: " << std::setw(16) << std::setprecision(12) << smol_out.getMax() << std::endl; - return smol_out.getMax() < 1.e-7; -} - -bool -TestRunnable::product_normal_moments(const GeneralMatrix &m, int imom, int level) -{ - // First make m·mᵀ and then Cholesky factor - GeneralMatrix msq(m * transpose(m)); - - // Make vector function - int dim = m.nrows(); - TensorPower tp(dim, imom); - GaussConverterFunction func(tp, msq); - - // Product quadrature - Vector prod_out(UFSTensor::calcMaxOffset(dim, imom)); - { - WallTimer tim("\tProduct quadrature time: "); - GaussHermite gs; - ProductQuadrature quad(dim, gs); - quad.integrate(func, level, sthread::detach_thread_group::max_parallel_threads, prod_out); - std::cout << "\tNumber of product evaluations: " << quad.numEvals(level) << std::endl; - } - - // Check against theoretical moments - UNormalMoments moments(imom, msq); - prod_out.add(-1.0, moments.get(Symmetry{imom}).getData()); - std::cout << "\tError: " << std::setw(16) << std::setprecision(12) << prod_out.getMax() << std::endl; - return prod_out.getMax() < 1.e-7; -} - -bool -TestRunnable::smolyak_product_cube(const VectorFunction &func, const Vector &res, - double tol, int level) -{ - if (res.length() != func.outdim()) - { - std::cerr << "Incompatible dimensions of check value and function." << std::endl; - std::exit(EXIT_FAILURE); - } - - GaussLegendre glq; - Vector out(func.outdim()); - double smol_error; - double prod_error; - { - WallTimer tim("\tSmolyak quadrature time: "); - SmolyakQuadrature quad(func.indim(), level, glq); - quad.integrate(func, level, sthread::detach_thread_group::max_parallel_threads, out); - out.add(-1.0, res); - smol_error = out.getMax(); - std::cout << "\tNumber of Smolyak evaluations: " << quad.numEvals(level) << std::endl; - std::cout << "\tError: " << std::setw(16) << std::setprecision(12) << smol_error << std::endl; - } - { - WallTimer tim("\tProduct quadrature time: "); - ProductQuadrature quad(func.indim(), glq); - quad.integrate(func, level, sthread::detach_thread_group::max_parallel_threads, out); - out.add(-1.0, res); - prod_error = out.getMax(); - std::cout << "\tNumber of product evaluations: " << quad.numEvals(level) << std::endl; - std::cout << "\tError: " << std::setw(16) << std::setprecision(12) << prod_error << std::endl; - } - - return smol_error < tol && prod_error < tol; -} - -bool -TestRunnable::qmc_cube(const VectorFunction &func, double res, double tol, int level) -{ - Vector r(1); - double error1; - { - WallTimer tim("\tQuasi-Monte Carlo (Warnock scrambling) time: "); - WarnockPerScheme wps; - QMCarloCubeQuadrature qmc(func.indim(), level, wps); - qmc.integrate(func, level, sthread::detach_thread_group::max_parallel_threads, r); - error1 = std::max(res - r[0], r[0] - res); - std::cout << "\tQuasi-Monte Carlo (Warnock scrambling) error: " << std::setw(16) << std::setprecision(12) << error1 << std::endl; - } - double error2; - { - WallTimer tim("\tQuasi-Monte Carlo (reverse scrambling) time: "); - ReversePerScheme rps; - QMCarloCubeQuadrature qmc(func.indim(), level, rps); - qmc.integrate(func, level, sthread::detach_thread_group::max_parallel_threads, r); - error2 = std::max(res - r[0], r[0] - res); - std::cout << "\tQuasi-Monte Carlo (reverse scrambling) error: " << std::setw(16) << std::setprecision(12) << error2 << std::endl; - } - double error3; - { - WallTimer tim("\tQuasi-Monte Carlo (no scrambling) time: "); - IdentityPerScheme ips; - QMCarloCubeQuadrature qmc(func.indim(), level, ips); - qmc.integrate(func, level, sthread::detach_thread_group::max_parallel_threads, r); - error3 = std::max(res - r[0], r[0] - res); - std::cout << "\tQuasi-Monte Carlo (no scrambling) error: " << std::setw(16) << std::setprecision(12) << error3 << std::endl; - } - - return error1 < tol && error2 < tol && error3 < tol; -} - -/****************************************************/ -/* definition of TestRunnable subclasses */ -/****************************************************/ -class SmolyakNormalMom1 : public TestRunnable -{ -public: - SmolyakNormalMom1() - : TestRunnable("Smolyak normal moments (dim=2, level=4, order=4)", 4, 2) - { - } - - bool - run() const override - { - GeneralMatrix m(2, 2); - m.zeros(); - m.get(0, 0) = 1; - m.get(1, 1) = 1; - return smolyak_normal_moments(m, 4, 4); - } -}; - -class SmolyakNormalMom2 : public TestRunnable -{ -public: - SmolyakNormalMom2() - : TestRunnable("Smolyak normal moments (dim=3, level=8, order=8)", 8, 3) - { - } - - bool - run() const override - { - GeneralMatrix m(3, 3); - m.zeros(); - m.get(0, 0) = 1; - m.get(0, 2) = 0.5; - m.get(1, 1) = 1; - m.get(1, 0) = 0.5; - m.get(2, 2) = 2; - m.get(2, 1) = 4; - return smolyak_normal_moments(m, 8, 8); - } -}; - -class ProductNormalMom1 : public TestRunnable -{ -public: - ProductNormalMom1() - : TestRunnable("Product normal moments (dim=2, level=4, order=4)", 4, 2) - { - } - - bool - run() const override - { - GeneralMatrix m(2, 2); - m.zeros(); - m.get(0, 0) = 1; - m.get(1, 1) = 1; - return product_normal_moments(m, 4, 4); - } -}; - -class ProductNormalMom2 : public TestRunnable -{ -public: - ProductNormalMom2() - : TestRunnable("Product normal moments (dim=3, level=8, order=8)", 8, 3) - { - } - - bool - run() const override - { - GeneralMatrix m(3, 3); - m.zeros(); - m.get(0, 0) = 1; - m.get(0, 2) = 0.5; - m.get(1, 1) = 1; - m.get(1, 0) = 0.5; - m.get(2, 2) = 2; - m.get(2, 1) = 4; - return product_normal_moments(m, 8, 8); - } -}; - -// Note that here we pass 1,1 to tls since smolyak has its own PascalTriangle -class F1GaussLegendre : public TestRunnable -{ -public: - F1GaussLegendre() - : TestRunnable("Function1 Gauss-Legendre (dim=6, level=13", 1, 1) - { - } - - bool - run() const override - { - Function1Trans f1(6); - Vector res(1); - res[0] = 1.0; - return smolyak_product_cube(f1, res, 1e-2, 13); - } -}; - -class F1QuasiMCarlo : public TestRunnable -{ -public: - F1QuasiMCarlo() - : TestRunnable("Function1 Quasi-Monte Carlo (dim=6, level=1000000)", 1, 1) - { - } - - bool - run() const override - { - Function1 f1(6); - return qmc_cube(f1, 1.0, 1.e-4, 1000000); - } -}; - -int -main() -{ - std::vector<std::unique_ptr<TestRunnable>> all_tests; - // Fill in vector of all tests - all_tests.push_back(std::make_unique<SmolyakNormalMom1>()); - all_tests.push_back(std::make_unique<SmolyakNormalMom2>()); - all_tests.push_back(std::make_unique<ProductNormalMom1>()); - all_tests.push_back(std::make_unique<ProductNormalMom2>()); - all_tests.push_back(std::make_unique<F1GaussLegendre>()); - all_tests.push_back(std::make_unique<F1QuasiMCarlo>()); - - // Find maximum dimension and maximum nvar - int dmax = 0; - int nvmax = 0; - for (const auto &test : all_tests) - { - dmax = std::max(dmax, test->dim); - nvmax = std::max(nvmax, test->nvar); - } - TLStatic::init(dmax, nvmax); // initialize library - - // Launch the tests - int success = 0; - for (const auto &test : all_tests) - { - try - { - if (test->test()) - success++; - } - catch (const TLException &e) - { - std::cout << "Caught TL exception in <" << test->name << ">:" << std::endl; - e.print(); - } - catch (SylvException &e) - { - std::cout << "Caught Sylv exception in <" << test->name << ">:" << std::endl; - e.printMessage(); - } - } - - int nfailed = all_tests.size() - success; - std::cout << "There were " << nfailed << " tests that failed out of " - << all_tests.size() << " tests run." << std::endl; - - if (nfailed) - return EXIT_FAILURE; - else - return EXIT_SUCCESS; -} diff --git a/dynare++/kord/Makefile.am b/dynare++/kord/Makefile.am deleted file mode 100644 index 2779a754428be950e57b45727a90ff555694e291..0000000000000000000000000000000000000000 --- a/dynare++/kord/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -noinst_LIBRARIES = libkord.a - -libkord_a_SOURCES = \ - approximation.cc \ - approximation.hh \ - decision_rule.cc \ - decision_rule.hh \ - dynamic_model.cc \ - dynamic_model.hh \ - faa_di_bruno.cc \ - faa_di_bruno.hh \ - first_order.cc \ - first_order.hh \ - global_check.cc \ - global_check.hh \ - kord_exception.hh \ - korder.cc \ - korder.hh \ - korder_stoch.cc \ - korder_stoch.hh \ - journal.cc \ - journal.hh \ - normal_conjugate.cc \ - normal_conjugate.hh \ - seed_generator.cc \ - seed_generator.hh - -libkord_a_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -I../utils/cc -I$(top_srcdir)/mex/sources $(CPPFLAGS_MATIO) -DDYNVERSION=\"$(PACKAGE_VERSION)\" - -check_PROGRAMS = tests - -tests_SOURCES = tests.cc -tests_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -I../utils/cc -I$(top_srcdir)/mex/sources -tests_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) -tests_LDADD = libkord.a ../tl/cc/libtl.a ../sylv/cc/libsylv.a ../utils/cc/libutils.a $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) $(LIBADD_MATIO) - -check-local: - ./tests - -CLEANFILES = out.txt diff --git a/dynare++/kord/decision_rule.cc b/dynare++/kord/decision_rule.cc deleted file mode 100644 index 9330a73aa119267339e173d438dd69fa52acdf2a..0000000000000000000000000000000000000000 --- a/dynare++/kord/decision_rule.cc +++ /dev/null @@ -1,586 +0,0 @@ -/* - * Copyright © 2004 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "kord_exception.hh" -#include "decision_rule.hh" -#include "dynamic_model.hh" -#include "seed_generator.hh" - -#include "SymSchurDecomp.hh" - -#include <dynlapack.h> - -#include <limits> -#include <utility> -#include <memory> - -// FoldDecisionRule conversion from UnfoldDecisionRule -FoldDecisionRule::FoldDecisionRule(const UnfoldDecisionRule &udr) - : DecisionRuleImpl<Storage::fold>(ctraits<Storage::fold>::Tpol(udr.nrows(), udr.nvars()), - udr.ypart, udr.nu, udr.ysteady) -{ - for (const auto &it : udr) - insert(std::make_unique<ctraits<Storage::fold>::Ttensym>(*(it.second))); -} - -// UnfoldDecisionRule conversion from FoldDecisionRule -UnfoldDecisionRule::UnfoldDecisionRule(const FoldDecisionRule &fdr) - : DecisionRuleImpl<Storage::unfold>(ctraits<Storage::unfold>::Tpol(fdr.nrows(), fdr.nvars()), - fdr.ypart, fdr.nu, fdr.ysteady) -{ - for (const auto &it : fdr) - insert(std::make_unique<ctraits<Storage::unfold>::Ttensym>(*(it.second))); -} - -/* This runs simulations with an output to journal file. Note that we - report how many simulations had to be thrown out due to Nan or Inf. */ - -void -SimResults::simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov, Journal &journal) -{ - JournalRecordPair paa(journal); - paa << "Performing " << num_sim << " stochastic simulations for " - << num_per << " periods burning " << num_burn << " initial periods" << endrec; - simulate(num_sim, dr, start, vcov); - int thrown = num_sim - data.size(); - if (thrown > 0) - { - JournalRecord rec(journal); - rec << "I had to throw " << thrown << " simulations away due to Nan or Inf" << endrec; - } -} - -/* This runs a given number of simulations by creating - SimulationWorker for each simulation and inserting them to the - thread group. */ - -void -SimResults::simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov) -{ - std::vector<RandomShockRealization> rsrs; - rsrs.reserve(num_sim); - - sthread::detach_thread_group gr; - for (int i = 0; i < num_sim; i++) - { - RandomShockRealization sr(vcov, seed_generator::get_new_seed()); - rsrs.push_back(sr); - gr.insert(std::make_unique<SimulationWorker>(*this, dr, DecisionRule::emethod::horner, - num_per+num_burn, start, rsrs.back())); - } - gr.run(); -} - -/* This adds the data with the realized shocks. It takes only periods - which are not to be burnt. If the data is not finite, the both data - and shocks are thrown away. */ - -bool -SimResults::addDataSet(const TwoDMatrix &d, const ExplicitShockRealization &sr, const ConstVector &st) -{ - KORD_RAISE_IF(d.nrows() != num_y, - "Incompatible number of rows for SimResults::addDataSets"); - KORD_RAISE_IF(d.ncols() != num_per+num_burn, - "Incompatible number of cols for SimResults::addDataSets"); - bool ret = false; - if (d.isFinite()) - { - data.emplace_back(d, num_burn, num_per); - shocks.emplace_back(ConstTwoDMatrix(sr.getShocks(), num_burn, num_per)); - if (num_burn == 0) - start.emplace_back(st); - else - start.emplace_back(d.getCol(num_burn-1)); - ret = true; - } - - return ret; -} - -void -SimResults::writeMat(const std::string &base, const std::string &lname) const -{ - std::string matfile_name = base + ".mat"; - mat_t *matfd = Mat_Create(matfile_name.c_str(), nullptr); - if (matfd) - { - writeMat(matfd, lname); - Mat_Close(matfd); - } -} - -/* This save the results as matrices with given prefix and with index - appended. If there is only one matrix, the index is not appended. */ - -void -SimResults::writeMat(mat_t *fd, const std::string &lname) const -{ - for (int i = 0; i < getNumSets(); i++) - { - std::string tmp = lname + "_data"; - if (getNumSets() > 1) - tmp += std::to_string(i+1); - data[i].writeMat(fd, tmp); - } -} - -void -SimResultsStats::simulate(int num_sim, const DecisionRule &dr, - const Vector &start, - const TwoDMatrix &vcov, Journal &journal) -{ - SimResults::simulate(num_sim, dr, start, vcov, journal); - { - JournalRecordPair paa(journal); - paa << "Calculating means from the simulations." << endrec; - calcMean(); - } - { - JournalRecordPair paa(journal); - paa << "Calculating covariances from the simulations." << endrec; - calcVcov(); - } -} - -/* Here we do not save the data itself, we save only mean and vcov. */ -void -SimResultsStats::writeMat(mat_t *fd, const std::string &lname) const -{ - ConstTwoDMatrix(num_y, 1, mean).writeMat(fd, lname + "_mean");; - vcov.writeMat(fd, lname + "_vcov"); -} - -void -SimResultsStats::calcMean() -{ - mean.zeros(); - if (data.size()*num_per > 0) - { - double mult = 1.0/data.size()/num_per; - for (const auto &i : data) - { - for (int j = 0; j < num_per; j++) - { - ConstVector col{i.getCol(j)}; - mean.add(mult, col); - } - } - } -} - -void -SimResultsStats::calcVcov() -{ - if (data.size()*num_per > 1) - { - vcov.zeros(); - double mult = 1.0/(data.size()*num_per - 1); - for (const auto &d : data) - for (int j = 0; j < num_per; j++) - for (int m = 0; m < num_y; m++) - for (int n = m; n < num_y; n++) - { - double s = (d.get(m, j)-mean[m])*(d.get(n, j)-mean[n]); - vcov.get(m, n) += mult*s; - if (m != n) - vcov.get(n, m) += mult*s; - } - } - else - vcov.infs(); -} - -void -SimResultsDynamicStats::simulate(int num_sim, const DecisionRule &dr, - const Vector &start, - const TwoDMatrix &vcov, Journal &journal) -{ - SimResults::simulate(num_sim, dr, start, vcov, journal); - { - JournalRecordPair paa(journal); - paa << "Calculating means of the conditional simulations." << endrec; - calcMean(); - } - { - JournalRecordPair paa(journal); - paa << "Calculating variances of the conditional simulations." << endrec; - calcVariance(); - } -} - -void -SimResultsDynamicStats::writeMat(mat_t *fd, const std::string &lname) const -{ - mean.writeMat(fd, lname + "_cond_mean"); - variance.writeMat(fd, lname + "_cond_variance"); -} - -void -SimResultsDynamicStats::calcMean() -{ - mean.zeros(); - if (data.size() > 0) - { - double mult = 1.0/data.size(); - for (int j = 0; j < num_per; j++) - { - Vector meanj{mean.getCol(j)}; - for (const auto &i : data) - { - ConstVector col{i.getCol(j)}; - meanj.add(mult, col); - } - } - } -} - -void -SimResultsDynamicStats::calcVariance() -{ - if (data.size() > 1) - { - variance.zeros(); - double mult = 1.0/(data.size()-1); - for (int j = 0; j < num_per; j++) - { - ConstVector meanj{mean.getCol(j)}; - Vector varj{variance.getCol(j)}; - for (const auto &i : data) - { - Vector col{i.getCol(j)}; - col.add(-1.0, meanj); - for (int k = 0; k < col.length(); k++) - col[k] = col[k]*col[k]; - varj.add(mult, col); - } - } - } - else - variance.infs(); -} - -void -SimResultsIRF::simulate(const DecisionRule &dr, Journal &journal) -{ - JournalRecordPair paa(journal); - paa << "Performing " << control.getNumSets() << " IRF simulations for " - << num_per << " periods; shock=" << ishock << ", impulse=" << imp << endrec; - simulate(dr); - int thrown = control.getNumSets() - data.size(); - if (thrown > 0) - { - JournalRecord rec(journal); - rec << "I had to throw " << thrown - << " simulations away due to Nan or Inf" << endrec; - } - calcMeans(); - calcVariances(); -} - -void -SimResultsIRF::simulate(const DecisionRule &dr) -{ - sthread::detach_thread_group gr; - for (int idata = 0; idata < control.getNumSets(); idata++) - gr.insert(std::make_unique<SimulationIRFWorker>(*this, dr, DecisionRule::emethod::horner, - num_per, idata, ishock, imp)); - gr.run(); -} - -void -SimResultsIRF::calcMeans() -{ - means.zeros(); - if (data.size() > 0) - { - for (const auto &i : data) - means.add(1.0, i); - means.mult(1.0/data.size()); - } -} - -void -SimResultsIRF::calcVariances() -{ - if (data.size() > 1) - { - variances.zeros(); - for (const auto &i : data) - { - TwoDMatrix d(i); - d.add(-1.0, means); - for (int j = 0; j < d.nrows(); j++) - for (int k = 0; k < d.ncols(); k++) - variances.get(j, k) += d.get(j, k)*d.get(j, k); - d.mult(1.0/(data.size()-1)); - } - } - else - variances.infs(); -} - -void -SimResultsIRF::writeMat(mat_t *fd, const std::string &lname) const -{ - means.writeMat(fd, lname + "_mean"); - variances.writeMat(fd, lname + "_var"); -} - -void -RTSimResultsStats::simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &v, Journal &journal) -{ - JournalRecordPair paa(journal); - paa << "Performing " << num_sim << " real-time stochastic simulations for " - << num_per << " periods" << endrec; - simulate(num_sim, dr, start, v); - mean = nc.getMean(); - mean.add(1.0, dr.getSteady()); - nc.getVariance(vcov); - if (thrown_periods > 0) - { - JournalRecord rec(journal); - rec << "I had to throw " << thrown_periods << " periods away due to Nan or Inf" << endrec; - JournalRecord rec1(journal); - rec1 << "This affected " << incomplete_simulations << " out of " - << num_sim << " simulations" << endrec; - } -} - -void -RTSimResultsStats::simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov) -{ - std::vector<RandomShockRealization> rsrs; - rsrs.reserve(num_sim); - - sthread::detach_thread_group gr; - for (int i = 0; i < num_sim; i++) - { - RandomShockRealization sr(vcov, seed_generator::get_new_seed()); - rsrs.push_back(sr); - gr.insert(std::make_unique<RTSimulationWorker>(*this, dr, DecisionRule::emethod::horner, - num_per, start, rsrs.back())); - } - gr.run(); -} - -void -RTSimResultsStats::writeMat(mat_t *fd, const std::string &lname) -{ - ConstTwoDMatrix(nc.getDim(), 1, mean).writeMat(fd, lname + "_rt_mean"); - vcov.writeMat(fd, lname + "_rt_vcov"); -} - -IRFResults::IRFResults(const DynamicModel &mod, const DecisionRule &dr, - const SimResults &control, std::vector<int> ili, - Journal &journal) - : model(mod), irf_list_ind(std::move(ili)) -{ - int num_per = control.getNumPer(); - JournalRecordPair pa(journal); - pa << "Calculating IRFs against control for " << static_cast<int>(irf_list_ind.size()) << " shocks and for " - << num_per << " periods" << endrec; - const TwoDMatrix &vcov = mod.getVcov(); - for (int ishock : irf_list_ind) - { - double stderror = sqrt(vcov.get(ishock, ishock)); - irf_res.emplace_back(control, model.numeq(), num_per, - ishock, stderror); - irf_res.emplace_back(control, model.numeq(), num_per, - ishock, -stderror); - } - - for (unsigned int ii = 0; ii < irf_list_ind.size(); ii++) - { - irf_res[2*ii].simulate(dr, journal); - irf_res[2*ii+1].simulate(dr, journal); - } -} - -void -IRFResults::writeMat(mat_t *fd, const std::string &prefix) const -{ - for (unsigned int i = 0; i < irf_list_ind.size(); i++) - { - int ishock = irf_list_ind[i]; - auto shockname = model.getExogNames().getName(ishock); - irf_res[2*i].writeMat(fd, prefix + "_irfp_" + shockname); - irf_res[2*i+1].writeMat(fd, prefix + "_irfm_" + shockname); - } -} - -void -SimulationWorker::operator()(std::mutex &mut) -{ - ExplicitShockRealization esr(sr, np); - TwoDMatrix m{dr.simulate(em, np, st, esr)}; - { - std::unique_lock<std::mutex> lk{mut}; - res.addDataSet(m, esr, st); - } -} - -/* Here we create a new instance of ExplicitShockRealization of the - corresponding control, add the impulse, and simulate. */ - -void -SimulationIRFWorker::operator()(std::mutex &mut) -{ - ExplicitShockRealization esr(res.control.getShocks(idata)); - esr.addToShock(ishock, 0, imp); - TwoDMatrix m{dr.simulate(em, np, res.control.getStart(idata), esr)}; - m.add(-1.0, res.control.getData(idata)); - { - std::unique_lock<std::mutex> lk{mut}; - res.addDataSet(m, esr, res.control.getStart(idata)); - } -} - -void -RTSimulationWorker::operator()(std::mutex &mut) -{ - NormalConj nc(res.nc.getDim()); - const PartitionY &ypart = dr.getYPart(); - int nu = dr.nexog(); - const Vector &ysteady = dr.getSteady(); - - // initialize vectors and subvectors for simulation - Vector dyu(ypart.nys()+nu); - ConstVector ystart_pred(ystart, ypart.nstat, ypart.nys()); - ConstVector ysteady_pred(ysteady, ypart.nstat, ypart.nys()); - Vector dy(dyu, 0, ypart.nys()); - Vector u(dyu, ypart.nys(), nu); - Vector y(nc.getDim()); - ConstVector ypred(y, ypart.nstat, ypart.nys()); - - // simulate the first real-time period - int ip = 0; - dy = ystart_pred; - dy.add(-1.0, ysteady_pred); - sr.get(ip, u); - dr.eval(em, y, dyu); - if (ip >= res.num_burn) - nc.update(y); - - // simulate other real-time periods - while (y.isFinite() && ip < res.num_burn + res.num_per) - { - ip++; - dy = ypred; - sr.get(ip, u); - dr.eval(em, y, dyu); - if (ip >= res.num_burn) - nc.update(y); - } - { - std::unique_lock<std::mutex> lk{mut}; - res.nc.update(nc); - if (res.num_per-ip > 0) - { - res.incomplete_simulations++; - res.thrown_periods += res.num_per-ip; - } - } -} - -/* This calculates factorization FFᵀ=V in the Cholesky way. It does - not work for semidefinite matrices. */ - -void -RandomShockRealization::choleskyFactor(const ConstTwoDMatrix &v) -{ - factor = v; - lapack_int rows = factor.nrows(), lda = factor.getLD(); - for (int i = 0; i < rows; i++) - for (int j = i+1; j < rows; j++) - factor.get(i, j) = 0.0; - lapack_int info; - - dpotrf("L", &rows, factor.base(), &lda, &info); - KORD_RAISE_IF(info != 0, - "Info!=0 in RandomShockRealization::choleskyFactor"); -} - -/* This calculates FFᵀ=V factorization by symmetric Schur - decomposition. It works for semidefinite matrices. */ - -void -RandomShockRealization::schurFactor(const ConstTwoDMatrix &v) -{ - SymSchurDecomp(v).getFactor(factor); -} - -void -RandomShockRealization::get(int n, Vector &out) -{ - KORD_RAISE_IF(out.length() != numShocks(), - "Wrong length of out vector in RandomShockRealization::get"); - Vector d(out.length()); - for (int i = 0; i < d.length(); i++) - d[i] = dis(mtwister); - out.zeros(); - factor.multaVec(out, ConstVector(d)); -} - -ExplicitShockRealization::ExplicitShockRealization(ShockRealization &sr, - int num_per) - : shocks(sr.numShocks(), num_per) -{ - for (int j = 0; j < num_per; j++) - { - Vector jcol{shocks.getCol(j)}; - sr.get(j, jcol); - } -} - -void -ExplicitShockRealization::get(int n, Vector &out) -{ - KORD_RAISE_IF(out.length() != numShocks(), - "Wrong length of out vector in ExplicitShockRealization::get"); - int i = n % shocks.ncols(); - ConstVector icol{shocks.getCol(i)}; - out = icol; -} - -void -ExplicitShockRealization::addToShock(int ishock, int iper, double val) -{ - KORD_RAISE_IF(ishock < 0 || ishock > numShocks(), - "Wrong index of shock in ExplicitShockRealization::addToShock"); - int j = iper % shocks.ncols(); - shocks.get(ishock, j) += val; -} - -void -GenShockRealization::get(int n, Vector &out) -{ - KORD_RAISE_IF(out.length() != numShocks(), - "Wrong length of out vector in GenShockRealization::get"); - ExplicitShockRealization::get(n, out); - Vector r(numShocks()); - RandomShockRealization::get(n, r); - for (int j = 0; j < numShocks(); j++) - if (!std::isfinite(out[j])) - out[j] = r[j]; -} diff --git a/dynare++/kord/dynamic_model.cc b/dynare++/kord/dynamic_model.cc deleted file mode 100644 index 99b5d525cf00944eb9fa3cfc660947d42d57babf..0000000000000000000000000000000000000000 --- a/dynare++/kord/dynamic_model.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "dynamic_model.hh" - -#include <iostream> -#include <algorithm> - -void -NameList::print() const -{ - for (int i = 0; i < getNum(); i++) - std::cout << getName(i) << '\n'; -} - -void -NameList::writeMat(mat_t *fd, const std::string &vname) const -{ - int maxlen = 0; - for (int i = 0; i < getNum(); i++) - maxlen = std::max(maxlen, static_cast<int>(getName(i).size())); - - if (maxlen == 0) - return; - - auto m = std::make_unique<char[]>(getNum()*maxlen); - - for (int i = 0; i < getNum(); i++) - for (int j = 0; j < maxlen; j++) - if (j < static_cast<int>(getName(i).size())) - m[j*getNum()+i] = getName(i)[j]; - else - m[j*getNum()+i] = ' '; - - size_t dims[2]; - dims[0] = getNum(); - dims[1] = maxlen; - - matvar_t *v = Mat_VarCreate(vname.c_str(), MAT_C_CHAR, MAT_T_UINT8, 2, dims, m.get(), 0); - - Mat_VarWrite(fd, v, MAT_COMPRESSION_NONE); - - Mat_VarFree(v); -} - -void -NameList::writeMatIndices(mat_t *fd, const std::string &prefix) const -{ - TwoDMatrix aux(1, 1); - for (int i = 0; i < getNum(); i++) - { - aux.get(0, 0) = i+1; - aux.writeMat(fd, prefix + "_i_" + getName(i)); - } -} diff --git a/dynare++/kord/global_check.cc b/dynare++/kord/global_check.cc deleted file mode 100644 index 0992c8ad16a75eb8ff41984913af781f563fce59..0000000000000000000000000000000000000000 --- a/dynare++/kord/global_check.cc +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "SymSchurDecomp.hh" - -#include "global_check.hh" -#include "seed_generator.hh" - -#include "smolyak.hh" -#include "product.hh" -#include "quasi_mcarlo.hh" - -#include <utility> -#include <cmath> - -/* Here we just set a reference to the approximation, and create a new - DynamicModel. */ - -ResidFunction::ResidFunction(const Approximation &app) - : VectorFunction(app.getModel().nexog(), app.getModel().numeq()), approx(app), - model(app.getModel().clone()) -{ -} - -ResidFunction::ResidFunction(const ResidFunction &rf) - : VectorFunction(rf), approx(rf.approx), model(rf.model->clone()) -{ - if (rf.yplus) - yplus = std::make_unique<Vector>(*(rf.yplus)); - if (rf.ystar) - ystar = std::make_unique<Vector>(*(rf.ystar)); - if (rf.u) - u = std::make_unique<Vector>(*(rf.u)); - if (rf.hss) - hss = std::make_unique<FTensorPolynomial>(*(rf.hss)); -} - -/* This sets y* and u. We have to create ‘ystar’, ‘u’, ‘yplus’ and ‘hss’. */ - -void -ResidFunction::setYU(const ConstVector &ys, const ConstVector &xx) -{ - ystar = std::make_unique<Vector>(ys); - u = std::make_unique<Vector>(xx); - yplus = std::make_unique<Vector>(model->numeq()); - approx.getFoldDecisionRule().evaluate(DecisionRule::emethod::horner, - *yplus, *ystar, *u); - - // make a tensor polynomial of in-place subtensors from decision rule - /* Note that the non-const polynomial will be used for a construction of - ‘hss’ and will be used in a const context. So this const cast is safe. - - Note, that there is always a folded decision rule in Approximation. */ - const FoldDecisionRule &dr = approx.getFoldDecisionRule(); - FTensorPolynomial dr_ss(model->nstat()+model->npred(), model->nboth()+model->nforw(), - const_cast<FoldDecisionRule &>(dr)); - - // make ‘ytmp_star’ be a difference of ‘yplus’ from steady - Vector ytmp_star(ConstVector(*yplus, model->nstat(), model->npred()+model->nboth())); - ConstVector ysteady_star(dr.getSteady(), model->nstat(), - model->npred()+model->nboth()); - ytmp_star.add(-1.0, ysteady_star); - - // make ‘hss’ and add steady to it - /* Here is the const context of ‘dr_ss’. */ - hss = std::make_unique<FTensorPolynomial>(dr_ss, ytmp_star); - ConstVector ysteady_ss(dr.getSteady(), model->nstat()+model->npred(), - model->nboth()+model->nforw()); - if (hss->check(Symmetry{0})) - hss->get(Symmetry{0}).getData().add(1.0, ysteady_ss); - else - { - auto ten = std::make_unique<FFSTensor>(hss->nrows(), hss->nvars(), 0); - ten->getData() = ysteady_ss; - hss->insert(std::move(ten)); - } -} - -/* Here we evaluate the residual F(y*,u,u′). We have to evaluate ‘hss’ for - u′=point and then we evaluate the system f. */ - -void -ResidFunction::eval(const Vector &point, const ParameterSignal &sig, Vector &out) -{ - KORD_RAISE_IF(point.length() != hss->nvars(), - "Wrong dimension of input vector in ResidFunction::eval"); - KORD_RAISE_IF(out.length() != model->numeq(), - "Wrong dimension of output vector in ResidFunction::eval"); - Vector yss(hss->nrows()); - hss->evalHorner(yss, point); - model->evaluateSystem(out, *ystar, *yplus, yss, *u); -} - -/* This checks the 𝔼[F(y*,u,u′)] for a given y* and u by integrating with a - given quadrature. Note that the input ‘ys’ is y* not whole y. */ - -void -GlobalChecker::check(const Quadrature &quad, int level, - const ConstVector &ys, const ConstVector &x, Vector &out) -{ - for (int ifunc = 0; ifunc < vfs.getNum(); ifunc++) - dynamic_cast<GResidFunction &>(vfs.getFunc(ifunc)).setYU(ys, x); - quad.integrate(vfs, level, out); -} - -/* This method is a bulk version of GlobalChecker::check() vector code. It - decides between Smolyak and product quadrature according to ‘max_evals’ - constraint. - - Note that ‘y’ can be either full (all endogenous variables including static - and forward looking), or just y* (state variables). The method is able to - recognize it. */ - -void -GlobalChecker::check(int max_evals, const ConstTwoDMatrix &y, - const ConstTwoDMatrix &x, TwoDMatrix &out) -{ - JournalRecordPair pa(journal); - pa << "Checking approximation error for " << y.ncols() - << " states with at most " << max_evals << " evaluations" << endrec; - - // Decide about which type of quadrature - GaussHermite gh; - - SmolyakQuadrature dummy_sq(model.nexog(), 1, gh); - int smol_evals; - int smol_level; - dummy_sq.designLevelForEvals(max_evals, smol_level, smol_evals); - - ProductQuadrature dummy_pq(model.nexog(), gh); - int prod_evals; - int prod_level; - dummy_pq.designLevelForEvals(max_evals, prod_level, prod_evals); - - bool take_smolyak = (smol_evals < prod_evals) && (smol_level >= prod_level-1); - - std::unique_ptr<Quadrature> quad; - int lev; - - // Create the quadrature and report the decision - if (take_smolyak) - { - quad = std::make_unique<SmolyakQuadrature>(model.nexog(), smol_level, gh); - lev = smol_level; - JournalRecord rec(journal); - rec << "Selected Smolyak (level,evals)=(" << smol_level << "," - << smol_evals << ") over product (" << prod_level << "," - << prod_evals << ")" << endrec; - } - else - { - quad = std::make_unique<ProductQuadrature>(model.nexog(), gh); - lev = prod_level; - JournalRecord rec(journal); - rec << "Selected product (level,evals)=(" << prod_level << "," - << prod_evals << ") over Smolyak (" << smol_level << "," - << smol_evals << ")" << endrec; - } - - // Check all columns of ‘y’ and ‘x’ - int first_row = (y.nrows() == model.numeq()) ? model.nstat() : 0; - ConstTwoDMatrix ysmat(y, first_row, 0, model.npred()+model.nboth(), y.ncols()); - for (int j = 0; j < y.ncols(); j++) - { - ConstVector yj{ysmat.getCol(j)}; - ConstVector xj{x.getCol(j)}; - Vector outj{out.getCol(j)}; - check(*quad, lev, yj, xj, outj); - } -} - -/* This method checks an error of the approximation by evaluating residual - 𝔼[F(y*,u,u′) | y*,u] for y* equal to the steady state, and changing u. We go - through all elements of u and vary them from −mult·σ to mult·σ in ‘m’ - steps. */ - -void -GlobalChecker::checkAlongShocksAndSave(mat_t *fd, const std::string &prefix, - int m, double mult, int max_evals) -{ - JournalRecordPair pa(journal); - pa << "Calculating errors along shocks +/- " - << mult << " std errors, granularity " << m << endrec; - - // Setup ‘y_mat’ of steady states for checking - TwoDMatrix y_mat(model.numeq(), 2*m*model.nexog()+1); - for (int j = 0; j < 2*m*model.nexog()+1; j++) - { - Vector yj{y_mat.getCol(j)}; - yj = model.getSteady(); - } - - // Setup ‘exo_mat’ for checking - TwoDMatrix exo_mat(model.nexog(), 2*m*model.nexog()+1); - exo_mat.zeros(); - for (int ishock = 0; ishock < model.nexog(); ishock++) - { - double max_sigma = sqrt(model.getVcov().get(ishock, ishock)); - for (int j = 0; j < 2*m; j++) - { - int jmult = (j < m) ? j-m : j-m+1; - exo_mat.get(ishock, 1+2*m*ishock+j) = mult*jmult*max_sigma/m; - } - } - - TwoDMatrix errors(model.numeq(), 2*m*model.nexog()+1); - check(max_evals, y_mat, exo_mat, errors); - - // Report errors along shock and save them - TwoDMatrix res(model.nexog(), 2*m+1); - JournalRecord rec(journal); - rec << "Shock value error" << endrec; - ConstVector err0{errors.getCol(0)}; - for (int ishock = 0; ishock < model.nexog(); ishock++) - { - TwoDMatrix err_out(model.numeq(), 2*m+1); - for (int j = 0; j < 2*m+1; j++) - { - int jj; - Vector error{err_out.getCol(j)}; - if (j != m) - { - if (j < m) - jj = 1 + 2*m*ishock+j; - else - jj = 1 + 2*m*ishock+j-1; - ConstVector coljj{errors.getCol(jj)}; - error = coljj; - } - else - { - jj = 0; - error = err0; - } - JournalRecord rec1(journal); - std::string shockname{model.getExogNames().getName(ishock)}; - shockname.resize(8, ' '); - rec1 << shockname << ' ' << exo_mat.get(ishock, jj) - << "\t" << error.getMax() << endrec; - } - err_out.writeMat(fd, prefix + "_shock_" + model.getExogNames().getName(ishock) + "_errors"); - } -} - -/* This method checks errors on ellipse of endogenous states (predetermined - variables). The ellipse is shaped according to covariance matrix of - endogenous variables based on the first order approximation and scaled by - ‘mult’. The points on the ellipse are chosen as polar images of the low - discrepancy grid in a cube. - - The method works as follows. First we calculate symmetric Schur factor of - covariance matrix of the states. Second we generate low discrepancy points - on the unit sphere. Third we transform the sphere with the - variance-covariance matrix factor and multiplier ‘mult’ and initialize - matrix of uₜ to zeros. Fourth we run the check() method and save the - results. */ - -void -GlobalChecker::checkOnEllipseAndSave(mat_t *fd, const std::string &prefix, - int m, double mult, int max_evals) -{ - JournalRecordPair pa(journal); - pa << "Calculating errors at " << m - << " ellipse points scaled by " << mult << endrec; - - // Make factor of covariance of variables - /* Here we set ‘ycovfac’ to the symmetric Schur decomposition factor of a - submatrix of covariances of all endogenous variables. The submatrix - corresponds to state variables (predetermined plus both). */ - TwoDMatrix ycov{approx.calcYCov()}; - TwoDMatrix ycovpred(const_cast<const TwoDMatrix &>(ycov), model.nstat(), model.nstat(), - model.npred()+model.nboth(), model.npred()+model.nboth()); - SymSchurDecomp ssd(ycovpred); - ssd.correctDefinitness(1.e-05); - TwoDMatrix ycovfac(ycovpred.nrows(), ycovpred.ncols()); - KORD_RAISE_IF(!ssd.isPositiveSemidefinite(), - "Covariance matrix of the states not positive \ - semidefinite in GlobalChecker::checkOnEllipseAndSave"); - ssd.getFactor(ycovfac); - - // Put low discrepancy sphere points to ‘ymat’ - /* Here we first calculate dimension ‘d’ of the sphere, which is a number of - state variables minus one. We go through the ‘d’-dimensional cube [0,1]ᵈ - by QMCarloCubeQuadrature and make a polar transformation to the sphere. - The polar transformation fⁱ can be written recursively w.r.t. the - dimension i as: - - f⁰() = [1] - - ⎡cos(2πxᵢ)·fⁱ⁻¹(x₁,…,xᵢ₋₁)⎤ - fⁱ(x₁,…,xᵢ) = ⎣ sin(2πxᵢ) ⎦ - */ - int d = model.npred()+model.nboth()-1; - TwoDMatrix ymat(model.npred()+model.nboth(), (d == 0) ? 2 : m); - if (d == 0) - { - ymat.get(0, 0) = 1; - ymat.get(0, 1) = -1; - } - else - { - int icol = 0; - ReversePerScheme ps; - QMCarloCubeQuadrature qmc(d, m, ps); - qmcpit beg = qmc.start(m); - qmcpit end = qmc.end(m); - for (qmcpit run = beg; run != end; ++run, icol++) - { - Vector ycol{ymat.getCol(icol)}; - Vector x(run.point()); - x.mult(2*M_PI); - ycol[0] = 1; - for (int i = 0; i < d; i++) - { - Vector subsphere(ycol, 0, i+1); - subsphere.mult(cos(x[i])); - ycol[i+1] = sin(x[i]); - } - } - } - - // Transform sphere ‘ymat’ and prepare ‘umat’ for checking - /* Here we multiply the sphere points in ‘ymat’ with the Cholesky factor to - obtain the ellipse, scale the ellipse by the given ‘mult’, and initialize - matrix of shocks ‘umat’ to zero. */ - TwoDMatrix umat(model.nexog(), ymat.ncols()); - umat.zeros(); - ymat.mult(mult); - ymat.multLeft(ycovfac); - ConstVector ys(model.getSteady(), model.nstat(), - model.npred()+model.nboth()); - for (int icol = 0; icol < ymat.ncols(); icol++) - { - Vector ycol{ymat.getCol(icol)}; - ycol.add(1.0, ys); - } - - // Check on ellipse and save - /* Here we check the points and save the results to MAT-4 file. */ - TwoDMatrix out(model.numeq(), ymat.ncols()); - check(max_evals, ymat, umat, out); - - ymat.writeMat(fd, prefix + "_ellipse_points"); - out.writeMat(fd, prefix + "_ellipse_errors"); -} - -/* Here we check the errors along a simulation. We simulate, then set ‘x’ to - zeros, check and save results. */ - -void -GlobalChecker::checkAlongSimulationAndSave(mat_t *fd, const std::string &prefix, - int m, int max_evals) -{ - JournalRecordPair pa(journal); - pa << "Calculating errors at " << m - << " simulated points" << endrec; - RandomShockRealization sr(model.getVcov(), seed_generator::get_new_seed()); - TwoDMatrix y{approx.getFoldDecisionRule().simulate(DecisionRule::emethod::horner, - m, model.getSteady(), sr)}; - TwoDMatrix x(model.nexog(), m); - x.zeros(); - TwoDMatrix out(model.numeq(), m); - check(max_evals, y, x, out); - - y.writeMat(fd, prefix + "_simul_points"); - out.writeMat(fd, prefix + "_simul_errors"); -} diff --git a/dynare++/kord/global_check.hh b/dynare++/kord/global_check.hh deleted file mode 100644 index e5dae5057303b975030d20e7ceaf5921c5076fcc..0000000000000000000000000000000000000000 --- a/dynare++/kord/global_check.hh +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -// Global check - -/* The purpose of this file is to provide classes for checking error of - approximation. If yₜ=g(y*ₜ₋₁,u) is an approximate solution, then we check - for the error of residuals of the system equations. Let - F(y*,u,u′)=f(g**(g*(y*,u′),u),g(y*,u),y*,u), then we calculate the integral: - - 𝔼ₜ[F(y*,u,u′)] - - which we want to be zero for all y* and u. - - There are a few possibilities how and where the integral is evaluated. - Currently we offer the following ones: - - — Along shocks. The y* is set to the steady state, and u is set to zero but - one element is going from minus through plus shocks in few steps. The user - gives the scaling factor, for instance the interval [−3σ,3σ] (where σ is - one standard error of the shock), and a number of steps. This is repeated - for each shock (element of the u vector). - - — Along simulation. Some random simulation is run, and for each realization - of y* and u along the path we evaluate the residual. - - — On ellipse. Let V=AAᵀ be a covariance matrix of the predetermined - variables y* based on linear approximation, then we calculate integral for - points on the ellipse { Ax | ‖x‖₂=1 }. The points are selected by means of - low discrepancy method and polar transformation. The shock u are zeros. - - — Unconditional distribution. -*/ - -#ifndef GLOBAL_CHECK_H -#define GLOBAL_CHECK_H - -#include <matio.h> - -#include <memory> - -#include "vector_function.hh" -#include "quadrature.hh" - -#include "dynamic_model.hh" -#include "journal.hh" -#include "approximation.hh" - -/* This is a class for implementing the VectorFunction interface evaluating the - residual of equations, this is F(y*,u,u′)=f(g**(g*(y*,u),u′),y*,u) is - written as a function of u′. - - When the object is constructed, one has to specify (y*,u), this is done by - the setYU() method. The object has basically two states. One is after - construction and before the call to setYU(). The second is after the call to - setYU(). We distinguish between the two states, an object in the second - state contains ‘yplus’, ‘ystar’, ‘u’, and ‘hss’. - - The vector ‘yplus’ is g*(y*,u). ‘ystar’ is y*, and polynomial ‘hss’ is - partially evaluated g**(yplus, u). - - The pointer to DynamicModel is important, since the DynamicModel evaluates - the function f. When copying the object, we have to make also a copy of - DynamicModel. */ - -class ResidFunction : public VectorFunction -{ -protected: - const Approximation ≈ - std::unique_ptr<DynamicModel> model; - std::unique_ptr<Vector> yplus, ystar, u; - std::unique_ptr<FTensorPolynomial> hss; -public: - ResidFunction(const Approximation &app); - ResidFunction(const ResidFunction &rf); - - std::unique_ptr<VectorFunction> - clone() const override - { - return std::make_unique<ResidFunction>(*this); - } - void eval(const Vector &point, const ParameterSignal &sig, Vector &out) override; - void setYU(const ConstVector &ys, const ConstVector &xx); -}; - -/* This is a ResidFunction wrapped with GaussConverterFunction. */ - -class GResidFunction : public GaussConverterFunction -{ -public: - GResidFunction(const Approximation &app) - : GaussConverterFunction(std::make_unique<ResidFunction>(app), app.getModel().getVcov()) - { - } - std::unique_ptr<VectorFunction> - clone() const override - { - return std::make_unique<GResidFunction>(*this); - } - void - setYU(const ConstVector &ys, const ConstVector &xx) - { - dynamic_cast<ResidFunction *>(func)->setYU(ys, xx); - } -}; - -/* This is a class encapsulating checking algorithms. Its core routine is - check(), which calculates integral 𝔼[F(y*,u,u′) | y*,u] for given - realizations of y* and u. The both are given in matrices. The methods - checking along shocks, on ellipse and anlong a simulation path, just fill - the matrices and call the core check(). - - The method checkUnconditionalAndSave() evaluates unconditional 𝔼[F(y,u,u′)]. - - The object also maintains a set of GResidFunction functions ‘vfs’ in order - to save (possibly expensive) copying of DynamicModel’s. */ - -class GlobalChecker -{ - const Approximation ≈ - const DynamicModel &model; - Journal &journal; - GResidFunction rf; - VectorFunctionSet vfs; -public: - GlobalChecker(const Approximation &app, int n, Journal &jr) - : approx(app), model(approx.getModel()), journal(jr), - rf(approx), vfs(rf, n) - { - } - void check(int max_evals, const ConstTwoDMatrix &y, - const ConstTwoDMatrix &x, TwoDMatrix &out); - void checkAlongShocksAndSave(mat_t *fd, const std::string &prefix, - int m, double mult, int max_evals); - void checkOnEllipseAndSave(mat_t *fd, const std::string &prefix, - int m, double mult, int max_evals); - void checkAlongSimulationAndSave(mat_t *fd, const std::string &prefix, - int m, int max_evals); - void checkUnconditionalAndSave(mat_t *fd, const std::string &prefix, - int m, int max_evals); -protected: - void check(const Quadrature &quad, int level, - const ConstVector &y, const ConstVector &x, Vector &out); -}; - -/* Signalled resid function. Not implemented yet. todo: */ - -class ResidFunctionSig : public ResidFunction -{ -public: - ResidFunctionSig(const Approximation &app, const Vector &ys, const Vector &xx); -}; - -#endif diff --git a/dynare++/kord/normal_conjugate.cc b/dynare++/kord/normal_conjugate.cc deleted file mode 100644 index 3c5fd8b138ebeb1668776a2be772b2e1a41d2b35..0000000000000000000000000000000000000000 --- a/dynare++/kord/normal_conjugate.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © 2007 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "normal_conjugate.hh" -#include "kord_exception.hh" - -// NormalConj diffuse prior constructor -NormalConj::NormalConj(int d) - : mu(d), kappa(0), nu(-1), lambda(d, d) -{ - mu.zeros(); - lambda.zeros(); -} - -// NormalConj data update constructor -NormalConj::NormalConj(const ConstTwoDMatrix &ydata) - : mu(ydata.nrows()), kappa(ydata.ncols()), nu(ydata.ncols()-1), - lambda(ydata.nrows(), ydata.nrows()) -{ - mu.zeros(); - for (int i = 0; i < ydata.ncols(); i++) - mu.add(1.0/ydata.ncols(), ydata.getCol(i)); - - lambda.zeros(); - for (int i = 0; i < ydata.ncols(); i++) - { - Vector diff{ydata.getCol(i)}; - diff.add(-1, mu); - lambda.addOuter(diff); - } -} - -// NormalConj::update() one observation code -/* The method performs the following: - - κ₀ 1 - μ₁ = ──── μ₀ + ──── y - κ₀+1 κ₀+1 - - κ₁ = κ₀ + 1 - - ν₁ = ν₀ + 1 - - κ₀ - Λ₁ = Λ₀ + ──── (y − μ₀)(y − μ₀)ᵀ - κ₀+1 -*/ -void -NormalConj::update(const ConstVector &y) -{ - KORD_RAISE_IF(y.length() != mu.length(), - "Wrong length of a vector in NormalConj::update"); - - mu.mult(kappa/(1.0+kappa)); - mu.add(1.0/(1.0+kappa), y); - - Vector diff(y); - diff.add(-1, mu); - lambda.addOuter(diff, kappa/(1.0+kappa)); - - kappa++; - nu++; -} - -// NormalConj::update() multiple observations code -/* The method evaluates the formula in the header file. */ -void -NormalConj::update(const ConstTwoDMatrix &ydata) -{ - NormalConj nc(ydata); - update(nc); -} - -// NormalConj::update() with NormalConj code -void -NormalConj::update(const NormalConj &nc) -{ - double wold = static_cast<double>(kappa)/(kappa+nc.kappa); - double wnew = 1-wold; - - mu.mult(wold); - mu.add(wnew, nc.mu); - - Vector diff(nc.mu); - diff.add(-1, mu); - lambda.add(1.0, nc.lambda); - lambda.addOuter(diff); - - kappa = kappa + nc.kappa; - nu = nu + nc.kappa; -} - -/* This returns 1/(ν−d−1)·Λ, which is the mean of the variance in the posterior - distribution. If the number of degrees of freedom is less than d, then NaNs - are returned. */ -void -NormalConj::getVariance(TwoDMatrix &v) const -{ - if (nu > getDim()+1) - { - v = const_cast<const TwoDMatrix &>(lambda); - v.mult(1.0/(nu-getDim()-1)); - } - else - v.nans(); -} diff --git a/dynare++/kord/normal_conjugate.hh b/dynare++/kord/normal_conjugate.hh deleted file mode 100644 index 2f6268087da2b218e6ac700d40eafc66f371ceff..0000000000000000000000000000000000000000 --- a/dynare++/kord/normal_conjugate.hh +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright © 2007 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -// Conjugate family for normal distribution - -/* The main purpose here is to implement a class representing conjugate - distributions for mean and variance of the normal distribution. The class - has two main methods: the first one is to update itself with respect to one - observation, the second one is to update itself with respect to anothe - object of the class. In the both methods, the previous state of the class - corresponds to the prior distribution, and the final state corresponds to - the posterior distribution. - - The algebra can be found in Gelman, Carlin, Stern, Rubin (p.87). It goes as - follows. Prior conjugate distribution takes the following form: - - Σ ↝ InvWishart_ν₀(Λ₀⁻¹) - μ|Σ ↝ 𝒩(μ₀,Σ/κ₀) - - If the observations are y₁…yₙ, then the posterior distribution has the same - form with the following parameters: - - κ₀ n - μₙ = ──── μ₀ + ──── ȳ - κ₀+n κ₀+n - - κₙ = κ₀ + n - - νₙ = ν₀ + n - - κ₀·n - Λₙ = Λ₀ + S + ──── (ȳ − μ₀)(ȳ − μ₀)ᵀ - κ₀+n - - where - - 1 ₙ - ȳ = ─ ∑ yᵢ - n ⁱ⁼¹ - - ₙ - S = ∑ (yᵢ − ȳ)(yᵢ − ȳ)ᵀ - ⁱ⁼¹ -*/ - -#ifndef NORMAL_CONJUGATE_H -#define NORMAL_CONJUGATE_H - -#include "twod_matrix.hh" - -/* The class is described by the four parameters: μ, κ, ν and Λ. */ - -class NormalConj -{ -protected: - Vector mu; - int kappa; - int nu; - TwoDMatrix lambda; -public: - /* We provide the following constructors: The first constructs diffuse - (Jeffrey’s) prior. It sets κ and Λ to zeros, ν to −1 and also the mean μ - to zero (it should not be referenced). The second constructs the posterior - using the diffuse prior and the observed data (columnwise). The third is a - copy constructor. */ - NormalConj(int d); - NormalConj(const ConstTwoDMatrix &ydata); - NormalConj(const NormalConj &) = default; - NormalConj(NormalConj &&) = default; - - virtual ~NormalConj() = default; - void update(const ConstVector &y); - void update(const ConstTwoDMatrix &ydata); - void update(const NormalConj &nc); - int - getDim() const - { - return mu.length(); - } - const Vector & - getMean() const - { - return mu; - } - void getVariance(TwoDMatrix &v) const; -}; - -#endif diff --git a/dynare++/kord/seed_generator.cc b/dynare++/kord/seed_generator.cc deleted file mode 100644 index ccc138c516958309f4bf04bea1872afd4a0dfad7..0000000000000000000000000000000000000000 --- a/dynare++/kord/seed_generator.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © 2019 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/>. - */ - -#include "seed_generator.hh" - -#include <limits> -#include <mutex> - -namespace seed_generator -{ - std::mutex mut; - - std::mt19937 rng; - - std::uniform_int_distribution<std::mt19937::result_type> seed_generator(std::numeric_limits<std::mt19937::result_type>::min(), - std::numeric_limits<std::mt19937::result_type>::max()); - - std::mt19937::result_type - get_new_seed() - { - std::lock_guard<std::mutex> lk{mut}; - return seed_generator(rng); - } - - void - set_meta_seed(std::mt19937::result_type s) - { - std::lock_guard<std::mutex> lk{mut}; - rng.seed(s); - } -}; diff --git a/dynare++/parser/cc/Makefile.am b/dynare++/parser/cc/Makefile.am deleted file mode 100644 index 6294c1cf35a39353f37dc17b0b6d15b28c15f517..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -noinst_LIBRARIES = libparser.a - -GENERATED_FILES = assign_tab.cc formula_tab.cc matrix_tab.cc assign_tab.hh formula_tab.hh matrix_tab.hh assign_ll.cc formula_ll.cc matrix_ll.cc - -libparser_a_SOURCES = \ - location.hh \ - atom_assignings.cc \ - atom_assignings.hh \ - atom_substitutions.cc \ - atom_substitutions.hh \ - dynamic_atoms.cc \ - dynamic_atoms.hh \ - fine_atoms.cc \ - fine_atoms.hh \ - formula_parser.cc \ - formula_parser.hh \ - matrix_parser.cc \ - matrix_parser.hh \ - parser_exception.cc \ - parser_exception.hh \ - static_atoms.cc \ - static_atoms.hh \ - static_fine_atoms.cc \ - static_fine_atoms.hh \ - tree.cc \ - tree.hh \ - $(GENERATED_FILES) - -libparser_a_CPPFLAGS = -I../.. $(BOOST_CPPFLAGS) - -BUILT_SOURCES = $(GENERATED_FILES) - -EXTRA_DIST = assign.yy formula.yy matrix.yy assign.ll formula.ll matrix.ll - -%_tab.cc %_tab.hh: %.yy - $(YACC) -W -o$*_tab.cc $< - -%_tab.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast - -%_ll.cc: %.ll - $(LEX) -i -o$@ $< - -%_ll.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast diff --git a/dynare++/parser/cc/assign.ll b/dynare++/parser/cc/assign.ll deleted file mode 100644 index 64d756ffef3727743ec66733c7a251741b919b7e..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/assign.ll +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ -%{ -#include "location.hh" -#include "assign_tab.hh" - -#define YY_USER_ACTION SET_LLOC(asgn_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="asgn_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* spaces */ -[ \t\r\n] {return BLANK;} - - /* names */ -[A-Za-z_][A-Za-z0-9_]* { - asgn_lval.string = asgn_text; - return NAME; -} - -; {return SEMICOLON;} -= {return EQUAL_SIGN;} -. { - asgn_lval.character = asgn_text[0]; - return CHARACTER; -} - -%% - -int -asgn_wrap() -{ - return 1; -} - -void -asgn__destroy_buffer(void* p) -{ - asgn__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/parser/cc/assign.yy b/dynare++/parser/cc/assign.yy deleted file mode 100644 index 167063c609804d358bfa28783644e56b194f4027..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/assign.yy +++ /dev/null @@ -1,76 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -%code requires -{ -#include "location.hh" -#define ASGN_LTYPE ogp::location_type -} - -%code -{ -#include "atom_assignings.hh" -#include <string> - -void asgn_error(std::string); -int asgn_lex(); -extern ogp::AtomAssignings* aparser; -} - -%union -{ - int integer; - char *string; - char character; -} - -%token EQUAL_SIGN SEMICOLON CHARACTER BLANK -%token <string> NAME; - -%define api.prefix {asgn_} - -%locations -%defines -%define parse.error verbose - -%% - -root : assignments | %empty; - -assignments : assignments BLANK | assignments assignment | assignment | BLANK; - -assignment : NAME EQUAL_SIGN material SEMICOLON { - aparser->add_assignment(@1.off, $1, @1.ll, @3.off-@1.off, @3.ll + @4.ll);} - | NAME space EQUAL_SIGN material SEMICOLON { - aparser->add_assignment(@1.off, $1, @1.ll, @4.off-@1.off, @4.ll + @5.ll);} - ; - -material : material CHARACTER | material NAME | material BLANK | NAME | CHARACTER | BLANK; - -space : space BLANK | BLANK; - -%% - -void -asgn_error(std::string mes) -{ - aparser->error(std::move(mes)); -} diff --git a/dynare++/parser/cc/atom_assignings.cc b/dynare++/parser/cc/atom_assignings.cc deleted file mode 100644 index dc4b995501f4e6710a60ca052a3a96738ac4bfc7..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_assignings.cc +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "atom_assignings.hh" -#include "location.hh" -#include "parser_exception.hh" - -#include "utils/cc/exception.hh" - -#include <limits> -#include <iostream> -#include <sstream> -#include <iomanip> - -using namespace ogp; - -AtomAssignings::AtomAssignings(const AtomAssignings &aa, ogp::StaticAtoms &a) - : atoms(a), expr(aa.expr, atoms), left_names(aa.left_names), - lname2expr(aa.lname2expr), order(aa.order) -{ -} - -/** A global symbol for passing info to the AtomAssignings from - * asgn_parse(). */ -AtomAssignings *aparser; - -/** The declaration of functions defined in asgn_ll.cc and asgn_tab.cc - * generated from assign.lex assign.y */ -void *asgn__scan_string(const char *); -void asgn__destroy_buffer(void *); -void asgn_parse(); -extern location_type asgn_lloc; - -void -AtomAssignings::parse(const string &stream) -{ - asgn_lloc.off = 0; - asgn_lloc.ll = 0; - void *p = asgn__scan_string(stream.c_str()); - aparser = this; - asgn_parse(); - asgn__destroy_buffer(p); -} - -void -AtomAssignings::error(string mes) -{ - throw ParserException(std::move(mes), asgn_lloc.off); -} - -void -AtomAssignings::add_assignment_to_double(string name, double val) -{ - // if left hand side is a registered atom, insert it to tree - int t; - try - { - if (atoms.check(name)) - t = expr.add_nulary(name); - else - t = -1; - } - catch (const ParserException &e) - { - t = -1; - } - // register left hand side in order - order.push_back(t); - - // add the double to the tree - std::ostringstream buf; - buf << std::setprecision(std::numeric_limits<double>::max_digits10) - << val; - try - { - expr.parse(buf.str()); - } - catch (const ParserException &e) - { - // should never happen - throw ParserException("Error parsing double "+buf.str()+": "+e.message(), 0); - } - - // register name of the left hand side and put to lname2expr - left_names.insert(name); - lname2expr.emplace(std::move(name), order.size()-1); -} - -void -AtomAssignings::add_assignment(int asgn_off, const string &str, int name_len, - int right_off, int right_len) -{ - // the order of doing things here is important: since the - // FormulaParser requires that all references from the i-th tree - // refere to trees with index lass than i, so to capture also a - // nulary term for the left hand side, it must be inserted to the - // expression tree before the expression is parsed. - - // find the name in the atoms - string name = str.substr(0, name_len); - - // if left hand side is a registered atom, insert it to tree - int t; - try - { - t = atoms.check(name); - if (t == -1) - t = expr.add_nulary(name); - } - catch (const ParserException &e) - { - atoms.register_name(name); - t = expr.add_nulary(name); - } - // register left hand side in order - order.push_back(t); - - // parse expression on the right - try - { - expr.parse(str.substr(right_off, right_len)); - } - catch (const ParserException &e) - { - throw ParserException(e, asgn_off+right_off); - } - - // register name of the left hand side and put to lname2expr - left_names.insert(name); - if (lname2expr.find(name) != lname2expr.end()) - { - // Prevent the occurrence of #415 - std::cerr << "Changing the value of " << name << " through a second assignment (e.g. in initval) is not supported. Aborting." << std::endl; - exit(EXIT_FAILURE); - } - lname2expr[name] = order.size()-1; -} - -void -AtomAssignings::apply_subst(const AtomSubstitutions::Toldnamemap &mm) -{ - // go through all old variables and see what are their derived new - // variables - for (const auto &it : mm) - { - const string &oldname = it.first; - const AtomSubstitutions::Tshiftnameset &sset = it.second; - if (!sset.empty()) - { - int told = atoms.index(oldname); - if (told < 0 && !atoms.get_name_storage().query(oldname)) - atoms.register_name(oldname); - if (told == -1) - told = expr.add_nulary(oldname); - // at least one substitution here, so make an expression - expr.add_formula(told); - // say that this expression is not assigned to any atom - order.push_back(-1); - // now go through all new names derived from the old name and - // reference to the newly added formula - for (const auto &itt : sset) - { - const string &newname = itt.first; - left_names.insert(newname); - lname2expr.emplace(newname, expr.nformulas()-1); - } - } - } -} - -void -AtomAssignings::print() const -{ - std::cout << "Atom Assignings\nExpressions:\n"; - expr.print(); - std::cout << "Left names:\n"; - for (auto it : lname2expr) - std::cout << it.first << " ⇒ " << expr.formula(it.second) << " (t=" << order[it.second] << ")\n"; -} - -void -AtomAsgnEvaluator::setValues(EvalTree &et) const -{ - // set values of constants - aa.atoms.setValues(et); - - // set values of variables to NaN or to user set values - double nan = std::numeric_limits<double>::quiet_NaN(); - for (int i = 0; i < aa.atoms.nvar(); i++) - { - const string &ss = aa.atoms.name(i); - int t = aa.atoms.index(ss); - if (t >= 0) - { - auto it = user_values.find(t); - if (it == user_values.end()) - et.set_nulary(t, nan); - else - et.set_nulary(t, it->second); - } - } -} - -void -AtomAsgnEvaluator::set_user_value(const string &name, double val) -{ - int t = aa.atoms.index(name); - if (t >= 0) - { - auto it = user_values.find(t); - if (it == user_values.end()) - user_values.emplace(t, val); - else - it->second = val; - } -} - -void -AtomAsgnEvaluator::load(int i, double res) -{ - // set the value - operator[](i) = res; - // if i-th expression is atom, set its value to this EvalTree - int t = aa.order[i]; - if (t >= 0) - etree.set_nulary(t, res); -} - -double -AtomAsgnEvaluator::get_value(const string &name) const -{ - auto it = aa.lname2expr.find(name); - if (it == aa.lname2expr.end()) - return std::numeric_limits<double>::quiet_NaN(); - else - return operator[](it->second); -} diff --git a/dynare++/parser/cc/atom_assignings.hh b/dynare++/parser/cc/atom_assignings.hh deleted file mode 100644 index e5a12413544167e298e4ad59546dfd4fd9345692..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_assignings.hh +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_ATOM_ASSIGNINGS_H -#define OGP_ATOM_ASSIGNINGS_H - -#include "static_atoms.hh" -#include "formula_parser.hh" -#include "atom_substitutions.hh" - -#include <vector> -#include <map> - -namespace ogp -{ - class AtomAsgnEvaluator; - - /** This class represents atom assignments used in parameters - * settings and initval initialization. It maintains atoms of the - * all expressions on the right hand side, the parsed formulas of - * the right hand sides, and the information about the left hand - * sides. See documentation to the order member below. */ - class AtomAssignings - { - friend class AtomAsgnEvaluator; - protected: - using Tvarintmap = std::map<string, int>; - /** All atoms which should be sufficient for formulas at the - * right hand sides. The atoms should be filled with names - * (preregistered). This is a responsibility of the caller. */ - StaticAtoms &atoms; - /** The formulas of right hand sides. */ - FormulaParser expr; - /** Name storage of the names from left hand sides. */ - NameStorage left_names; - /** Information on left hand sides. This maps a name to the - * index of its assigned expression in expr. More than one - * name may reference to the same expression. */ - Tvarintmap lname2expr; - /** Information on left hand sides. If order[i] >= 0, then it - * says that i-th expression in expr is assigned to atom with - * order[i] tree index. */ - std::vector<int> order; - public: - /** Construct the object using the provided static atoms. */ - AtomAssignings(StaticAtoms &a) : atoms(a), expr(atoms) - { - } - /** Make a copy with provided reference to (posibly different) - * static atoms. */ - AtomAssignings(const AtomAssignings &aa, StaticAtoms &a); - virtual ~AtomAssignings() = default; - /** Parse the assignments from the given string. */ - void parse(const string &stream); - /** Process a syntax error from bison. */ - void error(string mes); - /** Add an assignment of the given name to the given - * double. Can be called by a user, anytime. */ - void add_assignment_to_double(string name, double val); - /** Add an assignment. Called from assign.y. */ - void add_assignment(int asgn_off, const string &str, int name_len, - int right_off, int right_len); - /** This applies old2new map (possibly from atom - * substitutions) to this object. It registers new variables - * in the atoms, and adds the expressions to expr, and left - * names to lname2expr. The information about dynamical part - * of substitutions is ignored, since we are now in the static - * world. */ - void apply_subst(const AtomSubstitutions::Toldnamemap &mm); - /** Debug print. */ - void print() const; - }; - - /** This class basically evaluates the atom assignments - * AtomAssignings, so it inherits from ogp::FormulaEvaluator. It - * is also a storage for the results of the evaluation stored as a - * vector, so the class inherits from std::vector<double> and - * ogp::FormulaEvalLoader. As the expressions for atoms are - * evaluated, the results are values for atoms which will be - * used in subsequent evaluations. For this reason, the class - * inherits also from AtomValues. */ - class AtomAsgnEvaluator : public FormulaEvalLoader, - public AtomValues, - protected FormulaEvaluator, - public std::vector<double> - { - protected: - using Tusrvalmap = std::map<int, double>; - Tusrvalmap user_values; - const AtomAssignings &aa; - public: - AtomAsgnEvaluator(const AtomAssignings &a) - : FormulaEvaluator(a.expr), - std::vector<double>(a.expr.nformulas()), aa(a) - { - } - ~AtomAsgnEvaluator() override = default; - /** This sets all initial values to NaNs, all constants and - * all values set by user by call set_value. This is called by - * FormulaEvaluator::eval() method, which is called by eval() - * method passing this argument as AtomValues. So the - * ogp::EvalTree will be always this->etree. */ - void setValues(EvalTree &et) const override; - /** User setting of the values. For example in initval, - * parameters are known and should be set to their values. In - * constrast endogenous variables are set initially to NaNs by - * AtomValues::setValues. */ - void set_user_value(const string &name, double val); - /** This sets the result of i-th expression in aa to res, and - * also checks whether the i-th expression is an atom. If so, - * it sets the value of the atom in ogp::EvalTree - * this->etree. */ - void load(int i, double res) override; - /** After the user values have been set, the assignments can - * be evaluated. For this purpose we have eval() method. The - * result is that this object as std::vector<double> will - * contain the values. It is ordered given by formulas in - * expr. */ - void - eval() - { - FormulaEvaluator::eval(*this, *this); - } - /** This returns a value for a given name. If the name is not - * found among atoms, or there is no assignment for the atom, - * NaN is returned. */ - double get_value(const string &name) const; - }; -}; - -#endif diff --git a/dynare++/parser/cc/atom_substitutions.cc b/dynare++/parser/cc/atom_substitutions.cc deleted file mode 100644 index 83d4f42ce637dd8f44e60953d3340088017617a5..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_substitutions.cc +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "atom_substitutions.hh" -#include "utils/cc/exception.hh" - -using namespace ogp; - -AtomSubstitutions::AtomSubstitutions(const AtomSubstitutions &as, const FineAtoms &oa, - FineAtoms &na) - : new2old(as.new2old), old2new(as.old2new), old_atoms(oa), new_atoms(na) -{ -} - -void -AtomSubstitutions::add_substitution(string newname, string oldname, int tshift) -{ - // insert to new2old map - new2old.emplace(newname, Tshiftname(oldname, tshift)); - // insert to old2new map - auto it = old2new.find(oldname); - if (it != old2new.end()) - it->second.emplace(std::move(newname), -tshift); - else - { - Tshiftnameset snset; - snset.emplace(std::move(newname), -tshift); - old2new.emplace(std::move(oldname), snset); - } - - // put to info - info.num_substs++; -} - -void -AtomSubstitutions::substitutions_finished(VarOrdering::ord_type ot) -{ - // create an external ordering of new_atoms from old_atoms - const vector<string> &oa_ext = old_atoms.get_allvar(); - vector<string> na_ext; - for (const auto &oname : oa_ext) - { - // add the old name itself - na_ext.push_back(oname); - // add all new names derived from the old name - auto it = old2new.find(oname); - if (it != old2new.end()) - for (const auto &itt : it->second) - na_ext.push_back(itt.first); - } - - // call parsing finished for the new_atoms - new_atoms.parsing_finished(ot, na_ext); -} - -string -AtomSubstitutions::get_new4old(const string &oldname, int tshift) const -{ - auto it = old2new.find(oldname); - if (it != old2new.end()) - { - const Tshiftnameset &sset = it->second; - for (const auto &itt : sset) - if (itt.second == -tshift) - return itt.first; - } - return ""; -} - -void -AtomSubstitutions::print() const -{ - std::cout << "Atom Substitutions:\nOld ⇒ New:\n"; - for (const auto &it : old2new) - for (const auto &itt : it.second) - std::cout << " " << it.first << " ⇒ [" << itt.first << ", " << itt.second << "]\n"; - - std::cout << "Old ⇐ New:\n"; - for (const auto &it : new2old) - std::cout << " [" << it.second.first << ", " << it.second.second << "] ⇐ " << it.first << '\n'; -} - -void -SAtoms::substituteAllLagsAndLeads(FormulaParser &fp, AtomSubstitutions &as) -{ - string name; - - int mlead, mlag; - endovarspan(mlead, mlag); - - // substitute all endo lagged more than 1 - while (!(name = findEndoWithLeadInInterval(mlag, -2)).empty()) - makeAuxVariables(name, -1, -2, mlag, fp, as); - // substitute all endo leaded more than 1 - while (!(name = findEndoWithLeadInInterval(2, mlead)).empty()) - makeAuxVariables(name, 1, 2, mlead, fp, as); - - exovarspan(mlead, mlag); - - // substitute all lagged exo - while (!(name = findExoWithLeadInInterval(mlag, -1)).empty()) - makeAuxVariables(name, -1, -1, mlag, fp, as); - // substitute all leaded exo - while (!(name = findExoWithLeadInInterval(1, mlead)).empty()) - makeAuxVariables(name, 1, 1, mlead, fp, as); - - // notify that substitution have been finished - as.substitutions_finished(order_type); -} - -void -SAtoms::substituteAllLagsAndExo1Leads(FormulaParser &fp, AtomSubstitutions &as) -{ - string name; - - int mlead, mlag; - endovarspan(mlead, mlag); - - // substitute all endo lagged more than 1 - while (!(name = findEndoWithLeadInInterval(mlag, -2)).empty()) - makeAuxVariables(name, -1, -2, mlag, fp, as); - - exovarspan(mlead, mlag); - - // substitute all lagged exo - while (!(name = findExoWithLeadInInterval(mlag, -1)).empty()) - makeAuxVariables(name, -1, -1, mlag, fp, as); - // substitute all leaded exo by 1 - while (!(name = findExoWithLeadInInterval(1, 1)).empty()) - makeAuxVariables(name, 1, 1, 1, fp, as); - - // notify that substitution have been finished - as.substitutions_finished(order_type); -} - -string -SAtoms::findNameWithLeadInInterval(const vector<string> &names, - int ll1, int ll2) const -{ - for (auto name : names) - { - auto it = vars.find(name); - if (it != vars.end()) - { - const DynamicAtoms::Tlagmap &lmap = it->second; - for (auto itt : lmap) - if (itt.first >= ll1 && itt.first <= ll2) - return name; - } - } - - // nothing found - return ""; -} - -void -SAtoms::attemptAuxName(const string &str, int ll, string &out) const -{ - char c = (ll >= 0) ? ((ll == 0) ? 'e' : 'p') : 'm'; - string absll = std::to_string(std::abs(ll)); - int iter = 1; - do - { - out = str + '_'; - for (int i = 0; i < iter; i++) - out += c; - if (ll != 0) - out += absll; - iter++; - } - while (varnames.query(out)); -} - -void -SAtoms::makeAuxVariables(const string &name, int step, int start, int limit_lead, - FormulaParser &fp, AtomSubstitutions &as) -{ - if (!(step == 1 || step == -1)) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong value of step in SAtoms::makeAuxVariables"); - if (step*start > step*limit_lead) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong value of start in SAtoms::makeAuxVariables"); - - // make sure that we do not go further than necessary, this is - // that the limit lead is not behind maxlead or minlag - int mlead, mlag; - varspan(name, mlead, mlag); - if (step == -1) - limit_lead = std::max(limit_lead, mlag); - else - limit_lead = std::min(limit_lead, mlead); - - // Comment to comments: name="a"; start=-3; step=-1; - - // recover tree index of a previous atom, i.e. set tprev to a tree - // index of atom "a(-2)" - int tprev = index(name, start-step); - if (tprev == -1) - tprev = fp.add_nulary(name + '(' + std::to_string(start-step) + ')'); - - int ll = start; - do - { - // either create atom "a_m2(0)" with tree index taux and add - // equation "a_m2(0)=a(-2)" - // or - // check if "a_m2(0)" has not been already created (with - // different step), in this case do not add equation "a_m2(0) - // = a(-2)" - string newname, newname_str; - int taux; - if ((newname = as.get_new4old(name, ll-step)).empty()) - { - attemptAuxName(name, ll-step, newname_str); - newname = newname_str; - register_uniq_endo(newname); - taux = fp.add_nulary(newname + "(0)"); - // add to substitutions - as.add_substitution(newname, name, ll-step); - - // add equation "a_m2(0) = a(-2)", this is taux = tprev - fp.add_formula(fp.add_binary(code_t::MINUS, taux, tprev)); - } - else - { - // example: exogenous EPS and occurrence at both EPS(-1) - // EPS(+1) - // first call makeAuxVariables("EPS",1,1,...) will make endo EPS_p0 = EPS - // second call makeAuxVariables("EPS",-1,-1,...) will use this EPS_p0 - // to substitute for EPS(-1) - taux = index(newname, 0); - if (taux < 0) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find tree index of previously substituted variable"); - } - - // create atom "a_m2(-1)" or turn "a(-3)" if any to "a_m2(-1)"; tree index t - int t = index(name, ll); - if (t == -1) - { - // no "a(-3)", make t <-> a_m2(-1) - t = fp.add_nulary(newname + '(' + std::to_string(step) + ')'); - } - else - { - // turn a(-3) to a_m2(-1) - unassign_variable(name, ll, t); - assign_variable(newname, step, t); - } - - // next iteration starts with tprev <-> "a_m2(-1)" (this will be made equal to "a_m3(0)") - tprev = t; - - ll += step; - } - while (step*ll <= step*limit_lead); -} diff --git a/dynare++/parser/cc/atom_substitutions.hh b/dynare++/parser/cc/atom_substitutions.hh deleted file mode 100644 index 3fbf3e80a40a3951b41cadf7f3542b6e0c3f9c6c..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_substitutions.hh +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_ATOM_SUBSTITUTIONS_H -#define OGP_ATOM_SUBSTITUTIONS_H - -#include "fine_atoms.hh" - -#include <string> - -namespace ogp -{ - - using std::string; - using std::map; - using std::pair; - - /** This class tracts an information about the performed - * substitutions. In fact, there is only one number to keep track - * about, this is a number of substitutions. */ - struct SubstInfo - { - int num_substs{0}; - SubstInfo() = default; - }; - - /** This class tracks all atom substitutions during the job and - * then builds structures when all substitutions are finished. */ - class AtomSubstitutions - { - public: - using Tshiftname = pair<string, int>; - using Tshiftmap = map<string, Tshiftname>; - using Tshiftnameset = set<Tshiftname>; - using Toldnamemap = map<string, Tshiftnameset>; - protected: - /** This maps a new name to a shifted old name. This is, one - * entry looks as "a_m3 ==> a(-3)", saying that a variable - * "a_m3" corresponds to a variable "a" lagged by 3. */ - Tshiftmap new2old; - /** This is inverse to new2old, which is not unique. For old - * name, say "a", it says what new names are derived with what - * shifts from the "a". For example, it can map "a" to a two - * element set {["a_m3", +3], ["a_p2", -2]}. This says that - * leading "a_m3" by 3 one gets old "a" and lagging "a_p2" by - * 2 one gets also old "a". */ - Toldnamemap old2new; - /** This is a reference to old atoms with multiple leads and - * lags. They are supposed to be used with parsing finished - * being had called, so that the external ordering is - * available. */ - const FineAtoms &old_atoms; - /** This is a reference to new atoms. All name pointers point - * to storage of these atoms. */ - FineAtoms &new_atoms; - /** Substitutions information. */ - SubstInfo info; - public: - /** Create the object with reference to the old and new - * atoms. In the beginning, old atoms are supposed to be with - * parsing_finished() called, and new atoms a simple copy of - * old atoms. The new atoms will be an instance of SAtoms. All - * substitution job is done by a substitution method of the - * new atoms. */ - AtomSubstitutions(const FineAtoms &oa, FineAtoms &na) - : old_atoms(oa), new_atoms(na) - { - } - /** Construct a copy of the object using a different instances - * of old atoms and new atoms, which are supposed to be - * semantically same as the atoms from as. */ - AtomSubstitutions(const AtomSubstitutions &as, const FineAtoms &oa, FineAtoms &na); - virtual ~AtomSubstitutions() = default; - /** This is called during the substitution job from the - * substitution method of the new atoms. This says that the - * new name, say "a_m3" is a substitution of old name "a" - * shifted by -3. */ - void add_substitution(string newname, string oldname, int tshift); - /** This is called when all substitutions are finished. This - * forms the new external ordering of the new atoms and calls - * parsing_finished() for the new atoms with the given ordering type. */ - void substitutions_finished(VarOrdering::ord_type ot); - /** Returns a new name for old name and given tshift. For "a" - * and tshift=-3, it returns "a_m3". If there is no such - * substitution, it returns an empty string. */ - string get_new4old(const string &oldname, int tshift) const; - /** Return new2old. */ - const Tshiftmap & - get_new2old() const - { - return new2old; - } - /** Return old2new. */ - const Toldnamemap & - get_old2new() const - { - return old2new; - } - /** Return substitution info. */ - const SubstInfo & - get_info() const - { - return info; - } - /** Return old atoms. */ - const FineAtoms & - get_old_atoms() const - { - return old_atoms; - } - /** Return new atoms. */ - const FineAtoms & - get_new_atoms() const - { - return new_atoms; - } - /** Debug print. */ - void print() const; - }; - - class SAtoms : public FineAtoms - { - public: - SAtoms() - : FineAtoms() - { - } - SAtoms(const SAtoms &sa) = default; - /** This substitutes all lags and leads for all exogenous and - * all lags and leads greater than 1 for all endogenous - * variables. This is useful for perfect foresight problems - * where we can do that. */ - void substituteAllLagsAndLeads(FormulaParser &fp, AtomSubstitutions &as); - /** This substitutes all lags of all endo and exo and one step - * leads of all exo variables. This is useful for stochastic - * models where we cannot solve leads more than 1. */ - void substituteAllLagsAndExo1Leads(FormulaParser &fp, AtomSubstitutions &as); - protected: - /** This finds an endogenous variable name which occurs between - * ll1 and ll2 included. */ - string - findEndoWithLeadInInterval(int ll1, int ll2) const - { - return findNameWithLeadInInterval(get_endovars(), ll1, ll2); - } - /** This finds an exogenous variable name which occurs between - * ll1 and ll2 included. */ - string - findExoWithLeadInInterval(int ll1, int ll2) const - { - return findNameWithLeadInInterval(get_exovars(), ll1, ll2); - } - - /** This attempts to find a non registered name of the form - * <str>_m<abs(ll)> or <str>_p<abs(ll)>. A letter 'p' is - * chosen if ll is positive, 'm' if negative. If a name of - * such form is already registered, one more character (either - * 'p' or 'm') is added and the test is performed again. The - * resulting name is returned in a string out. */ - void attemptAuxName(const string &str, int ll, string &out) const; - - /** This makes auxiliary variables to eliminate all leads/lags - * greater/less than or equal to start up to the limit_lead - * for a variable with the given name. If the limit_lead is - * greater/less than the maxlead/minlag of the variable, than - * maxlead/minlag is used. This process is recorded in - * AtomSubstitutions. The new auxiliary variables and their - * atoms are created in this object. The auxiliary equations - * are created in the given FormulaParser. The value of step - * is allowed to be either -1 (lags) or +1 (leads). */ - void makeAuxVariables(const string &name, int step, int start, int limit_lead, - FormulaParser &fp, AtomSubstitutions &as); - private: - /** This is a worker routine for findEndoWithLeadInInterval - * and findExoWithLeadInInterval. */ - string findNameWithLeadInInterval(const vector<string> &names, - int ll1, int ll2) const; - - }; - -}; - -#endif diff --git a/dynare++/parser/cc/dynamic_atoms.cc b/dynare++/parser/cc/dynamic_atoms.cc deleted file mode 100644 index 580ec70d00bf5ce12e4d53b2f2740f9c99674942..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/dynamic_atoms.cc +++ /dev/null @@ -1,617 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "utils/cc/exception.hh" -#include "dynamic_atoms.hh" - -using namespace ogp; - -void -NameStorage::insert(string name) -{ - if (!query(name)) - { - name_store.push_back(name); - name_set.insert(std::move(name)); - } -} - -void -NameStorage::print() const -{ - for (auto i : name_store) - std::cout << i << '\n'; -} - -void -Constants::import_constants(const Constants &c, OperationTree &otree, Tintintmap &tmap) -{ - for (auto it : c.cmap) - { - int told = it.first; - int tnew = otree.add_nulary(); - tmap.emplace(told, tnew); - add_constant(tnew, it.second); - } -} - -void -Constants::setValues(EvalTree &et) const -{ - for (const auto &it : cmap) - et.set_nulary(it.first, it.second); -} - -void -Constants::add_constant(int t, double val) -{ - cmap.emplace(t, val); - cinvmap.emplace(val, t); -} - -bool -Constants::is_constant(int t) const -{ - if (t < OperationTree::num_constants) - return true; - auto it = cmap.find(t); - return (it != cmap.end()); -} - -double -Constants::get_constant_value(int t) const -{ - auto it = cmap.find(t); - if (it != cmap.end()) - return it->second; - else - throw ogu::Exception(__FILE__, __LINE__, - "Tree index is not constant in Constants::get_constant_value"); -} - -int -Constants::check(const string &str) const -{ - double d = std::stod(str); - auto it = cinvmap.find(d); - if (it != cinvmap.end()) - return it->second; - else - return -1; -} - -void -Constants::print() const -{ - for (const auto &it : cmap) - std::cout << "$" << it.first << ": " << it.second << "\n"; -} - -int -DynamicAtoms::check(const string &name) const -{ - if (is_string_constant(name)) - return Constants::check(name); - - return check_variable(name); -} - -int -DynamicAtoms::check_variable(const string &name) const -{ - string str; - int ll; - parse_variable(name, str, ll); - auto it = vars.find(str); - - if (it != vars.end()) - { - const Tlagmap &lmap = it->second; - auto itt = lmap.find(ll); - if (itt != lmap.end()) - return itt->second; - } - return -1; -} - -void -DynamicAtoms::assign(const string &name, int t) -{ - if (is_string_constant(name)) - assign_constant(name, t); - else - assign_variable(name, t); -} - -void -DynamicAtoms::assign_constant(const string &name, int t) -{ - double val = std::stod(name); - add_constant(t, val); -} - -// parse the name and then call assing_variable(varname, ll, t) - -void -DynamicAtoms::assign_variable(const string &name, int t) -{ - int ll; - string str; - parse_variable(name, str, ll); - // here str is just name without lead/lag - varnames.insert(str); - - assign_variable(str, ll, t); -} - -void -DynamicAtoms::assign_variable(const string &varname, int ll, int t) -{ - if (indices.end() != indices.find(t)) - throw ogu::Exception(__FILE__, __LINE__, - "Attempt to assign already allocated tree index"); - - auto it = vars.find(varname); - if (it != vars.end()) - { - Tlagmap &lmap = it->second; - if (lmap.end() != lmap.find(ll)) - throw ogu::Exception(__FILE__, __LINE__, - "Attempt to assign already allocated variable"); - lmap.emplace(ll, t); - } - else - { - Tlagmap lmap; - lmap.emplace(ll, t); - vars.emplace(varname, lmap); - } - indices.emplace(t, varname); - - nv++; - minlag = std::min(ll, minlag); - maxlead = std::max(ll, maxlead); -} - -void -DynamicAtoms::unassign_variable(const string &varname, int ll, int t) -{ - auto it = vars.find(varname); - if (it != vars.end()) - { - Tlagmap &lmap = it->second; - auto itt = lmap.find(ll); - if (itt != lmap.end()) - { - if (itt->second == t) - { - // erase it from the lagmap; if it becomes empty, - // erase the lagmap from varmap - lmap.erase(itt); - if (lmap.size() == 0) - vars.erase(it); - // erase it from the indices - auto ittt = indices.find(t); - if (ittt != indices.end()) - indices.erase(ittt); - - nv--; - if (ll == minlag || ll == maxlead) - update_minmaxll(); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "Tree index inconsistent in DynamicAtoms::unassign_variable"); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "Lead/lag of the variable not found in DynamicAtoms::unassign_variable"); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "Variable not found in DynamicAtoms::unassign_variable"); -} - -void -DynamicAtoms::update_minmaxll() -{ - minlag = std::numeric_limits<int>::max(); - maxlead = std::numeric_limits<int>::min(); - for (const auto &it : vars) - { - const Tlagmap &lmap = it.second; - for (auto itt : lmap) - { - int ll = itt.first; - minlag = std::min(ll, minlag); - maxlead = std::max(ll, maxlead); - } - } -} - -vector<int> -DynamicAtoms::variables() const -{ - vector<int> res; - for (const auto &var : vars) - { - const Tlagmap &lmap = var.second; - for (auto itt : lmap) - res.push_back(itt.second); - } - return res; -} - -void -DynamicAtoms::varspan(int t, int &mlead, int &mlag) const -{ - auto it = indices.find(t); - if (indices.end() == it) - { - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - return; - } - varspan(it->second, mlead, mlag); -} - -void -DynamicAtoms::varspan(const string &name, int &mlead, int &mlag) const -{ - auto it = vars.find(name); - if (vars.end() == it) - { - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - return; - } - const Tlagmap &lmap = it->second; - auto beg = lmap.begin(); - auto end = lmap.rbegin(); - mlag = beg->first; - mlead = end->first; -} - -void -DynamicAtoms::varspan(const vector<string> &names, int &mlead, int &mlag) const -{ - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - for (const auto &name : names) - { - int lag, lead; - varspan(name, lead, lag); - mlead = std::max(lead, mlead); - mlag = std::min(lag, mlag); - } -} - -bool -DynamicAtoms::is_named_atom(int t) const -{ - return indices.end() != indices.find(t); -} - -int -DynamicAtoms::index(const string &name, int ll) const -{ - auto it = vars.find(name); - if (vars.end() != it) - { - const Tlagmap &lmap = it->second; - auto itt = lmap.find(ll); - if (lmap.end() != itt) - return itt->second; - } - return -1; -} - -bool -DynamicAtoms::is_referenced(const string &name) const -{ - return vars.find(name) != vars.end(); -} - -const DynamicAtoms::Tlagmap & -DynamicAtoms::lagmap(const string &name) const -{ - auto it = vars.find(name); - if (vars.end() == it) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find the name " - + name + " in DynamicAtoms::lagmap"); - return it->second; -} - -const string & -DynamicAtoms::name(int t) const -{ - auto it = indices.find(t); - if (indices.end() == it) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find tree index in DynamicAtoms::name"); - return it->second; -} - -int -DynamicAtoms::lead(int t) const -{ - const string &nam = name(t); - const Tlagmap &lmap = lagmap(nam); - auto it = lmap.begin(); - while (it != lmap.end() && it->second != t) - ++it; - if (lmap.end() == it) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find the three index in DynamicAtoms::lead"); - return it->first; -} - -void -DynamicAtoms::print() const -{ - std::cout << "names:\n"; - varnames.print(); - std::cout << "constants:\n"; - Constants::print(); - std::cout << "variables:\n"; - for (const auto &var : vars) - { - const Tlagmap &lmap = var.second; - for (auto itt : lmap) - std::cout << "$" << itt.second << ": " << var.first << "(" << itt.first << ")\n"; - } - std::cout << "indices:\n"; - for (auto indice : indices) - std::cout << "t=" << indice.first << " ⇒ " << indice.second << "\n"; -} - -/** Note that the str has been parsed by the lexicographic - * analyzer. It can be either a variable or a double. So it is easy to - * recognize it by the first character. */ -bool -DynamicAtoms::is_string_constant(const string &str) -{ - return str[0] == '.' || str[0] == '-' || (str[0] >= '0' && str[0] <= '9'); -} - -VarOrdering::VarOrdering(const VarOrdering &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : n_stat(vo.n_stat), n_pred(vo.n_pred), n_both(vo.n_both), n_forw(vo.n_forw), - der_atoms(vo.der_atoms), positions(vo.positions), - outer2y(vo.outer2y), y2outer(vo.y2outer), varnames(vnames), atoms(a) -{ -} - -bool -VarOrdering::check(int t) const -{ - return positions.find(t) != positions.end(); -} - -int -VarOrdering::get_pos_of(int t) const -{ - auto it = positions.find(t); - if (it != positions.end()) - return it->second; - else - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find the tree index in VarOrdering::get_pos_of"); -} - -void -VarOrdering::do_general(ord_type ordering) -{ - // auxiliary vectors for setting der_atoms and map - vector<int> pred_minus; - vector<int> both_minus; - vector<int> stat; - vector<int> pred_pad; - vector<int> both_pad; - vector<int> forw_pad; - vector<int> both_plus; - vector<int> forw_plus; - - // auxiliary vectors for setting y2outer and outer2y - vector<int> y2o_stat; - vector<int> y2o_pred; - vector<int> y2o_both; - vector<int> y2o_forw; - - for (unsigned int i = 0; i < varnames.size(); i++) - { - const string &ss = varnames[i]; - int lead; - int lag; - atoms.varspan(ss, lead, lag); - if (lag == 0 && lead == 0) - { - stat.push_back(atoms.index(ss, 0)); - y2o_stat.push_back(i); - } - else if (lag == -1 && lead < 1) - { - pred_minus.push_back(atoms.index(ss, -1)); - pred_pad.push_back(atoms.index(ss, 0)); - y2o_pred.push_back(i); - } - else if (lag > -1 && lead == 1) - { - forw_pad.push_back(atoms.index(ss, 0)); - forw_plus.push_back(atoms.index(ss, 1)); - y2o_forw.push_back(i); - } - else if (lag == -1 && lead == 1) - { - both_minus.push_back(atoms.index(ss, -1)); - both_pad.push_back(atoms.index(ss, 0)); - both_plus.push_back(atoms.index(ss, 1)); - y2o_both.push_back(i); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "A wrong lag/lead of a variable in VarOrdering::do_pbspbfbf"); - } - - // here we fill ords according to ordering - vector<int> *ords[8]; - if (ordering == pbspbfbf) - { - ords[0] = &pred_minus; - ords[1] = &both_minus; - ords[2] = &stat; - ords[3] = &pred_pad; - ords[4] = &both_pad; - ords[5] = &forw_pad; - ords[6] = &both_plus; - ords[7] = &forw_plus; - } - else if (ordering == bfspbfpb) - { - ords[0] = &both_plus; - ords[1] = &forw_plus; - ords[2] = &stat; - ords[3] = &pred_pad; - ords[4] = &both_pad; - ords[5] = &forw_pad; - ords[6] = &pred_minus; - ords[7] = &both_minus; - } - else // BEWARE: when implementing a new ordering, check also the code below setting y2outer - throw ogu::Exception(__FILE__, __LINE__, - "Ordering not implemented in VarOrdering::do_general"); - - // make der_atoms and positions - int off = 0; - for (auto &ord : ords) - for (unsigned int j = 0; j < ord->size(); j++, off++) - if ((*ord)[j] != -1) - { - der_atoms.push_back((*ord)[j]); - positions.emplace((*ord)[j], off); - } - - // set integer constants - n_stat = stat.size(); - n_pred = pred_pad.size(); - n_both = both_pad.size(); - n_forw = forw_pad.size(); - - // make y2outer mapping - y2outer.insert(y2outer.end(), y2o_stat.begin(), y2o_stat.end()); - y2outer.insert(y2outer.end(), y2o_pred.begin(), y2o_pred.end()); - y2outer.insert(y2outer.end(), y2o_both.begin(), y2o_both.end()); - y2outer.insert(y2outer.end(), y2o_forw.begin(), y2o_forw.end()); - // make outer2y mapping - outer2y.resize(y2outer.size(), -1); - for (unsigned int i = 0; i < y2outer.size(); i++) - outer2y[y2outer[i]] = i; -} - -void -VarOrdering::do_increasing_time() -{ - // get maxlead and minlag of the variables - int mlag, mlead; - atoms.varspan(varnames, mlead, mlag); - // setup the matrix of tree indices, if there is no occurrence, - // the index is set to -1 - vector<int> ll_init(varnames.size(), -1); - vector<vector<int>> tree_ind(mlead-mlag+1, ll_init); - for (unsigned int iv = 0; iv < varnames.size(); iv++) - { - try - { - const DynamicAtoms::Tlagmap &lmap = atoms.lagmap(varnames[iv]); - for (auto it : lmap) - { - int ll = it.first; - int t = it.second; - tree_ind[ll-mlag][iv] = t; - } - } - catch (const ogu::Exception &e) - { - // ignore the error of not found variable in the tree - } - } - - // setup der_atoms and positions - for (int ll = mlag; ll <= mlead; ll++) - for (unsigned int iv = 0; iv < varnames.size(); iv++) - { - int t = tree_ind[ll-mlag][iv]; - if (t != -1) - { - der_atoms.push_back(t); - int pos = (ll-mlag)*varnames.size() + iv; - positions.emplace(t, pos); - } - } - - // set outer2y and y2outer to identities - for (unsigned int iv = 0; iv < varnames.size(); iv++) - { - outer2y.push_back(iv); - y2outer.push_back(iv); - } - - // set n_stat, n_pred, n_both, and n_forw - for (auto varname : varnames) - { - int mmlag, mmlead; - atoms.varspan(varname, mmlead, mmlag); - if (mmlead == 0 && mmlag == 0) - n_stat++; - else if (mmlead <= 0 && mmlag < 0) - n_pred++; - else if (mmlead > 0 && mmlag >= 0) - n_forw++; - else if (mmlead > 0 && mmlag < 0) - n_both++; - else if (mmlead < mmlag) - // variable does not occur in the tree, cound as static - n_stat++; - else - throw ogu::Exception(__FILE__, __LINE__, - "A wrong lag/lead of a variable in VarOrdering::do_increasing_time"); - } -} - -void -VarOrdering::print() const -{ - std::cout << "nstat=" << n_stat << ", npred=" << n_pred << ", nboth=" << n_both - << ", nforw=" << n_forw << "\n" - << "der_atoms:\n"; - for (int der_atom : der_atoms) - std::cout << " " << der_atom; - std::cout << "\nmap:\n"; - for (auto position : positions) - std::cout << " [" << position.first << "→" << position.second << "]"; - std::cout << "\ny2outer:\n"; - for (int i : y2outer) - std::cout << " " << i; - std::cout << "\nouter2y:\n"; - for (int i : outer2y) - std::cout << " " << i; - std::cout << "\n"; -} diff --git a/dynare++/parser/cc/dynamic_atoms.hh b/dynare++/parser/cc/dynamic_atoms.hh deleted file mode 100644 index f0f1bfaefe4d7ca714c71126bc9059f5dffdeb39..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/dynamic_atoms.hh +++ /dev/null @@ -1,470 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_DYNAMIC_ATOMS_H -#define OGP_DYNAMIC_ATOMS_H - -#include "formula_parser.hh" - -#include <vector> -#include <map> -#include <set> -#include <string> -#include <limits> -#include <memory> - -namespace ogp -{ - using std::vector; - using std::map; - using std::set; - using std::string; - - /** Class storing names. We will keep names of variables in - * various places, and all these pointers will point to one - * storage, which will be responsible for allocation and - * deallocation. The main function of the class is to allocate - * space for names, and return a pointer of the stored name if - * required. */ - class NameStorage - { - protected: - /** Vector of names allocated, this is the storage. */ - vector<string> name_store; - /** Map useful to quickly decide if the name is already - * allocated or not. */ - set<string> name_set; - public: - /** Query for the name. If the name has been stored, it - * true, otherwise false. */ - bool - query(const string &name) const - { - return name_set.find(name) != name_set.end(); - } - /** Insert the name if it has not been inserted yet. */ - void insert(string name); - int - num() const - { - return static_cast<int>(name_store.size()); - } - const string & - get_name(int i) const - { - return name_store[i]; - } - /** Debug print. */ - void print() const; - }; - - class Constants : public AtomValues - { - public: - /** Type for a map mapping tree indices to double values. */ - using Tconstantmap = map<int, double>; - using Tintintmap = map<int, int>; - protected: - /** Map mapping a tree index of a constant to its double value. */ - Tconstantmap cmap; - public: - Constants() = default; - /** Copy constructor. */ - Constants(const Constants &c) - : cmap(c.cmap), cinvmap(c.cinvmap) - { - } - /** Copy constructor registering the constants in the given - * tree. The mapping from old tree indices to new ones is - * traced in tmap. */ - Constants(const Constants &c, OperationTree &otree, Tintintmap &tmap) - { - import_constants(c, otree, tmap); - } - /** Import constants registering their tree indices in the - * given tree. The mapping form old tree indices to new ones - * is traced in tmap. */ - void import_constants(const Constants &c, OperationTree &otree, Tintintmap &tmap); - /** Implements AtomValues interface. This sets the values to - * the evaluation tree EvalTree. */ - void setValues(EvalTree &et) const override; - /** This adds a constant with the given tree index. The - * constant must be checked previously and asserted that it - * does not exist. */ - void add_constant(int t, double val); - /** Returns true if the tree index is either an hardwired - * constant (initial number OperationTree:num_constants in - * OperationTree) or the tree index is a registered constant - * by add_constant method. */ - bool is_constant(int t) const; - double get_constant_value(int t) const; - /** Return -1 if the given string representation of a constant - * is not among the constants (double represenations). If it - * is, its tree index is returned. */ - int check(const string &str) const; - /** Debug print. */ - void print() const; - const Tconstantmap & - get_constantmap() const - { - return cmap; - } - private: - /** Inverse map to Tconstantmap. */ - using Tconstantinvmap = map<double, int>; - /** This is an inverse map to cmap. This is only used for fast - * queries for the existing double constants in check - * method and add_constant. */ - Tconstantinvmap cinvmap; - }; - - /** This class is a parent to Atoms classes which distinguish between - * constants (numerical literals), and variables with lags and - * leads. This abstraction does not distinguish between a parameter - * and a variable without lag or lead. In this sense, everything is a - * variable.*/ - class DynamicAtoms : public Atoms, public Constants - { - public: - /** Definition of a type mapping lags to the indices of the variables. */ - using Tlagmap = map<int, int>; - protected: - /** Definition of a type mapping names of the atoms to Tlagmap. */ - using Tvarmap = map<string, Tlagmap>; - /** Definition of a type mapping indices of variables to the variable names. */ - using Tindexmap = map<int, string>; - /** This is just a storage for variable names, since all other - * instances of a variable name just point to the memory - * allocated by this object. */ - NameStorage varnames; - /** This is the map for variables. Each variable name is - * mapped to the Tlagmap, which maps lags/leads to the nulary - * term indices in the tree. */ - Tvarmap vars; - /** This is almost inverse map to the vars. It maps variable - * indices to the names. A returned name can be in turn used - * as a key in vars. */ - Tindexmap indices; - - /** Number of variables. */ - int nv{0}; - /** Minimum lag, if there is at least one lag, than this is a negative number. */ - int minlag{std::numeric_limits<int>::max()}; - /** Maximum lead, if there is at least one lead, than this is a positive number. */ - int maxlead{std::numeric_limits<int>::min()}; - public: - /** Construct empty DynamicAtoms. */ - DynamicAtoms() = default; - /** Check the nulary term identified by its string - * representation. The nulary term can be either a constant or - * a variable. If constant, -1 is returned so that it could be - * assigned regardless if the same constant has already - * appeared or not. If variable, then -1 is returned only if - * the variable has not been assigned an index, otherwise the - * assigned index is returned. */ - int check(const string &name) const override; - /** Assign the nulary term identified by its string - * representation. This method should be called when check() - * returns -1. */ - void assign(const string &name, int t) override; - /** Return a number of all variables. */ - int - nvar() const override - { - return nv; - } - /** Return the vector of variable indices. */ - vector<int> variables() const override; - /** Return max lead and min lag for a variable given by the - * index. If a variable cannot be found, the method retursn - * the smallest integer as maxlead and the largest integer as - * minlag. */ - void varspan(int t, int &mlead, int &mlag) const; - /** Return max lead and min lag for a variable given by the - * name (without lead, lag). The same is valid if the variable - * name cannot be found. */ - void varspan(const string &name, int &mlead, int &mlag) const; - /** Return max lead and min lag for a vector of variables given by the names. */ - void varspan(const vector<string> &names, int &mlead, int &mlag) const; - /** Return true for all tree indices corresponding to a - * variable in the sense of this class. (This is parameters, - * exo and endo). Since the semantics of 'variable' will be - * changed in subclasses, we use name 'named atom'. These are - * all atoms but constants. */ - bool is_named_atom(int t) const; - /** Return index of the variable described by the variable - * name and lag/lead. If it doesn't exist, return -1. */ - int index(const string &name, int ll) const; - /** Return true if a variable is referenced, i.e. it has lag - * map. */ - bool is_referenced(const string &name) const; - /** Return the lag map for the variable name. */ - const Tlagmap &lagmap(const string &name) const; - /** Return the variable name for the tree index. It throws an - * exception if the tree index t is not a named atom. */ - const string &name(int t) const; - /** Return the lead/lag for the tree index. It throws an - * exception if the tree index t is not a named atom. */ - int lead(int t) const; - /** Return maximum lead. */ - int - get_maxlead() const - { - return maxlead; - } - /** Return minimum lag. */ - int - get_minlag() const - { - return minlag; - } - /** Return the name storage to allow querying to other - * classes. */ - const NameStorage & - get_name_storage() const - { - return varnames; - } - /** Assign the variable with a given lead. The varname must be - * from the varnames storage. The method checks if the - * variable iwht the given lead/lag is not assigned. If so, an - * exception is thrown. */ - void assign_variable(const string &varname, int ll, int t); - /** Unassign the variable with a given lead and given tree - * index. The tree index is only provided as a check. An - * exception is thrown if the name, ll, and the tree index t - * are not consistent. The method also updates nv, indices, - * maxlead and minlag. The varname must be from the varnames - * storage. */ - void unassign_variable(const string &varname, int ll, int t); - /** Debug print. */ - void print() const override; - protected: - /** Do the check for the variable. A subclass may need to - * reimplement this so that it could raise an error if the - * variable is not among a given list. */ - virtual int check_variable(const string &name) const; - /** Assign the constant. */ - void assign_constant(const string &name, int t); - /** Assign the variable. */ - void assign_variable(const string &name, int t); - /** The method just updates minlag or/and maxlead. Note that - * when assigning variables, the update is done when inserting - * to the maps, however, if removing a variable, we need to - * call this method. */ - void update_minmaxll(); - /** The method parses the string to recover a variable name - * and lag/lead ll. The variable name doesn't contain a lead/lag. */ - virtual void parse_variable(const string &in, string &out, int &ll) const = 0; - public: - /** Return true if the str represents a double.*/ - static bool is_string_constant(const string &str); - }; - - /** This class is a parent of all orderings of the dynamic atoms - * of variables which can appear before t, at t, or after t. It - * encapsulates the ordering, and the information about the number - * of static (appearing only at time t) predetermined (appearing - * before t and possibly at t), both (appearing before t and after - * t and possibly at t) and forward looking (appearing after t and - * possibly at t). - * - * The constructor takes a list of variable names. The class also - * provides mapping from the ordering of the variables in the list - * (outer) to the new ordering (at time t) and back. - * - * The user of the subclass must call do_ordering() after - * initialization. - * - * The class contains a few preimplemented methods for - * ordering. The class is used in this way: Make a subclass, and - * implement pure virtual do_ordering() by just plugging a - * preimplemented method, or plugging your own implementation. The - * method do_ordering() is called by the user after the constructor. - */ - class VarOrdering - { - protected: - /** Number of static variables. */ - int n_stat; - /** Number of predetermined variables. */ - int n_pred; - /** Number of both variables. */ - int n_both; - /** Number of forward looking variables. */ - int n_forw; - /** This is a set of tree indices corresponding to the - * variables at all times as they occur in the formulas. In - * fact, since this is used only for derivatives, the ordering - * of this vector is only important for ordering of the - * derivatives, in other contexts the ordering is not - * important, so it is rather a set of indices.*/ - vector<int> der_atoms; - /** This maps tree index of the variable to the position in - * the row of the ordering. One should be careful with making - * space in the positions for variables not appearing at time - * t. For instance in the pred(t-1), both(t-1), stat(t), - * pred(t), both(t), forw(t), both(t+1), forw(t+1) ordering, - * the variables x(t-1), y(t-1), x(t+1), z(t-1), z(t), and - * z(t+1) having tree indices 6,5,4,3,2,1 will be ordered as - * follows: y(t-1), x(t-1), z(t-1), [y(t)], [x(t)], z(t), - * x(t+1), where a bracketed expresion means non-existent by - * occupying a space. The map thus will look as follows: - * {5→0, 6→1, 3→2, 2→5, 3→6}. Note that nothing is mapped - * to positions 3 and 4. */ - map<int, int> positions; - /** This maps an ordering of the list of variables in - * constructor to the new ordering (at time t). The length is - * the number of variables. */ - vector<int> outer2y; - /** This maps a new ordering to the ordering of the list of - * variables in constructor (at time t). The length is the - * number of variables. */ - vector<int> y2outer; - /** This is just a reference for variable names to keep it - * from constructor to do_ordering() implementations. */ - const vector<string> &varnames; - /** This is just a reference to atoms to keep it from - * constructor to do_ordering() implementations. */ - const DynamicAtoms &atoms; - public: - /** This is an enum type for an ordering type implemented by - * do_general. */ - enum ord_type { pbspbfbf, bfspbfpb }; - /** Construct the ordering of the variables given by the names - * with their dynamic occurrences defined by the atoms. It - * calls the virtual method do_ordering which can be - * reimplemented. */ - VarOrdering(const vector<string> &vnames, const DynamicAtoms &a) - : n_stat(0), n_pred(0), n_both(0), n_forw(0), varnames(vnames), atoms(a) - { - } - VarOrdering(const VarOrdering &vo, const vector<string> &vnames, - const DynamicAtoms &a); - VarOrdering(const VarOrdering &vo) = delete; - virtual std::unique_ptr<VarOrdering> clone(const vector<string> &vnames, - const DynamicAtoms &a) const = 0; - /** Destructor does nothing here. */ - virtual ~VarOrdering() = default; - /** This is the method setting the ordering and the map. A - * subclass must reimplement it, possibly using a - * preimplemented ordering. This method must be called by the - * user after the class has been created. */ - virtual void do_ordering() = 0; - /** Return number of static. */ - int - nstat() const - { - return n_stat; - } - /** Return number of predetermined. */ - int - npred() const - { - return n_pred; - } - /** Return number of both. */ - int - nboth() const - { - return n_both; - } - /** Return number of forward looking. */ - int - nforw() const - { - return n_forw; - } - /** Return the set of tree indices for derivatives. */ - const vector<int> & - get_der_atoms() const - { - return der_atoms; - } - /** Return the y2outer. */ - const vector<int> & - get_y2outer() const - { - return y2outer; - } - /** Return the outer2y. */ - const vector<int> & - get_outer2y() const - { - return outer2y; - } - /** Query the atom given by the tree index. True is returned - * if the atom is one of the variables in the object. */ - bool check(int t) const; - /** Return the position of the atom (nulary term) given by a - * tree index. It is a lookup to the map. If the atom cannot - * be found, the exception is raised. */ - int get_pos_of(int t) const; - /** This returns a length of ordered row of atoms. In all - * cases so far, it does not depend on the ordering and it is - * as follows. */ - int - length() const - { - return n_stat+2*n_pred+3*n_both+2*n_forw; - } - /** Debug print. */ - void print() const; - protected: - /** This is a general ordering method which orders the - * variables by the given ordering ord_type. See documentation - * for respective do_ methods. */ - void do_general(ord_type ordering); - /** This is a preimplemented ordering for do_ordering() - * method. It assumes that the variables appear only at time - * t-1, t, t+1. It orders the atoms as pred(t-1), both(t-1), - * stat(t), pred(t), both(t), forw(t), both(t+1), - * forw(t+1). It builds the der_atoms, the map of positions, - * as well as y2outer and outer2y. */ - void - do_pbspbfbf() - { - do_general(pbspbfbf); - } - /** This is a preimplemented ordering for do_ordering() - * method. It assumes that the variables appear only at time - * t-1, t, t+1. It orders the atoms as both(t+1), forw(t+1), - * stat(t), pred(t), both(t), forw(t), pred(t-1), - * both(t-1). It builds the der_atoms, the map of positions, - * as well as y2outer and outer2y. */ - void - do_bfspbfpb() - { - do_general(bfspbfpb); - } - /** This is a preimplemented ordering for do_ordering() - * method. It makes no assumptions about occurences of - * variables at different times. It orders the atoms with - * increasing time keeping the given ordering within one - * time. This implies that y2outer and outer2y will be - * identities. The der_atoms will be just a sequence of atoms - * from the least to the most time preserving the order of atoms - * within one time. */ - void do_increasing_time(); - }; - -}; - -#endif diff --git a/dynare++/parser/cc/fine_atoms.cc b/dynare++/parser/cc/fine_atoms.cc deleted file mode 100644 index 8143e074e25b910b45c1530860b53d3cb303a807..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/fine_atoms.cc +++ /dev/null @@ -1,536 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "utils/cc/exception.hh" - -#include "parser_exception.hh" -#include "fine_atoms.hh" - -using namespace ogp; - -AllvarOuterOrdering::AllvarOuterOrdering(const vector<string> &allvar_outer, - const FineAtoms &a) - : atoms(a), allvar(), - endo2all(a.get_endovars().size(), -1), - exo2all(a.get_exovars().size(), -1) -{ - // fill in the allvar from allvar_outer - for (const auto &s : allvar_outer) - { - if (atoms.varnames.query(s)) - allvar.push_back(s); - else - throw ogu::Exception(__FILE__, __LINE__, - "Variable " + s + " is not a declared symbol in AllvarOuterOrdering constructor"); - } - - // fill in endo2all and exo2all - for (unsigned int i = 0; i < allvar.size(); i++) - { - auto it = atoms.endo_outer_map.find(allvar[i]); - if (it != atoms.endo_outer_map.end()) - endo2all[it->second] = i; - else - { - it = atoms.exo_outer_map.find(allvar[i]); - if (it != atoms.exo_outer_map.end()) - exo2all[it->second] = i; - else - throw ogu::Exception(__FILE__, __LINE__, - "Name " + allvar[i] + " is neither endogenous nor exogenous variable in AllvarOuterOrdering constructor"); - } - } - - // check whether everything has been filled - unsigned int iendo = 0; - while (iendo < endo2all.size() && endo2all[iendo] != -1) - iendo++; - unsigned int iexo = 0; - while (iexo < exo2all.size() && exo2all[iexo] != -1) - iexo++; - if (iendo < endo2all.size()) - throw ogu::Exception(__FILE__, __LINE__, - "Endogenous variable " + atoms.get_endovars()[iendo] - +" not found in outer all ordering in AllvarOuterOrdering constructor"); - if (iexo < exo2all.size()) - throw ogu::Exception(__FILE__, __LINE__, - "Exogenous variable " + atoms.get_exovars()[iexo] - +" not found in outer all ordering in AllvarOuterOrdering constructor"); -} - -AllvarOuterOrdering::AllvarOuterOrdering(const AllvarOuterOrdering &avo, - const FineAtoms &a) - : atoms(a), allvar(avo.allvar), - endo2all(avo.endo2all), - exo2all(avo.exo2all) -{ -} - -FineAtoms::FineAtoms(const FineAtoms &fa) - : DynamicAtoms(fa), params(), endovars(), exovars(), - der_atoms(fa.der_atoms), - endo_atoms_map(fa.endo_atoms_map), - exo_atoms_map(fa.exo_atoms_map) -{ - // fill in params - for (const auto ¶m : fa.params) - { - if (!varnames.query(param)) - throw ogu::Exception(__FILE__, __LINE__, - "Parameter " + param + " does not exist in FineAtoms copy cosntructor"); - params.push_back(param); - param_outer_map.emplace(param, params.size()-1); - } - // fill in endovars - for (const auto &endovar : fa.endovars) - { - if (!varnames.query(endovar)) - throw ogu::Exception(__FILE__, __LINE__, - "Endo variable " + endovar + " does not exist in FineAtoms copy constructor"); - endovars.push_back(endovar); - endo_outer_map.emplace(endovar, endovars.size()-1); - } - // fill in exovars - for (const auto &exovar : fa.exovars) - { - if (!varnames.query(exovar)) - throw ogu::Exception(__FILE__, __LINE__, - "Exo variable " + exovar + " does not exist in FineAtoms copy cosntructor"); - exovars.push_back(exovar); - exo_outer_map.emplace(exovar, exovars.size()-1); - } - - if (fa.endo_order) - endo_order = fa.endo_order->clone(endovars, *this); - - if (fa.exo_order) - exo_order = fa.exo_order->clone(exovars, *this); - - if (fa.allvar_order) - allvar_order = std::make_unique<AllvarOuterOrdering>(*(fa.allvar_order), *this); -} - -int -FineAtoms::check_variable(const string &name) const -{ - string str; - int ll; - parse_variable(name, str, ll); - if (varnames.query(str)) - return DynamicAtoms::check_variable(name); - else - { - throw ParserException("Variable <"+str+"> not declared.", 0); - return -1; - } -} - -int -FineAtoms::num_exo_periods() const -{ - int mlead, mlag; - exovarspan(mlead, mlag); - return mlead-mlag+1; -} - -void -FineAtoms::parsing_finished(VarOrdering::ord_type ot) -{ - make_internal_orderings(ot); - - // by default, concatenate outer endo and outer exo and make it as - // allvar outer: - vector<string> allvar_tmp; - allvar_tmp.insert(allvar_tmp.end(), endovars.begin(), endovars.end()); - allvar_tmp.insert(allvar_tmp.end(), exovars.begin(), exovars.end()); - - allvar_order = std::make_unique<AllvarOuterOrdering>(allvar_tmp, *this); -} - -void -FineAtoms::parsing_finished(VarOrdering::ord_type ot, - const vector<string> &allvar) -{ - make_internal_orderings(ot); - allvar_order = std::make_unique<AllvarOuterOrdering>(allvar, *this); -} - -const vector<string> & -FineAtoms::get_allvar() const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_allvars called before parsing_finished"); - - return allvar_order->get_allvar(); -} - -const vector<int> & -FineAtoms::outer_endo2all() const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer_endo2all called before parsing_finished"); - - return allvar_order->get_endo2all(); -} - -const vector<int> & -FineAtoms::outer_exo2all() const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer_exo2all called before parsing_finished"); - - return allvar_order->get_exo2all(); -} - -vector<int> -FineAtoms::variables() const -{ - if (endo_order) - return der_atoms; - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::variables called before parsing_finished"); - return {}; - } -} - -int -FineAtoms::nstat() const -{ - if (endo_order) - return endo_order->nstat(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::nstat called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::npred() const -{ - if (endo_order) - return endo_order->npred(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::npred called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::nboth() const -{ - if (endo_order) - return endo_order->nboth(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::nboth called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::nforw() const -{ - if (endo_order) - return endo_order->nforw(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::nforw called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::get_pos_of_endo(int t) const -{ - if (endo_order) - return endo_order->get_pos_of(t); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_pos_of_endo called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::get_pos_of_exo(int t) const -{ - if (exo_order) - return exo_order->get_pos_of(t); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_pos_of_exo called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::get_pos_of_all(int t) const -{ - if (endo_order && exo_order) - { - if (endo_order->check(t)) - return endo_order->get_pos_of(t); - else if (exo_order->check(t)) - return endo_order->length() + exo_order->get_pos_of(t); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Atom is not endo nor exo in FineAtoms::get_pos_of_all"); - return -1; - } - } - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_pos_of_exo called before parsing_finished"); - return -1; - } -} - -const vector<int> & -FineAtoms::y2outer_endo() const -{ - if (!endo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::y2outer_endo called before parsing_finished"); - return endo_order->get_y2outer(); -} - -const vector<int> & -FineAtoms::outer2y_endo() const -{ - if (!endo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer2y_endo called before parsing_finished"); - return endo_order->get_outer2y(); -} - -const vector<int> & -FineAtoms::y2outer_exo() const -{ - if (!exo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::y2outer_endo called before parsing_finished"); - return exo_order->get_y2outer(); -} - -const vector<int> & -FineAtoms::outer2y_exo() const -{ - if (!exo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer2y_exo called before parsing_finished"); - return exo_order->get_outer2y(); -} - -const vector<int> & -FineAtoms::get_endo_atoms_map() const -{ - if (!endo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_endo_atoms_map called before parsing_finished"); - return endo_atoms_map; -} - -const vector<int> & -FineAtoms::get_exo_atoms_map() const -{ - if (!exo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_exo_atoms_map called before parsing_finished"); - return exo_atoms_map; -} - -int -FineAtoms::name2outer_param(const string &name) const -{ - auto it = param_outer_map.find(name); - if (it == param_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not a parameter in FineAtoms::name2outer_param"); - return it->second; -} - -int -FineAtoms::name2outer_endo(const string &name) const -{ - auto it = endo_outer_map.find(name); - if (it == endo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an endogenous variable in FineAtoms::name2outer_endo"); - return it->second; -} - -int -FineAtoms::name2outer_exo(const string &name) const -{ - auto it = exo_outer_map.find(name); - if (it == exo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an exogenous variable in FineAtoms::name2outer_exo"); - return it->second; -} - -int -FineAtoms::name2outer_allvar(const string &name) const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::name2outer_allvar called beore parsing_finished"); - - auto it = endo_outer_map.find(name); - if (it != endo_outer_map.end()) - return allvar_order->get_endo2all()[it->second]; - else - { - it = exo_outer_map.find(name); - if (it != exo_outer_map.end()) - return allvar_order->get_exo2all()[it->second]; - } - - throw ogu::Exception(__FILE__, __LINE__, - "Name " + name + " is neither endo nor exo variable in FineAtoms::name2outer_allvar"); - return -1; -} - -void -FineAtoms::register_uniq_endo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Endogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - endovars.push_back(name); - endo_outer_map.emplace(std::move(name), endovars.size()-1); -} - -void -FineAtoms::register_uniq_exo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Exogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - exovars.push_back(name); - exo_outer_map.emplace(std::move(name), exovars.size()-1); -} - -void -FineAtoms::register_uniq_param(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Parameter <"+name+"> is not unique.", 0); - varnames.insert(name); - params.push_back(name); - param_outer_map.emplace(std::move(name), params.size()-1); -} - -void -FineAtoms::make_internal_orderings(VarOrdering::ord_type ot) -{ - bool endo_ordering_done = false; - bool exo_ordering_done = false; - - order_type = ot; - - int mlead, mlag; - endovarspan(mlead, mlag); - if (mlag >= -1 && mlead <= 1) - { - // make endo ordering - if (ot == VarOrdering::pbspbfbf) - endo_order = std::make_unique<EndoVarOrdering1>(endovars, *this); - else - endo_order = std::make_unique<EndoVarOrdering2>(endovars, *this); - endo_order->do_ordering(); - endo_ordering_done = true; - } - - exovarspan(mlead, mlag); - if (mlag == 0 && mlead == 0) - { - // make exo ordering - exo_order = std::make_unique<ExoVarOrdering>(exovars, *this); - exo_order->do_ordering(); - exo_ordering_done = true; - } - - if (endo_ordering_done && exo_ordering_done) - { - // concatenate der atoms from endo_order and exo_order - der_atoms.clear(); - der_atoms.insert(der_atoms.end(), - endo_order->get_der_atoms().begin(), - endo_order->get_der_atoms().end()); - der_atoms.insert(der_atoms.end(), - exo_order->get_der_atoms().begin(), - exo_order->get_der_atoms().end()); - - // create endo_atoms_map; der_atoms is a concatenation, so it is easy - int endo_atoms = endo_order->get_der_atoms().size(); - endo_atoms_map.clear(); - for (int i = 0; i < endo_atoms; i++) - endo_atoms_map.push_back(i); - // create exo_atoms_map - int exo_atoms = exo_order->get_der_atoms().size(); - exo_atoms_map.clear(); - for (int i = 0; i < exo_atoms; i++) - exo_atoms_map.push_back(endo_atoms + i); - } -} - -void -FineAtoms::print() const -{ - DynamicAtoms::print(); - if (endo_order) - { - std::cout << "Endo ordering:\n"; - endo_order->print(); - } - else - std::cout << "Endo ordering not created.\n"; - - if (exo_order) - { - std::cout << "Exo ordering:\n"; - exo_order->print(); - } - else - std::cout << "Exo ordering not created.\n"; - - std::cout << "endo atoms map:\n"; - for (unsigned int i = 0; i < endo_atoms_map.size(); i++) - std::cout << i << " → " << endo_atoms_map[i] << "\n"; - std::cout << "exo atoms map:\n"; - for (unsigned int i = 0; i < exo_atoms_map.size(); i++) - std::cout << i << " → " << exo_atoms_map[i] << "\n"; -} diff --git a/dynare++/parser/cc/fine_atoms.hh b/dynare++/parser/cc/fine_atoms.hh deleted file mode 100644 index c463c7c7c3b2a6b34d7365d63263967480604104..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/fine_atoms.hh +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_FINE_ATOMS_H -#define OGP_FINE_ATOMS_H - -#include "dynamic_atoms.hh" - -#include <vector> -#include <string> -#include <memory> - -namespace ogp -{ - using std::vector; - using std::string; - - /** This is just ordering used for endogenous variables. It - * assumes that we have only time t-1, t, and t+1, orders them as - * pred(t-1), both(t-1), stat(t), pred(t), both(t), forw(t), - * both(t+1), forw(t+1). */ - class EndoVarOrdering1 : public VarOrdering - { - public: - EndoVarOrdering1(const vector<string> &vnames, const DynamicAtoms &a) - : VarOrdering(vnames, a) - { - } - EndoVarOrdering1(const EndoVarOrdering1 &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : VarOrdering(vo, vnames, a) - { - } - std::unique_ptr<VarOrdering> - clone(const vector<string> &vnames, const DynamicAtoms &a) const override - { - return std::make_unique<EndoVarOrdering1>(*this, vnames, a); - } - void - do_ordering() override - { - do_pbspbfbf(); - } - }; - - /** This is just another ordering used for endogenous - * variables. It assumes that we have only time t-1, t, and t+1, - * orders them as both(t+1), forw(t+1), pred(t-1), both(t-1), - * stat(t), pred(t), both(t), forw(t). */ - class EndoVarOrdering2 : public VarOrdering - { - public: - EndoVarOrdering2(const vector<string> &vnames, const DynamicAtoms &a) - : VarOrdering(vnames, a) - { - } - EndoVarOrdering2(const EndoVarOrdering2 &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : VarOrdering(vo, vnames, a) - { - } - std::unique_ptr<VarOrdering> - clone(const vector<string> &vnames, const DynamicAtoms &a) const override - { - return std::make_unique<EndoVarOrdering2>(*this, vnames, a); - } - void - do_ordering() override - { - do_bfspbfpb(); - } - }; - - /** This is just ordering used for exogenous variables. It makes - * no assumptions about their timing. It orders them from the - * least time to the latest time. */ - class ExoVarOrdering : public VarOrdering - { - public: - ExoVarOrdering(const vector<string> &vnames, const DynamicAtoms &a) - : VarOrdering(vnames, a) - { - } - ExoVarOrdering(const ExoVarOrdering &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : VarOrdering(vo, vnames, a) - { - } - std::unique_ptr<VarOrdering> - clone(const vector<string> &vnames, const DynamicAtoms &a) const override - { - return std::make_unique<ExoVarOrdering>(*this, vnames, a); - } - void - do_ordering() override - { - do_increasing_time(); - } - }; - - class FineAtoms; - - /** This class provides an outer ordering of all variables (endo - * and exo). It maps the ordering to the particular outer - * orderings of endo and exo. It works tightly with the FineAtoms - * class. */ - class AllvarOuterOrdering - { - protected: - /** Type for a map mapping a variable name to an integer. */ - using Tvarintmap = map<string, int>; - /** Reference to atoms. */ - const FineAtoms &atoms; - /** The vector of all endo and exo variables in outer - * ordering. The pointers point to storage in atoms. */ - vector<string> allvar; - /** The mapping from outer endogenous to outer all. For - * example endo2all[0] is the order of the first outer - * endogenous variable in the allvar ordering. */ - vector<int> endo2all; - /** The mapping from outer exogenous to outer all. For example - * exo2all[0] is the order of the first outer exogenous - * variables in the allvar ordering. */ - vector<int> exo2all; - public: - /** Construct the allvar outer ordering from the provided - * sequence of endo and exo names. The names can have an - * arbitrary storage, the storage is transformed to the atoms - * storage. An exception is thrown if either the list is not - * exhaustive, or some string is not a variable. */ - AllvarOuterOrdering(const vector<string> &allvar_outer, const FineAtoms &a); - /** Copy constructor using the storage of provided atoms. */ - AllvarOuterOrdering(const AllvarOuterOrdering &allvar_outer, const FineAtoms &a); - /** Return endo2all mapping. */ - const vector<int> & - get_endo2all() const - { - return endo2all; - } - /** Return exo2all mapping. */ - const vector<int> & - get_exo2all() const - { - return exo2all; - } - /** Return the allvar ordering. */ - const vector<string> & - get_allvar() const - { - return allvar; - } - }; - - /** This class refines the DynamicAtoms by distinguishing among - * parameters (no lag and leads) and endogenous and exogenous - * variables (with lags and leads). For parameters, endogenous and - * exogenous, it defines outer orderings and internal - * orderings. The internal orderings are created by - * parsing_finished() method when it is sure that no new variables - * would be registered. The outer orderings are given by the order - * of calls of registering methods. - * - * In addition, the class also defines outer ordering of - * endogenous and exogenous variables. This is input as a - * parameter to parsing_finished(). By default, this whole outer - * ordering is just a concatenation of outer ordering of - * endogenous and exogenous variables. - * - * The internal ordering of all endo and exo variables is just a - * concatenation of endo and exo variables in their internal - * orderings. This is the ordering with respect to which all - * derivatives are taken. */ - class FineAtoms : public DynamicAtoms - { - friend class AllvarOuterOrdering; - protected: - using Tvarintmap = map<string, int>; - private: - /** The vector of parameters names. The order gives the order - * the data is communicated with outside world. */ - vector<string> params; - /** A map mapping a name of a parameter to an index in the outer - * ordering. */ - Tvarintmap param_outer_map; - /** The vector of endogenous variables. This defines the order - * like parameters. */ - vector<string> endovars; - /** A map mapping a name of an endogenous variable to an index - * in the outer ordering. */ - Tvarintmap endo_outer_map; - /** The vector of exogenous variables. Also defines the order - * like parameters and endovars. */ - vector<string> exovars; - /** A map mapping a name of an exogenous variable to an index - * in the outer ordering. */ - Tvarintmap exo_outer_map; - - protected: - /** This is the internal ordering of all atoms corresponding - * to endogenous variables. It is constructed by - * parsing_finished() method, which should be called after all - * parsing jobs have been finished. */ - std::unique_ptr<VarOrdering> endo_order; - /** This is the internal ordering of all atoms corresponding - * to exogenous variables. It has the same handling as - * endo_order. */ - std::unique_ptr<VarOrdering> exo_order; - /** This is the all variables outer ordering. It is - * constructed by parsing finished. */ - std::unique_ptr<AllvarOuterOrdering> allvar_order; - /** This vector defines a set of atoms as tree indices used - * for differentiation. The order of the atoms in this vector - * defines ordering of the derivative tensors. The ordering is - * a concatenation of atoms from endo_order and then - * exo_order. This vector is setup by parsing_finished() and - * is returned by variables(). */ - vector<int> der_atoms; - /** This is a mapping from endogenous atoms to all atoms in - * der_atoms member. The mapping maps index in endogenous atom - * ordering to index (not value) in der_atoms. It is useful if - * one wants to evaluate derivatives wrt only endogenous - * variables. It is set by parsing_finished(). By definition, - * it is monotone. */ - vector<int> endo_atoms_map; - /** This is a mapping from exogenous atoms to all atoms in - * der_atoms member. It is the same as endo_atoms_map for - * atoms of exogenous variables. */ - vector<int> exo_atoms_map; - public: - FineAtoms() = default; - FineAtoms(const FineAtoms &fa); - /** Deletes endo_order and exo_order. */ - ~FineAtoms() override = default; - /** Overrides DynamicAtoms::check_variable so that the error - * would be raised if the variable name is not declared. A - * variable is declared by inserting it to - * DynamicAtoms::varnames. This is a responsibility of a - * subclass. */ - int check_variable(const string &name) const override; - /** This calculates min lag and max lead of endogenous variables. */ - void - endovarspan(int &mlead, int &mlag) const - { - varspan(endovars, mlead, mlag); - } - /** This calculates mim lag and max lead of exogenous variables. */ - void - exovarspan(int &mlead, int &mlag) const - { - varspan(exovars, mlead, mlag); - } - /** This calculates the number of periods in which at least - * one exogenous variable occurs. */ - int num_exo_periods() const; - /** Return an (external) ordering of parameters. */ - const vector<string> & - get_params() const - { - return params; - } - /** Return an external ordering of endogenous variables. */ - const vector<string> & - get_endovars() const - { - return endovars; - } - /** Return an external ordering of exogenous variables. */ - const vector<string> & - get_exovars() const - { - return exovars; - } - /** This constructs internal orderings and makes the indices - * returned by variables method available. Further it - * constructs outer ordering of all variables by a simple - * concatenation of outer endogenous and outer exogenous. In - * addition, it makes nstat, npred, nboth, nforw available. */ - void parsing_finished(VarOrdering::ord_type ot); - /** This does the same thing as - * parsing_finished(VarOrdering::ord_type) plus it allows for - * inputing a different outer ordering of all variables. The - * ordering is input as a list of strings, their storage can - * be arbitrary. */ - void parsing_finished(VarOrdering::ord_type ot, const vector<string> &avo); - /** Return the external ordering of all variables (endo and - * exo). This is either the second argument to - * parsing_finished or the default external ordering. This - * must be called only after parsing_finished. */ - const vector<string> &get_allvar() const; - /** Return the map from outer ordering of endo variables to - * the allvar ordering. This must be called only after - * parsing_finished. */ - const vector<int> &outer_endo2all() const; - /** Return the map from outer ordering of exo variables to - * the allvar ordering. This must be called only after - * parsing_finished. */ - const vector<int> &outer_exo2all() const; - /** Return the atoms with respect to which we are going to - * differentiate. This must be called after - * parsing_finished. */ - vector<int> variables() const override; - /** Return the number of static. */ - int nstat() const; - /** Return the number of predetermined. */ - int npred() const; - /** Return the number of both. */ - int nboth() const; - /** Return the number of forward looking. */ - int nforw() const; - /** Return the index of an endogenous atom given by tree index in - * the endo ordering. This must be also called only after - * parsing_finished(). */ - int get_pos_of_endo(int t) const; - /** Return the index of an exogenous atom given by tree index in - * the exo ordering. This must be also called only after - * parsing_finished(). */ - int get_pos_of_exo(int t) const; - /** Return the index of either endogenous or exogenous atom - * given by tree index in the concatenated ordering of - * endogenous and exogenous atoms. This must be also called - * only after parsing_finished(). */ - int get_pos_of_all(int t) const; - /** Return the mapping from endogenous at time t to outer - * ordering of endogenous. */ - const vector<int> &y2outer_endo() const; - /** Return the mapping from the outer ordering of endogenous to endogenous - * at time t. */ - const vector<int> &outer2y_endo() const; - /** Return the mapping from exogenous at time t to outer - * ordering of exogenous. */ - const vector<int> &y2outer_exo() const; - /** Return the mapping from the outer ordering of exogenous to exogenous - * at time t. */ - const vector<int> &outer2y_exo() const; - /** Return the endo_atoms_map. */ - const vector<int> &get_endo_atoms_map() const; - /** Return the exo_atoms_map. */ - const vector<int> &get_exo_atoms_map() const; - /** Return an index in the outer ordering of a given - * parameter. An exception is thrown if the name is not a - * parameter. */ - int name2outer_param(const string &name) const; - /** Return an index in the outer ordering of a given - * endogenous variable. An exception is thrown if the name is not a - * and endogenous variable. */ - int name2outer_endo(const string &name) const; - /** Return an index in the outer ordering of a given - * exogenous variable. An exception is thrown if the name is not a - * and exogenous variable. */ - int name2outer_exo(const string &name) const; - /** Return an index in the outer ordering of all variables - * (endo and exo) for a given name. An exception is thrown if - * the name is not a variable. This must be called only after - * parsing_finished(). */ - int name2outer_allvar(const string &name) const; - /** Return the number of endogenous variables at time t-1, these are state - * variables. */ - int - nys() const - { - return npred()+nboth(); - } - /** Return the number of endogenous variables at time t+1. */ - int - nyss() const - { - return nboth()+nforw(); - } - /** Return the number of endogenous variables. */ - int - ny() const - { - return endovars.size(); - } - /** Return the number of exogenous variables. */ - int - nexo() const - { - return static_cast<int>(exovars.size()); - } - /** Return the number of parameters. */ - int - np() const - { - return static_cast<int>(params.size()); - } - /** Register unique endogenous variable name. The order of - * calls defines the endo outer ordering. The method is - * virtual, since a superclass may want to do some additional - * action. */ - virtual void register_uniq_endo(string name); - /** Register unique exogenous variable name. The order of - * calls defines the exo outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_exo(string name); - /** Register unique parameter name. The order of calls defines - * the param outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_param(string name); - /** Debug print. */ - void print() const override; - private: - /** This performs the common part of parsing_finished(), which - * is a construction of internal orderings. */ - void make_internal_orderings(VarOrdering::ord_type ot); - protected: - /** This remembers the ordering type of the last call make_internal_ordering. */ - VarOrdering::ord_type order_type; - }; -}; - -#endif diff --git a/dynare++/parser/cc/formula.ll b/dynare++/parser/cc/formula.ll deleted file mode 100644 index 4b5b2aeb2c5bdb9dab3025b4a2341a8b936e25d8..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula.ll +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ -%{ -#include "location.hh" -#include "formula_tab.hh" - -#define YY_USER_ACTION SET_LLOC(fmla_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="fmla_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* initial spaces or tabs are ignored */ - -[ \t\r\n] -[+] {return YPLUS;} -[-] {return YMINUS;} -[*] {return YTIMES;} -[/] {return YDIVIDE;} -[\^] {return YPOWER;} -exp {return YEXP;} -log {return YLOG;} -sin {return YSIN;} -cos {return YCOS;} -tan {return YTAN;} -sqrt {return YSQRT;} -erf {return YERF;} -erfc {return YERFC;} -diff {return YDIFF;} - - /* names: parameters, variables (lagged/leaded) */ -[A-Za-z_][A-Za-z0-9_]*([\(\{][+-]?[0-9]+[\)\}])? { - fmla_lval.string=fmla_text; - return NAME; -} - - /* floating point numbers */ -(([0-9]*\.?[0-9]+)|([0-9]+\.))([edED][-+]?[0-9]+)? { - fmla_lval.string=fmla_text; - return DNUMBER; -} - -= {return EQUAL_SIGN;} - -. {return fmla_text[0];} - -%% - -int -fmla_wrap() -{ - return 1; -} - -void -fmla__destroy_buffer(void* p) -{ - fmla__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/parser/cc/formula.yy b/dynare++/parser/cc/formula.yy deleted file mode 100644 index 4fc7f934d9c288cd16205c883aed18d289e92927..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula.yy +++ /dev/null @@ -1,101 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -%code requires -{ -#include "location.hh" -#define FMLA_LTYPE ogp::location_type -} - -%code -{ -#include "formula_parser.hh" -#include <string> - -void fmla_error(std::string); -int fmla_lex(); -extern ogp::FormulaParser* fparser; -} - -%union -{ - char* string; - double dvalue; - int integer; -} - -%token EQUAL_SIGN -%left YPLUS YMINUS -%left YTIMES YDIVIDE -%precedence YUMINUS YUPLUS -%right YPOWER -%token YEXP YLOG YSIN YCOS YTAN YSQRT YERF YERFC YDIFF -%token <string> DNUMBER NAME -%type <integer> expression - -%define api.prefix {fmla_} - -%locations -%defines -%define parse.error verbose - -%% - root : equation_list - | expression - {fparser->add_formula($1);} - ; - - equation_list : equation_list equation | equation ; - - equation : expression EQUAL_SIGN expression ';' - {fparser->add_formula(fparser->add_binary(ogp::code_t::MINUS,$1,$3));} - | expression ';' - {fparser->add_formula($1);} - ; - - expression : '(' expression ')' { $$ = $2;} - | expression YPLUS expression {$$=fparser->add_binary(ogp::code_t::PLUS,$1,$3);} - | expression YMINUS expression {$$=fparser->add_binary(ogp::code_t::MINUS,$1,$3);} - | expression YTIMES expression {$$=fparser->add_binary(ogp::code_t::TIMES,$1,$3);} - | expression YDIVIDE expression {$$=fparser->add_binary(ogp::code_t::DIVIDE,$1,$3);} - | expression YPOWER expression {$$=fparser->add_binary(ogp::code_t::POWER,$1,$3);} - | YMINUS expression %prec YUMINUS {$$=fparser->add_unary(ogp::code_t::UMINUS,$2);} - | YPLUS expression %prec YUPLUS {$$ = $2;} - | YSIN '(' expression ')' {$$=fparser->add_unary(ogp::code_t::SIN,$3);} - | YCOS '(' expression ')' {$$=fparser->add_unary(ogp::code_t::COS,$3);} - | YTAN '(' expression ')' {$$=fparser->add_unary(ogp::code_t::TAN,$3);} - | YEXP '(' expression ')' {$$=fparser->add_unary(ogp::code_t::EXP,$3);} - | YLOG '(' expression ')' {$$=fparser->add_unary(ogp::code_t::LOG,$3);} - | YSQRT '(' expression ')' {$$=fparser->add_unary(ogp::code_t::SQRT,$3);} - | YERF '(' expression ')' {$$=fparser->add_unary(ogp::code_t::ERF,$3);} - | YERFC '(' expression ')' {$$=fparser->add_unary(ogp::code_t::ERFC,$3);} - | YDIFF '(' expression ',' NAME ')' {$$=fparser->add_derivative($3, fparser->add_nulary($5));} - | NAME {$$=fparser->add_nulary($1);} - | DNUMBER {$$=fparser->add_nulary($1);} - ; - -%% - -void -fmla_error(std::string s) -{ - fparser->error(std::move(s)); -} diff --git a/dynare++/parser/cc/formula_parser.cc b/dynare++/parser/cc/formula_parser.cc deleted file mode 100644 index e23ca3a0d2e4941612f1ec75bacdcf1ac2bad02f..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula_parser.cc +++ /dev/null @@ -1,536 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "utils/cc/pascal_triangle.hh" -#include "utils/cc/exception.hh" - -#include "parser_exception.hh" -#include "location.hh" -#include "formula_parser.hh" -#include "formula_tab.hh" - -#include <cmath> -#include <algorithm> - -using namespace ogp; - -extern location_type fmla_lloc; - -FormulaParser::FormulaParser(const FormulaParser &fp, Atoms &a) - : otree(fp.otree), atoms(a), formulas(fp.formulas), ders() -{ - // create derivatives - for (const auto &der : fp.ders) - ders.push_back(std::make_unique<FormulaDerivatives>(*der)); -} - -void -FormulaParser::differentiate(int max_order) -{ - ders.clear(); - vector<int> vars; - vars = atoms.variables(); - for (int formula : formulas) - ders.push_back(std::make_unique<FormulaDerivatives>(otree, vars, formula, max_order)); -} - -const FormulaDerivatives & -FormulaParser::derivatives(int i) const -{ - if (i < static_cast<int>(ders.size())) - return *(ders[i]); - else - throw ogu::Exception(__FILE__, __LINE__, - "Wrong formula index in FormulaParser::derivatives"); - return *(ders[0]); // just because of compiler -} - -void -FormulaParser::add_formula(int t) -{ - formulas.push_back(t); -} - -int -FormulaParser::add_binary(code_t code, int t1, int t2) -{ - return otree.add_binary(code, t1, t2); -} - -int -FormulaParser::add_unary(code_t code, int t) -{ - return otree.add_unary(code, t); -} - -int -FormulaParser::add_nulary(const string &str) -{ - int t = -1; - try - { - t = atoms.check(str); - } - catch (const ParserException &e) - { - throw ParserException(e, fmla_lloc.off); - } - if (t == -1) - { - t = otree.add_nulary(); - atoms.assign(str, t); - } - return t; -} - -void -FormulaParser::add_subst_formulas(const map<int, int> &subst, const FormulaParser &fp) -{ - for (int i = 0; i < fp.nformulas(); i++) - { - int f = add_substitution(fp.formula(i), subst, fp); - add_formula(f); - } -} - -void -FormulaParser::substitute_formulas(const map<int, int> &smap) -{ - for (int i = 0; i < nformulas(); i++) - { - // make substitution and replace the formula for it - int f = add_substitution(formulas[i], smap); - formulas[i] = f; - // update the derivatives if any - if (i < static_cast<int>(ders.size()) && ders[i]) - { - int order = ders[i]->get_order(); - ders[i] = std::make_unique<FormulaDerivatives>(otree, atoms.variables(), formulas[i], order); - } - } -} - -/** Global symbols for passing info to parser. */ -FormulaParser *fparser; - -/** The declarations of functions defined in formula_ll.cc and - * formula_tab.cc generated from formula.lex and formula.y */ -void *fmla__scan_string(const char *); -void fmla__destroy_buffer(void *); -int fmla_parse(); -extern location_type fmla_lloc; - -/** This makes own copy of provided data, sets the buffer for the - * parser with fmla_scan_buffer, and launches fmla_parse(). Note that - * the pointer returned from fmla_scan_buffer must be freed at the - * end. */ -void -FormulaParser::parse(const string &stream) -{ - fmla_lloc.off = 0; - fmla_lloc.ll = 0; - void *p = fmla__scan_string(stream.c_str()); - fparser = this; - fmla_parse(); - fmla__destroy_buffer(p); -} - -void -FormulaParser::error(string mes) const -{ - throw ParserException(std::move(mes), fmla_lloc.off); -} - -int -FormulaParser::last_formula() const -{ - int res = -1; - for (int formula : formulas) - res = std::max(res, formula); - return std::max(res, otree.get_last_nulary()); -} - -int -FormulaParser::pop_last_formula() -{ - if (formulas.size() == 0) - return -1; - int t = formulas.back(); - if (formulas.size() == ders.size()) - ders.pop_back(); - formulas.pop_back(); - return t; -} - -void -FormulaParser::print() const -{ - atoms.print(); - for (int formula : formulas) - { - std::cout << "formula " << formula << ":\n"; - otree.print_operation(formula); - } - for (unsigned int i = 0; i < ders.size(); i++) - { - std::cout << "derivatives for the formula " << formulas[i] << ":\n"; - ders[i]->print(otree); - } -} - -/** This constructor makes a vector of indices for formulas - * corresponding to derivatives of the given formula. The formula is - * supposed to belong to the provided tree, the created derivatives - * are added to the tree. - * - * The algorithm is as follows. todo: update description of the - * algorithm - */ -FormulaDerivatives::FormulaDerivatives(OperationTree &otree, - const vector<int> &vars, int f, int max_order) - : nvar(vars.size()), order(max_order) -{ - FoldMultiIndex fmi_zero(nvar); - tder.push_back(f); - indices.push_back(fmi_zero); - unsigned int last_order_beg = 0; - unsigned int last_order_end = tder.size(); - - for (int k = 1; k <= order; k++) - { - // interval <last_order_beg,last_order_end) is guaranteed - // here to contain at least one item - for (unsigned int run = last_order_beg; run < last_order_end; run++) - { - // shift one order from the run - FoldMultiIndex fmi(indices[run], 1); - // set starting variable from the run, note that if k=1, - // the shift order ctor of fmi will set it to zero - int ivar_start = fmi[k-1]; - for (int ivar = ivar_start; ivar < nvar; ivar++, fmi.increment()) - { - int der = otree.add_derivative(tder[run], vars[ivar]); - if (der != OperationTree::zero) - { - tder.push_back(der); - indices.push_back(fmi); - } - } - } - - // set new last_order_beg and last_order_end - last_order_beg = last_order_end; - last_order_end = tder.size(); - // if there was no new derivative, break out from the loop - if (last_order_beg >= last_order_end) - break; - } - - // build ind2der map - for (unsigned int i = 0; i < indices.size(); i++) - ind2der.emplace(indices[i], i); - -} - -FormulaDerivatives::FormulaDerivatives(const FormulaDerivatives &fd) = default; - -int -FormulaDerivatives::derivative(const FoldMultiIndex &mi) const -{ - if (mi.order() > order) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong order of multi-index in FormulaDerivatives::derivative"); - if (mi.nv() != nvar) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong multi-index variables in FormulaDerivatives::derivative"); - - auto it = ind2der.find(mi); - if (it == ind2der.end()) - return OperationTree::zero; - else - return tder[it->second]; -} - -void -FormulaDerivatives::print(const OperationTree &otree) const -{ - for (const auto &it : ind2der) - { - std::cout << "derivative "; - it.first.print(); - std::cout << " is formula " << tder[it.second] << '\n'; - otree.print_operation(tder[it.second]); - } -} - -void -FormulaCustomEvaluator::eval(const AtomValues &av, FormulaEvalLoader &loader) -{ - etree.reset_all(); - av.setValues(etree); - for (unsigned int i = 0; i < terms.size(); i++) - { - double res = etree.eval(terms[i]); - loader.load(static_cast<int>(i), res); - } -} - -FoldMultiIndex::FoldMultiIndex(int nv) - : nvar(nv), ord(0), data(std::make_unique<int[]>(ord)) -{ -} - -FoldMultiIndex::FoldMultiIndex(int nv, int ordd, int ii) - : nvar(nv), ord(ordd), data(std::make_unique<int[]>(ord)) -{ - for (int i = 0; i < ord; i++) - data[i] = ii; -} - -/** Note that a monotone sequence mapped by monotone mapping yields a - * monotone sequence. */ -FoldMultiIndex::FoldMultiIndex(int nv, const FoldMultiIndex &mi, const vector<int> &mp) - : nvar(nv), ord(mi.ord), data(std::make_unique<int[]>(ord)) -{ - for (int i = 0; i < ord; i++) - { - if (i < ord-1 && mp[i+1] < mp[i]) - throw ogu::Exception(__FILE__, __LINE__, - "Mapping not monotone in FoldMultiIndex constructor"); - if (mp[mi[i]] >= nv || mp[mi[i]] < 0) - throw ogu::Exception(__FILE__, __LINE__, - "Mapping out of bounds in FoldMultiIndex constructor"); - data[i] = mp[mi[i]]; - } -} - -FoldMultiIndex::FoldMultiIndex(const FoldMultiIndex &fmi, int new_orders) - : nvar(fmi.nvar), - ord(fmi.ord+new_orders), - data(std::make_unique<int[]>(ord)) -{ - std::copy_n(fmi.data.get(), fmi.ord, data.get()); - int new_item = (fmi.ord > 0) ? fmi.data[fmi.ord-1] : 0; - for (int i = fmi.ord; i < ord; i++) - data[i] = new_item; -} - -FoldMultiIndex::FoldMultiIndex(const FoldMultiIndex &fmi) - : nvar(fmi.nvar), - ord(fmi.ord), - data(std::make_unique<int[]>(ord)) -{ - std::copy_n(fmi.data.get(), ord, data.get()); -} - -const FoldMultiIndex & -FoldMultiIndex::operator=(const FoldMultiIndex &fmi) -{ - if (ord != fmi.ord) - data = std::make_unique<int[]>(fmi.ord); - - ord = fmi.ord; - nvar = fmi.nvar; - std::copy_n(fmi.data.get(), ord, data.get()); - - return *this; -} - -bool -FoldMultiIndex::operator<(const FoldMultiIndex &fmi) const -{ - if (nvar != fmi.nvar) - ogu::Exception(__FILE__, __LINE__, - "Different nvar in FoldMultiIndex::operator<"); - - if (ord < fmi.ord) - return true; - if (ord > fmi.ord) - return false; - - int i = 0; - while (i < ord && data[i] == fmi.data[i]) - i++; - if (i == ord) - return false; - else - return data[i] < fmi.data[i]; -} - -bool -FoldMultiIndex::operator==(const FoldMultiIndex &fmi) const -{ - bool res = true; - res = res && (nvar == fmi.nvar) && (ord == fmi.ord); - if (res) - for (int i = 0; i < ord; i++) - if (data[i] != fmi.data[i]) - return false; - return res; -} - -void -FoldMultiIndex::increment() -{ - if (ord == 0) - return; - - int k = ord-1; - data[k]++; - while (k > 0 && data[k] == nvar) - { - data[k] = 0; - data[--k]++; - } - for (int kk = 1; kk < ord; kk++) - if (data[kk-1] > data[kk]) - data[kk] = data[kk-1]; -} - -// For description of an algorithm for calculation of folded offset, -// see Tensor Library Documentation, Ondra Kamenik, 2005, description -// of FTensor::getOffsetRecurse(). -int -FoldMultiIndex::offset() const -{ - // make copy for the recursions - auto tmp = std::make_unique<int[]>(ord); - std::copy_n(data.get(), ord, tmp.get()); - // call the recursive algorithm - int res = offset_recurse(tmp.get(), ord, nvar); - return res; -} - -void -FoldMultiIndex::print() const -{ - std::cout << "["; - for (int i = 0; i < ord; i++) - std::cout << data[i] << ' '; - std::cout << "]"; -} - -int -FoldMultiIndex::offset_recurse(int *data, int len, int nv) -{ - if (len == 0) - return 0; - // calculate length of initial constant indices - int prefix = 1; - while (prefix < len && data[0] == data[prefix]) - prefix++; - - int m = data[0]; - int s1 = PascalTriangle::noverk(nv+len-1, len) - PascalTriangle::noverk(nv-m+len-1, len); - - // cancel m from the rest of the sequence - for (int i = prefix; i < len; i++) - data[i] -= m; - - // calculate offset of the remaining sequence - int s2 = offset_recurse(data+prefix, len-prefix, nv-m); - // return the sum - return s1+s2; -} - -bool -ltfmi::operator()(const FoldMultiIndex &i1, const FoldMultiIndex &i2) const -{ - return i1 < i2; -} - -FormulaDerEvaluator::FormulaDerEvaluator(const FormulaParser &fp) - : etree(fp.otree, -1) -{ - for (const auto &der : fp.ders) - ders.push_back(der.get()); - - der_atoms = fp.atoms.variables(); -} - -void -FormulaDerEvaluator::eval(const AtomValues &av, FormulaDerEvalLoader &loader, int order) -{ - if (ders.size() == 0) - return; - int maxorder = ders[0]->order; - - if (order > maxorder) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong order in FormulaDerEvaluator::eval"); - - etree.reset_all(); - av.setValues(etree); - - auto vars = std::make_unique<int[]>(order); - - for (unsigned int i = 0; i < ders.size(); i++) - { - for (const auto &it : ders[i]->ind2der) - { - const FoldMultiIndex &mi = it.first; - if (mi.order() == order) - { - // set vars from multiindex mi and variables - for (int k = 0; k < order; k++) - vars[k] = der_atoms[mi[k]]; - // evaluate - double res = etree.eval(ders[i]->tder[it.second]); - // load - loader.load(i, order, vars.get(), res); - } - } - } -} - -void -FormulaDerEvaluator::eval(const vector<int> &mp, const AtomValues &av, - FormulaDerEvalLoader &loader, int order) -{ - etree.reset_all(); - av.setValues(etree); - - int nvar_glob = der_atoms.size(); - int nvar = mp.size(); - auto vars = std::make_unique<int[]>(order); - - for (unsigned int i = 0; i < ders.size(); i++) - { - FoldMultiIndex mi(nvar, order); - do - { - // find index of the derivative in the tensor - FoldMultiIndex mi_glob(nvar_glob, mi, mp); - int der = ders[i]->derivative(mi_glob); - if (der != OperationTree::zero) - { - // set vars from the global multiindex - for (int k = 0; k < order; k++) - vars[k] = der_atoms[mi_glob[k]]; - // evaluate derivative - double res = etree.eval(der); - // load - loader.load(i, order, vars.get(), res); - } - mi.increment(); - } - while (!mi.past_the_end()); - } -} diff --git a/dynare++/parser/cc/formula_parser.hh b/dynare++/parser/cc/formula_parser.hh deleted file mode 100644 index 09a9e37d64672c30f360e7ddd501ef0e49090e3a..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula_parser.hh +++ /dev/null @@ -1,497 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_FORMULA_PARSER_H -#define OGP_FORMULA_PARSER_H - -#include <utility> -#include <memory> -#include <vector> - -#include "tree.hh" - -namespace ogp -{ - using std::vector; - - /** Pure virtual class defining a minimal interface for - * representation of nulary terms within FormulaParser. */ - class Atoms - { - public: - Atoms() = default; - virtual ~Atoms() = default; - /** This returns previously assigned internal index to the - * given atom, or returns -1 if the atom has not been assigned - * yet. The method can raise an exception, if the Atoms - * implementation is strict and the name is not among - * prescribed possible values. */ - virtual int check(const std::string &name) const = 0; - /** This method assigns an internal index to the nulary term - * described by the name. The internal index is allocated by - * OperationTree class. */ - virtual void assign(const std::string &name, int t) = 0; - /** Returns a number of variables which will be used for - * differentiations. */ - virtual int nvar() const = 0; - /** Returns a vector of variable's internal indices which will - * be used for differentiations. */ - virtual vector<int> variables() const = 0; - /** Debug print. */ - virtual void print() const = 0; - }; - - /** Pure virtual class defining interface for all classes able to - * set nulary terms to evaluation tree EvalTree. The - * implementations of this class will have to be connected with - * Atoms to have knowledge about the atoms and their indices in - * the tree, and will call EvalTree::set_nulary. */ - class AtomValues - { - public: - virtual ~AtomValues() = default; - virtual void setValues(EvalTree &et) const = 0; - }; - - class FormulaDerEvaluator; - class FoldMultiIndex; - /** For ordering FoldMultiIndex in the std::map. */ - struct ltfmi - { - bool operator()(const FoldMultiIndex &i1, const FoldMultiIndex &i2) const; - }; - - /** This class stores derivatives (tree indices) of one formula - * for all orders upto a given one. It stores the derivatives as a - * sequence (vector) of these tree indices and sequence of the - * multidimensional indices of variables wrt which the derivatives - * were taken. In order to speed up querying for a derivative - * given the variables, we have a map mapping the multidimensional - * index to the order of the derivative in the sequence. - * - * The only reason we do not have only this map is that the - * iterators of the map do not survive the insertions to the map, - * and implementation of the constructor has to be very difficult. - */ - class FormulaDerivatives - { - friend class FormulaDerEvaluator; - protected: - /** Vector of derivatives. This is a list of derivatives (tree - * indices), the ordering is given by the algorithm used to - * create it. Currently, it starts with zero-th derivative, - * the formula itself and carries with first order, second, - * etc. */ - vector<int> tder; - /** Vector of multiindices corresponding to the vector of - * derivatives. */ - vector<FoldMultiIndex> indices; - /** For retrieving derivatives via a multiindex, we have a map - * mapping a multiindex to a derivative in the tder - * ordering. This means that indices[ind2der[index]] == index. */ - using Tfmiintmap = map<FoldMultiIndex, int, ltfmi>; - Tfmiintmap ind2der; - /** The number of variables. */ - int nvar; - /** The maximum order of derivatives. */ - int order; - public: - /** The constructor allocates and fills the sequence of the - * indices of derivatives for a formula. - * @param otree the OperationTree for which all work is done - * and to which the derivatives are added. - * @param vars the vector of nulary terms in the tree; the - * derivatives are taken with respect to these variables in - * the ordering given by the vector. - * @param f the index of the formula being differentiated. The - * zero derivative is set to f. - * @param max_order the maximum order of differentiation. - */ - FormulaDerivatives(OperationTree &otree, const vector<int> &vars, int f, int max_order); - /** Copy constructor. */ - FormulaDerivatives(const FormulaDerivatives &fd); - virtual ~FormulaDerivatives() = default; - /** Random access to the derivatives via multiindex. */ - int derivative(const FoldMultiIndex &mi) const; - /** Return the order. */ - int - get_order() const - { - return order; - } - /** Debug print. */ - void print(const OperationTree &otree) const; - }; - - class FormulaEvaluator; - - /** This class is able to parse a number of formulas and - * differentiate them. The life cycle of the object is as follows: - * After it is created, a few calls to parse will add formulas - * (zero derivatives) to the object. Then a method differentiate() - * can be called and a vector of pointers to derivatives for each - * formula is created. After this, no one should call other - * parse() or differentiate(). A const reference of the object can - * be used in constructors of FormulaEvaluator and - * FormulaDerEvaluator in order to evaluate formulas (zero - * derivatives) and higher derivatives resp. */ - class FormulaParser - { - friend class FormulaCustomEvaluator; - friend class FormulaDerEvaluator; - protected: - /** The OperationTree of all formulas, including derivatives. */ - OperationTree otree; - /** Reference to Atoms. The Atoms are filled with nulary terms - * during execution of parse(). */ - Atoms &atoms; - /** Vector of formulas (zero derivatives) in the order as they - * have been parsed. */ - vector<int> formulas; - /** The vector to derivatives, each vector corresponds to a - * formula in the vector formulas. */ - vector<std::unique_ptr<FormulaDerivatives>> ders; - public: - /** Construct an empty formula parser. */ - FormulaParser(Atoms &a) - : atoms(a) - { - } - FormulaParser(const FormulaParser &fp) = delete; - /** Copy constructor using a different instance of Atoms. */ - FormulaParser(const FormulaParser &fp, Atoms &a); - virtual ~FormulaParser() = default; - - /** Requires an addition of the formula; called from the - * parser. */ - void add_formula(int t); - /** Requires an addition of the binary operation; called from - * the parser. */ - int add_binary(code_t code, int t1, int t2); - /** Requires an addition of the unary operation; called from - * the parser. */ - int add_unary(code_t code, int t); - /** Requires an addition of the nulary operation given by the - * string. The Atoms are consulted for uniquness and are given - * an internal index generated by the OperationTree. This is - * the channel through which the Atoms are filled. */ - int add_nulary(const std::string &str); - - /** Adds a derivative to the tree. This just calls - * OperationTree::add_derivative. */ - int - add_derivative(int t, int v) - { - return otree.add_derivative(t, v); - } - /** Adds a substitution. This just calls - * OperationTree::add_substitution. */ - int - add_substitution(int t, const map<int, int> &subst) - { - return otree.add_substitution(t, subst); - } - /** Add the substitution given by the map where left sides of - * substitutions come from another parser. The right sides are - * from this object. The given t is from the given parser fp. */ - int - add_substitution(int t, const map<int, int> &subst, - const FormulaParser &fp) - { - return otree.add_substitution(t, subst, fp.otree); - } - /** This adds formulas from the given parser with (possibly) - * different atoms applying substitutions from the given map - * mapping atoms from fp to atoms of the object. */ - void add_subst_formulas(const map<int, int> &subst, const FormulaParser &fp); - /** Substitute formulas. For each i from 1 through all - * formulas, it adds a substitution of the i-th formula and - * make it to be i-th formula.*/ - void substitute_formulas(const std::map<int, int> &subst); - /** This method turns the given term to nulary operation. It - * should be used with caution, since this method does not - * anything do with atoms, but usually some action is also - * needed (at leat to assign the tree index t to some - * atom). */ - void - nularify(int t) - { - otree.nularify(t); - } - /** Returns a set of nulary terms of the given term. Just - * calls OperationTree::nulary_of_term. */ - const unordered_set<int> & - nulary_of_term(int t) const - { - return otree.nulary_of_term(t); - } - - /** Parse a given string containing one or more formulas. The - * formulas are parsed and added to the OperationTree and to - * the formulas vector. */ - void parse(const std::string &stream); - /** Processes a syntax error from bison. */ - void error(std::string mes) const; - /** Differentiate all the formulas up to the given order. The - * variables with respect to which the derivatives are taken - * are obtained by Atoms::variables(). If the derivates exist, - * they are destroyed and created again (with possibly - * different order). */ - void differentiate(int max_order); - /** Return i-th formula derivatives. */ - const FormulaDerivatives &derivatives(int i) const; - - /** This returns a maximum index of zero derivative formulas - * including all nulary terms. This is a mimumum length of the - * tree for which it is safe to evaluate zero derivatives of - * the formulas. */ - int last_formula() const; - /** This returns a tree index of the i-th formula in the - * vector. */ - int - formula(int i) const - { - return formulas[i]; - } - - /** This returns a tree index of the last formula and pops its - * item from the formulas vector. The number of formulas is - * then less by one. Returns -1 if there is no formula. If - * there are derivatives of the last formula, they are - * destroyed and the vector ders is popped from the back. */ - int pop_last_formula(); - - /** This returns a number of formulas. */ - int - nformulas() const - { - return static_cast<int>(formulas.size()); - } - - /** This returns a reference to atoms. */ - const Atoms & - getAtoms() const - { - return atoms; - } - Atoms & - getAtoms() - { - return atoms; - } - /** This returns the tree. */ - const OperationTree & - getTree() const - { - return otree; - } - OperationTree & - getTree() - { - return otree; - } - - /** Debug print. */ - void print() const; - }; - - /** This is a pure virtual class defining an interface for all - * classes which will load the results of formula (zero - * derivative) evaluations. A primitive implementation of this - * class can be a vector of doubles. */ - class FormulaEvalLoader - { - public: - virtual ~FormulaEvalLoader() = default; - /** Set the value res for the given formula. The formula is - * identified by an index corresponding to the ordering in - * which the formulas have been parsed (starting from - * zero). */ - virtual void load(int i, double res) = 0; - }; - - /** This class evaluates a selected subset of terms of the - * tree. In the protected constructor, one can constraint the - * initialization of the evaluation tree to a given number of - * terms in the beginning. Using this constructor, one has to make - * sure, that the terms in the beginning do not refer to terms - * behind the initial part. */ - class FormulaCustomEvaluator - { - protected: - /** The evaluation tree. */ - EvalTree etree; - /** The custom tree indices to be evaluated. */ - vector<int> terms; - public: - /** Construct from FormulaParser and given list of terms. */ - FormulaCustomEvaluator(const FormulaParser &fp, vector<int> ts) - : etree(fp.otree), terms(std::move(ts)) - { - } - /** Construct from OperationTree and given list of terms. */ - FormulaCustomEvaluator(const OperationTree &ot, vector<int> ts) - : etree(ot), terms(std::move(ts)) - { - } - /** Evaluate the terms using the given AtomValues and load the - * results using the given loader. The loader is called for - * each term in the order of the terms. */ - void eval(const AtomValues &av, FormulaEvalLoader &loader); - protected: - FormulaCustomEvaluator(const FormulaParser &fp) - : etree(fp.otree, fp.last_formula()), terms(fp.formulas) - { - } - }; - - /** This class evaluates zero derivatives of the FormulaParser. */ - class FormulaEvaluator : public FormulaCustomEvaluator - { - public: - /** Construct from FormulaParser. */ - FormulaEvaluator(const FormulaParser &fp) - : FormulaCustomEvaluator(fp) - { - } - }; - - /** This is a pure virtual class defining an interface for all - * classes which will load the results of formula derivative - * evaluations. */ - class FormulaDerEvalLoader - { - public: - virtual ~FormulaDerEvalLoader() = default; - /** This loads the result of the derivative of the given - * order. The semantics of i is the same as in - * FormulaEvalLoader::load. The indices of variables with - * respect to which the derivative was taken are stored in - * memory pointed by vars. These are the tree indices of the - * variables. */ - virtual void load(int i, int order, const int *vars, double res) = 0; - }; - - /** This class is a utility class representing the tensor - * multindex. It can basically increment itself, and calculate - * its offset in the folded tensor. */ - class FoldMultiIndex - { - /** Number of variables. */ - int nvar; - /** Dimension. */ - int ord; - /** The multiindex. */ - std::unique_ptr<int[]> data; - public: - /** Initializes to the zero derivative. Order is 0, data is - * empty. */ - FoldMultiIndex(int nv); - /** Initializes the multiindex to zeros or given i. */ - FoldMultiIndex(int nv, int order, int i = 0); - /** Makes a new multiindex of the same order applying a given - * mapping to the indices. The mapping is supposed to be monotone. */ - FoldMultiIndex(int nv, const FoldMultiIndex &mi, const vector<int> &mp); - /** Shifting constructor. This adds a given number of orders - * to the end, copying the last item to the newly added items, - * keeping the index ordered. If the index was empty (zero-th - * dimension), then zeros are added. */ - FoldMultiIndex(const FoldMultiIndex &fmi, int new_orders); - /** Copy constructor. */ - FoldMultiIndex(const FoldMultiIndex &fmi); - /** Desctructor. */ - virtual ~FoldMultiIndex() = default; - /** Assignment operator. */ - const FoldMultiIndex &operator=(const FoldMultiIndex &fmi); - /** Operator < implementing lexicographic ordering within one - * order, increasing order across orders. */ - bool operator<(const FoldMultiIndex &fmi) const; - bool operator==(const FoldMultiIndex &fmi) const; - /** Increment the multiindex. */ - void increment(); - /** Return offset of the multiindex in the folded tensor. */ - int offset() const; - const int & - operator[](int i) const - { - return data[i]; - } - /** Return order of the multiindex, i.e. dimension of the - * tensor. */ - int - order() const - { - return ord; - } - /** Return the number of variables. */ - int - nv() const - { - return nvar; - } - /** Return the data. */ - const int * - ind() const - { - return data.get(); - } - /** Return true if the end of the tensor is reached. The - * result of a subsequent increment should be considered - * unpredictable. */ - bool - past_the_end() const - { - return (ord == 0) || (data[0] == nvar); - } - /** Prints the multiindex in the brackets. */ - void print() const; - private: - static int offset_recurse(int *data, int len, int nv); - }; - - /** This class evaluates derivatives of the FormulaParser. */ - class FormulaDerEvaluator - { - /** Its own instance of EvalTree. */ - EvalTree etree; - /** The indices of derivatives for each formula. This is a - * const copy FormulaParser::ders. We do not allocate nor - * deallocate anything here. */ - vector<const FormulaDerivatives *> ders; - /** A copy of tree indices corresponding to atoms to with - * respect the derivatives were taken. */ - vector<int> der_atoms; - public: - /** Construct the object from FormulaParser. */ - FormulaDerEvaluator(const FormulaParser &fp); - /** Evaluate the derivatives from the FormulaParser wrt to all - * atoms in variables vector at the given AtomValues. The - * given loader is used for output. */ - void eval(const AtomValues &av, FormulaDerEvalLoader &loader, int order); - /** Evaluate the derivatives from the FormulaParser wrt to a - * selection of atoms of the atoms in der_atoms vector at the - * given AtomValues. The selection is given by a monotone - * mapping to the indices (not values) of the der_atoms. */ - void eval(const vector<int> &mp, const AtomValues &av, FormulaDerEvalLoader &loader, - int order); - }; -}; - -#endif diff --git a/dynare++/parser/cc/location.hh b/dynare++/parser/cc/location.hh deleted file mode 100644 index 43a2839cef8332dae1e6877daa0481c967df9d0f..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/location.hh +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2006, Ondra Kamenik - -// $Id: location.h 762 2006-05-22 13:00:07Z kamenik $ - -// Purpose: This file defines macros for lex and bison so that the -// very primitive location tracking would be enabled. The location of -// a token is given by offset of its first character. The offset is -// relative to the number which is (and must be) initialized before -// parsing. This file is to be included to the top of bison and lex -// sources. - -// How to use: in preamble of bison and flex, you must include this -// file and declare extern YYLTYPE prefix##lloc. In addition, in flex, -// you must define int prefix##ll =0; and use macro SET_LLOC(prefix) -// in EVERY action consuming material (this can be done with #define -// YY_USER_ACTION) and in bison you must use option %locations. - -#ifndef OG_LOCATION_H -#define OG_LOCATION_H - -namespace ogp -{ - struct location_type - { - int off{0}; // offset of the token - int ll{0}; // length ot the token - location_type() = default; - }; -}; - -// set current off to the first off and add all lengths -#define YYLLOC_DEFAULT(Current, Rhs, N) \ - { \ - (Current).off = (Rhs)[1].off; \ - (Current).ll = 0; \ - for (int i = 1; i <= N; i++) \ - (Current).ll += (Rhs)[i].ll; \ - } - -#define SET_LLOC(prefix) (prefix ## lloc.off += prefix ## lloc.ll, prefix ## lloc.ll = prefix ## leng) - -#endif diff --git a/dynare++/parser/cc/matrix.ll b/dynare++/parser/cc/matrix.ll deleted file mode 100644 index ca710f25899afb72faea8cdd78d2d21ad8e95acd..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix.ll +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -%{ -#include <string> - -#include "location.hh" -#include "matrix_tab.hh" - -extern void matrix_error(std::string); - -#define YY_USER_ACTION SET_LLOC(matrix_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="matrix_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* ignore spaces and commas */ -[ \t,] - /* new row */ -\r\n {return NEW_ROW;} -\n {return NEW_ROW;} -;[ \t]*\n {return NEW_ROW;} -;[ \t]*\r\n {return NEW_ROW;} -; {return NEW_ROW;} - -[+-]?(([0-9]*\.?[0-9]+)|([0-9]+\.))([edED][-+]?[0-9]+)? { - matrix_lval.val = strtod(matrix_text, NULL); - return DNUMBER; -} - -. { - using namespace std::string_literals; - matrix_error("Unrecognized character "s + matrix_text); -} - -%% - -int -matrix_wrap() -{ - return 1; -} - -void -matrix__destroy_buffer(void* p) -{ - matrix__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/parser/cc/matrix.yy b/dynare++/parser/cc/matrix.yy deleted file mode 100644 index b80f3aef7126e2df43a13293b14b116b7a4918ff..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix.yy +++ /dev/null @@ -1,89 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -%code requires -{ -#include "location.hh" -#define MATRIX_LTYPE ogp::location_type -} - -%code -{ -#include "matrix_parser.hh" - -void matrix_error(std::string); -int matrix_lex(); -extern ogp::MatrixParser* mparser; -} - -%union -{ - double val; - int integer; -} - -%token NEW_ROW -%token <val> DNUMBER - -%define api.prefix {matrix_}; - -%locations -%defines -%define parse.error verbose - -%% - -matrix : first_row other_rows - | first_row other_rows empty_rows - | first_row empty_rows other_rows empty_rows - | first_row empty_rows other_rows - | empty_rows first_row other_rows - | empty_rows first_row other_rows empty_rows - | empty_rows first_row empty_rows other_rows empty_rows - | empty_rows first_row empty_rows - | first_row empty_rows - | empty_rows first_row - | first_row - | empty_rows - ; - -empty_rows : empty_rows NEW_ROW | NEW_ROW; - -lod : DNUMBER {mparser->add_item($1);} - | lod DNUMBER {mparser->add_item($2);} - ; - -first_row : lod; - -other_rows : other_rows one_row | other_rows empty_rows one_row |one_row ; - -one_row : NEW_ROW {mparser->start_row();} lod; - - -%% - -void -matrix_error(std::string s) -{ - mparser->error(std::move(s)); -} - - diff --git a/dynare++/parser/cc/matrix_parser.cc b/dynare++/parser/cc/matrix_parser.cc deleted file mode 100644 index 91d90a01f5193c7382106789f778fba9beadce78..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix_parser.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "parser_exception.hh" -#include "matrix_parser.hh" -#include "location.hh" -#include "matrix_tab.hh" - -#include <algorithm> - -using namespace ogp; - -/** A global symbol for passing info to the MatrixParser from - * matrix_parse(). */ -MatrixParser *mparser; - -/** The declaration of functions defined in matrix_ll.cc and - * matrix_tab.cc generated from matrix.lex and matrix.y. */ -void *matrix__scan_string(const char *); -void matrix__destroy_buffer(void *); -int matrix_parse(); -extern ogp::location_type matrix_lloc; - -void -MatrixParser::parse(const string &stream) -{ - // reinitialize the object - data.clear(); - row_lengths.clear(); - nc = 0; - // allocate temporary buffer and parse - matrix_lloc.off = 0; - matrix_lloc.ll = 0; - void *p = matrix__scan_string(stream.c_str()); - mparser = this; - matrix_parse(); - matrix__destroy_buffer(p); -} - -void -MatrixParser::add_item(double v) -{ - data.push_back(v); - if (row_lengths.size() == 0) - row_lengths.push_back(0); - (row_lengths.back())++; - nc = std::max(nc, row_lengths.back()); -} - -void -MatrixParser::start_row() -{ - row_lengths.push_back(0); -} - -void -MatrixParser::error(string mes) const -{ - throw ParserException(std::move(mes), matrix_lloc.off); -} - -int -MatrixParser::find_first_non_empty_row(int start) const -{ - int r = start; - while (r < static_cast<int>(row_lengths.size()) && row_lengths[r] == 0) - r++; - return r; -} - -MPIterator -MatrixParser::begin() const -{ - MPIterator it(*this); - return it; -} - -MPIterator -MatrixParser::end() const -{ - MPIterator it(*this, "end"); - return it; -} - -MPIterator::MPIterator(const MatrixParser &mp) - : p(&mp), i(0), r(mp.find_first_non_empty_row()) -{ -} - -MPIterator::MPIterator(const MatrixParser &mp, const char *dummy) - : p(&mp), i(mp.data.size()), r(mp.row_lengths.size()) -{ -} - -MPIterator & -MPIterator::operator++() -{ - i++; - c++; - if (p->row_lengths[r] <= c) - { - c = 0; - r = p->find_first_non_empty_row(r+1); - } - return *this; -} diff --git a/dynare++/parser/cc/matrix_parser.hh b/dynare++/parser/cc/matrix_parser.hh deleted file mode 100644 index 3a7c9c2962b11cdf24fab1996c7a5b366e7d8d16..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix_parser.hh +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_MATRIX_PARSER -#define OGP_MATRIX_PARSER - -#include <vector> -#include <string> - -namespace ogp -{ - using std::vector; - - /** This class reads the given string and parses it as a - * matrix. The matrix is read row by row. The row delimiter is - * either a newline character or semicolon (first newline - * character after the semicolon is ignored), the column delimiter - * is either blank character or comma. A different number of items - * in the row is not reconciliated, we do not construct a matrix - * here. The class provides only an iterator to go through all - * read items, the iterator provides information on row number and - * column number of the item. */ - class MPIterator; - class MatrixParser - { - friend class MPIterator; - protected: - /** Raw data as they were read. */ - vector<double> data; - /** Number of items in each row. */ - vector<int> row_lengths; - /** Maximum number of row lengths. */ - int nc{0}; - public: - MatrixParser() = default; - MatrixParser(const MatrixParser &mp) = default; - virtual ~MatrixParser() = default; - /** Return a number of read rows. */ - int - nrows() const - { - return static_cast<int>(row_lengths.size()); - } - /** Return a maximum number of items in the rows. */ - int - ncols() const - { - return nc; - } - /** Parses a given data. This initializes the object data. */ - void parse(const std::string &stream); - /** Adds newly read item. This should be called from bison - * parser. */ - void add_item(double v); - /** Starts a new row. This should be called from bison - * parser. */ - void start_row(); - /** Process a parse error from the parser. */ - void error(std::string mes) const; - /** Return begin iterator. */ - MPIterator begin() const; - /** Return end iterator. */ - MPIterator end() const; - protected: - /** Returns an index of the first non-empty row starting at - * start. If the start row is non-empty, returns the start. If - * there is no other non-empty row, returns - * row_lengths.size(). */ - int find_first_non_empty_row(int start = 0) const; - }; - - /** This is an iterator intended to iterate through a matrix parsed - * by MatrixParser. The iterator provides only read-only access. */ - class MPIterator - { - friend class MatrixParser; - protected: - /** Reference to the matrix parser. */ - const MatrixParser *p{nullptr}; - /** The index of the pointed item in the matrix parser. */ - unsigned int i{0}; - /** The column number of the pointed item starting from zero. */ - int c{0}; - /** The row number of the pointed item starting from zero. */ - int r{0}; - - public: - MPIterator() = default; - /** Constructs an iterator pointing to the beginning of the - * parsed matrix. */ - MPIterator(const MatrixParser &mp); - /** Constructs an iterator pointing to the past-the-end of the - * parsed matrix. */ - MPIterator(const MatrixParser &mp, const char *dummy); - /** Return read-only reference to the pointed item. */ - const double & - operator*() const - { - return p->data[i]; - } - /** Return a row index of the pointed item. */ - int - row() const - { - return r; - } - /** Return a column index of the pointed item. */ - int - col() const - { - return c; - } - /** Assignment operator. */ - MPIterator &operator=(const MPIterator &it) = default; - /** Return true if the iterators are the same, this is if they - * have the same underlying object and the same item index. */ - bool - operator==(const MPIterator &it) const - { - return it.p == p && it.i == i; - } - /** Negative of the operator==. */ - bool - operator!=(const MPIterator &it) const - { - return !(it == *this); - } - /** Increment operator. */ - MPIterator &operator++(); - }; -}; - -#endif diff --git a/dynare++/parser/cc/parser_exception.cc b/dynare++/parser/cc/parser_exception.cc deleted file mode 100644 index 8659c33363a81276b839de4d7f27be893b5ca930..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/parser_exception.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "parser_exception.hh" - -using namespace ogp; - -ParserException::ParserException(string m, int offset) - : mes(std::move(m)), off(offset), - aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ -} - -ParserException::ParserException(string m, const char *dum, int i1) - : mes(std::move(m)), off(0), - aux_i1(i1), aux_i2(-1), aux_i3(-1) -{ -} - -ParserException::ParserException(string m, const char *dum, int i1, int i2) - : mes(std::move(m)), off(0), - aux_i1(i1), aux_i2(i2), aux_i3(-1) -{ -} - -ParserException::ParserException(string m, const char *dum, int i1, int i2, int i3) - : mes(std::move(m)), off(0), - aux_i1(i1), aux_i2(i2), aux_i3(i3) -{ -} - -ParserException::ParserException(const ParserException &m, int plus_offset) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - off += plus_offset; -} - -ParserException::ParserException(const ParserException &m, const char *dum, int i) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - aux_i3 = m.aux_i2; - aux_i2 = m.aux_i1; - aux_i1 = i; -} - -ParserException::ParserException(const ParserException &m, const char *dum, int i1, int i2) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - aux_i3 = m.aux_i1; - aux_i2 = i2; - aux_i1 = i1; -} - -ParserException::ParserException(const ParserException &m, const char *dum, int i1, int i2, int i3) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - aux_i3 = i3; - aux_i2 = i2; - aux_i1 = i1; -} - -void -ParserException::copy(const ParserException &e) -{ - mes = e.mes; - off = e.off; - aux_i1 = e.aux_i1; - aux_i2 = e.aux_i2; - aux_i3 = e.aux_i3; -} diff --git a/dynare++/parser/cc/parser_exception.hh b/dynare++/parser/cc/parser_exception.hh deleted file mode 100644 index d8b69fe1f945f1931689aaa83027504f3aa93061..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/parser_exception.hh +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OG_FORMULA_PARSER_H -#define OG_FORMULA_PARSER_H - -#include <string> - -namespace ogp -{ - using std::string; - - /** This is an easy exception, which, besides the message, stores - * also an offset of the parse error. Since we might need to track - * the argument number and for example the filed in the argument - * which caused the error, we add three integers, which have no - * semantics here. They should be documented in the function which - * throws an exception and sets them. Their default value is -1, - * which means they have not been set. */ - class ParserException - { - protected: - string mes; - int off; - int aux_i1; - int aux_i2; - int aux_i3; - public: - ParserException(string m, int offset); - ParserException(string m, const char *dum, int i1); - ParserException(string m, const char *dum, int i1, int i2); - ParserException(string m, const char *dum, int i1, int i2, int i3); - ParserException(const ParserException &e, int plus_offset); - /** Makes a copy and pushes given integer to aux_i1 shuffling - * others and forgetting the last. */ - ParserException(const ParserException &e, const char *dum, int i); - /** Makes a copy and pushes given two integers to aux_i1 and aux_i2 shuffling - * others and forgetting the last two. */ - ParserException(const ParserException &e, const char *dum, int i1, int i2); - /** Makes a copy and pushes given three integers to aux_i1, aux_i2, aus_i3 shuffling - * others and forgetting the last three. */ - ParserException(const ParserException &e, const char *dum, int i1, int i2, int i3); - ParserException(const ParserException &e) = default; - virtual ~ParserException() = default; - const string & - message() const - { - return mes; - } - int - offset() const - { - return off; - } - const int & - i1() const - { - return aux_i1; - } - int & - i1() - { - return aux_i1; - } - const int & - i2() const - { - return aux_i2; - } - int & - i2() - { - return aux_i2; - } - const int & - i3() const - { - return aux_i3; - } - int & - i3() - { - return aux_i3; - } - protected: - void copy(const ParserException &e); - }; -}; - -#endif diff --git a/dynare++/parser/cc/static_atoms.cc b/dynare++/parser/cc/static_atoms.cc deleted file mode 100644 index cc64d98979d6e8529d401029554955d758567b21..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_atoms.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "static_atoms.hh" -#include "utils/cc/exception.hh" - -using namespace ogp; - -void -StaticAtoms::import_atoms(const DynamicAtoms &da, OperationTree &otree, Tintintmap &tmap) -{ - Constants::import_constants(da, otree, tmap); - - for (int i = 0; i < da.get_name_storage().num(); i++) - { - const string &name = da.get_name_storage().get_name(i); - register_name(name); - int tnew = otree.add_nulary(); - assign(name, tnew); - if (da.is_referenced(name)) - { - const DynamicAtoms::Tlagmap &lmap = da.lagmap(name); - for (const auto &it : lmap) - { - int told = it.second; - tmap.emplace(told, tnew); - } - } - } -} - -int -StaticAtoms::check(const string &name) const -{ - if (DynamicAtoms::is_string_constant(name)) - return Constants::check(name); - else - return check_variable(name); -} - -int -StaticAtoms::index(const string &name) const -{ - auto it = vars.find(name); - if (it == vars.end()) - return -1; - else - return it->second; -} - -void -StaticAtoms::assign(const string &name, int t) -{ - if (DynamicAtoms::is_string_constant(name)) - { - double val = std::stod(name); - add_constant(t, val); - } - else - { - varnames.insert(name); - vars.emplace(name, t); - indices.emplace(t, name); - } -} - -vector<int> -StaticAtoms::variables() const -{ - vector<int> res; - for (const auto &var : vars) - res.push_back(var.second); - return res; -} - -void -StaticAtoms::register_name(string name) -{ - varnames.insert(name); - varorder.push_back(std::move(name)); -} - -void -StaticAtoms::print() const -{ - std::cout << "constants:\n"; - Constants::print(); - std::cout << "variable names:\n"; - varnames.print(); - std::cout << "map to tree indices:\n"; - for (auto var : vars) - std::cout << var.first << "\t→\t" << var.second << "\n"; -} diff --git a/dynare++/parser/cc/static_atoms.hh b/dynare++/parser/cc/static_atoms.hh deleted file mode 100644 index bb2d954fe6001e0e075bff71f69db9c68846cdf2..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_atoms.hh +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_STATIC_ATOMS -#define OGP_STATIC_ATOMS - -#include "dynamic_atoms.hh" - -namespace ogp -{ - class StaticAtoms : public Atoms, public Constants - { - protected: - using Tvarmap = map<string, int>; - using Tinvmap = map<int, string>; - /** Storage for names. */ - NameStorage varnames; - /** Outer order of variables. */ - vector<string> varorder; - /** This is the map mapping a variable name to the tree - * index. */ - Tvarmap vars; - /** This is the inverse mapping. It maps a tree index to the - * variable name. */ - Tinvmap indices; - public: - StaticAtoms() = default; - /** Conversion from DynamicAtoms. This takes all atoms from - * the DynamicAtoms and adds its static version. The new tree - * indices are allocated in the passed OperationTree. Whole - * the process is traced in the map mapping old tree indices - * to new tree indices. */ - StaticAtoms(const DynamicAtoms &da, OperationTree &otree, Tintintmap &tmap) - : Atoms(), Constants(), varnames(), varorder(), vars() - { - import_atoms(da, otree, tmap); - } - /* Destructor. */ - ~StaticAtoms() override = default; - /** This imports atoms from dynamic atoms inserting the new - * tree indices to the given tree (including constants). The - * mapping from old atoms to new atoms is traced in tmap. */ - void import_atoms(const DynamicAtoms &da, OperationTree &otree, - Tintintmap &tmap); - /** If the name is constant, it returns its tree index if the - * constant is registered in Constants, it returns -1 - * otherwise. If the name is not constant, it returns result - * from check_variable, which is implemented by a subclass. */ - int check(const string &name) const override; - /** This assigns a given tree index to the variable name. The - * name should have been checked before the call. */ - void assign(const string &name, int t) override; - int - nvar() const override - { - return varnames.num(); - } - /** This returns a vector of all variables. */ - vector<int> variables() const override; - /** This returns a tree index of the given variable. */ - int index(const string &name) const; - /** This returns a name in a outer ordering. (There is no other ordering.) */ - const string & - name(int i) const - { - return varorder[i]; - } - /** Debug print. */ - void print() const override; - /** This registers a variable. A subclass can reimplement - * this, for example, to ensure uniqueness of the - * name. However, this method should be always called in - * overriding methods to do the registering job. */ - virtual void register_name(string name); - /** Return the name storage to allow querying to other - * classes. */ - const NameStorage & - get_name_storage() const - { - return varnames; - } - protected: - /** This checks the variable. The implementing subclass might - * want to throw an exception if the variable has not been - * registered. */ - virtual int check_variable(const string &name) const = 0; - }; -}; - -#endif diff --git a/dynare++/parser/cc/static_fine_atoms.cc b/dynare++/parser/cc/static_fine_atoms.cc deleted file mode 100644 index 4d7406c14e624e0a19079de23aed1763d5fe5f3d..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_fine_atoms.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "utils/cc/exception.hh" - -#include "static_fine_atoms.hh" -#include "parser_exception.hh" - -using namespace ogp; - -void -StaticFineAtoms::import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap) -{ - StaticAtoms::import_atoms(fa, otree, tmap); - - // we just need to put parameters, endovars, and exovars to - // respective vectors, the names are already in the storage - - // parameters - auto &fa_params = fa.get_params(); - for (const auto &fa_param : fa_params) - register_param(fa_param); - - // endogenous - auto &fa_endovars = fa.get_endovars(); - for (const auto &fa_endovar : fa_endovars) - register_endo(fa_endovar); - - // exogenous - auto &fa_exovars = fa.get_exovars(); - for (const auto &fa_exovar : fa_exovars) - register_exo(fa_exovar); - - parsing_finished(); -} - -void -StaticFineAtoms::import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap, - const char *dummy) -{ - StaticAtoms::import_atoms(fa, otree, tmap); - - // we just need to put parameters, endovars, and exovars to - // respective vectors, the names are already in the storage - - // parameters - auto &fa_params = fa.get_params(); - for (const auto &fa_param : fa_params) - register_param(fa_param); - - // endogenous - auto &fa_endovars = fa.get_endovars(); - for (unsigned int i = 0; i < fa_endovars.size(); i++) - register_endo(fa_endovars[fa.y2outer_endo()[i]]); - - // exogenous - auto &fa_exovars = fa.get_exovars(); - for (unsigned int i = 0; i < fa_exovars.size(); i++) - register_exo(fa_exovars[fa.y2outer_exo()[i]]); - - parsing_finished(); -} - -int -StaticFineAtoms::check_variable(const string &name) const -{ - if (!varnames.query(name)) - throw ParserException("Variable <"+name+"> not declared.", 0); - return index(name); -} - -void -StaticFineAtoms::parsing_finished() -{ - // build der_atoms, and endo_atoms_map and exo_atoms_map - der_atoms.clear(); - endo_atoms_map.clear(); - exo_atoms_map.clear(); - - // go through all endo and exo insert tree indices, ignore names - // whose tree index is -1 (those which are not referenced) - for (auto &endovar : endovars) - { - int t = index(endovar); - if (t != -1) - { - endo_atoms_map.push_back(der_atoms.size()); - der_atoms.push_back(t); - } - } - for (auto &exovar : exovars) - { - int t = index(exovar); - if (t != -1) - { - exo_atoms_map.push_back(der_atoms.size()); - der_atoms.push_back(t); - } - } -} - -int -StaticFineAtoms::name2outer_param(const string &name) const -{ - auto it = param_outer_map.find(name); - if (it == param_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not a parameter in StaticFineAtoms::name2outer_param"); - return it->second; -} - -int -StaticFineAtoms::name2outer_endo(const string &name) const -{ - auto it = endo_outer_map.find(name); - if (it == endo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an endogenous variable in StaticFineAtoms::name2outer_endo"); - return it->second; -} - -int -StaticFineAtoms::name2outer_exo(const string &name) const -{ - auto it = exo_outer_map.find(name); - if (it == exo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an exogenous variable in StaticFineAtoms::name2outer_exo"); - return it->second; -} - -void -StaticFineAtoms::register_uniq_endo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Endogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - register_endo(std::move(name)); -} - -void -StaticFineAtoms::register_uniq_exo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Exogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - register_exo(std::move(name)); -} - -void -StaticFineAtoms::register_uniq_param(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Parameter <"+name+"> is not unique.", 0); - varnames.insert(name); - register_param(std::move(name)); -} - -void -StaticFineAtoms::print() const -{ - StaticAtoms::print(); - std::cout << "endo atoms map:\n"; - for (unsigned int i = 0; i < endo_atoms_map.size(); i++) - std::cout << i << " → " << endo_atoms_map[i] << "\n"; - std::cout << "exo atoms map:\n"; - for (unsigned int i = 0; i < exo_atoms_map.size(); i++) - std::cout << i << " → " << exo_atoms_map[i] << "\n"; - std::cout << "der atoms:\n"; - for (unsigned int i = 0; i < der_atoms.size(); i++) - std::cout << i << "\t" << der_atoms[i] << "\n"; -} - -void -StaticFineAtoms::register_endo(string name) -{ - if (!varnames.query(name)) - throw ogp::ParserException("Endogenous variable <"+name+"> not found in storage.", 0); - endovars.push_back(name); - endo_outer_map.emplace(std::move(name), endovars.size()-1); -} - -void -StaticFineAtoms::register_exo(string name) -{ - if (!varnames.query(name)) - throw ogp::ParserException("Exogenous variable <"+name+"> not found in storage.", 0); - exovars.push_back(name); - exo_outer_map.emplace(std::move(name), exovars.size()-1); -} - -void -StaticFineAtoms::register_param(string name) -{ - if (!varnames.query(name)) - throw ogp::ParserException("Parameter <"+name+"> not found in storage.", 0); - params.push_back(name); - param_outer_map.emplace(std::move(name), params.size()-1); -} diff --git a/dynare++/parser/cc/static_fine_atoms.hh b/dynare++/parser/cc/static_fine_atoms.hh deleted file mode 100644 index 482d5e33d21460612f5228a600892f3fc1c72187..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_fine_atoms.hh +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGP_STATIC_FINE_ATOMS_H -#define OGP_STATIC_FINE_ATOMS_H - -#include "static_atoms.hh" -#include "fine_atoms.hh" - -namespace ogp -{ - /** This class represents static atoms distinguishing between - * parameters, endogenous and exogenous variables. The class - * maintains also ordering of all three categories (referenced as - * outer or inner, since there is only one ordering). It can be - * constructed either from scratch, or from fine dynamic atoms. In - * the latter case, one can decide if the ordering of this static - * atoms should be internal or external ordering of the original - * dynamic fine atoms. */ - class StaticFineAtoms : public StaticAtoms - { - public: - using Tintintmap = map<int, int>; - protected: - using Tvarintmap = map<string, int>; - private: - /** The vector of parameter names, gives the parameter - * ordering. */ - vector<string> params; - /** A map mappping a parameter name to an index in the ordering. */ - Tvarintmap param_outer_map; - /** The vector of endogenous variables. This defines the order - * like parameters. */ - vector<string> endovars; - /** A map mapping a name of an endogenous variable to an index - * in the ordering. */ - Tvarintmap endo_outer_map; - /** The vector of exogenous variables. Also defines the order - * like parameters and endovars. */ - vector<string> exovars; - /** A map mapping a name of an exogenous variable to an index - * in the outer ordering. */ - Tvarintmap exo_outer_map; - /** This vector defines a set of atoms as tree indices used - * for differentiation. The order of the atoms in is the - * concatenation of the outer ordering of endogenous and - * exogenous. This vector is setup by parsing_finished() and - * is returned by variables(). */ - vector<int> der_atoms; - /** This is a mapping from endogenous atoms to all atoms in - * der_atoms member. The mapping maps index in endogenous atom - * ordering to index (not value) in der_atoms. It is useful if - * one wants to evaluate derivatives wrt only endogenous - * variables. It is set by parsing_finished(). By definition, - * it is monotone. */ - vector<int> endo_atoms_map; - /** This is a mapping from exogenous atoms to all atoms in - * der_atoms member. It is the same as endo_atoms_map for - * atoms of exogenous variables. */ - vector<int> exo_atoms_map; - public: - StaticFineAtoms() = default; - /** Conversion from dynamic FineAtoms taking its outer - * ordering as ordering of parameters, endogenous and - * exogenous. A biproduct is an integer to integer map mapping - * tree indices of the dynamic atoms to tree indices of the - * static atoms. */ - StaticFineAtoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap) - { - StaticFineAtoms::import_atoms(fa, otree, tmap); - } - /** Conversion from dynamic FineAtoms taking its internal - * ordering as ordering of parameters, endogenous and - * exogenous. A biproduct is an integer to integer map mapping - * tree indices of the dynamic atoms to tree indices of the - * static atoms. */ - StaticFineAtoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap, - const char *dummy) - { - StaticFineAtoms::import_atoms(fa, otree, tmap, dummy); - } - ~StaticFineAtoms() override = default; - /** This adds atoms from dynamic atoms inserting new tree - * indices to the given tree and tracing the mapping from old - * atoms to new atoms in tmap. The ordering of the static - * atoms is the same as outer ordering of dynamic atoms. */ - void import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap); - /** This adds atoms from dynamic atoms inserting new tree - * indices to the given tree and tracing the mapping from old - * atoms to new atoms in tmap. The ordering of the static - * atoms is the same as internal ordering of dynamic atoms. */ - void import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap, - const char *dummy); - /** Overrides StaticAtoms::check_variable so that the error - * would be raised if the variable name is not declared. A - * variable is declared by inserting it to - * StaticAtoms::varnames, which is done with registering - * methods. This a responsibility of a subclass. */ - int check_variable(const string &name) const override; - /** Return an (external) ordering of parameters. */ - const vector<string> & - get_params() const - { - return params; - } - /** Return an external ordering of endogenous variables. */ - const vector<string> & - get_endovars() const - { - return endovars; - } - /** Return an external ordering of exogenous variables. */ - const vector<string> & - get_exovars() const - { - return exovars; - } - /** This constructs der_atoms, and the endo_endoms_map and - * exo_atoms_map, which can be created only after the parsing - * is finished. */ - void parsing_finished(); - /** Return the atoms with respect to which we are going to - * differentiate. */ - vector<int> - variables() const override - { - return der_atoms; - } - /** Return the endo_atoms_map. */ - const vector<int> & - get_endo_atoms_map() const - { - return endo_atoms_map; - } - /** Return the exo_atoms_map. */ - const vector<int> & - get_exo_atoms_map() const - { - return endo_atoms_map; - } - /** Return an index in the outer ordering of a given - * parameter. An exception is thrown if the name is not a - * parameter. */ - int name2outer_param(const string &name) const; - /** Return an index in the outer ordering of a given - * endogenous variable. An exception is thrown if the name is not a - * and endogenous variable. */ - int name2outer_endo(const string &name) const; - /** Return an index in the outer ordering of a given - * exogenous variable. An exception is thrown if the name is not a - * and exogenous variable. */ - int name2outer_exo(const string &name) const; - /** Return the number of endogenous variables. */ - int - ny() const - { - return endovars.size(); - } - /** Return the number of exogenous variables. */ - int - nexo() const - { - return static_cast<int>(exovars.size()); - } - /** Return the number of parameters. */ - int - np() const - { - return static_cast<int>(params.size()); - } - /** Register unique endogenous variable name. The order of - * calls defines the endo outer ordering. The method is - * virtual, since a superclass may want to do some additional - * action. */ - virtual void register_uniq_endo(string name); - /** Register unique exogenous variable name. The order of - * calls defines the exo outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_exo(string name); - /** Register unique parameter name. The order of calls defines - * the param outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_param(string name); - /** Debug print. */ - void print() const override; - private: - /** Add endogenous variable name, which is already in the name - * storage. */ - void register_endo(string name); - /** Add exogenous variable name, which is already in the name - * storage. */ - void register_exo(string name); - /** Add parameter name, which is already in the name - * storage. */ - void register_param(string name); - }; -}; - -#endif diff --git a/dynare++/parser/cc/tree.cc b/dynare++/parser/cc/tree.cc deleted file mode 100644 index 7d05a13e3d9074a11a0f09871fc015cb852787dc..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/tree.cc +++ /dev/null @@ -1,1011 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "utils/cc/exception.hh" - -#include "tree.hh" - -#include <cmath> -#include <limits> -#include <sstream> -#include <iomanip> - -using namespace ogp; - -/** Here we initialize OperationTree to contain only zero, one, nan - * and two_over_pi terms. */ -OperationTree::OperationTree() -{ - last_nulary = -1; - // allocate space for the constants - for (int i = 0; i < num_constants; i++) - add_nulary(); -} - -int -OperationTree::add_nulary() -{ - int op = terms.size(); - terms.push_back({}); - _Tintset s; - s.insert(op); - nul_incidence.push_back(s); - derivatives.push_back({}); - last_nulary = op; - return op; -} - -int -OperationTree::add_unary(code_t code, int op) -{ - if (op == zero - && (code == code_t::UMINUS - || code == code_t::SIN - || code == code_t::TAN - || code == code_t::SQRT - || code == code_t::ERF)) - return zero; - if ((op == zero && code == code_t::LOG) || op == nan) - return nan; - if (op == zero && (code == code_t::EXP - || code == code_t::COS - || code == code_t::ERFC)) - return one; - - Operation unary(code, op); - auto i = opmap.find(unary); - if (i == opmap.end()) - { - int newop = terms.size(); - // add to the terms - terms.push_back(unary); - // copy incidence of the operand - nul_incidence.push_back(nul_incidence[op]); - // insert it to opmap - opmap.emplace(unary, newop); - // add empty map of derivatives - _Tderivmap empty; - derivatives.push_back(empty); - return newop; - } - return i->second; -} - -int -OperationTree::add_binary(code_t code, int op1, int op2) -{ - // quick exits for special values - if (op1 == nan || op2 == nan) - return nan; - // for plus - if (code == code_t::PLUS) - { - if (op1 == zero && op2 == zero) - return zero; - else if (op1 == zero) - return op2; - else if (op2 == zero) - return op1; - } - // for minus - if (code == code_t::MINUS) - { - if (op1 == zero && op2 == zero) - return zero; - else if (op1 == zero) - return add_unary(code_t::UMINUS, op2); - else if (op2 == zero) - return op1; - } - // for times - if (code == code_t::TIMES) - { - if (op1 == zero || op2 == zero) - return zero; - else if (op1 == one) - return op2; - else if (op2 == one) - return op1; - } - // for divide - if (code == code_t::DIVIDE) - { - if (op1 == op2) - return one; - else if (op1 == zero) - return zero; - else if (op2 == zero) - return nan; - } - // for power - if (code == code_t::POWER) - { - if (op1 == zero && op2 == zero) - return nan; - else if (op1 == zero) - return zero; - else if (op2 == zero) - return one; - else if (op1 == one) - return one; - else if (op2 == one) - return op1; - } - - // order operands of commutative operations - if (code == code_t::TIMES || code == code_t::PLUS) - if (op1 > op2) - { - int tmp = op1; - op1 = op2; - op2 = tmp; - } - - // construct operation and check/add it - Operation binary(code, op1, op2); - auto i = opmap.find(binary); - if (i == opmap.end()) - { - int newop = terms.size(); - terms.push_back(binary); - // sum both sets of incidenting nulary operations - nul_incidence.push_back(nul_incidence[op1]); - nul_incidence.back().insert(nul_incidence[op2].begin(), nul_incidence[op2].end()); - // add to opmap - opmap.emplace(binary, newop); - // add empty map of derivatives - _Tderivmap empty; - derivatives.push_back(empty); - return newop; - } - return i->second; -} - -int -OperationTree::add_derivative(int t, int v) -{ - if (t < 0 || t >= static_cast<int>(terms.size())) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong value for tree index in OperationTree::add_derivative"); - - // quick returns for nulary terms or empty incidence - if (terms[t].nary() == 0 && t != v) - return zero; - - if (terms[t].nary() == 0 && t == v) - return one; - - if (nul_incidence[t].end() == nul_incidence[t].find(v)) - return zero; - - // quick return if the derivative has been registered - auto i = derivatives[t].find(v); - if (i != derivatives[t].end()) - return i->second; - - int res = -1; - switch (terms[t].getCode()) - { - case code_t::UMINUS: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_unary(code_t::UMINUS, tmp); - break; - } - case code_t::LOG: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::DIVIDE, tmp, terms[t].getOp1()); - break; - } - case code_t::EXP: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::TIMES, t, tmp); - break; - } - case code_t::SIN: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::TIMES, add_unary(code_t::COS, terms[t].getOp1()), tmp); - break; - } - case code_t::COS: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_unary(code_t::UMINUS, add_binary(code_t::TIMES, add_unary(code_t::SIN, terms[t].getOp1()), tmp)); - break; - } - case code_t::TAN: - { - int tmp = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_unary(code_t::COS, terms[t].getOp1()); - res = add_binary(code_t::DIVIDE, tmp, add_binary(code_t::TIMES, tmp2, tmp2)); - break; - } - case code_t::SQRT: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::DIVIDE, tmp, - add_binary(code_t::PLUS, t, t)); - break; - } - case code_t::ERF: - { - int tmp = add_binary(code_t::TIMES, terms[t].getOp1(), terms[t].getOp1()); - tmp = add_unary(code_t::UMINUS, tmp); - tmp = add_unary(code_t::EXP, tmp); - int der = add_derivative(terms[t].getOp1(), v); - tmp = add_binary(code_t::TIMES, tmp, der); - res = add_binary(code_t::TIMES, two_over_pi, tmp); - break; - } - case code_t::ERFC: - { - int tmp = add_binary(code_t::TIMES, terms[t].getOp1(), terms[t].getOp1()); - tmp = add_unary(code_t::UMINUS, tmp); - tmp = add_unary(code_t::EXP, tmp); - int der = add_derivative(terms[t].getOp1(), v); - tmp = add_binary(code_t::TIMES, tmp, der); - tmp = add_binary(code_t::TIMES, two_over_pi, tmp); - res = add_unary(code_t::UMINUS, tmp); - break; - } - case code_t::PLUS: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - res = add_binary(code_t::PLUS, tmp1, tmp2); - break; - } - case code_t::MINUS: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - res = add_binary(code_t::MINUS, tmp1, tmp2); - break; - } - case code_t::TIMES: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - int res1 = add_binary(code_t::TIMES, terms[t].getOp1(), tmp2); - int res2 = add_binary(code_t::TIMES, tmp1, terms[t].getOp2()); - res = add_binary(code_t::PLUS, res1, res2); - break; - } - case code_t::DIVIDE: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - if (tmp2 == zero) - res = add_binary(code_t::DIVIDE, tmp1, terms[t].getOp2()); - else - { - int nom = add_binary(code_t::MINUS, - add_binary(code_t::TIMES, tmp1, terms[t].getOp2()), - add_binary(code_t::TIMES, tmp2, terms[t].getOp1())); - int den = add_binary(code_t::TIMES, terms[t].getOp2(), terms[t].getOp2()); - res = add_binary(code_t::DIVIDE, nom, den); - } - break; - } - case code_t::POWER: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - int s1 = add_binary(code_t::TIMES, tmp2, - add_binary(code_t::TIMES, t, - add_unary(code_t::LOG, terms[t].getOp1()))); - int s2 = add_binary(code_t::TIMES, tmp1, - add_binary(code_t::TIMES, terms[t].getOp2(), - add_binary(code_t::POWER, terms[t].getOp1(), - add_binary(code_t::MINUS, terms[t].getOp2(), one)))); - res = add_binary(code_t::PLUS, s1, s2); - break; - } - case code_t::NONE: - break; - } - - if (res == -1) - throw ogu::Exception(__FILE__, __LINE__, - "Unknown operation code."); - - register_derivative(t, v, res); - - return res; -} - -int -OperationTree::add_substitution(int t, const map<int, int> &subst) -{ - return add_substitution(t, subst, *this); -} - -int -OperationTree::add_substitution(int t, const map<int, int> &subst, - const OperationTree &otree) -{ - // return substitution of t if it is in the map - auto it = subst.find(t); - if (subst.end() != it) - return it->second; - - int nary = otree.terms[t].nary(); - if (nary == 2) - { - // return the binary operation of the substituted terms - int t1 = add_substitution(otree.terms[t].getOp1(), subst, otree); - int t2 = add_substitution(otree.terms[t].getOp2(), subst, otree); - return add_binary(otree.terms[t].getCode(), t1, t2); - } - else if (nary == 1) - { - // return the unary operation of the substituted term - int t1 = add_substitution(otree.terms[t].getOp1(), subst, otree); - return add_unary(otree.terms[t].getCode(), t1); - } - else - { - // if t is not the first num_constants, and otree is not this - // tree, then raise and exception. Otherwise return t, since - // it is either a special term (having the same semantics in - // both trees), or the trees are the same, hence t has the - // same semantics - if (t < num_constants || this == &otree) - return t; - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Incomplete substitution map in OperationTree::add_substitution"); - return -1; - } - } -} - -void -OperationTree::nularify(int t) -{ - // remove the original operation from opmap - auto it = opmap.find(terms[t]); - if (it != opmap.end()) - opmap.erase(it); - // turn the operation to nulary - Operation nulary_op; - terms[t] = nulary_op; - // update last nulary - if (last_nulary < t) - last_nulary = t; - // update nul_incidence information for all terms including t - update_nul_incidence_after_nularify(t); -} - -void -OperationTree::register_derivative(int t, int v, int tder) -{ - // todo: might check that the insert inserts a new pair - derivatives[t].emplace(v, tder); -} - -unordered_set<int> -OperationTree::select_terms(int t, const opselector &sel) const -{ - unordered_set<int> subterms; - select_terms(t, sel, subterms); - return subterms; -} - -void -OperationTree::select_terms(int t, const opselector &sel, unordered_set<int> &subterms) const -{ - const Operation &op = terms[t]; - - if (sel(t)) - subterms.insert(t); - else - if (op.nary() == 2) - { - select_terms(op.getOp1(), sel, subterms); - select_terms(op.getOp2(), sel, subterms); - } - else if (op.nary() == 1) - select_terms(op.getOp1(), sel, subterms); -} - -unordered_set<int> -OperationTree::select_terms_inv(int t, const opselector &sel) const -{ - unordered_set<int> subterms; - select_terms_inv(t, sel, subterms); - return subterms; -} - -bool -OperationTree::select_terms_inv(int t, const opselector &sel, unordered_set<int> &subterms) const -{ - const Operation &op = terms[t]; - - if (op.nary() == 2) - { - bool a1 = select_terms_inv(op.getOp1(), sel, subterms); - bool a2 = select_terms_inv(op.getOp2(), sel, subterms); - if (a1 && a2 && sel(t)) - { - subterms.insert(t); - return true; - } - } - else if (op.nary() == 1) - { - bool a1 = select_terms_inv(op.getOp1(), sel, subterms); - if (a1 && sel(t)) - { - subterms.insert(t); - return true; - } - } - else - { - if (sel(t)) - { - subterms.insert(t); - return true; - } - } - - return false; -} - -void -OperationTree::forget_derivative_maps() -{ - for (auto &derivative : derivatives) - derivative.clear(); -} - -void -OperationTree::print_operation_tree(int t, std::ostream &os, OperationFormatter &f) const -{ - f.format(terms[t], t, os); -} - -void -OperationTree::print_operation(int t) const -{ - DefaultOperationFormatter dof(*this); - print_operation_tree(t, std::cout, dof); -} - -void -OperationTree::update_nul_incidence_after_nularify(int t) -{ - unordered_set<int> updated; - for (int tnode = num_constants; tnode < static_cast<int>(terms.size()); tnode++) - { - const Operation &op = terms[tnode]; - if (op.nary() == 2) - { - int op1 = op.getOp1(); - int op2 = op.getOp2(); - if (op1 >= tnode || op2 >= tnode) - throw ogu::Exception(__FILE__, __LINE__, - "Tree disorder asserted"); - bool updated1 = (updated.end() != updated.find(op1)); - bool updated2 = (updated.end() != updated.find(op2)); - if (updated1 || updated2) - { - nul_incidence[tnode] = nul_incidence[op1]; - nul_incidence[tnode].insert(nul_incidence[op2].begin(), nul_incidence[op2].end()); - updated.insert(tnode); - } - } - else if (op.nary() == 1) - { - int op1 = op.getOp1(); - if (op1 >= tnode) - throw ogu::Exception(__FILE__, __LINE__, - "Tree disorder asserted"); - bool updated1 = (updated.end() != updated.find(op1)); - if (updated1) - { - nul_incidence[tnode] = nul_incidence[op1]; - updated.insert(tnode); - } - } - else if (op.nary() == 0) - { - if (tnode == t) - { - nul_incidence[tnode].clear(); - nul_incidence[tnode].insert(tnode); - updated.insert(tnode); - } - } - } -} - -EvalTree::EvalTree(const OperationTree &ot, int last) - : otree(ot), - values(std::make_unique<double[]>((last == -1) ? ot.terms.size() : last+1)), - flags(std::make_unique<bool[]>((last == -1) ? ot.terms.size() : last+1)), - last_operation((last == -1) ? ot.terms.size()-1 : last) -{ - if (last_operation < OperationTree::num_constants-1 - || last_operation > static_cast<int>(ot.terms.size())-1) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong last in EvalTree constructor."); - - values[0] = 0.0; - flags[0] = true; - values[1] = 1.0; - flags[1] = true; - values[2] = std::numeric_limits<double>::quiet_NaN(); - flags[2] = true; - values[3] = 2.0/std::sqrt(M_PI); - flags[3] = true; - // this sets from num_constants on - reset_all(); -} - -void -EvalTree::reset_all() -{ - for (int i = OperationTree::num_constants; i <= last_operation; i++) - flags[i] = false; -} - -void -EvalTree::set_nulary(int t, double val) -{ - if (t < 0 || t > last_operation) - throw ogu::Exception(__FILE__, __LINE__, - "The tree index out of bounds in EvalTree::set_nulary"); - if (t < OperationTree::num_constants || otree.terms[t].nary() != 0) - throw ogu::Exception(__FILE__, __LINE__, - "The term is not nulary assignable in EvalTree::set_nulary"); - - values[t] = val; - flags[t] = true; -} - -double -EvalTree::eval(int t) -{ - if (t < 0 || t > last_operation) - throw ogu::Exception(__FILE__, __LINE__, - "The tree index out of bounds in EvalTree::eval"); - if (otree.terms[t].nary() == 0 && flags[t] == false) - throw ogu::Exception(__FILE__, __LINE__, - "Nulary term has not been assigned a value in EvalTree::eval"); - - if (!flags[t]) - { - const Operation &op = otree.terms[t]; - if (op.nary() == 1) - { - double r1 = eval(op.getOp1()); - double res; - if (op.getCode() == code_t::UMINUS) - res = -r1; - else if (op.getCode() == code_t::LOG) - res = log(r1); - else if (op.getCode() == code_t::EXP) - res = exp(r1); - else if (op.getCode() == code_t::SIN) - res = sin(r1); - else if (op.getCode() == code_t::COS) - res = cos(r1); - else if (op.getCode() == code_t::TAN) - res = tan(r1); - else if (op.getCode() == code_t::SQRT) - res = sqrt(r1); - else if (op.getCode() == code_t::ERF) - res = erf(r1); - else if (op.getCode() == code_t::ERFC) - res = erfc(r1); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Unknown unary operation code in EvalTree::eval"); - res = 0.0; - } - values[t] = res; - flags[t] = true; - } - else if (op.nary() == 2) - { - double res; - if (op.getCode() == code_t::PLUS) - { - double r1 = eval(op.getOp1()); - double r2 = eval(op.getOp2()); - res = r1 + r2; - } - else if (op.getCode() == code_t::MINUS) - { - double r1 = eval(op.getOp1()); - double r2 = eval(op.getOp2()); - res = r1 - r2; - } - else if (op.getCode() == code_t::TIMES) - { - // pickup less complex formula first - unsigned int nul1 = otree.nulary_of_term(op.getOp1()).size(); - unsigned int nul2 = otree.nulary_of_term(op.getOp2()).size(); - if (nul1 < nul2) - { - double r1 = eval(op.getOp1()); - if (r1 == 0.0) - res = 0.0; - else - { - double r2 = eval(op.getOp2()); - res = r1 * r2; - } - } - else - { - double r2 = eval(op.getOp2()); - if (r2 == 0) - res = 0.0; - else - { - double r1 = eval(op.getOp1()); - res = r1*r2; - } - } - } - else if (op.getCode() == code_t::DIVIDE) - { - double r1 = eval(op.getOp1()); - if (r1 == 0) - res = 0.0; - else - { - double r2 = eval(op.getOp2()); - res = r1 / r2; - } - } - else if (op.getCode() == code_t::POWER) - { - // suppose that more complex is the first op in average - double r2 = eval(op.getOp2()); - if (r2 == 0.0) - res = 1.0; - else - { - double r1 = eval(op.getOp1()); - res = pow(r1, r2); - } - } - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Unknown binary operation code in EvalTree::eval"); - res = 0.0; - } - values[t] = res; - flags[t] = true; - } - return values[t]; - } - - return values[t]; -} - -void -EvalTree::print() const -{ - std::cout << "last_op=" << last_operation << '\n' - << " 0 1 2 3 4 5 6 7 8 9\n" - << "────────────────────────────────────────────────────────────────\n"; - for (int i = 0; i <= (last_operation+1)/10; i++) - { - std::cout << std::setw(3) << i << "│"; - int j = 0; - while (j < 10 && 10*i+j < last_operation+1) - { - int k = 10*i+j; - if (flags[k]) - std::cout << " " << std::setw(5) << std::setprecision(1) << values[k]; - else - std::cout << " ─────"; - j++; - } - std::cout << "\n"; - } -} - -void -DefaultOperationFormatter::format(const Operation &op, int t, std::ostream &os) -{ - // add to the stop_set - if (stop_set.end() == stop_set.find(t)) - stop_set.insert(t); - else - return; - - // call recursively non-nulary terms of the operation - if (op.nary() == 2) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - int t2 = op.getOp2(); - const Operation &op2 = otree.terms[t2]; - if (op1.nary() > 0) - format(op1, t1, os); - if (op2.nary() > 0) - format(op2, t2, os); - } - if (op.nary() == 1) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - if (op1.nary() > 0) - format(op1, t1, os); - } - - // print 'term =' - format_term(t, os); - os << " = "; - if (op.nary() == 0) - format_nulary(t, os); - else if (op.nary() == 1) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::UMINUS: - opname = "-"; - break; - case code_t::LOG: - opname = "log"; - break; - case code_t::EXP: - opname = "exp"; - break; - case code_t::SIN: - opname = "sin"; - break; - case code_t::COS: - opname = "cos"; - break; - case code_t::TAN: - opname = "tan"; - break; - case code_t::SQRT: - opname = "sqrt"; - break; - case code_t::ERF: - opname = "erf"; - break; - case code_t::ERFC: - opname = "erfc"; - break; - default: - break; - } - os << opname << '('; - if (op1.nary() == 0) - format_nulary(t1, os); - else - format_term(t1, os); - os << ")"; - } - else - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - int t2 = op.getOp2(); - const Operation &op2 = otree.terms[t2]; - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::PLUS: - opname = "+"; - break; - case code_t::MINUS: - opname = "-"; - break; - case code_t::TIMES: - opname = "*"; - break; - case code_t::DIVIDE: - opname = "/"; - break; - case code_t::POWER: - opname = "^"; - break; - default: - break; - } - if (op1.nary() == 0) - format_nulary(t1, os); - else - format_term(t1, os); - os << ' ' << opname << ' '; - if (op2.nary() == 0) - format_nulary(t2, os); - else - format_term(t2, os); - } - - print_delim(os); -} - -void -DefaultOperationFormatter::format_term(int t, std::ostream &os) const -{ - os << '$' << t; -} - -void -DefaultOperationFormatter::format_nulary(int t, std::ostream &os) const -{ - if (t == OperationTree::zero) - os << '0'; - else if (t == OperationTree::one) - os << '1'; - else if (t == OperationTree::nan) - os << "NaN"; - else - os << '$' << t; -} - -void -DefaultOperationFormatter::print_delim(std::ostream &os) const -{ - os << ";\n"; -} - -std::string -OperationStringConvertor::convert(const Operation &op, int t) const -{ - if (op.nary() == 0) - { - if (t < OperationTree::num_constants) - if (t == OperationTree::zero) - return "0"; - else if (t == OperationTree::one) - return "1"; - else if (t == OperationTree::nan) - return "NaN"; - else if (t == OperationTree::two_over_pi) - { - std::ostringstream buf; - buf << std::setprecision(std::numeric_limits<double>::max_digits10) - << 2.0/std::sqrt(M_PI); - return buf.str(); - } - else - return "error!error"; - else - return nulsc.convert(t); - } - else if (op.nary() == 1) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.operation(t1); - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::UMINUS: - opname = "-"; - break; - case code_t::LOG: - opname = "log"; - break; - case code_t::EXP: - opname = "exp"; - break; - case code_t::SIN: - opname = "sin"; - break; - case code_t::COS: - opname = "cos"; - break; - case code_t::TAN: - opname = "tan"; - break; - case code_t::SQRT: - opname = "sqrt"; - break; - case code_t::ERF: - opname = "erf"; - break; - case code_t::ERFC: - opname = "erfc"; - break; - default: - break; - } - std::string s1 = convert(op1, t1); - return opname + "(" + s1 + ")"; - } - else - { - int t1 = op.getOp1(); - const Operation &op1 = otree.operation(t1); - int t2 = op.getOp2(); - const Operation &op2 = otree.operation(t2); - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::PLUS: - opname = "+"; - break; - case code_t::MINUS: - opname = "-"; - break; - case code_t::TIMES: - opname = "*"; - break; - case code_t::DIVIDE: - opname = "/"; - break; - case code_t::POWER: - opname = "^"; - break; - default: - break; - } - // decide about parenthesis - bool op1_par = true; - bool op2_par = true; - if (op.getCode() == code_t::PLUS) - { - op1_par = false; - op2_par = false; - } - else if (op.getCode() == code_t::MINUS) - { - op1_par = false; - if (op2.getCode() != code_t::MINUS && op2.getCode() != code_t::PLUS) - op2_par = false; - } - else - { - if (op1.nary() < 2) - op1_par = false; - if (op2.nary() < 2) - op2_par = false; - } - - std::string res; - if (op1_par) - res += "("; - res += convert(op1, t1); - if (op1_par) - res += ")"; - res += " "; - res += opname; - res += " "; - if (op2_par) - res += "("; - res += convert(op2, t2); - if (op2_par) - res += ")"; - - return res; - } -} diff --git a/dynare++/parser/cc/tree.hh b/dynare++/parser/cc/tree.hh deleted file mode 100644 index 88474b369ef51feb9ea29faeed86becc8f4ae064..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/tree.hh +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#ifndef OGP_TREE_H -#define OGP_TREE_H - -#include <vector> -#include <set> -#include <map> -#include <unordered_map> -#include <unordered_set> -#include <ostream> -#include <memory> - -namespace ogp -{ - using std::unordered_set; - using std::unordered_map; - using std::vector; - using std::set; - using std::map; - - /** Enumerator representing nulary, unary and binary operation - * codes. For nulary, 'none' is used. When one is adding a new - * codes, he should update the code of #OperationTree::add_unary, - * #OperationTree::add_binary, and of course - * #OperationTree::add_derivative. */ - enum class code_t { NONE, UMINUS, LOG, EXP, SIN, COS, TAN, SQRT, ERF, - ERFC, PLUS, MINUS, TIMES, DIVIDE, POWER }; - - /** Class representing a nulary, unary, or binary operation. */ - class Operation - { - protected: - /** Code of the operation. */ - code_t code{code_t::NONE}; - /** First operand. If none, then it is -1. */ - int op1{-1}; - /** Second operand. If none, then it is -1. */ - int op2{-1}; - - public: - /** Constructs a binary operation. */ - Operation(code_t cd, int oper1, int oper2) - : code(cd), op1(oper1), op2(oper2) - { - } - /** Constructs a unary operation. */ - Operation(code_t cd, int oper1) - : code(cd), op1(oper1) - { - } - /** Constructs a nulary operation. */ - Operation() = default; - /** A copy constructor. */ - Operation(const Operation &op) = default; - - /** Operator =. */ - Operation &operator=(const Operation &op) = default; - /** Operator ==. */ - bool - operator==(const Operation &op) const - { - return code == op.code && op1 == op.op1 && op2 == op.op2; - } - /** Operator < implementing lexicographic ordering. */ - bool - operator<(const Operation &op) const - { - return (code < op.code - || (code == op.code - && (op1 < op.op1 || (op1 == op.op1 && op2 < op.op2)))); - } - /** Returns a number of operands. */ - int - nary() const - { - return (op2 == -1) ? ((op1 == -1) ? 0 : 1) : 2; - } - /** Returns a hash value of the operation. */ - size_t - hashval() const - { - return (op2+1 + op1+1)^(15 + static_cast<int>(code))^30; - } - - code_t - getCode() const - { - return code; - } - int - getOp1() const - { - return op1; - } - int - getOp2() const - { - return op2; - } - }; - - /** This struct is a predicate for ordering of the operations in - * OperationTree class. now obsolete */ - struct ltoper - { - bool - operator()(const Operation &oper1, const Operation &oper2) const - { - return oper1 < oper2; - } - }; - - /** Hash function object for Operation. */ - struct ophash - { - size_t - operator()(const Operation &op) const - { - return op.hashval(); - } - }; - - /** This struct is a function object selecting some - * operations. The operation is given by a tree index. */ - struct opselector - { - virtual bool operator()(int t) const = 0; - virtual ~opselector() = default; - }; - - /** Forward declaration of OperationFormatter. */ - class OperationFormatter; - class DefaultOperationFormatter; - - /** Forward declaration of EvalTree to make it friend of OperationTree. */ - class EvalTree; - - /** Class representing a set of trees for terms. Each term is - * given a unique non-negative integer. The terms are basically - * operations whose (integer) operands point to another terms in - * the tree. The terms are stored in the vector. Equivalent unary - * and binary terms are stored only once. This class guarantees - * the uniqueness. The uniqueness of nulary terms is guaranteed by - * the caller, since at this level of Operation abstraction, one - * cannot discriminate between different nulary operations - * (constants, variables). The uniqueness is enforced by the - * unordered_map whose keys are operations and values are integers - * (indices of the terms). - - * This class can also make derivatives of a given term with - * respect to a given nulary term. I order to be able to quickly - * recognize zero derivativates, we maintain a list of nulary - * terms contained in the term. A possible zero derivative is then quickly - * recognized by looking at the list. The list is implemented as a - * unordered_set of integers. - * - * In addition, many term can be differentiated multiple times wrt - * one variable since they can be referenced multiple times. To - * avoid this, for each term we maintain a map mapping variables - * to the derivatives of the term. As the caller will - * differentiate wrt more and more variables, these maps will - * become richer and richer. - */ - class OperationTree - { - friend class EvalTree; - friend class DefaultOperationFormatter; - protected: - /** This is the vector of the terms. An index to this vector - * uniquelly determines the term. */ - vector<Operation> terms; - - /** This defines a type for a map mapping the unary and binary - * operations to their indices. */ - using _Topmap = unordered_map<Operation, int, ophash>; - - /** This is the map mapping the unary and binary operations to - * the indices of the terms.*/ - _Topmap opmap; - - /** This is a type for a set of integers. */ - using _Tintset = unordered_set<int>; - /** This is a vector of integer sets corresponding to the - * nulary terms contained in the term. */ - vector<_Tintset> nul_incidence; - - /** This is a type of the map from variables (nulary terms) to - * the terms. */ - using _Tderivmap = unordered_map<int, int>; - /** This is a vector of derivative mappings. For each term, it - * maps variables to the derivatives of the term with respect - * to the variables. */ - vector<_Tderivmap> derivatives; - - /** The tree index of the last nulary term. */ - int last_nulary; - public: - /** Enumeration for special terms. We need zero, one, nan and - * 2/pi. These will be always first four terms having indices - * zero, one and two, three. If adding anything to this - * enumeration, make sure ‘num_constants’ remains the last one.*/ - enum { zero, one, nan, two_over_pi, num_constants }; - - /** The unique constructor which initializes the object to - * contain only zero, one and nan and two_over_pi.*/ - OperationTree(); - - /** Copy constructor. */ - OperationTree(const OperationTree &ot) = default; - - /** Add a nulary operation. The caller is responsible for not - * inserting two semantically equivalent nulary operations. - * @return newly allocated index - */ - int add_nulary(); - - /** Add a unary operation. The uniqness is checked, if it - * already exists, then it is not added. - * @param code the code of the unary operation - * @param op the index of the operand - * @return the index of the operation - */ - int add_unary(code_t code, int op); - - /** Add a binary operation. The uniqueness is checked, if it - * already exists, then it is not added. - * @param code the code of the binary operation - * @param op1 the index of the first operand - * @param op2 the index of the second operand - * @return the index of the operation - */ - int add_binary(code_t code, int op1, int op2); - - /** Add the derivative of the given term with respect to the - * given nulary operation. - * @param t the index of the operation being differentiated - * @param v the index of the nulary operation - * @return the index of the derivative - */ - int add_derivative(int t, int v); - - /** Add the substitution given by the map. This adds a new - * term which is equal to the given term with applied - * substitutions given by the map replacing each term on the - * left by a term on the right. We do not check that the terms - * on the left are not subterms of the terms on the right. If - * so, the substituted terms are not subject of further - * substitution. */ - int add_substitution(int t, const map<int, int> &subst); - - /** Add the substitution given by the map where left sides of - * substitutions come from another tree. The right sides are - * from this tree. The given t is from the given otree. */ - int add_substitution(int t, const map<int, int> &subst, - const OperationTree &otree); - - /** This method turns the given term to a nulary - * operation. This is an only method, which changes already - * existing term (all other methods add something new). User - * should use this with caution and must make sure that - * something similar has happened for atoms. In addition, it - * does not do anything with derivatives, so it should not be - * used after some derivatives were created, and derivatives - * already created and saved in derivatives mappings should be - * forgotten with forget_derivative_maps. */ - void nularify(int t); - - /** Return the set of nulary terms of the given term. */ - const unordered_set<int> & - nulary_of_term(int t) const - { - return nul_incidence[t]; - } - - /** Select subterms of the given term according a given - * operation selector and return the set of terms that - * correspond to the compounded operations. The given term is - * a compound function of the returned subterms and the - * function consists only from operations which yield false in - * the selector. */ - unordered_set<int> select_terms(int t, const opselector &sel) const; - - /** Select subterms of the given term according a given - * operation selector and return the set of terms that - * correspond to the compounded operations. The given term is - * a compound function of the returned subterms and the - * subterms are maximal subterms consisting from operations - * yielding true in the selector. */ - unordered_set<int> select_terms_inv(int t, const opselector &sel) const; - - /** This forgets all the derivative mappings. It is used after - * a term has been nularified, and then the derivative - * mappings carry wrong information. Note that the derivatives - * mappings serve only as a tool for quick returns in - * add_derivative. Resseting the mappings is harmless, all the - * information is rebuilt in add_derivative without any - * additional nodes (trees). */ - void forget_derivative_maps(); - - /** This returns an operation of a given term. */ - const Operation & - operation(int t) const - { - return terms[t]; - } - - /** This outputs the operation to the given file descriptor - * using the given OperationFormatter. */ - void print_operation_tree(int t, std::ostream &os, OperationFormatter &f) const; - - /** Debug print of a given operation: */ - void print_operation(int t) const; - - /** Return the last tree index of a nulary term. */ - int - get_last_nulary() const - { - return last_nulary; - } - - /** Get the number of all operations. */ - int - get_num_op() const - { - return static_cast<int>(terms.size()); - } - private: - /** This registers a calculated derivative of the term in the - * #derivatives vector. - * @param t the index of the term for which we register the derivative - * @param v the index of the nulary term (variable) to which - * respect the derivative was taken - * @param tder the index of the resulting derivative - */ - void register_derivative(int t, int v, int tder); - /** This does the same job as select_terms with the only - * difference, that it adds the terms to the given set and - * hence can be used recursivelly. */ - void select_terms(int t, const opselector &sel, unordered_set<int> &subterms) const; - /** This does the same job as select_terms_inv with the only - * difference, that it adds the terms to the given set and - * hence can be used recursivelly and returns true if the term - * was selected. */ - bool select_terms_inv(int t, const opselector &sel, unordered_set<int> &subterms) const; - /** This updates nul_incidence information after the term t - * was turned to a nulary term in all terms. It goes through - * the tree from simplest terms to teh more complex ones and - * changes the nul_incidence information where necesary. It - * maintains a set where the changes have been made.*/ - void update_nul_incidence_after_nularify(int t); - }; - - /** EvalTree class allows for an evaluation of the given tree for - * a given values of nulary terms. For each term in the - * OperationTree the class maintains a resulting value and a flag - * if the value has been calculated or set. The life cycle of the - * class is the following: After it is initialized, the user must - * set values for necessary nulary terms. Then the object can be - * requested to evaluate particular terms. During this process, - * the number of evaluated terms is increasing. Then the user can - * request overall reset of evaluation flags, set the nulary terms - * to new values and evaluate a number of terms. - * - * Note that currently the user cannot request a reset of - * evaluation flags only for those terms depending on a given - * nulary term. This might be added in future and handeled by a - * subclasses of OperationTree and EvalTree, since we need a - * support for this in OperationTree. - */ - class EvalTree - { - protected: - /** Reference to the OperationTree over which all evaluations - * are done. */ - const OperationTree &otree; - /** The array of values. */ - const std::unique_ptr<double[]> values; - /** The array of evaluation flags. */ - const std::unique_ptr<bool[]> flags; - /** The index of last operation in the EvalTree. Length of - * values and flags will be then last_operation+1. */ - int last_operation; - public: - /** Initializes the evaluation tree for the given operation - * tree. If last is greater than -1, that the evaluation tree - * will contain only formulas up to the given last index - * (included). */ - EvalTree(const OperationTree &otree, int last = -1); - EvalTree(const EvalTree &) = delete; - virtual ~EvalTree() = default; - /** Set evaluation flag to all terms (besides the first - * special terms) to false. */ - void reset_all(); - /** Set value for a given nulary term. */ - void set_nulary(int t, double val); - /** Evaluate the given term with nulary terms set so far. */ - double eval(int t); - /** Debug print. */ - void print() const; - /* Return the operation tree. */ - const OperationTree & - getOperationTree() const - { - return otree; - } - }; - - /** This is an interface describing how a given operation is - * formatted for output. */ - class OperationFormatter - { - public: - /** Empty virtual destructor. */ - virtual ~OperationFormatter() = default; - /** Print the formatted operation op with a given tree index t - * to a given descriptor. (See class OperationTree to know - * what is a tree index.) This prints all the tree. This - * always writes equation, left hand side is a string - * represenation (a variable, temporary, whatever) of the - * term, the right hand side is a string representation of the - * operation (which will refer to other string representation - * of subterms). */ - virtual void format(const Operation &op, int t, std::ostream &os) = 0; - }; - - /** The default formatter formats the formulas with a usual syntax - * (for example Matlab). A formatting of atoms and terms might be - * reimplemented by a subclass. In addition, during its life, the - * object maintains a set of tree indices which have been output - * and they are not output any more. */ - class DefaultOperationFormatter : public OperationFormatter - { - protected: - const OperationTree &otree; - set<int> stop_set; - public: - DefaultOperationFormatter(const OperationTree &ot) - : otree(ot) - { - } - /** Format the operation with the default syntax. */ - void format(const Operation &op, int t, std::ostream &os) override; - /** This prints a string represenation of the given term, for - * example 'tmp10' for term 10. In this implementation it - * prints $10. */ - virtual void format_term(int t, std::ostream &os) const; - /** Print a string representation of the nulary term. */ - virtual void format_nulary(int t, std::ostream &os) const; - /** Print a delimiter between two statements. By default it is - * "\n". */ - virtual void print_delim(std::ostream &os) const; - }; - - class NularyStringConvertor - { - public: - virtual ~NularyStringConvertor() = default; - /** Return the string representation of the atom with the tree - * index t. */ - virtual std::string convert(int t) const = 0; - }; - - /** This class converts the given term to its mathematical string representation. */ - class OperationStringConvertor - { - protected: - const NularyStringConvertor &nulsc; - const OperationTree &otree; - public: - OperationStringConvertor(const NularyStringConvertor &nsc, const OperationTree &ot) - : nulsc(nsc), otree(ot) - { - } - /** Empty virtual destructor. */ - virtual ~OperationStringConvertor() = default; - /** Convert the operation to the string mathematical - * representation. This does not write any equation, just - * returns a string representation of the formula. */ - std::string convert(const Operation &op, int t) const; - }; -}; - -#endif diff --git a/dynare++/src/Makefile.am b/dynare++/src/Makefile.am deleted file mode 100644 index 85abffa34b6ab401da47605d90e70a7a37efd177..0000000000000000000000000000000000000000 --- a/dynare++/src/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -bin_PROGRAMS = dynare++ - -GENERATED_FILES = dynglob_ll.cc dynglob_tab.cc dynglob_tab.hh - -dynare___SOURCES = \ - main.cc \ - dynare3.cc \ - dynare_atoms.hh \ - dynare_model.hh \ - forw_subst_builder.hh \ - planner_builder.cc \ - dynare3.hh \ - dynare_exception.hh \ - dynare_params.cc \ - planner_builder.hh \ - dynare_atoms.cc \ - dynare_model.cc \ - dynare_params.hh \ - forw_subst_builder.cc \ - nlsolve.cc \ - nlsolve.hh \ - $(GENERATED_FILES) - -dynare___CPPFLAGS = -I../sylv/cc -I../tl/cc -I../kord -I../integ/cc -I../utils/cc -I.. -I$(top_srcdir)/mex/sources $(BOOST_CPPFLAGS) $(CPPFLAGS_MATIO) -dynare___LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) $(BOOST_LDFLAGS) -dynare___LDADD = ../kord/libkord.a ../integ/cc/libinteg.a ../tl/cc/libtl.a ../parser/cc/libparser.a ../utils/cc/libutils.a ../sylv/cc/libsylv.a $(LIBADD_MATIO) $(noinst_LIBRARIES) $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) - -BUILT_SOURCES = $(GENERATED_FILES) -EXTRA_DIST = dynglob.ll dynglob.yy - -dynglob_tab.cc dynglob_tab.hh: dynglob.yy - $(YACC) -W -odynglob_tab.cc dynglob.yy - -dynare__-dynglob_tab.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast - -dynglob_ll.cc: dynglob.ll - $(LEX) -i -odynglob_ll.cc dynglob.ll - -dynare__-dynglob_ll.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast diff --git a/dynare++/src/dynare3.cc b/dynare++/src/dynare3.cc deleted file mode 100644 index 746cf21ff6136eef1d3dfd110d698ba41589fb79..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare3.cc +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include <sstream> -#include <fstream> - -#include "dynare3.hh" -#include "dynare_exception.hh" -#include "planner_builder.hh" -#include "forw_subst_builder.hh" - -#include "utils/cc/exception.hh" -#include "parser/cc/parser_exception.hh" -#include "parser/cc/atom_substitutions.hh" -#include "../tl/cc/tl_exception.hh" -#include "../kord/kord_exception.hh" - -/**************************************************************************************/ -/* DynareNameList class */ -/**************************************************************************************/ -std::vector<int> -DynareNameList::selectIndices(const std::vector<std::string> &ns) const -{ - std::vector<int> res; - for (const auto &n : ns) - { - int j = 0; - while (j < getNum() && n != getName(j)) - j++; - if (j == getNum()) - throw DynareException(__FILE__, __LINE__, - "Couldn't find name for " + n - +" in DynareNameList::selectIndices"); - res.push_back(j); - } - return res; -} - -/**************************************************************************************/ -/* Dynare class */ -/**************************************************************************************/ - -Dynare::Dynare(const std::string &modname, int ord, double sstol, Journal &jr) - : journal(jr), md(1), ss_tol(sstol) -{ - std::ifstream f{modname}; - if (f.fail()) - throw DynareException(__FILE__, __LINE__, "Could not open model file "+modname); - - std::ostringstream buffer; - buffer << f.rdbuf(); - std::string contents{buffer.str()}; - - try - { - model = std::make_unique<ogdyn::DynareParser>(contents, ord); - } - catch (const ogp::ParserException &pe) - { - // Compute line and column, given the offset in the file - int line = 1; - int col = 0; - size_t i = 0; - while (i < contents.length() && i < static_cast<size_t>(pe.offset())) - { - if (contents[i] == '\n') - { - line++; - col = 0; - } - i++; - col++; - } - throw DynareException(pe.message(), modname, line, col); - } - ysteady = std::make_unique<Vector>(model->getAtoms().ny()); - dnl = std::make_unique<DynareNameList>(*this); - denl = std::make_unique<DynareExogNameList>(*this); - dsnl = std::make_unique<DynareStateNameList>(*this, *dnl, *denl); - fe = std::make_unique<ogp::FormulaEvaluator>(model->getParser()); - fde = std::make_unique<ogp::FormulaDerEvaluator>(model->getParser()); - writeModelInfo(journal); -} - -Dynare::Dynare(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const std::string &equations, int ord, - double sstol, Journal &jr) - : journal(jr), md(1), ss_tol(sstol) -{ - try - { - model = std::make_unique<ogdyn::DynareSPModel>(endo, exo, par, equations, ord); - } - catch (const ogp::ParserException &pe) - { - throw DynareException(pe.message(), pe.offset()); - } - ysteady = std::make_unique<Vector>(model->getAtoms().ny()); - dnl = std::make_unique<DynareNameList>(*this); - denl = std::make_unique<DynareExogNameList>(*this); - dsnl = std::make_unique<DynareStateNameList>(*this, *dnl, *denl); - fe = std::make_unique<ogp::FormulaEvaluator>(model->getParser()); - fde = std::make_unique<ogp::FormulaDerEvaluator>(model->getParser()); - writeModelInfo(journal); -} - -Dynare::Dynare(const Dynare &dynare) - : journal(dynare.journal), md(dynare.md), ss_tol(dynare.ss_tol) -{ - model = dynare.model->clone(); - ysteady = std::make_unique<Vector>(*(dynare.ysteady)); - dnl = std::make_unique<DynareNameList>(*this); - denl = std::make_unique<DynareExogNameList>(*this); - dsnl = std::make_unique<DynareStateNameList>(*this, *dnl, *denl); - fe = std::make_unique<ogp::FormulaEvaluator>(model->getParser()); - fde = std::make_unique<ogp::FormulaDerEvaluator>(model->getParser()); -} - -void -Dynare::writeMat(mat_t *fd, const std::string &prefix) const -{ - getAllEndoNames().writeMat(fd, prefix + "_vars"); - getAllEndoNames().writeMatIndices(fd, prefix); - getStateNames().writeMat(fd, prefix + "_state_vars"); - getExogNames().writeMat(fd, prefix + "_shocks"); - getExogNames().writeMatIndices(fd, prefix); - model->getVcov().writeMat(fd, prefix + "_vcov_exo"); - TwoDMatrix aux(1, 1); - aux.get(0, 0) = nstat(); - aux.writeMat(fd, prefix + "_nstat"); - aux.get(0, 0) = npred(); - aux.writeMat(fd, prefix + "_npred"); - aux.get(0, 0) = nboth(); - aux.writeMat(fd, prefix + "_nboth"); - aux.get(0, 0) = nforw(); - aux.writeMat(fd, prefix + "_nforw"); -} - -void -Dynare::writeDump(const std::string &basename) const -{ - std::string fname(basename + ".dump"); - std::ofstream out(fname); - model->dump_model(out); - out.close(); -} - -void -Dynare::solveDeterministicSteady(Vector &steady) -{ - JournalRecordPair pa(journal); - pa << "Non-linear solver for deterministic steady state" << endrec; - steady = const_cast<const Vector &>(model->getInit()); - DynareVectorFunction dvf(*this); - DynareJacobian dj(*this); - ogu::NLSolver nls(dvf, dj, 500, ss_tol, journal); - int iter; - if (!nls.solve(steady, iter)) - throw DynareException(__FILE__, __LINE__, - "Could not obtain convergence in non-linear solver"); -} - -// Evaluate system at given yₜ=yₜ₊₁=yₜ₋₁, and given shocks xₜ -void -Dynare::evaluateSystem(Vector &out, const ConstVector &yy, const Vector &xx) -{ - ConstVector yym(yy, nstat(), nys()); - ConstVector yyp(yy, nstat()+npred(), nyss()); - evaluateSystem(out, yym, yy, yyp, xx); -} - -/* Evaluate system at given y*ₜ₋₁, yₜ, y**ₜ₊₁ and at exogenous xₜ, all three - vectors yym, yy, and yyp have the respective lengths of y*ₜ₋₁, yₜ, y**ₜ₊₁ */ -void -Dynare::evaluateSystem(Vector &out, const ConstVector &yym, const ConstVector &yy, - const ConstVector &yyp, const Vector &xx) -{ - ogdyn::DynareAtomValues dav(model->getAtoms(), model->getParams(), yym, yy, yyp, xx); - DynareEvalLoader del(model->getAtoms(), out); - fe->eval(dav, del); -} - -void -Dynare::calcDerivatives(const Vector &yy, const Vector &xx) -{ - ConstVector yym(yy, nstat(), nys()); - ConstVector yyp(yy, nstat()+npred(), nyss()); - ogdyn::DynareAtomValues dav(model->getAtoms(), model->getParams(), yym, yy, yyp, xx); - DynareDerEvalLoader ddel(model->getAtoms(), md, model->getOrder()); - for (int iord = 1; iord <= model->getOrder(); iord++) - fde->eval(dav, ddel, iord); -} - -void -Dynare::calcDerivativesAtSteady() -{ - Vector xx(nexog()); - xx.zeros(); - calcDerivatives(*ysteady, xx); -} - -void -Dynare::writeModelInfo(Journal &jr) const -{ - // write info on variables - { - JournalRecordPair rp(journal); - rp << "Information on variables" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of endogenous: " << ny() << endrec; - JournalRecord rec2(journal); - rec2 << "Number of exogenous: " << nexog() << endrec; - JournalRecord rec3(journal); - rec3 << "Number of static: " << nstat() << endrec; - JournalRecord rec4(journal); - rec4 << "Number of predetermined: " << npred()+nboth() << endrec; - JournalRecord rec5(journal); - rec5 << "Number of forward looking: " << nforw()+nboth() << endrec; - JournalRecord rec6(journal); - rec6 << "Number of both: " << nboth() << endrec; - } - - // write info on planner variables - const ogdyn::PlannerInfo *pinfo = model->get_planner_info(); - if (pinfo) - { - JournalRecordPair rp(journal); - rp << "Information on planner variables" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of Lagrange multipliers: " << pinfo->num_lagrange_mults << endrec; - JournalRecord rec2(journal); - rec2 << "Number of auxiliary variables: " << pinfo->num_aux_variables << endrec; - JournalRecord rec3(journal); - rec3 << "Number of new terms in the tree: " << pinfo->num_new_terms << endrec; - } - - // write info on forward substitutions - const ogdyn::ForwSubstInfo *finfo = model->get_forw_subst_info(); - if (finfo) - { - JournalRecordPair rp(journal); - rp << "Information on forward substitutions" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of affected equations: " << finfo->num_affected_equations << endrec; - JournalRecord rec2(journal); - rec2 << "Number of substituted terms: " << finfo->num_subst_terms << endrec; - JournalRecord rec3(journal); - rec3 << "Number of auxiliary variables: " << finfo->num_aux_variables << endrec; - JournalRecord rec4(journal); - rec4 << "Number of new terms in the tree: " << finfo->num_new_terms << endrec; - } - - // write info on substitutions - const ogp::SubstInfo *sinfo = model->get_subst_info(); - if (sinfo) - { - JournalRecordPair rp(journal); - rp << "Information on substitutions" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of substitutions: " << sinfo->num_substs << endrec; - } -} - -DynareNameList::DynareNameList(const Dynare &dynare) -{ - for (int i = 0; i < dynare.ny(); i++) - { - int j = dynare.model->getAtoms().y2outer_endo()[i]; - const std::string &name = dynare.model->getAtoms().get_endovars()[j]; - names.push_back(name); - } -} - -DynareStateNameList::DynareStateNameList(const Dynare &dynare, const DynareNameList &dnl, - const DynareExogNameList &denl) -{ - for (int i = 0; i < dynare.nys(); i++) - names.push_back(dnl.getName(i+dynare.nstat())); - for (int i = 0; i < dynare.nexog(); i++) - names.push_back(denl.getName(i)); -} - -DynareExogNameList::DynareExogNameList(const Dynare &dynare) -{ - for (int i = 0; i < dynare.nexog(); i++) - { - int j = dynare.model->getAtoms().y2outer_exo()[i]; - const std::string &name = dynare.model->getAtoms().get_exovars()[j]; - names.push_back(name); - } -} - -DynareEvalLoader::DynareEvalLoader(const ogp::FineAtoms &a, Vector &out) - : Vector(out) -{ - if (a.ny() != out.length()) - throw DynareException(__FILE__, __LINE__, "Wrong length of out vector in DynareEvalLoader constructor"); -} - -/* This clears the container of model derivatives and initializes it inserting - empty sparse tensors up to the given order. */ -DynareDerEvalLoader::DynareDerEvalLoader(const ogp::FineAtoms &a, - TensorContainer<FSSparseTensor> &mod_ders, - int order) - : atoms(a), md(mod_ders) -{ - md.clear(); - for (int iord = 1; iord <= order; iord++) - { - auto t = std::make_unique<FSSparseTensor>(iord, atoms.ny()+atoms.nys()+atoms.nyss()+atoms.nexo(), atoms.ny()); - md.insert(std::move(t)); - } -} - -void -DynareDerEvalLoader::load(int i, int iord, const int *vars, double res) -{ - FSSparseTensor &t = md.get(Symmetry{iord}); - IntSequence s(iord, 0); - for (int j = 0; j < iord; j++) - s[j] = atoms.get_pos_of_all(vars[j]); - t.insert(s, i, res); -} - -DynareJacobian::DynareJacobian(Dynare &dyn) - : Jacobian(dyn.ny()), d(dyn) -{ - zeros(); -} - -void -DynareJacobian::eval(const Vector &yy) -{ - ogdyn::DynareSteadyAtomValues - dav(d.getModel().getAtoms(), d.getModel().getParams(), yy); - zeros(); - d.fde->eval(dav, *this, 1); -} - -void -DynareJacobian::load(int i, int iord, const int *vars, double res) -{ - if (iord != 1) - throw DynareException(__FILE__, __LINE__, - "Derivative order different from order=1 in DynareJacobian::load"); - - int t = vars[0]; - int j = d.getModel().getAtoms().get_pos_of_all(t); - if (j < d.nyss()) - get(i, j+d.nstat()+d.npred()) += res; - else if (j < d.nyss()+d.ny()) - get(i, j-d.nyss()) += res; - else if (j < d.nyss()+d.ny()+d.nys()) - get(i, j-d.nyss()-d.ny()+d.nstat()) += res; -} - -void -DynareVectorFunction::eval(const ConstVector &in, Vector &out) -{ - check_for_eval(in, out); - Vector xx(d.nexog()); - xx.zeros(); - d.evaluateSystem(out, in, xx); -} diff --git a/dynare++/src/dynare3.hh b/dynare++/src/dynare3.hh deleted file mode 100644 index d0c2098725a93d4fe6389ad759d943874136ecfe..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare3.hh +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef DYNARE3_H -#define DYNARE3_H - -#include "../tl/cc/t_container.hh" -#include "../tl/cc/sparse_tensor.hh" -#include "../kord/decision_rule.hh" -#include "../kord/dynamic_model.hh" - -#include "dynare_model.hh" -#include "nlsolve.hh" - -#include <vector> -#include <memory> - -#include <matio.h> - -class Dynare; - -class DynareNameList : public NameList -{ - std::vector<std::string> names; -public: - DynareNameList(const Dynare &dynare); - int - getNum() const override - { - return static_cast<int>(names.size()); - } - const std::string & - getName(int i) const override - { - return names[i]; - } - /* This for each string of the input vector calculates its index in the - names. And returns the resulting vector of indices. If the name cannot be - found, then an exception is raised. */ - std::vector<int> selectIndices(const std::vector<std::string> &ns) const; -}; - -class DynareExogNameList : public NameList -{ - std::vector<std::string> names; -public: - DynareExogNameList(const Dynare &dynare); - int - getNum() const override - { - return static_cast<int>(names.size()); - } - const std::string & - getName(int i) const override - { - return names[i]; - } -}; - -class DynareStateNameList : public NameList -{ - std::vector<std::string> names; -public: - DynareStateNameList(const Dynare &dynare, const DynareNameList &dnl, - const DynareExogNameList &denl); - int - getNum() const override - { - return static_cast<int>(names.size()); - } - const std::string & - getName(int i) const override - { - return names[i]; - } -}; - -// The following only implements DynamicModel with help of ogdyn::DynareModel - -class DynareJacobian; -class Dynare : public DynamicModel -{ - friend class DynareNameList; - friend class DynareExogNameList; - friend class DynareStateNameList; - friend class DynareJacobian; - Journal &journal; - std::unique_ptr<ogdyn::DynareModel> model; - std::unique_ptr<Vector> ysteady; - TensorContainer<FSSparseTensor> md; - std::unique_ptr<DynareNameList> dnl; - std::unique_ptr<DynareExogNameList> denl; - std::unique_ptr<DynareStateNameList> dsnl; - std::unique_ptr<ogp::FormulaEvaluator> fe; - std::unique_ptr<ogp::FormulaDerEvaluator> fde; - const double ss_tol; -public: - /* Parses the given model file and uses the given order to - override order from the model file (if it is ≠ −1). */ - Dynare(const std::string &modname, int ord, double sstol, Journal &jr); - /** Parses the given equations with explicitly given names. */ - Dynare(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const std::string &equations, int ord, - double sstol, Journal &jr); - /* Makes a deep copy of the object. */ - Dynare(const Dynare &dyn); - Dynare(Dynare &&) = default; - std::unique_ptr<DynamicModel> - clone() const override - { - return std::make_unique<Dynare>(*this); - } - - ~Dynare() override = default; - int - nstat() const override - { - return model->getAtoms().nstat(); - } - int - nboth() const override - { - return model->getAtoms().nboth(); - } - int - npred() const override - { - return model->getAtoms().npred(); - } - int - nforw() const override - { - return model->getAtoms().nforw(); - } - int - nexog() const override - { - return model->getAtoms().nexo(); - } - int - nys() const - { - return model->getAtoms().nys(); - } - int - nyss() const - { - return model->getAtoms().nyss(); - } - int - ny() const - { - return model->getAtoms().ny(); - } - int - order() const override - { - return model->getOrder(); - } - - const NameList & - getAllEndoNames() const override - { - return *dnl; - } - const NameList & - getStateNames() const override - { - return *dsnl; - } - const NameList & - getExogNames() const override - { - return *denl; - } - - TwoDMatrix & - getVcov() - { - return model->getVcov(); - } - const TwoDMatrix & - getVcov() const override - { - return model->getVcov(); - } - Vector & - getParams() - { - return model->getParams(); - } - const Vector & - getParams() const - { - return model->getParams(); - } - void - setInitOuter(const Vector &x) - { - model->setInitOuter(x); - } - - const TensorContainer<FSSparseTensor> & - getModelDerivatives() const override - { - return md; - } - const Vector & - getSteady() const override - { - return *ysteady; - } - Vector & - getSteady() override - { - return *ysteady; - } - const ogdyn::DynareModel & - getModel() const - { - return *model; - } - - // here is true public interface - void solveDeterministicSteady(Vector &steady); - void - solveDeterministicSteady() override - { - solveDeterministicSteady(*ysteady); - } - void evaluateSystem(Vector &out, const ConstVector &yy, const Vector &xx) override; - void evaluateSystem(Vector &out, const ConstVector &yym, const ConstVector &yy, - const ConstVector &yyp, const Vector &xx) override; - void calcDerivatives(const Vector &yy, const Vector &xx); - void calcDerivativesAtSteady() override; - - void writeMat(mat_t *fd, const std::string &prefix) const; - void writeDump(const std::string &basename) const; -private: - void writeModelInfo(Journal &jr) const; -}; - -class DynareEvalLoader : public ogp::FormulaEvalLoader, public Vector -{ -public: - DynareEvalLoader(const ogp::FineAtoms &a, Vector &out); - void - load(int i, double res) override - { - operator[](i) = res; - } -}; - -class DynareDerEvalLoader : public ogp::FormulaDerEvalLoader -{ -protected: - const ogp::FineAtoms &atoms; - TensorContainer<FSSparseTensor> &md; -public: - DynareDerEvalLoader(const ogp::FineAtoms &a, TensorContainer<FSSparseTensor> &mod_ders, - int order); - void load(int i, int iord, const int *vars, double res) override; -}; - -class DynareJacobian : public ogu::Jacobian, public ogp::FormulaDerEvalLoader -{ -protected: - Dynare &d; -public: - DynareJacobian(Dynare &dyn); - ~DynareJacobian() override = default; - void load(int i, int iord, const int *vars, double res) override; - void eval(const Vector &in) override; -}; - -class DynareVectorFunction : public ogu::VectorFunction -{ -protected: - Dynare &d; -public: - DynareVectorFunction(Dynare &dyn) - : d(dyn) - { - } - ~DynareVectorFunction() override = default; - int - inDim() const override - { - return d.ny(); - } - int - outDim() const override - { - return d.ny(); - } - void eval(const ConstVector &in, Vector &out) override; -}; - -#endif diff --git a/dynare++/src/dynare_atoms.cc b/dynare++/src/dynare_atoms.cc deleted file mode 100644 index 567dcb28f4d0d80250948edfe559e73c8b0bb513..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_atoms.cc +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "parser/cc/parser_exception.hh" -#include "utils/cc/exception.hh" - -#include "dynare_atoms.hh" - -#include <string> -#include <cmath> -#include <limits> -#include <sstream> -#include <iomanip> - -using namespace ogdyn; -using std::string; - -void -DynareStaticAtoms::register_name(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("The name "+name+" is not unique.", 0); - StaticAtoms::register_name(std::move(name)); -} - -int -DynareStaticAtoms::check_variable(const string &name) const -{ - if (!varnames.query(name)) - throw ogp::ParserException("Unknown name <"+name+">", 0); - auto it = vars.find(name); - if (it == vars.end()) - return -1; - else - return it->second; -} - -void -DynareDynamicAtoms::parse_variable(const string &in, std::string &out, int &ll) const -{ - ll = 0; - auto left = in.find_first_of("({"); - if (left != string::npos) - { - out = in.substr(0, left); - left++; - auto right = in.find_first_of(")}", left); - if (string::npos == right) - throw ogp::ParserException("Syntax error when parsing Dynare atom <"+in+">.", 0); - ll = std::stoi(in.substr(left, right-left)); - } - else - out = in; -} - -void -DynareDynamicAtoms::register_uniq_endo(string name) -{ - FineAtoms::register_uniq_endo(name); - atom_type.emplace(std::move(name), atype::endovar); -} - -void -DynareDynamicAtoms::register_uniq_exo(string name) -{ - FineAtoms::register_uniq_exo(name); - atom_type.emplace(std::move(name), atype::exovar); -} - -void -DynareDynamicAtoms::register_uniq_param(string name) -{ - FineAtoms::register_uniq_param(name); - atom_type.emplace(std::move(name), atype::param); -} - -bool -DynareDynamicAtoms::is_type(const string &name, atype tp) const -{ - auto it = atom_type.find(name); - if (it != atom_type.end() && it->second == tp) - return true; - else - return false; -} - -void -DynareDynamicAtoms::print() const -{ - SAtoms::print(); - std::cout << "Name types:\n"; - for (auto it : atom_type) - std::cout << "name=" << it.first << " type=" - << (it.second == atype::endovar ? "endovar" : it.second == atype::exovar ? "exovar" : "param") - << '\n'; -} - -std::string -DynareDynamicAtoms::convert(int t) const -{ - if (t < ogp::OperationTree::num_constants) - { - throw ogu::Exception(__FILE__, __LINE__, - "Tree index is a built-in constant in DynareDynamicAtoms::convert"); - return {}; - } - if (is_constant(t)) - { - double v = get_constant_value(t); - std::ostringstream buf; - buf << std::setprecision(std::numeric_limits<double>::max_digits10) - << v; - return buf.str(); - } - - const string &s = name(t); - if (is_type(s, atype::endovar)) - { - int ll = lead(t); - if (ll) - return s + '(' + std::to_string(ll) + ')'; - } - - return s; -} - -void -DynareAtomValues::setValues(ogp::EvalTree &et) const -{ - // set constants - atoms.setValues(et); - - // set parameteres - for (unsigned int i = 0; i < atoms.get_params().size(); i++) - if (atoms.is_referenced(atoms.get_params()[i])) - { - const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_params()[i]); - for (auto it : lmap) - { - int t = it.second; - et.set_nulary(t, paramvals[i]); - } - } - - // set endogenous - for (unsigned int outer_i = 0; outer_i < atoms.get_endovars().size(); outer_i++) - if (atoms.is_referenced(atoms.get_endovars()[outer_i])) - { - const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_endovars()[outer_i]); - for (auto it : lmap) - { - int ll = it.first; - int t = it.second; - int i = atoms.outer2y_endo()[outer_i]; - if (ll == -1) - et.set_nulary(t, yym[i-atoms.nstat()]); - else if (ll == 0) - et.set_nulary(t, yy[i]); - else - et.set_nulary(t, yyp[i-atoms.nstat()-atoms.npred()]); - } - } - - // set exogenous - for (unsigned int outer_i = 0; outer_i < atoms.get_exovars().size(); outer_i++) - if (atoms.is_referenced(atoms.get_exovars()[outer_i])) - { - const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_exovars()[outer_i]); - for (auto it : lmap) - { - int ll = it.first; - if (ll == 0) // this is always true because of checks - { - int t = it.second; - int i = atoms.outer2y_exo()[outer_i]; - et.set_nulary(t, xx[i]); - } - } - } -} - -void -DynareStaticSteadyAtomValues::setValues(ogp::EvalTree &et) const -{ - // set constants - atoms_static.setValues(et); - - // set parameters - for (auto name : atoms_static.get_params()) - { - int t = atoms_static.index(name); - if (t != -1) - { - int idyn = atoms.name2outer_param(name); - et.set_nulary(t, paramvals[idyn]); - } - } - - // set endogenous - for (auto name : atoms_static.get_endovars()) - { - int t = atoms_static.index(name); - if (t != -1) - { - int idyn = atoms.outer2y_endo()[atoms.name2outer_endo(name)]; - et.set_nulary(t, yy[idyn]); - } - } - - // set exogenous - for (auto name : atoms_static.get_exovars()) - { - int t = atoms_static.index(name); - if (t != -1) - et.set_nulary(t, 0.0); - } -} - -DynareSteadySubstitutions::DynareSteadySubstitutions(const ogp::FineAtoms &a, - const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy) - : atoms(a), y(yy) -{ - // fill the vector of left and right hand sides - for (auto it : subst) - { - left_hand_sides.push_back(it.first); - right_hand_sides.push_back(it.second); - } - - // evaluate right hand sides - DynareSteadyAtomValues dsav(atoms, pvals, y); - ogp::FormulaCustomEvaluator fe(tree, right_hand_sides); - fe.eval(dsav, *this); -} - -void -DynareSteadySubstitutions::load(int i, double res) -{ - const string &name = left_hand_sides[i]; - int iouter = atoms.name2outer_endo(name); - int iy = atoms.outer2y_endo()[iouter]; - if (!std::isfinite(y[iy])) - y[iy] = res; -} - -DynareStaticSteadySubstitutions:: -DynareStaticSteadySubstitutions(const ogp::FineAtoms &a, const ogp::StaticFineAtoms &sa, - const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy) - : atoms(a), atoms_static(sa), y(yy) -{ - // fill the vector of left and right hand sides - for (const auto &it : subst) - { - left_hand_sides.push_back(it.first); - right_hand_sides.push_back(it.second); - } - - // evaluate right hand sides - DynareStaticSteadyAtomValues dsav(atoms, atoms_static, pvals, y); - ogp::FormulaCustomEvaluator fe(tree, right_hand_sides); - fe.eval(dsav, *this); -} - -void -DynareStaticSteadySubstitutions::load(int i, double res) -{ - const string &name = left_hand_sides[i]; - int iouter = atoms.name2outer_endo(name); - int iy = atoms.outer2y_endo()[iouter]; - if (!std::isfinite(y[iy])) - y[iy] = res; -} diff --git a/dynare++/src/dynare_atoms.hh b/dynare++/src/dynare_atoms.hh deleted file mode 100644 index 60d8244910c9e52946b46d0585acee4a3dee1494..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_atoms.hh +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGDYN_DYNARE_ATOMS_H -#define OGDYN_DYNARE_ATOMS_H - -#include "sylv/cc/Vector.hh" - -#include "parser/cc/static_atoms.hh" -#include "parser/cc/static_fine_atoms.hh" -#include "parser/cc/atom_substitutions.hh" -#include "parser/cc/tree.hh" - -#include <map> -#include <vector> - -namespace ogdyn -{ - using std::map; - using std::vector; - using std::string; - - /* A definition of a type mapping a string to an integer. Used as a - substitution map, saying what names are substituted for what expressions - represented by tree indices. */ - using Tsubstmap = map<string, int>; - - class DynareStaticAtoms : public ogp::StaticAtoms - { - public: - DynareStaticAtoms() - : StaticAtoms() - { - } - DynareStaticAtoms(const DynareStaticAtoms &a) = default; - ~DynareStaticAtoms() override = default; - /* This registers a unique varname identifier. It throws an exception if - the variable name is duplicate. It checks the uniqueness and then it - calls StaticAtoms::register_name. */ - void register_name(string name) override; - protected: - /* This returns a tree index of the given variable, and if the variable has - not been registered, it throws an exception. */ - int check_variable(const string &name) const override; - }; - - class DynareDynamicAtoms : public ogp::SAtoms, public ogp::NularyStringConvertor - { - public: - enum class atype { endovar, exovar, param }; - protected: - using Tatypemap = map<string, atype>; - /* The map assigining a type to each name. */ - Tatypemap atom_type; - public: - DynareDynamicAtoms() - : ogp::SAtoms() - { - } - /* This parses a variable of the forms: varname(+3), varname(3), varname, - varname(-3), varname(0), varname(+0), varname(-0). */ - void parse_variable(const string &in, std::string &out, int &ll) const override; - /* Registers unique name of endogenous variable. */ - void register_uniq_endo(string name) override; - /* Registers unique name of exogenous variable. */ - void register_uniq_exo(string name) override; - /* Registers unique name of parameter. */ - void register_uniq_param(string name) override; - /* Return true if the name is a given type. */ - bool is_type(const string &name, atype tp) const; - /* Debug print. */ - void print() const override; - /* Implement NularyStringConvertor::convert. */ - std::string convert(int t) const override; - }; - - /* This class represents the atom values for dynare, where exogenous - variables can occur only at time t, and endogenous at times t−1, t, and - t+1. */ - class DynareAtomValues : public ogp::AtomValues - { - protected: - /* Reference to the atoms (we suppose that they are only at t−1,t,t+1. */ - const ogp::FineAtoms &atoms; - /* De facto reference to the values of parameters. */ - const ConstVector paramvals; - /* De facto reference to the values of endogenous at time t−1. Only - predetermined and both part. */ - const ConstVector yym; - /* De facto reference to the values of endogenous at time t. Ordering given - by the atoms. */ - const ConstVector yy; - /* De facto reference to the values of endogenous at time t+1. Only both - and forward looking part. */ - const ConstVector yyp; - /* De facto reference to the values of exogenous at time t. */ - const ConstVector xx; - public: - DynareAtomValues(const ogp::FineAtoms &a, const Vector &pvals, const Vector &ym, - const Vector &y, const Vector &yp, const Vector &x) - : atoms(a), paramvals(pvals), yym(ym), yy(y), yyp(yp), xx(x) - { - } - DynareAtomValues(const ogp::FineAtoms &a, const Vector &pvals, const ConstVector &ym, - const ConstVector &y, const ConstVector &yp, const Vector &x) - : atoms(a), paramvals(pvals), yym(ym), yy(y), yyp(yp), xx(x) - { - } - void setValues(ogp::EvalTree &et) const override; - }; - - /* This class represents the atom values at the steady state. It makes only - appropriate subvector yym and yyp of the y vector, makes a vector of zero - exogenous variables and uses DynareAtomValues with more general - interface. */ - class DynareSteadyAtomValues : public ogp::AtomValues - { - protected: - /* Subvector of yy. */ - const ConstVector yym; - /* Subvector of yy. */ - const ConstVector yyp; - /* Vector of zeros for exogenous variables. */ - Vector xx; - /* Atom values using this yym, yyp and xx. */ - DynareAtomValues av; - public: - DynareSteadyAtomValues(const ogp::FineAtoms &a, const Vector &pvals, const Vector &y) - : yym(y, a.nstat(), a.nys()), - yyp(y, a.nstat()+a.npred(), a.nyss()), - xx(a.nexo()), - av(a, pvals, yym, y, yyp, xx) - { - xx.zeros(); - } - void - setValues(ogp::EvalTree &et) const override - { - av.setValues(et); - } - }; - - class DynareStaticSteadyAtomValues : public ogp::AtomValues - { - protected: - /* Reference to static atoms over which the tree, where the values go, is - defined. */ - const ogp::StaticFineAtoms &atoms_static; - /* Reference to dynamic atoms for which the class gets input data. */ - const ogp::FineAtoms &atoms; - /* De facto reference to input data, this is a vector of endogenous - variables in internal ordering of the dynamic atoms. */ - ConstVector yy; - /* De facto reference to input parameters corresponding to ordering defined - by the dynamic atoms. */ - ConstVector paramvals; - public: - /* Construct the object. */ - DynareStaticSteadyAtomValues(const ogp::FineAtoms &a, const ogp::StaticFineAtoms &sa, - const Vector &pvals, const Vector &yyy) - : atoms_static(sa), - atoms(a), - yy(yyy), - paramvals(pvals) - { - } - /* Set the values to the tree defined over the static atoms. */ - void setValues(ogp::EvalTree &et) const override; - }; - - /* This class takes a vector of endogenous variables and a substitution map. - It supposes that variables at the right hand sides of the substitutions - are set in the endogenous vector. It evaluates the substitutions and if - the variables corresponding to left hand sides are not set in the - endogenous vector it sets them to calculated values. If a variable is - already set, it does not override its value. It has no methods, everything - is done in the constructor. */ - class DynareSteadySubstitutions : public ogp::FormulaEvalLoader - { - protected: - const ogp::FineAtoms &atoms; - public: - DynareSteadySubstitutions(const ogp::FineAtoms &a, const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy); - void load(int i, double res) override; - protected: - Vector &y; - vector<string> left_hand_sides; - vector<int> right_hand_sides; - }; - - /* This class is a static version of DynareSteadySustitutions. It works for - static atoms and static tree and substitution map over the static tree. It - also needs dynamic version of the atoms, since it defines ordering of the - vectors pvals, and yy. */ - class DynareStaticSteadySubstitutions : public ogp::FormulaEvalLoader - { - protected: - const ogp::FineAtoms &atoms; - const ogp::StaticFineAtoms &atoms_static; - public: - DynareStaticSteadySubstitutions(const ogp::FineAtoms &a, - const ogp::StaticFineAtoms &sa, - const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy); - void load(int i, double res) override; - protected: - Vector &y; - vector<string> left_hand_sides; - vector<int> right_hand_sides; - }; - -}; - -#endif diff --git a/dynare++/src/dynare_model.cc b/dynare++/src/dynare_model.cc deleted file mode 100644 index ce9e48dcb61485cb30e0e76de5b92918f4795eaa..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_model.cc +++ /dev/null @@ -1,968 +0,0 @@ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "parser/cc/parser_exception.hh" -#include "parser/cc/location.hh" -#include "utils/cc/exception.hh" -#include "dynare_model.hh" -#include "dynare_exception.hh" -#include "planner_builder.hh" -#include "forw_subst_builder.hh" - -#include <string> -#include <cmath> -#include <limits> -#include <ostream> -#include <memory> -#include <algorithm> -#include <iomanip> - -using namespace ogdyn; - -ParsedMatrix::ParsedMatrix(const ogp::MatrixParser &mp) - : TwoDMatrix(mp.nrows(), mp.ncols()) -{ - zeros(); - for (ogp::MPIterator it = mp.begin(); it != mp.end(); ++it) - get(it.row(), it.col()) = *it; -} - -DynareModel::DynareModel() - : atoms(), eqs(atoms) -{ -} - -DynareModel::DynareModel(const DynareModel &dm) - : atoms(dm.atoms), eqs(dm.eqs, atoms), order(dm.order), - t_plobjective(dm.t_plobjective), - t_pldiscount(dm.t_pldiscount) -{ - if (dm.param_vals) - param_vals = std::make_unique<Vector>(const_cast<const Vector &>(*dm.param_vals)); - if (dm.init_vals) - init_vals = std::make_unique<Vector>(const_cast<const Vector &>(*dm.init_vals)); - if (dm.vcov_mat) - vcov_mat = std::make_unique<TwoDMatrix>(const_cast<const TwoDMatrix &>(*dm.vcov_mat)); - if (dm.old_atoms) - old_atoms = std::make_unique<DynareDynamicAtoms>(static_cast<const DynareDynamicAtoms &>(*dm.old_atoms)); - if (dm.atom_substs) - atom_substs = std::make_unique<ogp::AtomSubstitutions>(*dm.atom_substs, *old_atoms, atoms); - if (dm.pbuilder) - pbuilder = std::make_unique<PlannerBuilder>(*dm.pbuilder, *this); - if (dm.fbuilder) - fbuilder = std::make_unique<ForwSubstBuilder>(*dm.fbuilder, *this); -} - -const PlannerInfo * -DynareModel::get_planner_info() const -{ - if (pbuilder) - return &(pbuilder->get_info()); - return nullptr; -} - -const ForwSubstInfo * -DynareModel::get_forw_subst_info() const -{ - if (fbuilder) - return &(fbuilder->get_info()); - return nullptr; -} - -const ogp::SubstInfo * -DynareModel::get_subst_info() const -{ - if (atom_substs) - return &(atom_substs->get_info()); - return nullptr; -} - -void -DynareModel::setInitOuter(const Vector &x) -{ - if (x.length() != atoms.ny()) - throw DynareException(__FILE__, __LINE__, - "Wrong length of vector in DynareModel::setInitOuter"); - for (int i = 0; i < atoms.ny(); i++) - (*init_vals)[i] = x[atoms.y2outer_endo()[i]]; -} - -void -DynareModel::print() const -{ - std::cout << "all atoms:\n"; - atoms.print(); - std::cout << "formulas:\n"; - DebugOperationFormatter dof(*this); - for (int i = 0; i < eqs.nformulas(); i++) - { - int tf = eqs.formula(i); - std::cout << "formula " << tf << "%d:\n"; - eqs.getTree().print_operation_tree(tf, std::cout, dof); - } -} - -void -DynareModel::dump_model(std::ostream &os) const -{ - // endogenous variable declaration - os << "var"; - for (auto i : atoms.get_endovars()) - os << " " << i; - os << ";\n\n"; - - // exogenous variables - os << "varexo"; - for (auto i : atoms.get_exovars()) - os << " " << i; - os << ";\n\n"; - - // parameters - os << "parameters"; - for (auto i : atoms.get_params()) - os << " " << i; - os << ";\n\n"; - - // parameter values - os.precision(16); - for (int i = 0; i < static_cast<int>(atoms.get_params().size()); i++) - os << atoms.get_params()[i] << "=" << getParams()[i] << ";\n"; - os << "\n\n"; - - // model section - ogp::OperationStringConvertor osc(atoms, getParser().getTree()); - os << "model;\n"; - for (int i = 0; i < getParser().nformulas(); i++) - { - os << "// Equation " << i << "\n0 = "; - int t = getParser().formula(i); - os << osc.convert(getParser().getTree().operation(t), t); - os << ";\n"; - } - os << "end;\n"; - - // initval as steady state - os << "initval;\n"; - for (int i = 0; i < static_cast<int>(atoms.get_endovars().size()); i++) - os << atoms.get_endovars()[atoms.y2outer_endo()[i]] << "=" << getInit()[i] << ";\n"; - os << "end;\n"; -} - -void -DynareModel::add_name(std::string name, int flag) -{ - if (flag == 1) - // endogenous - atoms.register_uniq_endo(name); - else if (flag == 2) - // exogenous - atoms.register_uniq_exo(name); - else if (flag == 3) - // parameter - atoms.register_uniq_param(name); - else - throw DynareException(__FILE__, __LINE__, "Unrecognized flag value."); -} - -void -DynareModel::check_model() const -{ - if (order == -1) - throw DynareException(__FILE__, __LINE__, - "Order of approximation not set in DynareModel::check_model"); - - if (atoms.ny() != eqs.nformulas()) - throw DynareException(__FILE__, __LINE__, "Model has " + std::to_string(eqs.nformulas()) - + " equations for " + std::to_string(atoms.ny()) + " endogenous variables"); - - /* check whether all nulary terms of all formulas in eqs are either constant - or assigned to a name */ - for (int i = 0; i < eqs.nformulas(); i++) - { - int ft = eqs.formula(i); - const unordered_set<int> &nuls = eqs.nulary_of_term(ft); - for (int nul : nuls) - if (!atoms.is_constant(nul) && !atoms.is_named_atom(nul)) - throw DynareException(__FILE__, __LINE__, - "Dangling nulary term found, internal error."); - } - - int mlag, mlead; - atoms.exovarspan(mlead, mlag); - if (atoms.nexo() > 0 && (mlead != 0 || mlag != 0)) - throw DynareException(__FILE__, __LINE__, - "The model contains occurrences of lagged/leaded exogenous variables"); - - atoms.endovarspan(mlead, mlag); - if (mlead > 1 || mlag < -1) - throw DynareException(__FILE__, __LINE__, - "The model contains occurrences of too lagged/leaded endogenous variables"); - - // check the dimension of vcov matrix - if (getAtoms().nexo() != getVcov().nrows()) - throw DynareException(__FILE__, __LINE__, - "Dimension of VCOV matrix does not correspond to the shocks"); -} - -int -DynareModel::variable_shift(int t, int tshift) -{ - const string &name = atoms.name(t); - if (atoms.is_type(name, DynareDynamicAtoms::atype::param) - || atoms.is_constant(t)) - throw DynareException(__FILE__, __LINE__, - "The tree index is not a variable in DynareModel::variable_shift"); - int ll = atoms.lead(t) + tshift; - int res = atoms.index(name, ll); - if (res == -1) - res = eqs.add_nulary(name + '(' + std::to_string(ll) + ')'); - return res; -} - -void -DynareModel::variable_shift_map(const unordered_set<int> &a_set, int tshift, - map<int, int> &s_map) -{ - s_map.clear(); - for (int t : a_set) - // make shift map only for non-constants and non-parameters - if (!atoms.is_constant(t)) - { - const string &name = atoms.name(t); - if (atoms.is_type(name, DynareDynamicAtoms::atype::endovar) - || atoms.is_type(name, DynareDynamicAtoms::atype::exovar)) - { - int tt = variable_shift(t, tshift); - s_map.emplace(t, tt); - } - } -} - -void -DynareModel::termspan(int t, int &mlead, int &mlag) const -{ - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - const unordered_set<int> &nul_terms = eqs.nulary_of_term(t); - for (int nul_term : nul_terms) - { - if (!atoms.is_constant(nul_term) - && (atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::atype::endovar) - || atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::atype::exovar))) - { - int ll = atoms.lead(nul_term); - mlag = std::min(ll, mlag); - mlead = std::max(ll, mlead); - } - } -} - -bool -DynareModel::is_constant_term(int t) const -{ - const unordered_set<int> &nul_terms = eqs.nulary_of_term(t); - for (int nul_term : nul_terms) - if (!atoms.is_constant(nul_term) - && !atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::atype::param)) - return false; - return true; -} - -unordered_set<int> -DynareModel::get_nonlinear_subterms(int t) const -{ - NLSelector nls(*this); - return eqs.getTree().select_terms(t, nls); -} - -void -DynareModel::substitute_atom_for_term(const string &name, int ll, int t) -{ - /* if the term t is itself a named atom (parameter, exo, endo), then we have - to unassign it first */ - if (atoms.is_named_atom(t)) - atoms.unassign_variable(atoms.name(t), atoms.lead(t), t); - /* assign allocated tree index for the term now to name(ll) */ - atoms.assign_variable(name, ll, t); - // make operation t nulary in operation tree - eqs.nularify(t); -} - -void -DynareModel::final_job() -{ - if (t_plobjective != -1 && t_pldiscount != -1) - { - /* at this moment include all equations and all variables; in future we - will exclude purely exogenous processes; TODO */ - PlannerBuilder::Tvarset vset; - for (int i = 0; i < atoms.ny(); i++) - vset.insert(atoms.get_endovars()[i]); - PlannerBuilder::Teqset eset; - for (int i = 0; i < eqs.nformulas(); i++) - eset.push_back(i); - - // construct the planner builder, this adds a lot of stuff to the model - pbuilder = std::make_unique<PlannerBuilder>(*this, vset, eset); - } - - // construct ForwSubstBuilder - fbuilder = std::make_unique<ForwSubstBuilder>(*this); - - // call parsing_finished (this will define an outer ordering of all variables) - atoms.parsing_finished(ogp::VarOrdering::bfspbfpb); - // make a copy of atoms and name it old_atoms - old_atoms = std::make_unique<DynareDynamicAtoms>(atoms); - // construct empty substitutions from old_atoms to atoms - atom_substs = std::make_unique<ogp::AtomSubstitutions>(*old_atoms, atoms); - /* do the actual substitution, it will also call parsing_finished for atoms - which creates internal orderings */ - atoms.substituteAllLagsAndExo1Leads(eqs, *atom_substs); -} - -extern ogp::location_type dynglob_lloc; - -DynareParser::DynareParser(const string &stream, int ord) - : DynareModel(), - pa_atoms(), paramset(pa_atoms), - ia_atoms(), initval(ia_atoms), vcov(), - model_beg(0), model_end(-1), - paramset_beg(0), paramset_end(-1), - initval_beg(0), initval_end(-1), - vcov_beg(0), vcov_end(-1), - order_beg(0), order_end(-1), - plobjective_beg(0), plobjective_end(-1), - pldiscount_beg(0), pldiscount_end(-1) -{ - // global parse - try - { - parse_glob(stream); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, dynglob_lloc.off); - } - // setting parameters parse - try - { - if (paramset_end > paramset_beg) - paramset.parse(stream.substr(paramset_beg, paramset_end-paramset_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, paramset_beg); - } - // model parse - try - { - if (model_end > model_beg) - eqs.parse(stream.substr(model_beg, model_end-model_beg)); - else - throw ogp::ParserException("Model section not found.", 0); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, model_beg); - } - // initval setting parse - try - { - if (initval_end > initval_beg) - initval.parse(stream.substr(initval_beg, initval_end-initval_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, initval_beg); - } - // vcov parse - try - { - if (vcov_end > vcov_beg) - vcov.parse(stream.substr(vcov_beg, vcov_end-vcov_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, vcov_beg); - } - // planner objective parse - try - { - if (plobjective_end > plobjective_beg) - { - eqs.parse(stream.substr(plobjective_beg, plobjective_end-plobjective_beg)); - t_plobjective = eqs.pop_last_formula(); - } - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, plobjective_beg); - } - // planner discount parse - try - { - if (pldiscount_end > pldiscount_beg) - t_pldiscount = parse_pldiscount(stream.substr(pldiscount_beg, pldiscount_end - pldiscount_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, pldiscount_beg); - } - // order parse - try - { - if (order_end > order_beg) - order = parse_order(stream.substr(order_beg, order_end - order_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, order_beg); - } - - // check the overridden order - if (ord != -1) - order = ord; - - // end parsing job, add planner's FOCs, make substitutions - DynareModel::final_job(); - - // calculate parameters - calc_params(); - // calculate initial values - calc_init(); - - if (vcov_end > vcov_beg) - vcov_mat = std::make_unique<ParsedMatrix>(vcov); - else - { - // vcov has not been asserted, set it to unit matrix - vcov_mat = std::make_unique<TwoDMatrix>(atoms.nexo(), atoms.nexo()); - vcov_mat->unit(); - } - - // check the model - check_model(); - - // differentiate - if (order >= 1) - eqs.differentiate(order); -} - -DynareParser::DynareParser(const DynareParser &dp) - : DynareModel(dp), - pa_atoms(dp.pa_atoms), paramset(dp.paramset, pa_atoms), - ia_atoms(dp.ia_atoms), initval(dp.initval, ia_atoms), vcov(dp.vcov), - model_beg(dp.model_beg), model_end(dp.model_end), - paramset_beg(dp.paramset_beg), paramset_end(dp.paramset_end), - initval_beg(dp.initval_beg), initval_end(dp.initval_end), - vcov_beg(dp.vcov_beg), vcov_end(dp.vcov_end), - order_beg(dp.order_beg), order_end(dp.order_end), - plobjective_beg(dp.plobjective_beg), plobjective_end(dp.plobjective_end), - pldiscount_beg(dp.pldiscount_beg), pldiscount_end(dp.pldiscount_end) -{ -} - -void -DynareParser::add_name(string name, int flag) -{ - DynareModel::add_name(name, flag); - // register with static atoms used for atom assignements - if (flag == 1) - // endogenous - ia_atoms.register_name(std::move(name)); - else if (flag == 2) - // exogenous - ia_atoms.register_name(std::move(name)); - else if (flag == 3) - { - // parameter - pa_atoms.register_name(name); - ia_atoms.register_name(std::move(name)); - } - else - throw DynareException(__FILE__, __LINE__, "Unrecognized flag value."); -} - -void -DynareParser::error(string mes) -{ - // throwing zero offset since this exception will be caugth at constructor - throw ogp::ParserException(std::move(mes), 0); -} - -void -DynareParser::print() const -{ - DynareModel::print(); - std::cout << "parameter atoms:\n"; - paramset.print(); - std::cout << "initval atoms:\n"; - initval.print(); - std::cout << "model position: " << model_beg << ' ' << model_end << '\n' - << "paramset position: " << paramset_beg << ' ' << paramset_end << '\n' - << "initval position: " << initval_beg << ' ' << initval_end << '\n'; -} - -/* A global symbol for passing info to the DynareParser from parser. */ -DynareParser *dynare_parser; - -/* The declarations of functions defined in dynglob_ll.cc and dynglob_tab.cc - generated from dynglob.lex and dynglob.y */ -void *dynglob__scan_string(const char *); -void dynglob__destroy_buffer(void *); -void dynglob_parse(); -extern ogp::location_type dynglob_lloc; - -void -DynareParser::parse_glob(const string &stream) -{ - void *p = dynglob__scan_string(stream.c_str()); - dynare_parser = this; - dynglob_parse(); - dynglob__destroy_buffer(p); -} - -int -DynareParser::parse_order(const string &str) -{ - return std::stoi(str); -} - -int -DynareParser::parse_pldiscount(const string &str) -{ - if (!atoms.is_type(str, DynareDynamicAtoms::atype::param)) - throw ogp::ParserException("Name " + str + " is not a parameter", 0); - - int t = atoms.index(str, 0); - if (t == -1) - t = eqs.add_nulary(str); - - return t; -} - -void -DynareParser::calc_params() -{ - param_vals = std::make_unique<Vector>(atoms.np()); - ogp::AtomAsgnEvaluator aae(paramset); - aae.eval(); - for (int i = 0; i < atoms.np(); i++) - (*param_vals)[i] = aae.get_value(atoms.get_params()[i]); - - for (unsigned int i = 0; i < atoms.get_params().size(); i++) - if (!std::isfinite((*param_vals)[i])) - std::cout << "dynare++: warning: value for parameter " << atoms.get_params()[i] << " is not finite\n"; -} - -void -DynareParser::calc_init() -{ - // update initval atoms assignings according to substitutions - if (atom_substs) - initval.apply_subst(atom_substs->get_old2new()); - - // calculate the vector of initial values - init_vals = std::make_unique<Vector>(atoms.ny()); - ogp::AtomAsgnEvaluator aae(initval); - // set parameters - for (int ip = 0; ip < atoms.np(); ip++) - aae.set_user_value(atoms.get_params()[ip], (*param_vals)[ip]); - // set exogenous to zeros - for (int ie = 0; ie < atoms.nexo(); ie++) - aae.set_user_value(atoms.get_exovars()[ie], 0.0); - // evaluate - aae.eval(); - // set results to internally ordered vector init_vals - for (int outer = 0; outer < atoms.ny(); outer++) - { - int i = atoms.outer2y_endo()[outer]; - (*init_vals)[i] = aae.get_value(atoms.get_endovars()[outer]); - } - - /* if the planner's FOCs have been added, then add estimate of Lagrange - multipliers to the vector */ - if (pbuilder) - MultInitSS mis(*pbuilder, *param_vals, *init_vals); - - /* if forward substitution builder has been created, we have to its - substitutions and evaluate them */ - if (fbuilder) - ogdyn::DynareSteadySubstitutions dss(atoms, eqs.getTree(), - fbuilder->get_aux_map(), *param_vals, *init_vals); - - for (unsigned int i = 0; i < atoms.get_endovars().size(); i++) - if (!std::isfinite((*init_vals)[i])) - std::cout << "dynare++: warning: initval for <" << atoms.get_endovars()[atoms.y2outer_endo()[i]] << "> is not finite\n"; -} - -// this returns false for linear functions -bool -NLSelector::operator()(int t) const -{ - const ogp::Operation &op = model.getParser().getTree().operation(t); - const DynareDynamicAtoms &atoms = model.getAtoms(); - // if the term is constant, return false - if (model.is_constant_term(t)) - return false; - int nary = op.nary(); - if (nary == 0) - { - if (atoms.is_type(atoms.name(t), DynareDynamicAtoms::atype::endovar) - || atoms.is_type(atoms.name(t), DynareDynamicAtoms::atype::exovar)) - return true; - else - return false; - } - else if (nary == 1) - { - if (op.getCode() == ogp::code_t::UMINUS) - return false; - else - return true; - } - else - { - if (op.getCode() == ogp::code_t::TIMES) - // if at least one operand is constant, than the TIMES is linear - if (model.is_constant_term(op.getOp1()) - || model.is_constant_term(op.getOp2())) - return false; - else - return true; - // both PLUS and MINUS are linear - if (op.getCode() == ogp::code_t::PLUS - || op.getCode() == ogp::code_t::MINUS) - return false; - // POWER is linear if exponent or base is 0 or one - if (op.getCode() == ogp::code_t::POWER - && (op.getOp1() == ogp::OperationTree::zero - || op.getOp1() == ogp::OperationTree::one - || op.getOp2() == ogp::OperationTree::zero - || op.getOp2() == ogp::OperationTree::one)) - return false; - else - return true; - /* DIVIDE is linear if the denominator is constant, or if the nominator - is zero */ - if (op.getCode() == ogp::code_t::DIVIDE - && (op.getOp1() == ogp::OperationTree::zero - || model.is_constant_term(op.getOp2()))) - return false; - else - return true; - } - - throw DynareException(__FILE__, __LINE__, - "Wrong operation in operation tree"); - return false; -} - -DynareSPModel::DynareSPModel(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const string &equations, - int ord) - : DynareModel() -{ - // set the order - order = ord; - - // add names - for (const auto &it : endo) - add_name(it, 1); - for (const auto &it : exo) - add_name(it, 2); - for (const auto &it : par) - add_name(it, 3); - - // parse the equations - eqs.parse(equations); - - // parsing finished - atoms.parsing_finished(ogp::VarOrdering::bfspbfpb); - - // create what has to be created from DynareModel - param_vals = std::make_unique<Vector>(atoms.np()); - init_vals = std::make_unique<Vector>(atoms.ny()); - vcov_mat = std::make_unique<TwoDMatrix>(atoms.nexo(), atoms.nexo()); - - // check the model - check_model(); - - // differentiate - if (order >= 1) - eqs.differentiate(order); -} - -void -ModelSSWriter::write_der0(std::ostream &os) -{ - write_der0_preamble(os); - write_atom_assignment(os); - - stop_set.clear(); - for (int fi = 0; fi < model.eqs.nformulas(); fi++) - otree.print_operation_tree(model.eqs.formula(fi), os, *this); - - write_der0_assignment(os); -} - -void -ModelSSWriter::write_der1(std::ostream &os) -{ - write_der1_preamble(os); - write_atom_assignment(os); - - stop_set.clear(); - - const vector<int> &variables = model.getAtoms().variables(); - const vector<int> &eam = model.getAtoms().get_endo_atoms_map(); - for (int i = 0; i < model.getParser().nformulas(); i++) - { - const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i); - for (int j : eam) - { - int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, j)); - if (t > 0) - otree.print_operation_tree(t, os, *this); - } - } - - write_der1_assignment(os); -} - -MatlabSSWriter::MatlabSSWriter(const DynareModel &dm, std::string id_arg) - : ModelSSWriter(dm), id(std::move(id_arg)) -{ -} - -void -MatlabSSWriter::write_der0_preamble(std::ostream &os) const -{ - os << "% Usage:\n" - << "% out = " << id << "_f(params, y)\n" - << "% where\n" - << "% out is a (" << model.getAtoms().ny() << ",1) column vector of the residuals\n" - << "% of the static system\n"; - write_common1_preamble(os); - os << "function out = " << id << "_f(params, y)\n"; - write_common2_preamble(os); -} - -void -MatlabSSWriter::write_der1_preamble(std::ostream &os) const -{ - os << "% Usage:\n" - << "% out = " << id << "_ff(params, y)\n" - << "% where\n" - << "% out is a (" << model.getAtoms().ny() << "," << model.getAtoms().ny() << ") matrix of the first order\n" - << "% derivatives of the static system residuals\n" - << "% columns correspond to endo variables in\n" - << "% the ordering as declared\n"; - write_common1_preamble(os); - os << "function out = " << id << "_ff(params, y)\n"; - write_common2_preamble(os); -} - -void -MatlabSSWriter::write_common1_preamble(std::ostream &os) const -{ - os << "% params is a (" << model.getAtoms().np() << ",1) vector of parameter values\n" - << "% in the ordering as declared\n" - << "% y is a (" << model.getAtoms().ny() << ",1) vector of endogenous variables\n" - << "% in the ordering as declared\n" - << "%\n" - << "% Created by Dynare++ v. " << VERSION << "\n"; - // write ordering of parameters - os << "\n% params ordering\n% =====================\n"; - for (auto parname : model.getAtoms().get_params()) - os << "% " << parname << "\n"; - - // write endogenous variables - os << "%\n% y ordering\n% =====================\n"; - for (auto endoname : model.getAtoms().get_endovars()) - os << "% " << endoname << "\n"; - os << "\n"; -} - -void -MatlabSSWriter::write_common2_preamble(std::ostream &os) const -{ - os << "if size(y) ~= [" << model.getAtoms().ny() << ",1]\n" - << "\terror('Wrong size of y, must be [" << model.getAtoms().ny() << ",1]');\nend\n" - << "if size(params) ~= [" << model.getAtoms().np() << ",1]\n" - << "\terror('Wrong size of params, must be [" << model.getAtoms().np() << ",1]');\nend\n\n"; -} - -void -MatlabSSWriter::write_atom_assignment(std::ostream &os) const -{ - // write OperationTree::num_constants - os << "% hardwired constants\n"; - ogp::EvalTree etree(model.getParser().getTree(), ogp::OperationTree::num_constants-1); - for (int i = 0; i < ogp::OperationTree::num_constants; i++) - { - format_nulary(i, os); - double g = etree.eval(i); - if (std::isnan(g)) - os << " = NaN;\n"; - else - os << " = " << std::defaultfloat << std::setprecision(8) << etree.eval(i) << ";\n"; - } - // write numerical constants - os << "% numerical constants\n"; - const ogp::Constants::Tconstantmap &cmap = model.getAtoms().get_constantmap(); - for (auto it : cmap) - { - format_nulary(it.first, os); - os << " = " << std::defaultfloat << std::setprecision(8) << it.second << ";\n"; - } - // write parameters - os << "% parameter values\n"; - for (unsigned int ip = 0; ip < model.getAtoms().get_params().size(); ip++) - { - const string &parname = model.getAtoms().get_params()[ip]; - int t = model.getAtoms().index(parname, 0); - if (t == -1) - os << "% " << parname << " not used in the model\n"; - else - { - format_nulary(t, os); - os << " = params(" << ip+1 << "); % " << parname << "\n"; - } - } - // write exogenous variables - os << "% exogenous variables to zeros\n"; - for (unsigned int ie = 0; ie < model.getAtoms().get_exovars().size(); ie++) - { - const string &exoname = model.getAtoms().get_exovars()[ie]; - try - { - const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(exoname); - for (auto it : lmap) - { - format_nulary(it.second, os); - os << " = 0.0; % " << exoname << "\n"; - } - } - catch (const ogu::Exception &e) - { - // ignore the error of not found variable in the tree - } - } - // write endogenous variables - os << "% endogenous variables to y\n"; - for (unsigned int ie = 0; ie < model.getAtoms().get_endovars().size(); ie++) - { - const string &endoname = model.getAtoms().get_endovars()[ie]; - const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(endoname); - for (auto it : lmap) - { - format_nulary(it.second, os); - os << " = y(" << ie+1 << "); % " << endoname << "\n"; - } - } - os << "\n"; -} - -void -MatlabSSWriter::write_der0_assignment(std::ostream &os) const -{ - - // initialize out variable - os << "% setting the output variable\n" - << "out = zeros(" << model.getParser().nformulas() << ", 1);\n"; - - // fill out with the terms - for (int i = 0; i < model.getParser().nformulas(); i++) - { - os << "out(" << i+1 << ") = "; - format_term(model.getParser().formula(i), os); - os << ";\n"; - } -} - -void -MatlabSSWriter::write_der1_assignment(std::ostream &os) const -{ - // initialize out variable - os << "% setting the output variable\n"; - os << "out = zeros(" << model.getParser().nformulas() << ", " << model.getAtoms().ny() << ");\n"; - - // fill out with the terms - const vector<int> &variables = model.getAtoms().variables(); - const vector<int> &eam = model.getAtoms().get_endo_atoms_map(); - for (int i = 0; i < model.getParser().nformulas(); i++) - { - const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i); - for (int j : eam) - { - int tvar = variables[j]; - const string &name = model.getAtoms().name(tvar); - int yi = model.getAtoms().name2outer_endo(name); - int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, j)); - if (t != ogp::OperationTree::zero) - { - os << "out(" << i+1 << "," << yi+1 << ") = out("<< i+1 << "," << yi+1 << ") + "; - format_term(t, os); - os << "; % " << name << "(" << model.getAtoms().lead(tvar) << ")\n"; - } - } - } -} - -void -MatlabSSWriter::format_term(int t, std::ostream &os) const -{ - os << 't' << t; -} - -void -MatlabSSWriter::format_nulary(int t, std::ostream &os) const -{ - os << 'a' << t; -} - -void -DebugOperationFormatter::format_nulary(int t, std::ostream &os) const -{ - const DynareDynamicAtoms &a = model.getAtoms(); - - if (t == ogp::OperationTree::zero) - os << '0'; - else if (t == ogp::OperationTree::one) - os << '1'; - else if (t == ogp::OperationTree::nan) - os << "NaN"; - else if (t == ogp::OperationTree::two_over_pi) - os << "2/sqrt(PI)"; - else if (a.is_constant(t)) - os << a.get_constant_value(t); - else - { - int ll = a.lead(t); - const std::string &name = a.name(t); - if (ll == 0) - os << name; - else - os << name << '(' << ll << ')'; - } -} diff --git a/dynare++/src/dynare_model.hh b/dynare++/src/dynare_model.hh deleted file mode 100644 index a4498d9dea8dd735280bc5589fe0ba4a46ea633d..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_model.hh +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGDYN_DYNARE_MODEL -#define OGDYN_DYNARE_MODEL - -#include "parser/cc/matrix_parser.hh" -#include "parser/cc/atom_assignings.hh" - -#include "dynare_atoms.hh" -#include "twod_matrix.hh" -#include "planner_builder.hh" -#include "forw_subst_builder.hh" - -#include "Vector.hh" -#include "GeneralMatrix.hh" - -#include <map> -#include <unordered_set> -#include <ostream> -#include <memory> -#include <iostream> - -namespace ogdyn -{ - using std::unordered_set; - using std::map; - - /* This represents an interval in a string by the pair of positions - (including the first, excluding the second). A position is given by the - line and the column within the line (both starting from 1). */ - struct PosInterval - { - int fl; - int fc; - int ll; - int lc; - PosInterval() = default; - PosInterval(int ifl, int ifc, int ill, int ilc) - : fl(ifl), fc(ifc), ll(ill), lc(ilc) - { - } - PosInterval &operator=(const PosInterval &pi) = default; - /* Debug print. */ - void - print() const - { - std::cout << "fl=" << fl << " fc=" << fc << " ll=" << ll << " lc=" << lc << '\n'; - } - }; - - /* This class is basically a GeneralMatrix but is created from parsed matrix - data. */ - class ParsedMatrix : public TwoDMatrix - { - public: - /* Construct the object from the parsed data of ogp::MatrixParser. */ - ParsedMatrix(const ogp::MatrixParser &mp); - }; - - class PlannerBuilder; - class PlannerInfo; - class ForwSubstBuilder; - class ForwSubstInfo; - class MultInitSS; - class ModelSSWriter; - - /* A subclass is responsible for creating param_vals, init_vals, and - vcov_mat. */ - class DynareModel - { - friend class PlannerBuilder; - friend class ForwSubstBuilder; - friend class MultInitSS; - friend class ModelSSWriter; - protected: - /* All atoms for whole model. */ - DynareDynamicAtoms atoms; - /* Parsed model equations. */ - ogp::FormulaParser eqs; - /* Order of approximation. */ - int order{-1}; - /* A vector of parameters values created by a subclass. It is stored with - natural ordering (outer) of the parameters given by atoms. */ - std::unique_ptr<Vector> param_vals; - /* A vector of initial values created by a subclass. It is stored with - internal ordering given by atoms. */ - std::unique_ptr<Vector> init_vals; - /* A matrix for vcov. It is created by a subclass. */ - std::unique_ptr<TwoDMatrix> vcov_mat; - /* Tree index of the planner objective. If there was no planner objective - keyword, the value is set to −1. */ - int t_plobjective{-1}; - /* Tree index of the planner discount. If there was no planner discount - keyword, the value is set to −1. */ - int t_pldiscount{-1}; - /* Pointer to PlannerBuilder, which is created only if the planner's FOC - are added to the model. */ - std::unique_ptr<PlannerBuilder> pbuilder; - /* Pointer to an object which builds auxiliary variables and equations to - rewrite a model containing multiple leads to an equivalent model having - only +1 leads. */ - std::unique_ptr<ForwSubstBuilder> fbuilder; - /* Pointer to AtomSubstitutions which are created when the atoms are being - substituted because of multiple lags etc. It uses also an old copy of - atoms, which is created. */ - std::unique_ptr<ogp::AtomSubstitutions> atom_substs; - /* Pointer to a copy of original atoms before substitutions took place. */ - std::unique_ptr<ogp::SAtoms> old_atoms; - public: - /* Initializes the object to an empty state. */ - DynareModel(); - /* Construct a new deep copy. */ - DynareModel(const DynareModel &dm); - virtual ~DynareModel() = default; - virtual std::unique_ptr<DynareModel> clone() const = 0; - const DynareDynamicAtoms & - getAtoms() const - { - return atoms; - } - const ogp::FormulaParser & - getParser() const - { - return eqs; - } - int - getOrder() const - { - return order; - } - /* Return the vector of parameter values. */ - const Vector & - getParams() const - { - return *param_vals; - } - Vector & - getParams() - { - return *param_vals; - } - /* Return the vector of initial values of endo variables. */ - const Vector & - getInit() const - { - return *init_vals; - } - Vector & - getInit() - { - return *init_vals; - } - /* Return the vcov matrix. */ - const TwoDMatrix & - getVcov() const - { - return *vcov_mat; - } - TwoDMatrix & - getVcov() - { - return *vcov_mat; - } - /* Return planner info. */ - const PlannerInfo *get_planner_info() const; - /* Return forward substitutions info. */ - const ForwSubstInfo *get_forw_subst_info() const; - /* Return substitutions info. */ - const ogp::SubstInfo *get_subst_info() const; - /* This sets initial values given in outer ordering. */ - void setInitOuter(const Vector &x); - /* This returns true if the given term is a function of hardwired - constants, numerical constants and parameters. */ - bool is_constant_term(int t) const; - /* Debug print. */ - void print() const; - /* Dump the model to the output stream. This includes variable - declarations, parameter values, model code, initval, vcov and order. */ - void dump_model(std::ostream &os) const; - protected: - /* Adds a name of endogenous, exogenous or a parameter. The sort is - governed by the flag. See dynglob.yy for values of the flag. This is - used by a subclass when declaring the names. */ - void add_name(std::string name, int flag); - /* This checks the model consistency. Thus includes: number of endo - variables and number of equations, min and max lag of endogenous - variables and occurrrences of exogenous variables. It throws an - exception, if there is a problem. */ - void check_model() const; - /* This shifts the given variable identified by the tree index in time. So - if the given tree index represents a(+3) and the tshift is −4, the - method returns tree index of the a(-1). If a(-1) doesn't exist, it is - added to the tree. If it exists, its tree index is returned. If the tree - index doesn't correspond to an endogenous nor exogenous variable, an - exception is thrown. */ - int variable_shift(int t, int tshift); - /* For the given set of atoms identified by tree indices and given time - shift, this method returns a map mapping each variable in the given set - to its time shifted variable. The map is passed through the reference - and is cleared in the beginning. */ - void variable_shift_map(const unordered_set<int> &a_set, int tshift, - map<int, int> &s_map); - /* This returns maximum lead and minimum lag of an endogenous or exogenous - variable in the given term. If there are no endo or exo variables, than - it returns the least integer as max lead and the greatest integer as min - lag. */ - void termspan(int t, int &mlead, int &mlag) const; - /* This function returns a set of non-linear subterms of the given term, - these are terms whose linear combination constitutes the given term. */ - unordered_set<int> get_nonlinear_subterms(int t) const; - /* This method assigns already used tree index of some term to the not-yet - used atom name with the given lead/lag. In this way, all occurrences of - term t are substituted with the atom name(ll). The method handles also - rewriting operation tree including derivatives of the term t. */ - void substitute_atom_for_term(const string &name, int ll, int t); - /* This performs a final job after the model is parsed. It creates the - PlannerBuilder object if the planner's FOC are needed, then it creates - ForwSubstBuilder handling multiple leads and finally it creates the - substitution object saving old atoms and performs the substitutions. */ - void final_job(); - }; - - /* This class constructs DynareModel from dynare++ model file. It parses - variable declarations, model equations, parameter assignments, initval - assignments, vcov matrix and order of approximation. */ - class DynareParser : public DynareModel - { - protected: - /* Static atoms for parameter assignments. */ - DynareStaticAtoms pa_atoms; - /* Assignments for the parameters. */ - ogp::AtomAssignings paramset; - /* Static atoms for initval assignments. */ - DynareStaticAtoms ia_atoms; - /* Assignments for the initval. */ - ogp::AtomAssignings initval; - /* Matrix parser for vcov. */ - ogp::MatrixParser vcov; - public: - /* This, in fact, creates DynareModel from the given string of the given - length corresponding to the Dynare++ model file. If the given ord is not - −1, then it overrides setting in the model file. */ - DynareParser(const string &str, int ord); - DynareParser(const DynareParser &dp); - std::unique_ptr<DynareModel> - clone() const override - { - return std::make_unique<DynareParser>(*this); - } - /* Adds a name of endogenous, exogenous or a parameter. This addss the name - to the parent class DynareModel and also registers the name to either - paramset, or initval. */ - void add_name(string name, int flag); - /* Sets position of the model section. Called from dynglob.yy. */ - void - set_model_pos(int off1, int off2) - { - model_beg = off1; - model_end = off2; - } - /* Sets position of the section setting parameters. Called from - dynglob.yy. */ - void - set_paramset_pos(int off1, int off2) - { - paramset_beg = off1; - paramset_end = off2; - } - /* Sets position of the initval section. Called from dynglob.yy. */ - void - set_initval_pos(int off1, int off2) - { - initval_beg = off1; - initval_end = off2; - } - /* Sets position of the vcov section. Called from dynglob.yy. */ - void - set_vcov_pos(int off1, int off2) - { - vcov_beg = off1; - vcov_end = off2; - } - /* Parser the given string as integer and set to as the order. */ - void - set_order_pos(int off1, int off2) - { - order_beg = off1; - order_end = off2; - } - /* Sets position of the planner_objective section. Called from - dynglob.yy. */ - void - set_pl_objective_pos(int off1, int off2) - { - plobjective_beg = off1; - plobjective_end = off2; - } - /* Sets position of the planner_discount section. Called from - dynglob.yy. */ - void - set_pl_discount_pos(int off1, int off2) - { - pldiscount_beg = off1; - pldiscount_end = off2; - } - /* Processes a syntax error from bison. */ - void error(string mes); - /* Debug print. */ - void print() const; - protected: - void parse_glob(const string &stream); - int parse_order(const string &stream); - int parse_pldiscount(const string &stream); - /* Evaluate paramset assignings and set param_vals. */ - void calc_params(); - /* Evaluate initval assignings and set init_vals. */ - void calc_init(); - /* Do the final job. This includes building the planner problem (if any) - and substituting for multiple lags, and one period leads of exogenous - variables, and calculating initial guess of lagrange multipliers in the - social planner problem. Precondtion: everything parsed and calculated - parameters, postcondition: calculated initvals vector and - parsing_finished for expanded vectors. */ - void final_job(); - private: - int model_beg, model_end; - int paramset_beg, paramset_end; - int initval_beg, initval_end; - int vcov_beg, vcov_end; - int order_beg, order_end; - int plobjective_beg, plobjective_end; - int pldiscount_beg, pldiscount_end; - }; - - /* Semiparsed model. The equations are given by a string, everything other by - C++ objects. The initial values are set manually after the creation of - this object. This implies that no automatic substitutions cannot be done - here, which in turn implies that we cannot do here a social planner nor - substitutions of multiple lags. */ - class DynareSPModel : public DynareModel - { - public: - DynareSPModel(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const string &equations, int ord); - DynareSPModel(const DynareSPModel &dm) = default; - ~DynareSPModel() override = default; - std::unique_ptr<DynareModel> - clone() const override - { - return std::make_unique<DynareSPModel>(*this); - } - }; - - /* This class implements a selector of operations which correspond to - non-linear functions. This inherits from ogp::opselector and is used to - calculate non-linear subterms in DynareModel::get_nonlinear_subterms(). */ - class NLSelector : public ogp::opselector - { - private: - const DynareModel &model; - public: - NLSelector(const DynareModel &m) : model(m) - { - } - bool operator()(int t) const override; - }; - - /* This class writes a mathematical code evaluating the system of equations - and the first derivatives at zero shocks and at the given (static) state. - Static means that lags and leads are ignored. */ - class ModelSSWriter : public ogp::DefaultOperationFormatter - { - protected: - const DynareModel &model; - public: - ModelSSWriter(const DynareModel &m) - : DefaultOperationFormatter(m.eqs.getTree()), - model(m) - { - } - /* This writes the evaluation of the system. It calls pure virtual methods - for writing a preamble, then assignment of atoms, and then assignment - for resulting object. These are language dependent and are implemented - in the subclass. */ - void write_der0(std::ostream &os); - /* This writes the evaluation of the first order derivative of the system. - It calls pure virtual methods for writing a preamble, assignment, and - assignemnt of the resulting objects. */ - void write_der1(std::ostream &os); - protected: - virtual void write_der0_preamble(std::ostream &os) const = 0; - virtual void write_der1_preamble(std::ostream &os) const = 0; - virtual void write_atom_assignment(std::ostream &os) const = 0; - virtual void write_der0_assignment(std::ostream &os) const = 0; - virtual void write_der1_assignment(std::ostream &os) const = 0; - }; - - class MatlabSSWriter : public ModelSSWriter - { - protected: - /* Identifier used in function names. */ - std::string id; - public: - MatlabSSWriter(const DynareModel &dm, std::string id_arg); - protected: - // from ModelSSWriter - void write_der0_preamble(std::ostream &os) const override; - void write_der1_preamble(std::ostream &os) const override; - /* This writes atom assignments. We have four kinds of atoms set here: - endogenous vars coming from one parameter, parameter values given by the - second parameter, constants, and the OperationTree::num_constants - hardwired constants in ogp::OperationTree. */ - void write_atom_assignment(std::ostream &os) const override; - void write_der0_assignment(std::ostream &os) const override; - void write_der1_assignment(std::ostream &os) const override; - /* This prints t10 for t=10. */ - void format_term(int t, std::ostream &os) const override; - /* This prints a10 for t=10. The atoms a10 are supposed to be set by - write_atom_assignments(). */ - void format_nulary(int t, std::ostream &os) const override; - private: - void write_common1_preamble(std::ostream &os) const; - void write_common2_preamble(std::ostream &os) const; - }; - - /* This class implements OperationFormatter for debugging purposes. It - renders atoms in a more friendly way than the - ogp::DefaulOperationFormatter. */ - class DebugOperationFormatter : public ogp::DefaultOperationFormatter - { - protected: - const DynareModel &model; - public: - DebugOperationFormatter(const DynareModel &m) - : DefaultOperationFormatter(m.getParser().getTree()), - model(m) - { - } - void format_nulary(int t, std::ostream &os) const override; - }; -}; - -#endif diff --git a/dynare++/src/dynare_params.cc b/dynare++/src/dynare_params.cc deleted file mode 100644 index 3679ecf381404ec6e513389790c44ca50726971d..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_params.cc +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "dynare_params.hh" - -#include "sthread.hh" - -#include <getopt.h> -#include <string> -#include <iostream> - -DynareParams::DynareParams(int argc, char **argv) - : num_per(100), num_burn(0), num_sim(80), - num_rtper(0), num_rtsim(0), - num_condper(0), num_condsim(0), - num_threads(sthread::default_threads_number()), num_steps(0), - prefix("dyn"), seed(934098), order(-1), ss_tol(1.e-13), - check_along_path(false), check_along_shocks(false), - check_on_ellipse(false), check_evals(1000), check_num(10), check_scale(2.0), - do_irfs_all(true), do_centralize(true), qz_criterium(1.0+1e-6), - help(false), version(false) -{ - using namespace std::string_literals; - if (argc == 1 || argv[1] == "--help"s) - { - help = true; - return; - } - if (argc == 1 || argv[1] == "--version"s) - { - version = true; - return; - } - - modname = argv[argc-1]; - argc--; - - struct option const opts[] = - { - {"periods", required_argument, nullptr, static_cast<int>(opt::per)}, - {"per", required_argument, nullptr, static_cast<int>(opt::per)}, - {"burn", required_argument, nullptr, static_cast<int>(opt::burn)}, - {"simulations", required_argument, nullptr, static_cast<int>(opt::sim)}, - {"sim", required_argument, nullptr, static_cast<int>(opt::sim)}, - {"rtperiods", required_argument, nullptr, static_cast<int>(opt::rtper)}, - {"rtper", required_argument, nullptr, static_cast<int>(opt::rtper)}, - {"rtsimulations", required_argument, nullptr, static_cast<int>(opt::rtsim)}, - {"rtsim", required_argument, nullptr, static_cast<int>(opt::rtsim)}, - {"condperiods", required_argument, nullptr, static_cast<int>(opt::condper)}, - {"condper", required_argument, nullptr, static_cast<int>(opt::condper)}, - {"condsimulations", required_argument, nullptr, static_cast<int>(opt::condsim)}, - {"condsim", required_argument, nullptr, static_cast<int>(opt::condsim)}, - {"prefix", required_argument, nullptr, static_cast<int>(opt::prefix)}, - {"threads", required_argument, nullptr, static_cast<int>(opt::threads)}, - {"steps", required_argument, nullptr, static_cast<int>(opt::steps)}, - {"seed", required_argument, nullptr, static_cast<int>(opt::seed)}, - {"order", required_argument, nullptr, static_cast<int>(opt::order)}, - {"ss-tol", required_argument, nullptr, static_cast<int>(opt::ss_tol)}, - {"check", required_argument, nullptr, static_cast<int>(opt::check)}, - {"check-scale", required_argument, nullptr, static_cast<int>(opt::check_scale)}, - {"check-evals", required_argument, nullptr, static_cast<int>(opt::check_evals)}, - {"check-num", required_argument, nullptr, static_cast<int>(opt::check_num)}, - {"qz-criterium", required_argument, nullptr, static_cast<int>(opt::qz_criterium)}, - {"no-irfs", no_argument, nullptr, static_cast<int>(opt::noirfs)}, - {"irfs", no_argument, nullptr, static_cast<int>(opt::irfs)}, - {"centralize", no_argument, nullptr, static_cast<int>(opt::centralize)}, - {"no-centralize", no_argument, nullptr, static_cast<int>(opt::no_centralize)}, - {"help", no_argument, nullptr, static_cast<int>(opt::help)}, - {"version", no_argument, nullptr, static_cast<int>(opt::version)}, - {nullptr, 0, nullptr, 0} - }; - - int ret; - int index; - while (-1 != (ret = getopt_long(argc, argv, "", opts, &index))) - { - if (ret == '?') - { - std::cerr << "Unknown option, ignored\n"; - continue; - } - - try - { - switch (static_cast<opt>(ret)) - { - case opt::per: - num_per = std::stoi(optarg); - break; - case opt::burn: - num_burn = std::stoi(optarg); - break; - case opt::sim: - num_sim = std::stoi(optarg); - break; - case opt::rtper: - num_rtper = std::stoi(optarg); - break; - case opt::rtsim: - num_rtsim = std::stoi(optarg); - break; - case opt::condper: - num_condper = std::stoi(optarg); - break; - case opt::condsim: - num_condsim = std::stoi(optarg); - break; - case opt::prefix: - prefix = optarg; - break; - case opt::threads: - num_threads = std::stoi(optarg); - break; - case opt::steps: - num_steps = std::stoi(optarg); - break; - case opt::seed: - seed = std::stoi(optarg); - break; - case opt::order: - order = std::stoi(optarg); - break; - case opt::ss_tol: - ss_tol = std::stod(optarg); - break; - case opt::check: - processCheckFlags(optarg); - break; - case opt::check_scale: - check_scale = std::stod(optarg); - break; - case opt::check_evals: - check_evals = std::stoi(optarg); - break; - case opt::check_num: - check_num = std::stoi(optarg); - break; - case opt::noirfs: - irf_list.clear(); - do_irfs_all = false; - break; - case opt::irfs: - processIRFList(argc, argv); - if (irf_list.empty()) - do_irfs_all = true; - else - do_irfs_all = false; - break; - case opt::centralize: - do_centralize = true; - break; - case opt::no_centralize: - do_centralize = false; - break; - case opt::qz_criterium: - qz_criterium = std::stod(optarg); - break; - case opt::help: - help = true; - break; - case opt::version: - version = true; - break; - } - } - catch (std::invalid_argument &) - { - std::cerr << "Couldn't parse option " << optarg << ", ignored\n"; - } - catch (std::out_of_range &) - { - std::cerr << "Out-of-range value " << optarg << ", ignored\n"; - } - } - - // make basename (get rid of the directory and the extension) - basename = modname; - auto pos = basename.find_last_of(R"(/\)"); - if (pos != std::string::npos) - basename = basename.substr(pos+1); - pos = basename.find_last_of('.'); - if (pos != std::string::npos) - basename.erase(pos); -} - -void -DynareParams::printHelp() const -{ - std::cout << "usage: dynare++ [--help] [--version] [options] <model file>\n" - "\n" - " --help print this message and return\n" - " --version print version and return\n" - "\n" - "options:\n" - " --per <num> number of periods simulated after burnt [100]\n" - " --burn <num> number of periods burnt [0]\n" - " --sim <num> number of simulations [80]\n" - " --rtper <num> number of RT periods simulated after burnt [0]\n" - " --rtsim <num> number of RT simulations [0]\n" - " --condper <num> number of periods in cond. simulations [0]\n" - " --condsim <num> number of conditional simulations [0]\n" - " --steps <num> steps towards stoch. SS [0=deter.]\n" - " --centralize centralize the rule [do centralize]\n" - " --no-centralize do not centralize the rule [do centralize]\n" - " --prefix <string> prefix of variables in Mat-4 file [\"dyn\"]\n" - " --seed <num> random number generator seed [934098]\n" - " --order <num> order of approximation [no default]\n" - " --threads <num> number of max parallel threads [1/2 * nb. of logical CPUs]\n" - " --ss-tol <num> steady state calcs tolerance [1.e-13]\n" - " --check pesPES check model residuals [no checks]\n" - " lower/upper case switches off/on\n" - " pP checking along simulation path\n" - " eE checking on ellipse\n" - " sS checking along shocks\n" - " --check-evals <num> max number of evals per residual [1000]\n" - " --check-num <num> number of checked points [10]\n" - " --check-scale <num> scaling of checked points [2.0]\n" - " --no-irfs shuts down IRF simulations [do IRFs]\n" - " --irfs performs IRF simulations [do IRFs]\n" - " --qz-criterium <num> threshold for stable eigenvalues [1.000001]\n" - "\n\n"; -} - -void -DynareParams::processCheckFlags(const std::string &flags) -{ - for (char c : flags) - switch (c) - { - case 'p': - check_along_path = false; - break; - case 'P': - check_along_path = true; - break; - case 'e': - check_on_ellipse = false; - break; - case 'E': - check_on_ellipse = true; - break; - case 's': - check_along_shocks = false; - break; - case 'S': - check_along_shocks = true; - break; - default: - std::cerr << "Unknown check type selection character <" << c << ">, ignored.\n"; - } -} - -void -DynareParams::processIRFList(int argc, char **argv) -{ - irf_list.clear(); - while (optind < argc && *(argv[optind]) != '-') - { - irf_list.push_back(argv[optind]); - optind++; - } -} diff --git a/dynare++/src/dynare_params.hh b/dynare++/src/dynare_params.hh deleted file mode 100644 index 91363356ec5c5eb7eda786b230f813ae3074c8b0..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_params.hh +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2004 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -/* - along shocks: m mult max_evals - ellipse: m mult max_evals (10·m) (0.5·mult) - simul: m max_evals (10·m) - - --check-scale 2.0 --check-evals 1000 --check-num 10 --check PES -*/ - -#include <vector> -#include <string> - -struct DynareParams -{ - std::string modname; - std::string basename; - int num_per; - int num_burn; - int num_sim; - int num_rtper; - int num_rtsim; - int num_condper; - int num_condsim; - int num_threads; - int num_steps; - std::string prefix; - int seed; - int order; - /* Tolerance used for steady state calcs. */ - double ss_tol; - bool check_along_path; - bool check_along_shocks; - bool check_on_ellipse; - int check_evals; - int check_num; - double check_scale; - /* Flag for doing IRFs even if the irf_list is empty. */ - bool do_irfs_all; - /* List of shocks for which IRF will be calculated. */ - std::vector<std::string> irf_list; - bool do_centralize; - double qz_criterium; - bool help; - bool version; - DynareParams(int argc, char **argv); - void printHelp() const; - int - getCheckShockPoints() const - { - return check_num; - } - double - getCheckShockScale() const - { - return check_scale; - } - int - getCheckEllipsePoints() const - { - return 10*check_num; - } - double - getCheckEllipseScale() const - { - return 0.5*check_scale; - } - int - getCheckPathPoints() const - { - return 10*check_num; - } -private: - enum class opt { per, burn, sim, rtper, rtsim, condper, condsim, - prefix, threads, - steps, seed, order, ss_tol, check, - check_evals, check_scale, check_num, noirfs, irfs, - help, version, centralize, no_centralize, qz_criterium }; - void processCheckFlags(const std::string &flags); - /* This gathers strings from argv[optind] and on not starting with '-' to the - irf_list. It stops one item before the end, since this is the model - file. */ - void processIRFList(int argc, char **argv); -}; diff --git a/dynare++/src/dynglob.ll b/dynare++/src/dynglob.ll deleted file mode 100644 index cbb0341b9f56ebb82c2e1b3b051961908551e0ea..0000000000000000000000000000000000000000 --- a/dynare++/src/dynglob.ll +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ -%{ -#include "parser/cc/location.hh" -#include "dynglob_tab.hh" - -#define YY_USER_ACTION SET_LLOC(dynglob_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="dynglob_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* initial spaces or tabs are ignored */ - -[ \t\r\n\0] -var {return VAR;} -varexo {return VAREXO;} -parameters {return PARAMETERS;} -model {return MODEL;} -end {return END;} -initval {return INITVAL;} -order {return ORDER;} -vcov {return VCOV;} -planner_objective {return PLANNEROBJECTIVE;} -planner_discount {return PLANNERDISCOUNT;} - - /* names */ -[A-Za-z_][A-Za-z0-9_]* { - dynglob_lval.string = dynglob_text; - return NAME; -} - -; {return SEMICOLON;} -, {return COMMA;} -= {return EQUAL_SIGN;} -\[ {return LEFT_BRACKET;} -\] {return RIGHT_BRACKET;} -. { - dynglob_lval.character = dynglob_text[0]; - return CHARACTER; -} - -%% - -int -dynglob_wrap() -{ - return 1; -} - -void -dynglob__destroy_buffer(void* p) -{ - dynglob__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/src/dynglob.yy b/dynare++/src/dynglob.yy deleted file mode 100644 index dac74dc8c980af795ec3d7805109b545300a6acb..0000000000000000000000000000000000000000 --- a/dynare++/src/dynglob.yy +++ /dev/null @@ -1,135 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -%code requires -{ -#include "parser/cc/location.hh" -#define DYNGLOB_LTYPE ogp::location_type -} - -%code -{ -#include <string> - -#include "dynare_model.hh" - -void dynglob_error(std::string); -int dynglob_lex(); -extern ogdyn::DynareParser* dynare_parser; -int symblist_flag; -} - -%union -{ - int integer; - char *string; - char character; -} - -%token END INITVAL MODEL PARAMETERS VAR VAREXO SEMICOLON COMMA EQUAL_SIGN CHARACTER -%token VCOV LEFT_BRACKET RIGHT_BRACKET ORDER PLANNEROBJECTIVE PLANNERDISCOUNT -%token <string> NAME; - -%define api.prefix {dynglob_} - -%locations -%defines -%define parse.error verbose - -%% - -dynare_file : preamble paramset model rest { - dynare_parser->set_paramset_pos(@2.off, @3.off);} - | preamble model rest { - dynare_parser->set_paramset_pos(0, 0);} - | preamble paramset planner model rest { - dynare_parser->set_paramset_pos(@2.off, @3.off);} - ; - -preamble : preamble preamble_statement | preamble_statement; - -preamble_statement : var | varexo | parameters; - -var : VAR {symblist_flag=1;} symblist SEMICOLON; - -varexo : VAREXO {symblist_flag=2;} symblist SEMICOLON; - -parameters : PARAMETERS {symblist_flag=3;} symblist SEMICOLON; - - -symblist : symblist NAME {dynare_parser->add_name($2,symblist_flag);} - | symblist COMMA NAME {dynare_parser->add_name($3,symblist_flag);} - | NAME {dynare_parser->add_name($1,symblist_flag);} - ; - -paramset : recnameset; - -recnameset : recnameset onenameset | onenameset; - -onenameset : NAME EQUAL_SIGN material SEMICOLON; - -material : material CHARACTER | material NAME | NAME | CHARACTER; - -model : MODEL SEMICOLON equations END SEMICOLON { - dynare_parser->set_model_pos(@3.off, @4.off); -}; - -equations : equations equation | equation; - -equation : material EQUAL_SIGN material SEMICOLON | material SEMICOLON; - -rest : rest_statement | rest rest_statement; - -rest_statement : initval | vcov | order | planner; - -initval : INITVAL SEMICOLON recnameset END SEMICOLON { - dynare_parser->set_initval_pos(@3.off, @4.off); -}; - -vcov : VCOV EQUAL_SIGN LEFT_BRACKET m_material RIGHT_BRACKET SEMICOLON { - dynare_parser->set_vcov_pos(@4.off, @5.off); -}; - -m_material : m_material CHARACTER | m_material NAME | m_material SEMICOLON | m_material COMMA | CHARACTER | NAME | SEMICOLON | COMMA; - -order : ORDER EQUAL_SIGN material SEMICOLON { - dynare_parser->set_order_pos(@3.off, @4.off); -}; - -planner : planner_objective planner_discount - | planner_discount planner_objective -; - -planner_objective : PLANNEROBJECTIVE material SEMICOLON { - dynare_parser->set_pl_objective_pos(@2.off, @3.off); -}; - -planner_discount : PLANNERDISCOUNT NAME SEMICOLON { - dynare_parser->set_pl_discount_pos(@2.off, @3.off); -}; - -%% - -void -dynglob_error(std::string mes) -{ - dynare_parser->error(mes); -} diff --git a/dynare++/src/forw_subst_builder.cc b/dynare++/src/forw_subst_builder.cc deleted file mode 100644 index 08ebd8a1e921c155141747e347882ce17de27dff..0000000000000000000000000000000000000000 --- a/dynare++/src/forw_subst_builder.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "forw_subst_builder.hh" - -#include "dynare_model.hh" - -using namespace ogdyn; - -ForwSubstBuilder::ForwSubstBuilder(DynareModel &m) - : model(m) -{ - info.num_new_terms -= model.getParser().getTree().get_num_op(); - - // go through all equations - int neq = model.eqs.nformulas(); - for (int i = 0; i < neq; i++) - { - int ft = model.eqs.formula(i); - int mlead, mlag; - model.termspan(ft, mlead, mlag); - // if equation is too forward looking - if (mlead > 1) - { - info.num_affected_equations++; - // break it to non-linear terms - unordered_set<int> nlt = model.get_nonlinear_subterms(ft); - int j = 0; // indexes subterms - // and make substitutions for all these non-linear subterms - for (const auto &it : nlt) - substitute_for_term(it, i, j++); - } - } - // unassign all variables with lead greater than 1 - unassign_gt_1_leads(); - - /* Forget the derivatives in the tree because some variables could have been - unassigned */ - model.eqs.getTree().forget_derivative_maps(); - - info.num_new_terms += model.getParser().getTree().get_num_op(); -} - -void -ForwSubstBuilder::substitute_for_term(int t, int i, int j) -{ - int mlead, mlag; - model.termspan(t, mlead, mlag); - if (mlead > 1) - { - info.num_subst_terms++; - // Example for comments: let t = f(x(+4)) - // first make lagsubst be substitution setting f(x(+4)) to f(x(+1)) - // this is lag = -3 (1-mlead) - map<int, int> lagsubst; - unordered_set<int> nult = model.eqs.nulary_of_term(t); // make copy of nult! - model.variable_shift_map(nult, 1-mlead, lagsubst); - int lagt = model.eqs.add_substitution(t, lagsubst); - - // now maxlead of lagt is +1 - // add AUXLD_*_*_1 = f(x(+1)) to the model - std::string name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + "_1"; - model.atoms.register_uniq_endo(name); - info.num_aux_variables++; - int auxt = model.eqs.add_nulary(name); - model.eqs.add_formula(model.eqs.add_binary(ogp::code_t::MINUS, auxt, lagt)); - aux_map.emplace(name, lagt); - // now add variables and equations - // AUXLD_*_*_2 = AUXLD_*_*_1(+1) through - // AUXLD_*_*_{mlead-1} = AUXLD_*_*_{mlead-2}(+1) - for (int ll = 1; ll <= mlead-2; ll++) - { - // create AUXLD_*_*_{ll}(+1) - name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + '_' + std::to_string(ll) + "(+1)"; - int lastauxt_lead = model.eqs.add_nulary(name); - // create AUXLD_*_*{ll+1} - name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + '_' + std::to_string(ll+1); - model.atoms.register_uniq_endo(name); - info.num_aux_variables++; - auxt = model.eqs.add_nulary(name); - // add AUXLD_*_*_{ll+1} = AUXLD_*_*_{ll}(+1) - model.eqs.add_formula(model.eqs.add_binary(ogp::code_t::MINUS, auxt, lastauxt_lead)); - /* add substitution to the map; TODO: this works well because in the - context where aux_map is used the timing doesn't matter, however, - it is misleading, needs to be changed */ - aux_map.emplace(name, lagt); - } - - // now we have to substitute AUXLD_*_*{mlead-1}(+1) for t - name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + '_' + std::to_string(mlead-1); - model.substitute_atom_for_term(name, +1, t); - } -} - -void -ForwSubstBuilder::unassign_gt_1_leads(const string &name) -{ - int mlead, mlag; - model.atoms.varspan(name, mlead, mlag); - for (int ll = 2; ll <= mlead; ll++) - { - int t = model.atoms.index(name, ll); - if (t != -1) - model.atoms.unassign_variable(name, ll, t); - } -} - -void -ForwSubstBuilder::unassign_gt_1_leads() -{ - auto &endovars = model.atoms.get_endovars(); - for (const auto &endovar : endovars) - unassign_gt_1_leads(endovar); - auto &exovars = model.atoms.get_exovars(); - for (const auto &exovar : exovars) - unassign_gt_1_leads(exovar); -} - -ForwSubstBuilder::ForwSubstBuilder(const ForwSubstBuilder &b, DynareModel &m) - : model(m) -{ - for (auto it : b.aux_map) - aux_map.insert(it); -} diff --git a/dynare++/src/forw_subst_builder.hh b/dynare++/src/forw_subst_builder.hh deleted file mode 100644 index 7bf12f1e7673ba301f9fe4461150b00b308e8142..0000000000000000000000000000000000000000 --- a/dynare++/src/forw_subst_builder.hh +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef FORW_SUBST_BUILDER_H -#define FORW_SUBST_BUILDER_H - -#include <map> - -#include "dynare_atoms.hh" - -namespace ogdyn -{ - /* This struct encapsulates information about the process of forward - substitutions. */ - struct ForwSubstInfo - { - int num_affected_equations{0}; - int num_subst_terms{0}; - int num_aux_variables{0}; - int num_new_terms{0}; - }; - - class DynareModel; - - class ForwSubstBuilder - { - using Ttermauxmap = map<int, string>; - protected: - /* Reference to the model, to which we will add equations and change some - equations. */ - DynareModel &model; - /* A map mapping new auxiliary variables to the terms in the tree in the - DynareModel. */ - Tsubstmap aux_map; - /* Information about the substitutions. */ - ForwSubstInfo info; - public: - /* Do all the jobs needed. This scans all equations in the model, and for - equations containing forward looking variables greater than 1 lead, it - makes corresponding substitutions. Basically, it breaks each equation to - its non-linear components and creates substitutions for these - components, not for whole equation. This is because the expectation - operator can go through the linear part of the function. This will save - us many occurrences of other variables involved in the equation. */ - ForwSubstBuilder(DynareModel &m); - ForwSubstBuilder(const ForwSubstBuilder &b) = delete; - /* Copy constructor with a new instance of the model. */ - ForwSubstBuilder(const ForwSubstBuilder &b, DynareModel &m); - /* Return the auxiliary variable mapping. */ - const Tsubstmap & - get_aux_map() const - { - return aux_map; - } - /* Return the information. */ - const ForwSubstInfo & - get_info() const - { - return info; - } - private: - /* This method takes a nonlinear term t, and if it has leads of greater - than 1, then it substitutes the term for the new variable (or string of - variables). Note that the substitution is done by - DynamicAtoms::assign_variable. This means that the substitution is made - for all other ocurrences of t in the model. So there is no need of - tracking already substituted terms. The other two parameters are just - for identification of the new auxiliary variables. When called from the - constructor, i is an equation number, j is an order of the non-linear - term in the equation. */ - void substitute_for_term(int t, int i, int j); - /* This is called just at the end of the job. It unassigns all nulary terms - with a lead greater than 1. */ - void unassign_gt_1_leads(); - /* This unassigns all leads greater than 1 of the given name. */ - void unassign_gt_1_leads(const string &name); - }; -}; - -#endif diff --git a/dynare++/src/main.cc b/dynare++/src/main.cc deleted file mode 100644 index 3d46230ffa78652715358748e8d9d2cc9f2251b1..0000000000000000000000000000000000000000 --- a/dynare++/src/main.cc +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "dynare3.hh" -#include "dynare_exception.hh" -#include "dynare_params.hh" - -#include "utils/cc/exception.hh" -#include "parser/cc/parser_exception.hh" -#include "../sylv/cc/SylvException.hh" -#include "../kord/seed_generator.hh" -#include "../kord/global_check.hh" -#include "../kord/approximation.hh" - -#include <fstream> -#include <iostream> -#include <cstdlib> - -int -main(int argc, char **argv) -{ - DynareParams params(argc, argv); - if (params.help) - { - params.printHelp(); - return EXIT_SUCCESS; - } - if (params.version) - { - std::cout << "Dynare++ v. " << VERSION << '\n' - << '\n' - << "Copyright © 2004-2011 Ondra Kamenik\n" - << "Copyright © 2019-2020 Dynare Team\n" - << "Dynare++ comes with ABSOLUTELY NO WARRANTY and is distributed under the GNU GPL,\n" - << "version 3 or later (see https://www.gnu.org/licenses/gpl.html)\n"; - return EXIT_SUCCESS; - } - sthread::detach_thread_group::max_parallel_threads = params.num_threads; - - try - { - // make journal - Journal journal(params.basename + ".jnl"); - - // make dynare object - Dynare dynare(params.modname, params.order, params.ss_tol, journal); - // make list of shocks for which we will do IRFs - std::vector<int> irf_list_ind; - if (params.do_irfs_all) - for (int i = 0; i < dynare.nexog(); i++) - irf_list_ind.push_back(i); - else - irf_list_ind = static_cast<const DynareNameList &>(dynare.getExogNames()).selectIndices(params.irf_list); - - // write matlab files - std::string mfile1(params.basename + "_f.m"); - std::ofstream mfd{mfile1, std::ios::out | std::ios::trunc}; - if (mfd.fail()) - { - std::cerr << "Couldn't open " << mfile1 << " for writing.\n"; - std::exit(EXIT_FAILURE); - } - ogdyn::MatlabSSWriter writer0(dynare.getModel(), params.basename); - writer0.write_der0(mfd); - mfd.close(); - - std::string mfile2(params.basename + "_ff.m"); - mfd.open(mfile2, std::ios::out | std::ios::trunc); - if (mfd.fail()) - { - std::cerr << "Couldn't open " << mfile2 << " for writing.\n"; - std::exit(EXIT_FAILURE); - } - ogdyn::MatlabSSWriter writer1(dynare.getModel(), params.basename); - writer1.write_der1(mfd); - mfd.close(); - - // open mat file - std::string matfile(params.basename + ".mat"); - mat_t *matfd = Mat_Create(matfile.c_str(), nullptr); - if (!matfd) - { - std::cerr << "Couldn't open " << matfile << " for writing.\n"; - std::exit(EXIT_FAILURE); - } - - // write info about the model (dimensions and variables) - dynare.writeMat(matfd, params.prefix); - // write the dump file corresponding to the input - dynare.writeDump(params.basename); - - seed_generator::set_meta_seed(static_cast<std::mt19937::result_type>(params.seed)); - - TLStatic::init(dynare.order(), - dynare.nstat()+2*dynare.npred()+3*dynare.nboth() - +2*dynare.nforw()+dynare.nexog()); - - Approximation app(dynare, journal, params.num_steps, params.do_centralize, params.qz_criterium); - try - { - app.walkStochSteady(); - } - catch (const KordException &e) - { - // tell about the exception and continue - std::cout << "Caught (not yet fatal) Kord exception: "; - e.print(); - JournalRecord rec(journal); - rec << "Solution routine not finished (" << e.get_message() - << "), see what happens" << endrec; - } - - std::string ss_matrix_name(params.prefix + "_steady_states"); - ConstTwoDMatrix(app.getSS()).writeMat(matfd, ss_matrix_name); - - // check the approximation - if (params.check_along_path || params.check_along_shocks - || params.check_on_ellipse) - { - GlobalChecker gcheck(app, sthread::detach_thread_group::max_parallel_threads, journal); - if (params.check_along_shocks) - gcheck.checkAlongShocksAndSave(matfd, params.prefix, - params.getCheckShockPoints(), - params.getCheckShockScale(), - params.check_evals); - if (params.check_on_ellipse) - gcheck.checkOnEllipseAndSave(matfd, params.prefix, - params.getCheckEllipsePoints(), - params.getCheckEllipseScale(), - params.check_evals); - if (params.check_along_path) - gcheck.checkAlongSimulationAndSave(matfd, params.prefix, - params.getCheckPathPoints(), - params.check_evals); - } - - // write the folded decision rule to the Mat-4 file - app.getFoldDecisionRule().writeMat(matfd, params.prefix); - - // simulate conditional - if (params.num_condper > 0 && params.num_condsim > 0) - { - SimResultsDynamicStats rescond(dynare.numeq(), params.num_condper, 0); - Vector det_ss{app.getSS().getCol(0)}; - rescond.simulate(params.num_condsim, app.getFoldDecisionRule(), det_ss, dynare.getVcov(), journal); - rescond.writeMat(matfd, params.prefix); - } - - // simulate unconditional - //const DecisionRule& dr = app.getUnfoldDecisionRule(); - const DecisionRule &dr = app.getFoldDecisionRule(); - if (params.num_per > 0 && params.num_sim > 0) - { - SimResultsStats res(dynare.numeq(), params.num_per, params.num_burn); - res.simulate(params.num_sim, dr, dynare.getSteady(), dynare.getVcov(), journal); - res.writeMat(matfd, params.prefix); - - // impulse response functions - if (!irf_list_ind.empty()) - { - IRFResults irf(dynare, dr, res, irf_list_ind, journal); - irf.writeMat(matfd, params.prefix); - } - } - - // simulate with real-time statistics - if (params.num_rtper > 0 && params.num_rtsim > 0) - { - RTSimResultsStats rtres(dynare.numeq(), params.num_rtper, params.num_burn); - rtres.simulate(params.num_rtsim, dr, dynare.getSteady(), dynare.getVcov(), journal); - rtres.writeMat(matfd, params.prefix); - } - - Mat_Close(matfd); - } - catch (const KordException &e) - { - std::cout << "Caught Kord exception: "; - e.print(); - return e.code(); - } - catch (const TLException &e) - { - std::cout << "Caught TL exception: "; - e.print(); - return 255; - } - catch (SylvException &e) - { - std::cout << "Caught Sylv exception: "; - e.printMessage(); - return 255; - } - catch (const DynareException &e) - { - std::cout << "Caught Dynare exception: " << e.message() << '\n'; - return 255; - } - catch (const ogu::Exception &e) - { - std::cout << "Caught ogu::Exception: "; - e.print(); - return 255; - } - catch (const ogp::ParserException &e) - { - std::cout << "Caught parser exception: " << e.message() << '\n'; - return 255; - } - - return EXIT_SUCCESS; -} diff --git a/dynare++/src/nlsolve.cc b/dynare++/src/nlsolve.cc deleted file mode 100644 index 3286652c352a4f0bf90a019cb24529b57314762f..0000000000000000000000000000000000000000 --- a/dynare++/src/nlsolve.cc +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-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/>. - */ - -#include "nlsolve.hh" -#include "dynare_exception.hh" - -#include <sstream> -#include <iomanip> - -using namespace ogu; - -double GoldenSectionSearch::golden = (3.-std::sqrt(5.))/2; - -double -GoldenSectionSearch::search(OneDFunction &f, double x1, double x2) -{ - double b; - if (init_bracket(f, x1, x2, b)) - { - double fb = f.eval(b); - double f1 = f.eval(x1); - f.eval(x2); - double dx; - do - { - double w = (b-x1)/(x2-x1); - dx = std::abs((1-2*w)*(x2-x1)); - double x; - if (b-x1 > x2-b) - x = b - dx; - else - x = b + dx; - double fx = f.eval(x); - if (!std::isfinite(fx)) - return x1; - if (b-x1 > x2-b) - { - // x is on the left from b - if (f1 > fx && fx < fb) - { - // pickup bracket [f1,fx,fb] - x2 = b; - fb = fx; - b = x; - } - else - { - // pickup bracket [fx,fb,fx2] - f1 = fx; - x1 = x; - } - } - else - { - // x is on the right from b - if (f1 > fb && fb < fx) - // pickup bracket [f1,fb,fx] - x2 = x; - else - { - // pickup bracket [fb,fx,f2] - f1 = fb; - x1 = b; - fb = fx; - b = x; - } - } - } - while (dx > tol); - } - return b; -} - -bool -GoldenSectionSearch::init_bracket(OneDFunction &f, double x1, double &x2, double &b) -{ - double f1 = f.eval(x1); - if (!std::isfinite(f1)) - throw DynareException(__FILE__, __LINE__, - "Safer point not finite in GoldenSectionSearch::init_bracket"); - - int cnt = 0; - bool bracket_found = false; - do - { - bool finite_found = search_for_finite(f, x1, x2, b); - if (!finite_found) - { - b = x1; - return false; - } - double f2 = f.eval(x2); - double fb = f.eval(b); - double bsym = 2*x2 - b; - double fbsym = f.eval(bsym); - // now we know that f1, f2, and fb are finite - if (std::isfinite(fbsym)) - { - /* we have four numbers f1, fb, f2, fbsym, we test for the following - combinations to find the bracket: [f1,f2,fbsym], [f1,fb,fbsym] and - [f1,fb,fbsym] */ - if (f1 > f2 && f2 < fbsym) - { - bracket_found = true; - b = x2; - x2 = bsym; - } - else if (f1 > fb && fb < fbsym) - { - bracket_found = true; - x2 = bsym; - } - else if (f1 > fb && fb < f2) - bracket_found = true; - else - { - double newx2 = b; - // choose the smallest value in case we end - if (f1 > fbsym) - { - /* the smallest value is on the other end, we do not want to - continue */ - b = bsym; - return false; - } - else - b = x1; - // move x2 to b in case we continue - x2 = newx2; - } - } - else - { - /* we have only three numbers, we test for the bracket, and if not - found, we set b as potential result and shorten x2 as potential - init value for next cycle */ - if (f1 > fb && fb < f2) - bracket_found = true; - else - { - double newx2 = b; - // choose the smaller value in case we end - if (f1 > f2) - b = x2; - else - b = x1; - // move x2 to b in case we continue - x2 = newx2; - } - } - cnt++; - } - while (!bracket_found && cnt < 5); - - return bracket_found; -} - -/* This moves x2 toward to x1 until the function at x2 is finite and b as a - golden section between x1 and x2 yields also finite f. */ -bool -GoldenSectionSearch::search_for_finite(OneDFunction &f, double x1, double &x2, double &b) -{ - int cnt = 0; - bool found = false; - do - { - double f2 = f.eval(x2); - b = (1-golden)*x1 + golden*x2; - double fb = f.eval(b); - found = std::isfinite(f2) && std::isfinite(fb); - if (!found) - x2 = b; - cnt++; - } - while (!found && cnt < 5); - - return found; -} - -void -VectorFunction::check_for_eval(const ConstVector &in, Vector &out) const -{ - if (inDim() != in.length() || outDim() != out.length()) - throw DynareException(__FILE__, __LINE__, - "Wrong dimensions in VectorFunction::check_for_eval"); -} - -double -NLSolver::eval(double lambda) -{ - Vector xx(const_cast<const Vector &>(x)); - xx.add(1-lambda, xcauchy); - xx.add(lambda, xnewton); - Vector ff(func.outDim()); - func.eval(xx, ff); - return ff.dot(ff); -} - -bool -NLSolver::solve(Vector &xx, int &iter) -{ - JournalRecord rec(journal); - rec << "Iter lambda residual" << endrec; - JournalRecord rec1(journal); - rec1 << "───────────────────────────" << endrec; - - x = const_cast<const Vector &>(xx); - iter = 0; - // setup fx - Vector fx(func.outDim()); - func.eval(x, fx); - if (!fx.isFinite()) - throw DynareException(__FILE__, __LINE__, - "Initial guess does not yield finite residual in NLSolver::solve"); - bool converged = fx.getMax() < tol; - JournalRecord rec2(journal); - auto format_double = [](double v) - { - std::ostringstream buf; - buf << std::setw(11) << v; - return buf.str(); - }; - rec2 << iter << " N/A " << format_double(fx.getMax()) << endrec; - while (!converged && iter < max_iter) - { - // setup Jacobian - jacob.eval(x); - // calculate cauchy step - Vector g(func.inDim()); - g.zeros(); - ConstTwoDMatrix(jacob).multaVecTrans(g, fx); - Vector Jg(func.inDim()); - Jg.zeros(); - ConstTwoDMatrix(jacob).multaVec(Jg, g); - double m = -g.dot(g)/Jg.dot(Jg); - xcauchy = const_cast<const Vector &>(g); - xcauchy.mult(m); - // calculate newton step - xnewton = const_cast<const Vector &>(fx); - ConstTwoDMatrix(jacob).multInvLeft(xnewton); - xnewton.mult(-1); - - // line search - double lambda = GoldenSectionSearch::search(*this, 0, 1); - x.add(1-lambda, xcauchy); - x.add(lambda, xnewton); - // evaluate func - func.eval(x, fx); - converged = fx.getMax() < tol; - - // iter - iter++; - - JournalRecord rec3(journal); - rec3 << iter << " " << lambda << " " << format_double(fx.getMax()) << endrec; - } - xx = const_cast<const Vector &>(x); - - return converged; -} diff --git a/dynare++/src/nlsolve.hh b/dynare++/src/nlsolve.hh deleted file mode 100644 index b1e1bc21f9205ca4cebd5eb3ef4b10080b00ab9b..0000000000000000000000000000000000000000 --- a/dynare++/src/nlsolve.hh +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef OGU_NLSOLVE_H -#define OGU_NLSOLVE_H - -#include "twod_matrix.hh" -#include "journal.hh" - -#include <cmath> - -namespace ogu -{ - class OneDFunction - { - public: - virtual ~OneDFunction() = default; - virtual double eval(double) = 0; - }; - - class GoldenSectionSearch - { - protected: - constexpr static double tol = 1.e-4; - /* This is equal to the golden section ratio. */ - static double golden; - public: - static double search(OneDFunction &f, double x1, double x2); - protected: - /* This initializes a bracket by moving x2 and b (as a golden section of - x1,x2) so that f(x1)>f(b) && f(b)<f(x2). The point x1 is not moved, - since it is considered as reliable and f(x1) is supposed to be finite. - If initialization of a bracket succeeded, then [x1,b,x2] is the bracket - and true is returned. Otherwise, b is the minimum found and false is - returned. */ - static bool init_bracket(OneDFunction &f, double x1, double &x2, double &b); - /* This supposes that f(x1) is finite and it moves x2 toward x1 until x2 - and b (as a golden section of x1,x2) are finite. If succeeded, the - routine returns true and x2, and b. Otherwise, it returns false. */ - static bool search_for_finite(OneDFunction &f, double x1, double &x2, double &b); - }; - - class VectorFunction - { - public: - VectorFunction() = default; - virtual ~VectorFunction() = default; - virtual int inDim() const = 0; - virtual int outDim() const = 0; - /* Check dimensions of eval parameters. */ - void check_for_eval(const ConstVector &in, Vector &out) const; - /* Evaluate the vector function. */ - virtual void eval(const ConstVector &in, Vector &out) = 0; - }; - - class Jacobian : public TwoDMatrix - { - public: - Jacobian(int n) : TwoDMatrix(n, n) - { - } - ~Jacobian() override = default; - virtual void eval(const Vector &in) = 0; - }; - - class NLSolver : public OneDFunction - { - protected: - Journal &journal; - VectorFunction &func; - Jacobian &jacob; - const int max_iter; - const double tol; - private: - Vector xnewton; - Vector xcauchy; - Vector x; - public: - NLSolver(VectorFunction &f, Jacobian &j, int maxit, double tl, Journal &jr) - : journal(jr), func(f), jacob(j), max_iter(maxit), tol(tl), - xnewton(f.inDim()), xcauchy(f.inDim()), x(f.inDim()) - { - xnewton.zeros(); xcauchy.zeros(); x.zeros(); - } - ~NLSolver() override = default; - /* Returns true if the problem has converged. xx as input is the starting - value, as output it is a solution. */ - bool solve(Vector &xx, int &iter); - /* To implement OneDFunction interface. It returns func(xx)ᵀ·func(xx), - where xx=x+lambda·xcauchy+(1−lambda)·xnewton. It is non-const only - because it calls func, x, xnewton, xcauchy is not changed. */ - double eval(double lambda) override; - }; -}; - -#endif diff --git a/dynare++/src/planner_builder.cc b/dynare++/src/planner_builder.cc deleted file mode 100644 index 41bb6f91da2ae31a8c6d9da1c3316181415820a7..0000000000000000000000000000000000000000 --- a/dynare++/src/planner_builder.cc +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#include "planner_builder.hh" -#include "dynare_exception.hh" -#include "dynare_model.hh" - -#include <cmath> -#include <utility> - -using namespace ogdyn; - -const IntegerMatrix & -IntegerMatrix::operator=(const IntegerMatrix &im) -{ - if (nr != im.nr || nc != im.nc) - throw DynareException(__FILE__, __LINE__, - "Matrices have different dimensions in IntegerMatrix::operator="); - std::copy_n(im.data.get(), nr*nc, data.get()); - return *this; -} - -const IntegerArray3 & -IntegerArray3::operator=(const IntegerArray3 &ia3) -{ - if (n1 != ia3.n1 || n2 != ia3.n2 || n3 != ia3.n3) - throw DynareException(__FILE__, __LINE__, - "Arrays have different dimensions in IntegerArray3::operator="); - std::copy_n(ia3.data.get(), n1*n2*n3, data.get()); - return *this; -} - -PlannerBuilder::PlannerBuilder(DynareModel &m, const Tvarset &yyset, - Teqset ffset) - : yset(), fset(std::move(ffset)), model(m), - tb(model.t_plobjective), tbeta(model.t_pldiscount), - maxlead(model.atoms.get_maxlead()), - minlag(model.atoms.get_minlag()), - diff_b(yyset.size(), 1-minlag), - diff_f(yyset.size(), fset.size(), 1+maxlead-minlag), - static_atoms(), - static_tree(), - diff_b_static(yyset.size(), 1-minlag), - diff_f_static(yyset.size(), fset.size(), 1+maxlead-minlag) -{ - info.num_new_terms -= model.getParser().getTree().get_num_op(); - - fill_yset(m.atoms.get_name_storage(), yyset); - - add_derivatives_of_b(); - add_derivatives_of_f(); - shift_derivatives_of_b(); - shift_derivatives_of_f(); - beta_multiply_b(); - beta_multiply_f(); - make_static_version(); - lagrange_mult_f(); - form_equations(); - - info.num_new_terms += model.getParser().getTree().get_num_op(); -} - -PlannerBuilder::PlannerBuilder(const PlannerBuilder &pb, ogdyn::DynareModel &m) - : yset(), fset(pb.fset), model(m), - tb(pb.tb), tbeta(pb.tbeta), - maxlead(pb.maxlead), minlag(pb.minlag), - diff_b(pb.diff_b), diff_f(pb.diff_f), - static_atoms(pb.static_atoms), - static_tree(pb.static_tree), - diff_b_static(pb.diff_b_static), - diff_f_static(pb.diff_f_static), - aux_map(), static_aux_map() -{ - fill_yset(m.atoms.get_name_storage(), pb.yset); - fill_aux_map(m.atoms.get_name_storage(), pb.aux_map, pb.static_aux_map); -} - -void -PlannerBuilder::add_derivatives_of_b() -{ - int yi = 0; - for (auto yname = yset.begin(); yname != yset.end(); ++yname, yi++) - for (int ll = minlag; ll <= 0; ll++) - { - int yt = model.atoms.index(*yname, ll); - if (yt != -1) - diff_b(yi, ll-minlag) = model.eqs.add_derivative(tb, yt); - else - diff_b(yi, ll-minlag) = ogp::OperationTree::zero; - } -} - -void -PlannerBuilder::add_derivatives_of_f() -{ - int yi = 0; - for (auto yname = yset.begin(); yname != yset.end(); ++yname, yi++) - for (unsigned int fi = 0; fi < fset.size(); fi++) - for (int ll = minlag; ll <= maxlead; ll++) - { - int yt = model.atoms.index(*yname, ll); - if (yt != -1) - diff_f(yi, fi, ll-minlag) - = model.eqs.add_derivative(model.eqs.formula(fset[fi]), yt); - else - diff_f(yi, fi, ll-minlag) = ogp::OperationTree::zero; - } -} - -void -PlannerBuilder::shift_derivatives_of_b() -{ - map<int, int> subst; - for (int yi = 0; yi < diff_b.nrows(); yi++) - for (int ll = minlag; ll < 0; ll++) - if (diff_b(yi, ll-minlag) != ogp::OperationTree::zero) - { - model.variable_shift_map(model.eqs.nulary_of_term(diff_b(yi, ll-minlag)), - -ll, subst); - diff_b(yi, ll-minlag) = model.eqs.add_substitution(diff_b(yi, ll-minlag), subst); - } -} - -void -PlannerBuilder::shift_derivatives_of_f() -{ - map<int, int> subst; - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - { - // first do it leads which are put under expectation before t: no problem - for (int ll = 0; ll <= maxlead; ll++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - { - model.variable_shift_map(model.eqs.nulary_of_term(diff_f(yi, fi, ll-minlag)), - -ll, subst); - diff_f(yi, fi, ll-minlag) - = model.eqs.add_substitution(diff_f(yi, fi, ll-minlag), subst); - } - /* now do it for lags, these are put as leads under expectations after - time t, so we have to introduce auxiliary variables at time t, and - make leads of them here */ - for (int ll = minlag; ll < 0; ll++) - { - int ft = diff_f(yi, fi, ll-minlag); - if (ft != ogp::OperationTree::zero) - { - /* if the ft term has a lead, than we need to introduce an - auxiliary variable zₜ, define it as 𝔼ₜ[ft] and put z_{t-ll} - to the equation. Otherwise, we just put leaded ft to the - equation directly. */ - int ft_maxlead, ft_minlag; - model.termspan(ft, ft_maxlead, ft_minlag); - if (ft_maxlead > 0) - { - // make an auxiliary variable - std::string name; - name = "AUX_" + std::to_string(yi) + '_' + std::to_string(fset[fi]) + '_' + std::to_string(-ll); - model.atoms.register_uniq_endo(name); - info.num_aux_variables++; - int taux = model.eqs.add_nulary(name); - name = "AUX_" + std::to_string(yi) + '_' + std::to_string(fset[fi]) + '_' + std::to_string(-ll) + '(' + std::to_string(-ll) + ')'; - int taux_leaded = model.eqs.add_nulary(name); - // put aux_leaded to the equation - diff_f(yi, fi, ll-minlag) = taux_leaded; - // save auxiliary variable and the term - aux_map.emplace(model.atoms.name(taux), ft); - } - else - { - /* no auxiliary variable is needed and the term ft can be - leaded in place */ - model.variable_shift_map(model.eqs.nulary_of_term(ft), -ll, subst); - diff_f(yi, fi, ll-minlag) = model.eqs.add_substitution(ft, subst); - } - } - } - } -} - -void -PlannerBuilder::beta_multiply_b() -{ - int beta_pow = ogp::OperationTree::one; - for (int ll = 0; ll >= minlag; ll--, - beta_pow = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, tbeta)) - for (int yi = 0; yi < diff_b.nrows(); yi++) - if (diff_b(yi, ll-minlag) != ogp::OperationTree::zero) - diff_b(yi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, diff_b(yi, ll-minlag)); -} - -void -PlannerBuilder::beta_multiply_f() -{ - int beta_pow = ogp::OperationTree::one; - for (int ll = 0; ll <= maxlead; ll++, - beta_pow = model.eqs.add_binary(ogp::code_t::DIVIDE, beta_pow, tbeta)) - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - diff_f(yi, fi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, diff_f(yi, fi, ll-minlag)); - - beta_pow = ogp::OperationTree::one; - for (int ll = 0; ll >= minlag; ll--, - beta_pow = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, tbeta)) - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - diff_f(yi, fi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, diff_f(yi, fi, ll-minlag)); -} - -void -PlannerBuilder::make_static_version() -{ - // map holding substitutions from dynamic to static - ogp::StaticFineAtoms::Tintintmap tmap; - - // fill static atoms with outer ordering - static_atoms.import_atoms(model.atoms, static_tree, tmap); - - // go through diff_b and fill diff_b_static - for (int ll = minlag; ll <= 0; ll++) - for (int yi = 0; yi < diff_b.nrows(); yi++) - diff_b_static(yi, ll-minlag) - = static_tree.add_substitution(diff_b(yi, ll-minlag), - tmap, model.eqs.getTree()); - - // go through diff_f and fill diff_f_static - for (int ll = minlag; ll <= maxlead; ll++) - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - diff_f_static(yi, fi, ll-minlag) - = static_tree.add_substitution(diff_f(yi, fi, ll-minlag), - tmap, model.eqs.getTree()); - - // go through aux_map and fill static_aux_map - for (const auto &it : aux_map) - { - int tstatic = static_tree.add_substitution(it.second, tmap, model.eqs.getTree()); - static_aux_map.emplace(it.first, tstatic); - } -} - -void -PlannerBuilder::lagrange_mult_f() -{ - // register multipliers - std::string mult_name; - for (int fi = 0; fi < diff_f.dim2(); fi++) - { - mult_name = "MULT" + std::to_string(fset[fi]); - model.atoms.register_uniq_endo(mult_name); - info.num_lagrange_mults++; - } - // multiply with the multipliers - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - for (int ll = minlag; ll <= maxlead; ll++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - { - mult_name = "MULT" + std::to_string(fset[fi]) + '(' + std::to_string(-ll) + ')'; - int tm = model.eqs.add_nulary(mult_name); - diff_f(yi, fi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, tm, diff_f(yi, fi, ll-minlag)); - } -} - -void -PlannerBuilder::form_equations() -{ - // add planner’s FOCs - for (int yi = 0; yi < diff_f.dim1(); yi++) - { - int eq = ogp::OperationTree::zero; - for (int ll = minlag; ll <= 0; ll++) - eq = model.eqs.add_binary(ogp::code_t::PLUS, eq, diff_b(yi, ll-minlag)); - for (int fi = 0; fi < diff_f.dim2(); fi++) - for (int ll = minlag; ll <= maxlead; ll++) - eq = model.eqs.add_binary(ogp::code_t::PLUS, eq, diff_f(yi, fi, ll-minlag)); - model.eqs.add_formula(eq); - } - - // add equations for auxiliary variables - for (const auto &it : aux_map) - { - int t = model.atoms.index(it.first, 0); - model.eqs.add_formula(model.eqs.add_binary(ogp::code_t::MINUS, t, it.second)); - } -} - -void -PlannerBuilder::fill_yset(const ogp::NameStorage &ns, - const PlannerBuilder::Tvarset &yyset) -{ - for (auto it : yyset) - yset.insert(it); -} - -void -PlannerBuilder::fill_aux_map(const ogp::NameStorage &ns, const Tsubstmap &aaux_map, - const Tsubstmap &astatic_aux_map) -{ - // fill aux_map - for (auto it : aaux_map) - aux_map.insert(it); - - // fill static_aux_map - for (auto it : astatic_aux_map) - static_aux_map.insert(it); -} - -MultInitSS::MultInitSS(const PlannerBuilder &pb, const Vector &pvals, Vector &yy) - : builder(pb), b(builder.diff_b_static.nrows()), - F(builder.diff_f_static.dim1(), builder.diff_f_static.dim2()) -{ - b.zeros(); - F.zeros(); - - // first evaluate substitutions (auxiliary variables) from the builder - ogdyn::DynareStaticSteadySubstitutions dss(builder.model.atoms, builder.static_atoms, - builder.static_tree, - builder.static_aux_map, pvals, yy); - - /* gather all the terms from builder.diff_b_static and builder.diff_f_static - to the vector, the ordering is important, since the index of this vector - will have to be decoded to the position in b and F. */ - vector<int> terms; - for (int yi = 0; yi < builder.diff_b_static.nrows(); yi++) - for (int l = 0; l < builder.diff_b_static.ncols(); l++) - terms.push_back(builder.diff_b_static(yi, l)); - for (int yi = 0; yi < builder.diff_f_static.dim1(); yi++) - for (int fi = 0; fi < builder.diff_f_static.dim2(); fi++) - for (int l = 0; l < builder.diff_f_static.dim3(); l++) - terms.push_back(builder.diff_f_static(yi, fi, l)); - - /* evaluate the terms, it will call a series of load(i,res), which sum the - results through lags/leads to b and F */ - DynareStaticSteadyAtomValues dssav(builder.model.atoms, builder.static_atoms, pvals, yy); - ogp::FormulaCustomEvaluator fe(builder.static_tree, terms); - fe.eval(dssav, *this); - - // solve overdetermined system b+F*lambda=0 using SVD decomposition - SVDDecomp decomp(F); - Vector lambda(builder.diff_f_static.dim2()); - decomp.solve(b, lambda); - lambda.mult(-1); - - // take values of lambda and put it to yy - for (int fi = 0; fi < builder.diff_f_static.dim2(); fi++) - { - std::string mult_name = "MULT" + std::to_string(builder.fset[fi]); - int iouter = builder.model.atoms.name2outer_endo(mult_name); - int iy = builder.model.atoms.outer2y_endo()[iouter]; - if (!std::isfinite(yy[iy])) - yy[iy] = lambda[fi]; - - /* go through all substitutions of the multiplier and set them as well */ - if (builder.model.atom_substs) - { - const ogp::AtomSubstitutions::Toldnamemap &old2new - = builder.model.atom_substs->get_old2new(); - auto it = old2new.find(mult_name); - if (it != old2new.end()) - { - const ogp::AtomSubstitutions::Tshiftnameset &sset = it->second; - for (const auto &itt : sset) - { - const std::string &newname = itt.first; - int iouter = builder.model.atoms.name2outer_endo(newname); - int iy = builder.model.atoms.outer2y_endo()[iouter]; - if (!std::isfinite(yy[iy])) - yy[iy] = lambda[fi]; - } - } - } - } -} - -void -MultInitSS::load(int i, double res) -{ - /* we can afford it, since the evaluator sets res to exact zero if the term - is zero */ - if (res == 0) - return; - // decode i and add to either b or F - if (i < builder.diff_b_static.nrows()*builder.diff_b_static.ncols()) - // add to b - b[i / builder.diff_b_static.ncols()] += res; - else - { - // add to F - i -= builder.diff_b_static.nrows()*builder.diff_b_static.ncols(); - int yifi = i / builder.diff_f_static.dim3(); - int yi = yifi / builder.diff_f_static.dim2(); - int fi = yifi % builder.diff_f_static.dim2(); - F.get(yi, fi) += res; - } -} diff --git a/dynare++/src/planner_builder.hh b/dynare++/src/planner_builder.hh deleted file mode 100644 index 206df7da767dd53cd1274ad40a3a536db48c6be4..0000000000000000000000000000000000000000 --- a/dynare++/src/planner_builder.hh +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 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/>. - */ - -#ifndef PLANNER_BUILDER_H -#define PLANNER_BUILDER_H - -#include <unordered_set> -#include <map> -#include <vector> -#include <memory> -#include <algorithm> - -#include "parser/cc/static_fine_atoms.hh" -#include "dynare_atoms.hh" -#include "GeneralMatrix.hh" - -namespace ogdyn -{ - using std::unordered_set; - using std::map; - using std::vector; - - /** This is a two dimensional array of integers. Nothing - * difficult. */ - class IntegerMatrix - { - protected: - /** Number of rows. */ - int nr; - /** Number of columns. */ - int nc; - /** The pointer to the data. */ - std::unique_ptr<int[]> data; - public: - /** Construct uninitialized array. */ - IntegerMatrix(int nrr, int ncc) - : nr(nrr), nc(ncc), data(std::make_unique<int[]>(nr*nc)) - { - } - /** Copy constructor. */ - IntegerMatrix(const IntegerMatrix &im) - : nr(im.nr), nc(im.nc), data(std::make_unique<int[]>(nr*nc)) - { - std::copy_n(im.data.get(), nr*nc, data.get()); - } - /** Assignment operator. It can only assing array with the - * same dimensions. */ - const IntegerMatrix &operator=(const IntegerMatrix &im); - int & - operator()(int i, int j) - { - return data[i+j*nr]; - } - const int & - operator()(int i, int j) const - { - return data[i+j*nr]; - } - int - nrows() const - { - return nr; - } - int - ncols() const - { - return nc; - } - }; - - /** The three dimensional array of integers. Nothing difficult. */ - class IntegerArray3 - { - protected: - /** First dimension. */ - int n1; - /** Second dimension. */ - int n2; - /** Third dimension. */ - int n3; - /** The data. */ - std::unique_ptr<int[]> data; - public: - /** Constrcut unitialized array. */ - IntegerArray3(int nn1, int nn2, int nn3) - : n1(nn1), n2(nn2), n3(nn3), data(std::make_unique<int[]>(n1*n2*n3)) - { - } - /** Copy constructor. */ - IntegerArray3(const IntegerArray3 &ia3) - : n1(ia3.n1), n2(ia3.n2), n3(ia3.n3), data(std::make_unique<int[]>(n1*n2*n3)) - { - std::copy_n(ia3.data.get(), n1*n2*n3, data.get()); - } - /** Assignment operator assigning the arrays with the same dimensions. */ - const IntegerArray3 &operator=(const IntegerArray3 &ia3); - int & - operator()(int i, int j, int k) - { - return data[i+j*n1+k*n1*n2]; - } - const int & - operator()(int i, int j, int k) const - { - return data[i+j*n1+k*n1*n2]; - } - int - dim1() const - { - return n1; - } - int - dim2() const - { - return n2; - } - int - dim3() const - { - return n3; - } - }; - - /** This struct encapsulates information about the building of a - * planner's problem. */ - struct PlannerInfo - { - int num_lagrange_mults{0}; - int num_aux_variables{0}; - int num_new_terms{0}; - }; - - class MultInitSS; - class DynareModel; - - /** This class builds the first order conditions of the social - * planner problem with constraints being the equations in the - * model. The model is non-const parameter to the constructor - * which adds appropriate FOCs to the system. It also allows for - * an estimation of the lagrange multipliers given all other - * endogenous variables of the static system. For this purpose we - * need to create static atoms and static versions of all the tree - * index matrices. The algorithm and algebra are documented in - * dynare++-ramsey.pdf. */ - class PlannerBuilder - { - friend class MultInitSS; - public: - /** Type for a set of variable names. */ - using Tvarset = unordered_set<string>; - /** Type for a set of equations. An equation is identified by - * an index to an equation in the equation vector given by - * DynareModel::eqs. The tree index of the i-th formula is - * retrieved as DynareModel::egs.formula(i). */ - using Teqset = vector<int>; - protected: - /** This is a set of variables wrt which the planner - * optimizes. These could be all endogenous variables, but it - * is beneficial to exclude all variables which are - * deterministic transformations of past exogenous variables, - * since the planner cannot influence them. This could save a - * few equations. This is not changed after it is constructed, - * but it is constructed manually, so it cannot be declared as - * const. */ - Tvarset yset; - /** These are the equation indices constituing the constraints - * for the planner. Again, it is beneficial to exclude all - * equations defining exogenous variables excluded from - * yset. */ - const Teqset fset; - /** Reference to the model. */ - ogdyn::DynareModel &model; - /** Tree index of the planner objective. */ - int tb; - /** Tree index of the planner discount parameter. */ - int tbeta; - /** The maximum lead in the model including the planner's - * objective before building the planner's FOCs. */ - const int maxlead; - /** The minimum lag in the model including the planner's objective - * before building the planner's FOCs. */ - const int minlag; - /** Tree indices of formulas in the planner FOCs involving - * derivatives of the planner's objective. Rows correspond to the - * endogenous variables, columns correspond to lags in the - * objective function. The contents of the matrix will evolve as - * the algorithm proceeds. */ - IntegerMatrix diff_b; - /** Tree indices of formulas in the planner FOCs involving - * derivatives of the model equations (constraints). The first - * dimension corresponds to endogenous variables, the second to - * the constraints, the third to lags or leads of endogenous - * variables in the constraints. The contents of the array will - * evolve as the algorithm proceeds.*/ - IntegerArray3 diff_f; - /** Static version of the model atoms. It is needed to build - * static version of diff_b and diff_f. */ - ogp::StaticFineAtoms static_atoms; - /** Static version of all the trees of diff_b and diff_f build - * over static_atoms. */ - ogp::OperationTree static_tree; - /** Tree indices of static version of diff_b over static_atoms and static_tree. */ - IntegerMatrix diff_b_static; - /** Tree indices of static version of diff_f over static_atoms - * and static_tree. This member is created before calling - * lagrange_mult_f(), so it does not contain the - * multiplication with the lagrange multipliers. */ - IntegerArray3 diff_f_static; - /** Auxiliary variables mapping. During the algorithm, some - * auxiliary variables for the terms might be created, so we - * remember their names and tree indices of the terms. This - * maps a name to the tree index of an expression equal to the - * auxiliary variable at time zero. The auxiliary variables - * names point to the dynamic atoms storage, tree inidices to - * the dynamic model tree. */ - Tsubstmap aux_map; - /** Static version of aux_map. The names point to static_atoms - * storage, the tree indices to the static_tree. */ - Tsubstmap static_aux_map; - /** Information about the number of various things. */ - PlannerInfo info; - public: - /** Build the planner problem for the given model optimizing - * through the given endogenous variables with the given - * constraints. We allow for a selection of a subset of - * equations and variables in order to eliminate exogenous - * predetermined process which cannot be influenced by the - * social planner. */ - PlannerBuilder(ogdyn::DynareModel &m, const Tvarset &yyset, - Teqset ffset); - /** Construct a copy of the builder with provided model, which - * is supposed to be the copy of the model in the builder. */ - PlannerBuilder(const PlannerBuilder &pb, ogdyn::DynareModel &m); - /** Avoid copying from only PlannerBuilder. */ - PlannerBuilder(const PlannerBuilder &pb) = delete; - /** Return the information. */ - const PlannerInfo & - get_info() const - { - return info; - } - protected: - /** Differentiate the planner objective wrt endogenous - * variables with different lags. */ - void add_derivatives_of_b(); - /** Differentiate the constraints wrt endogenous variables - * with different lags and leads. */ - void add_derivatives_of_f(); - /** Shift derivatives of diff_b. */ - void shift_derivatives_of_b(); - /** Shift derivatives of diff_ff. */ - void shift_derivatives_of_f(); - /** Multiply with the discount factor terms in diff_b. */ - void beta_multiply_b(); - /** Multiply with the discount factor terms in diff_f. */ - void beta_multiply_f(); - /** Fill static_atoms and static_tree and build diff_b_static, - * diff_f_static and aux_map_static with static versions of diff_b, - * diff_f and aux_map. */ - void make_static_version(); - /** Multiply diff_f with Langrange multipliers. */ - void lagrange_mult_f(); - /** Add the equations to the mode, including equation for auxiliary variables. */ - void form_equations(); - private: - /** Fill yset for a given yyset and given name storage. */ - void fill_yset(const ogp::NameStorage &ns, const Tvarset &yyset); - /** Fill aux_map and aux_map_static for a given aaux_map and - * aaux_map_static for a given storage of dynamic atoms (used - * for aux_map) and static atoms storage from this object for - * aux_map_static. */ - void fill_aux_map(const ogp::NameStorage &ns, const Tsubstmap &aaux_map, - const Tsubstmap &astatic_aux_map); - }; - - /** This class only calculates for the given initial guess of - * endogenous variables, initial guess of the Langrange - * multipliers of the social planner problem yielding the least - * square error. It is used by just calling its constructor. The - * constructor takes non-const reference to the vector of - * endogenous variables, calculates lambdas and put the values of - * lambdas to the vector. The algbera is found in - * dynare++-ramsey.pdf. - * - * The code can be run only after the parsing has been finished in - * atoms. */ - class MultInitSS : public ogp::FormulaEvalLoader - { - protected: - /** The constant reference to the builder. */ - const PlannerBuilder &builder; - /** The constant term of the problem. Its length is the number - * of endogenous variable wrt the planner optimizes. */ - Vector b; - /** The matrix of the overdetermined problem. The number of - * rows is equal to the number of endogenous variables wrt - * which the planner optimizes, the number of columns is equal - * to the number of Langrange multipliers which is equal to - * the number of constraints which is smaller than the number - * of endogenous variables. Hence the system b+F*lambda=0 is - * overdetermined. */ - GeneralMatrix F; - public: - /** The constructor of the object which does everything. Its - * main goal is to update yy. Note that if an item of yy - * corresponding to a lagrange multiplier is already set, it - * is not reset. */ - MultInitSS(const PlannerBuilder &pb, const Vector &pvals, Vector &yy); - /** This loads evaluated parts of b or F and decodes i and - * advances b or F depending on the decoded i. The decoding is - * dependent on the way how the terms of builder.diff_b and - * builder.diff_f_save have been put the the - * ogp::FormulaCustomEvaluator. This is documented in the code - * of the constructor. */ - void load(int i, double res) override; - }; -}; - -#endif diff --git a/dynare++/sylv/Makefile.am b/dynare++/sylv/Makefile.am deleted file mode 100644 index ffebab6fe3641d3346316761575936e56f4be6f5..0000000000000000000000000000000000000000 --- a/dynare++/sylv/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = cc testing diff --git a/dynare++/sylv/cc/Makefile.am b/dynare++/sylv/cc/Makefile.am deleted file mode 100644 index d1e88bbc3272b8155fe00818f0d19baa038f0069..0000000000000000000000000000000000000000 --- a/dynare++/sylv/cc/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -noinst_LIBRARIES = libsylv.a - -# For dynblas.h and dynlapack.h -libsylv_a_CPPFLAGS = -I$(top_srcdir)/mex/sources -I../../utils/cc - -libsylv_a_SOURCES = \ - BlockDiagonal.cc \ - BlockDiagonal.hh \ - GeneralMatrix.cc \ - GeneralMatrix.hh \ - GeneralSylvester.cc \ - GeneralSylvester.hh \ - IterativeSylvester.cc \ - IterativeSylvester.hh \ - KronUtils.cc \ - KronUtils.hh \ - KronVector.cc \ - KronVector.hh \ - QuasiTriangular.cc \ - QuasiTriangular.hh \ - QuasiTriangularZero.cc \ - QuasiTriangularZero.hh \ - SchurDecomp.cc \ - SchurDecomp.hh \ - SchurDecompEig.cc \ - SchurDecompEig.hh \ - SimilarityDecomp.cc \ - SimilarityDecomp.hh \ - SylvException.cc \ - SylvException.hh \ - SylvMatrix.cc \ - SylvMatrix.hh \ - SylvParams.cc \ - SylvParams.hh \ - SylvesterSolver.hh \ - SymSchurDecomp.cc \ - SymSchurDecomp.hh \ - TriangularSylvester.cc \ - TriangularSylvester.hh \ - Vector.cc \ - Vector.hh diff --git a/dynare++/tests/Makefile.am b/dynare++/tests/Makefile.am deleted file mode 100644 index e98e408637a5ee497d19c07d1c0f2bd0e6eca6f8..0000000000000000000000000000000000000000 --- a/dynare++/tests/Makefile.am +++ /dev/null @@ -1,46 +0,0 @@ -MODFILES = \ - asset.mod \ - c20.mod \ - czech2.mod \ - dm7.mod \ - example1.mod \ - example1_optim.mod \ - gentay1a.mod \ - judd.mod \ - judd_norm.mod \ - kp1980_1.mod \ - kp1980_2.mod \ - kp1980_3.mod \ - lucas78.mod \ - m_0_3_0_0_0_0_0_0.mod \ - m_1_3_0_0_0_0_0_0.mod \ - m_1_3_0_0_0_0_0_1.mod \ - or0a.mod \ - portfolio4.mod \ - portfolio4_norm.mod \ - portfolio.mod \ - psd_exo3.mod \ - q3a2.mod \ - q3a50.mod \ - sedmodel1.mod \ - swma_pie.mod \ - test1.mod \ - test2a.mod \ - test2.mod \ - test3.mod \ - test4.mod \ - test5.mod \ - test6.mod \ - test7.mod \ - test.mod - -EXTRA_DIST = $(MODFILES) \ - sw_euro.mod # This one crashes at steady state computation - -check-local: $(MODFILES:%.mod=%.jnl) - -%.jnl: %.mod - ../src/dynare++ --sim 2 $< - -clean-local: - rm -f *.jnl *_f.m *_ff.m *.dump diff --git a/dynare++/tests/asset.mod b/dynare++/tests/asset.mod deleted file mode 100644 index c9a5b9e2877ac6ec4b5ad3de84e35513582c315a..0000000000000000000000000000000000000000 --- a/dynare++/tests/asset.mod +++ /dev/null @@ -1,28 +0,0 @@ -var y, x; -varexo e; - -parameters theta, rho, bet, xbar; - -xbar = 0.0179; -rho = -0.139; -theta = -10; -bet = 0.95; - -model; -y = bet*exp(theta*x(+1))*(1+y(+1)); -x = (1-rho)*xbar + rho*x(-1) + e; -end; - -initval; -x = 0.0179; -y = 0.3; -e = 0; -end; - -vcov = [ 0.0012110]; - -order = 6; - - - - diff --git a/dynare++/tests/c20.mod b/dynare++/tests/c20.mod deleted file mode 100644 index a3b7bd1fabfa3dd28c68daaa7a51bac15898811f..0000000000000000000000000000000000000000 --- a/dynare++/tests/c20.mod +++ /dev/null @@ -1,497 +0,0 @@ -var C10_PIE C10_RR C10_RS C10_Y C11_PIE C11_RR C11_RS C11_Y C12_PIE C12_RR C12_RS C12_Y C13_PIE C13_RR C13_RS C13_Y C14_PIE C14_RR C14_RS C14_Y C15_PIE C15_RR C15_RS C15_Y C16_PIE C16_RR C16_RS C16_Y C17_PIE C17_RR C17_RS C17_Y C18_PIE C18_RR C18_RS C18_Y C19_PIE C19_RR C19_RS C19_Y C1_PIE C1_RR C1_RS C1_Y C20_PIE C20_RR C20_RS C20_Y C2_PIE C2_RR C2_RS C2_Y C3_PIE C3_RR C3_RS C3_Y C4_PIE C4_RR C4_RS C4_Y C5_PIE C5_RR C5_RS C5_Y C6_PIE C6_RR C6_RS C6_Y C7_PIE C7_RR C7_RS C7_Y C8_PIE C8_RR C8_RS C8_Y C9_PIE C9_RR C9_RS C9_Y; - -varexo C1_EPIE C1_EY C1_ERS C2_EPIE C2_EY C2_ERS C3_EPIE C3_EY C3_ERS C4_EPIE C4_EY C4_ERS C5_EPIE C5_EY C5_ERS C6_EPIE C6_EY C6_ERS C7_EPIE C7_EY C7_ERS C8_EPIE C8_EY C8_ERS C9_EPIE C9_EY C9_ERS C10_EPIE C10_EY C10_ERS C11_EPIE C11_EY C11_ERS C12_EPIE C12_EY C12_ERS C13_EPIE C13_EY C13_ERS C14_EPIE C14_EY C14_ERS C15_EPIE C15_EY C15_ERS C16_EPIE C16_EY C16_ERS C17_EPIE C17_EY C17_ERS C18_EPIE C18_EY C18_ERS C19_EPIE C19_EY C19_ERS C20_EPIE C20_EY C20_ERS; - -parameters C10_CALFA1 C10_CALFA2 C10_CALFA3 C10_CALFA4 C10_CALFA5 C10_CALFA6 C10_CALFA7 C10_CALFA8 C10_CALFA9 C11_CALFA1 C11_CALFA2 C11_CALFA3 C11_CALFA4 C11_CALFA5 C11_CALFA6 C11_CALFA7 C11_CALFA8 C11_CALFA9 C12_CALFA1 C12_CALFA2 C12_CALFA3 C12_CALFA4 C12_CALFA5 C12_CALFA6 C12_CALFA7 C12_CALFA8 C12_CALFA9 C13_CALFA1 C13_CALFA2 C13_CALFA3 C13_CALFA4 C13_CALFA5 C13_CALFA6 C13_CALFA7 C13_CALFA8 C13_CALFA9 C14_CALFA1 C14_CALFA2 C14_CALFA3 C14_CALFA4 C14_CALFA5 C14_CALFA6 C14_CALFA7 C14_CALFA8 C14_CALFA9 C15_CALFA1 C15_CALFA2 C15_CALFA3 C15_CALFA4 C15_CALFA5 C15_CALFA6 C15_CALFA7 C15_CALFA8 C15_CALFA9 C16_CALFA1 C16_CALFA2 C16_CALFA3 C16_CALFA4 C16_CALFA5 C16_CALFA6 C16_CALFA7 C16_CALFA8 C16_CALFA9 C17_CALFA1 C17_CALFA2 C17_CALFA3 C17_CALFA4 C17_CALFA5 C17_CALFA6 C17_CALFA7 C17_CALFA8 C17_CALFA9 C18_CALFA1 C18_CALFA2 C18_CALFA3 C18_CALFA4 C18_CALFA5 C18_CALFA6 C18_CALFA7 C18_CALFA8 C18_CALFA9 C19_CALFA1 C19_CALFA2 C19_CALFA3 C19_CALFA4 C19_CALFA5 C19_CALFA6 C19_CALFA7 C19_CALFA8 C19_CALFA9 C1_CALFA1 C1_CALFA2 C1_CALFA3 C1_CALFA4 C1_CALFA5 C1_CALFA6 C1_CALFA7 C1_CALFA8 C1_CALFA9 C20_CALFA1 C20_CALFA2 C20_CALFA3 C20_CALFA4 C20_CALFA5 C20_CALFA6 C20_CALFA7 C20_CALFA8 C20_CALFA9 C2_CALFA1 C2_CALFA2 C2_CALFA3 C2_CALFA4 C2_CALFA5 C2_CALFA6 C2_CALFA7 C2_CALFA8 C2_CALFA9 C3_CALFA1 C3_CALFA2 C3_CALFA3 C3_CALFA4 C3_CALFA5 C3_CALFA6 C3_CALFA7 C3_CALFA8 C3_CALFA9 C4_CALFA1 C4_CALFA2 C4_CALFA3 C4_CALFA4 C4_CALFA5 C4_CALFA6 C4_CALFA7 C4_CALFA8 C4_CALFA9 C5_CALFA1 C5_CALFA2 C5_CALFA3 C5_CALFA4 C5_CALFA5 C5_CALFA6 C5_CALFA7 C5_CALFA8 C5_CALFA9 C6_CALFA1 C6_CALFA2 C6_CALFA3 C6_CALFA4 C6_CALFA5 C6_CALFA6 C6_CALFA7 C6_CALFA8 C6_CALFA9 C7_CALFA1 C7_CALFA2 C7_CALFA3 C7_CALFA4 C7_CALFA5 C7_CALFA6 C7_CALFA7 C7_CALFA8 C7_CALFA9 C8_CALFA1 C8_CALFA2 C8_CALFA3 C8_CALFA4 C8_CALFA5 C8_CALFA6 C8_CALFA7 C8_CALFA8 C8_CALFA9 C9_CALFA1 C9_CALFA2 C9_CALFA3 C9_CALFA4 C9_CALFA5 C9_CALFA6 C9_CALFA7 C9_CALFA8 C9_CALFA9 C10_PIESTAR C11_PIESTAR C12_PIESTAR C13_PIESTAR C14_PIESTAR C15_PIESTAR C16_PIESTAR C17_PIESTAR C18_PIESTAR C19_PIESTAR C1_PIESTAR C20_PIESTAR C2_PIESTAR C3_PIESTAR C4_PIESTAR C5_PIESTAR C6_PIESTAR C7_PIESTAR C8_PIESTAR C9_PIESTAR; -C10_CALFA1=0.5; -C10_CALFA2=0.5; -C10_CALFA3=0.5; -C10_CALFA4=0; -C10_CALFA5=0.75; -C10_CALFA6=-0.25; -C10_CALFA7=0.1; -C10_CALFA8=0.5; -C10_CALFA9=0.5; -C11_CALFA1=0.5; -C11_CALFA2=0.5; -C11_CALFA3=0.5; -C11_CALFA4=0; -C11_CALFA5=0.75; -C11_CALFA6=-0.25; -C11_CALFA7=0.1; -C11_CALFA8=0.5; -C11_CALFA9=0.5; -C12_CALFA1=0.5; -C12_CALFA2=0.5; -C12_CALFA3=0.5; -C12_CALFA4=0; -C12_CALFA5=0.75; -C12_CALFA6=-0.25; -C12_CALFA7=0.1; -C12_CALFA8=0.5; -C12_CALFA9=0.5; -C13_CALFA1=0.5; -C13_CALFA2=0.5; -C13_CALFA3=0.5; -C13_CALFA4=0; -C13_CALFA5=0.75; -C13_CALFA6=-0.25; -C13_CALFA7=0.1; -C13_CALFA8=0.5; -C13_CALFA9=0.5; -C14_CALFA1=0.5; -C14_CALFA2=0.5; -C14_CALFA3=0.5; -C14_CALFA4=0; -C14_CALFA5=0.75; -C14_CALFA6=-0.25; -C14_CALFA7=0.1; -C14_CALFA8=0.5; -C14_CALFA9=0.5; -C15_CALFA1=0.5; -C15_CALFA2=0.5; -C15_CALFA3=0.5; -C15_CALFA4=0; -C15_CALFA5=0.75; -C15_CALFA6=-0.25; -C15_CALFA7=0.1; -C15_CALFA8=0.5; -C15_CALFA9=0.5; -C16_CALFA1=0.5; -C16_CALFA2=0.5; -C16_CALFA3=0.5; -C16_CALFA4=0; -C16_CALFA5=0.75; -C16_CALFA6=-0.25; -C16_CALFA7=0.1; -C16_CALFA8=0.5; -C16_CALFA9=0.5; -C17_CALFA1=0.5; -C17_CALFA2=0.5; -C17_CALFA3=0.5; -C17_CALFA4=0; -C17_CALFA5=0.75; -C17_CALFA6=-0.25; -C17_CALFA7=0.1; -C17_CALFA8=0.5; -C17_CALFA9=0.5; -C18_CALFA1=0.5; -C18_CALFA2=0.5; -C18_CALFA3=0.5; -C18_CALFA4=0; -C18_CALFA5=0.75; -C18_CALFA6=-0.25; -C18_CALFA7=0.1; -C18_CALFA8=0.5; -C18_CALFA9=0.5; -C19_CALFA1=0.5; -C19_CALFA2=0.5; -C19_CALFA3=0.5; -C19_CALFA4=0; -C19_CALFA5=0.75; -C19_CALFA6=-0.25; -C19_CALFA7=0.1; -C19_CALFA8=0.5; -C19_CALFA9=0.5; -C1_CALFA1=0.5; -C1_CALFA2=0.5; -C1_CALFA3=0.5; -C1_CALFA4=0; -C1_CALFA5=0.75; -C1_CALFA6=-0.25; -C1_CALFA7=0.1; -C1_CALFA8=0.5; -C1_CALFA9=0.5; -C20_CALFA1=0.5; -C20_CALFA2=0.5; -C20_CALFA3=0.5; -C20_CALFA4=0; -C20_CALFA5=0.75; -C20_CALFA6=-0.25; -C20_CALFA7=0.1; -C20_CALFA8=0.5; -C20_CALFA9=0.5; -C2_CALFA1=0.5; -C2_CALFA2=0.5; -C2_CALFA3=0.5; -C2_CALFA4=0; -C2_CALFA5=0.75; -C2_CALFA6=-0.25; -C2_CALFA7=0.1; -C2_CALFA8=0.5; -C2_CALFA9=0.5; -C3_CALFA1=0.5; -C3_CALFA2=0.5; -C3_CALFA3=0.5; -C3_CALFA4=0; -C3_CALFA5=0.75; -C3_CALFA6=-0.25; -C3_CALFA7=0.1; -C3_CALFA8=0.5; -C3_CALFA9=0.5; -C4_CALFA1=0.5; -C4_CALFA2=0.5; -C4_CALFA3=0.5; -C4_CALFA4=0; -C4_CALFA5=0.75; -C4_CALFA6=-0.25; -C4_CALFA7=0.1; -C4_CALFA8=0.5; -C4_CALFA9=0.5; -C5_CALFA1=0.5; -C5_CALFA2=0.5; -C5_CALFA3=0.5; -C5_CALFA4=0; -C5_CALFA5=0.75; -C5_CALFA6=-0.25; -C5_CALFA7=0.1; -C5_CALFA8=0.5; -C5_CALFA9=0.5; -C6_CALFA1=0.5; -C6_CALFA2=0.5; -C6_CALFA3=0.5; -C6_CALFA4=0; -C6_CALFA5=0.75; -C6_CALFA6=-0.25; -C6_CALFA7=0.1; -C6_CALFA8=0.5; -C6_CALFA9=0.5; -C7_CALFA1=0.5; -C7_CALFA2=0.5; -C7_CALFA3=0.5; -C7_CALFA4=0; -C7_CALFA5=0.75; -C7_CALFA6=-0.25; -C7_CALFA7=0.1; -C7_CALFA8=0.5; -C7_CALFA9=0.5; -C8_CALFA1=0.5; -C8_CALFA2=0.5; -C8_CALFA3=0.5; -C8_CALFA4=0; -C8_CALFA5=0.75; -C8_CALFA6=-0.25; -C8_CALFA7=0.1; -C8_CALFA8=0.5; -C8_CALFA9=0.5; -C9_CALFA1=0.5; -C9_CALFA2=0.5; -C9_CALFA3=0.5; -C9_CALFA4=0; -C9_CALFA5=0.75; -C9_CALFA6=-0.25; -C9_CALFA7=0.1; -C9_CALFA8=0.5; -C9_CALFA9=0.5; -C10_PIESTAR=2.5; -C11_PIESTAR=2.5; -C12_PIESTAR=2.5; -C13_PIESTAR=2.5; -C14_PIESTAR=2.5; -C15_PIESTAR=2.5; -C16_PIESTAR=2.5; -C17_PIESTAR=2.5; -C18_PIESTAR=2.5; -C19_PIESTAR=2.5; -C1_PIESTAR=2.5; -C20_PIESTAR=2.5; -C2_PIESTAR=2.5; -C3_PIESTAR=2.5; -C4_PIESTAR=2.5; -C5_PIESTAR=2.5; -C6_PIESTAR=2.5; -C7_PIESTAR=2.5; -C8_PIESTAR=2.5; -C9_PIESTAR=2.5; - -model; - C1_PIE = C1_CALFA1*C1_PIE(1)+(1-C1_CALFA1)*C1_PIE(-1)+C1_CALFA2*(C1_Y+0.1)+C1_CALFA3*(C1_Y+0.1)^2/2+C1_EPIE ; - C1_Y = C1_CALFA4*C1_Y(1)+C1_CALFA5*C1_Y(-1)+C1_CALFA6*C1_RR+C1_EY+C1_CALFA7*(0+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C1_RR = C1_RS-C1_PIE(1) ; - C1_RS = C1_PIE(1)+C1_CALFA8*(C1_PIE-C1_PIESTAR)+C1_CALFA9*C1_Y+C1_ERS ; - C2_PIE = C2_CALFA1*C2_PIE(1)+(1-C2_CALFA1)*C2_PIE(-1)+C2_CALFA2*(C2_Y+0.1)+C2_CALFA3*(C2_Y+0.1)^2/2+C2_EPIE ; - C2_Y = C2_CALFA4*C2_Y(1)+C2_CALFA5*C2_Y(-1)+C2_CALFA6*C2_RR+C2_EY+C2_CALFA7*(0+C1_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C2_RR = C2_RS-C2_PIE(1) ; - C2_RS = C2_PIE(1)+C2_CALFA8*(C2_PIE-C2_PIESTAR)+C2_CALFA9*C2_Y+C2_ERS ; - C3_PIE = C3_CALFA1*C3_PIE(1)+(1-C3_CALFA1)*C3_PIE(-1)+C3_CALFA2*(C3_Y+0.1)+C3_CALFA3*(C3_Y+0.1)^2/2+C3_EPIE ; - C3_Y = C3_CALFA4*C3_Y(1)+C3_CALFA5*C3_Y(-1)+C3_CALFA6*C3_RR+C3_EY+C3_CALFA7*(0+C1_Y+C2_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C3_RR = C3_RS-C3_PIE(1) ; - C3_RS = C3_PIE(1)+C3_CALFA8*(C3_PIE-C3_PIESTAR)+C3_CALFA9*C3_Y+C3_ERS ; - C4_PIE = C4_CALFA1*C4_PIE(1)+(1-C4_CALFA1)*C4_PIE(-1)+C4_CALFA2*(C4_Y+0.1)+C4_CALFA3*(C4_Y+0.1)^2/2+C4_EPIE ; - C4_Y = C4_CALFA4*C4_Y(1)+C4_CALFA5*C4_Y(-1)+C4_CALFA6*C4_RR+C4_EY+C4_CALFA7*(0+C1_Y+C2_Y+C3_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C4_RR = C4_RS-C4_PIE(1) ; - C4_RS = C4_PIE(1)+C4_CALFA8*(C4_PIE-C4_PIESTAR)+C4_CALFA9*C4_Y+C4_ERS ; - C5_PIE = C5_CALFA1*C5_PIE(1)+(1-C5_CALFA1)*C5_PIE(-1)+C5_CALFA2*(C5_Y+0.1)+C5_CALFA3*(C5_Y+0.1)^2/2+C5_EPIE ; - C5_Y = C5_CALFA4*C5_Y(1)+C5_CALFA5*C5_Y(-1)+C5_CALFA6*C5_RR+C5_EY+C5_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C5_RR = C5_RS-C5_PIE(1) ; - C5_RS = C5_PIE(1)+C5_CALFA8*(C5_PIE-C5_PIESTAR)+C5_CALFA9*C5_Y+C5_ERS ; - C6_PIE = C6_CALFA1*C6_PIE(1)+(1-C6_CALFA1)*C6_PIE(-1)+C6_CALFA2*(C6_Y+0.1)+C6_CALFA3*(C6_Y+0.1)^2/2+C6_EPIE ; - C6_Y = C6_CALFA4*C6_Y(1)+C6_CALFA5*C6_Y(-1)+C6_CALFA6*C6_RR+C6_EY+C6_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C6_RR = C6_RS-C6_PIE(1) ; - C6_RS = C6_PIE(1)+C6_CALFA8*(C6_PIE-C6_PIESTAR)+C6_CALFA9*C6_Y+C6_ERS ; - C7_PIE = C7_CALFA1*C7_PIE(1)+(1-C7_CALFA1)*C7_PIE(-1)+C7_CALFA2*(C7_Y+0.1)+C7_CALFA3*(C7_Y+0.1)^2/2+C7_EPIE ; - C7_Y = C7_CALFA4*C7_Y(1)+C7_CALFA5*C7_Y(-1)+C7_CALFA6*C7_RR+C7_EY+C7_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C7_RR = C7_RS-C7_PIE(1) ; - C7_RS = C7_PIE(1)+C7_CALFA8*(C7_PIE-C7_PIESTAR)+C7_CALFA9*C7_Y+C7_ERS ; - C8_PIE = C8_CALFA1*C8_PIE(1)+(1-C8_CALFA1)*C8_PIE(-1)+C8_CALFA2*(C8_Y+0.1)+C8_CALFA3*(C8_Y+0.1)^2/2+C8_EPIE ; - C8_Y = C8_CALFA4*C8_Y(1)+C8_CALFA5*C8_Y(-1)+C8_CALFA6*C8_RR+C8_EY+C8_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C8_RR = C8_RS-C8_PIE(1) ; - C8_RS = C8_PIE(1)+C8_CALFA8*(C8_PIE-C8_PIESTAR)+C8_CALFA9*C8_Y+C8_ERS ; - C9_PIE = C9_CALFA1*C9_PIE(1)+(1-C9_CALFA1)*C9_PIE(-1)+C9_CALFA2*(C9_Y+0.1)+C9_CALFA3*(C9_Y+0.1)^2/2+C9_EPIE ; - C9_Y = C9_CALFA4*C9_Y(1)+C9_CALFA5*C9_Y(-1)+C9_CALFA6*C9_RR+C9_EY+C9_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C9_RR = C9_RS-C9_PIE(1) ; - C9_RS = C9_PIE(1)+C9_CALFA8*(C9_PIE-C9_PIESTAR)+C9_CALFA9*C9_Y+C9_ERS ; - C10_PIE = C10_CALFA1*C10_PIE(1)+(1-C10_CALFA1)*C10_PIE(-1)+C10_CALFA2*(C10_Y+0.1)+C10_CALFA3*(C10_Y+0.1)^2/2+C10_EPIE ; - C10_Y = C10_CALFA4*C10_Y(1)+C10_CALFA5*C10_Y(-1)+C10_CALFA6*C10_RR+C10_EY+C10_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C10_RR = C10_RS-C10_PIE(1) ; - C10_RS = C10_PIE(1)+C10_CALFA8*(C10_PIE-C10_PIESTAR)+C10_CALFA9*C10_Y+C10_ERS ; - C11_PIE = C11_CALFA1*C11_PIE(1)+(1-C11_CALFA1)*C11_PIE(-1)+C11_CALFA2*(C11_Y+0.1)+C11_CALFA3*(C11_Y+0.1)^2/2+C11_EPIE ; - C11_Y = C11_CALFA4*C11_Y(1)+C11_CALFA5*C11_Y(-1)+C11_CALFA6*C11_RR+C11_EY+C11_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C11_RR = C11_RS-C11_PIE(1) ; - C11_RS = C11_PIE(1)+C11_CALFA8*(C11_PIE-C11_PIESTAR)+C11_CALFA9*C11_Y+C11_ERS ; - C12_PIE = C12_CALFA1*C12_PIE(1)+(1-C12_CALFA1)*C12_PIE(-1)+C12_CALFA2*(C12_Y+0.1)+C12_CALFA3*(C12_Y+0.1)^2/2+C12_EPIE ; - C12_Y = C12_CALFA4*C12_Y(1)+C12_CALFA5*C12_Y(-1)+C12_CALFA6*C12_RR+C12_EY+C12_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C12_RR = C12_RS-C12_PIE(1) ; - C12_RS = C12_PIE(1)+C12_CALFA8*(C12_PIE-C12_PIESTAR)+C12_CALFA9*C12_Y+C12_ERS ; - C13_PIE = C13_CALFA1*C13_PIE(1)+(1-C13_CALFA1)*C13_PIE(-1)+C13_CALFA2*(C13_Y+0.1)+C13_CALFA3*(C13_Y+0.1)^2/2+C13_EPIE ; - C13_Y = C13_CALFA4*C13_Y(1)+C13_CALFA5*C13_Y(-1)+C13_CALFA6*C13_RR+C13_EY+C13_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C13_RR = C13_RS-C13_PIE(1) ; - C13_RS = C13_PIE(1)+C13_CALFA8*(C13_PIE-C13_PIESTAR)+C13_CALFA9*C13_Y+C13_ERS ; - C14_PIE = C14_CALFA1*C14_PIE(1)+(1-C14_CALFA1)*C14_PIE(-1)+C14_CALFA2*(C14_Y+0.1)+C14_CALFA3*(C14_Y+0.1)^2/2+C14_EPIE ; - C14_Y = C14_CALFA4*C14_Y(1)+C14_CALFA5*C14_Y(-1)+C14_CALFA6*C14_RR+C14_EY+C14_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C14_RR = C14_RS-C14_PIE(1) ; - C14_RS = C14_PIE(1)+C14_CALFA8*(C14_PIE-C14_PIESTAR)+C14_CALFA9*C14_Y+C14_ERS ; - C15_PIE = C15_CALFA1*C15_PIE(1)+(1-C15_CALFA1)*C15_PIE(-1)+C15_CALFA2*(C15_Y+0.1)+C15_CALFA3*(C15_Y+0.1)^2/2+C15_EPIE ; - C15_Y = C15_CALFA4*C15_Y(1)+C15_CALFA5*C15_Y(-1)+C15_CALFA6*C15_RR+C15_EY+C15_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C15_RR = C15_RS-C15_PIE(1) ; - C15_RS = C15_PIE(1)+C15_CALFA8*(C15_PIE-C15_PIESTAR)+C15_CALFA9*C15_Y+C15_ERS ; - C16_PIE = C16_CALFA1*C16_PIE(1)+(1-C16_CALFA1)*C16_PIE(-1)+C16_CALFA2*(C16_Y+0.1)+C16_CALFA3*(C16_Y+0.1)^2/2+C16_EPIE ; - C16_Y = C16_CALFA4*C16_Y(1)+C16_CALFA5*C16_Y(-1)+C16_CALFA6*C16_RR+C16_EY+C16_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C16_RR = C16_RS-C16_PIE(1) ; - C16_RS = C16_PIE(1)+C16_CALFA8*(C16_PIE-C16_PIESTAR)+C16_CALFA9*C16_Y+C16_ERS ; - C17_PIE = C17_CALFA1*C17_PIE(1)+(1-C17_CALFA1)*C17_PIE(-1)+C17_CALFA2*(C17_Y+0.1)+C17_CALFA3*(C17_Y+0.1)^2/2+C17_EPIE ; - C17_Y = C17_CALFA4*C17_Y(1)+C17_CALFA5*C17_Y(-1)+C17_CALFA6*C17_RR+C17_EY+C17_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C18_Y+C19_Y+C20_Y)/19 ; - C17_RR = C17_RS-C17_PIE(1) ; - C17_RS = C17_PIE(1)+C17_CALFA8*(C17_PIE-C17_PIESTAR)+C17_CALFA9*C17_Y+C17_ERS ; - C18_PIE = C18_CALFA1*C18_PIE(1)+(1-C18_CALFA1)*C18_PIE(-1)+C18_CALFA2*(C18_Y+0.1)+C18_CALFA3*(C18_Y+0.1)^2/2+C18_EPIE ; - C18_Y = C18_CALFA4*C18_Y(1)+C18_CALFA5*C18_Y(-1)+C18_CALFA6*C18_RR+C18_EY+C18_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C19_Y+C20_Y)/19 ; - C18_RR = C18_RS-C18_PIE(1) ; - C18_RS = C18_PIE(1)+C18_CALFA8*(C18_PIE-C18_PIESTAR)+C18_CALFA9*C18_Y+C18_ERS ; - C19_PIE = C19_CALFA1*C19_PIE(1)+(1-C19_CALFA1)*C19_PIE(-1)+C19_CALFA2*(C19_Y+0.1)+C19_CALFA3*(C19_Y+0.1)^2/2+C19_EPIE ; - C19_Y = C19_CALFA4*C19_Y(1)+C19_CALFA5*C19_Y(-1)+C19_CALFA6*C19_RR+C19_EY+C19_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C20_Y)/19 ; - C19_RR = C19_RS-C19_PIE(1) ; - C19_RS = C19_PIE(1)+C19_CALFA8*(C19_PIE-C19_PIESTAR)+C19_CALFA9*C19_Y+C19_ERS ; - C20_PIE = C20_CALFA1*C20_PIE(1)+(1-C20_CALFA1)*C20_PIE(-1)+C20_CALFA2*(C20_Y+0.1)+C20_CALFA3*(C20_Y+0.1)^2/2+C20_EPIE ; - C20_Y = C20_CALFA4*C20_Y(1)+C20_CALFA5*C20_Y(-1)+C20_CALFA6*C20_RR+C20_EY+C20_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y)/19 ; - C20_RR = C20_RS-C20_PIE(1) ; - C20_RS = C20_PIE(1)+C20_CALFA8*(C20_PIE-C20_PIESTAR)+C20_CALFA9*C20_Y+C20_ERS ; -end; - -initval; -C10_PIE=2.5; -C10_RR=0; -C10_RS=2.5; -C10_Y=0; -C11_PIE=2.5; -C11_RR=0; -C11_RS=2.5; -C11_Y=0; -C12_PIE=2.5; -C12_RR=0; -C12_RS=2.5; -C12_Y=0; -C13_PIE=2.5; -C13_RR=0; -C13_RS=2.5; -C13_Y=0; -C14_PIE=2.5; -C14_RR=0; -C14_RS=2.5; -C14_Y=0; -C15_PIE=2.5; -C15_RR=0; -C15_RS=2.5; -C15_Y=0; -C16_PIE=2.5; -C16_RR=0; -C16_RS=2.5; -C16_Y=0; -C17_PIE=2.5; -C17_RR=0; -C17_RS=2.5; -C17_Y=0; -C18_PIE=2.5; -C18_RR=0; -C18_RS=2.5; -C18_Y=0; -C19_PIE=2.5; -C19_RR=0; -C19_RS=2.5; -C19_Y=0; -C1_PIE=2.5; -C1_RR=0; -C1_RS=2.5; -C1_Y=0; -C20_PIE=2.5; -C20_RR=0; -C20_RS=2.5; -C20_Y=0; -C2_PIE=2.5; -C2_RR=0; -C2_RS=2.5; -C2_Y=0; -C3_PIE=2.5; -C3_RR=0; -C3_RS=2.5; -C3_Y=0; -C4_PIE=2.5; -C4_RR=0; -C4_RS=2.5; -C4_Y=0; -C5_PIE=2.5; -C5_RR=0; -C5_RS=2.5; -C5_Y=0; -C6_PIE=2.5; -C6_RR=0; -C6_RS=2.5; -C6_Y=0; -C7_PIE=2.5; -C7_RR=0; -C7_RS=2.5; -C7_Y=0; -C8_PIE=2.5; -C8_RR=0; -C8_RS=2.5; -C8_Y=0; -C9_PIE=2.5; -C9_RR=0; -C9_RS=2.5; -C9_Y=0; -C1_EPIE=0; -C1_EY=0; -C1_ERS=0; -C2_EPIE=0; -C2_EY=0; -C2_ERS=0; -C3_EPIE=0; -C3_EY=0; -C3_ERS=0; -C4_EPIE=0; -C4_EY=0; -C4_ERS=0; -C5_EPIE=0; -C5_EY=0; -C5_ERS=0; -C6_EPIE=0; -C6_EY=0; -C6_ERS=0; -C7_EPIE=0; -C7_EY=0; -C7_ERS=0; -C8_EPIE=0; -C8_EY=0; -C8_ERS=0; -C9_EPIE=0; -C9_EY=0; -C9_ERS=0; -C10_EPIE=0; -C10_EY=0; -C10_ERS=0; -C11_EPIE=0; -C11_EY=0; -C11_ERS=0; -C12_EPIE=0; -C12_EY=0; -C12_ERS=0; -C13_EPIE=0; -C13_EY=0; -C13_ERS=0; -C14_EPIE=0; -C14_EY=0; -C14_ERS=0; -C15_EPIE=0; -C15_EY=0; -C15_ERS=0; -C16_EPIE=0; -C16_EY=0; -C16_ERS=0; -C17_EPIE=0; -C17_EY=0; -C17_ERS=0; -C18_EPIE=0; -C18_EY=0; -C18_ERS=0; -C19_EPIE=0; -C19_EY=0; -C19_ERS=0; -C20_EPIE=0; -C20_EY=0; -C20_ERS=0; -end; - -vcov = [ -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -]; - -order = 1; - diff --git a/dynare++/tests/czech2.mod b/dynare++/tests/czech2.mod deleted file mode 100644 index 2e7adeb785fc5b17f19408c2226f34b086cec925..0000000000000000000000000000000000000000 --- a/dynare++/tests/czech2.mod +++ /dev/null @@ -1,712 +0,0 @@ -var PIE4EU ZZ_PIE4EU ZZ_RNOMEU GDPGAPEU ZZ_DRNOMEU AF AH BIGGAMF BIGGAMH BIGGAMIMPF BIGGAMIMPH BIGGAMMF BIGGAMMH BIGGAMNF BIGGAMNH BIGGAMQF BIGGAMQH BIGGAM_MONF BIGGAM_MONH BIGGAM_MOTF BIGGAM_MOTH BIGGAM_O_NF BIGGAM_O_NH BIGGAM_O_TF BIGGAM_O_TH CAPAF CAPAH CF CF_NAT CH CH_NAT CURBALF_RAT CURBALH_RAT DEEF DEEH DEPEX EXPORTSF EXPORTSF_NAT EXPORTSH EXPORTSH_NAT EYEF EYEH GAF GAH GAMMAF GAMMAH GDPF GDPF_NAT GDPGAPF GDPGAPH GDPH GDPH_NAT GF_NAT GH_NAT GNF GNH HF HH IMPORTSF IMPORTSF_NAT IMPORTSH IMPORTSH_NAT KF KH KNF KNF_RAT KNH KNH_RAT KTF KTF_RAT KTH KTH_RAT K_OF K_OF_RAT K_OH K_OH_RAT LANDF LANDH LF LH LNF LNH LTF LTH L_OF L_OH MARGUTF MARGUTH MF MF_NAT MH MH_NAT M_ONF M_ONH M_OTF M_OTH NF NH NNF NNH O_NF O_NH O_TF O_TH PIE4F PIE4H PIE4TARF PIE4TARH PIEBARMF PIEBARMH PIEBARQF PIEBARQH PIEF PIEH PIENF PIENH PIEWF PIEWH PSIF PSIH PSIPRIMEF PSIPRIMEH QF QH Q_ONF Q_ONH Q_OTF Q_OTH REALBF REALBH REALEX REALEXF REALEXH REALFINH REALMCNF REALMCNH REALMCTF REALMCTH REALMONEYF REALMONEYH REALPBARMF REALPBARMH REALPBARQF REALPBARQH REALPLANDF REALPLANDH REALPMF REALPMH REALPNF REALPNH REALPQF REALPQH REALPXF REALPXH REALP_MOF REALP_MOH REALP_ONF REALP_ONH REALP_OTF REALP_OTH REALP_QOF REALP_QOH REALRF REALRH REALTBALF REALTBALH REALWF REALWH RNOMF RNOMH SHOPF SHOPH SHOPPRIMEF SHOPPRIMEH TF TH T_OF T_OH VELOF VELOH VPRIMEF VPRIMEH XF_NAT XH_NAT XI ZBF ZBH ZEYEF ZEYEH ZNF ZNH ZTF ZTH ZUF ZUH ZZ_CF ZZ_CH ZZ_CURBALF_RAT ZZ_CURBALH_RAT ZZ_C_SHARF ZZ_C_SHARH ZZ_DPIE4F ZZ_DPIE4H ZZ_DRNOMF ZZ_DRNOMH ZZ_EXPORTSF ZZ_EXPORTSH ZZ_EYEF ZZ_EYEH ZZ_EYE_SHARF ZZ_EYE_SHARH ZZ_GDPF ZZ_GDPH ZZ_GDP_PPP_RATH ZZ_GF ZZ_GH ZZ_IMPORTSF ZZ_IMPORTSH ZZ_M_ON_SHARF ZZ_M_ON_SHARH ZZ_M_OT_SHARF ZZ_M_OT_SHARH ZZ_M_O_SHARF ZZ_M_O_SHARH ZZ_M_SHARF ZZ_M_SHARH ZZ_N_SHARF ZZ_N_SHARH ZZ_PIE4F ZZ_PIE4H ZZ_REALEX ZZ_RNOMF ZZ_RNOMH ZZ_UTILITYF ZZ_UTILITYH ZZ_XBALF_TOT_RAT ZZ_XBALH_TOT_RAT Z_OF Z_OH PIEH_1 PIEH_2 PIEF_1 PIEF_2 REALBH_1 VALUE VALUE2; - -varexo E_ZBH E_ZUH E_ZUF E_ZEYEH E_ZEYEF E_GAMMAH E_GAMMAF E_LANDH E_LANDF E_GAH E_GAF E_CAPAH E_CAPAF; - -parameters COSTLF COSTLH EPSF EPSH EPSQMF EPSQMH GLAMBDAF GLAMBDAH SIGMAF SIGMAH SSF SSH XR1F XR1H XR2F XR2H XR3F XR3H XR4F XR4H ALPHANF ALPHANH ALPHATF ALPHATH ALPHA_OF ALPHA_OH A_ONEF A_ONEH A_ZEROF A_ZEROH B0F B0H B1F B1H B2F B2H BET CAPAF_SS CAPAH_SS CHI0 CHI1 CHI2 CHI3 COSTF COSTH COST_MONF COST_MONH COST_MOTF COST_MOTH COST_O_NF COST_O_NH COST_O_TF COST_O_TH DELTAF DELTAH EPS_ONF EPS_ONH EPS_OTF EPS_OTH ETAF ETAH E_PIE4TARF E_PIE4TARH E_ZBF GAMA_NF GAMA_NH GAMA_TF GAMA_TH GAMMAF_SS GAMMAH_SS GAMMA_LANDF GAMMA_LANDH GA_RATF GA_RATH GDPF_EXOG GDPH_EXOG GN_RATF GN_RATH LANDF_SS LANDH_SS LILCAPPA1F LILCAPPA1H LILCAPPA2F LILCAPPA2H LILCAPPA3F LILCAPPA3H LILCAPPA4F LILCAPPA4H LILCAPPA5F LILCAPPA5H LILCAPPA6F LILCAPPA6H LILCAPPA7F LILCAPPA7H LILCAPPA8F LILCAPPA8H NYF NYH NY_NF NY_NH NY_TF NY_TH OMEGA0F OMEGA0H OMEGAF OMEGAH PHIF PHIH PIE4TARF_SS PIE4TARH_SS REALEX_EXOG REALPBARMF_EXOG REALPBARMH_EXOG REALPNF_EXOG REALPNH_EXOG REALP_MOF_EXOG REALP_MOH_EXOG RNOM_EXOGF RNOM_EXOGH THETAF THETAH XDUMF XDUMH XIXI_NF XIXI_NH XIXI_OF XIXI_OH XIXI_TF XIXI_TH ZBF_SS ZBH_SS ZEDF ZEDH ZEYEF_SS ZEYEH_SS ZNF_SS ZNH_SS ZTF_SS ZTH_SS ZUF_SS ZUH_SS Z_OF_SS Z_OH_SS; - -COSTLF=5; -COSTLH=5; -EPSF=1.1; -EPSH=1.1; -EPSQMF=4; -EPSQMH=1.1; -GLAMBDAF=0; -GLAMBDAH=0; -SIGMAF=0.333333333333333; -SIGMAH=0.333333333333333; -SSF=0.95; -SSH=0.05; -XR1F=1; -XR1H=1; -XR2F=0; -XR2H=0; -XR3F=0.5; -XR3H=0.5; -XR4F=0; -XR4H=0; -ALPHANF=0.33; -ALPHANH=0.4; -ALPHATF=0.33; -ALPHATH=0.4; -ALPHA_OF=0.2; -ALPHA_OH=0.2; -A_ONEF=0.075; -A_ONEH=0.075; -A_ZEROF=0.011; -A_ZEROH=0.011; -B0F=1; -B0H=1; -B1F=0.95; -B1H=0.95; -B2F=1; -B2H=1; -BET=0.99263753614514; -CAPAF_SS=11; -CAPAH_SS=11; -CHI0=0.05; -CHI1=.1; -CHI2=0; -CHI3=0; -COSTF=5; -COSTH=5; -COST_MONF=5; -COST_MONH=5; -COST_MOTF=5; -COST_MOTH=5; -COST_O_NF=5; -COST_O_NH=5; -COST_O_TF=5; -COST_O_TH=5; -DELTAF=0.025; -DELTAH=0.025; -EPS_ONF=3; -EPS_ONH=3; -EPS_OTF=3; -EPS_OTH=3; -ETAF=0.35; -ETAH=0.2; -E_PIE4TARF=0; -E_PIE4TARH=0; -E_ZBF=0; -GAMA_NF=0.3; -GAMA_NH=0.1; -GAMA_TF=0.3; -GAMA_TH=0.5; -GAMMAF_SS=0.5; -GAMMAH_SS=0.25; -GAMMA_LANDF=0.1; -GAMMA_LANDH=0.1; -GA_RATF=0.05; -GA_RATH=0.05; -GDPF_EXOG=2.41500497257461; -GDPH_EXOG=2.90512477822209; -GN_RATF=0.1; -GN_RATH=0.1; -LANDF_SS=0.1; -LANDH_SS=0.1; -LILCAPPA1F=0; -LILCAPPA1H=0; -LILCAPPA2F=800; -LILCAPPA2H=400; -LILCAPPA3F=0; -LILCAPPA3H=0; -LILCAPPA4F=800; -LILCAPPA4H=400; -LILCAPPA5F=0; -LILCAPPA5H=0; -LILCAPPA6F=800; -LILCAPPA6H=400; -LILCAPPA7F=0; -LILCAPPA7H=0; -LILCAPPA8F=0; -LILCAPPA8H=0; -NYF=0.98; -NYH=0.0499999999999999; -NY_NF=0.98; -NY_NH=0.0499999999999999; -NY_TF=0.98; -NY_TH=0.02; -OMEGA0F=60; -OMEGA0H=60; -OMEGAF=5; -OMEGAH=5; -PHIF=3; -PHIH=3; -PIE4TARF_SS=1.125; -PIE4TARH_SS=1.125; -REALEX_EXOG=1.3734519289908; -REALPBARMF_EXOG=0.87146958398196; -REALPBARMH_EXOG=1.19072687148694; -REALPNF_EXOG=0.840675522925242; -REALPNH_EXOG=0.902486321747893; -REALP_MOF_EXOG=0.966533486000563; -REALP_MOH_EXOG=1.63690883121281; -RNOM_EXOGF=1.00741707177773; -RNOM_EXOGH=1.00741707177773; -THETAF=6; -THETAH=6; -XDUMF=1; -XDUMH=1; -XIXI_NF=0.75; -XIXI_NH=0.75; -XIXI_OF=0.75; -XIXI_OH=0.75; -XIXI_TF=0.75; -XIXI_TH=0.75; -ZBF_SS=0; -ZBH_SS=0; -ZEDF=2.5; -ZEDH=2.5; -ZEYEF_SS=0; -ZEYEH_SS=0; -ZNF_SS=1; -ZNH_SS=1; -ZTF_SS=1; -ZTH_SS=0.6; -ZUF_SS=1; -ZUH_SS=1; -Z_OF_SS=1; -Z_OH_SS=1; - -model; -PIE4EU = SSH*PIE4H+(1-SSH)*PIE4F; -ZZ_PIE4EU = SSH*ZZ_PIE4H+(1-SSH)*ZZ_PIE4F; -ZZ_RNOMEU = SSH*ZZ_RNOMH+(1-SSH)*ZZ_RNOMF; - -ZZ_DRNOMEU = SSH*ZZ_DRNOMH+(1-SSH)*ZZ_DRNOMF; -GDPGAPEU = SSH*GDPGAPH+(1-SSH)*GDPGAPF; - - ZZ_UTILITYH = (ZUH*(CH-HH)^(1-SIGMAH)-1)/(1-SIGMAH)-CAPAH*LH^(1+ZEDH)/(1+ZEDH) ; - ZZ_GH = 100*log(GH_NAT) ; - ZZ_CURBALH_RAT = CURBALH_RAT*100 ; - ZZ_M_SHARH = REALPBARMH*MH/AH ; - ZZ_M_O_SHARH = (REALP_MOH*M_ONH+REALP_MOH*M_OTH)/AH ; - ZZ_M_ON_SHARH = REALP_MOH*M_ONH/AH ; - ZZ_M_OT_SHARH = REALP_MOH*M_OTH/AH ; - ZZ_N_SHARH = NH*REALPNH/AH ; - ZZ_EYE_SHARH = EYEH/GDPH ; - ZZ_C_SHARH = CH/GDPH ; - ZZ_GDPH = 100*log(GDPH_NAT) ; - ZZ_CH = 100*log(CH_NAT) ; - ZZ_EYEH = 100*log(EYEH) ; - ZZ_EXPORTSH = 100*log(EXPORTSH_NAT) ; - ZZ_IMPORTSH = 100*log(IMPORTSH_NAT) ; - ZZ_XBALH_TOT_RAT = 100*(EXPORTSH_NAT-IMPORTSH_NAT)/GDPH_NAT ; - ZZ_PIE4H = 100*(PIE4H-1) ; - ZZ_DPIE4H = ZZ_PIE4H-ZZ_PIE4H(-1) ; - ZZ_RNOMH = 100*(RNOMH^4-1) ; - ZZ_DRNOMH = ZZ_RNOMH-ZZ_RNOMH(-1) ; - 100*(PIE4TARH-1) = 1*100*(PIE4TARH_SS-1)+(1-1)*100*(PIE4TARH(-1)-1)+E_PIE4TARH ; - log(ZUH) = 0.3*log(ZUH_SS)+0.7*log(ZUH(-1))+E_ZUH ; - ZBH = 0.3*ZBH_SS+0.7*ZBH(-1)+E_ZBH ; - log(LANDH) = 0.05*log(LANDH_SS)+0.95*log(LANDH(-1))+E_LANDH ; - log(ZTH) = 0.05*log(ZTH_SS)+0.95*log(ZTH(-1))+E_LANDH ; - log(ZNH) = 0.05*log(ZNH_SS)+0.95*log(ZNH(-1))+E_LANDH ; - log(Z_OH) = 0.05*log(Z_OH_SS)+0.95*log(Z_OH(-1))+E_LANDH ; - ZEYEH = 0.05*ZEYEH_SS+0.95*ZEYEH(-1)+E_ZEYEH ; - CAPAH = 0.05*CAPAH_SS+0.95*CAPAH(-1)+E_CAPAH ; - log(GAMMAH) = 0.05*log(GAMMAH_SS)+0.95*log(GAMMAH(-1))+E_GAMMAH ; - BIGGAM_O_NH = 1-COST_O_NH/2*(O_NH/NH/(O_NH(-1)/NH(-1))-1)^2 ; - BIGGAM_O_TH = 1-COST_O_TH/2*(O_TH/TH/(O_TH(-1)/TH(-1))-1)^2 ; - O_NH = GAMA_NH*NH/ZNH*(REALP_ONH/(REALMCNH*ZNH))^(-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^XIXI_NH/BIGGAM_O_NH ; - O_TH = GAMA_TH*TH/ZTH*(REALP_OTH/(REALMCTH*ZTH))^(-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^XIXI_NH/BIGGAM_O_TH ; - NH = ZNH*((1-ALPHANH-GAMA_NH)^(1/XIXI_NH)*LNH^(1-1/XIXI_NH)+ALPHANH^(1/XIXI_NH)*KNH^(1-1/XIXI_NH)+GAMA_NH^(1/XIXI_NH)*(BIGGAM_O_NH*O_NH)^(1-1/XIXI_NH))^(XIXI_NH/(XIXI_NH-1)) ; - TH = ZTH*((1-ALPHATH-GAMA_TH)^(1/XIXI_TH)*LTH^(1-1/XIXI_TH)+ALPHATH^(1/XIXI_TH)*KTH^(1-1/XIXI_TH)+GAMA_TH^(1/XIXI_TH)*(BIGGAM_O_TH*O_TH)^(1-1/XIXI_TH))^(XIXI_TH/(XIXI_TH-1)) ; - REALMCNH = 1/ZNH*((1-ALPHANH-GAMA_NH)*REALWH^(1-XIXI_NH)+ALPHANH*REALRH^(1-XIXI_NH)+GAMA_NH*REALP_ONH^(1-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^(XIXI_NH-1))^(1/(1-XIXI_NH)) ; - REALMCTH = 1/ZTH*((1-ALPHATH-GAMA_TH)*REALWH^(1-XIXI_TH)+ALPHATH*REALRH^(1-XIXI_TH)+GAMA_TH*REALP_OTH^(1-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^(XIXI_TH-1))^(1/(1-XIXI_TH)) ; - MARGUTH = (CH-B2H*HH)^(-SIGMAH)*ZUH ; - HH = (1-B0H)*HH(-1)+B0H*B1H*CH(-1) ; - VPRIMEH = CAPAH*LH^ZEDH ; - AH^(1-1/EPSH) = GAMMAH^(1/EPSH)*(NYH^(1/EPSQMH)*QH^(1-1/EPSQMH)+(1-NYH)^(1/EPSQMH)*(MH*BIGGAMIMPH)^(1-1/EPSQMH))^(EPSQMH/(EPSQMH-1)*(1-1/EPSH))+(1-GAMMAH)^(1/EPSH)*NNH^(1-1/EPSH) ; - QH = GAMMAH*NYH*REALPQH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH) ; - MH = GAMMAH*(1-NYH)*REALPMH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH)*1/BIGGAMIMPH*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^EPSQMH ; - REALPXH = (NYH*REALPQH^(1-EPSQMH)+(1-NYH)*REALPMH^(1-EPSQMH)*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^(EPSQMH-1))^(1/(1-EPSQMH)) ; - BIGGAMIMPH = 1-COSTH/2*(MH/AH/(MH(-1)/AH(-1))-1)^2 ; - NNH = (1-GAMMAH)*REALPNH^(-EPSH)*AH ; - NH = NNH+ETAH*MH+ETAH*QH+GNH ; - PIENH = REALPNH/REALPNH(-1)*PIEH ; - BIGGAMNH = LILCAPPA3H/2*(PIENH/PIE4TARH^0.25-1)^2+LILCAPPA4H/2*(PIENH/PIENH(-1)-1)^2 ; - -(1-BIGGAMNH)*(REALPNH*(1-THETAH)+THETAH*REALMCNH) = -(REALPNH-REALMCNH)*(LILCAPPA3H*PIENH/PIE4TARH^0.25*(PIENH/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH/PIENH(-1)*(PIENH/PIENH(-1)-1))+DEEH*PIEH(+1)*(REALPNH(+1)-REALMCNH(+1))*NH(+1)/NH*(LILCAPPA3H*PIENH(+1)/PIE4TARH^0.25*(PIENH(+1)/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH(+1)/PIENH*(PIENH(+1)/PIENH-1)) ; - PIEBARQH = PIEH*REALPBARQH/REALPBARQH(-1) ; - BIGGAMQH = LILCAPPA5H/2*(PIEBARQH/PIE4TARH^0.25-1)^2+LILCAPPA6H/2*(PIEBARQH/PIEBARQH(-1)-1)^2 ; - -(1-BIGGAMQH)*REALPBARQH/REALPQH*(REALPBARQH*(1-THETAH)+ETAH*REALPNH+THETAH*REALMCTH) = -(REALPBARQH-REALMCTH)*(LILCAPPA5H*PIEBARQH/PIE4TARH^0.25*(PIEBARQH/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH/PIEBARQH(-1)*(PIEBARQH/PIEBARQH(-1)-1))+DEEH*PIEH(+1)*(REALPBARQH(+1)-REALMCTH(+1))*QH(+1)/QH*(LILCAPPA5H*PIEBARQH(+1)/PIE4TARH^0.25*(PIEBARQH(+1)/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH(+1)/PIEBARQH*(PIEBARQH(+1)/PIEBARQH-1)) ; - REALPQH = REALPBARQH+ETAH*REALPNH ; - KH = KH(-1)*(1-DELTAH)+PSIH(-1)*KH(-1) ; - PSIH = EYEH/KH-OMEGAH/2*(EYEH/KH-DELTAH*(1+ZEYEH))^2-OMEGA0H/2*(EYEH/KH-EYEH(-1)/KH(-1))^2 ; - PSIPRIMEH = 1-OMEGAH*(EYEH/KH-DELTAH*(1+ZEYEH))-OMEGA0H*(EYEH/KH-EYEH(-1)/KH(-1)) ; - 1/PSIPRIMEH = DEEH*PIEH(+1)*(REALRH(+1)+1/PSIPRIMEH(+1)*(1-DELTAH+PSIH(+1)*(1-PSIPRIMEH(+1)*EYEH(+1)/(PSIH(+1)*KH(+1))))) ; - BIGGAMH = LILCAPPA1H/2*(PIEWH/PIE4TARH^0.25-1)^2+LILCAPPA2H/2*(PIEWH/PIEWH(-1)-1)^2 ; - PIEH*REALWH/REALWH(-1) = PIEWH ; - REALWH = PHIH*VPRIMEH/MARGUTH*((PHIH-1)*(1-BIGGAMH)+PIEWH*LILCAPPA1H/PIE4TARH^0.25*(PIEWH/PIE4TARH^0.25-1)+PIEWH/PIEWH(-1)*LILCAPPA2H*(PIEWH/PIEWH(-1)-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA1H*PIEWH(+1)/PIE4TARH^0.25*(PIEWH(+1)/PIE4TARH^0.25-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA2H*PIEWH(+1)/(REALWH/REALWH(-1))*(PIEWH(+1)/PIEWH-1))^(-1) ; - DEEH = BET*MARGUTH(+1)/PIEH(+1)/MARGUTH*(1+SHOPH+SHOPPRIMEH*VELOH)/(1+SHOPH(+1)+SHOPPRIMEH(+1)*VELOH(+1)) ; - SHOPH = A_ZEROH*VELOH+A_ONEH/VELOH-2*(A_ZEROH*A_ONEH)^0.5 ; - SHOPPRIMEH = A_ZEROH-A_ONEH*VELOH^(-2) ; - VELOH = CH/REALMONEYH ; - DEEH = 1-SHOPPRIMEH*VELOH^2 ; - 1 = RNOMH*DEEH ; -/* - 100*(RNOMH^4-1) = (1-XDUMH)*100*(RNOM_EXOGH^4-1)+XDUMH*(XR3H*100*(RNOMH(-1)^4-1)+(1-XR3H)*(100*((1/BET*PIE4H^0.25)^4-1))+XR1H*(100*(PIE4H-1)-100*(PIE4TARH-1))+XR4H*100*(DEPEX^4-1)+XR2H*GDPGAPH) ; -*/ - 100*(RNOMH^4-1) = 100*(RNOMH(-1)^4-1)+1000*100*(DEPEX^4-1); - GDPGAPH = 100*(GDPH_NAT-GDPH_EXOG)/GDPH_EXOG ; - PIE4H = PIEH*PIEH(-1)*PIEH_1(-1)*PIEH_2(-1) ; - AH = CH*(1+SHOPH)+EYEH+GAH ; - GAH = .05*(GA_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG))+.95*GAH(-1)+E_GAH; - GNH = GN_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG)/REALPNH_EXOG ; - PIEBARMH = PIEH*REALPBARMH/REALPBARMH(-1) ; - BIGGAMMH = LILCAPPA7H/2*(PIEBARMH/PIE4TARH^0.25-1)^2+LILCAPPA8H/2*(PIEBARMH/PIEBARMH(-1)-1)^2 ; - REALPMH = REALPBARMH+ETAH*REALPNH ; - KNH_RAT = ALPHANH/(1-ALPHANH-GAMA_NH)*(REALWH/REALRH)^XIXI_NH ; - KTH_RAT = ALPHATH/(1-ALPHATH-GAMA_TH)*(REALWH/REALRH)^XIXI_TH ; - KNH_RAT = KNH/LNH ; - KTH_RAT = KTH/LTH ; - KH = KTH+KNH+K_OH ; - LH = (LNH+LTH+L_OH)*(1-COSTLH/2*(LNH/(LTH+L_OH)/(LNH(-1)/(LTH(-1)+L_OH(-1)))-1)^2) ; - T_OH = Z_OH*((1-ALPHA_OH-GAMMA_LANDH)^(1/XIXI_OH)*L_OH^(1-1/XIXI_OH)+ALPHA_OH^(1/XIXI_OH)*K_OH^(1-1/XIXI_OH)+GAMMA_LANDH^(1/XIXI_OH)*LANDH^(1-1/XIXI_OH))^(XIXI_OH/(XIXI_OH-1)) ; - Q_ONH = NY_NH*(REALP_QOH/REALP_ONH)^(-EPS_ONH)*O_NH ; - Q_OTH = NY_TH*(REALP_QOH/REALP_OTH)^(-EPS_OTH)*O_TH ; - M_ONH = (1-NY_NH)*(REALP_MOH/REALP_ONH)^(-EPS_ONH)*O_NH*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^EPS_ONH/BIGGAM_MONH ; - M_OTH = (1-NY_TH)*(REALP_MOH/REALP_OTH)^(-EPS_OTH)*O_TH*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^EPS_OTH/BIGGAM_MOTH ; - BIGGAM_MONH = 1-COST_MONH/2*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)^2 ; - BIGGAM_MOTH = 1-COST_MOTH/2*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)^2 ; - K_OH_RAT = ALPHA_OH/(1-ALPHA_OH-GAMMA_LANDH)*(REALWH/REALRH)^XIXI_OH ; - K_OH_RAT = K_OH/L_OH ; - REALP_QOH = 1/Z_OH*((1-ALPHA_OH-GAMMA_LANDH)*REALWH^(1-XIXI_OH)+ALPHA_OH*REALRH^(1-XIXI_OH)+GAMMA_LANDH*REALPLANDH^(1-XIXI_OH))^(1/(1-XIXI_OH)) ; - LANDH = GAMMA_LANDH*(REALPLANDH/(REALP_QOH*Z_OH))^(-XIXI_OH)*T_OH/Z_OH ; - REALP_ONH = (NY_NH*REALP_QOH^(1-EPS_ONH)+(1-NY_NH)*REALP_MOH^(1-EPS_ONH)*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^(EPS_ONH-1))^(1/(1-EPS_ONH)) ; - REALP_OTH = (NY_TH*REALP_QOH^(1-EPS_OTH)+(1-NY_TH)*REALP_MOH^(1-EPS_OTH)*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^(EPS_OTH-1))^(1/(1-EPS_OTH)) ; - SSH*TH = SSH*QH+SSF*MF ; - SSH*T_OH = SSH*Q_ONH+SSH*Q_OTH+SSF*M_ONF+SSF*M_OTF ; - REALP_MOH = REALP_QOF*REALEXH ; - ZZ_GDP_PPP_RATH = GDPH/REALEX/GDPF ; - XI = CHI0*(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH_1(-1)/PIEF(-1))/GDPH(-1))^2-1)/(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH_1(-1)/PIEF(-1))/GDPH(-1))^2+1)+ZBH ; - 1 = RNOMF*(1-XI)*DEEH*DEPEX(+1) ; - DEPEX = PIEH/PIEF*REALEX/REALEX(-1) ; - REALFINH = RNOMF(-1)*(1-XI(-1))*REALEX*REALBH(-1)/PIEF ; - SSH*DEEH*PIEH(+1)*REALFINH(+1) = SSH*REALFINH+SSH*RNOMF(-1)*XI(-1)*REALEX*REALBH(-1)/PIEF+REALTBALH ; - REALEXH = REALEX ; - REALEXF = 1/REALEXH ; - ZZ_REALEX = 100*log(REALEX) ; - -(1-BIGGAMMH)*REALPBARMH/REALPMH*(REALPBARMH/REALEX*(1-THETAF)+ETAH*REALPNH/REALEX+THETAF*REALMCTF) = -(REALPBARMH/REALEX-REALMCTF)*(LILCAPPA7H*PIEBARMH/PIE4TARH^0.25*(PIEBARMH/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH/PIEBARMH(-1)*(PIEBARMH/PIEBARMH(-1)-1))+DEEF*PIEF(+1)*(REALPBARMH(+1)/REALEX(+1)-REALMCTF(+1))*MH(+1)/MH*(LILCAPPA7H*PIEBARMH(+1)/PIE4TARH^0.25*(PIEBARMH(+1)/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH(+1)/PIEBARMH*(PIEBARMH(+1)/PIEBARMH-1)) ; - GDPH = AH+REALPNH*GNH+EXPORTSH-IMPORTSH+(RNOMF(-1)-1)*REALEX*REALBH(-1)/PIEF ; - GDPH_NAT = AH+REALPNH_EXOG*GNH+EXPORTSH_NAT-IMPORTSH_NAT ; - CH_NAT = CH*(1+SHOPH) ; - GH_NAT = GAH+REALPNH_EXOG*GNH ; - XH_NAT = SSF/SSH*REALEX_EXOG*REALPBARMF_EXOG*MF ; - MH_NAT = REALPBARMH_EXOG*MH ; - CURBALH_RAT = REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH ; - REALTBALH = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH) ; - EXPORTSH = SSF/SSH*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX ; - IMPORTSH = REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH ; - EXPORTSH_NAT = SSF/SSH*(REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF)*REALEX_EXOG ; - IMPORTSH_NAT = REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH ; - ZZ_UTILITYF = (ZUF*(CF-HF)^(1-SIGMAF)-1)/(1-SIGMAF)-CAPAF*LF^(1+ZEDF)/(1+ZEDF) ; - ZZ_GF = 100*log(GF_NAT) ; - ZZ_CURBALF_RAT = CURBALF_RAT*100 ; - ZZ_M_SHARF = REALPBARMF*MF/AF ; - ZZ_M_O_SHARF = (REALP_MOF*M_ONF+REALP_MOF*M_OTF)/AF ; - ZZ_M_ON_SHARF = REALP_MOF*M_ONF/AF ; - ZZ_M_OT_SHARF = REALP_MOF*M_OTF/AF ; - ZZ_N_SHARF = NF*REALPNF/AF ; - ZZ_EYE_SHARF = EYEF/GDPF ; - ZZ_C_SHARF = CF/GDPF ; - ZZ_GDPF = 100*log(GDPF_NAT) ; - ZZ_CF = 100*log(CF_NAT) ; - ZZ_EYEF = 100*log(EYEF) ; - ZZ_EXPORTSF = 100*log(EXPORTSF_NAT) ; - ZZ_IMPORTSF = 100*log(IMPORTSF_NAT) ; - ZZ_XBALF_TOT_RAT = 100*(EXPORTSF_NAT-IMPORTSF_NAT)/GDPF_NAT ; - ZZ_PIE4F = 100*(PIE4F-1) ; - ZZ_DPIE4F = ZZ_PIE4F-ZZ_PIE4F(-1) ; - ZZ_RNOMF = 100*(RNOMF^4-1) ; - ZZ_DRNOMF = ZZ_RNOMF-ZZ_RNOMF(-1) ; - 100*(PIE4TARF-1) = 1*100*(PIE4TARF_SS-1)+(1-1)*100*(PIE4TARF(-1)-1)+E_PIE4TARF ; - log(ZUF) = 0.3*log(ZUF_SS)+0.7*log(ZUF(-1))+E_ZUF ; - ZBF = 0.3*ZBF_SS+0.7*ZBF(-1)+E_ZBF ; - log(LANDF) = 0.05*log(LANDF_SS)+0.95*log(LANDF(-1))+E_LANDF ; - log(ZTF) = 0.05*log(ZTF_SS)+0.95*log(ZTF(-1))+E_LANDF ; - log(ZNF) = 0.05*log(ZNF_SS)+0.95*log(ZNF(-1))+E_LANDF ; - log(Z_OF) = 0.05*log(Z_OF_SS)+0.95*log(Z_OF(-1))+E_LANDF ; - ZEYEF = 0.05*ZEYEF_SS+0.95*ZEYEF(-1)+E_ZEYEF ; - CAPAF = 0.05*CAPAF_SS+0.95*CAPAF(-1)+E_CAPAF ; - log(GAMMAF) = 0.05*log(GAMMAF_SS)+0.95*log(GAMMAF(-1))+E_GAMMAF ; - BIGGAM_O_NF = 1-COST_O_NF/2*(O_NF/NF/(O_NF(-1)/NF(-1))-1)^2 ; - BIGGAM_O_TF = 1-COST_O_TF/2*(O_TF/TF/(O_TF(-1)/TF(-1))-1)^2 ; - O_NF = GAMA_NF*NF/ZNF*(REALP_ONF/(REALMCNF*ZNF))^(-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^XIXI_NF/BIGGAM_O_NF ; - O_TF = GAMA_TF*TF/ZTF*(REALP_OTF/(REALMCTF*ZTF))^(-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^XIXI_NF/BIGGAM_O_TF ; - NF = ZNF*((1-ALPHANF-GAMA_NF)^(1/XIXI_NF)*LNF^(1-1/XIXI_NF)+ALPHANF^(1/XIXI_NF)*KNF^(1-1/XIXI_NF)+GAMA_NF^(1/XIXI_NF)*(BIGGAM_O_NF*O_NF)^(1-1/XIXI_NF))^(XIXI_NF/(XIXI_NF-1)) ; - TF = ZTF*((1-ALPHATF-GAMA_TF)^(1/XIXI_TF)*LTF^(1-1/XIXI_TF)+ALPHATF^(1/XIXI_TF)*KTF^(1-1/XIXI_TF)+GAMA_TF^(1/XIXI_TF)*(BIGGAM_O_TF*O_TF)^(1-1/XIXI_TF))^(XIXI_TF/(XIXI_TF-1)) ; - REALMCNF = 1/ZNF*((1-ALPHANF-GAMA_NF)*REALWF^(1-XIXI_NF)+ALPHANF*REALRF^(1-XIXI_NF)+GAMA_NF*REALP_ONF^(1-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^(XIXI_NF-1))^(1/(1-XIXI_NF)) ; - REALMCTF = 1/ZTF*((1-ALPHATF-GAMA_TF)*REALWF^(1-XIXI_TF)+ALPHATF*REALRF^(1-XIXI_TF)+GAMA_TF*REALP_OTF^(1-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^(XIXI_TF-1))^(1/(1-XIXI_TF)) ; - MARGUTF = (CF-B2F*HF)^(-SIGMAF)*ZUF ; - HF = (1-B0F)*HF(-1)+B0F*B1F*CF(-1) ; - VPRIMEF = CAPAF*LF^ZEDF ; - AF^(1-1/EPSF) = GAMMAF^(1/EPSF)*(NYF^(1/EPSQMF)*QF^(1-1/EPSQMF)+(1-NYF)^(1/EPSQMF)*(MF*BIGGAMIMPF)^(1-1/EPSQMF))^(EPSQMF/(EPSQMF-1)*(1-1/EPSF))+(1-GAMMAF)^(1/EPSF)*NNF^(1-1/EPSF) ; - QF = GAMMAF*NYF*REALPQF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF) ; - MF = GAMMAF*(1-NYF)*REALPMF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF)*1/BIGGAMIMPF*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^EPSQMF ; - REALPXF = (NYF*REALPQF^(1-EPSQMF)+(1-NYF)*REALPMF^(1-EPSQMF)*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^(EPSQMF-1))^(1/(1-EPSQMF)) ; - BIGGAMIMPF = 1-COSTF/2*(MF/AF/(MF(-1)/AF(-1))-1)^2 ; - NNF = (1-GAMMAF)*REALPNF^(-EPSF)*AF ; - NF = NNF+ETAF*MF+ETAF*QF+GNF ; - PIENF = REALPNF/REALPNF(-1)*PIEF ; - BIGGAMNF = LILCAPPA3F/2*(PIENF/PIE4TARF^0.25-1)^2+LILCAPPA4F/2*(PIENF/PIENF(-1)-1)^2 ; - -(1-BIGGAMNF)*(REALPNF*(1-THETAF)+THETAF*REALMCNF) = -(REALPNF-REALMCNF)*(LILCAPPA3F*PIENF/PIE4TARF^0.25*(PIENF/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF/PIENF(-1)*(PIENF/PIENF(-1)-1))+DEEF*PIEF(+1)*(REALPNF(+1)-REALMCNF(+1))*NF(+1)/NF*(LILCAPPA3F*PIENF(+1)/PIE4TARF^0.25*(PIENF(+1)/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF(+1)/PIENF*(PIENF(+1)/PIENF-1)) ; - PIEBARQF = PIEF*REALPBARQF/REALPBARQF(-1) ; - BIGGAMQF = LILCAPPA5F/2*(PIEBARQF/PIE4TARF^0.25-1)^2+LILCAPPA6F/2*(PIEBARQF/PIEBARQF(-1)-1)^2 ; - -(1-BIGGAMQF)*REALPBARQF/REALPQF*(REALPBARQF*(1-THETAF)+ETAF*REALPNF+THETAF*REALMCTF) = -(REALPBARQF-REALMCTF)*(LILCAPPA5F*PIEBARQF/PIE4TARF^0.25*(PIEBARQF/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF/PIEBARQF(-1)*(PIEBARQF/PIEBARQF(-1)-1))+DEEF*PIEF(+1)*(REALPBARQF(+1)-REALMCTF(+1))*QF(+1)/QF*(LILCAPPA5F*PIEBARQF(+1)/PIE4TARF^0.25*(PIEBARQF(+1)/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF(+1)/PIEBARQF*(PIEBARQF(+1)/PIEBARQF-1)) ; - REALPQF = REALPBARQF+ETAF*REALPNF ; - KF = KF(-1)*(1-DELTAF)+PSIF(-1)*KF(-1) ; - PSIF = EYEF/KF-OMEGAF/2*(EYEF/KF-DELTAF*(1+ZEYEF))^2-OMEGA0F/2*(EYEF/KF-EYEF(-1)/KF(-1))^2 ; - PSIPRIMEF = 1-OMEGAF*(EYEF/KF-DELTAF*(1+ZEYEF))-OMEGA0F*(EYEF/KF-EYEF(-1)/KF(-1)) ; - 1/PSIPRIMEF = DEEF*PIEF(+1)*(REALRF(+1)+1/PSIPRIMEF(+1)*(1-DELTAF+PSIF(+1)*(1-PSIPRIMEF(+1)*EYEF(+1)/(PSIF(+1)*KF(+1))))) ; - BIGGAMF = LILCAPPA1F/2*(PIEWF/PIE4TARF^0.25-1)^2+LILCAPPA2F/2*(PIEWF/PIEWF(-1)-1)^2 ; - PIEF*REALWF/REALWF(-1) = PIEWF ; - REALWF = PHIF*VPRIMEF/MARGUTF*((PHIF-1)*(1-BIGGAMF)+PIEWF*LILCAPPA1F/PIE4TARF^0.25*(PIEWF/PIE4TARF^0.25-1)+PIEWF/PIEWF(-1)*LILCAPPA2F*(PIEWF/PIEWF(-1)-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA1F*PIEWF(+1)/PIE4TARF^0.25*(PIEWF(+1)/PIE4TARF^0.25-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA2F*PIEWF(+1)/(REALWF/REALWF(-1))*(PIEWF(+1)/PIEWF-1))^(-1) ; - DEEF = BET*MARGUTF(+1)/PIEF(+1)/MARGUTF*(1+SHOPF+SHOPPRIMEF*VELOF)/(1+SHOPF(+1)+SHOPPRIMEF(+1)*VELOF(+1)) ; - SHOPF = A_ZEROF*VELOF+A_ONEF/VELOF-2*(A_ZEROF*A_ONEF)^0.5 ; - SHOPPRIMEF = A_ZEROF-A_ONEF*VELOF^(-2) ; - VELOF = CF/REALMONEYF ; - DEEF = 1-SHOPPRIMEF*VELOF^2 ; - 1 = RNOMF*DEEF ; - - 100*(RNOMF^4-1) = (1-XDUMF)*100*(RNOM_EXOGF^4-1) - +XDUMF*(XR3F*100*(RNOMF(-1)^4-1)+ - (1-XR3F)*(100*((1/BET*PIE4EU^0.25)^4-1)) - +XR1F*(100*(PIE4EU-1)-100*(PIE4TARF-1))+XR4F*100*(DEPEX^4-1)+XR2F*GDPGAPEU) ; - - - - GDPGAPF = 100*(GDPF_NAT-GDPF_EXOG)/GDPF_EXOG ; - PIE4F = PIEF*PIEF(-1)*PIEF_1(-1)*PIEF_2(-1) ; - AF = CF*(1+SHOPF)+EYEF+GAF ; - GAF = .05*(GA_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG))+.95*GAF(-1)+E_GAF; - GNF = GN_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG)/REALPNF_EXOG ; - PIEBARMF = PIEF*REALPBARMF/REALPBARMF(-1) ; - BIGGAMMF = LILCAPPA7F/2*(PIEBARMF/PIE4TARF^0.25-1)^2+LILCAPPA8F/2*(PIEBARMF/PIEBARMF(-1)-1)^2 ; - REALPMF = REALPBARMF+ETAF*REALPNF ; - KNF_RAT = ALPHANF/(1-ALPHANF-GAMA_NF)*(REALWF/REALRF)^XIXI_NF ; - KTF_RAT = ALPHATF/(1-ALPHATF-GAMA_TF)*(REALWF/REALRF)^XIXI_TF ; - KNF_RAT = KNF/LNF ; - KTF_RAT = KTF/LTF ; - KF = KTF+KNF+K_OF ; - LF = (LNF+LTF+L_OF)*(1-COSTLF/2*(LNF/(LTF+L_OF)/(LNF(-1)/(LTF(-1)+L_OF(-1)))-1)^2) ; - T_OF = Z_OF*((1-ALPHA_OF-GAMMA_LANDF)^(1/XIXI_OF)*L_OF^(1-1/XIXI_OF)+ALPHA_OF^(1/XIXI_OF)*K_OF^(1-1/XIXI_OF)+GAMMA_LANDF^(1/XIXI_OF)*LANDF^(1-1/XIXI_OF))^(XIXI_OF/(XIXI_OF-1)) ; - Q_ONF = NY_NF*(REALP_QOF/REALP_ONF)^(-EPS_ONF)*O_NF ; - Q_OTF = NY_TF*(REALP_QOF/REALP_OTF)^(-EPS_OTF)*O_TF ; - M_ONF = (1-NY_NF)*(REALP_MOF/REALP_ONF)^(-EPS_ONF)*O_NF*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^EPS_ONF/BIGGAM_MONF ; - M_OTF = (1-NY_TF)*(REALP_MOF/REALP_OTF)^(-EPS_OTF)*O_TF*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^EPS_OTF/BIGGAM_MOTF ; - BIGGAM_MONF = 1-COST_MONF/2*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)^2 ; - BIGGAM_MOTF = 1-COST_MOTF/2*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)^2 ; - K_OF_RAT = ALPHA_OF/(1-ALPHA_OF-GAMMA_LANDF)*(REALWF/REALRF)^XIXI_OF ; - K_OF_RAT = K_OF/L_OF ; - REALP_QOF = 1/Z_OF*((1-ALPHA_OF-GAMMA_LANDF)*REALWF^(1-XIXI_OF)+ALPHA_OF*REALRF^(1-XIXI_OF)+GAMMA_LANDF*REALPLANDF^(1-XIXI_OF))^(1/(1-XIXI_OF)) ; - LANDF = GAMMA_LANDF*(REALPLANDF/(REALP_QOF*Z_OF))^(-XIXI_OF)*T_OF/Z_OF ; - REALP_ONF = (NY_NF*REALP_QOF^(1-EPS_ONF)+(1-NY_NF)*REALP_MOF^(1-EPS_ONF)*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^(EPS_ONF-1))^(1/(1-EPS_ONF)) ; - REALP_OTF = (NY_TF*REALP_QOF^(1-EPS_OTF)+(1-NY_TF)*REALP_MOF^(1-EPS_OTF)*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^(EPS_OTF-1))^(1/(1-EPS_OTF)) ; - SSF*TF = SSF*QF+SSH*MH ; - SSF*T_OF = SSF*Q_ONF+SSF*Q_OTF+SSH*M_ONH+SSH*M_OTH ; - REALP_MOF = REALP_QOH*REALEXF ; - SSH*REALBH+SSF*REALBF = 0 ; - REALTBALF = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - EXPORTSF = SSH/SSF*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - IMPORTSF = REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF ; - EXPORTSF_NAT = SSH/SSF*(REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH)*1/REALEX_EXOG ; - IMPORTSF_NAT = REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF ; - -(1-BIGGAMMF)*REALPBARMF/REALPMF*(REALPBARMF*REALEX*(1-THETAH)+ETAF*REALPNF*REALEX+THETAH*REALMCTH) = -(REALPBARMF*REALEX-REALMCTH)*(LILCAPPA7F*PIEBARMF/PIE4TARF^0.25*(PIEBARMF/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF/PIEBARMF(-1)*(PIEBARMF/PIEBARMF(-1)-1))+DEEH*PIEH(+1)*(REALPBARMF(+1)*REALEX(+1)-REALMCTH(+1))*MF(+1)/MF*(LILCAPPA7F*PIEBARMF(+1)/PIE4TARF^0.25*(PIEBARMF(+1)/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF(+1)/PIEBARMF*(PIEBARMF(+1)/PIEBARMF-1)) ; - GDPF = AF+REALPNF*GNF+EXPORTSF-IMPORTSF+(RNOMF(-1)-1)*REALBF(-1)/PIEF ; - GDPF_NAT = AF+REALPNF_EXOG*GNF+EXPORTSF_NAT-IMPORTSF_NAT ; - CF_NAT = CF*(1+SHOPF) ; - GF_NAT = GAF+REALPNF_EXOG*GNF ; - XF_NAT = SSH/SSF*1/REALEX_EXOG*REALPBARMH_EXOG*MH ; - MF_NAT = REALPBARMF_EXOG*MF ; - CURBALF_RAT = -(REALTBALH/REALEX/SSF/GDPF)+(RNOMF(-1)-1)*REALBF(-1)/PIEF/GDPF ; -PIEH_1 = PIEH(-1); -PIEH_2 = PIEH_1(-1); -PIEF_1 = PIEF(-1); -PIEF_2 = PIEF_1(-1); -REALBH_1 = REALBH(-1); - -VALUE = ZZ_UTILITYH + BET*VALUE(+1); -VALUE2 = ZUH*CH^(1-SIGMAH)/(1-SIGMAH)-CAPAH*LH^(1+ZEDH)/(1+ZEDH) + BET*VALUE2(+1); -end; - -initval; -AF=2.17350447531715; -AH=2.61461230039988; -BIGGAMF=0; -BIGGAMH=0; -BIGGAMIMPF=1; -BIGGAMIMPH=1; -BIGGAMMF=0; -BIGGAMMH=0; -BIGGAMNF=0; -BIGGAMNH=0; -BIGGAMQF=0; -BIGGAMQH=0; -BIGGAM_MONF=1; -BIGGAM_MONH=1; -BIGGAM_MOTF=1; -BIGGAM_MOTH=1; -BIGGAM_O_NF=1; -BIGGAM_O_NH=1; -BIGGAM_O_TF=1; -BIGGAM_O_TH=1; -CAPAF=11; -CAPAH=11; -CF=1.77599320017707; -CF_NAT=1.77797456682707; -CH=2.10139281352027; -CH_NAT=2.10373720855446; -CURBALF_RAT=2.20209042676066e-018; -CURBALH_RAT=0; -DEEF=0.963834712172592; -DEEH=0.963834712172592; -DEPEX=1; -EXPORTSF=0.0374229290542059; -EXPORTSF_NAT=0.0374229290542059; -EXPORTSH=0.976573287861717; -EXPORTSH_NAT=0.976573287861717; -EYEF=0.27477965986135; -EYEH=0.365618852934316; -GAF=0.12075024862873; -GAH=0.145256238911104; -GAMMAF=0.5; -GAMMAH=0.25; -GDPF=2.41500497257461; -GDPF_NAT=2.41500497257461; -GDPGAPF=0; -GDPGAPH=0; -GDPH=2.90512477822209; -GDPH_NAT=2.90512477822209; -GF_NAT=0.362250745886191; -GH_NAT=0.435768716733313; -GNF=0.287269571519256; -GNH=0.321902361090147; -HF=1.68719354016822; -HH=1.99632317284426; -IMPORTSF=0.0374229290542059; -IMPORTSF_NAT=0.0374229290542059; -IMPORTSH=0.976573287861718; -IMPORTSH_NAT=0.976573287861718; -KF=10.991186394454; -KH=14.6247541173726; -KNF=6.33686501417153; -KNF_RAT=22.6981730731029; -KNH=11.034700665508; -KNH_RAT=22.8755992006951; -KTF=2.97137434524903; -KTF_RAT=22.6981730731029; -KTH=2.23720856941572; -KTH_RAT=114.377996003476; -K_OF=1.68294703503345; -K_OF_RAT=7.27127622255245; -K_OH=1.35284488244891; -K_OH_RAT=8.16985685739111; -LANDF=0.1; -LANDH=0.1; -LF=0.64153899810027; -LH=0.667528221502678; -LNF=0.279179517830034; -LNH=0.482378650224502; -LTF=0.130908083909629; -LTH=0.019559781143112; -L_OF=0.231451396360608; -L_OH=0.165589790135064; -MARGUTF=2.24145263303312; -MARGUTH=2.11921125101343; -MF=0.0196445696804563; -MF_NAT=0.0171196449669319; -MH=0.438784845846124; -MH_NAT=0.522472906750236; -M_ONF=0.0143006671963624; -M_ONH=0.134410532365428; -M_OTF=0.00670562423725087; -M_OTH=0.143002828997546; -NF=1.91582345366461; -NH=2.609674642079; -NNF=1.31534385473198; -NNH=2.19524942542191; -O_NF=0.387338325509274; -O_NH=0.147043832240678; -O_TF=0.18162406186278; -O_TH=0.148205762233076; -PIE4F=1.125; -PIE4H=1.125; -PIE4TARF=1.125; -PIE4TARH=1.125; -PIEBARMF=1.02988357195356; -PIEBARMH=1.02988357195356; -PIEBARQF=1.02988357195356; -PIEBARQH=1.02988357195356; -PIEF=1.02988357195356; -PIEF_1=1.02988357195356; -PIEF_2=1.02988357195356; -PIEH=1.02988357195356; -PIEH_1=1.02988357195356; -PIEH_2=1.02988357195356; -PIENF=1.02988357195356; -PIENH=1.02988357195356; -PIEWF=1.02988357195356; -PIEWH=1.02988357195356; -PSIF=0.025; -PSIH=0.025; -PSIPRIMEF=1; -PSIPRIMEH=1; -QF=0.875241222929181; -QH=0.0238294319885835; -Q_ONF=0.373740369418894; -Q_ONH=0.0132636199615755; -Q_OTF=0.175247940896905; -Q_OTH=0.00547180886242481; -REALBF=0; -REALBH=0; -REALBH_1=0; -REALEX=1.3734519289908; -REALEXF=0.728092464608345; -REALEXH=1.3734519289908; -REALFINH=0; -REALMCNF=0.700562935771035; -REALMCNH=0.752071934789911; -REALMCTF=0.700562935771035; -REALMCTH=0.930081384894704; -REALMONEYF=0.558667031035572; -REALMONEYH=0.661026677383566; -REALPBARMF=0.87146958398196; -REALPBARMH=1.19072687148694; -REALPBARQF=0.899522809530009; -REALPBARQH=1.15219711474356; -REALPLANDF=0.554831427212494; -REALPLANDH=0.414697221827051; -REALPMF=1.16570601700579; -REALPMH=1.37122413583652; -REALPNF=0.840675522925242; -REALPNH=0.902486321747893; -REALPQF=1.19375924255384; -REALPQH=1.33269437909314; -REALPXF=1.19317131724075; -REALPXH=1.36926881180313; -REALP_MOF=0.966533486000563; -REALP_MOH=1.63690883121281; -REALP_ONF=1.18566549908199; -REALP_ONH=1.61601524261254; -REALP_OTF=1.18566549908199; -REALP_OTH=1.62845456685201; -REALP_QOF=1.1918209852569; -REALP_QOH=1.32748728078168; -REALRF=0.0324170717777328; -REALRH=0.0324170717777329; -REALTBALF=-6.93889390390723e-018; -REALTBALH=-6.93889390390723e-018; -REALWF=2.42667732699502; -REALWH=2.83454771236558; -RNOMF=1.03752229232945; -RNOMH=1.03752229232945; -SHOPF=0.00111563864647424; -SHOPH=0.00111563864647424; -SHOPPRIMEF=0.00357861859467432; -SHOPPRIMEH=0.00357861859467432; -TF=0.89833516218424; -TH=0.397076255917254; -T_OF=0.563589013545429; -T_OH=0.417854966062653; -VALUE=-2.621110285550203e+02; -VALUE2=2.305114066037580e+02; -VELOF=3.17898336847443; -VELOH=3.17898336847443; -VPRIMEF=3.62618818940983; -VPRIMEH=4.00467026905301; -XF_NAT=0.0200215045456245; -XH_NAT=0.446747178665936; -XI=0; -ZBF=0; -ZBH=0; -ZEYEF=0; -ZEYEH=0; -ZNF=1; -ZNH=1; -ZTF=1; -ZTH=0.6; -ZUF=1; -ZUH=1; -ZZ_CF=57.5474832617676; -ZZ_CH=74.3715386197541; -ZZ_CURBALF_RAT=2.20209042676066e-016; -ZZ_CURBALH_RAT=0; -ZZ_C_SHARF=0.735399396831762; -ZZ_C_SHARH=0.723339950584259; -ZZ_DPIE4F=0; -ZZ_DPIE4H=0; -ZZ_DRNOMF=0; -ZZ_DRNOMH=0; -ZZ_EXPORTSF=-328.547168610049; -ZZ_EXPORTSH=-2.37054799079326; -ZZ_EYEF=-129.17857393452; -ZZ_EYEH=-100.616387362469; -ZZ_EYE_SHARF=0.113780163180538; -ZZ_EYE_SHARH=0.12585306341233; -ZZ_GDPF=88.1701346139521; -ZZ_GDPH=106.647634229781; -ZZ_GDP_PPP_RATH=0.875857186130553; -ZZ_GF=-101.541863874636; -ZZ_GH=-83.0643642588075; -ZZ_IMPORTSF=-328.547168610049; -ZZ_IMPORTSH=-2.37054799079323; -ZZ_M_ON_SHARF=0.0063593490946998; -ZZ_M_ON_SHARH=0.084149297164759; -ZZ_M_OT_SHARF=0.00298191719568198; -ZZ_M_OT_SHARH=0.0895286056899133; -ZZ_M_O_SHARF=0.00934126629038178; -ZZ_M_O_SHARH=0.173677902854672; -ZZ_M_SHARF=0.00787651700806085; -ZZ_M_SHARH=0.19982806118916; -ZZ_N_SHARF=0.741008772713445; -ZZ_N_SHARH=0.90078198910348; -ZZ_PIE4F=12.5; -ZZ_PIE4H=12.5; -ZZ_REALEX=31.7327227026121; -ZZ_RNOMF=15.8749999999999; -ZZ_RNOMH=15.8749999999999; -ZZ_UTILITYF=-1.86610854895021; -ZZ_UTILITYH=-1.9297829736965; -ZZ_XBALF_TOT_RAT=0; -ZZ_XBALH_TOT_RAT=-7.6432037132987e-015; -Z_OF=1; -Z_OH=1; - -E_ZBH=0; - -E_ZUH=0; -E_ZUF=0; - -E_ZEYEH=0; -E_ZEYEF=0; - -E_GAMMAH=0; -E_GAMMAF=0; - -E_LANDH=0; -E_LANDF=0; - -E_GAH = 0; -E_GAF = 0; - -E_CAPAH=0; -E_CAPAF=0; - -ZZ_PIE4EU= 12.5; -ZZ_RNOMEU=15.8749999999999; -GDPGAPEU= 0; -ZZ_DRNOMEU=0; -PIE4EU = 1.125; -end; - -vcov = [ -/* E_ZBH 0.000289 */ - 0.000289 0 0 0 0 0 0 0 0 0 0 0 0; -/* E_ZUH */ -0 0.000016 0 0 0 0 0 0 0 0 0 0 0; -/* E_ZUF */ -0 0 0.000001 0 0 0 0 0 0 0 0 0 0; -/* E_ZEYEH */ -0 0 0 0.0049 0 0 0 0 0 0 0 0 0; -/* E_ZEYEF */ -0 0 0 0 0.000025 0 0 0 0 0 0 0 0; -/* E_GAMMAH */ -0 0 0 0 0 0.0004 0 0 0 0 0 0 0; -/* E_GAMMAF */ -0 0 0 0 0 0 0.000324 0 0 0 0 0 0; -/* E_LANDH */ -0 0 0 0 0 0 0 0.000004 0 0 0 0 0; -/* E_LANDF */ -0 0 0 0 0 0 0 0 0.00000001 0 0 0 0; -/* E_GAH */ -0 0 0 0 0 0 0 0 0 0.00001225 0 0 0; -/* E_GAF */ -0 0 0 0 0 0 0 0 0 0 0.0000005625 0 0; -/* E_CAPAH */ -0 0 0 0 0 0 0 0 0 0 0 0.1 0; -/* E_CAPAF */ -0 0 0 0 0 0 0 0 0 0 0 0 0.0001 -]; - -order = 2; \ No newline at end of file diff --git a/dynare++/tests/dm7.mod b/dynare++/tests/dm7.mod deleted file mode 100644 index 0a31faf4b466af0f07cca1cbaefe6759f46cc103..0000000000000000000000000000000000000000 --- a/dynare++/tests/dm7.mod +++ /dev/null @@ -1,40 +0,0 @@ -var C K r w N tau I; -varexo e; - -parameters alph bet delt thet tau_m rho; -alph = 0.3; -bet = 0.96; -thet = 0.3; -delt = 0.05; -tau_m = 0.35; -rho = 0.8; - -model; -C = C(+1)/(bet*(r(+1)+1-delt)); -I = K(-1)^alph*N^(1-alph)-C; -K = I+(1-delt)*K(-1); -N = 1-(1-thet)*C/(thet*w); -r = (1-tau)*alph*(K(-1)/N)^(alph-1); -w = (1-tau)*(1-alph)*(K(-1)/N)^alph; -tau = (1-rho)*tau_m + rho*tau(-1)+e; -end; - -initval; -C=0.2; -I=0.02; -K=0.5; -N=0.18; -r=0.09; -w=0.6; -tau=0.35; -e=0; -end; - -vcov = [0.007208]; - -order=7; - - - - - diff --git a/dynare++/tests/example1.mod b/dynare++/tests/example1.mod deleted file mode 100644 index ca528c0d9a6aaa7652fcb3fb9dc845c00926374f..0000000000000000000000000000000000000000 --- a/dynare++/tests/example1.mod +++ /dev/null @@ -1,41 +0,0 @@ -// this is an example from the tutorial - -var Y, C, K, A, H, B; - -varexo EPS, NU; - -parameters rho, beta, 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; diff --git a/dynare++/tests/example1_optim.mod b/dynare++/tests/example1_optim.mod deleted file mode 100644 index 0bd57477c7b3dbfb2f36058406daba905729a9d2..0000000000000000000000000000000000000000 --- a/dynare++/tests/example1_optim.mod +++ /dev/null @@ -1,43 +0,0 @@ -// this is a file trying to replicate example1.mod as optimization of a social planner -// it serves also as an example combining +2 lead and optimal policy - -var Y, C, K, A, H, B; - -varexo EPS, NU; - -parameters rho, beta, 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; - -planner_objective log(C)-theta*H^(1+psi)/(1+psi); - -planner_discount beta; - -model; -//Y = exp(A)*K^alpha*H^(1-alpha); -Y = exp(A)*exp(A(+1))*exp(A(+2))*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 = 2; diff --git a/dynare++/tests/gentay1a.mod b/dynare++/tests/gentay1a.mod deleted file mode 100644 index 8c2a9566d6104daba72f1a09268667ff889056c2..0000000000000000000000000000000000000000 --- a/dynare++/tests/gentay1a.mod +++ /dev/null @@ -1,671 +0,0 @@ -var AF AH BIGGAMF BIGGAMH BIGGAMIMPF BIGGAMIMPH BIGGAMMF BIGGAMMH BIGGAMNF BIGGAMNH BIGGAMQF BIGGAMQH BIGGAM_MONF BIGGAM_MONH BIGGAM_MOTF BIGGAM_MOTH BIGGAM_O_NF BIGGAM_O_NH BIGGAM_O_TF BIGGAM_O_TH CAPAF CAPAH CF CF_NAT CH CH_NAT CURBALF_RAT CURBALH_RAT DEEF DEEH DEPEX EXPORTSF EXPORTSF_NAT EXPORTSH EXPORTSH_NAT EYEF EYEH GAF GAH GAMMAF GAMMAH GDPF GDPF_NAT GDPGAPF GDPGAPH GDPH GDPH_NAT GF_NAT GH_NAT GNF GNH HF HH IMPORTSF IMPORTSF_NAT IMPORTSH IMPORTSH_NAT KF KH KNF KNF_RAT KNH KNH_RAT KTF KTF_RAT KTH KTH_RAT K_OF K_OF_RAT K_OH K_OH_RAT LANDF LANDH LF LH LNF LNH LTF LTH L_OF L_OH MARGUTF MARGUTH MF MF_NAT MH MH_NAT M_ONF M_ONH M_OTF M_OTH NF NH NNF NNH O_NF O_NH O_TF O_TH PIE4F PIE4H PIE4TARF PIE4TARH PIEBARMF PIEBARMH PIEBARQF PIEBARQH PIEF PIEH PIENF PIENH PIEWF PIEWH PSIF PSIH PSIPRIMEF PSIPRIMEH QF QH Q_ONF Q_ONH Q_OTF Q_OTH REALBF REALBH REALEX REALEXF REALEXH REALFINH REALMCNF REALMCNH REALMCTF REALMCTH REALMONEYF REALMONEYH REALPBARMF REALPBARMH REALPBARQF REALPBARQH REALPLANDF REALPLANDH REALPMF REALPMH REALPNF REALPNH REALPQF REALPQH REALPXF REALPXH REALP_MOF REALP_MOH REALP_ONF REALP_ONH REALP_OTF REALP_OTH REALP_QOF REALP_QOH REALRF REALRH REALTBALF REALTBALH REALWF REALWH RNOMF RNOMH SHOPF SHOPH SHOPPRIMEF SHOPPRIMEH TF TH T_OF T_OH VELOF VELOH VPRIMEF VPRIMEH XF_NAT XH_NAT XI ZBF ZBH ZEYEF ZEYEH ZNF ZNH ZTF ZTH ZUF ZUH ZZ_CF ZZ_CH ZZ_CURBALF_RAT ZZ_CURBALH_RAT ZZ_C_SHARF ZZ_C_SHARH ZZ_DPIE4F ZZ_DPIE4H ZZ_DRNOMF ZZ_DRNOMH ZZ_EXPORTSF ZZ_EXPORTSH ZZ_EYEF ZZ_EYEH ZZ_EYE_SHARF ZZ_EYE_SHARH ZZ_GDPF ZZ_GDPH ZZ_GDP_PPP_RATH ZZ_GF ZZ_GH ZZ_IMPORTSF ZZ_IMPORTSH ZZ_M_ON_SHARF ZZ_M_ON_SHARH ZZ_M_OT_SHARF ZZ_M_OT_SHARH ZZ_M_O_SHARF ZZ_M_O_SHARH ZZ_M_SHARF ZZ_M_SHARH ZZ_N_SHARF ZZ_N_SHARH ZZ_PIE4F ZZ_PIE4H ZZ_REALEX ZZ_RNOMF ZZ_RNOMH ZZ_UTILITYF ZZ_UTILITYH ZZ_XBALF_TOT_RAT ZZ_XBALH_TOT_RAT Z_OF Z_OH PIEF1 PIEF2 PIEH1 PIEH2 REALBH1; - -varexo E_ZBH E_ZUH E_ZUF E_ZEYEH E_ZEYEF E_GAMMAH E_GAMMAF E_LANDH E_LANDF E_GAH E_GAF E_CAPAH E_CAPAF; - -parameters COSTLF COSTLH EPSF EPSH EPSQMF EPSQMH GLAMBDAF GLAMBDAH SIGMAF SIGMAH SSF SSH XR1F XR1H XR2F XR2H XR3F XR3H XR4F XR4H ALPHANF ALPHANH ALPHATF ALPHATH ALPHA_OF ALPHA_OH A_ONEF A_ONEH A_ZEROF A_ZEROH B0F B0H B1F B1H B2F B2H BET CAPAF_SS CAPAH_SS CHI0 CHI1 CHI2 CHI3 COSTF COSTH COST_MONF COST_MONH COST_MOTF COST_MOTH COST_O_NF COST_O_NH COST_O_TF COST_O_TH DELTAF DELTAH EPS_ONF EPS_ONH EPS_OTF EPS_OTH ETAF ETAH E_PIE4TARF E_PIE4TARH E_ZBF GAMA_NF GAMA_NH GAMA_TF GAMA_TH GAMMAF_SS GAMMAH_SS GAMMA_LANDF GAMMA_LANDH GA_RATF GA_RATH GDPF_EXOG GDPH_EXOG GN_RATF GN_RATH LANDF_SS LANDH_SS LILCAPPA1F LILCAPPA1H LILCAPPA2F LILCAPPA2H LILCAPPA3F LILCAPPA3H LILCAPPA4F LILCAPPA4H LILCAPPA5F LILCAPPA5H LILCAPPA6F LILCAPPA6H LILCAPPA7F LILCAPPA7H LILCAPPA8F LILCAPPA8H NYF NYH NY_NF NY_NH NY_TF NY_TH OMEGA0F OMEGA0H OMEGAF OMEGAH PHIF PHIH PIE4TARF_SS PIE4TARH_SS REALEX_EXOG REALPBARMF_EXOG REALPBARMH_EXOG REALPNF_EXOG REALPNH_EXOG REALP_MOF_EXOG REALP_MOH_EXOG RNOM_EXOGF RNOM_EXOGH THETAF THETAH XDUMF XDUMH XIXI_NF XIXI_NH XIXI_OF XIXI_OH XIXI_TF XIXI_TH ZBF_SS ZBH_SS ZEDF ZEDH ZEYEF_SS ZEYEH_SS ZNF_SS ZNH_SS ZTF_SS ZTH_SS ZUF_SS ZUH_SS Z_OF_SS Z_OH_SS; - -COSTLF=5; -COSTLH=5; -EPSF=1.1; -EPSH=1.1; -EPSQMF=4; -EPSQMH=1.1; -GLAMBDAF=0; -GLAMBDAH=0; -SIGMAF=0.333333333333333; -SIGMAH=0.333333333333333; -SSF=0.95; -SSH=0.05; -XR1F=1; -XR1H=0.40; -XR2F=0; -XR2H=0.1; -XR3F=0.5; -XR3H=0.84; -XR4F=0; -XR4H=0; -ALPHANF=0.33; -ALPHANH=0.4; -ALPHATF=0.33; -ALPHATH=0.4; -ALPHA_OF=0.2; -ALPHA_OH=0.2; -A_ONEF=0.075; -A_ONEH=0.075; -A_ZEROF=0.011; -A_ZEROH=0.011; -B0F=1; -B0H=1; -B1F=0.95; -B1H=0.95; -B2F=1; -B2H=1; -BET=0.99263753614514; -CAPAF_SS=11; -CAPAH_SS=11; -CHI0=0.05; -CHI1=.1; -CHI2=0; -CHI3=0; -COSTF=5; -COSTH=5; -COST_MONF=5; -COST_MONH=5; -COST_MOTF=5; -COST_MOTH=5; -COST_O_NF=5; -COST_O_NH=5; -COST_O_TF=5; -COST_O_TH=5; -DELTAF=0.025; -DELTAH=0.025; -EPS_ONF=3; -EPS_ONH=3; -EPS_OTF=3; -EPS_OTH=3; -ETAF=0.35; -ETAH=0.2; -E_PIE4TARF=0; -E_PIE4TARH=0; -E_ZBF=0; -GAMA_NF=0.3; -GAMA_NH=0.1; -GAMA_TF=0.3; -GAMA_TH=0.5; -GAMMAF_SS=0.5; -GAMMAH_SS=0.25; -GAMMA_LANDF=0.1; -GAMMA_LANDH=0.1; -GA_RATF=0.05; -GA_RATH=0.05; -GDPF_EXOG=2.41500497257461; -GDPH_EXOG=2.90512477822209; -GN_RATF=0.1; -GN_RATH=0.1; -LANDF_SS=0.1; -LANDH_SS=0.1; -LILCAPPA1F=0; -LILCAPPA1H=0; -LILCAPPA2F=800; -LILCAPPA2H=400; -LILCAPPA3F=0; -LILCAPPA3H=0; -LILCAPPA4F=800; -LILCAPPA4H=400; -LILCAPPA5F=0; -LILCAPPA5H=0; -LILCAPPA6F=800; -LILCAPPA6H=400; -LILCAPPA7F=0; -LILCAPPA7H=0; -LILCAPPA8F=0; -LILCAPPA8H=0; -NYF=0.98; -NYH=0.0499999999999999; -NY_NF=0.98; -NY_NH=0.0499999999999999; -NY_TF=0.98; -NY_TH=0.02; -OMEGA0F=60; -OMEGA0H=60; -OMEGAF=5; -OMEGAH=5; -PHIF=3; -PHIH=3; -PIE4TARF_SS=1.125; -PIE4TARH_SS=1.125; -REALEX_EXOG=1.3734519289908; -REALPBARMF_EXOG=0.87146958398196; -REALPBARMH_EXOG=1.19072687148694; -REALPNF_EXOG=0.840675522925242; -REALPNH_EXOG=0.902486321747893; -REALP_MOF_EXOG=0.966533486000563; -REALP_MOH_EXOG=1.63690883121281; -RNOM_EXOGF=1.00741707177773; -RNOM_EXOGH=1.00741707177773; -THETAF=6; -THETAH=6; -XDUMF=1; -XDUMH=1; -XIXI_NF=0.75; -XIXI_NH=0.75; -XIXI_OF=0.75; -XIXI_OH=0.75; -XIXI_TF=0.75; -XIXI_TH=0.75; -ZBF_SS=0; -ZBH_SS=0; -ZEDF=2.5; -ZEDH=2.5; -ZEYEF_SS=0; -ZEYEH_SS=0; -ZNF_SS=1; -ZNH_SS=1; -ZTF_SS=1; -ZTH_SS=0.6; -ZUF_SS=1; -ZUH_SS=1; -Z_OF_SS=1; -Z_OH_SS=1; - -model; - ZZ_UTILITYH = (ZUH*(CH-HH)^(1-SIGMAH)-1)/(1-SIGMAH)-CAPAH*LH^(1+ZEDH)/(1+ZEDH) ; - ZZ_GH = 100*log(GH_NAT) ; - ZZ_CURBALH_RAT = CURBALH_RAT*100 ; - ZZ_M_SHARH = REALPBARMH*MH/AH ; - ZZ_M_O_SHARH = (REALP_MOH*M_ONH+REALP_MOH*M_OTH)/AH ; - ZZ_M_ON_SHARH = REALP_MOH*M_ONH/AH ; - ZZ_M_OT_SHARH = REALP_MOH*M_OTH/AH ; - ZZ_N_SHARH = NH*REALPNH/AH ; - ZZ_EYE_SHARH = EYEH/GDPH ; - ZZ_C_SHARH = CH/GDPH ; - ZZ_GDPH = 100*log(GDPH_NAT) ; - ZZ_CH = 100*log(CH_NAT) ; - ZZ_EYEH = 100*log(EYEH) ; - ZZ_EXPORTSH = 100*log(EXPORTSH_NAT) ; - ZZ_IMPORTSH = 100*log(IMPORTSH_NAT) ; - ZZ_XBALH_TOT_RAT = 100*(EXPORTSH_NAT-IMPORTSH_NAT)/GDPH_NAT ; - ZZ_PIE4H = 100*(PIE4H-1) ; - ZZ_DPIE4H = ZZ_PIE4H-ZZ_PIE4H(-1) ; - ZZ_RNOMH = 100*(RNOMH^4-1) ; - ZZ_DRNOMH = ZZ_RNOMH-ZZ_RNOMH(-1) ; - 100*(PIE4TARH-1) = 1*100*(PIE4TARH_SS-1)+(1-1)*100*(PIE4TARH(-1)-1)+E_PIE4TARH ; - log(ZUH) = 0.3*log(ZUH_SS)+0.7*log(ZUH(-1))+E_ZUH ; - ZBH = 0.3*ZBH_SS+0.7*ZBH(-1)+E_ZBH ; - log(LANDH) = 0.05*log(LANDH_SS)+0.95*log(LANDH(-1))+E_LANDH ; - log(ZTH) = 0.05*log(ZTH_SS)+0.95*log(ZTH(-1))+E_LANDH ; - log(ZNH) = 0.05*log(ZNH_SS)+0.95*log(ZNH(-1))+E_LANDH ; - log(Z_OH) = 0.05*log(Z_OH_SS)+0.95*log(Z_OH(-1))+E_LANDH ; - ZEYEH = 0.05*ZEYEH_SS+0.95*ZEYEH(-1)+E_ZEYEH ; - CAPAH = 0.05*CAPAH_SS+0.95*CAPAH(-1)+E_CAPAH ; - log(GAMMAH) = 0.05*log(GAMMAH_SS)+0.95*log(GAMMAH(-1))+E_GAMMAH ; - BIGGAM_O_NH = 1-COST_O_NH/2*(O_NH/NH/(O_NH(-1)/NH(-1))-1)^2 ; - BIGGAM_O_TH = 1-COST_O_TH/2*(O_TH/TH/(O_TH(-1)/TH(-1))-1)^2 ; - O_NH = GAMA_NH*NH/ZNH*(REALP_ONH/(REALMCNH*ZNH))^(-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^XIXI_NH/BIGGAM_O_NH ; - O_TH = GAMA_TH*TH/ZTH*(REALP_OTH/(REALMCTH*ZTH))^(-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^XIXI_NH/BIGGAM_O_TH ; - NH = ZNH*((1-ALPHANH-GAMA_NH)^(1/XIXI_NH)*LNH^(1-1/XIXI_NH)+ALPHANH^(1/XIXI_NH)*KNH^(1-1/XIXI_NH)+GAMA_NH^(1/XIXI_NH)*(BIGGAM_O_NH*O_NH)^(1-1/XIXI_NH))^(XIXI_NH/(XIXI_NH-1)) ; - TH = ZTH*((1-ALPHATH-GAMA_TH)^(1/XIXI_TH)*LTH^(1-1/XIXI_TH)+ALPHATH^(1/XIXI_TH)*KTH^(1-1/XIXI_TH)+GAMA_TH^(1/XIXI_TH)*(BIGGAM_O_TH*O_TH)^(1-1/XIXI_TH))^(XIXI_TH/(XIXI_TH-1)) ; - REALMCNH = 1/ZNH*((1-ALPHANH-GAMA_NH)*REALWH^(1-XIXI_NH)+ALPHANH*REALRH^(1-XIXI_NH)+GAMA_NH*REALP_ONH^(1-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^(XIXI_NH-1))^(1/(1-XIXI_NH)) ; - REALMCTH = 1/ZTH*((1-ALPHATH-GAMA_TH)*REALWH^(1-XIXI_TH)+ALPHATH*REALRH^(1-XIXI_TH)+GAMA_TH*REALP_OTH^(1-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^(XIXI_TH-1))^(1/(1-XIXI_TH)) ; - MARGUTH = (CH-B2H*HH)^(-SIGMAH)*ZUH ; - HH = (1-B0H)*HH(-1)+B0H*B1H*CH(-1) ; - VPRIMEH = CAPAH*LH^ZEDH ; - AH^(1-1/EPSH) = GAMMAH^(1/EPSH)*(NYH^(1/EPSQMH)*QH^(1-1/EPSQMH)+(1-NYH)^(1/EPSQMH)*(MH*BIGGAMIMPH)^(1-1/EPSQMH))^(EPSQMH/(EPSQMH-1)*(1-1/EPSH))+(1-GAMMAH)^(1/EPSH)*NNH^(1-1/EPSH) ; - QH = GAMMAH*NYH*REALPQH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH) ; - MH = GAMMAH*(1-NYH)*REALPMH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH)*1/BIGGAMIMPH*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^EPSQMH ; - REALPXH = (NYH*REALPQH^(1-EPSQMH)+(1-NYH)*REALPMH^(1-EPSQMH)*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^(EPSQMH-1))^(1/(1-EPSQMH)) ; - BIGGAMIMPH = 1-COSTH/2*(MH/AH/(MH(-1)/AH(-1))-1)^2 ; - NNH = (1-GAMMAH)*REALPNH^(-EPSH)*AH ; - NH = NNH+ETAH*MH+ETAH*QH+GNH ; - PIENH = REALPNH/REALPNH(-1)*PIEH ; - BIGGAMNH = LILCAPPA3H/2*(PIENH/PIE4TARH^0.25-1)^2+LILCAPPA4H/2*(PIENH/PIENH(-1)-1)^2 ; - -(1-BIGGAMNH)*(REALPNH*(1-THETAH)+THETAH*REALMCNH) = -(REALPNH-REALMCNH)*(LILCAPPA3H*PIENH/PIE4TARH^0.25*(PIENH/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH/PIENH(-1)*(PIENH/PIENH(-1)-1))+DEEH*PIEH(+1)*(REALPNH(+1)-REALMCNH(+1))*NH(+1)/NH*(LILCAPPA3H*PIENH(+1)/PIE4TARH^0.25*(PIENH(+1)/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH(+1)/PIENH*(PIENH(+1)/PIENH-1)) ; - PIEBARQH = PIEH*REALPBARQH/REALPBARQH(-1) ; - BIGGAMQH = LILCAPPA5H/2*(PIEBARQH/PIE4TARH^0.25-1)^2+LILCAPPA6H/2*(PIEBARQH/PIEBARQH(-1)-1)^2 ; - -(1-BIGGAMQH)*REALPBARQH/REALPQH*(REALPBARQH*(1-THETAH)+ETAH*REALPNH+THETAH*REALMCTH) = -(REALPBARQH-REALMCTH)*(LILCAPPA5H*PIEBARQH/PIE4TARH^0.25*(PIEBARQH/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH/PIEBARQH(-1)*(PIEBARQH/PIEBARQH(-1)-1))+DEEH*PIEH(+1)*(REALPBARQH(+1)-REALMCTH(+1))*QH(+1)/QH*(LILCAPPA5H*PIEBARQH(+1)/PIE4TARH^0.25*(PIEBARQH(+1)/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH(+1)/PIEBARQH*(PIEBARQH(+1)/PIEBARQH-1)) ; - REALPQH = REALPBARQH+ETAH*REALPNH ; - KH = KH(-1)*(1-DELTAH)+PSIH(-1)*KH(-1) ; - PSIH = EYEH/KH-OMEGAH/2*(EYEH/KH-DELTAH*(1+ZEYEH))^2-OMEGA0H/2*(EYEH/KH-EYEH(-1)/KH(-1))^2 ; - PSIPRIMEH = 1-OMEGAH*(EYEH/KH-DELTAH*(1+ZEYEH))-OMEGA0H*(EYEH/KH-EYEH(-1)/KH(-1)) ; - 1/PSIPRIMEH = DEEH*PIEH(+1)*(REALRH(+1)+1/PSIPRIMEH(+1)*(1-DELTAH+PSIH(+1)*(1-PSIPRIMEH(+1)*EYEH(+1)/(PSIH(+1)*KH(+1))))) ; - BIGGAMH = LILCAPPA1H/2*(PIEWH/PIE4TARH^0.25-1)^2+LILCAPPA2H/2*(PIEWH/PIEWH(-1)-1)^2 ; - PIEH*REALWH/REALWH(-1) = PIEWH ; - REALWH = PHIH*VPRIMEH/MARGUTH*((PHIH-1)*(1-BIGGAMH)+PIEWH*LILCAPPA1H/PIE4TARH^0.25*(PIEWH/PIE4TARH^0.25-1)+PIEWH/PIEWH(-1)*LILCAPPA2H*(PIEWH/PIEWH(-1)-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA1H*PIEWH(+1)/PIE4TARH^0.25*(PIEWH(+1)/PIE4TARH^0.25-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA2H*PIEWH(+1)/(REALWH/REALWH(-1))*(PIEWH(+1)/PIEWH-1))^(-1) ; - DEEH = BET*MARGUTH(+1)/PIEH(+1)/MARGUTH*(1+SHOPH+SHOPPRIMEH*VELOH)/(1+SHOPH(+1)+SHOPPRIMEH(+1)*VELOH(+1)) ; - SHOPH = A_ZEROH*VELOH+A_ONEH/VELOH-2*(A_ZEROH*A_ONEH)^0.5 ; - SHOPPRIMEH = A_ZEROH-A_ONEH*VELOH^(-2) ; - VELOH = CH/REALMONEYH ; - DEEH = 1-SHOPPRIMEH*VELOH^2 ; - 1 = RNOMH*DEEH ; - 100*(RNOMH^4-1) = (1-XDUMH)*100*(RNOM_EXOGH^4-1)+XDUMH*(XR3H*100*(RNOMH(-1)^4-1)+(1-XR3H)*(100*((1/BET*PIE4H^0.25)^4-1))+XR1H*(100*(PIE4H-1)-100*(PIE4TARH-1))+XR4H*100*(DEPEX^4-1)+XR2H*GDPGAPH) ; - GDPGAPH = 100*(GDPH_NAT-GDPH_EXOG)/GDPH_EXOG ; - PIE4H = PIEH*PIEH(-1)*PIEH1(-1)*PIEH2(-1) ; - AH = CH*(1+SHOPH)+EYEH+GAH ; - GAH = .05*(GA_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG))+.95*GAH(-1)+E_GAH; - GNH = GN_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG)/REALPNH_EXOG ; - PIEBARMH = PIEH*REALPBARMH/REALPBARMH(-1) ; - BIGGAMMH = LILCAPPA7H/2*(PIEBARMH/PIE4TARH^0.25-1)^2+LILCAPPA8H/2*(PIEBARMH/PIEBARMH(-1)-1)^2 ; - REALPMH = REALPBARMH+ETAH*REALPNH ; - KNH_RAT = ALPHANH/(1-ALPHANH-GAMA_NH)*(REALWH/REALRH)^XIXI_NH ; - KTH_RAT = ALPHATH/(1-ALPHATH-GAMA_TH)*(REALWH/REALRH)^XIXI_TH ; - KNH_RAT = KNH/LNH ; - KTH_RAT = KTH/LTH ; - KH = KTH+KNH+K_OH ; - LH = (LNH+LTH+L_OH)*(1-COSTLH/2*(LNH/(LTH+L_OH)/(LNH(-1)/(LTH(-1)+L_OH(-1)))-1)^2) ; - T_OH = Z_OH*((1-ALPHA_OH-GAMMA_LANDH)^(1/XIXI_OH)*L_OH^(1-1/XIXI_OH)+ALPHA_OH^(1/XIXI_OH)*K_OH^(1-1/XIXI_OH)+GAMMA_LANDH^(1/XIXI_OH)*LANDH^(1-1/XIXI_OH))^(XIXI_OH/(XIXI_OH-1)) ; - Q_ONH = NY_NH*(REALP_QOH/REALP_ONH)^(-EPS_ONH)*O_NH ; - Q_OTH = NY_TH*(REALP_QOH/REALP_OTH)^(-EPS_OTH)*O_TH ; - M_ONH = (1-NY_NH)*(REALP_MOH/REALP_ONH)^(-EPS_ONH)*O_NH*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^EPS_ONH/BIGGAM_MONH ; - M_OTH = (1-NY_TH)*(REALP_MOH/REALP_OTH)^(-EPS_OTH)*O_TH*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^EPS_OTH/BIGGAM_MOTH ; - BIGGAM_MONH = 1-COST_MONH/2*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)^2 ; - BIGGAM_MOTH = 1-COST_MOTH/2*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)^2 ; - K_OH_RAT = ALPHA_OH/(1-ALPHA_OH-GAMMA_LANDH)*(REALWH/REALRH)^XIXI_OH ; - K_OH_RAT = K_OH/L_OH ; - REALP_QOH = 1/Z_OH*((1-ALPHA_OH-GAMMA_LANDH)*REALWH^(1-XIXI_OH)+ALPHA_OH*REALRH^(1-XIXI_OH)+GAMMA_LANDH*REALPLANDH^(1-XIXI_OH))^(1/(1-XIXI_OH)) ; - LANDH = GAMMA_LANDH*(REALPLANDH/(REALP_QOH*Z_OH))^(-XIXI_OH)*T_OH/Z_OH ; - REALP_ONH = (NY_NH*REALP_QOH^(1-EPS_ONH)+(1-NY_NH)*REALP_MOH^(1-EPS_ONH)*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^(EPS_ONH-1))^(1/(1-EPS_ONH)) ; - REALP_OTH = (NY_TH*REALP_QOH^(1-EPS_OTH)+(1-NY_TH)*REALP_MOH^(1-EPS_OTH)*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^(EPS_OTH-1))^(1/(1-EPS_OTH)) ; - SSH*TH = SSH*QH+SSF*MF ; - SSH*T_OH = SSH*Q_ONH+SSH*Q_OTH+SSF*M_ONF+SSF*M_OTF ; - REALP_MOH = REALP_QOF*REALEXH ; - ZZ_GDP_PPP_RATH = GDPH/REALEX/GDPF ; - XI = CHI0*(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH1(-1)/PIEF(-1))/GDPH(-1))^2-1)/(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH1(-1)/PIEF(-1))/GDPH(-1))^2+1)+ZBH ; - 1 = RNOMF*(1-XI)*DEEH*DEPEX(+1) ; - DEPEX = PIEH/PIEF*REALEX/REALEX(-1) ; - REALFINH = RNOMF(-1)*(1-XI(-1))*REALEX*REALBH(-1)/PIEF ; - SSH*DEEH*PIEH(+1)*REALFINH(+1) = SSH*REALFINH+SSH*RNOMF(-1)*XI(-1)*REALEX*REALBH(-1)/PIEF+REALTBALH ; - REALEXH = REALEX ; - REALEXF = 1/REALEXH ; - ZZ_REALEX = 100*log(REALEX) ; - -(1-BIGGAMMH)*REALPBARMH/REALPMH*(REALPBARMH/REALEX*(1-THETAF)+ETAH*REALPNH/REALEX+THETAF*REALMCTF) = -(REALPBARMH/REALEX-REALMCTF)*(LILCAPPA7H*PIEBARMH/PIE4TARH^0.25*(PIEBARMH/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH/PIEBARMH(-1)*(PIEBARMH/PIEBARMH(-1)-1))+DEEF*PIEF(+1)*(REALPBARMH(+1)/REALEX(+1)-REALMCTF(+1))*MH(+1)/MH*(LILCAPPA7H*PIEBARMH(+1)/PIE4TARH^0.25*(PIEBARMH(+1)/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH(+1)/PIEBARMH*(PIEBARMH(+1)/PIEBARMH-1)) ; - GDPH = AH+REALPNH*GNH+EXPORTSH-IMPORTSH+(RNOMF(-1)-1)*REALEX*REALBH(-1)/PIEF ; - GDPH_NAT = AH+REALPNH_EXOG*GNH+EXPORTSH_NAT-IMPORTSH_NAT ; - CH_NAT = CH*(1+SHOPH) ; - GH_NAT = GAH+REALPNH_EXOG*GNH ; - XH_NAT = SSF/SSH*REALEX_EXOG*REALPBARMF_EXOG*MF ; - MH_NAT = REALPBARMH_EXOG*MH ; - CURBALH_RAT = REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH ; - REALTBALH = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH) ; - EXPORTSH = SSF/SSH*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX ; - IMPORTSH = REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH ; - EXPORTSH_NAT = SSF/SSH*(REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF)*REALEX_EXOG ; - IMPORTSH_NAT = REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH ; - ZZ_UTILITYF = (ZUF*(CF-HF)^(1-SIGMAF)-1)/(1-SIGMAF)-CAPAF*LF^(1+ZEDF)/(1+ZEDF) ; - ZZ_GF = 100*log(GF_NAT) ; - ZZ_CURBALF_RAT = CURBALF_RAT*100 ; - ZZ_M_SHARF = REALPBARMF*MF/AF ; - ZZ_M_O_SHARF = (REALP_MOF*M_ONF+REALP_MOF*M_OTF)/AF ; - ZZ_M_ON_SHARF = REALP_MOF*M_ONF/AF ; - ZZ_M_OT_SHARF = REALP_MOF*M_OTF/AF ; - ZZ_N_SHARF = NF*REALPNF/AF ; - ZZ_EYE_SHARF = EYEF/GDPF ; - ZZ_C_SHARF = CF/GDPF ; - ZZ_GDPF = 100*log(GDPF_NAT) ; - ZZ_CF = 100*log(CF_NAT) ; - ZZ_EYEF = 100*log(EYEF) ; - ZZ_EXPORTSF = 100*log(EXPORTSF_NAT) ; - ZZ_IMPORTSF = 100*log(IMPORTSF_NAT) ; - ZZ_XBALF_TOT_RAT = 100*(EXPORTSF_NAT-IMPORTSF_NAT)/GDPF_NAT ; - ZZ_PIE4F = 100*(PIE4F-1) ; - ZZ_DPIE4F = ZZ_PIE4F-ZZ_PIE4F(-1) ; - ZZ_RNOMF = 100*(RNOMF^4-1) ; - ZZ_DRNOMF = ZZ_RNOMF-ZZ_RNOMF(-1) ; - 100*(PIE4TARF-1) = 1*100*(PIE4TARF_SS-1)+(1-1)*100*(PIE4TARF(-1)-1)+E_PIE4TARF ; - log(ZUF) = 0.3*log(ZUF_SS)+0.7*log(ZUF(-1))+E_ZUF ; - ZBF = 0.3*ZBF_SS+0.7*ZBF(-1)+E_ZBF ; - log(LANDF) = 0.05*log(LANDF_SS)+0.95*log(LANDF(-1))+E_LANDF ; - log(ZTF) = 0.05*log(ZTF_SS)+0.95*log(ZTF(-1))+E_LANDF ; - log(ZNF) = 0.05*log(ZNF_SS)+0.95*log(ZNF(-1))+E_LANDF ; - log(Z_OF) = 0.05*log(Z_OF_SS)+0.95*log(Z_OF(-1))+E_LANDF ; - ZEYEF = 0.05*ZEYEF_SS+0.95*ZEYEF(-1)+E_ZEYEF ; - CAPAF = 0.05*CAPAF_SS+0.95*CAPAF(-1)+E_CAPAF ; - log(GAMMAF) = 0.05*log(GAMMAF_SS)+0.95*log(GAMMAF(-1))+E_GAMMAF ; - BIGGAM_O_NF = 1-COST_O_NF/2*(O_NF/NF/(O_NF(-1)/NF(-1))-1)^2 ; - BIGGAM_O_TF = 1-COST_O_TF/2*(O_TF/TF/(O_TF(-1)/TF(-1))-1)^2 ; - O_NF = GAMA_NF*NF/ZNF*(REALP_ONF/(REALMCNF*ZNF))^(-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^XIXI_NF/BIGGAM_O_NF ; - O_TF = GAMA_TF*TF/ZTF*(REALP_OTF/(REALMCTF*ZTF))^(-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^XIXI_NF/BIGGAM_O_TF ; - NF = ZNF*((1-ALPHANF-GAMA_NF)^(1/XIXI_NF)*LNF^(1-1/XIXI_NF)+ALPHANF^(1/XIXI_NF)*KNF^(1-1/XIXI_NF)+GAMA_NF^(1/XIXI_NF)*(BIGGAM_O_NF*O_NF)^(1-1/XIXI_NF))^(XIXI_NF/(XIXI_NF-1)) ; - TF = ZTF*((1-ALPHATF-GAMA_TF)^(1/XIXI_TF)*LTF^(1-1/XIXI_TF)+ALPHATF^(1/XIXI_TF)*KTF^(1-1/XIXI_TF)+GAMA_TF^(1/XIXI_TF)*(BIGGAM_O_TF*O_TF)^(1-1/XIXI_TF))^(XIXI_TF/(XIXI_TF-1)) ; - REALMCNF = 1/ZNF*((1-ALPHANF-GAMA_NF)*REALWF^(1-XIXI_NF)+ALPHANF*REALRF^(1-XIXI_NF)+GAMA_NF*REALP_ONF^(1-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^(XIXI_NF-1))^(1/(1-XIXI_NF)) ; - REALMCTF = 1/ZTF*((1-ALPHATF-GAMA_TF)*REALWF^(1-XIXI_TF)+ALPHATF*REALRF^(1-XIXI_TF)+GAMA_TF*REALP_OTF^(1-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^(XIXI_TF-1))^(1/(1-XIXI_TF)) ; - MARGUTF = (CF-B2F*HF)^(-SIGMAF)*ZUF ; - HF = (1-B0F)*HF(-1)+B0F*B1F*CF(-1) ; - VPRIMEF = CAPAF*LF^ZEDF ; - AF^(1-1/EPSF) = GAMMAF^(1/EPSF)*(NYF^(1/EPSQMF)*QF^(1-1/EPSQMF)+(1-NYF)^(1/EPSQMF)*(MF*BIGGAMIMPF)^(1-1/EPSQMF))^(EPSQMF/(EPSQMF-1)*(1-1/EPSF))+(1-GAMMAF)^(1/EPSF)*NNF^(1-1/EPSF) ; - QF = GAMMAF*NYF*REALPQF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF) ; - MF = GAMMAF*(1-NYF)*REALPMF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF)*1/BIGGAMIMPF*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^EPSQMF ; - REALPXF = (NYF*REALPQF^(1-EPSQMF)+(1-NYF)*REALPMF^(1-EPSQMF)*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^(EPSQMF-1))^(1/(1-EPSQMF)) ; - BIGGAMIMPF = 1-COSTF/2*(MF/AF/(MF(-1)/AF(-1))-1)^2 ; - NNF = (1-GAMMAF)*REALPNF^(-EPSF)*AF ; - NF = NNF+ETAF*MF+ETAF*QF+GNF ; - PIENF = REALPNF/REALPNF(-1)*PIEF ; - BIGGAMNF = LILCAPPA3F/2*(PIENF/PIE4TARF^0.25-1)^2+LILCAPPA4F/2*(PIENF/PIENF(-1)-1)^2 ; - -(1-BIGGAMNF)*(REALPNF*(1-THETAF)+THETAF*REALMCNF) = -(REALPNF-REALMCNF)*(LILCAPPA3F*PIENF/PIE4TARF^0.25*(PIENF/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF/PIENF(-1)*(PIENF/PIENF(-1)-1))+DEEF*PIEF(+1)*(REALPNF(+1)-REALMCNF(+1))*NF(+1)/NF*(LILCAPPA3F*PIENF(+1)/PIE4TARF^0.25*(PIENF(+1)/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF(+1)/PIENF*(PIENF(+1)/PIENF-1)) ; - PIEBARQF = PIEF*REALPBARQF/REALPBARQF(-1) ; - BIGGAMQF = LILCAPPA5F/2*(PIEBARQF/PIE4TARF^0.25-1)^2+LILCAPPA6F/2*(PIEBARQF/PIEBARQF(-1)-1)^2 ; - -(1-BIGGAMQF)*REALPBARQF/REALPQF*(REALPBARQF*(1-THETAF)+ETAF*REALPNF+THETAF*REALMCTF) = -(REALPBARQF-REALMCTF)*(LILCAPPA5F*PIEBARQF/PIE4TARF^0.25*(PIEBARQF/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF/PIEBARQF(-1)*(PIEBARQF/PIEBARQF(-1)-1))+DEEF*PIEF(+1)*(REALPBARQF(+1)-REALMCTF(+1))*QF(+1)/QF*(LILCAPPA5F*PIEBARQF(+1)/PIE4TARF^0.25*(PIEBARQF(+1)/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF(+1)/PIEBARQF*(PIEBARQF(+1)/PIEBARQF-1)) ; - REALPQF = REALPBARQF+ETAF*REALPNF ; - KF = KF(-1)*(1-DELTAF)+PSIF(-1)*KF(-1) ; - PSIF = EYEF/KF-OMEGAF/2*(EYEF/KF-DELTAF*(1+ZEYEF))^2-OMEGA0F/2*(EYEF/KF-EYEF(-1)/KF(-1))^2 ; - PSIPRIMEF = 1-OMEGAF*(EYEF/KF-DELTAF*(1+ZEYEF))-OMEGA0F*(EYEF/KF-EYEF(-1)/KF(-1)) ; - 1/PSIPRIMEF = DEEF*PIEF(+1)*(REALRF(+1)+1/PSIPRIMEF(+1)*(1-DELTAF+PSIF(+1)*(1-PSIPRIMEF(+1)*EYEF(+1)/(PSIF(+1)*KF(+1))))) ; - BIGGAMF = LILCAPPA1F/2*(PIEWF/PIE4TARF^0.25-1)^2+LILCAPPA2F/2*(PIEWF/PIEWF(-1)-1)^2 ; - PIEF*REALWF/REALWF(-1) = PIEWF ; - REALWF = PHIF*VPRIMEF/MARGUTF*((PHIF-1)*(1-BIGGAMF)+PIEWF*LILCAPPA1F/PIE4TARF^0.25*(PIEWF/PIE4TARF^0.25-1)+PIEWF/PIEWF(-1)*LILCAPPA2F*(PIEWF/PIEWF(-1)-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA1F*PIEWF(+1)/PIE4TARF^0.25*(PIEWF(+1)/PIE4TARF^0.25-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA2F*PIEWF(+1)/(REALWF/REALWF(-1))*(PIEWF(+1)/PIEWF-1))^(-1) ; - DEEF = BET*MARGUTF(+1)/PIEF(+1)/MARGUTF*(1+SHOPF+SHOPPRIMEF*VELOF)/(1+SHOPF(+1)+SHOPPRIMEF(+1)*VELOF(+1)) ; - SHOPF = A_ZEROF*VELOF+A_ONEF/VELOF-2*(A_ZEROF*A_ONEF)^0.5 ; - SHOPPRIMEF = A_ZEROF-A_ONEF*VELOF^(-2) ; - VELOF = CF/REALMONEYF ; - DEEF = 1-SHOPPRIMEF*VELOF^2 ; - 1 = RNOMF*DEEF ; - 100*(RNOMF^4-1) = (1-XDUMF)*100*(RNOM_EXOGF^4-1)+XDUMF*(XR3F*100*(RNOMF(-1)^4-1)+(1-XR3F)*(100*((1/BET*PIE4F^0.25)^4-1)+XR1F*(100*(PIE4F-1)-100*(PIE4TARF-1))+XR4F*100*(DEPEX^4-1)+XR2F*GDPGAPF)) ; - GDPGAPF = 100*(GDPF_NAT-GDPF_EXOG)/GDPF_EXOG ; - PIE4F = PIEF*PIEF(-1)*PIEF1(-1)*PIEF2(-1) ; - AF = CF*(1+SHOPF)+EYEF+GAF ; - GAF = .05*(GA_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG))+.95*GAF(-1)+E_GAF; - GNF = GN_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG)/REALPNF_EXOG ; - PIEBARMF = PIEF*REALPBARMF/REALPBARMF(-1) ; - BIGGAMMF = LILCAPPA7F/2*(PIEBARMF/PIE4TARF^0.25-1)^2+LILCAPPA8F/2*(PIEBARMF/PIEBARMF(-1)-1)^2 ; - REALPMF = REALPBARMF+ETAF*REALPNF ; - KNF_RAT = ALPHANF/(1-ALPHANF-GAMA_NF)*(REALWF/REALRF)^XIXI_NF ; - KTF_RAT = ALPHATF/(1-ALPHATF-GAMA_TF)*(REALWF/REALRF)^XIXI_TF ; - KNF_RAT = KNF/LNF ; - KTF_RAT = KTF/LTF ; - KF = KTF+KNF+K_OF ; - LF = (LNF+LTF+L_OF)*(1-COSTLF/2*(LNF/(LTF+L_OF)/(LNF(-1)/(LTF(-1)+L_OF(-1)))-1)^2) ; - T_OF = Z_OF*((1-ALPHA_OF-GAMMA_LANDF)^(1/XIXI_OF)*L_OF^(1-1/XIXI_OF)+ALPHA_OF^(1/XIXI_OF)*K_OF^(1-1/XIXI_OF)+GAMMA_LANDF^(1/XIXI_OF)*LANDF^(1-1/XIXI_OF))^(XIXI_OF/(XIXI_OF-1)) ; - Q_ONF = NY_NF*(REALP_QOF/REALP_ONF)^(-EPS_ONF)*O_NF ; - Q_OTF = NY_TF*(REALP_QOF/REALP_OTF)^(-EPS_OTF)*O_TF ; - M_ONF = (1-NY_NF)*(REALP_MOF/REALP_ONF)^(-EPS_ONF)*O_NF*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^EPS_ONF/BIGGAM_MONF ; - M_OTF = (1-NY_TF)*(REALP_MOF/REALP_OTF)^(-EPS_OTF)*O_TF*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^EPS_OTF/BIGGAM_MOTF ; - BIGGAM_MONF = 1-COST_MONF/2*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)^2 ; - BIGGAM_MOTF = 1-COST_MOTF/2*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)^2 ; - K_OF_RAT = ALPHA_OF/(1-ALPHA_OF-GAMMA_LANDF)*(REALWF/REALRF)^XIXI_OF ; - K_OF_RAT = K_OF/L_OF ; - REALP_QOF = 1/Z_OF*((1-ALPHA_OF-GAMMA_LANDF)*REALWF^(1-XIXI_OF)+ALPHA_OF*REALRF^(1-XIXI_OF)+GAMMA_LANDF*REALPLANDF^(1-XIXI_OF))^(1/(1-XIXI_OF)) ; - LANDF = GAMMA_LANDF*(REALPLANDF/(REALP_QOF*Z_OF))^(-XIXI_OF)*T_OF/Z_OF ; - REALP_ONF = (NY_NF*REALP_QOF^(1-EPS_ONF)+(1-NY_NF)*REALP_MOF^(1-EPS_ONF)*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^(EPS_ONF-1))^(1/(1-EPS_ONF)) ; - REALP_OTF = (NY_TF*REALP_QOF^(1-EPS_OTF)+(1-NY_TF)*REALP_MOF^(1-EPS_OTF)*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^(EPS_OTF-1))^(1/(1-EPS_OTF)) ; - SSF*TF = SSF*QF+SSH*MH ; - SSF*T_OF = SSF*Q_ONF+SSF*Q_OTF+SSH*M_ONH+SSH*M_OTH ; - REALP_MOF = REALP_QOH*REALEXF ; - SSH*REALBH+SSF*REALBF = 0 ; - REALTBALF = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - EXPORTSF = SSH/SSF*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - IMPORTSF = REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF ; - EXPORTSF_NAT = SSH/SSF*(REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH)*1/REALEX_EXOG ; - IMPORTSF_NAT = REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF ; - -(1-BIGGAMMF)*REALPBARMF/REALPMF*(REALPBARMF*REALEX*(1-THETAH)+ETAF*REALPNF*REALEX+THETAH*REALMCTH) = -(REALPBARMF*REALEX-REALMCTH)*(LILCAPPA7F*PIEBARMF/PIE4TARF^0.25*(PIEBARMF/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF/PIEBARMF(-1)*(PIEBARMF/PIEBARMF(-1)-1))+DEEH*PIEH(+1)*(REALPBARMF(+1)*REALEX(+1)-REALMCTH(+1))*MF(+1)/MF*(LILCAPPA7F*PIEBARMF(+1)/PIE4TARF^0.25*(PIEBARMF(+1)/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF(+1)/PIEBARMF*(PIEBARMF(+1)/PIEBARMF-1)) ; - GDPF = AF+REALPNF*GNF+EXPORTSF-IMPORTSF+(RNOMF(-1)-1)*REALBF(-1)/PIEF ; - GDPF_NAT = AF+REALPNF_EXOG*GNF+EXPORTSF_NAT-IMPORTSF_NAT ; - CF_NAT = CF*(1+SHOPF) ; - GF_NAT = GAF+REALPNF_EXOG*GNF ; - XF_NAT = SSH/SSF*1/REALEX_EXOG*REALPBARMH_EXOG*MH ; - MF_NAT = REALPBARMF_EXOG*MF ; - CURBALF_RAT = -(REALTBALH/REALEX/SSF/GDPF)+(RNOMF(-1)-1)*REALBF(-1)/PIEF/GDPF ; - PIEF1 = PIEF(-1); - PIEF2 = PIEF1(-1); - PIEH1 = PIEH(-1); - PIEH2 = PIEH1(-1); - REALBH1 = REALBH(-1); -end; - -initval; -AF=2.17350447531715; -AH=2.61461230039988; -BIGGAMF=0; -BIGGAMH=0; -BIGGAMIMPF=1; -BIGGAMIMPH=1; -BIGGAMMF=0; -BIGGAMMH=0; -BIGGAMNF=0; -BIGGAMNH=0; -BIGGAMQF=0; -BIGGAMQH=0; -BIGGAM_MONF=1; -BIGGAM_MONH=1; -BIGGAM_MOTF=1; -BIGGAM_MOTH=1; -BIGGAM_O_NF=1; -BIGGAM_O_NH=1; -BIGGAM_O_TF=1; -BIGGAM_O_TH=1; -CAPAF=11; -CAPAH=11; -CF=1.77599320017707; -CF_NAT=1.77797456682707; -CH=2.10139281352027; -CH_NAT=2.10373720855446; -CURBALF_RAT=2.20209042676066e-018; -CURBALH_RAT=0; -DEEF=0.963834712172592; -DEEH=0.963834712172592; -DEPEX=1; -EXPORTSF=0.0374229290542059; -EXPORTSF_NAT=0.0374229290542059; -EXPORTSH=0.976573287861717; -EXPORTSH_NAT=0.976573287861717; -EYEF=0.27477965986135; -EYEH=0.365618852934316; -GAF=0.12075024862873; -GAH=0.145256238911104; -GAMMAF=0.5; -GAMMAH=0.25; -GDPF=2.41500497257461; -GDPF_NAT=2.41500497257461; -GDPGAPF=0; -GDPGAPH=0; -GDPH=2.90512477822209; -GDPH_NAT=2.90512477822209; -GF_NAT=0.362250745886191; -GH_NAT=0.435768716733313; -GNF=0.287269571519256; -GNH=0.321902361090147; -HF=1.68719354016822; -HH=1.99632317284426; -IMPORTSF=0.0374229290542059; -IMPORTSF_NAT=0.0374229290542059; -IMPORTSH=0.976573287861718; -IMPORTSH_NAT=0.976573287861718; -KF=10.991186394454; -KH=14.6247541173726; -KNF=6.33686501417153; -KNF_RAT=22.6981730731029; -KNH=11.034700665508; -KNH_RAT=22.8755992006951; -KTF=2.97137434524903; -KTF_RAT=22.6981730731029; -KTH=2.23720856941572; -KTH_RAT=114.377996003476; -K_OF=1.68294703503345; -K_OF_RAT=7.27127622255245; -K_OH=1.35284488244891; -K_OH_RAT=8.16985685739111; -LANDF=0.1; -LANDH=0.1; -LF=0.64153899810027; -LH=0.667528221502678; -LNF=0.279179517830034; -LNH=0.482378650224502; -LTF=0.130908083909629; -LTH=0.019559781143112; -L_OF=0.231451396360608; -L_OH=0.165589790135064; -MARGUTF=2.24145263303312; -MARGUTH=2.11921125101343; -MF=0.0196445696804563; -MF_NAT=0.0171196449669319; -MH=0.438784845846124; -MH_NAT=0.522472906750236; -M_ONF=0.0143006671963624; -M_ONH=0.134410532365428; -M_OTF=0.00670562423725087; -M_OTH=0.143002828997546; -NF=1.91582345366461; -NH=2.609674642079; -NNF=1.31534385473198; -NNH=2.19524942542191; -O_NF=0.387338325509274; -O_NH=0.147043832240678; -O_TF=0.18162406186278; -O_TH=0.148205762233076; -PIE4F=1.125; -PIE4H=1.125; -PIE4TARF=1.125; -PIE4TARH=1.125; -PIEBARMF=1.02988357195356; -PIEBARMH=1.02988357195356; -PIEBARQF=1.02988357195356; -PIEBARQH=1.02988357195356; -PIEF=1.02988357195356; -PIEF1=1.02988357195356; -PIEF2=1.02988357195356; -PIEH=1.02988357195356; -PIEH1=1.02988357195356; -PIEH2=1.02988357195356; -PIENF=1.02988357195356; -PIENH=1.02988357195356; -PIEWF=1.02988357195356; -PIEWH=1.02988357195356; -PSIF=0.025; -PSIH=0.025; -PSIPRIMEF=1; -PSIPRIMEH=1; -QF=0.875241222929181; -QH=0.0238294319885835; -Q_ONF=0.373740369418894; -Q_ONH=0.0132636199615755; -Q_OTF=0.175247940896905; -Q_OTH=0.00547180886242481; -REALBF=0; -REALBH=0; -REALBH1=0; -REALEX=1.3734519289908; -REALEXF=0.728092464608345; -REALEXH=1.3734519289908; -REALFINH=0; -REALMCNF=0.700562935771035; -REALMCNH=0.752071934789911; -REALMCTF=0.700562935771035; -REALMCTH=0.930081384894704; -REALMONEYF=0.558667031035572; -REALMONEYH=0.661026677383566; -REALPBARMF=0.87146958398196; -REALPBARMH=1.19072687148694; -REALPBARQF=0.899522809530009; -REALPBARQH=1.15219711474356; -REALPLANDF=0.554831427212494; -REALPLANDH=0.414697221827051; -REALPMF=1.16570601700579; -REALPMH=1.37122413583652; -REALPNF=0.840675522925242; -REALPNH=0.902486321747893; -REALPQF=1.19375924255384; -REALPQH=1.33269437909314; -REALPXF=1.19317131724075; -REALPXH=1.36926881180313; -REALP_MOF=0.966533486000563; -REALP_MOH=1.63690883121281; -REALP_ONF=1.18566549908199; -REALP_ONH=1.61601524261254; -REALP_OTF=1.18566549908199; -REALP_OTH=1.62845456685201; -REALP_QOF=1.1918209852569; -REALP_QOH=1.32748728078168; -REALRF=0.0324170717777328; -REALRH=0.0324170717777329; -REALTBALF=-6.93889390390723e-018; -REALTBALH=-6.93889390390723e-018; -REALWF=2.42667732699502; -REALWH=2.83454771236558; -RNOMF=1.03752229232945; -RNOMH=1.03752229232945; -SHOPF=0.00111563864647424; -SHOPH=0.00111563864647424; -SHOPPRIMEF=0.00357861859467432; -SHOPPRIMEH=0.00357861859467432; -TF=0.89833516218424; -TH=0.397076255917254; -T_OF=0.563589013545429; -T_OH=0.417854966062653; -VELOF=3.17898336847443; -VELOH=3.17898336847443; -VPRIMEF=3.62618818940983; -VPRIMEH=4.00467026905301; -XF_NAT=0.0200215045456245; -XH_NAT=0.446747178665936; -XI=0; -ZBF=0; -ZBH=0; -ZEYEF=0; -ZEYEH=0; -ZNF=1; -ZNH=1; -ZTF=1; -ZTH=0.6; -ZUF=1; -ZUH=1; -ZZ_CF=57.5474832617676; -ZZ_CH=74.3715386197541; -ZZ_CURBALF_RAT=2.20209042676066e-016; -ZZ_CURBALH_RAT=0; -ZZ_C_SHARF=0.735399396831762; -ZZ_C_SHARH=0.723339950584259; -ZZ_DPIE4F=0; -ZZ_DPIE4H=0; -ZZ_DRNOMF=0; -ZZ_DRNOMH=0; -ZZ_EXPORTSF=-328.547168610049; -ZZ_EXPORTSH=-2.37054799079326; -ZZ_EYEF=-129.17857393452; -ZZ_EYEH=-100.616387362469; -ZZ_EYE_SHARF=0.113780163180538; -ZZ_EYE_SHARH=0.12585306341233; -ZZ_GDPF=88.1701346139521; -ZZ_GDPH=106.647634229781; -ZZ_GDP_PPP_RATH=0.875857186130553; -ZZ_GF=-101.541863874636; -ZZ_GH=-83.0643642588075; -ZZ_IMPORTSF=-328.547168610049; -ZZ_IMPORTSH=-2.37054799079323; -ZZ_M_ON_SHARF=0.0063593490946998; -ZZ_M_ON_SHARH=0.084149297164759; -ZZ_M_OT_SHARF=0.00298191719568198; -ZZ_M_OT_SHARH=0.0895286056899133; -ZZ_M_O_SHARF=0.00934126629038178; -ZZ_M_O_SHARH=0.173677902854672; -ZZ_M_SHARF=0.00787651700806085; -ZZ_M_SHARH=0.19982806118916; -ZZ_N_SHARF=0.741008772713445; -ZZ_N_SHARH=0.90078198910348; -ZZ_PIE4F=12.5; -ZZ_PIE4H=12.5; -ZZ_REALEX=31.7327227026121; -ZZ_RNOMF=15.8749999999999; -ZZ_RNOMH=15.8749999999999; -ZZ_UTILITYF=-1.86610854895021; -ZZ_UTILITYH=-1.9297829736965; -ZZ_XBALF_TOT_RAT=0; -ZZ_XBALH_TOT_RAT=-7.6432037132987e-015; -Z_OF=1; -Z_OH=1; - -E_ZBH=0; - -E_ZUH=0; -E_ZUF=0; - -E_ZEYEH=0; -E_ZEYEF=0; - -E_GAMMAH=0; -E_GAMMAF=0; - -E_LANDH=0; -E_LANDF=0; - -E_GAH = 0; -E_GAF = 0; - -E_CAPAH=0; -E_CAPAF=0; -end; - -vcov = [ -0.000324 0 0 0 0 0 0 0 0 0 0 0 0; -0 0.0004 0 0 0 0 0 0 0 0 0 0 0; -0 0 0.00000001 0 0 0 0 0 0 0 0 0 0; -0 0 0 0.000004 0 0 0 0 0 0 0 0 0; -0 0 0 0 0.000289 0 0 0 0 0 0 0 0; -0 0 0 0 0 0.000025 0 0 0 0 0 0 0; -0 0 0 0 0 0 0.0049 0 0 0 0 0 0; -0 0 0 0 0 0 0 0.000001 0 0 0 0 0; -0 0 0 0 0 0 0 0 0.000016 0 0 0 0; -0 0 0 0 0 0 0 0 0 0.00001225 0 0 0; -0 0 0 0 0 0 0 0 0 0 0.0000005625 0 0; -0 0 0 0 0 0 0 0 0 0 0 0.01 0; -0 0 0 0 0 0 0 0 0 0 0 0 0.0001 -]; - -order=2; \ No newline at end of file diff --git a/dynare++/tests/judd.mod b/dynare++/tests/judd.mod deleted file mode 100644 index 7acfb1218c13241bc31235bd23956faa1e940b9f..0000000000000000000000000000000000000000 --- a/dynare++/tests/judd.mod +++ /dev/null @@ -1,50 +0,0 @@ -var C K1 K2 L S1 S2 THETA V V1 V2; - -varexo KSI; - -parameters theta_ss lambda delta1 delta2 alpha1 alpha2 eta beta gamma depr1 depr2; - -theta_ss=1; -lambda=0.8; -delta1=0.1; -delta2=0.05; -alpha1=0.3; -alpha2=0.15; -eta=3; -beta=0.95; -gamma=0.5; -depr1=0.1; -depr2=0.05; - -model; -C = THETA*K1^alpha1*K2^alpha2*L^(1-alpha1-alpha2)-S1*K1-S2*K2; -K1 = (1-depr1+(1-0.5*delta1*S1)*S1)*K1(-1); -K2 = (1-depr2+(1-0.5*delta2*S2)*S2)*K2(-1); -THETA = THETA(-1)^lambda*theta_ss^(1-lambda)*exp(KSI); -/* -THETA = THETA(-1)*lambda+theta_ss*(1-lambda)+KSI; -*/ -C^(-gamma)*THETA*K1^alpha1*K2^alpha2*L^(-alpha1-alpha2)*(1-alpha1-alpha2) = L^eta; -C^(-gamma) = beta*V1(+1)*(1-delta1*S1); -C^(-gamma) = beta*V2(+1)*(1-delta2*S2); -V1 = C^(-gamma)*(alpha1*THETA*K1^(alpha1-1)*K2^alpha2*L^(1-alpha1-alpha2)-S1)+beta*V1(+1)*(1-depr1+(1-0.5*delta1*S1)*S1); -V2 = C^(-gamma)*(alpha2*THETA*K1^alpha1*K2^(alpha2-1)*L^(1-alpha1-alpha2)-S2)+beta*V2(+1)*(1-depr2+(1-0.5*delta2*S2)*S2); -V = (C^(1-gamma)/(1-gamma)-L^(1+eta)/(1+eta)) + beta*V(+1); -end; - -initval; -C= 1.33341818203972; -K1= 3.80023995548668; -K2= 3.80023995563911; -L= 0.85120255261552; -S1= 0; -S2= 0; -THETA= 1.00000000000000; -V1= 0.59202988402399; -V2= 0.59202988402399; -V= -17.6239; -end; - -vcov = [ 0.001 ]; - -order = 6; diff --git a/dynare++/tests/judd_norm.mod b/dynare++/tests/judd_norm.mod deleted file mode 100644 index 30a74af3e6c4a8c2ae99c24d89cc2c99a5d83cc3..0000000000000000000000000000000000000000 --- a/dynare++/tests/judd_norm.mod +++ /dev/null @@ -1,50 +0,0 @@ -var C K1 K2 L S1 S2 THETA V V1 V2; - -varexo KSI; - -parameters theta_ss lambda delta1 delta2 alpha1 alpha2 eta beta gamma depr1 depr2; - -theta_ss=1; -lambda=0.5; -delta1=0.05; -delta2=0.2; -alpha1=0.3; -alpha2=0.3; -eta=3; -beta=0.95; -gamma=0.5; -depr1=0.1; -depr2=0.05; - -model; -1 = (THETA*K1^alpha1*K2^alpha2*L^(1-alpha1-alpha2)-S1*K1-S2*K2)/C; -1 = (1-depr1+(1-0.5*delta1*S1)*S1)*K1(-1)/K1; -1 = (1-depr2+(1-0.5*delta2*S2)*S2)*K2(-1)/K2; -1 = THETA(-1)^lambda/THETA*theta_ss^(1-lambda)*exp(KSI); -/* -1 = (THETA(-1)*lambda+theta_ss*(1-lambda)+KSI)/THETA; -*/ -C^(-gamma)*THETA*K1^alpha1*K2^alpha2*L^(-alpha1-alpha2)*(1-alpha1-alpha2)*L^(-eta)=1; -1 = beta*V1(+1)*(1-delta1*S1)*C^gamma; -1 = beta*V2(+1)*(1-delta2*S2)*C^gamma; -1 = (C^(-gamma)*(alpha1*THETA*K1^(alpha1-1)*K2^alpha2*L^(1-alpha1-alpha2)-S1)+beta*V1(+1)*(1-depr1+(1-0.5*delta1*S1)*S1))/V1; -1 = (C^(-gamma)*(alpha2*THETA*K1^alpha1*K2^(alpha2-1)*L^(1-alpha1-alpha2)-S2)+beta*V2(+1)*(1-depr2+(1-0.5*delta2*S2)*S2))/V2; -1 = (C^(1-gamma)/(1-gamma)-L^(1+eta)/(1+eta) + beta*V(+1))/V; -end; - -initval; -C =1.0997055 ; -L =0.9425540 ; -S1 =0.1005051 ; -S2 =0.0500627 ; -K1 =2.9378521 ; -K2 =2.1952681 ; -THETA =1. ; -V =38.000392 ; -V1 =1.0139701 ; -V2 =1.0062981 ; -end; - -vcov = [ 0.05 ]; - -order = 5; diff --git a/dynare++/tests/kp1980_1.mod b/dynare++/tests/kp1980_1.mod deleted file mode 100644 index 8083544a1b34753dcc8bdf69c9699c29d522a769..0000000000000000000000000000000000000000 --- a/dynare++/tests/kp1980_1.mod +++ /dev/null @@ -1,41 +0,0 @@ -// Model from Kydland & Prescott JEDC 1980 - -// case 1: optimal policy, in fact, optimal control - -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; - -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; - -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -end; - -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/alpha)^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -end; - -order = 4; - -vcov = [ - 0.01 -]; diff --git a/dynare++/tests/kp1980_2.mod b/dynare++/tests/kp1980_2.mod deleted file mode 100644 index 6d9d58f73396f30744ea9dde4d043195a0ae84c9..0000000000000000000000000000000000000000 --- a/dynare++/tests/kp1980_2.mod +++ /dev/null @@ -1,42 +0,0 @@ -// Model from Kydland & Prescott JEDC 1980 - -// case 2: time inconsistent optimal policy with different policy and consumer objectives - -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; - -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; - -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -C^(-eta) = beta*C(+1)^(-eta)*(1-delta+exp(Z(+1))*alpha*K(+1)^(alpha-1)*(1-alpha*TAU(+1))); -end; - -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/(alpha*(1-alpha*TAU)))^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -end; - -order = 4; - -vcov = [ - 0.01 -]; diff --git a/dynare++/tests/kp1980_3.mod b/dynare++/tests/kp1980_3.mod deleted file mode 100644 index 9bb36f12680c72698c289166966747c8dde9a43f..0000000000000000000000000000000000000000 --- a/dynare++/tests/kp1980_3.mod +++ /dev/null @@ -1,42 +0,0 @@ -// Model from Kydland & Prescott JEDC 1980 - -// case 3: optimal policy with consistent objective (equivalent to kp1980_1.dyn) - -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; - -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; - -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -C^(-eta) = beta*C(+1)^(-eta)*(1-delta+exp(Z(+1))*alpha*K(+1)^(alpha-1)*(1-alpha*TAU(+1))) + beta*a*G(+1)^(-phi)*TAU(+1)*exp(Z(+1))*alpha^2*K(+1)^(alpha-1); -end; - -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/alpha)^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -end; - -order = 4; - -vcov = [ - 0.01 -]; diff --git a/dynare++/tests/lucas78.mod b/dynare++/tests/lucas78.mod deleted file mode 100644 index c4c1a8ae1836db2bbeaed62a50ff76ac9c67dbaf..0000000000000000000000000000000000000000 --- a/dynare++/tests/lucas78.mod +++ /dev/null @@ -1,26 +0,0 @@ -var Y P; - -varexo EXO_Y; - -parameters beta gamma rho y_ss; - -beta = 0.95; -gamma= 0.5; -rho = 0.9; -y_ss = 2; - -model; -Y-y_ss = rho*(Y(-1)-y_ss) + EXO_Y; -Y^(-gamma)*P = beta*Y(+1)^(-gamma)*(P(+1) + Y(+1)); -end; - -initval; -Y = 2; -P = 38; -end; - -vcov = [ -10 -]; - -order = 7; diff --git a/dynare++/tests/m_0_3_0_0_0_0_0_0.mod b/dynare++/tests/m_0_3_0_0_0_0_0_0.mod deleted file mode 100644 index 1d7c522b441eceb1bc99c7aa561dc7645488287e..0000000000000000000000000000000000000000 --- a/dynare++/tests/m_0_3_0_0_0_0_0_0.mod +++ /dev/null @@ -1,47 +0,0 @@ -var lambda a1 a2 k1 k2 i1 i2 c1 c2 l1 l2; -varexo e e1 e2; -parameters beta delta rho sigma phi AA alpha gamma mu chi b Le tau; -beta = 0.99; -delta = 0.025; -rho = 0.95; -sigma = 0.001; -phi = 0.5; -alpha = 0.36; -AA = 0.028058361; -tau = 6.36522e-11; -gamma = 0.25; -mu = -0.2; -chi = 0.83; -b = 2.16872693993; -Le = 2.5; - -model; -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -lambda = tau*c1^(-1/chi)*(c1^(1-1/chi)+b*(Le-l1)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1); -lambda = tau*c2^(-1/chi)*(c2^(1-1/chi)+b*(Le-l2)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1); -tau*(-b)*(Le-l1)^(-1/chi)*(c1^(1-1/chi)+b*(Le-l1)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1) = -lambda*a1*AA*(1-alpha)*l1^(mu-1)*(alpha*k1(-1)^mu+(1-alpha)*l1^mu)^(1/mu-1); -tau*(-b)*(Le-l2)^(-1/chi)*(c2^(1-1/chi)+b*(Le-l2)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1) = -lambda*a2*AA*(1-alpha)*l2^(mu-1)*(alpha*k2(-1)^mu+(1-alpha)*l2^mu)^(1/mu-1); -lambda*(1+phi*(i1/k1(-1)-delta)) =beta*lambda(+1)*(1+a1(+1)*AA*alpha*k1^(mu-1)*(alpha*k1^mu+(1-alpha)*l1(+1)^mu)^(1/mu-1)+phi*(1-delta+i1(+1)/k1-0.5*(i1(+1)/k1-delta))*(i1(+1)/k1-delta)); -lambda*(1+phi*(i2/k2(-1)-delta)) =beta*lambda(+1)*(1+a2(+1)*AA*alpha*k2^(mu-1)*(alpha*k2^mu+(1-alpha)*l2(+1)^mu)^(1/mu-1)+phi*(1-delta+i2(+1)/k2-0.5*(i2(+1)/k2-delta))*(i2(+1)/k2-delta)); -k1 = i1 + (1-delta)*k1(-1); -k2 = i2 + (1-delta)*k2(-1); -c1+i1-delta*k1(-1) + c2+i2-delta*k2(-1) = a1*AA*(alpha*k1(-1)^mu+(1-alpha)*l1^mu)^(1/mu)-(phi/2)*k1(-1)*(i1/k1(-1)-delta)^2 + a2*AA*(alpha*k2(-1)^mu+(1-alpha)*l2^mu)^(1/mu)-(phi/2)*k2(-1)*(i2/k2(-1)-delta)^2; -end; -initval; -a1 = 1; -a2 = 1; -k1 = 1; -k2 = 1; -c1 = 0.028058361; -c2 = 0.028058361; -i1 = 0.025; -i2 = 0.025; -l1 = 1; -l2 = 1; -lambda = 1; -end; - -vcov = [1 0 0; 0 1 0; 0 0 1]; - -order = 4; \ No newline at end of file diff --git a/dynare++/tests/m_1_3_0_0_0_0_0_0.mod b/dynare++/tests/m_1_3_0_0_0_0_0_0.mod deleted file mode 100644 index a95e8137d9c3ef1d0e7d6665a2ec1c9b6af4efa6..0000000000000000000000000000000000000000 --- a/dynare++/tests/m_1_3_0_0_0_0_0_0.mod +++ /dev/null @@ -1,53 +0,0 @@ -var lambda a1 a2 k1 k2 i1 i2 c1 c2 l1 l2; -varexo e e1 e2; -parameters beta delta rho sigma phi AA alpha Le gamma1 gamma2 mu1 mu2 chi1 chi2 b1 b2 tau1 tau2; -beta = 0.99; -delta = 0.025; -rho = 0.95; -sigma = 0.01; -phi = 0.5; -alpha = 0.36; -AA = 0.028058361; -tau1 = 1.0604611e-11; -tau2 = 2.9305887e-08; -Le = 2.5; -gamma1 = 0.2; -gamma2 = 0.4; -chi1 = 0.75; -chi2 = 0.9; -mu1 = -0.3; -mu2 = 0.3; -b1 = 3.6164368; -b2 = 1.4937381; - -model; -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -lambda = tau1*c1^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1); -lambda = tau2*c2^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1); -tau1*(-b1)*(Le-l1)^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1) = -lambda*a1*AA*(1-alpha)*l1^(mu1-1)*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1-1); -tau2*(-b2)*(Le-l2)^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1) = -lambda*a2*AA*(1-alpha)*l2^(mu2-1)*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2-1); -lambda*(1+phi*(i1/k1(-1)-delta)) =beta*lambda(+1)*(1+a1(+1)*AA*alpha*k1^(mu1-1)*(alpha*k1^mu1+(1-alpha)*l1(+1)^mu1)^(1/mu1-1)+phi*(1-delta+i1(+1)/k1-0.5*(i1(+1)/k1-delta))*(i1(+1)/k1-delta)); -lambda*(1+phi*(i2/k2(-1)-delta)) =beta*lambda(+1)*(1+a2(+1)*AA*alpha*k2^(mu2-1)*(alpha*k2^mu2+(1-alpha)*l2(+1)^mu2)^(1/mu2-1)+phi*(1-delta+i2(+1)/k2-0.5*(i2(+1)/k2-delta))*(i2(+1)/k2-delta)); -k1 = i1 + (1-delta)*k1(-1); -k2 = i2 + (1-delta)*k2(-1); -c1+i1-delta*k1(-1) + c2+i2-delta*k2(-1) = a1*AA*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1)-(phi/2)*k1(-1)*(i1/k1(-1)-delta)^2 + a2*AA*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2)-(phi/2)*k2(-1)*(i2/k2(-1)-delta)^2; -end; - -initval; -a1 = 1; -a2 = 1; -k1 = 1; -k2 = 1; -c1 = 0.028058361; -c2 = 0.028058361; -i1 = 0.025; -i2 = 0.025; -l1 = 1; -l2 = 1; -lambda = 1; -end; - -vcov = [1 0 0; 0 1 0; 0 0 1]; - -order = 4; diff --git a/dynare++/tests/m_1_3_0_0_0_0_0_1.mod b/dynare++/tests/m_1_3_0_0_0_0_0_1.mod deleted file mode 100644 index 05e29ffd81f6b96b239692f63fa69323e1361d95..0000000000000000000000000000000000000000 --- a/dynare++/tests/m_1_3_0_0_0_0_0_1.mod +++ /dev/null @@ -1,82 +0,0 @@ -var lambda a1 a2 a3 a4 k1 k2 k3 k4 i1 i2 i3 i4 c1 c2 c3 c4 l1 l2 l3 l4; -varexo e e1 e2 e3 e4; -parameters beta delta rho sigma phi AA alpha Le gamma1 gamma2 gamma3 gamma4 mu1 mu2 mu3 mu4 chi1 chi2 chi3 chi4 b1 b2 b3 b4 tau1 tau2 tau3 tau4; -beta = 0.99; -delta = 0.025; -rho = 0.95; -sigma = 0.001; -phi = 0.5; -alpha = 0.36; -AA = 0.028058361; -tau1 = 1.0604611e-11; -tau2 = 1.8099765e-09; -tau3 = 2.1096359e-08; -tau4 = 2.9305887e-08; -Le = 2.5; -gamma1 = 0.2; -gamma2 = 0.266666666667; -gamma3 = 0.333333333333; -gamma4 = 0.4; -chi1 = 0.75; -chi2 = 0.8; -chi3 = 0.85; -chi4 = 0.9; -mu1 = -0.3; -mu2 = -0.1; -mu3 = 0.1; -mu4 = 0.3; -b1 = 3.6164368; -b2 = 2.5958433; -b3 = 1.9373921; -b4 = 1.4937381; - -model; -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -log(a3) = rho*log(a3(-1))+sigma*(e+e3); -log(a4) = rho*log(a4(-1))+sigma*(e+e4); -lambda = tau1*c1^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1); -lambda = tau2*c2^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1); -lambda = tau3*c3^(-1/chi3)*(c3^(1-1/chi3)+b3*(Le-l3)^(1-1/chi3))^((1-1/gamma3)/(1-1/chi3)-1); -lambda = tau4*c4^(-1/chi4)*(c4^(1-1/chi4)+b4*(Le-l4)^(1-1/chi4))^((1-1/gamma4)/(1-1/chi4)-1); -tau1*(-b1)*(Le-l1)^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1) = -lambda*a1*AA*(1-alpha)*l1^(mu1-1)*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1-1); -tau2*(-b2)*(Le-l2)^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1) = -lambda*a2*AA*(1-alpha)*l2^(mu2-1)*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2-1); -tau3*(-b3)*(Le-l3)^(-1/chi3)*(c3^(1-1/chi3)+b3*(Le-l3)^(1-1/chi3))^((1-1/gamma3)/(1-1/chi3)-1) = -lambda*a3*AA*(1-alpha)*l3^(mu3-1)*(alpha*k3(-1)^mu3+(1-alpha)*l3^mu3)^(1/mu3-1); -tau4*(-b4)*(Le-l4)^(-1/chi4)*(c4^(1-1/chi4)+b4*(Le-l4)^(1-1/chi4))^((1-1/gamma4)/(1-1/chi4)-1) = -lambda*a4*AA*(1-alpha)*l4^(mu4-1)*(alpha*k4(-1)^mu4+(1-alpha)*l4^mu4)^(1/mu4-1); -lambda*(1+phi*(i1/k1(-1)-delta)) =beta*lambda(+1)*(1+a1(+1)*AA*alpha*k1^(mu1-1)*(alpha*k1^mu1+(1-alpha)*l1(+1)^mu1)^(1/mu1-1)+phi*(1-delta+i1(+1)/k1-0.5*(i1(+1)/k1-delta))*(i1(+1)/k1-delta)); -lambda*(1+phi*(i2/k2(-1)-delta)) =beta*lambda(+1)*(1+a2(+1)*AA*alpha*k2^(mu2-1)*(alpha*k2^mu2+(1-alpha)*l2(+1)^mu2)^(1/mu2-1)+phi*(1-delta+i2(+1)/k2-0.5*(i2(+1)/k2-delta))*(i2(+1)/k2-delta)); -lambda*(1+phi*(i3/k3(-1)-delta)) =beta*lambda(+1)*(1+a3(+1)*AA*alpha*k3^(mu3-1)*(alpha*k3^mu3+(1-alpha)*l3(+1)^mu3)^(1/mu3-1)+phi*(1-delta+i3(+1)/k3-0.5*(i3(+1)/k3-delta))*(i3(+1)/k3-delta)); -lambda*(1+phi*(i4/k4(-1)-delta)) =beta*lambda(+1)*(1+a4(+1)*AA*alpha*k4^(mu4-1)*(alpha*k4^mu4+(1-alpha)*l4(+1)^mu4)^(1/mu4-1)+phi*(1-delta+i4(+1)/k4-0.5*(i4(+1)/k4-delta))*(i4(+1)/k4-delta)); -k1 = i1 + (1-delta)*k1(-1); -k2 = i2 + (1-delta)*k2(-1); -k3 = i3 + (1-delta)*k3(-1); -k4 = i4 + (1-delta)*k4(-1); -c1+i1-delta*k1(-1) + c2+i2-delta*k2(-1) + c3+i3-delta*k3(-1) + c4+i4-delta*k4(-1) = a1*AA*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1)-(phi/2)*k1(-1)*(i1/k1(-1)-delta)^2 + a2*AA*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2)-(phi/2)*k2(-1)*(i2/k2(-1)-delta)^2 + a3*AA*(alpha*k3(-1)^mu3+(1-alpha)*l3^mu3)^(1/mu3)-(phi/2)*k3(-1)*(i3/k3(-1)-delta)^2 + a4*AA*(alpha*k4(-1)^mu4+(1-alpha)*l4^mu4)^(1/mu4)-(phi/2)*k4(-1)*(i4/k4(-1)-delta)^2; -end; -initval; -a1 = 1; -a2 = 1; -a3 = 1; -a4 = 1; -k1 = 1; -k2 = 1; -k3 = 1; -k4 = 1; -c1 = 0.028058361; -c2 = 0.028058361; -c3 = 0.028058361; -c4 = 0.028058361; -i1 = 0.025; -i2 = 0.025; -i3 = 0.025; -i4 = 0.025; -l1 = 1; -l2 = 1; -l3 = 1; -l4 = 1; -lambda = 1; -end; - -vcov = [1.0 0 0 0 0; 0 1.0 0 0 0; 0 0 1.0 0 0; 0 0 0 1.0 0; 0 0 0 0 1.0]; - -order = 4; diff --git a/dynare++/tests/or0a.mod b/dynare++/tests/or0a.mod deleted file mode 100644 index 20b962e284c71e5743eb4f2595d19e45d8ac9dce..0000000000000000000000000000000000000000 --- a/dynare++/tests/or0a.mod +++ /dev/null @@ -1,119 +0,0 @@ -var -C -CF -CF_STAR -CH -CH_STAR -CN -CN_STAR -CT -CT_STAR -C_STAR -E -KE -KE_STAR -L -L_STAR -P -PF -PF_STAR -PH -PH_STAR -PN -PN_STAR -PT -PT_STAR -P_STAR -W -W_STAR -Y -Y_STAR -; - -varexo k k_star m m_star; - -parameters epsi chi thet nu phi gam; - -epsi = 0.5; -nu = 3; -chi = 1.2; -phi = 4; -thet = 3; -gam = 0.5; - -model; -C = (1/chi)*(exp(m)/P)^epsi; -C_STAR = (1/chi)*(exp(m_star)/P_STAR)^epsi; -CN = (1-gam)*(P/PN)*C; -CN_STAR = (1-gam)*(P_STAR/PN_STAR)*C_STAR; -CT = gam*(P/PT)*C; -CT_STAR = gam*(P_STAR/PT_STAR)*C_STAR; -CH = 0.5*(PT/PH)*CT; -CH_STAR = 0.5*(PT_STAR/PH_STAR)*CT_STAR; -CF = 0.5*(PT/PF)*CT; -CF_STAR = 0.5*(PT_STAR/PF_STAR)*CT_STAR; -P = PT^gam*PN^(1-gam); -P_STAR = PT_STAR^gam*PN_STAR^(1-gam); -PT = sqrt(PH*PF); -PT_STAR = sqrt(PH_STAR*PF_STAR); -PH = (thet/(thet-1))*W(-1); -PF_STAR = (thet/(thet-1))*W_STAR(-1); -PN = PH; -PN_STAR = PF_STAR; -L = Y; -L_STAR = Y_STAR; -(L(+1)/(P(+1)*C(+1)))*W = (phi/(phi-1))*KE(+1)*L(+1)^nu; -(L_STAR(+1)/(P_STAR(+1)*C_STAR(+1)))*W_STAR = (phi/(phi-1))*KE_STAR(+1)*L_STAR(+1)^nu; -P*C = Y*PH; -P_STAR*C_STAR = Y_STAR*PF_STAR; -Y = CH + CH_STAR + CN; -Y_STAR = CF + CF_STAR + CN_STAR; -PT = E*PT_STAR; -KE = exp(k); -KE_STAR = exp(k_star); -end; - -initval; -C = 1; -PH = 1; -P = 1; -PN = 1; -PT = 1; -L = 1; -Y = 1; -W = 1; -CF = 0.25; -CH = 0.25; -CT = 0.5; -CN = 0.5; -PF = 1; -C_STAR = 1; -PH_STAR = 1; -P_STAR = 1; -PN_STAR = 1; -PT_STAR = 1; -L_STAR = 1; -Y_STAR = 1; -W_STAR = 1; -CF_STAR = 0.25; -CH_STAR = 0.25; -CT_STAR = 0.5; -CN_STAR = 0.5; -PF_STAR = 1; -KE = 1; -KE_STAR = 1; -E = 1; -k = 0; -k_star = 0; -m = 0; -m_star = 0; -end; - -vcov = [ -0.01 0 -0.01 0; -0 0.01 0 -0.01; --0.01 0 0.01 0; -0 -0.01 0 0.01 -]; - -order=4; diff --git a/dynare++/tests/portfolio.mod b/dynare++/tests/portfolio.mod deleted file mode 100644 index 5309dce0bf15dad4f40bbf6e0a8abd70ba18e772..0000000000000000000000000000000000000000 --- a/dynare++/tests/portfolio.mod +++ /dev/null @@ -1,52 +0,0 @@ -var DOTQ Q1 Q2 X1 X2 C D1 D2; - -varexo E_D1 E_D2; - -parameters beta, r1, r2, gamma, d, rho1, rho2; - -beta = 0.95; -r1 = 0.2; -r2 = 0.05; - -gamma = 0.78; -d = 0.10; - -rho1 = 0.8; -rho2 = 0.2; - -model; -C + X1 + X2 = D1*Q1 + D2*Q2; -Q1+Q2 = 1; -C^(-gamma)/(1-2*r1*X1) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r1*X1(+1))*(D1(+1)*(1-2*r1*X1(+1))+1); -C^(-gamma)/(1-2*r2*X2) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r2*X2(+1))*(D2(+1)*(1-2*r2*X2(+1))+1); -DOTQ*Q1 = Q1(-1) + X1(-1) - r1*X1(-1)^2; -DOTQ*Q2 = Q2(-1) + X2(-1) - r2*X2(-1)^2; - -D1/d = D1(-1)^rho1/(d^rho1)*exp(E_D1); -D2/d = D2(-1)^rho2/(d^rho2)*exp(E_D2); - -/* -D1-d = rho1*(D1(-1)-d) + E_D1; -D2-d = rho2*(D2(-1)-d) + E_D2; -*/ -end; - -initval; -C =0.0441234; -D1 =0.1000000000000; -D2 =0.1000000000000; - -DOTQ =1.05567; -Q1 =0.333333; -Q2 =0.666667; - -X1 =0.0186255; -X2 =0.0372511; -end; - -vcov = [ -0.04 0; -0 0.01 -]; - -order=5; diff --git a/dynare++/tests/portfolio4.mod b/dynare++/tests/portfolio4.mod deleted file mode 100644 index 4413aa5ed72ab702c97f0c4c3a14e62f081104d3..0000000000000000000000000000000000000000 --- a/dynare++/tests/portfolio4.mod +++ /dev/null @@ -1,86 +0,0 @@ -var DOTQ Q1 Q2 Q3 Q4 X1 X2 X3 X4 C D1 D2 D3 D4 V; - -varexo E_D1 E_D2 E_D3 E_D4; - -parameters beta, r1, r2, r3, r4, gamma, ed1, ed2, ed3, ed4, rho1, rho2, rho3, rho4; - -beta = 0.95; -r1 = 0.2; -r2 = 0.1; -r3 = 0.06; -r4 = 0.03; - -gamma = 0.7; -ed1 = 0.1; -ed2 = 0.1; -ed3 = 0.1; -ed4 = 0.1; - -rho1 = 0.3; -rho2 = 0.01; -rho3 = 0.6; -rho4 = 0.6; - -model; -Q1+Q2+Q3+Q4 = 1; -C + X1 + X2 + X3 + X4 = D1*Q1 + D2*Q2 + D3*Q3 + D4*Q4; -DOTQ*Q1 = Q1(-1) + X1(-1) - r1*X1(-1)*X1(-1); -DOTQ*Q2 = Q2(-1) + X2(-1) - r2*X2(-1)*X2(-1); -DOTQ*Q3 = Q3(-1) + X3(-1) - r3*X3(-1)*X3(-1); -DOTQ*Q4 = Q4(-1) + X4(-1) - r4*X4(-1)*X4(-1); -C^(-gamma)/(1-2*r1*X1) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r1*X1(+1))*(D1(+1)*(1-2*r1*X1(+1))+1); -C^(-gamma)/(1-2*r2*X2) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r2*X2(+1))*(D2(+1)*(1-2*r2*X2(+1))+1); -C^(-gamma)/(1-2*r3*X3) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r3*X3(+1))*(D3(+1)*(1-2*r3*X3(+1))+1); -C^(-gamma)/(1-2*r4*X4) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r4*X4(+1))*(D4(+1)*(1-2*r4*X4(+1))+1); - -V = C^(1-gamma)/(1-gamma) + beta*V(+1); - -D1/ed1 = D1(-1)^rho1/(ed1^rho1)*exp(E_D1); -D2/ed2 = D2(-1)^rho2/(ed2^rho2)*exp(E_D2); -D3/ed3 = D3(-1)^rho3/(ed3^rho3)*exp(E_D3); -D4/ed4 = D4(-1)^rho4/(ed4^rho4)*exp(E_D4); - -/* -D1-ed1 = rho1*(D1(-1)-ed1) + E_D1; -D2-ed2 = rho2*(D2(-1)-ed2) + E_D2; -D3-ed3 = rho3*(D3(-1)-ed3) + E_D3; -D4-ed4 = rho4*(D4(-1)-ed4) + E_D4; -*/ - -end; - -initval; -D1 = ed1; -D2 = ed2; -D3 = ed3; -D4 = ed4; -DOTQ = 1.05; // provide a guess not larger than the true value -X1 = 1/2/r1*(1-1/D1*(1/beta*DOTQ^gamma - 1)); -X2 = 1/2/r2*(1-1/D2*(1/beta*DOTQ^gamma - 1)); -X3 = 1/2/r3*(1-1/D3*(1/beta*DOTQ^gamma - 1)); -X4 = 1/2/r4*(1-1/D4*(1/beta*DOTQ^gamma - 1)); -Q1 = 1/(DOTQ-1)*(X1 - r1*X1*X1); -Q2 = 1/(DOTQ-1)*(X2 - r2*X2*X2); -Q3 = 1/(DOTQ-1)*(X3 - r3*X3*X3); -Q4 = 1/(DOTQ-1)*(X4 - r4*X4*X4); -C = ed1*Q1 + ed2*Q2 + ed3*Q3 + ed4*Q4 - X1 - X2 - X3 - X4; -V = 1/(1-beta)*C^(1-gamma)/(1-gamma); -end; - -/* -vcov = [ -0.0005 0 0 0; -0 0.00025 0 0; -0 0 0.0005 0; -0 0 0 0.00025 -]; -*/ - -vcov = [ -0.05 0 0 0; -0 0.025 0 0; -0 0 0.05 0; -0 0 0 0.025 -]; - -order=5; diff --git a/dynare++/tests/portfolio4_norm.mod b/dynare++/tests/portfolio4_norm.mod deleted file mode 100644 index fdedaaa5a2278b640863e4f71964102f86761692..0000000000000000000000000000000000000000 --- a/dynare++/tests/portfolio4_norm.mod +++ /dev/null @@ -1,86 +0,0 @@ -var DOTQ Q1 Q2 Q3 Q4 X1 X2 X3 X4 C D1 D2 D3 D4 V; - -varexo E_D1 E_D2 E_D3 E_D4; - -parameters beta, r1, r2, r3, r4, gamma, ed1, ed2, ed3, ed4, rho1, rho2, rho3, rho4; - -beta = 0.95; -r1 = 0.2; -r2 = 0.1; -r3 = 0.06; -r4 = 0.03; - -gamma = 0.7; -ed1 = 0.1; -ed2 = 0.1; -ed3 = 0.1; -ed4 = 0.1; - -rho1 = 0.3; -rho2 = 0.01; -rho3 = 0.6; -rho4 = 0.6; - -model; -1 = (C + X1 + X2 + X3 + X4)/ (D1*Q1 + D2*Q2 + D3*Q3 + D4*Q4); -1 = (Q1(-1) + X1(-1) - r1*X1(-1)*X1(-1))/(DOTQ*Q1); -1 = (Q2(-1) + X2(-1) - r2*X2(-1)*X2(-1))/(DOTQ*Q2); -1 = (Q3(-1) + X3(-1) - r3*X3(-1)*X3(-1))/(DOTQ*Q3); -1 = (Q4(-1) + X4(-1) - r4*X4(-1)*X4(-1))/(DOTQ*Q4); -Q1+Q2+Q3+Q4 = 1; -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r1*X1(+1))*(D1(+1)*(1-2*r1*X1(+1))+1)/(C^(-gamma)/(1-2*r1*X1)); -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r2*X2(+1))*(D2(+1)*(1-2*r2*X2(+1))+1)/(C^(-gamma)/(1-2*r2*X2)); -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r3*X3(+1))*(D3(+1)*(1-2*r3*X3(+1))+1)/(C^(-gamma)/(1-2*r3*X3)); -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r4*X4(+1))*(D4(+1)*(1-2*r4*X4(+1))+1)/(C^(-gamma)/(1-2*r4*X4)); - - -1 = D1(-1)^rho1/D1*ed1^(1-rho1)*exp(E_D1); -1 = D2(-1)^rho2/D2*ed2^(1-rho2)*exp(E_D2); -1 = D3(-1)^rho3/D3*ed3^(1-rho3)*exp(E_D3); -1 = D4(-1)^rho4/D4*ed4^(1-rho4)*exp(E_D4); - -/* -D1-ed1 = rho1*(D1(-1)-ed1) + E_D1; -D2-ed2 = rho2*(D2(-1)-ed2) + E_D2; -D3-ed3 = rho3*(D3(-1)-ed3) + E_D3; -D4-ed4 = rho4*(D4(-1)-ed4) + E_D4; -*/ - -V/(C^(1-gamma)/(1-gamma) + beta*V(+1)) = 1; -end; - -initval; -Q1 =0.0769231; -Q2 =0.1538462; -Q3 =0.2564103; -Q4 =0.5128205; -X1 =0.0049761; -X2 =0.0099522; -X3 =0.0165871; -X4 =0.0331741; -D1 =0.1; -D2 =0.1; -D3 =0.1; -D4 =0.1; -DOTQ =1.0646251; -C =0.0353105; -V =24.450057; -end; - -/* -vcov = [ -0.0005 0 0 0; -0 0.00025 0 0; -0 0 0.0005 0; -0 0 0 0.00025 -]; -*/ - -vcov = [ -0.05 0 0 0; -0 0.025 0 0; -0 0 0.05 0; -0 0 0 0.025 -]; - -order=4; diff --git a/dynare++/tests/psd_exo3.mod b/dynare++/tests/psd_exo3.mod deleted file mode 100644 index ff59dab3604e5d162bb7830ae17481d01902d49e..0000000000000000000000000000000000000000 --- a/dynare++/tests/psd_exo3.mod +++ /dev/null @@ -1,26 +0,0 @@ -var c k x; -varexo rho; - -parameters a alph gam bet lamb; -alph = 0.7; -bet = 0.95; -gam = 2; -a = 1.052632; -lamb = 0.9; - -model; -c^(-gam) = bet*c(+1)^(-gam)*a*exp(x(+1))*k^(-alph); -k = a*exp(x)*k(-1)^(1-alph)/(1-alph)-c; -x = lamb*x(-1)+rho; -end; - -initval; -k = 1; -c = 2.508; -x = 0; -rho = 0; -end; - -vcov=[0.0001]; - -order=6; \ No newline at end of file diff --git a/dynare++/tests/q3a2.mod b/dynare++/tests/q3a2.mod deleted file mode 100644 index 650b27d3f92d2d3ce54612012fc2e2d1b20cc7ab..0000000000000000000000000000000000000000 --- a/dynare++/tests/q3a2.mod +++ /dev/null @@ -1,33 +0,0 @@ -var c,a1,k1,a2,k2; -varexo e,e1,e2; -parameters beta, gamma, phi, delta, alpha, rho, zeta, sigma, N; -alpha = 0.36; -delta = 0.025; -phi = 2; -gamma = 1; -beta = 0.99; -rho = 0.95; -zeta = 2; -sigma = 0.005; -N = 2; -model; -c^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))+phi*(k1-k1(-1))^zeta/(2*k1(-1)^2)-delta+alpha*a1(+1)*k1^(alpha-1)); -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -c^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))+phi*(k2-k2(-1))^zeta/(2*k2(-1)^2)-delta+alpha*a2(+1)*k2^(alpha-1)); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -N*c+k1+phi*(k1-k1(-1))^zeta/(2*k1)-(1-delta)*k1(-1)+k2+phi*(k2-k2(-1))^zeta/(2*k2)-(1-delta)*k2(-1)= a1*k1(-1)^alpha+a2*k2(-1)^alpha; -end; -initval; -c=1; -e=0; -a1=1; -e1=0; -k1=10; -a2=1; -e2=0; -k2=10; -end; - -vcov=[1 0 0; 0 1 0; 0 0 1]; - -order = 4; \ No newline at end of file diff --git a/dynare++/tests/q3a50.mod b/dynare++/tests/q3a50.mod deleted file mode 100644 index df2fe4c6ef9e1f93d0afa25ec11c9ddd63acbccb..0000000000000000000000000000000000000000 --- a/dynare++/tests/q3a50.mod +++ /dev/null @@ -1,324 +0,0 @@ -var c,a1,k1,a2,k2,a3,k3,a4,k4,a5,k5,a6,k6,a7,k7,a8,k8,a9,k9,a10,k10,a11,k11,a12,k12,a13,k13,a14,k14,a15,k15,a16,k16,a17,k17,a18,k18,a19,k19,a20,k20,a21,k21,a22,k22,a23,k23,a24,k24,a25,k25,a26,k26,a27,k27,a28,k28,a29,k29,a30,k30,a31,k31,a32,k32,a33,k33,a34,k34,a35,k35,a36,k36,a37,k37,a38,k38,a39,k39,a40,k40,a41,k41,a42,k42,a43,k43,a44,k44,a45,k45,a46,k46,a47,k47,a48,k48,a49,k49,a50,k50; -varexo e,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16,e17,e18,e19,e20,e21,e22,e23,e24,e25,e26,e27,e28,e29,e30,e31,e32,e33,e34,e35,e36,e37,e38,e39,e40,e41,e42,e43,e44,e45,e46,e47,e48,e49,e50; -parameters beta, gamma, phi, delta, alpha, rho, zeta, sigma, N; -alpha = 0.36; -delta = 0.1; -phi = 2; -gamma = 1; -beta = 0.99; -rho = 0.95; -zeta = 2; -sigma = 2; -N = 50; -model; -c^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))+phi*(k1-k1(-1))^zeta/(2*k1(-1)^2)-delta+alpha*a1(+1)*k1^(alpha-1)); -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -c^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))+phi*(k2-k2(-1))^zeta/(2*k2(-1)^2)-delta+alpha*a2(+1)*k2^(alpha-1)); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -c^(-gamma)*(1+phi*zeta*(k3-k3(-1))^(zeta-1)/(2*k3(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k3-k3(-1))^(zeta-1)/(2*k3(-1))+phi*(k3-k3(-1))^zeta/(2*k3(-1)^2)-delta+alpha*a3(+1)*k3^(alpha-1)); -log(a3) = rho*log(a3(-1))+sigma*(e+e3); -c^(-gamma)*(1+phi*zeta*(k4-k4(-1))^(zeta-1)/(2*k4(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k4-k4(-1))^(zeta-1)/(2*k4(-1))+phi*(k4-k4(-1))^zeta/(2*k4(-1)^2)-delta+alpha*a4(+1)*k4^(alpha-1)); -log(a4) = rho*log(a4(-1))+sigma*(e+e4); -c^(-gamma)*(1+phi*zeta*(k5-k5(-1))^(zeta-1)/(2*k5(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k5-k5(-1))^(zeta-1)/(2*k5(-1))+phi*(k5-k5(-1))^zeta/(2*k5(-1)^2)-delta+alpha*a5(+1)*k5^(alpha-1)); -log(a5) = rho*log(a5(-1))+sigma*(e+e5); -c^(-gamma)*(1+phi*zeta*(k6-k6(-1))^(zeta-1)/(2*k6(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k6-k6(-1))^(zeta-1)/(2*k6(-1))+phi*(k6-k6(-1))^zeta/(2*k6(-1)^2)-delta+alpha*a6(+1)*k6^(alpha-1)); -log(a6) = rho*log(a6(-1))+sigma*(e+e6); -c^(-gamma)*(1+phi*zeta*(k7-k7(-1))^(zeta-1)/(2*k7(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k7-k7(-1))^(zeta-1)/(2*k7(-1))+phi*(k7-k7(-1))^zeta/(2*k7(-1)^2)-delta+alpha*a7(+1)*k7^(alpha-1)); -log(a7) = rho*log(a7(-1))+sigma*(e+e7); -c^(-gamma)*(1+phi*zeta*(k8-k8(-1))^(zeta-1)/(2*k8(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k8-k8(-1))^(zeta-1)/(2*k8(-1))+phi*(k8-k8(-1))^zeta/(2*k8(-1)^2)-delta+alpha*a8(+1)*k8^(alpha-1)); -log(a8) = rho*log(a8(-1))+sigma*(e+e8); -c^(-gamma)*(1+phi*zeta*(k9-k9(-1))^(zeta-1)/(2*k9(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k9-k9(-1))^(zeta-1)/(2*k9(-1))+phi*(k9-k9(-1))^zeta/(2*k9(-1)^2)-delta+alpha*a9(+1)*k9^(alpha-1)); -log(a9) = rho*log(a9(-1))+sigma*(e+e9); -c^(-gamma)*(1+phi*zeta*(k10-k10(-1))^(zeta-1)/(2*k10(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k10-k10(-1))^(zeta-1)/(2*k10(-1))+phi*(k10-k10(-1))^zeta/(2*k10(-1)^2)-delta+alpha*a10(+1)*k10^(alpha-1)); -log(a10) = rho*log(a10(-1))+sigma*(e+e10); -c^(-gamma)*(1+phi*zeta*(k11-k11(-1))^(zeta-1)/(2*k11(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k11-k11(-1))^(zeta-1)/(2*k11(-1))+phi*(k11-k11(-1))^zeta/(2*k11(-1)^2)-delta+alpha*a11(+1)*k11^(alpha-1)); -log(a11) = rho*log(a11(-1))+sigma*(e+e11); -c^(-gamma)*(1+phi*zeta*(k12-k12(-1))^(zeta-1)/(2*k12(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k12-k12(-1))^(zeta-1)/(2*k12(-1))+phi*(k12-k12(-1))^zeta/(2*k12(-1)^2)-delta+alpha*a12(+1)*k12^(alpha-1)); -log(a12) = rho*log(a12(-1))+sigma*(e+e12); -c^(-gamma)*(1+phi*zeta*(k13-k13(-1))^(zeta-1)/(2*k13(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k13-k13(-1))^(zeta-1)/(2*k13(-1))+phi*(k13-k13(-1))^zeta/(2*k13(-1)^2)-delta+alpha*a13(+1)*k13^(alpha-1)); -log(a13) = rho*log(a13(-1))+sigma*(e+e13); -c^(-gamma)*(1+phi*zeta*(k14-k14(-1))^(zeta-1)/(2*k14(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k14-k14(-1))^(zeta-1)/(2*k14(-1))+phi*(k14-k14(-1))^zeta/(2*k14(-1)^2)-delta+alpha*a14(+1)*k14^(alpha-1)); -log(a14) = rho*log(a14(-1))+sigma*(e+e14); -c^(-gamma)*(1+phi*zeta*(k15-k15(-1))^(zeta-1)/(2*k15(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k15-k15(-1))^(zeta-1)/(2*k15(-1))+phi*(k15-k15(-1))^zeta/(2*k15(-1)^2)-delta+alpha*a15(+1)*k15^(alpha-1)); -log(a15) = rho*log(a15(-1))+sigma*(e+e15); -c^(-gamma)*(1+phi*zeta*(k16-k16(-1))^(zeta-1)/(2*k16(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k16-k16(-1))^(zeta-1)/(2*k16(-1))+phi*(k16-k16(-1))^zeta/(2*k16(-1)^2)-delta+alpha*a16(+1)*k16^(alpha-1)); -log(a16) = rho*log(a16(-1))+sigma*(e+e16); -c^(-gamma)*(1+phi*zeta*(k17-k17(-1))^(zeta-1)/(2*k17(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k17-k17(-1))^(zeta-1)/(2*k17(-1))+phi*(k17-k17(-1))^zeta/(2*k17(-1)^2)-delta+alpha*a17(+1)*k17^(alpha-1)); -log(a17) = rho*log(a17(-1))+sigma*(e+e17); -c^(-gamma)*(1+phi*zeta*(k18-k18(-1))^(zeta-1)/(2*k18(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k18-k18(-1))^(zeta-1)/(2*k18(-1))+phi*(k18-k18(-1))^zeta/(2*k18(-1)^2)-delta+alpha*a18(+1)*k18^(alpha-1)); -log(a18) = rho*log(a18(-1))+sigma*(e+e18); -c^(-gamma)*(1+phi*zeta*(k19-k19(-1))^(zeta-1)/(2*k19(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k19-k19(-1))^(zeta-1)/(2*k19(-1))+phi*(k19-k19(-1))^zeta/(2*k19(-1)^2)-delta+alpha*a19(+1)*k19^(alpha-1)); -log(a19) = rho*log(a19(-1))+sigma*(e+e19); -c^(-gamma)*(1+phi*zeta*(k20-k20(-1))^(zeta-1)/(2*k20(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k20-k20(-1))^(zeta-1)/(2*k20(-1))+phi*(k20-k20(-1))^zeta/(2*k20(-1)^2)-delta+alpha*a20(+1)*k20^(alpha-1)); -log(a20) = rho*log(a20(-1))+sigma*(e+e20); -c^(-gamma)*(1+phi*zeta*(k21-k21(-1))^(zeta-1)/(2*k21(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k21-k21(-1))^(zeta-1)/(2*k21(-1))+phi*(k21-k21(-1))^zeta/(2*k21(-1)^2)-delta+alpha*a21(+1)*k21^(alpha-1)); -log(a21) = rho*log(a21(-1))+sigma*(e+e21); -c^(-gamma)*(1+phi*zeta*(k22-k22(-1))^(zeta-1)/(2*k22(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k22-k22(-1))^(zeta-1)/(2*k22(-1))+phi*(k22-k22(-1))^zeta/(2*k22(-1)^2)-delta+alpha*a22(+1)*k22^(alpha-1)); -log(a22) = rho*log(a22(-1))+sigma*(e+e22); -c^(-gamma)*(1+phi*zeta*(k23-k23(-1))^(zeta-1)/(2*k23(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k23-k23(-1))^(zeta-1)/(2*k23(-1))+phi*(k23-k23(-1))^zeta/(2*k23(-1)^2)-delta+alpha*a23(+1)*k23^(alpha-1)); -log(a23) = rho*log(a23(-1))+sigma*(e+e23); -c^(-gamma)*(1+phi*zeta*(k24-k24(-1))^(zeta-1)/(2*k24(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k24-k24(-1))^(zeta-1)/(2*k24(-1))+phi*(k24-k24(-1))^zeta/(2*k24(-1)^2)-delta+alpha*a24(+1)*k24^(alpha-1)); -log(a24) = rho*log(a24(-1))+sigma*(e+e24); -c^(-gamma)*(1+phi*zeta*(k25-k25(-1))^(zeta-1)/(2*k25(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k25-k25(-1))^(zeta-1)/(2*k25(-1))+phi*(k25-k25(-1))^zeta/(2*k25(-1)^2)-delta+alpha*a25(+1)*k25^(alpha-1)); -log(a25) = rho*log(a25(-1))+sigma*(e+e25); -c^(-gamma)*(1+phi*zeta*(k26-k26(-1))^(zeta-1)/(2*k26(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k26-k26(-1))^(zeta-1)/(2*k26(-1))+phi*(k26-k26(-1))^zeta/(2*k26(-1)^2)-delta+alpha*a26(+1)*k26^(alpha-1)); -log(a26) = rho*log(a26(-1))+sigma*(e+e26); -c^(-gamma)*(1+phi*zeta*(k27-k27(-1))^(zeta-1)/(2*k27(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k27-k27(-1))^(zeta-1)/(2*k27(-1))+phi*(k27-k27(-1))^zeta/(2*k27(-1)^2)-delta+alpha*a27(+1)*k27^(alpha-1)); -log(a27) = rho*log(a27(-1))+sigma*(e+e27); -c^(-gamma)*(1+phi*zeta*(k28-k28(-1))^(zeta-1)/(2*k28(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k28-k28(-1))^(zeta-1)/(2*k28(-1))+phi*(k28-k28(-1))^zeta/(2*k28(-1)^2)-delta+alpha*a28(+1)*k28^(alpha-1)); -log(a28) = rho*log(a28(-1))+sigma*(e+e28); -c^(-gamma)*(1+phi*zeta*(k29-k29(-1))^(zeta-1)/(2*k29(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k29-k29(-1))^(zeta-1)/(2*k29(-1))+phi*(k29-k29(-1))^zeta/(2*k29(-1)^2)-delta+alpha*a29(+1)*k29^(alpha-1)); -log(a29) = rho*log(a29(-1))+sigma*(e+e29); -c^(-gamma)*(1+phi*zeta*(k30-k30(-1))^(zeta-1)/(2*k30(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k30-k30(-1))^(zeta-1)/(2*k30(-1))+phi*(k30-k30(-1))^zeta/(2*k30(-1)^2)-delta+alpha*a30(+1)*k30^(alpha-1)); -log(a30) = rho*log(a30(-1))+sigma*(e+e30); -c^(-gamma)*(1+phi*zeta*(k31-k31(-1))^(zeta-1)/(2*k31(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k31-k31(-1))^(zeta-1)/(2*k31(-1))+phi*(k31-k31(-1))^zeta/(2*k31(-1)^2)-delta+alpha*a31(+1)*k31^(alpha-1)); -log(a31) = rho*log(a31(-1))+sigma*(e+e31); -c^(-gamma)*(1+phi*zeta*(k32-k32(-1))^(zeta-1)/(2*k32(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k32-k32(-1))^(zeta-1)/(2*k32(-1))+phi*(k32-k32(-1))^zeta/(2*k32(-1)^2)-delta+alpha*a32(+1)*k32^(alpha-1)); -log(a32) = rho*log(a32(-1))+sigma*(e+e32); -c^(-gamma)*(1+phi*zeta*(k33-k33(-1))^(zeta-1)/(2*k33(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k33-k33(-1))^(zeta-1)/(2*k33(-1))+phi*(k33-k33(-1))^zeta/(2*k33(-1)^2)-delta+alpha*a33(+1)*k33^(alpha-1)); -log(a33) = rho*log(a33(-1))+sigma*(e+e33); -c^(-gamma)*(1+phi*zeta*(k34-k34(-1))^(zeta-1)/(2*k34(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k34-k34(-1))^(zeta-1)/(2*k34(-1))+phi*(k34-k34(-1))^zeta/(2*k34(-1)^2)-delta+alpha*a34(+1)*k34^(alpha-1)); -log(a34) = rho*log(a34(-1))+sigma*(e+e34); -c^(-gamma)*(1+phi*zeta*(k35-k35(-1))^(zeta-1)/(2*k35(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k35-k35(-1))^(zeta-1)/(2*k35(-1))+phi*(k35-k35(-1))^zeta/(2*k35(-1)^2)-delta+alpha*a35(+1)*k35^(alpha-1)); -log(a35) = rho*log(a35(-1))+sigma*(e+e35); -c^(-gamma)*(1+phi*zeta*(k36-k36(-1))^(zeta-1)/(2*k36(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k36-k36(-1))^(zeta-1)/(2*k36(-1))+phi*(k36-k36(-1))^zeta/(2*k36(-1)^2)-delta+alpha*a36(+1)*k36^(alpha-1)); -log(a36) = rho*log(a36(-1))+sigma*(e+e36); -c^(-gamma)*(1+phi*zeta*(k37-k37(-1))^(zeta-1)/(2*k37(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k37-k37(-1))^(zeta-1)/(2*k37(-1))+phi*(k37-k37(-1))^zeta/(2*k37(-1)^2)-delta+alpha*a37(+1)*k37^(alpha-1)); -log(a37) = rho*log(a37(-1))+sigma*(e+e37); -c^(-gamma)*(1+phi*zeta*(k38-k38(-1))^(zeta-1)/(2*k38(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k38-k38(-1))^(zeta-1)/(2*k38(-1))+phi*(k38-k38(-1))^zeta/(2*k38(-1)^2)-delta+alpha*a38(+1)*k38^(alpha-1)); -log(a38) = rho*log(a38(-1))+sigma*(e+e38); -c^(-gamma)*(1+phi*zeta*(k39-k39(-1))^(zeta-1)/(2*k39(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k39-k39(-1))^(zeta-1)/(2*k39(-1))+phi*(k39-k39(-1))^zeta/(2*k39(-1)^2)-delta+alpha*a39(+1)*k39^(alpha-1)); -log(a39) = rho*log(a39(-1))+sigma*(e+e39); -c^(-gamma)*(1+phi*zeta*(k40-k40(-1))^(zeta-1)/(2*k40(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k40-k40(-1))^(zeta-1)/(2*k40(-1))+phi*(k40-k40(-1))^zeta/(2*k40(-1)^2)-delta+alpha*a40(+1)*k40^(alpha-1)); -log(a40) = rho*log(a40(-1))+sigma*(e+e40); -c^(-gamma)*(1+phi*zeta*(k41-k41(-1))^(zeta-1)/(2*k41(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k41-k41(-1))^(zeta-1)/(2*k41(-1))+phi*(k41-k41(-1))^zeta/(2*k41(-1)^2)-delta+alpha*a41(+1)*k41^(alpha-1)); -log(a41) = rho*log(a41(-1))+sigma*(e+e41); -c^(-gamma)*(1+phi*zeta*(k42-k42(-1))^(zeta-1)/(2*k42(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k42-k42(-1))^(zeta-1)/(2*k42(-1))+phi*(k42-k42(-1))^zeta/(2*k42(-1)^2)-delta+alpha*a42(+1)*k42^(alpha-1)); -log(a42) = rho*log(a42(-1))+sigma*(e+e42); -c^(-gamma)*(1+phi*zeta*(k43-k43(-1))^(zeta-1)/(2*k43(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k43-k43(-1))^(zeta-1)/(2*k43(-1))+phi*(k43-k43(-1))^zeta/(2*k43(-1)^2)-delta+alpha*a43(+1)*k43^(alpha-1)); -log(a43) = rho*log(a43(-1))+sigma*(e+e43); -c^(-gamma)*(1+phi*zeta*(k44-k44(-1))^(zeta-1)/(2*k44(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k44-k44(-1))^(zeta-1)/(2*k44(-1))+phi*(k44-k44(-1))^zeta/(2*k44(-1)^2)-delta+alpha*a44(+1)*k44^(alpha-1)); -log(a44) = rho*log(a44(-1))+sigma*(e+e44); -c^(-gamma)*(1+phi*zeta*(k45-k45(-1))^(zeta-1)/(2*k45(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k45-k45(-1))^(zeta-1)/(2*k45(-1))+phi*(k45-k45(-1))^zeta/(2*k45(-1)^2)-delta+alpha*a45(+1)*k45^(alpha-1)); -log(a45) = rho*log(a45(-1))+sigma*(e+e45); -c^(-gamma)*(1+phi*zeta*(k46-k46(-1))^(zeta-1)/(2*k46(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k46-k46(-1))^(zeta-1)/(2*k46(-1))+phi*(k46-k46(-1))^zeta/(2*k46(-1)^2)-delta+alpha*a46(+1)*k46^(alpha-1)); -log(a46) = rho*log(a46(-1))+sigma*(e+e46); -c^(-gamma)*(1+phi*zeta*(k47-k47(-1))^(zeta-1)/(2*k47(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k47-k47(-1))^(zeta-1)/(2*k47(-1))+phi*(k47-k47(-1))^zeta/(2*k47(-1)^2)-delta+alpha*a47(+1)*k47^(alpha-1)); -log(a47) = rho*log(a47(-1))+sigma*(e+e47); -c^(-gamma)*(1+phi*zeta*(k48-k48(-1))^(zeta-1)/(2*k48(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k48-k48(-1))^(zeta-1)/(2*k48(-1))+phi*(k48-k48(-1))^zeta/(2*k48(-1)^2)-delta+alpha*a48(+1)*k48^(alpha-1)); -log(a48) = rho*log(a48(-1))+sigma*(e+e48); -c^(-gamma)*(1+phi*zeta*(k49-k49(-1))^(zeta-1)/(2*k49(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k49-k49(-1))^(zeta-1)/(2*k49(-1))+phi*(k49-k49(-1))^zeta/(2*k49(-1)^2)-delta+alpha*a49(+1)*k49^(alpha-1)); -log(a49) = rho*log(a49(-1))+sigma*(e+e49); -c^(-gamma)*(1+phi*zeta*(k50-k50(-1))^(zeta-1)/(2*k50(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k50-k50(-1))^(zeta-1)/(2*k50(-1))+phi*(k50-k50(-1))^zeta/(2*k50(-1)^2)-delta+alpha*a50(+1)*k50^(alpha-1)); -log(a50) = rho*log(a50(-1))+sigma*(e+e50); -N*c+k1+phi*(k1-k1(-1))^zeta/(2*k1)-(1-delta)*k1(-1)+k2+phi*(k2-k2(-1))^zeta/(2*k2)-(1-delta)*k2(-1)+k3+phi*(k3-k3(-1))^zeta/(2*k3)-(1-delta)*k3(-1)+k4+phi*(k4-k4(-1))^zeta/(2*k4)-(1-delta)*k4(-1)+k5+phi*(k5-k5(-1))^zeta/(2*k5)-(1-delta)*k5(-1)+k6+phi*(k6-k6(-1))^zeta/(2*k6)-(1-delta)*k6(-1)+k7+phi*(k7-k7(-1))^zeta/(2*k7)-(1-delta)*k7(-1)+k8+phi*(k8-k8(-1))^zeta/(2*k8)-(1-delta)*k8(-1)+k9+phi*(k9-k9(-1))^zeta/(2*k9)-(1-delta)*k9(-1)+k10+phi*(k10-k10(-1))^zeta/(2*k10)-(1-delta)*k10(-1)+k11+phi*(k11-k11(-1))^zeta/(2*k11)-(1-delta)*k11(-1)+k12+phi*(k12-k12(-1))^zeta/(2*k12)-(1-delta)*k12(-1)+k13+phi*(k13-k13(-1))^zeta/(2*k13)-(1-delta)*k13(-1)+k14+phi*(k14-k14(-1))^zeta/(2*k14)-(1-delta)*k14(-1)+k15+phi*(k15-k15(-1))^zeta/(2*k15)-(1-delta)*k15(-1)+k16+phi*(k16-k16(-1))^zeta/(2*k16)-(1-delta)*k16(-1)+k17+phi*(k17-k17(-1))^zeta/(2*k17)-(1-delta)*k17(-1)+k18+phi*(k18-k18(-1))^zeta/(2*k18)-(1-delta)*k18(-1)+k19+phi*(k19-k19(-1))^zeta/(2*k19)-(1-delta)*k19(-1)+k20+phi*(k20-k20(-1))^zeta/(2*k20)-(1-delta)*k20(-1)+k21+phi*(k21-k21(-1))^zeta/(2*k21)-(1-delta)*k21(-1)+k22+phi*(k22-k22(-1))^zeta/(2*k22)-(1-delta)*k22(-1)+k23+phi*(k23-k23(-1))^zeta/(2*k23)-(1-delta)*k23(-1)+k24+phi*(k24-k24(-1))^zeta/(2*k24)-(1-delta)*k24(-1)+k25+phi*(k25-k25(-1))^zeta/(2*k25)-(1-delta)*k25(-1)+k26+phi*(k26-k26(-1))^zeta/(2*k26)-(1-delta)*k26(-1)+k27+phi*(k27-k27(-1))^zeta/(2*k27)-(1-delta)*k27(-1)+k28+phi*(k28-k28(-1))^zeta/(2*k28)-(1-delta)*k28(-1)+k29+phi*(k29-k29(-1))^zeta/(2*k29)-(1-delta)*k29(-1)+k30+phi*(k30-k30(-1))^zeta/(2*k30)-(1-delta)*k30(-1)+k31+phi*(k31-k31(-1))^zeta/(2*k31)-(1-delta)*k31(-1)+k32+phi*(k32-k32(-1))^zeta/(2*k32)-(1-delta)*k32(-1)+k33+phi*(k33-k33(-1))^zeta/(2*k33)-(1-delta)*k33(-1)+k34+phi*(k34-k34(-1))^zeta/(2*k34)-(1-delta)*k34(-1)+k35+phi*(k35-k35(-1))^zeta/(2*k35)-(1-delta)*k35(-1)+k36+phi*(k36-k36(-1))^zeta/(2*k36)-(1-delta)*k36(-1)+k37+phi*(k37-k37(-1))^zeta/(2*k37)-(1-delta)*k37(-1)+k38+phi*(k38-k38(-1))^zeta/(2*k38)-(1-delta)*k38(-1)+k39+phi*(k39-k39(-1))^zeta/(2*k39)-(1-delta)*k39(-1)+k40+phi*(k40-k40(-1))^zeta/(2*k40)-(1-delta)*k40(-1)+k41+phi*(k41-k41(-1))^zeta/(2*k41)-(1-delta)*k41(-1)+k42+phi*(k42-k42(-1))^zeta/(2*k42)-(1-delta)*k42(-1)+k43+phi*(k43-k43(-1))^zeta/(2*k43)-(1-delta)*k43(-1)+k44+phi*(k44-k44(-1))^zeta/(2*k44)-(1-delta)*k44(-1)+k45+phi*(k45-k45(-1))^zeta/(2*k45)-(1-delta)*k45(-1)+k46+phi*(k46-k46(-1))^zeta/(2*k46)-(1-delta)*k46(-1)+k47+phi*(k47-k47(-1))^zeta/(2*k47)-(1-delta)*k47(-1)+k48+phi*(k48-k48(-1))^zeta/(2*k48)-(1-delta)*k48(-1)+k49+phi*(k49-k49(-1))^zeta/(2*k49)-(1-delta)*k49(-1)+k50+phi*(k50-k50(-1))^zeta/(2*k50)-(1-delta)*k50(-1)= a1*k1(-1)^alpha+a2*k2(-1)^alpha+a3*k3(-1)^alpha+a4*k4(-1)^alpha+a5*k5(-1)^alpha+a6*k6(-1)^alpha+a7*k7(-1)^alpha+a8*k8(-1)^alpha+a9*k9(-1)^alpha+a10*k10(-1)^alpha+a11*k11(-1)^alpha+a12*k12(-1)^alpha+a13*k13(-1)^alpha+a14*k14(-1)^alpha+a15*k15(-1)^alpha+a16*k16(-1)^alpha+a17*k17(-1)^alpha+a18*k18(-1)^alpha+a19*k19(-1)^alpha+a20*k20(-1)^alpha+a21*k21(-1)^alpha+a22*k22(-1)^alpha+a23*k23(-1)^alpha+a24*k24(-1)^alpha+a25*k25(-1)^alpha+a26*k26(-1)^alpha+a27*k27(-1)^alpha+a28*k28(-1)^alpha+a29*k29(-1)^alpha+a30*k30(-1)^alpha+a31*k31(-1)^alpha+a32*k32(-1)^alpha+a33*k33(-1)^alpha+a34*k34(-1)^alpha+a35*k35(-1)^alpha+a36*k36(-1)^alpha+a37*k37(-1)^alpha+a38*k38(-1)^alpha+a39*k39(-1)^alpha+a40*k40(-1)^alpha+a41*k41(-1)^alpha+a42*k42(-1)^alpha+a43*k43(-1)^alpha+a44*k44(-1)^alpha+a45*k45(-1)^alpha+a46*k46(-1)^alpha+a47*k47(-1)^alpha+a48*k48(-1)^alpha+a49*k49(-1)^alpha+a50*k50(-1)^alpha; -end; -initval; -c=1; -e=0; -a1=1; -e1=0; -k1=10; -a2=1; -e2=0; -k2=10; -a3=1; -e3=0; -k3=10; -a4=1; -e4=0; -k4=10; -a5=1; -e5=0; -k5=10; -a6=1; -e6=0; -k6=10; -a7=1; -e7=0; -k7=10; -a8=1; -e8=0; -k8=10; -a9=1; -e9=0; -k9=10; -a10=1; -e10=0; -k10=10; -a11=1; -e11=0; -k11=10; -a12=1; -e12=0; -k12=10; -a13=1; -e13=0; -k13=10; -a14=1; -e14=0; -k14=10; -a15=1; -e15=0; -k15=10; -a16=1; -e16=0; -k16=10; -a17=1; -e17=0; -k17=10; -a18=1; -e18=0; -k18=10; -a19=1; -e19=0; -k19=10; -a20=1; -e20=0; -k20=10; -a21=1; -e21=0; -k21=10; -a22=1; -e22=0; -k22=10; -a23=1; -e23=0; -k23=10; -a24=1; -e24=0; -k24=10; -a25=1; -e25=0; -k25=10; -a26=1; -e26=0; -k26=10; -a27=1; -e27=0; -k27=10; -a28=1; -e28=0; -k28=10; -a29=1; -e29=0; -k29=10; -a30=1; -e30=0; -k30=10; -a31=1; -e31=0; -k31=10; -a32=1; -e32=0; -k32=10; -a33=1; -e33=0; -k33=10; -a34=1; -e34=0; -k34=10; -a35=1; -e35=0; -k35=10; -a36=1; -e36=0; -k36=10; -a37=1; -e37=0; -k37=10; -a38=1; -e38=0; -k38=10; -a39=1; -e39=0; -k39=10; -a40=1; -e40=0; -k40=10; -a41=1; -e41=0; -k41=10; -a42=1; -e42=0; -k42=10; -a43=1; -e43=0; -k43=10; -a44=1; -e44=0; -k44=10; -a45=1; -e45=0; -k45=10; -a46=1; -e46=0; -k46=10; -a47=1; -e47=0; -k47=10; -a48=1; -e48=0; -k48=10; -a49=1; -e49=0; -k49=10; -a50=1; -e50=0; -k50=10; -end; - -vcov = [ -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]; - -order = 2; diff --git a/dynare++/tests/sedmodel1.mod b/dynare++/tests/sedmodel1.mod deleted file mode 100644 index a8ad536980ec01c971da60d570cc4d31c964ddf8..0000000000000000000000000000000000000000 --- a/dynare++/tests/sedmodel1.mod +++ /dev/null @@ -1,77 +0,0 @@ -var A, Disp, G, Int, L, - LStar, pi, Welf, WelfStar, x0, - Y, YGap, YStar, z1, z2, Cbar, Cequiv; -varexo eps1 eps2 eps3; - -parameters alpha beta gamma rhoa rhog rho phi chi chi0 theta xi -ABar GBar KBar ZBar piBar Istar; -alpha = 0.3; - beta = 0.99; - gamma = 15; - rhoa = 0.8; - rhog = 0.7; - phi = 1.5; - chi = 1.5; - chi0 = 1; - theta = 0.333333333333; - xi = 0.75; - ABar = 4.0266; - GBar = 0.3163; - KBar = 9.489; - ZBar = .03; - piBar = 1; - rho=.8; - Istar=1.01010101010101; - - -model; -z1 - ((Y-G)^(1-phi) + beta *xi *piBar *pi(+1)^(1/theta) *z1(+1)); -z2 - (Y *chi0 *(1-L-ZBar)^(-chi) / ((1-alpha) *A *KBar^alpha - *L^(-alpha)) + beta *xi *pi(+1)^((1+theta)/theta) *z2(+1)); -x0 - (1+theta)*z2 /z1; -pi^(-1/theta) - ((1-xi) *(x0*pi)^(-1/theta) + xi *piBar^(-1/theta)); -Y - (Disp^(-1) *A *KBar^alpha *L^(1-alpha)); -Disp - ((1-xi) *x0^(-(1+theta)/theta) - + xi *(piBar/pi)^(-(1+theta)/theta) *Disp(-1)); -log(A/ABar) - (rhoa *log(A(-1)/ABar) + eps1); -log(G/GBar) - (rhog *log(G(-1)/GBar) + eps2); -(Y-G)^(-phi) - (beta *(Int/pi(+1)) *(Y(+1)-G(+1))^(-phi)); -Welf - ((Y-G)^(1-phi) /(1-phi) - + chi0*(1-L-ZBar)^(1-chi) /(1-chi) + beta *Welf(+1)); -Cequiv = (((1-beta)*Welf-chi0*(1-LStar-ZBar)^(1-chi) /(1-chi))*(1-phi))^(1/(1-phi)); -(1-alpha) *A *KBar^alpha *LStar^(-alpha) - - (1+theta) *YStar *(YStar-G)^(phi-1) *chi0 - *(1-LStar-ZBar)^(-chi); -YStar - A *KBar^alpha *LStar^(1-alpha); -YGap - (log(Y/YStar)); -WelfStar - ((YStar-G)^(1-phi) /(1-phi) - + chi0*(1-LStar-ZBar)^(1-chi) /(1-chi) + beta *WelfStar(+1)); -Int = (Int(-1)^rho)*((Istar*(pi/piBar)^gamma)^(1-rho))*exp(eps3); -Cbar=(1/100)*((1-phi)*((1-beta)*WelfStar-chi0*(1-LStar-ZBar)^(1-chi)/(1-chi)))^(1/(1-phi)); -end; - -initval; -A= 4.022; -Disp= 1; -G= 0.3; -Int= 1.0101; -L= 0.22; -LStar= 0.22; -pi= 1; -Welf= -359; -WelfStar= -359; -x0= 1; -Y= 2.8; -YGap= 0; -YStar= 2.8; -z1= 2.5; -z2= 1.8; -Cbar= 0.024; -Cequiv = 0.024; -end; - -vcov = [0.001 0 0 ; 0 0.001 0; 0 0 0.001]; - -order=4; - - diff --git a/dynare++/tests/sw_euro.mod b/dynare++/tests/sw_euro.mod deleted file mode 100644 index fc6da21fb7221781489394a8607b86f65370c782..0000000000000000000000000000000000000000 --- a/dynare++/tests/sw_euro.mod +++ /dev/null @@ -1,98 +0,0 @@ -var MC EH EF R_KF QF CF IF YF LF PIEF WF RF R_KH QH CH IH YH LH PIEH WH RH EE_A PIE_BAR EE_B EE_G EE_L EE_I KF KH ONE; - -varexo E_A E_B E_G E_L E_I ETA_R E_PIE_BAR ETA_Q ETA_P ETA_W ; - -parameters xi_e lambda_w alpha czcap beta phi_i tau sig_c hab ccs cinvs phi_y gamma_w xi_w gamma_p xi_p sig_l r_dpi r_pie r_dy r_y rho rho_a rho_pb rho_b rho_g rho_l rho_i ; -alpha=.30; -beta=0.99; -tau=0.025; -ccs=0.6; -cinvs=.22; -lambda_w = 0.5; -phi_i= 6.771; -sig_c= 1.353; -hab= 0.573; -xi_w= 0.737; -sig_l= 2.400; -xi_p= 0.908; -xi_e= 0.599; -gamma_w= 0.763; -gamma_p= 0.469; -czcap= 0.169; -phi_y= 1.408; -r_pie= 1.684; -r_dpi= 0.14; -rho= 0.961; -r_y= 0.099; -r_dy= 0.159; -rho_a= 0.823; -rho_b= 0.855; -rho_g= 0.949; -rho_l= 0.889; -rho_i= 0.927; -rho_pb= 0.924; - - -model; - CF = (1/(1+hab))*(CF(1)+hab*CF(-1))-((1-hab)/((1+hab)*sig_c))*(RF-PIEF(1)-EE_B) ; - 0 = alpha*R_KF+(1-alpha)*WF -EE_A ; - PIEF = 0*ONE; - IF = (1/(1+beta))* (( IF(-1) + beta*(IF(1)))+(1/phi_i)*QF)+0*ETA_Q+EE_I ; - QF = -(RF-PIEF(1))+(1-beta*(1-tau))*((1+czcap)/czcap)*R_KF(1)+beta*(1-tau)*QF(1) +0*EE_I ; - KF = (1-tau)*KF(-1)+tau*IF(-1) ; - YF = (ccs*CF+cinvs*IF)+EE_G ; - YF = 1*phi_y*( alpha*KF+alpha*(1/czcap)*R_KF+(1-alpha)*LF+EE_A ) ; - WF = (sig_c/(1-hab))*(CF-hab*CF(-1)) + sig_l*LF - EE_L ; - LF = R_KF*((1+czcap)/czcap)-WF+KF ; - EF = EF(-1)+EF(1)-EF+(LF-EF)*((1-xi_e)*(1-xi_e*beta)/(xi_e)); - - CH = (hab/(1+hab))*CH(-1)+(1/(1+hab))*CH(1)-((1-hab)/((1+hab)*sig_c))*(RH-PIEH(1)-EE_B) ; - IH = (1/(1+beta))* (( IH(-1) + beta*(IH(1)))+(1/phi_i)*QH )+1*ETA_Q+1*EE_I ; - QH = -(RH-PIEH(1))+(1-beta*(1-tau))*((1+czcap)/czcap)*R_KH(1)+beta*(1-tau)*QH(1) +EE_I*0+0*ETA_Q ; - KH = (1-tau)*KH(-1)+tau*IH(-1) ; - YH = (ccs*CH+cinvs*IH)+ EE_G ; - YH = phi_y*( alpha*KH+alpha*(1/czcap)*R_KH+(1-alpha)*LH ) +phi_y*EE_A ; - PIEH = (1/(1+beta*gamma_p))* - ( - (beta)*(PIEH(1)) +(gamma_p)*(PIEH(-1)) - +((1-xi_p)*(1-beta*xi_p)/(xi_p))*(MC) - ) + ETA_P ; - - MC = alpha*R_KH+(1-alpha)*WH -EE_A; - WH = (1/(1+beta))*(beta*WH(+1)+WH(-1)) - +(beta/(1+beta))*(PIEH(+1)) - -((1+beta*gamma_w)/(1+beta))*(PIEH) - +(gamma_w/(1+beta))*(PIEH(-1)) - -(1/(1+beta))*(((1-beta*xi_w)*(1-xi_w))/(((1+(((1+lambda_w)*sig_l)/(lambda_w))))*xi_w))*(WH-sig_l*LH-(sig_c/(1-hab))*(CH-hab*CH(-1))+EE_L) - +ETA_W; - LH = R_KH*((1+czcap)/czcap)-WH+KH ; - RH = r_dpi*(PIEH-PIEH(-1)) - +(1-rho)*(r_pie*(PIEH(-1)-PIE_BAR)+r_y*(YH-YF)) - +r_dy*(YH-YF-(YH(-1)-YF(-1))) - +rho*(RH(-1)-PIE_BAR) - +PIE_BAR - +ETA_R; - EH = EH(-1)+EH(1)-EH+(LH-EH)*((1-xi_e)*(1-xi_e*beta)/(xi_e)); - - - EE_A = (rho_a)*EE_A(-1) + E_A; - PIE_BAR = rho_pb*PIE_BAR(-1)+ E_PIE_BAR ; - EE_B = rho_b*EE_B(-1) + E_B ; - EE_G = rho_g*EE_G(-1) + E_G ; - EE_L = rho_l*EE_L(-1) + E_L ; - EE_I = rho_i*EE_I(-1) + E_I ; - ONE = 0*ONE(-1) ; -end; - -vcov = [0.357604 0 0 0 0 0 0 0 0 0; - 0 0.112896 0 0 0 0 0 0 0 0; - 0 0 0.105625 0 0 0 0 0 0 0; - 0 0 0 12.39040 0 0 0 0 0 0; - 0 0 0 0 0.722500 0 0 0 0 0; - 0 0 0 0 0 0.656100 0 0 0 0; - 0 0 0 0 0 0 0.000289 0 0 0; - 0 0 0 0 0 0 0 0.364816 0 0; - 0 0 0 0 0 0 0 0 0.025600 0; - 0 0 0 0 0 0 0 0 0 0.083521]; - -order = 1; diff --git a/dynare++/tests/swma_pie.mod b/dynare++/tests/swma_pie.mod deleted file mode 100644 index bf6183ba6dcb57c623a82749e9074a7676e39060..0000000000000000000000000000000000000000 --- a/dynare++/tests/swma_pie.mod +++ /dev/null @@ -1,187 +0,0 @@ -// this model has sticky wages and adjustment costs in -// investment, consumer goods sector is perfectly competitive, thus MC=1 -// with money and transaction costs based on money velocity -// and it has a financial accelerator -// wage is indexed to past consumer price inflation - -// LAMBDA Lagrange multiplier on household's budget constraint (divided by price level) -// PIE inflation of CPI -// PIETILDE to what inflation new wage setters index (here PIE(-1) but could be PIEW(-1)) -// INT nominal interest rate -// C real consumption -// I real investment -// K real capital -// R real rental rate of capital -// W real wage -// L labour -// Y real output -// PIEW nominal wage inflation -// VW wage front loading term for newly set wages -// BBD, BBE, BBF, BBG terms in nominator and denominator in wage FOC -// G government -// SL process for labor shock -// SC process for consumption shock -// SY process for technology shock -// RM real money balances hold -// Q real price of capital -// Q_M1 lagged Q -// RK nominal return of capital for enterpreneurs -// OMEGABAR threshold value for idiosyncratic shock -// N real net worth of borrowers -// WF lifetime utility - -var LAMBDA PIE PIETILDE INT C I K R W L Y PIEW VW BBD BBE BBF BBG G SL SC SY RM - Q Q_M1 RK OMEGABAR N ACAL ACALPRIME BCAL BCALPRIME WF; - -varexo E_C E_L E_Y E_GOV E_INT; - -parameters dep beta gamma eta biga alpha sigmaw phiw deltaw sg pietar h psi nu osigma mu tc1 tc2 ksi1 ksi2 c_weight rho_g rho_l rho_c rho_y; -dep = 0.025; -beta = 0.99; -gamma = 1; -eta = 2; -alpha = 0.30; -biga = alpha^(-alpha)*(1-alpha)^(alpha-1); -sigmaw = 11; -phiw = 2; -deltaw = 0.75; -sg = 0.18; -pietar = 1.03^0.25; -h = 0.8; -// investment adjustment costs -psi = 12; -// enterpreneur saving rate -nu = 0.94; -// stderr of enterpreneur's idiosyncratic shocks -osigma = 0.5; -// monitoring cost for lender -mu = 0.2; -// consumption transaction costs -tc1 = 0.05; -tc2 = 0.5; -// Taylor rule -ksi1 = 0.106; -ksi2 = 3; -rho_g = 0.90; -rho_l = 0.90; -rho_c = 0.90; -rho_y = 0.90; -// weight of consumption utility -c_weight = 1; - -model; -// capital accumulation -K = (1 - dep - psi/2*(I(-1)/K(-1)-dep)^2)*K(-1) + I(-1); -// FOC bonds -LAMBDA = beta*INT*LAMBDA(+1)/PIE(+1); -// FOC consumption (right hand side is equal to LAMBDA*(1+TC+TCPRIME*C/RM)) -SC*c_weight*(C-h*C(-1))^(-eta) = LAMBDA*(1+2*tc1*C/RM-2*sqrt(tc1*tc2)); -// FOC money (right hand side is equal to 1 - TCPRIME*C*C/RM/RM) -beta*LAMBDA(+1)/LAMBDA/PIE(+1) = 1 - tc1*C*C/RM/RM + tc2; -// FOC investment removed -// FOC capital(+1) removed -// real price of capital -Q = (1-psi*(I/K-dep))^(-1); -// nominal return on capital -RK = PIE*(R + Q*(1 - dep + psi*(I/K-dep)*I/K -psi/2*(I/K-dep)^2))/Q(-1); -// FOC in optimal contract for K(+1) -RK(+1)*(BCAL(+1)*ACALPRIME(+1)/BCALPRIME(+1)-ACAL(+1)) = INT(+1)*ACALPRIME(+1)/BCALPRIME(+1); -// Participation constraint -//RK(+1)*BCAL(+1) = INT(+1)*(1-N(+1)*PIE(+1)/Q/K(+1)); -RK*BCAL = INT*(1-N*PIE/Q(-1)/K); -// evolution of net worth (real) -N*PIE*PIE(-1) = nu*(ACAL(-1)+BCAL(-1))*RK(-1)*Q_M1(-1)*K(-1) - nu*INT(-1)*(Q_M1(-1)*K(-1)-N(-1)*PIE); -// marginal cost is 1 -1 = biga*(W/SY)^(1-alpha)*R^alpha; -// labor attaining minimal MC -L = (1-alpha)/W*Y; -// capital attaining minimal MC -K = alpha/R*Y; -// FOC for newly set wages -W*VW = sigmaw/(sigmaw-1)*(BBD*VW^(-sigmaw*gamma) + phiw*BBE*VW^(-sigmaw) - phiw*BBF)/BBG; -// definition of BBD -BBD = SL*L^(1+gamma) + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-sigmaw*(1+gamma))*BBD(+1); -// definition of BBE -BBE = LAMBDA*L*W + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-2*sigmaw)*BBE(+1); -// definition of BBF -BBF = LAMBDA*L*W + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-sigmaw)*BBF(+1); -// definition of BBG -BBG = LAMBDA*L + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-sigmaw)*PIETILDE(+1)/PIE(+1)*BBG(+1); -// price index -1 = (1-deltaw)*VW^(1-sigmaw) + deltaw*(PIETILDE/PIEW)^(1-sigmaw); -// definition of ACAL -ACAL = 0.5*erfc((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0)) - OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -// definition of BCAL -BCAL = OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)) + (1-mu)/2*(1+erf((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0))); -// definition of ACALPRIME -ACALPRIME = -0.5*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -// definition of BCALPRIME -BCALPRIME = -ACALPRIME - mu/osigma/2.506628274631*exp(-((log(OMEGABAR) + 0.5*osigma)^2)/2/osigma/osigma); -// identity for PIEW -PIEW = PIE*W/W(-1); -// welfare identity -WF = SC*c_weight*(C-h*C(-1))^(1-eta)/(1-eta) - SL*L^(1+gamma)/(1+gamma) + beta*WF(+1); -// interest rate rule -INT = INT(-1)^ksi1*((PIE/beta)*(PIE/pietar)^ksi2)^(1-ksi1)*exp(E_INT); -// aggregate constraint -Y = C + I + G + (1-ACAL-BCAL)*RK*Q(-1)*K; -//Y = C + I + G; -// process for government -G/Y = (G(-1)/Y(-1))^rho_g*sg^(1-rho_g)*exp(E_GOV/sg); -// to what do they index (pietar, past inflation, past indexed inflation) -PIETILDE = PIE(-1); -//PIETILDE = pietar; -// exo processes -SL = SL(-1)^rho_l*exp(E_L); -SC = SC(-1)^rho_c*exp(E_C); -SY = SY(-1)^rho_y*exp(E_Y); -// lagged Q -Q_M1 = Q(-1); -end; - -initval; -RM = 0.1; -INT = pietar/beta; -PIE = pietar; -PIEW = pietar; -PIETILDE = pietar; -//R = dep/beta; -R = 0.1; -W = (1/biga/(R)^alpha)^(1/(1-alpha)); -LAMBDA = ((1-dep*alpha/R-sg)*(1-h)*c_weight/(1-alpha)*W^(1/gamma+1)*((sigmaw-1)/sigmaw)^(1/gamma))^(-1/(1/eta+1/gamma)); -L = (W*LAMBDA*(sigmaw-1)/sigmaw)^(1/gamma); -Y = W*L/(1-alpha); -K = alpha/R*Y; -I = dep*K; -G = sg*Y; -VW = 1; -BBD = L^(1+gamma)/(1-deltaw*beta); -BBE = LAMBDA*L*W/(1-deltaw*beta); -BBF = LAMBDA*L*W/(1-deltaw*beta); -BBG = LAMBDA*L/(1-deltaw*beta); -Q = 1; -Q_M1 = Q; -RK = 1/Q*PIE*(R+(1-dep)*Q); -OMEGABAR = 0.5; -ACAL = 0.5*erfc((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0)) - OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -BCAL = OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)) + (1-mu)/2*(1+erf((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0))); -ACALPRIME = -0.5*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -BCALPRIME = -ACALPRIME - mu/osigma/2.506628274631*exp(-((log(OMEGABAR) + 0.5*osigma)^2)/2/osigma/osigma); -N = (nu*(ACAL+BCAL)*RK*Q*K-nu*INT*Q*K)/(PIE*PIE-nu*INT*PIE); -C = Y - I - G - (1-ACAL-BCAL)*RK*Q*K; -SL = 1; -SC = 1; -SY = 1; -WF = 1/(1-beta)*(SC*c_weight*((1-h)*C)^(1-eta)/(1-eta) - SL*L^(1+gamma)/(1+gamma)); -end; - -vcov = [ -0.0001 0 0 0 0; -0 0.0001 0 0 0; -0 0 0.0001 0 0; -0 0 0 0.0001 0; -0 0 0 0 0.0001 -]; - -order = 4; - diff --git a/dynare++/tests/test.mod b/dynare++/tests/test.mod deleted file mode 100644 index 98b7158a7071436211d4fbdfb22034be78559db9..0000000000000000000000000000000000000000 --- a/dynare++/tests/test.mod +++ /dev/null @@ -1,39 +0,0 @@ -var a, b, c, h, k, y; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) + e; -b = tau*a(-1)+rho*b(-1) + u; -end; - -initval; -y = 1; -c = 0.7; -h = 0.1; -k = 11; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.000081 0.000008;0.000008 0.000081]; - -order = 2; - diff --git a/dynare++/tests/test1.mod b/dynare++/tests/test1.mod deleted file mode 100644 index 04e7f6196ebccf4fbf3dfab1c22f595803ab073b..0000000000000000000000000000000000000000 --- a/dynare++/tests/test1.mod +++ /dev/null @@ -1,42 +0,0 @@ -var y, c, k, a, h, b; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) + e; -b = tau*a(-1)+rho*b(-1) + u; -end; - -initval; -y = 1; -c = 0.7; -h = 0.1; -k = 11; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.000081 0.0000081; 0.0000081 0.000081]; - -order = 1; - - - - diff --git a/dynare++/tests/test2.mod b/dynare++/tests/test2.mod deleted file mode 100644 index 0abc1dfa559b6c28d29feb90a09d220fb26f5f17..0000000000000000000000000000000000000000 --- a/dynare++/tests/test2.mod +++ /dev/null @@ -1,39 +0,0 @@ -var y, c, k, a, h, b; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) - rho*a(-2) - tau*b(-3) + e; -b = tau*a(-1)+rho*b(-1) - rho*b(-2) - tau*a(-3) + u; -end; - -initval; -y = 1.08; -c = 0.8; -h = 0.29; -k = 11.08; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.01 0.005; 0.005 0.01]; - -order = 1; - diff --git a/dynare++/tests/test2a.mod b/dynare++/tests/test2a.mod deleted file mode 100644 index f0b0441816bf1fbe7b755dc8c3da2194a6a8cd05..0000000000000000000000000000000000000000 --- a/dynare++/tests/test2a.mod +++ /dev/null @@ -1,39 +0,0 @@ -var y, c, k, a, h, b; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) - rho*a(-2) - tau*b(-3) + e; -b = tau*a(-1)+rho*b(-1) - rho*b(-2) - tau*a(-3) + u; -end; - -initval; -y = 1.08; -c = 0.8; -h = 0.29; -k = 11.08; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.01 0.005; 0.005 0.01]; - -order = 2; - diff --git a/dynare++/tests/test3.mod b/dynare++/tests/test3.mod deleted file mode 100644 index 7f386f2a87fa9aa6a64f931760ac90bb916ca1fe..0000000000000000000000000000000000000000 --- a/dynare++/tests/test3.mod +++ /dev/null @@ -1,30 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, f, g, h, j; - -a=0.8; -b=0.9; -c=0.9; -d=1; -e=-0.556875; -f=-0.172125; -g=-0.9; -h=-0.2754; -j=-1.8; - - -model; -x=a*x(-1)+u; -c*y(+1)^2+d*y^2+e*x^2+f*u^2-d*v^2+g+h*x(-1)*u+j*x(-1)*v=0; -end; - -initval; -x=0; -y=0.7237469; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 2; \ No newline at end of file diff --git a/dynare++/tests/test4.mod b/dynare++/tests/test4.mod deleted file mode 100644 index 4250ac3a04f38f525c72f7563c1aefcffd0c76b6..0000000000000000000000000000000000000000 --- a/dynare++/tests/test4.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, f, m; - -a=0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -f = 1; - -model; -x = a*x(-1)+u; -c*y(+1)^2+d*y^2+e*x^2-(c+d)*m^2-(c*b*b*a*a+d*b*b+e*a*a)*x(-1)^2-(c*b*b+e)*u^2-2*(c*m*b*a+d*m*b)*x(-1)-2*c*m*b*u-2*(c*b*b*a+e*a)*x(-1)*u-d*f^2*v^2-2*d*m*f*v-2*d*b*f*x(-1)*v=0; -end; - -initval; -x=1; -y=21; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 2; diff --git a/dynare++/tests/test5.mod b/dynare++/tests/test5.mod deleted file mode 100644 index 4e2e5938a31f9307ada72a28af6e61900d116e23..0000000000000000000000000000000000000000 --- a/dynare++/tests/test5.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, m, n; - -a=-0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -n=0.2; - -model; -x=b*x(-1)+u; -a*y(+1)+y-(a*b^2+1)*x(-1)^2-2*a*b*x(-1)*u-a*u^2-a-2*x(-1)*v-v^2; -end; - -initval; -x=0; -y=0; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 3; diff --git a/dynare++/tests/test6.mod b/dynare++/tests/test6.mod deleted file mode 100644 index 53f4e826c21b7f4c09e05ad5a41f1cf64494ee80..0000000000000000000000000000000000000000 --- a/dynare++/tests/test6.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, m, n; - -a=-0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -n=0.2; - -model; -x=b*x(-1)+u; -a*y(+1)+y-(a*b^3+1)*x(-1)^3-3*a*b*x(-1)*u^2-3*a*b^2*x(-1)^2*u-a*u^3-a-v^2; -end; - -initval; -x=0; -y=0; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 3; diff --git a/dynare++/tests/test7.mod b/dynare++/tests/test7.mod deleted file mode 100644 index f520b9453622794c5e2971f2be137e2c074cdd3c..0000000000000000000000000000000000000000 --- a/dynare++/tests/test7.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, m, n; - -a=-0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -n=0.2; - -model; -x=b*x(-1)+u; -a*y(+1)+y-(a*b^4+1)*x(-1)^4-4*a*b*x(-1)*u^3-4*a*b^3*x(-1)^3*u-6*a*(b*x(-1)*u)^2-a*u^4-v; -end; - -initval; -x=0; -y=0; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 4; diff --git a/dynare++/tl/Makefile.am b/dynare++/tl/Makefile.am deleted file mode 100644 index ffebab6fe3641d3346316761575936e56f4be6f5..0000000000000000000000000000000000000000 --- a/dynare++/tl/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = cc testing diff --git a/dynare++/tl/cc/Makefile.am b/dynare++/tl/cc/Makefile.am deleted file mode 100644 index 026cb13f1df9b6dd5faa7c5478e241798405ef8a..0000000000000000000000000000000000000000 --- a/dynare++/tl/cc/Makefile.am +++ /dev/null @@ -1,45 +0,0 @@ -noinst_LIBRARIES = libtl.a - -libtl_a_SOURCES = \ - equivalence.cc \ - equivalence.hh \ - fine_container.cc \ - fine_container.hh \ - fs_tensor.cc \ - fs_tensor.hh \ - gs_tensor.cc \ - gs_tensor.hh \ - int_sequence.cc \ - int_sequence.hh \ - kron_prod.cc \ - kron_prod.hh \ - normal_moments.cc \ - normal_moments.hh \ - permutation.cc \ - permutation.hh \ - ps_tensor.cc \ - ps_tensor.hh \ - pyramid_prod.cc \ - pyramid_prod.hh \ - pyramid_prod2.cc \ - pyramid_prod2.hh \ - rfs_tensor.cc \ - rfs_tensor.hh \ - sparse_tensor.cc \ - sparse_tensor.hh \ - stack_container.cc \ - stack_container.hh \ - symmetry.cc \ - symmetry.hh \ - t_container.cc \ - t_container.hh \ - t_polynomial.cc \ - t_polynomial.hh \ - tensor.cc \ - tensor.hh \ - tl_exception.hh \ - tl_static.cc \ - tl_static.hh \ - twod_matrix.cc \ - twod_matrix.hh -libtl_a_CPPFLAGS = -I../../sylv/cc -I../../utils/cc $(CPPFLAGS_MATIO) diff --git a/dynare++/utils/cc/Makefile.am b/dynare++/utils/cc/Makefile.am deleted file mode 100644 index 93410c9b707c2ff1067fb9ad0ef26133b04c27d8..0000000000000000000000000000000000000000 --- a/dynare++/utils/cc/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -noinst_LIBRARIES = libutils.a - -libutils_a_SOURCES = \ - exception.hh \ - pascal_triangle.cc \ - pascal_triangle.hh \ - int_power.hh \ - int_power.cc \ - sthread.hh \ - sthread.cc diff --git a/license.txt b/license.txt index e471efd484e3b46f6b69dac9e046fc02ecc42d11..06f5bd8c50721adad910ddd749cebd06501822fc 100644 --- a/license.txt +++ b/license.txt @@ -278,9 +278,8 @@ Copyright: 2007-2017 Sébastien Villemot 2016-2017 Johannes Pfeifer License: GFDL-NIV-1.3+ -Files: dynare++/* +Files: doc/sylvester.tex doc/tl.tex Copyright: 2004-2011 Ondra Kamenik - 2019-2022 Dynare Team License: GPL-3+ Files: m4/ax_compare_version.m4 @@ -303,14 +302,15 @@ Copyright: 2010 Yannick Kalantzis License: GPL-3+ Files: mex/sources/gensylv/gensylv.cc -Copyright: 2005-2011 Ondra Kamenik - 2019-2020 Dynare Team + mex/sources/libkorder/kord/* mex/sources/libkorder/sylv/* + mex/sources/libkorder/tl/* mex/sources/libkorder/utils/* +Copyright: 2004-2011 Ondra Kamenik + 2019-2023 Dynare Team License: GPL-3+ -Files: mex/sources/sobol/sobol.hh mex/sources/sobol/initialize_v_array.hh - mex/sources/sobol/initialize_v_array.inc -Copyright: 2009 John Burkardt - 2010-2017 Dynare Team +Files: mex/sources/sobol/sobol.f08 +Copyright: 2004-2009 John Burkardt + 2023 Dynare Team License: LGPL-3+ Files: macOS/brewfiles/* diff --git a/m4/ax_matio.m4 b/m4/ax_matio.m4 index caab9ef4c70ab3d1141d075a3b116f89555b9cf7..9a4d56284d537aeb020b6020395f06549109144f 100644 --- a/m4/ax_matio.m4 +++ b/m4/ax_matio.m4 @@ -1,6 +1,6 @@ dnl Detect the MATIO Library. dnl -dnl Copyright © 2012-2021 Dynare Team +dnl Copyright © 2012-2023 Dynare Team dnl dnl This file is part of Dynare. dnl @@ -22,6 +22,8 @@ AC_DEFUN([AX_MATIO], AC_ARG_WITH(matio, AS_HELP_STRING([--with-matio=DIR], [prefix to MATIO installation]), matio_prefix="$withval", matio_prefix="") + AC_REQUIRE([AC_CANONICAL_HOST]) + has_matio=yes if test -n "$matio_prefix"; then @@ -40,15 +42,19 @@ AC_ARG_WITH(matio, AS_HELP_STRING([--with-matio=DIR], [prefix to MATIO installat CPPFLAGS="$CPPFLAGS_MATIO $CPPFLAGS" LDFLAGS="$LDFLAGS_MATIO $LDFLAGS" - dnl Workaround for the matio from RHEL 6 + EPEL 6 - dnl If detected, libz and libhdf5 are added to LIBS, used for matio test - LIBS="" - AC_CHECK_LIB([z], [compress]) - dnl szip is needed under MSYS2 - AC_CHECK_LIB([szip], [SZ_Compress]) - dnl szip is needed for static linking on macOS (it's called libsz on macOS) - AC_CHECK_LIB([sz], [SZ_Compress]) - AC_CHECK_LIB([hdf5], [H5Fcreate]) + dnl Under Windows and macOS, add hdf5 and its dependencies since we are linking statically + case ${host_os} in + *mingw32*) + dnl Partly inspired by /mingw64/lib/pkgconfig/{hdf5,libcurl}.pc (in particular for the system libraries) + LIBS="-lhdf5 -lcurl -lnghttp2 -lidn2 -lssh2 -lpsl -lunistring -liconv -lbcrypt -ladvapi32 -lcrypt32 -lbcrypt -lgdi32 -lwldap32 -lzstd -lbrotlidec -lbrotlicommon -lssl -lcrypto -lws2_32 -lz -lsz" + ;; + *darwin*) + LIBS="-lhdf5 -lz -lsz" + ;; + *) + LIBS="" + ;; + esac AC_CHECK_HEADER([matio.h], [], [has_matio=no]) AC_CHECK_LIB([matio], [Mat_Open], [LIBADD_MATIO="-lmatio $LIBS"], [has_matio=no]) diff --git a/m4/ax_matlab_arch.m4 b/m4/ax_matlab_arch.m4 index e37bd522880f92389ece091e1fc718137f6c7c82..3def1809a8a6d9a08ab9646e0f3138ed3aa4885c 100644 --- a/m4/ax_matlab_arch.m4 +++ b/m4/ax_matlab_arch.m4 @@ -1,7 +1,7 @@ dnl matlabarch.m4 --- check for MATLAB machine architecture. dnl dnl Copyright © 2002, 2003 Ralph Schleicher -dnl Copyright © 2009 Dynare Team +dnl Copyright © 2009-2023 Dynare Team dnl dnl This program is free software; you can redistribute it and/or dnl modify it under the terms of the GNU General Public License as @@ -57,6 +57,9 @@ else *mexmaci64) ax_cv_matlab_arch=maci64 ;; + *mexmaca64) + ax_cv_matlab_arch=maca64 + ;; *) ax_cv_matlab_arch=unknown ;; diff --git a/m4/ax_matlab_version.m4 b/m4/ax_matlab_version.m4 index daabee40e5bdc364d1103590a886a866df66eb8e..98f31456203b697a470d2105b9980e19a3721f2f 100644 --- a/m4/ax_matlab_version.m4 +++ b/m4/ax_matlab_version.m4 @@ -1,4 +1,4 @@ -dnl Copyright © 2009-2022 Dynare Team +dnl Copyright © 2009-2023 Dynare Team dnl dnl This file is part of Dynare. dnl @@ -44,6 +44,9 @@ fi if test -n "$MATLAB_VERSION"; then dnl Convert a release number (Rnnnnx) into a version number (x.y) case $MATLAB_VERSION in + *2023a | *2023A) + MATLAB_VERSION="9.14" + ;; *2022b | *2022B) MATLAB_VERSION="9.13" ;; diff --git a/m4/ax_mexopts.m4 b/m4/ax_mexopts.m4 index 52c7505811a56d08ee5660f54ddb6259cd29a325..1a5ef951255a622dd09f9a06150389174837fc0f 100644 --- a/m4/ax_mexopts.m4 +++ b/m4/ax_mexopts.m4 @@ -1,4 +1,4 @@ -dnl Copyright © 2009-2021 Dynare Team +dnl Copyright © 2009-2023 Dynare Team dnl dnl This file is part of Dynare. dnl @@ -37,6 +37,7 @@ case ${MATLAB_ARCH} in MATLAB_LDFLAGS_NOMAP="-shared -Wl,--no-undefined -Wl,-rpath-link,$MATLAB/bin/glnxa64 -L$MATLAB/bin/glnxa64" MATLAB_LDFLAGS="$MATLAB_LDFLAGS_NOMAP -Wl,--version-script,$MATLAB/extern/lib/glnxa64/mexFunction.map" MATLAB_LIBS="-lmx -lmex -lmat -lm -lmwlapack -lmwblas" + FORTRAN_LIBS_FOR_CXXLINK="-lgfortran -lquadmath" ax_mexopts_ok="yes" ;; win64) @@ -64,9 +65,10 @@ case ${MATLAB_ARCH} in # Should come by the end of the link command # (otherwise it will have to be enclosed within --whole-archive). OPENMP_LIBS="-Wl,-Bstatic -lgomp -Wl,-Bdynamic" + FORTRAN_LIBS_FOR_CXXLINK="-Wl,-Bstatic -lgfortran -Wl,-Bdynamic" # libquadmath is already in MATLAB_LDFLAGS_NOMAP ax_mexopts_ok="yes" ;; - maci64) + mac[[ai]]64) MATLAB_DEFS="-DNDEBUG" MATLAB_CFLAGS="-fno-common -fexceptions" MATLAB_CXXFLAGS="-fno-common -fexceptions" @@ -76,7 +78,8 @@ case ${MATLAB_ARCH} in # This -L flag is put here, hence later on the linker command line, so as # to avoid linking against the HDF5 shipped by MATLAB (which would # otherwise override the HDF5 from Homebrew) - MATLAB_LIBS="-L$MATLAB/bin/maci64 -lmx -lmex -lmat -lmwlapack -lmwblas" + MATLAB_LIBS="-L$MATLAB/bin/${MATLAB_ARCH} -lmx -lmex -lmat -lmwlapack -lmwblas" + FORTRAN_LIBS_FOR_CXXLINK="-lgfortran -lquadmath" ax_mexopts_ok="yes" ;; *) @@ -132,4 +135,5 @@ AC_SUBST([MATLAB_FCFLAGS]) AC_SUBST([MATLAB_LDFLAGS]) AC_SUBST([MATLAB_LIBS]) AC_SUBST([OPENMP_LIBS]) +AC_SUBST([FORTRAN_LIBS_FOR_CXXLINK]) ]) diff --git a/macOS/brewfiles/gcc.rb b/macOS/brewfiles/gcc.rb index 037597fe0cc010229f743d49d41b3e4e3c3310fb..d636f85d5d702a160c44d5dabb5967223003dea9 100644 --- a/macOS/brewfiles/gcc.rb +++ b/macOS/brewfiles/gcc.rb @@ -5,15 +5,15 @@ class Gcc < Formula head "https://gcc.gnu.org/git/gcc.git", branch: "master" stable do - url "https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz" - mirror "https://ftpmirror.gnu.org/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz" - sha256 "e549cf9cf3594a00e27b6589d4322d70e0720cdd213f39beb4181e06926230ff" + url "https://ftp.gnu.org/gnu/gcc/gcc-13.1.0/gcc-13.1.0.tar.xz" + mirror "https://ftpmirror.gnu.org/gcc/gcc-13.1.0/gcc-13.1.0.tar.xz" + sha256 "61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86" # Branch from the Darwin maintainer of GCC, with a few generic fixes and - # Apple Silicon support, located at https://github.com/iains/gcc-12-branch + # Apple Silicon support, located at https://github.com/iains/gcc-13-branch patch do - url "https://raw.githubusercontent.com/Homebrew/formula-patches/1d184289/gcc/gcc-12.2.0-arm.diff" - sha256 "a7843b5c6bf1401e40c20c72af69c8f6fc9754ae980bb4a5f0540220b3dcb62d" + url "https://raw.githubusercontent.com/Homebrew/formula-patches/5c206c47/gcc/gcc-13.1.0.diff" + sha256 "cb4e8a89387f748a744da0273025d0dc2e3c76780cc390b18ada704676afea11" end end @@ -23,13 +23,13 @@ class Gcc < Formula end bottle do - rebuild 1 - sha256 cellar: :any, arm64_monterey: "f37b8d3764f63e11a6e11dc23774eba527453de89fedb4e3b13aa3996059d386" - sha256 cellar: :any, arm64_big_sur: "5d98731c711f17707fe13276090a6a3669a9d68e766e56ead8c842465ff164bb" - sha256 cellar: :any, monterey: "453199069048503be8f072463aaa3cd60fc2764875528f234374872354528564" - sha256 cellar: :any, big_sur: "1f2aca239e706f455125dcb2c08df7744b8905b5b62d7aed4cdeae6cf5d5fcee" - sha256 cellar: :any, catalina: "98f37e3468e2a15343e02f613a2f8d7761d30eead960d04b2317f8292122e9ac" - sha256 cellar: :any_skip_relocation, x86_64_linux: "c7f773f9af560766b2d971d815a8d224c267088c05ed1f2b864bd1d9ebc26e1a" + sha256 cellar: :any, arm64_ventura: "d2b21a257c73e9b8f9c6bc03e6330ea8ba9fb3e7cdb9eb945d7ff7d96ba9708c" + sha256 cellar: :any, arm64_monterey: "5405f3b1ecdabb68e161308f35d72af907af21694a0e2b67f10edb25b2dd8f90" + sha256 cellar: :any, arm64_big_sur: "cc92fced3516bc72b69e31b0495fe416f206b540be02f1c817db96afbcc38f28" + sha256 cellar: :any, ventura: "3abd8c2c88a8e74b5df5c44f9c151ff7e760cf705307ecf3c95762492e777f1e" + sha256 cellar: :any, monterey: "f9cbc7eb14781df9228518a2d02590941206947e7dc419c0b232d523f39b1475" + sha256 cellar: :any, big_sur: "2eb458ed309ea4fa9451ab547fa3d797bd523ba4f50f01d5c997212109b74e5e" + sha256 cellar: :any_skip_relocation, x86_64_linux: "cca77a5d6625d3bb711ce40551751974d4cb5c74306329fc2fc8cdcade2ef564" end # The bottles are built on systems with the CLT installed, and do not work @@ -104,6 +104,9 @@ class Gcc < Formula # Fix Linux error: gnu/stubs-32.h: No such file or directory. args << "--disable-multilib" + # Enable to PIE by default to match what the host GCC uses + args << "--enable-default-pie" + # Change the default directory name for 64-bit libraries to `lib` # https://stackoverflow.com/a/54038769 inreplace "gcc/config/i386/t-linux64", "m64=../lib64", "m64=" @@ -204,8 +207,8 @@ class Gcc < Formula # * `-idirafter <dir>` instructs gcc to search system header # files after gcc internal header files. # For libraries: - # * `-nostdlib -L#{libgcc}` instructs gcc to use brewed glibc - # if applied. + # * `-nostdlib -L#{libgcc} -L#{glibc.opt_lib}` instructs gcc to use + # brewed glibc if applied. # * `-L#{libdir}` instructs gcc to find the corresponding gcc # libraries. It is essential if there are multiple brewed gcc # with different versions installed. @@ -219,7 +222,7 @@ class Gcc < Formula + -isysroot #{HOMEBREW_PREFIX}/nonexistent #{system_header_dirs.map { |p| "-idirafter #{p}" }.join(" ")} *link_libgcc: - #{glibc_installed ? "-nostdlib -L#{libgcc}" : "+"} -L#{libdir} -L#{HOMEBREW_PREFIX}/lib + #{glibc_installed ? "-nostdlib -L#{libgcc} -L#{glibc.opt_lib}" : "+"} -L#{libdir} -L#{HOMEBREW_PREFIX}/lib *link: + --dynamic-linker #{HOMEBREW_PREFIX}/lib/ld.so -rpath #{libdir} diff --git a/macOS/brewfiles/gmp.rb b/macOS/brewfiles/gmp.rb index 9aad4f70856f0f5f7f262b858714718aa266668f..e210d4840e55881cf52818c9b8a41e0f37813b93 100644 --- a/macOS/brewfiles/gmp.rb +++ b/macOS/brewfiles/gmp.rb @@ -22,8 +22,10 @@ class Gmp < Formula end bottle do + sha256 cellar: :any, arm64_ventura: "2436cd120e5678d67c24020a50cbbf7c0220e7ecaac63981335872b9d666bcad" sha256 cellar: :any, arm64_monterey: "a43a2ae4c44d90626b835a968a32327c8b8bbf754ec1d2590f8ac656c71dace9" sha256 cellar: :any, arm64_big_sur: "491220f1ff2c662b96295d931a80702523eeaee681d7305fb02b561e527dcbb8" + sha256 cellar: :any, ventura: "4c6488dfd53b8287702827a4e6d50569926417f2cd08613d37720de54b6afe0c" sha256 cellar: :any, monterey: "dddc6d8c871c92f6e5fb1249c28768aa2b4b47c38836a69cf787a639cf5eee73" sha256 cellar: :any, big_sur: "e566452815d2ff5dc66da160bd1cd3d9cf02a17a07284cf0bac46496133383ae" sha256 cellar: :any, catalina: "5ee7a460668864c28e541db15420e1480c3d31c5f216797a453a5310106fbc97" diff --git a/macOS/brewfiles/isl.rb b/macOS/brewfiles/isl.rb index 84038d63a898bdb920adcda1a45765dd15e33e48..474fb6ba3d322d11bac7dc0366c72d52174e6f9e 100644 --- a/macOS/brewfiles/isl.rb +++ b/macOS/brewfiles/isl.rb @@ -1,37 +1,29 @@ class Isl < Formula + # NOTE: Always use tarball instead of git tag for stable version. + # + # Currently isl detects its version using source code directory name + # and update isl_version() function accordingly. All other names will + # result in isl_version() function returning "UNKNOWN" and hence break + # package detection. desc "Integer Set Library for the polyhedral model" homepage "https://libisl.sourceforge.io/" + url "https://libisl.sourceforge.io/isl-0.26.tar.xz" + sha256 "a0b5cb06d24f9fa9e77b55fabbe9a3c94a336190345c2555f9915bb38e976504" license "MIT" - stable do - # NOTE: Always use tarball instead of git tag for stable version. - # - # Currently isl detects its version using source code directory name - # and update isl_version() function accordingly. All other names will - # result in isl_version() function returning "UNKNOWN" and hence break - # package detection. - url "https://libisl.sourceforge.io/isl-0.25.tar.xz" - sha256 "be7b210647ccadf90a2f0b000fca11a4d40546374a850db67adb32fad4b230d9" - - # Fix -flat_namespace being used on Big Sur and later. - patch do - url "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-big_sur.diff" - sha256 "35acd6aebc19843f1a2b3a63e880baceb0f5278ab1ace661e57a502d9d78c93c" - end - end - livecheck do url :homepage regex(/href=.*?isl[._-]v?(\d+(?:\.\d+)+)\.t/i) end bottle do - sha256 cellar: :any, arm64_monterey: "764bde8aa0d015c13cbf53891489f3ef56a5951f617ad9906aea34382dc1f4d1" - sha256 cellar: :any, arm64_big_sur: "24f86a50eea8a2d4dbc24ecb5f8b8ded61f6f7cd7054886b5dafcb82854b28ed" - sha256 cellar: :any, monterey: "568dd08209728ad3a036cf45287ff8384b9ed821460a216a9a79fa80fdcfbf52" - sha256 cellar: :any, big_sur: "be6456799bb670c16115d89feacf72cee9b444fe87aca6b1bd350bfb89ff6247" - sha256 cellar: :any, catalina: "c2ccd96c92ab0bbfdb775ccd7c8f20c2057cbe976769cf078e728b6f5f5938bc" - sha256 cellar: :any_skip_relocation, x86_64_linux: "c0244c95ed9cc89b826868de83bec3150fcc120add1265017176770150757083" + sha256 cellar: :any, arm64_ventura: "1814fe867c61b34cd5c763cf2ebda99d7883db78348c8b663f98cc95a1348d16" + sha256 cellar: :any, arm64_monterey: "0a3e83c458420e4b469ad7464d16d6c9cd26a888059358eb5f1f9d3cff54bbd7" + sha256 cellar: :any, arm64_big_sur: "a68a647249ad644cd8d1e1057bac65e5b4e1e08f9adaf15a07121853b0ed40cc" + sha256 cellar: :any, ventura: "0301489db7b26967657be0f6c89f11ea7e1e5fb50631686f86c597b01c00dc85" + sha256 cellar: :any, monterey: "0dcc555fd2517c6c93bca8999c741029bbdd821bfeb397505ec1f98deb79c551" + sha256 cellar: :any, big_sur: "91965ce2f54c7d1b16747ed05de989a3a122f5dbee67546bbf9bf065873b13c5" + sha256 cellar: :any_skip_relocation, x86_64_linux: "db14ba1e4ea23ab41e06930dcf25ae9023c5e395c88602da2a9b6a98d54c92d3" end head do diff --git a/macOS/brewfiles/libmpc.rb b/macOS/brewfiles/libmpc.rb index d987cd74c5a50570f7e6afc5ed7f85934dce6dee..8ce93a32b0b4c10b2df39a8bd439335e885f0103 100644 --- a/macOS/brewfiles/libmpc.rb +++ b/macOS/brewfiles/libmpc.rb @@ -1,33 +1,23 @@ class Libmpc < Formula desc "C library for the arithmetic of high precision complex numbers" homepage "http://www.multiprecision.org/mpc/" + url "https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz" + mirror "https://ftpmirror.gnu.org/mpc/mpc-1.3.1.tar.gz" + sha256 "ab642492f5cf882b74aa0cb730cd410a81edcdbec895183ce930e706c1c759b8" license "LGPL-3.0-or-later" - stable do - url "https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz" - mirror "https://ftpmirror.gnu.org/mpc/mpc-1.2.1.tar.gz" - sha256 "17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459" - - # Fix -flat_namespace being used on Big Sur and later. - patch do - url "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-big_sur.diff" - sha256 "35acd6aebc19843f1a2b3a63e880baceb0f5278ab1ace661e57a502d9d78c93c" - end - end - bottle do - sha256 cellar: :any, arm64_monterey: "658a1d260b6f77c431451a554ef8fa36ea2b6db19b38adc05c52821598ce2647" - sha256 cellar: :any, arm64_big_sur: "6a93bd78c1b55f8b29e11fd1e9c68c6c305ffe74aa5b978ba93189b6d84d1451" - sha256 cellar: :any, monterey: "b9984a72544255edf0c2d36dcb75d6adb7e68aa97233b005cf4120b36bb1fe6b" - sha256 cellar: :any, big_sur: "754667644cc287cd9691fd3215df260aa971562b5a7b6ca65e29b2e15ea1e656" - sha256 cellar: :any, catalina: "8c037df4b551058d00351676dc2c5ec395bd69c88545fac9ccfd0749dadb8ee2" - sha256 cellar: :any, mojave: "c229b6def61f4acc41b4b159d93dbc63a5c77f87f61623c9f7c5399da440cc4f" - sha256 cellar: :any, high_sierra: "939f0ad01d809356e33bdc70a8a8483eb1b021fd5f3723d0e61a2698af00f01b" - sha256 cellar: :any_skip_relocation, x86_64_linux: "d74eb5f1377d8fa72fad88baca1bd5f00c29d45ba186fbec89ad690c1d1f721f" + sha256 cellar: :any, arm64_ventura: "da4ff781bc469c82af17f98f0bdbf20932e222d0520ab784cd1b322b789ad7a5" + sha256 cellar: :any, arm64_monterey: "dd3994160b3625b1f14e34abf632b90bf49e71db1cc85c12e9ab529d4cae2a87" + sha256 cellar: :any, arm64_big_sur: "43bbe994c7bbb40f7172ef7a750bc6d2687275a76a25f67fc2d53ef00728d912" + sha256 cellar: :any, ventura: "aa4ddb0e50ace93746e6af2e6185493698b501e9359cf73ce41cfbb70369db09" + sha256 cellar: :any, monterey: "c32f2c3fe7ab06e308e6fa74874e1d4d92ff6eb3598da6e0f8e6fa7a333350f5" + sha256 cellar: :any, big_sur: "47b50c3df6a35ea3c876397eac4a7dc157b5f4109247671a16599a9a41b9c035" + sha256 cellar: :any_skip_relocation, x86_64_linux: "f6542ae5bcf643ca0c980c7000cde1585922e76be080b3cc3422dac0d4a50904" end head do - url "https://gitlab.inria.fr/mpc/mpc.git" + url "https://gitlab.inria.fr/mpc/mpc.git", branch: "master" depends_on "autoconf" => :build depends_on "automake" => :build depends_on "libtool" => :build @@ -37,15 +27,10 @@ class Libmpc < Formula depends_on "mpfr" def install - args = %W[ - --prefix=#{prefix} - --disable-dependency-tracking - --with-gmp=#{Formula["gmp"].opt_prefix} - --with-mpfr=#{Formula["mpfr"].opt_prefix} - ] - - system "autoreconf", "-fiv" if build.head? - system "./configure", *args + system "autoreconf", "--force", "--install", "--verbose" if build.head? + system "./configure", *std_configure_args, + "--with-gmp=#{Formula["gmp"].opt_prefix}", + "--with-mpfr=#{Formula["mpfr"].opt_prefix}" system "make" system "make", "check" system "make", "install" diff --git a/macOS/brewfiles/mpfr.rb b/macOS/brewfiles/mpfr.rb index f51f3d34dcabf22c7edb062ce005e79fc5fb479d..06c6b579a40c3f9eabc183aa9e676bc6f99a9136 100644 --- a/macOS/brewfiles/mpfr.rb +++ b/macOS/brewfiles/mpfr.rb @@ -4,30 +4,59 @@ class Mpfr < Formula license "LGPL-3.0-or-later" stable do - url "https://ftp.gnu.org/gnu/mpfr/mpfr-4.1.0.tar.xz" - mirror "https://ftpmirror.gnu.org/mpfr/mpfr-4.1.0.tar.xz" - sha256 "0c98a3f1732ff6ca4ea690552079da9c597872d30e96ec28414ee23c95558a7f" + url "https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.0.tar.xz" + mirror "https://ftpmirror.gnu.org/mpfr/mpfr-4.2.0.tar.xz" + sha256 "06a378df13501248c1b2db5aa977a2c8126ae849a9d9b7be2546fb4a9c26d993" + version "4.2.0-p9" - # Fix -flat_namespace being used on Big Sur and later. - patch do - url "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-big_sur.diff" - sha256 "35acd6aebc19843f1a2b3a63e880baceb0f5278ab1ace661e57a502d9d78c93c" + # Upstream patches, list at https://www.mpfr.org/mpfr-current/#fixed + %w[ + 01 2e465c31689e780a93b24bf2959917443fb882da85b7f1ef23ae53d3de614aa4 + 02 e1ef3d4dab999f4e0ad5ee046c3a2823d3a9395fb8092c3dcb85d3fe29994b52 + 03 a906f9ed8e4a7230980322a0154702664164690614e5ff55ae7049c3fae55584 + 04 ece14ee57596dc2e4f67d2e857c5c6b23d76b20183a50a8b6759b640df001b78 + 05 c4144564097a1be89c9cc2e7ee255c9fe59eb1b94a17c9d4a08169223e705ac1 + 06 70456748a8072265ba103d93ba94e9f93ae64565e6a5742194c56030086540fa + 07 472386aa5f8c51fbdf60154c19268ce2212be03e1c2f9004c1673b6c270508f6 + 08 6ecd3bd2edf178f4ede4be612964d1b2d0a0bb10ad6f8c51d1a8011fff87d5ea + 09 3e9aed5bcea95d34d0bd179a61cd7acb712c89c9a745535f18f0ef619833ba3b + ].each_slice(2) do |p, checksum| + patch do + url "https://www.mpfr.org/mpfr-4.2.0/patch#{p}" + sha256 checksum + end + end + end + + livecheck do + url "https://www.mpfr.org/mpfr-current/" + regex(/href=.*?mpfr[._-]v?(\d+(?:\.\d+)+)\.t/i) + strategy :page_match do |page, regex| + version = page.scan(regex).map { |match| Version.new(match[0]) }.max&.to_s + next if version.blank? + + patch = page.scan(%r{href=["']?/?patch(\d+)["' >]}i) + .map { |match| Version.new(match[0]) } + .max + &.to_s + next version if patch.blank? + + "#{version}-p#{patch.to_i}" end end bottle do - sha256 cellar: :any, arm64_monterey: "81ced499f237acfc2773711a3f8aa985572eaab2344a70485c06f72405e4a5e7" - sha256 cellar: :any, arm64_big_sur: "9df11560dd3650ffae35c134cef6e0e91aad0e862f5c8895c568b828cf0598d5" - sha256 cellar: :any, monterey: "7eb2f42b8f39d4f721620d1d54417e27fdb93c993e3ffd7e6ad43310cd84de1b" - sha256 cellar: :any, big_sur: "1e8eb0326f62d3461d420d98af6fc088daca481cae89fd77a75b420d2e76d776" - sha256 cellar: :any, catalina: "5fcf57834f58c18761c6c7b0eb961eb7f9fc54325b5361bf3a17c4dee6ebc08a" - sha256 cellar: :any, mojave: "93c0d2ca093819f125300002cd34c1d1b4dfb7a1403729205861bec21388ff12" - sha256 cellar: :any, high_sierra: "77581a1df66fb1ef55ffb19777d08b0b60fbc3d2d7ad491a8aceb3a6a4bf7ffd" - sha256 cellar: :any_skip_relocation, x86_64_linux: "4c5f1cfd038e8fbd640795e34e5e23c11244be3eca7781979600ec0d50bb9c0b" + sha256 cellar: :any, arm64_ventura: "176114984411aeb1187a50fd9ffc39d7dfe0bf5dc29ab13b0ecc95307d619ff9" + sha256 cellar: :any, arm64_monterey: "77a979ab547618549fc85a12212abd57b085b1712c53299847966d76a4e261f9" + sha256 cellar: :any, arm64_big_sur: "f5776604dbb68288c8dfe371e46398a671b6c34329ad473ada5d4e1fa7562086" + sha256 cellar: :any, ventura: "781d9c4887b8b18ccb96653ce59bb9aa5ee49dd1fb6c7d804750f58ce8726a2f" + sha256 cellar: :any, monterey: "a8eb9e75c01527d80843daba945a7581942362e689e3f3b7c6c891daa2655e9e" + sha256 cellar: :any, big_sur: "22360e6d89681f3d3d326a5654ab0cfb22d5ac42241c40e9f8f91eb06bb1b77c" + sha256 cellar: :any_skip_relocation, x86_64_linux: "d0cafd93a5957220615ae6478033031b750ba5eb6a830cf86d4cbde5bffec8d5" end head do - url "https://gitlab.inria.fr/mpfr/mpfr.git" + url "https://gitlab.inria.fr/mpfr/mpfr.git", branch: "master" depends_on "autoconf" => :build depends_on "automake" => :build depends_on "libtool" => :build @@ -50,16 +79,18 @@ class Mpfr < Formula #include <mpfr.h> #include <math.h> #include <stdlib.h> + #include <string.h> int main() { mpfr_t x, y; mpfr_inits2 (256, x, y, NULL); mpfr_set_ui (x, 2, MPFR_RNDN); - mpfr_root (y, x, 2, MPFR_RNDN); + mpfr_rootn_ui (y, x, 2, MPFR_RNDN); mpfr_pow_si (x, y, 4, MPFR_RNDN); mpfr_add_si (y, x, -4, MPFR_RNDN); mpfr_abs (y, y, MPFR_RNDN); if (fabs(mpfr_get_d (y, MPFR_RNDN)) > 1.e-30) abort(); + if (strcmp("#{version}", mpfr_get_version())) abort(); return 0; } EOS diff --git a/macOS/brewfiles/zstd.rb b/macOS/brewfiles/zstd.rb index 55ebf6b62aacecd5c4b01cac04a3371c2fa39bbe..09f2d358ed2a742d52a63962efef923b32b4002c 100644 --- a/macOS/brewfiles/zstd.rb +++ b/macOS/brewfiles/zstd.rb @@ -1,21 +1,26 @@ class Zstd < Formula desc "Zstandard is a real-time compression algorithm" homepage "https://facebook.github.io/zstd/" - url "https://github.com/facebook/zstd/archive/v1.5.2.tar.gz" - mirror "http://fresh-center.net/linux/misc/zstd-1.5.2.tar.gz" - mirror "http://fresh-center.net/linux/misc/legacy/zstd-1.5.2.tar.gz" - sha256 "f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e" + url "https://github.com/facebook/zstd/archive/v1.5.5.tar.gz" + mirror "http://fresh-center.net/linux/misc/zstd-1.5.5.tar.gz" + mirror "http://fresh-center.net/linux/misc/legacy/zstd-1.5.5.tar.gz" + sha256 "98e9c3d949d1b924e28e01eccb7deed865eefebf25c2f21c702e5cd5b63b85e1" license "BSD-3-Clause" head "https://github.com/facebook/zstd.git", branch: "dev" + livecheck do + url :stable + regex(/^v?(\d+(?:\.\d+)+)$/i) + end + bottle do - rebuild 3 - sha256 cellar: :any, arm64_monterey: "844b957a277cd93f70f8de91bd4caa21579f9b9e2f55bd5daf0334eee8ef1196" - sha256 cellar: :any, arm64_big_sur: "091743749cec2f0ae34482ae370aa5a563d6c7841c42fbc25e0d061863f5faa5" - sha256 cellar: :any, monterey: "b0eabfa556c5aed039a5b22cd7e2e3dd52c7d2416c1141e4a8e9e825b9238fc3" - sha256 cellar: :any, big_sur: "585bced60a658bfbda88d6a500fa26671871aa354f65cef767f17ea46209b4f2" - sha256 cellar: :any, catalina: "bdd2d3349fbcaa7e299cb6184f43e7f2bf29bd5936396d4c7c3d132bd687cd15" - sha256 cellar: :any_skip_relocation, x86_64_linux: "006b5ab6a4616a8b6f59953cb9efb546d312e3ba231c303bb56749e7f66f56df" + sha256 cellar: :any, arm64_ventura: "b709835f4cd5d339b97103f0dfa343489a02d2073f8e80ba7b04d682f1d29bd4" + sha256 cellar: :any, arm64_monterey: "e3cb579108afe4794143b33f24b6020648ca166f0104eb3d13cee56da62c949f" + sha256 cellar: :any, arm64_big_sur: "faf929cf92dad72eca2b16fb5aedb695f5d291aac18b496061b8b14003b2e224" + sha256 cellar: :any, ventura: "e4eb8cc0473c699ec424bfecc67fcfd30631f7fe5eacf26c727bfed73dcf7c12" + sha256 cellar: :any, monterey: "9c1cfe9158a48f6bd3eeb92608ed2799a048d1d27e70e7acef82d5eb4a7a1cea" + sha256 cellar: :any, big_sur: "73d78b5fef5ba31d3c37b8201310fe042f30c6000a97b8ba0d91208e1e1de231" + sha256 cellar: :any_skip_relocation, x86_64_linux: "68c8655224f058316c16462507b6cdd061bd546e161bf8419c68ca526d3a9a48" end depends_on "cmake" => :build @@ -35,6 +40,7 @@ class Zstd < Formula "-DZSTD_ZLIB_SUPPORT=ON", "-DZSTD_LZMA_SUPPORT=ON", "-DZSTD_LZ4_SUPPORT=ON", + "-DCMAKE_CXX_STANDARD=11", *std_cmake_args system "cmake", "--build", "builddir" system "cmake", "--install", "builddir" diff --git a/macOS/build.sh b/macOS/build.sh index 8be5b5551b10d58381a5f88ebc557f70888fc369..30e8c7abe3f42e9db93cf019158f91783036c62c 100755 --- a/macOS/build.sh +++ b/macOS/build.sh @@ -22,7 +22,7 @@ set -ex ROOTDIR=$(pwd)/.. # Set the GCC version -GCC_VERSION=12 +GCC_VERSION=13 # Set the compilers CC=gcc-$GCC_VERSION @@ -112,7 +112,7 @@ PKGFILES="$ROOTDIR"/macOS/pkg/"$NAME" mkdir -p \ "$PKGFILES"/preprocessor \ "$PKGFILES"/mex/matlab/maci64-8.3-9.3 \ - "$PKGFILES"/mex/matlab/maci64-9.4-9.13 \ + "$PKGFILES"/mex/matlab/maci64-9.4-9.14 \ "$PKGFILES"/doc \ "$PKGFILES"/scripts \ "$PKGFILES"/contrib/ms-sbvar/TZcode @@ -170,7 +170,7 @@ make clean --with-slicot="$LIB64"/Slicot/with-underscore \ --with-matlab=/Applications/MATLAB_R2022b.app make -j"$NTHREADS" -cp -L "$ROOTDIR"/mex/matlab/* "$PKGFILES"/mex/matlab/maci64-9.4-9.13 +cp -L "$ROOTDIR"/mex/matlab/* "$PKGFILES"/mex/matlab/maci64-9.4-9.14 ## diff --git a/macOS/deps/Makefile b/macOS/deps/Makefile index 42f511c93a14aceb493d053dbdd02ec4382f29ca..5b08d657760bbbd02cd5bb4a13d4d2ef2e73f258 100644 --- a/macOS/deps/Makefile +++ b/macOS/deps/Makefile @@ -1,4 +1,4 @@ -# Copyright © 2019-2022 Dynare Team +# Copyright © 2019-2023 Dynare Team # # This file is part of Dynare. # @@ -17,7 +17,7 @@ include versions.mk -GCC_VERSION = 12 +GCC_VERSION = 13 ROOT_PATH = $(realpath .) WGET_OPTIONS := --no-verbose --no-use-server-timestamps --retry-connrefused --retry-on-host-error diff --git a/matlab/+mom/run.m b/matlab/+mom/run.m index ccbb4bb3d5ac19c13950a5f34a56e2c976d1382f..720006edbbb9ebc9c7de4238b178e15cf1cbf334 100644 --- a/matlab/+mom/run.m +++ b/matlab/+mom/run.m @@ -62,8 +62,8 @@ function [oo_, options_mom_, M_] = run(bayestopt_, options_, oo_, estim_params_, % o set_state_space.m % o set_all_parameters.m % o test_for_deep_parameters_calibration.m -% ========================================================================= -% Copyright © 2020-2022 Dynare Team + +% Copyright © 2020-2023 Dynare Team % % This file is part of Dynare. % @@ -688,7 +688,7 @@ end old_steady_params=M_.params; %save initial parameters for check if steady state changes param values % Check steady state at initial model parameter values -[oo_.steady_state, new_steady_params, info] = evaluate_steady_state(oo_.steady_state,M_,options_mom_,oo_,steadystate_check_flag); +[oo_.steady_state, new_steady_params, info] = evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_mom_,steadystate_check_flag); if info(1) fprintf('\nmethod_of_moments: The steady state at the initial parameters cannot be computed.\n') print_info(info, 0, options_mom_); @@ -699,7 +699,7 @@ if isfield(estim_params_,'param_vals') && ~isempty(estim_params_.param_vals) Model_par_varied=M_; %store M_ structure Model_par_varied.params(estim_params_.param_vals(:,1))=Model_par_varied.params(estim_params_.param_vals(:,1))*1.01; %vary parameters - [~, new_steady_params_2] = evaluate_steady_state(oo_.steady_state,Model_par_varied,options_mom_,oo_,1); + [~, new_steady_params_2] = evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],Model_par_varied,options_mom_,true); changed_par_indices=find((old_steady_params(estim_params_.param_vals(:,1))-new_steady_params(estim_params_.param_vals(:,1))) ... | (Model_par_varied.params(estim_params_.param_vals(:,1))-new_steady_params_2(estim_params_.param_vals(:,1)))); diff --git a/matlab/@dprior/dprior.m b/matlab/@dprior/dprior.m new file mode 100644 index 0000000000000000000000000000000000000000..b56802586d506945736226ae9e4170220563358d --- /dev/null +++ b/matlab/@dprior/dprior.m @@ -0,0 +1,376 @@ +classdef dprior + + properties + p6 = []; % Prior first hyperparameter. + p7 = []; % Prior second hyperparameter. + p3 = []; % Lower bound of the prior support. + p4 = []; % Upper bound of the prior support. + 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; + end + + methods + + function o = dprior(BayesInfo, PriorTrunc, Uniform) + % Class constructor. + % + % INPUTS + % - BayesInfo [struct] Informations about the prior distribution, aka bayestopt_. + % - PriorTrunc [double] scalar, probability mass to be excluded, aka options_.prior_trunc + % - Uniform [logical] scalar, produce uniform random deviates on the prior support. + % + % OUTPUTS + % - o [dprior] scalar, prior object. + % + % REQUIREMENTS + % None. + o.p6 = BayesInfo.p6; + o.p7 = BayesInfo.p7; + o.p3 = BayesInfo.p3; + o.p4 = BayesInfo.p4; + bounds = prior_bounds(BayesInfo, PriorTrunc); + o.lb = bounds.lb; + o.ub = bounds.ub; + if nargin>2 && Uniform + prior_shape = repmat(5, length(o.p6), 1); + else + prior_shape = BayesInfo.pshape; + end + o.beta_index = find(prior_shape==1); + if ~isempty(o.beta_index) + o.beta_draws = true; + end + o.gamma_index = find(prior_shape==2); + if ~isempty(o.gamma_index) + o.gamma_draws = true; + end + o.gaussian_index = find(prior_shape==3); + if ~isempty(o.gaussian_index) + o.gaussian_draws = true; + end + o.inverse_gamma_1_index = find(prior_shape==4); + if ~isempty(o.inverse_gamma_1_index) + o.inverse_gamma_1_draws = true; + end + o.uniform_index = find(prior_shape==5); + if ~isempty(o.uniform_index) + o.uniform_draws = true; + end + o.inverse_gamma_2_index = find(prior_shape==6); + if ~isempty(o.inverse_gamma_2_index) + o.inverse_gamma_2_draws = true; + end + o.weibull_index = find(prior_shape==8); + if ~isempty(o.weibull_index) + o.weibull_draws = 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 % methods +end % classdef --*-- 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 + +%@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; +%$ +%$ 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:2 diff --git a/matlab/GetOneDraw.m b/matlab/GetOneDraw.m index ffd5665c90154a4b89ce53849bc8a2d4ca9c7e54..8c92a84ba70dac74984995a35d658ca067dd4c54 100644 --- a/matlab/GetOneDraw.m +++ b/matlab/GetOneDraw.m @@ -1,5 +1,5 @@ -function [xparams, logpost] = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_) -% function [xparams, logpost] = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_) +function [xparams, logpost] = GetOneDraw(distribution, M_, estim_params_, oo_, options_, bayestopt_) + % draws one parameter vector and its posterior from MCMC or the prior % % INPUTS @@ -18,7 +18,7 @@ function [xparams, logpost] = GetOneDraw(type,M_,estim_params_,oo_,options_,baye % SPECIAL REQUIREMENTS % none -% Copyright © 2005-2017 Dynare Team +% Copyright © 2005-2023 Dynare Team % % This file is part of Dynare. % @@ -35,12 +35,13 @@ function [xparams, logpost] = GetOneDraw(type,M_,estim_params_,oo_,options_,baye % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -switch type - case 'posterior' - [xparams, logpost] = metropolis_draw(0); - case 'prior' - xparams = prior_draw(); +if isprior(distribution) + xparams = distribution.draw(); if nargout>1 - logpost = evaluate_posterior_kernel(xparams',M_,estim_params_,oo_,options_,bayestopt_); + logpost = evaluate_posterior_kernel(xparams, M_, estim_params_, oo_, options_, bayestopt_); end -end \ No newline at end of file +elseif ischar(distribution) && strcmpi(distribution, 'posterior') + [xparams, logpost] = metropolis_draw(0); +else + error('GetOneDraw:: Wrong inputs.') +end diff --git a/matlab/PosteriorIRF_core1.m b/matlab/PosteriorIRF_core1.m index 2118704707ca69edfa29d4fd0fd4025effc07b4e..9b5122d14b496dcc09f2d621276f67737f1fd6e7 100644 --- a/matlab/PosteriorIRF_core1.m +++ b/matlab/PosteriorIRF_core1.m @@ -23,7 +23,7 @@ function myoutput=PosteriorIRF_core1(myinputs,fpar,B,whoiam, ThisMatlab) % SPECIAL REQUIREMENTS. % None. % -% Copyright © 2006-2019 Dynare Team +% Copyright © 2006-2023 Dynare Team % % This file is part of Dynare. % @@ -134,12 +134,17 @@ end % Parallel 'while' very good!!! stock_param=zeros(MAX_nruns,npar); stock_irf_dsge=zeros(options_.irf,nvar,M_.exo_nbr,MAX_nirfs_dsge); + +if strcmp(type, 'prior') + Prior = dprior(bayestopt_, options_.prior_trunc); +end + while fpar<B fpar = fpar + 1; irun = irun+1; irun2 = irun2+1; if strcmpi(type,'prior') - deep = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_); + deep = Prior.draw(); else deep = x(fpar,:); end @@ -294,7 +299,7 @@ end % directory on call machine that contain the model). myoutput.OutputFileName = [OutputFileName_dsge; - OutputFileName_param; - OutputFileName_bvardsge]; + OutputFileName_param; + OutputFileName_bvardsge]; myoutput.nosaddle = nosaddle; diff --git a/matlab/accessors/get_mean.m b/matlab/accessors/get_mean.m index 9311bd4a2b68140718fc90e4cc00a553e1ecae00..3c54cb98a89936f04ba68373d65614e88b7ba345 100644 --- a/matlab/accessors/get_mean.m +++ b/matlab/accessors/get_mean.m @@ -13,7 +13,7 @@ function y0 = get_mean(varargin) % SPECIAL REQUIREMENTS % none -% Copyright © 2019 Dynare Team +% Copyright © 2019-2023 Dynare Team % % This file is part of Dynare. % @@ -39,7 +39,7 @@ else end if order==1 ys_ = oo_.steady_state; - ys_ = evaluate_steady_state(ys_,M_,options_,oo_,1); + ys_ = evaluate_steady_state(ys_,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,true); elseif order==2 ys_ = oo_.dr.ys; ys_(oo_.dr.order_var)=ys_(oo_.dr.order_var)+oo_.dr.ghs2./2; diff --git a/matlab/add_path_to_mex_files.m b/matlab/add_path_to_mex_files.m index 0c7eb20be3b537e48b171e0a457593ae4d85617f..97548b1ea942e7e9f46f8128d3f0cec1f6010849 100644 --- a/matlab/add_path_to_mex_files.m +++ b/matlab/add_path_to_mex_files.m @@ -1,6 +1,6 @@ function mexpath = add_path_to_mex_files(dynareroot, modifypath) -% Copyright © 2015-2022 Dynare Team +% Copyright © 2015-2023 Dynare Team % % This file is part of Dynare. % @@ -60,7 +60,7 @@ else end end else - tmp = [dynareroot '../mex/matlab/win64-9.4-9.13/']; + tmp = [dynareroot '../mex/matlab/win64-9.4-9.14/']; if exist(tmp, 'dir') mexpath = tmp; if modifypath @@ -80,7 +80,7 @@ else end end else - tmp = [dynareroot '../mex/matlab/maci64-9.4-9.13']; + tmp = [dynareroot '../mex/matlab/maci64-9.4-9.14/']; if exist(tmp, 'dir') mexpath = tmp; if modifypath @@ -89,6 +89,15 @@ else end end end + if strcmp(computer, 'MACA64') + tmp = [dynareroot '../mex/matlab/maca64-9.14/']; + if exist(tmp, 'dir') + mexpath = tmp; + if modifypath + addpath(mexpath); + end + end + end % Add generic MATLAB path (with higher priority than the previous ones) if exist('mexpath') mexpath = { mexpath; [dynareroot '../mex/matlab/'] }; diff --git a/matlab/aggregate.m b/matlab/aggregate.m index ae3fc71e256da00cd1416d50aab7d35438bd3bd7..d42d87383f0fa28e7edb2a3a379017440e569ef3 100644 --- a/matlab/aggregate.m +++ b/matlab/aggregate.m @@ -21,7 +21,9 @@ function aggregate(ofile, dynopt, rootfolder, varargin) MAX_NUMBER_OF_ELEMENTS = 10000; -warning off MATLAB:subscripting:noSubscriptsSpecified +if ~isoctave && matlab_ver_less_than('9.14') % Warning removed in R2023a + warning off MATLAB:subscripting:noSubscriptsSpecified +end if ~isempty(dynopt) % Should be a list of options for the preprocessor in a cell @@ -318,8 +320,9 @@ end fprintf(fid, 'end;'); fclose(fid); -warning on MATLAB:subscripting:noSubscriptsSpecified - +if ~isoctave && matlab_ver_less_than('9.14') + warning on MATLAB:subscripting:noSubscriptsSpecified +end function b = isequationtag(str) b = true; diff --git a/matlab/backward/backward_model_forecast.m b/matlab/backward/backward_model_forecast.m index 87c6c424f0682c4d837df9fdf172d6547542f3f0..066df77573bcf6eaba343a07886a2d8ba3f51999 100644 --- a/matlab/backward/backward_model_forecast.m +++ b/matlab/backward/backward_model_forecast.m @@ -10,7 +10,7 @@ function forecasts = backward_model_forecast(initialcondition, listofvariables, % OUTPUTS % - forecast [dseries] -% Copyright © 2017-2018 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -63,7 +63,7 @@ for i=1:M_.exo_nbr end % Set up initial conditions -[initialcondition, periods, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, nx, ny1, iy1, jdx, model_dynamic, y] = ... +[initialcondition, periods, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, dynamic_resid, dynamic_g1, y] = ... simul_backward_model_init(initialcondition, periods, options_, M_, oo_, zeros(periods, M_.exo_nbr)); % Get vector of indices for the selected endogenous variables. @@ -91,10 +91,15 @@ end % Compute forecast without shock if options_.linear - ysim__0 = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, nx, ny1, iy1, jdx, model_dynamic); + [ysim__0, errorflag] = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); else - ysim__0 = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, iy1, model_dynamic); + [ysim__0, errorflag] = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); end + +if errorflag + error('Simulation failed.') +end + forecasts.pointforecast = dseries(transpose(ysim__0(idy,:)), initialcondition.init, listofvariables); % Set first period of forecast @@ -106,9 +111,12 @@ if withuncertainty for i=1:B innovations = transpose(sigma*randn(M_.exo_nbr, periods)); if options_.linear - [ysim__, xsim__] = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, nx, ny1, iy1, jdx, model_dynamic); + [ysim__, xsim__, errorflag] = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); else - [ysim__, xsim__] = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, iy1, model_dynamic); + [ysim__, xsim__, errorflag] = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); + end + if errorflag + error('Simulation failed.') end ArrayOfForecasts(:,:,i) = ysim__(idy,:); end @@ -120,4 +128,4 @@ if withuncertainty ArrayOfForecasts = sort(ArrayOfForecasts, 3); forecasts.lb = dseries(transpose(ArrayOfForecasts(:,:,round(0.025*B))), initialcondition.init, listofvariables); forecasts.ub = dseries(transpose(ArrayOfForecasts(:,:,round(0.975*B))), initialcondition.init, listofvariables); -end \ No newline at end of file +end diff --git a/matlab/backward/backward_model_inversion.m b/matlab/backward/backward_model_inversion.m index 3643c9aa90ea7f2130f208c97c3bd31d604b97b6..2b11559aafd00e9c4d0cc958ff9724ceedeaaf36 100644 --- a/matlab/backward/backward_model_inversion.m +++ b/matlab/backward/backward_model_inversion.m @@ -14,7 +14,7 @@ function [endogenousvariables, exogenousvariables] = backward_model_inversion(co % % REMARKS -% Copyright © 2017-2022 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -31,20 +31,17 @@ function [endogenousvariables, exogenousvariables] = backward_model_inversion(co % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -% Get indices for the calibrated and free innovations. +% Get indices for the free innovations. freeinnovations_id = zeros(length(freeinnovations), 1); if length(freeinnovations)<DynareModel.exo_nbr for i=1:length(freeinnovations) freeinnovations_id(i) = find(strcmp(freeinnovations{i}, exo_names)); end - calibratedinnovations_id = setdiff(transpose(1:length(exo_names)), freeinnovations_id); else freeinnovations_id = transpose(1:length(exo_names)); - calibratedinnovations_id = []; end nxfree = length(freeinnovations_id); -nxcalb = length(calibratedinnovations_id); % Get indices for the the controlled and free endogenous variables. controlledendogenousvariables_id = zeros(length(freeinnovations), 1); @@ -61,29 +58,18 @@ end nyfree = length(freeendogenousvariables_id); nyctrl = length(controlledendogenousvariables_id); -% Get indices of variables appearing at time t-1. -iy1 = find(DynareModel.lead_lag_incidence(1,:)>0); - -% Get indices of variables appearing at time t. -iy0 = find(DynareModel.lead_lag_incidence(2,:)>0); - -% Set indices for trust_region algorithm. -idx = 1:DynareModel.endo_nbr; -jdx = 1:(nyfree+nxfree); - % Build structure to be passed to the objective function. ModelInversion.nyfree = nyfree; ModelInversion.nyctrl = nyctrl; ModelInversion.nxfree = nxfree; -ModelInversion.nxcalb = nxcalb; -ModelInversion.y_constrained_id = vec(DynareModel.lead_lag_incidence(2,controlledendogenousvariables_id)); -ModelInversion.y_free_id = vec(DynareModel.lead_lag_incidence(2,freeendogenousvariables_id)); +ModelInversion.y_constrained_id = controlledendogenousvariables_id; +ModelInversion.y_free_id = freeendogenousvariables_id; ModelInversion.x_free_id = freeinnovations_id; -ModelInversion.J_id = [ModelInversion.y_free_id ; sum(DynareModel.lead_lag_incidence(:)>0)+ModelInversion.x_free_id]; +ModelInversion.J_id = [DynareModel.endo_nbr+ModelInversion.y_free_id ; 3*DynareModel.endo_nbr+ModelInversion.x_free_id]; -% Get the name of the dynamic model routines. -model_dynamic = str2func([DynareModel.fname,'.dynamic']); -model_dtransf = str2func('dynamic_backward_model_for_inversion'); +% Get function handles to the dynamic model routines. +dynamic_resid = str2func([DynareModel.fname '.sparse.dynamic_resid']); +dynamic_g1 = str2func([DynareModel.fname '.sparse.dynamic_g1']); % Initialization of the returned simulations (endogenous variables). Y = NaN(DynareModel.endo_nbr, nobs(constraints)); @@ -98,19 +84,18 @@ X = exogenousvariables{exo_names{:}}.data; % Inversion of the model, solvers for the free endogenous and exogenous variables (call a Newton-like algorithm in each period). ity = 2; itx = find(exogenousvariables.dates==constraints.dates(1)); -DynareOptions.solve_algo=4; for t = 1:nobs(constraints) % Set the lagged values of the endogenous variables. - ylag = Y(iy1,ity-1); + ylag = Y(:,ity-1); % Set the current values of the constrained endogenous variables. ycur = Y(controlledendogenousvariables_id,ity); % Vector z gather the free endogenous variables (initialized with lagged % values) and the free exogenous variables (initialized with 0). z = [Y(freeendogenousvariables_id,ity-1); zeros(nxfree, 1)]; % Solves for z. - [z, failed, ~, ~, errorcode] = dynare_solve(model_dtransf, z, ... + [z, failed, ~, ~, errorcode] = dynare_solve(@dynamic_backward_model_for_inversion, z, ... DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... - DynareOptions, model_dynamic, ylag, ycur, X, DynareModel.params, DynareOutput.steady_state, itx, ModelInversion); + DynareOptions, dynamic_resid, dynamic_g1, ylag, ycur, X(itx,:), DynareModel.params, DynareOutput.steady_state, DynareModel.dynamic_g1_sparse_rowval, DynareModel.dynamic_g1_sparse_colval, DynareModel.dynamic_g1_sparse_colptr, ModelInversion); if failed error('Nonlinear solver failed with errorcode=%i', errorcode) end @@ -126,4 +111,28 @@ for t = 1:nobs(constraints) end endogenousvariables = dseries(Y(:,2:end)', constraints.dates(1), endo_names); -exogenousvariables = dseries(X(find(exogenousvariables.dates==constraints.dates(1))+(0:(nobs(constraints)-1)),:), constraints.dates(1), exo_names); \ No newline at end of file +exogenousvariables = dseries(X(find(exogenousvariables.dates==constraints.dates(1))+(0:(nobs(constraints)-1)),:), constraints.dates(1), exo_names); + + +function [r, J] = dynamic_backward_model_for_inversion(z, dynamic_resid, dynamic_g1, ylag, ycur, x, params, steady_state, sparse_rowval, sparse_colval, sparse_colptr, ModelInversion) + +endo_nbr = ModelInversion.nyfree+ModelInversion.nyctrl; + +% Set up y +y = [ylag; zeros(2*endo_nbr, 1)]; + +y(endo_nbr+ModelInversion.y_constrained_id) = ycur; +if ModelInversion.nyfree + y(endo_nbr+ModelInversion.y_free_id) = z(1:ModelInversion.nyfree); +end + +% Update x +x(ModelInversion.x_free_id) = z(ModelInversion.nyfree+(1:ModelInversion.nxfree)); + +[r, T_order, T] = dynamic_resid(y, x, params, steady_state); + +if nargout>1 + Jacobian = dynamic_g1(y, x, params, steady_state, sparse_rowval, ... + sparse_colval, sparse_colptr, T_order, T); + J = Jacobian(:, ModelInversion.J_id); +end diff --git a/matlab/backward/backward_model_irf.m b/matlab/backward/backward_model_irf.m index 93b4fae717d1eb44fbec8bc9f328ec60df180786..c2accdee0fc2c882bdc274318254abb970661a4d 100644 --- a/matlab/backward/backward_model_irf.m +++ b/matlab/backward/backward_model_irf.m @@ -19,7 +19,7 @@ function [deviations, baseline, irfs] = backward_model_irf(initialcondition, inn % argument. % - If second argument is not empty, periods must not be greater than innovationbaseline.nobs. -% Copyright © 2017-2020 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -139,7 +139,7 @@ if ~isempty(innovationbaseline) end % Set up initial conditions -[initialcondition, periods, Innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, nx, ny1, iy1, jdx, model_dynamic, y] = ... +[initialcondition, periods, Innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, dynamic_resid, dynamic_g1, y] = ... simul_backward_model_init(initialcondition, periods, options_, M_, oo_, Innovations); % Get the covariance matrix of the shocks. @@ -163,9 +163,13 @@ irfs = struct(); % Baseline paths (get transition paths induced by the initial condition and % baseline innovations). if options_.linear - ysim__0 = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, Innovations, nx, ny1, iy1, jdx, model_dynamic); + [ysim__0, errorflag] = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, Innovations, dynamic_resid, dynamic_g1); else - ysim__0 = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, Innovations, iy1, model_dynamic); + [ysim__0, errorflag] = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, Innovations, dynamic_resid, dynamic_g1); +end + +if errorflag + error('Simulation failed. Cannot simulate baseline.') end % Transform the endogenous variables. @@ -198,9 +202,13 @@ for i=1:length(listofshocks) innovations(1,:) = innovations(1,:) + transpose(C(:,j)); end if options_.linear - ysim__1 = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, nx, ny1, iy1, jdx, model_dynamic); + [ysim__1, errorflag] = simul_backward_linear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); else - ysim__1 = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, iy1, model_dynamic); + [ysim__1, errorflag] = simul_backward_nonlinear_model_(initialcondition, periods, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); + end + if errorflag + warning('Simulation failed. Cannot compute IRF for %s.', listofshocks{i}) + continue end % Transform the endogenous variables if notransform @@ -230,4 +238,4 @@ end if nargout>1 baseline = dseries(transpose(endo_simul__0), initialcondition.init, endonames(1:M_.orig_endo_nbr), DynareModel.endo_names_tex(1:M_.orig_endo_nbr)); baseline = merge(baseline, innovationbaseline); -end \ No newline at end of file +end diff --git a/matlab/backward/calibrateresiduals.m b/matlab/backward/calibrateresiduals.m index 70b296a7f347079929fe20d17ac07d3b0758d384..d846300d250699c910e76d1dd887554ab4082c38 100644 --- a/matlab/backward/calibrateresiduals.m +++ b/matlab/backward/calibrateresiduals.m @@ -18,7 +18,7 @@ function [residuals, info] = calibrateresiduals(dbase, info, DynareModel) % The first two input arguments are the output of checkdatabaseforinversion % routine. -% Copyright © 2017-2020 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -38,7 +38,7 @@ function [residuals, info] = calibrateresiduals(dbase, info, DynareModel) displayresidualsequationmapping = false; % Get function handle for the dynamic model -model_dynamic = str2func([DynareModel.fname,'.dynamic']); +dynamic_resid = str2func([DynareModel.fname,'.sparse.dynamic_resid']); % Get data for all the endogenous variables. ydata = dbase{info.endonames{:}}.data; @@ -55,10 +55,8 @@ xdata = allexogenousvariables.data; % Evaluate the dynamic equation n = size(ydata, 2); -c = find(DynareModel.lead_lag_incidence'); -y = [ydata(1,:)'; ydata(2,:)']; -y = y(c); -r = model_dynamic(y, xdata, DynareModel.params, zeros(n, 1), 2); +y = [ydata(1,:)'; ydata(2,:)'; NaN(n, 1)]; +r = dynamic_resid(y, xdata(2,:), DynareModel.params, zeros(n, 1)); % Check that the number of equations evaluating to NaN matches the number of residuals idr = find(isnan(r)); @@ -104,7 +102,7 @@ for i = 1:residuals.vobs info.residualindex(i) = {strmatch(residualname, allexogenousvariables.name, 'exact')}; tmpxdata = xdata; tmpxdata(2, info.residualindex{i}) = 0; - r = model_dynamic(y, tmpxdata, DynareModel.params, zeros(n, 1), 2); + r = dynamic_resid(y, tmpxdata(2,:), DynareModel.params, zeros(n, 1)); info.equations(i) = { idr(find(~isnan(r(idr))))}; end @@ -131,8 +129,8 @@ end xdata(:,cell2mat(info.residualindex)) = 0; rdata = NaN(residuals.nobs, residuals.vobs); for t=2:size(xdata, 1) - y = transpose([ydata(t-1,:); ydata(t,:)]); - r = model_dynamic(y(c), xdata, DynareModel.params, zeros(n, 1), t); + y = [ydata(t-1,:)'; ydata(t,:)'; NaN(n, 1)]; + r = dynamic_resid(y, xdata(t,:), DynareModel.params, zeros(n, 1)); rdata(t,:) = transpose(r(cell2mat(info.equations))); end -residuals = dseries(rdata, dbase.init, info.residuals); \ No newline at end of file +residuals = dseries(rdata, dbase.init, info.residuals); diff --git a/matlab/backward/dynamic_backward_model_for_inversion.m b/matlab/backward/dynamic_backward_model_for_inversion.m deleted file mode 100644 index 4d25f9c19b462c1ed5d91bf437095bd639ebc8da..0000000000000000000000000000000000000000 --- a/matlab/backward/dynamic_backward_model_for_inversion.m +++ /dev/null @@ -1,39 +0,0 @@ -function [r, J] = dynamic_backward_model_for_inversion(z, dynamicmodel, ylag, ycur, x, params, steady_state, it_, ModelInversion) - -% Copyright © 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/>. - -% Set up y -y = zeros(length(ylag)+ModelInversion.nyfree+ModelInversion.nyctrl,1); -y(1:length(ylag)) = ylag; - -y(ModelInversion.y_constrained_id) = ycur; -if ModelInversion.nyfree - y(ModelInversion.y_free_id) = z(1:ModelInversion.nyfree); -end - -% Update x -x(it_, ModelInversion.x_free_id) = transpose(z(ModelInversion.nyfree+(1:ModelInversion.nxfree))); - -if nargout>1 - [r, Jacobian] = feval(dynamicmodel, y, x, params, steady_state, it_); -else - r = feval(dynamicmodel, y, x, params, steady_state, it_); - return -end - -J = Jacobian(:,ModelInversion.J_id); \ No newline at end of file diff --git a/matlab/backward/dynamic_backward_model_for_simulation.m b/matlab/backward/dynamic_backward_model_for_simulation.m index cf44d355c088e1f335de8bdb29f2f4fd76abccdc..54cbaf1f414506b65b0b0278a8d27ddd0f4af181 100644 --- a/matlab/backward/dynamic_backward_model_for_simulation.m +++ b/matlab/backward/dynamic_backward_model_for_simulation.m @@ -1,8 +1,8 @@ -function [r, J] = dynamic_backward_model_for_simulation(z, dynamicmodel, ylag, x, params, steady_state, it_) +function [r, J] = dynamic_backward_model_for_simulation(z, dynamic_resid, dynamic_g1, ylag, x, params, steady_state, sparse_rowval, sparse_colval, sparse_colptr) -% Dynamic routine's wrapper used by dynare_solve. +% Dynamic routine's wrapper used by dynare_solve for simulating backward models -% Copyright © 2017-2022 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -19,24 +19,15 @@ function [r, J] = dynamic_backward_model_for_simulation(z, dynamicmodel, ylag, x % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -% Get indices of the variables appearing at time t. -% NOTE: It is assumed that all variables appear at time t in the model. -idy = length(ylag)+(1:length(z)); +endo_nbr = length(z); % Build y vector to be passed to the dynamic model. -y = zeros(length(ylag)+length(z), 1); -y(1:length(ylag)) = ylag; -y(idy) = z; +y = [ ylag; z; NaN(endo_nbr, 1) ]; + +[r, T_order, T] = dynamic_resid(y, x, params, steady_state); if nargout>1 - % Compute residuals and jacobian of the full dynamic model. - [r, Jacobian] = feval(dynamicmodel, y, x, params, steady_state, it_); -else - % Compute residuals and return. - r = feval(dynamicmodel, y, x, params, steady_state, it_); - return + Jacobian = dynamic_g1(y, x, params, steady_state, sparse_rowval, ... + sparse_colval, sparse_colptr, T_order, T); + J = Jacobian(:, endo_nbr+(1:endo_nbr)); end - -% If the jacobian is computed, remove the columns related to the innovations -% and the variables appearing at time t-1. -J = Jacobian(:,idy); \ No newline at end of file diff --git a/matlab/backward/simul_backward_linear_model.m b/matlab/backward/simul_backward_linear_model.m index ea7dc2758a8d3a89fabee5ffd537a80d8aea36a2..57384ee885e6a020b5113282441b84d994dae259 100644 --- a/matlab/backward/simul_backward_linear_model.m +++ b/matlab/backward/simul_backward_linear_model.m @@ -1,4 +1,4 @@ -function simulations = simul_backward_linear_model(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations) +function [simulations, errorflag] = simul_backward_linear_model(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations) % Simulates a stochastic linear backward looking model. % @@ -12,6 +12,7 @@ function simulations = simul_backward_linear_model(initialconditions, samplesize % % OUTPUTS % - DynareOutput [struct] Dynare's oo_ global structure. +% - errorflag [logical] scalar, equal to false iff the simulation did not fail. % % REMARKS % [1] The innovations used for the simulation are saved in DynareOutput.exo_simul, and the resulting paths for the endogenous @@ -21,7 +22,7 @@ function simulations = simul_backward_linear_model(initialconditions, samplesize % [3] If the first input argument is empty, the endogenous variables are initialized with 0, or if available with the informations % provided thrtough the histval block. -% Copyright © 2012-2022 Dynare Team +% Copyright © 2012-2023 Dynare Team % % This file is part of Dynare. % @@ -50,9 +51,9 @@ if nargin<6 innovations = []; end -[initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, nx, ny1, iy1, jdx, model_dynamic] = ... +[initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, dynamic_resid, dynamic_g1] = ... simul_backward_model_init(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations); -[ysim, xsim] = simul_backward_linear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, nx, ny1, iy1, jdx, model_dynamic); +[ysim, xsim, errorflag] = simul_backward_linear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); -simulations = [dseries(ysim', initialconditions.init, endonames(1:DynareModel.orig_endo_nbr)), dseries(xsim, initialconditions.init, exonames)]; \ No newline at end of file +simulations = [dseries(ysim', initialconditions.init, endonames(1:DynareModel.orig_endo_nbr)), dseries(xsim, initialconditions.init, exonames)]; diff --git a/matlab/backward/simul_backward_linear_model_.m b/matlab/backward/simul_backward_linear_model_.m index 12f51254ab9b03a590627ae36a0543ace673e284..64c7a11963dea4ae811beb9a2e3608739da2928b 100644 --- a/matlab/backward/simul_backward_linear_model_.m +++ b/matlab/backward/simul_backward_linear_model_.m @@ -1,4 +1,4 @@ -function [ysim, xsim] = simul_backward_linear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, nx, ny1, iy1, jdx, model_dynamic) +function [ysim, xsim, errorflag] = simul_backward_linear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1) % Simulates a stochastic linear backward looking model. % @@ -12,6 +12,7 @@ function [ysim, xsim] = simul_backward_linear_model_(initialconditions, samplesi % % OUTPUTS % - DynareOutput [struct] Dynare's oo_ global structure. +% - errorflag [logical] scalar, equal to false iff the simulation did not fail. % % REMARKS % [1] The innovations used for the simulation are saved in DynareOutput.exo_simul, and the resulting paths for the endogenous @@ -21,7 +22,7 @@ function [ysim, xsim] = simul_backward_linear_model_(initialconditions, samplesi % [3] If the first input argument is empty, the endogenous variables are initialized with 0, or if available with the informations % provided thrtough the histval block. -% Copyright © 2017-2022 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -38,24 +39,34 @@ function [ysim, xsim] = simul_backward_linear_model_(initialconditions, samplesi % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. +errorflag = false; + if ~isempty(innovations) DynareOutput.exo_simul(initialconditions.nobs+(1:samplesize),:) = innovations; end % Get coefficients -[cst, jacob] = model_dynamic(zeros(DynareModel.endo_nbr+ny1,1), ... - zeros(DynareModel.orig_maximum_lag+1,DynareModel.exo_nbr), ... - DynareModel.params, ... - DynareOutput.steady_state, DynareModel.orig_maximum_lag+1); +y = [zeros(2*DynareModel.endo_nbr,1); NaN(DynareModel.endo_nbr,1)]; +x = zeros(DynareModel.exo_nbr, 1); +[cst, T_order, T] = dynamic_resid(y, x, DynareModel.params, DynareOutput.steady_state); +jacob = dynamic_g1(y, x, DynareModel.params, DynareOutput.steady_state, DynareModel.dynamic_g1_sparse_rowval, DynareModel.dynamic_g1_sparse_colval, DynareModel.dynamic_g1_sparse_colptr, T_order, T); + +try + A0inv = inv(jacob(:,DynareModel.endo_nbr+(1:DynareModel.endo_nbr))); +catch + errorflag = true; + ysim = []; + xsim = []; + return +end -A0inv = inv(jacob(:,jdx)); -A1 = jacob(:,nonzeros(DynareModel.lead_lag_incidence(1,:))); -B = jacob(:,end-nx+1:end); +A1 = jacob(:,1:DynareModel.endo_nbr); +B = jacob(:,3*DynareModel.endo_nbr+1:end); % Simulations for it = initialconditions.nobs+(1:samplesize) - DynareOutput.endo_simul(:,it) = -A0inv*(cst + A1*DynareOutput.endo_simul(iy1,it-1) + B*DynareOutput.exo_simul(it,:)'); + DynareOutput.endo_simul(:,it) = -A0inv*(cst + A1*DynareOutput.endo_simul(:,it-1) + B*DynareOutput.exo_simul(it,:)'); end ysim = DynareOutput.endo_simul(1:DynareModel.orig_endo_nbr,:); -xsim = DynareOutput.exo_simul; \ No newline at end of file +xsim = DynareOutput.exo_simul; diff --git a/matlab/backward/simul_backward_model.m b/matlab/backward/simul_backward_model.m index eb4f13088842dc7baca20d4439a4a54359e77ea2..0cf99c18e3082f108929a3df91a6c772c6584f3f 100644 --- a/matlab/backward/simul_backward_model.m +++ b/matlab/backward/simul_backward_model.m @@ -1,4 +1,4 @@ -function simulation = simul_backward_model(initialconditions, samplesize, innovations) +function [simulation, errorflag] = simul_backward_model(initialconditions, samplesize, innovations) % function simulation = simul_backward_model(initialconditions, samplesize, innovations) % Simulates a stochastic backward looking model (with arbitrary precision). % @@ -9,6 +9,7 @@ function simulation = simul_backward_model(initialconditions, samplesize, innova % % OUTPUTS % - simulation [dseries] Simulated endogenous and exogenous variables. +% - errorflag [logical] scalar, equal to false iff the simulation did not fail. % % REMARKS % [1] The innovations used for the simulation are saved in DynareOutput.exo_simul, and the resulting paths for the endogenous @@ -18,7 +19,7 @@ function simulation = simul_backward_model(initialconditions, samplesize, innova % [3] If the first input argument is empty, the endogenous variables are initialized with 0, or if available with the informations % provided through the histval block. -% Copyright © 2012-2022 Dynare Team +% Copyright © 2012-2023 Dynare Team % % This file is part of Dynare. % @@ -93,7 +94,7 @@ else end if options_.linear - simulation = simul_backward_linear_model(initialconditions, samplesize, options_, M_, oo_, Innovations); + [simulation, errorflag] = simul_backward_linear_model(initialconditions, samplesize, options_, M_, oo_, Innovations); else - simulation = simul_backward_nonlinear_model(initialconditions, samplesize, options_, M_, oo_, Innovations); + [simulation, errorflag] = simul_backward_nonlinear_model(initialconditions, samplesize, options_, M_, oo_, Innovations); end diff --git a/matlab/backward/simul_backward_model_init.m b/matlab/backward/simul_backward_model_init.m index ceecabf6d9f6daf0a3f6542785233ff8ae80d89a..447a2eee458fa42fc21c30d183fbe10cc977cc64 100644 --- a/matlab/backward/simul_backward_model_init.m +++ b/matlab/backward/simul_backward_model_init.m @@ -1,9 +1,9 @@ -function [initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, nx, ny1, iy1, jdx, model_dynamic, y] = ... +function [initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, dynamic_resid, dynamic_g1, y] = ... simul_backward_model_init(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations) % Initialization of the routines simulating backward models. -% Copyright © 2017-2019 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -190,14 +190,9 @@ end if nargout>8 - nx = size(DynareOutput.exo_simul,2); - ny0 = nnz(DynareModel.lead_lag_incidence(2,:)); - ny1 = nnz(DynareModel.lead_lag_incidence(1,:)); - iy1 = find(DynareModel.lead_lag_incidence(1,:)>0); - idx = 1:DynareModel.endo_nbr; - jdx = idx+ny1; - % Get the name of the dynamic model routine. - model_dynamic = str2func([DynareModel.fname,'.dynamic']); + % Get function handles to the dynamic model routines. + dynamic_resid = str2func([DynareModel.fname,'.sparse.dynamic_resid']); + dynamic_g1 = str2func([DynareModel.fname,'.sparse.dynamic_g1']); % initialization of vector y. - y = NaN(length(idx)+ny1,1); -end \ No newline at end of file + y = NaN(3*DynareModel.endo_nbr,1); +end diff --git a/matlab/backward/simul_backward_nonlinear_model.m b/matlab/backward/simul_backward_nonlinear_model.m index d4df3c39dfcfca9c7b3f4c3f9a2e2f2840b85409..db069b6826f5c8bc9dd69ab21bc829ecc5773ad1 100644 --- a/matlab/backward/simul_backward_nonlinear_model.m +++ b/matlab/backward/simul_backward_nonlinear_model.m @@ -1,4 +1,4 @@ -function simulations = simul_backward_nonlinear_model(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations) +function [simulations, errorflag] = simul_backward_nonlinear_model(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations) % function simulations = simul_backward_nonlinear_model(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations) % Simulates a stochastic non linear backward looking model with arbitrary precision (a deterministic solver is used). % @@ -12,6 +12,7 @@ function simulations = simul_backward_nonlinear_model(initialconditions, samples % % OUTPUTS % - simulation [dseries] Simulated endogenous and exogenous variables. +% - errorflag [logical] scalar, equal to false iff the simulation did not fail. % % REMARKS % [1] The innovations used for the simulation are saved in DynareOutput.exo_simul, and the resulting paths for the endogenous @@ -21,7 +22,7 @@ function simulations = simul_backward_nonlinear_model(initialconditions, samples % [3] If the first input argument is empty, the endogenous variables are initialized with 0, or if available with the informations % provided thrtough the histval block. -% Copyright (©) 2012-2022 Dynare Team +% Copyright (©) 2012-2023 Dynare Team % % This file is part of Dynare. % @@ -50,9 +51,9 @@ if nargin<6 innovations = []; end -[initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, ~, ~, iy1, ~, model_dynamic] = ... +[initialconditions, samplesize, innovations, DynareOptions, DynareModel, DynareOutput, endonames, exonames, dynamic_resid, dynamic_g1] = ... simul_backward_model_init(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations); -[ysim, xsim] = simul_backward_nonlinear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, iy1, model_dynamic); +[ysim, xsim, errorflag] = simul_backward_nonlinear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1); -simulations = [dseries(ysim', initialconditions.init, endonames(1:DynareModel.orig_endo_nbr)), dseries(xsim, initialconditions.init, exonames)]; \ No newline at end of file +simulations = [dseries(ysim', initialconditions.init, endonames(1:DynareModel.orig_endo_nbr)), dseries(xsim, initialconditions.init, exonames)]; diff --git a/matlab/backward/simul_backward_nonlinear_model_.m b/matlab/backward/simul_backward_nonlinear_model_.m index 024b8f1730ec8885f33c39bec30d0a4c6bce3936..e72f4c3160c154c88f3e48abe17d0498649329bb 100644 --- a/matlab/backward/simul_backward_nonlinear_model_.m +++ b/matlab/backward/simul_backward_nonlinear_model_.m @@ -1,4 +1,4 @@ -function [ysim, xsim] = simul_backward_nonlinear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, iy1, model_dynamic) +function [ysim, xsim, errorflag] = simul_backward_nonlinear_model_(initialconditions, samplesize, DynareOptions, DynareModel, DynareOutput, innovations, dynamic_resid, dynamic_g1) % Simulates a stochastic non linear backward looking model with arbitrary precision (a deterministic solver is used). % @@ -12,6 +12,7 @@ function [ysim, xsim] = simul_backward_nonlinear_model_(initialconditions, sampl % % OUTPUTS % - DynareOutput [struct] Dynare's oo_ global structure. +% - errorflag [logical] scalar, equal to false iff the simulation did not fail. % % REMARKS % [1] The innovations used for the simulation are saved in DynareOutput.exo_simul, and the resulting paths for the endogenous @@ -21,7 +22,7 @@ function [ysim, xsim] = simul_backward_nonlinear_model_(initialconditions, sampl % [3] If the first input argument is empty, the endogenous variables are initialized with 0, or if available with the informations % provided thrtough the histval block. -% Copyright © 2017-2022 Dynare Team +% Copyright © 2017-2023 Dynare Team % % This file is part of Dynare. % @@ -39,6 +40,7 @@ function [ysim, xsim] = simul_backward_nonlinear_model_(initialconditions, sampl % along with Dynare. If not, see <https://www.gnu.org/licenses/>. debug = false; +errorflag = false; if ~isempty(innovations) DynareOutput.exo_simul(initialconditions.nobs+(1:samplesize),:) = innovations; @@ -63,9 +65,9 @@ for it = initialconditions.nobs+(1:samplesize) end y_ = DynareOutput.endo_simul(:,it-1); y = y_; % A good guess for the initial conditions is the previous values for the endogenous variables. + x = DynareOutput.exo_simul(it,:); try if ismember(DynareOptions.solve_algo, [12,14]) - x = DynareOutput.exo_simul(it,:); T = NaN(DynareModel.block_structure.dyn_tmp_nbr); y_dynamic = [y_; y; NaN(DynareModel.endo_nbr, 1)]; for blk = 1:length(DynareModel.block_structure.block) @@ -93,13 +95,13 @@ for it = initialconditions.nobs+(1:samplesize) [DynareOutput.endo_simul(:,it), errorflag, ~, ~, errorcode] = ... dynare_solve(@dynamic_backward_model_for_simulation, y, ... DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... - DynareOptions, ... - model_dynamic, y_(iy1), DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it); + DynareOptions, dynamic_resid, dynamic_g1, y_, x, DynareModel.params, DynareOutput.steady_state, DynareModel.dynamic_g1_sparse_rowval, DynareModel.dynamic_g1_sparse_colval, DynareModel.dynamic_g1_sparse_colptr); if errorflag error('Nonlinear solver routine failed with errorcode=%i in period %i.', errorcode, it) end end catch Error + errorflag = true; DynareOutput.endo_simul = DynareOutput.endo_simul(:, 1:it-1); dprintf('Newton failed on iteration i = %s.', num2str(it-initialconditions.nobs)); ytm = DynareOutput.endo_simul(:,end); @@ -139,7 +141,7 @@ for it = initialconditions.nobs+(1:samplesize) % % Evaluate and check the residuals % - [r, J] = feval(@dynamic_backward_model_for_simulation, ytm, model_dynamic, ytm(iy1), DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it); + [r, J] = dynamic_backward_model_for_simulation(ytm, dynamic_resid, dynamic_g1, ytm, x, DynareModel.params, DynareOutput.steady_state, DynareModel.dynamic_g1_sparse_rowval, DynareModel.dynamic_g1_sparse_colval, DynareModel.dynamic_g1_sparse_colptr); residuals_evaluating_to_nan = isnan(r); residuals_evaluating_to_inf = isinf(r); residuals_evaluating_to_complex = ~isreal(r); diff --git a/matlab/default_option_values.m b/matlab/default_option_values.m index 309cb3177735e3e7221a413b6247b944d3a7f96f..e8442aa005d004f4041de460f655c8b79b6f7c3a 100644 --- a/matlab/default_option_values.m +++ b/matlab/default_option_values.m @@ -33,7 +33,6 @@ options_.datafile = ''; options_.dirname = M_.fname; options_.dataset = []; options_.verbosity = 1; -options_.terminal_condition = 0; options_.rplottype = 0; options_.smpl = 0; options_.dynatol.f = 1e-5; @@ -43,7 +42,6 @@ options_.gstep = ones(2,1); options_.gstep(1) = 1e-2; options_.gstep(2) = 1.0; options_.jacobian_tolerance = []; %tolerance for rank of Jacobian in model_diagnostics -options_.scalv = 1; options_.debug = false; options_.initval_file = false; options_.schur_vec_tol = 1e-11; % used to find nonstationary variables in Schur decomposition of the @@ -51,6 +49,7 @@ options_.schur_vec_tol = 1e-11; % used to find nonstationary variables in Schur options_.qz_criterium = []; options_.qz_zero_threshold = 1e-6; options_.lyapunov_complex_threshold = 1e-15; +options_.solve_algo = 4; options_.solve_tolf = eps^(1/3); options_.solve_tolx = eps^(2/3); options_.trust_region_initial_step_bound_factor = 1; @@ -328,16 +327,29 @@ options_.markowitz = 0.5; options_.minimal_solving_periods = 1; options_.endogenous_terminal_period = false; options_.no_homotopy = false; -options_.homotopy_alt_starting_point = false; +options_.simul.endval_steady = false; + +options_.simul.homotopy_max_completion_share = 1; +options_.simul.homotopy_min_step_size = 1e-3; +options_.simul.homotopy_step_size_increase_success_count = 3; +options_.simul.homotopy_initial_step_size = 1; +options_.simul.homotopy_linearization_fallback = false; +options_.simul.homotopy_marginal_linearization_fallback = 0; % Size of the step used for the marginal linearization; 0 means disabled + +% Options used by perfect_foresight_* commands when they compute the steady +% state corresponding to a terminal condition +options_.simul.steady_solve_algo = options_.solve_algo; +options_.simul.steady_maxit = options_.steady.maxit; +options_.simul.steady_tolf = options_.solve_tolf; +options_.simul.steady_tolx = options_.solve_tolx; +options_.simul.steady_markowitz = options_.markowitz; % Perfect foresight with expectation errors -options_.pfwee.terminal_steady_state_as_guess_value = false; options_.pfwee.constant_simulation_length = false; % Solution options_.order = 2; options_.pruning = false; -options_.solve_algo = 4; options_.replic = 50; options_.simul_replic = 1; options_.drop = 100; @@ -544,7 +556,7 @@ options_.hessian = hessian; csminwel.tolerance.f=1e-7; csminwel.maxiter=1000; csminwel.verbosity=1; -csminwel.Save_files=1; +csminwel.Save_files=false; options_.csminwel=csminwel; @@ -569,7 +581,7 @@ simplex.delta_factor=0.05; options_.simplex = simplex; % CMAES optimization routine. -cmaes.SaveVariables='on'; +cmaes.SaveVariables='off'; cmaes.DispFinal='on'; cmaes.WarnOnEqualFunctionValues='no'; cmaes.DispModulo='10'; @@ -686,7 +698,7 @@ options_.dr_logarithmic_reduction_maxiter = 100; options_.initial_date = dates(); % discretionary policy -options_.discretionary_policy = 0; +options_.discretionary_policy = false; options_.discretionary_tol = 1e-7; % Shock decomposition diff --git a/matlab/discretionary_policy/discretionary_policy.m b/matlab/discretionary_policy/discretionary_policy.m index 8e9701a6bfbe9f500316a5d87a66a4cd12191beb..3c57a91460f1d2782ebf5d93432e0e0bbd9cb636 100644 --- a/matlab/discretionary_policy/discretionary_policy.m +++ b/matlab/discretionary_policy/discretionary_policy.m @@ -12,7 +12,7 @@ function [info, oo_, options_, M_] = discretionary_policy(M_, options_, oo_, var % - options_ [structure] Matlab's structure describing the current options (options_). % - M_ [structure] Matlab's structure describing the model (M_). -% Copyright © 2007-2020 Dynare Team +% Copyright © 2007-2023 Dynare Team % % This file is part of Dynare. % @@ -32,7 +32,6 @@ function [info, oo_, options_, M_] = discretionary_policy(M_, options_, oo_, var M_=discretionary_policy_initialization(M_,options_); origorder = options_.order; -options_.discretionary_policy = 1; options_.order = 1; [info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list); diff --git a/matlab/display_problematic_vars_Jacobian.m b/matlab/display_problematic_vars_Jacobian.m index 07fe5ecf13d2bdb0e316b670a540ca6e1ce256bd..f204b421a877e4525e4305869b9fa3c0d425018e 100644 --- a/matlab/display_problematic_vars_Jacobian.m +++ b/matlab/display_problematic_vars_Jacobian.m @@ -16,7 +16,7 @@ function []=display_problematic_vars_Jacobian(problemrow,problemcol,M_,x,type,ca % none. % -% Copyright © 2014-2021 Dynare Team +% Copyright © 2014-2023 Dynare Team % % This file is part of Dynare. % @@ -37,7 +37,7 @@ skipline(); if nargin<6 caller_string=''; end -initial_aux_eq_nbr=M_.ramsey_eq_nbr; +initial_aux_eq_nbr=M_.ramsey_orig_endo_nbr; if strcmp(type,'dynamic') for ii=1:length(problemrow) if problemcol(ii)>max(M_.lead_lag_incidence) diff --git a/matlab/resid.m b/matlab/display_static_residuals.m similarity index 81% rename from matlab/resid.m rename to matlab/display_static_residuals.m index b7586ccea1490c72468cc91716cdd9e1edbef726..fd7f9b8352f899360c544d3a4732e4302607bd03 100644 --- a/matlab/resid.m +++ b/matlab/display_static_residuals.m @@ -1,5 +1,5 @@ -function z = resid(options_resid_) -% function z = resid(options_resid_) +function z = display_static_residuals(options_resid_) +% function z = display_static_residuals(options_resid_) % % Computes static residuals associated with the guess values. % @@ -12,7 +12,7 @@ function z = resid(options_resid_) % SPECIAL REQUIREMENTS % none -% Copyright © 2001-2022 Dynare Team +% Copyright © 2001-2023 Dynare Team % % This file is part of Dynare. % @@ -62,7 +62,7 @@ end if options_.steadystate_flag [oo_.steady_state,M_.params,info] = ... - evaluate_steady_state(oo_.steady_state,M_,options_,oo_,0); + evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,false); end % Compute the residuals @@ -93,15 +93,25 @@ if nargout == 0 fprintf('Residuals of the static equations%s:',disp_string) skipline() any_non_zero_residual = false; - for i=1:M_.orig_eq_nbr - if abs(z(i+M_.ramsey_eq_nbr)) < options_.solve_tolf/100 + if options_.ramsey_policy + first_eq = M_.ramsey_orig_endo_nbr+1; + last_eq = M_.ramsey_orig_endo_nbr+M_.ramsey_orig_eq_nbr; + elseif options_.discretionary_policy + first_eq = 1; + last_eq = M_.discretionary_orig_eq_nbr; + else + first_eq = 1; + last_eq = M_.orig_endo_nbr; + end + for i=first_eq:last_eq + if abs(z(i)) < options_.solve_tolf/100 tmp = 0; else - tmp = z(i+M_.ramsey_eq_nbr); + tmp = z(i); any_non_zero_residual = true; end if istag - tg = tags(cell2mat(tags(:,1)) == i+M_.ramsey_eq_nbr,2:3); % all tags for equation i + tg = tags(cell2mat(tags(:,1)) == i,2:3); % all tags for equation i ind = strmatch('name', cellstr( tg(:,1) ) ); end if ~(non_zero && tmp == 0) diff --git a/matlab/dyn_ramsey_static.m b/matlab/dyn_ramsey_static.m index f1ed495edf3f1850649795422e049fa33cf9acf7..9409b3ae9e1e67a90a6b0309e48bc2eec6b7f6cb 100644 --- a/matlab/dyn_ramsey_static.m +++ b/matlab/dyn_ramsey_static.m @@ -1,12 +1,20 @@ -function [steady_state, params, check] = dyn_ramsey_static(ys_init, M, options_, oo) +function [steady_state, params, check] = dyn_ramsey_static(ys_init, exo_ss, M, options_) % Computes the steady state for optimal policy % +% When there is no steady state file, relies on the fact that Lagrange +% multipliers appear linearly in the system to be solved. Instead of directly +% solving for the Lagrange multipliers along with the other variables, the +% algorithms reduces the size of the problem by always computing the value of +% the multipliers that minimizes the residuals, given the other variables +% (using a minimum norm solution, easy to compute because of the linearity +% property). + % INPUTS % ys_init: vector of endogenous variables or instruments +% exo_ss vector of exogenous steady state (incl. deterministic exogenous) % M: Dynare model structure % options: Dynare options structure -% oo: Dynare results structure % % OUTPUTS % steady_state: steady state value @@ -38,12 +46,9 @@ function [steady_state, params, check] = dyn_ramsey_static(ys_init, M, options_, params = M.params; check = 0; options_.steadystate.nocheck = 1; %locally disable checking because Lagrange multipliers are not accounted for in evaluate_steady_state_file - % dyn_ramsey_static_1 is a subfunction -nl_func = @(x) dyn_ramsey_static_1(x,M,options_,oo); -exo_ss = [oo.exo_steady_state oo.exo_det_steady_state]; +nl_func = @(x) dyn_ramsey_static_1(x,exo_ss,ys_init,M,options_); -% check_static_model is a subfunction -if ~options_.steadystate_flag && check_static_model(ys_init,M,options_,oo) +if ~options_.steadystate_flag && check_static_model(ys_init,exo_ss,M,options_) steady_state = ys_init; return elseif options_.steadystate_flag @@ -63,7 +68,7 @@ elseif options_.steadystate_flag end else %solve for instrument, using multivariate solver, starting at - %initial value for instrument + %initial value for instruments o_jacobian_flag = options_.jacobian_flag; options_.jacobian_flag = false; [inst_val, errorflag] = dynare_solve(nl_func, ys_init(k_inst), options_.ramsey.maxit, options_.solve_tolf, options_.solve_tolx, options_); @@ -76,8 +81,7 @@ elseif options_.steadystate_flag [xx,params] = evaluate_steady_state_file(ys_init,exo_ss,M,options_,~options_.steadystate.nocheck); %run steady state file again to update parameters [~,~,steady_state] = nl_func(inst_val); %compute and return steady state else - n_var = M.orig_endo_nbr; - xx = oo.steady_state(1:n_var); + xx = ys_init(1:M.orig_endo_nbr); o_jacobian_flag = options_.jacobian_flag; options_.jacobian_flag = false; [xx, errorflag] = dynare_solve(nl_func, xx, options_.ramsey.maxit, options_.solve_tolf, options_.solve_tolx, options_); @@ -89,81 +93,56 @@ else end - -function [resids,rJ,steady_state] = dyn_ramsey_static_1(x,M,options_,oo) +function [resids,rJ,steady_state] = dyn_ramsey_static_1(x,exo_ss,ys_init,M,options_) resids = []; rJ = []; mult = []; -% recovering usefull fields -params = M.params; -endo_nbr = M.endo_nbr; -endo_names = M.endo_names; -orig_endo_nbr = M.orig_endo_nbr; -aux_vars_type = [M.aux_vars.type]; -orig_endo_aux_nbr = orig_endo_nbr + min(find(aux_vars_type == 6)) - 1; -orig_eq_nbr = M.orig_eq_nbr; -inst_nbr = orig_endo_aux_nbr - orig_eq_nbr; -% indices of Lagrange multipliers -fname = M.fname; - -exo_ss = [oo.exo_steady_state oo.exo_det_steady_state]; +inst_nbr = M.ramsey_orig_endo_nbr - M.ramsey_orig_eq_nbr; if options_.steadystate_flag k_inst = []; - instruments = options_.instruments; - for i = 1:size(instruments,1) - k_inst = [k_inst; strmatch(instruments{i}, endo_names, 'exact')]; + for i = 1:size(options_.instruments,1) + k_inst = [k_inst; strmatch(options_.instruments{i}, M.endo_names, 'exact')]; end - ys_init=zeros(size(oo.steady_state)); %create starting vector for steady state computation as only instrument value is handed over ys_init(k_inst) = x; %set instrument, the only value required for steady state computation, to current value - [x,params,check] = evaluate_steady_state_file(ys_init,... %returned x now has size endo_nbr as opposed to input size of n_instruments - exo_ss, ... - M,options_,~options_.steadystate.nocheck); + [x,M.params,check] = evaluate_steady_state_file(ys_init,... %returned x now has size endo_nbr as opposed to input size of n_instruments + exo_ss, ... + M,options_,~options_.steadystate.nocheck); if any(imag(x(1:M.orig_endo_nbr))) %return with penalty resids=ones(inst_nbr,1)+sum(abs(imag(x(1:M.orig_endo_nbr)))); %return with penalty - steady_state=NaN(endo_nbr,1); + steady_state=NaN(M.endo_nbr,1); return end if check(1) %return resids=ones(inst_nbr,1)+sum(abs(x(1:M.orig_endo_nbr))); %return with penalty - steady_state=NaN(endo_nbr,1); + steady_state=NaN(M.endo_nbr,1); return end - end -xx = zeros(endo_nbr,1); %initialize steady state vector +xx = zeros(M.endo_nbr,1); %initialize steady state vector xx(1:M.orig_endo_nbr) = x(1:M.orig_endo_nbr); %set values of original endogenous variables based on steady state file or initial value -% setting steady state of auxiliary variables that depends on original endogenous variables +% Determine whether other auxiliary variables will need to be updated if any([M.aux_vars.type] ~= 6) %auxiliary variables other than multipliers - needs_set_auxiliary_variables = 1; - if M.set_auxiliary_variables - fh = str2func([M.fname '.set_auxiliary_variables']); - s_a_v_func = @(z) fh(z, exo_ss, params); - else - s_a_v_func = z; - end + needs_set_auxiliary_variables = true; + fh = str2func([M.fname '.set_auxiliary_variables']); + s_a_v_func = @(z) fh(z, exo_ss, M.params); xx = s_a_v_func(xx); else - needs_set_auxiliary_variables = 0; + needs_set_auxiliary_variables = false; end -% set multipliers and auxiliary variables that -% depends on multipliers to 0 to compute residuals -if (options_.bytecode) - [res, junk] = bytecode('static', xx, exo_ss, params, 'evaluate'); - fJ = junk.g1; +% Compute the value of the Lagrange multipliers that minimizes the norm of the +% residuals, given the other endogenous +if options_.bytecode + res = bytecode('static', xx, exo_ss, M.params, 'evaluate'); else - [res, T_order, T] = feval([fname '.sparse.static_resid'], xx, exo_ss, params); - fJ = feval([fname '.sparse.static_g1'], xx, exo_ss, params, M.static_g1_sparse_rowval, M.static_g1_sparse_colval, M.static_g1_sparse_colptr, T_order, T); + res = feval([M.fname '.sparse.static_resid'], xx, exo_ss, M.params); end -% index of multipliers and corresponding equations -% the auxiliary variables before the Lagrange multipliers are treated -% as ordinary endogenous variables -A = fJ(1:orig_endo_aux_nbr,orig_endo_nbr+find(aux_vars_type==6)); -y = res(1:orig_endo_aux_nbr); +A = feval([M.fname '.ramsey_multipliers_static_g1'], xx, exo_ss, M.params, M.ramsey_multipliers_static_g1_sparse_rowval, M.ramsey_multipliers_static_g1_sparse_colval, M.ramsey_multipliers_static_g1_sparse_colptr); +y = res(1:M.ramsey_orig_endo_nbr); mult = -A\y; resids1 = y+A*mult; @@ -177,18 +156,16 @@ end if options_.steadystate_flag resids = r1; else - resids = [res(orig_endo_nbr+(1:orig_endo_nbr-inst_nbr)); r1]; + resids = [res(M.ramsey_orig_endo_nbr+(1:M.orig_endo_nbr-inst_nbr)); r1]; end -rJ = []; if needs_set_auxiliary_variables - steady_state = s_a_v_func([xx(1:orig_endo_aux_nbr); mult]); + steady_state = s_a_v_func([xx(1:M.ramsey_orig_endo_nbr); mult]); else - steady_state = [xx(1:orig_endo_aux_nbr); mult]; + steady_state = [xx(1:M.ramsey_orig_endo_nbr); mult]; end -function result = check_static_model(ys,M,options_,oo) +function result = check_static_model(ys,exo_ss,M,options_) result = false; -exo_ss = [oo.exo_steady_state oo.exo_det_steady_state]; if (options_.bytecode) [res, ~] = bytecode('static', ys, exo_ss, M.params, 'evaluate'); else diff --git a/matlab/dynamic_static_model_for_simulation.m b/matlab/dynamic_static_model_for_simulation.m deleted file mode 100644 index cb70dbca8e41681821d7d3ebbf588d6d39afc334..0000000000000000000000000000000000000000 --- a/matlab/dynamic_static_model_for_simulation.m +++ /dev/null @@ -1,31 +0,0 @@ -function [r, J] = dynamic_static_model_for_simulation(z, dynamicmodel, x, params, steady_state, it_) - -% Dynamic routine's wrapper used by dynare_solve. - -% Copyright © 2021 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/>. - -% NOTE: It is assumed that all variables appear at time t in the model. - -if nargout>1 - % Compute residuals and jacobian of the full dynamic model. - [r, J] = feval(dynamicmodel, z, x, params, steady_state, it_); - J = J(:,1:rows(J)); % Remove derivatives with respect to shocks. -else - % Compute residuals. - r = feval(dynamicmodel, z, x, params, steady_state, it_); -end \ No newline at end of file diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index 2be5b45fde2a30c0077efb15abc1ac5d1c5effc7..2025734210eff681bbbb3c44e3168e3da6367ea8 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -488,7 +488,7 @@ if options_.analytic_derivation else steadystate_check_flag = 1; end - [tmp1, params] = evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag); + [tmp1, params] = evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M,options_,steadystate_check_flag); change_flag=any(find(params-M.params)); if change_flag skipline() @@ -561,7 +561,7 @@ ncn = estim_params_.ncn; if estim_params_.np M.params(estim_params_.param_vals(:,1)) = xparam1(nvx+ncx+nvn+ncn+1:end); end -[oo_.steady_state, params,info] = evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag); +[oo_.steady_state, params,info] = evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M,options_,steadystate_check_flag); if info(1) fprintf('\ndynare_estimation_init:: The steady state at the initial parameters cannot be computed.\n') @@ -688,3 +688,12 @@ if options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter options_.smoothed_state_uncertainty=false; end end + +if options_.occbin.smoother.status || options_.occbin.likelihood.status + if isfield(M_,'surprise_shocks') && ~isempty(M_.surprise_shocks) + fprintf('dynare_estimation_init: OccBin smoother/filter: previous shocks(surprise) block detected. Deleting its content.\n') + options_.occbin.simul.SHOCKS=zeros(1,M_.exo_nbr); + options_.occbin.simul.exo_pos=1:M_.exo_nbr; + M_.surprise_shocks=[]; + end +end diff --git a/matlab/dynare_identification.m b/matlab/dynare_identification.m index 89838b5d9ac4ac483326d524b5e2787aaa664166..0dd48f0714729f7039453dc300fb11b6084a5858 100644 --- a/matlab/dynare_identification.m +++ b/matlab/dynare_identification.m @@ -40,13 +40,14 @@ function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, ST % * identification_analysis % * isoctave % * plot_identification -% * prior_draw +% * dprior.draw % * set_default_option % * set_prior % * skipline % * vnorm % ========================================================================= -% Copyright © 2010-2022 Dynare Team + +% Copyright © 2010-2023 Dynare Team % % This file is part of Dynare. % @@ -328,18 +329,18 @@ if options_.discretionary_policy || options_.ramsey_policy options_ident.analytic_derivation_mode=-1; end end - + options_.analytic_derivation_mode = options_ident.analytic_derivation_mode; %overwrite setting in options_ -% initialize persistent variables in prior_draw +% Instantiate dprior object (Prior) if prior_exist if any(bayestopt_.pshape > 0) if options_ident.prior_range %sample uniformly from prior ranges (overwrite prior specification) - prior_draw(bayestopt_, options_.prior_trunc, true); + Prior = dprior(bayestopt_, options_.prior_trunc, true); else %sample from prior distributions - prior_draw(bayestopt_, options_.prior_trunc, false); + Prior = dprior(bayestopt_, options_.prior_trunc, false); end else options_ident.prior_mc = 1; %only one single point @@ -495,7 +496,7 @@ if iload <=0 kk=0; while kk<50 && info(1) kk=kk+1; - params = prior_draw(); + params = Prior.draw(); 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] = ... @@ -548,7 +549,7 @@ if iload <=0 if external_sample params = pdraws0(iteration+1,:); % loaded draws else - params = prior_draw(); % new random draw from prior + params = Prior.draw(); % new random draw from prior end options_ident.tittxt = []; % clear title text for graphs and figures % run identification analysis @@ -692,7 +693,7 @@ if iload <=0 end % store results for minimal system - if ~options_MC.no_identification_minimal + if ~options_MC.no_identification_minimal if ~error_indicator.identification_minimal STO_dMINIMAL(:,:,run_index) = ide_minimal.dMINIMAL; IDE_MINIMAL.cond(iteration,1) = ide_minimal.cond; @@ -901,7 +902,7 @@ if SampleSize > 1 store_nodisplay = options_.nodisplay; options_.nodisplay = 1; % HIGHEST CONDITION NUMBER - [~, jmax] = max(IDE_MOMENTS.cond); + [~, jmax] = max(IDE_MOMENTS.cond); tittxt = 'Draw with HIGHEST condition number'; fprintf('\nTesting %s.\n',tittxt); if ~iload diff --git a/matlab/dynare_sensitivity.m b/matlab/dynare_sensitivity.m index 0d04b3727bd02dc4aa27f988d8cc4fb044135335..3db43732a64b22411b203ecbb564834416d21a1a 100644 --- a/matlab/dynare_sensitivity.m +++ b/matlab/dynare_sensitivity.m @@ -90,6 +90,7 @@ if options_.order~=1 end original_prior_trunc = options_.prior_trunc; +original_qz_criterium = options_.qz_criterium; if ~isempty(options_gsa.datafile) || isempty(bayestopt_) || options_gsa.rmse if isempty(options_gsa.datafile) && options_gsa.rmse @@ -265,7 +266,7 @@ end if (options_gsa.load_stab || options_gsa.load_rmse || options_gsa.load_redform) && options_gsa.pprior filetoload=[OutputDirectoryName '/' fname_ '_prior.mat']; - if ~exist(filetoload) + if ~exist(filetoload,'file') disp([filetoload,' not found!']) disp(['You asked to load a non existent analysis']) %options_gsa.load_stab=0; @@ -436,6 +437,7 @@ if options_gsa.rmse end options_.opt_gsa = options_gsa; options_.prior_trunc=original_prior_trunc; +options_.qz_criterium=original_qz_criterium ; if options_gsa.glue @@ -450,7 +452,7 @@ if options_gsa.glue load([OutputDirectoryName,'/',fname_,'_mc']); end end - if ~exist('x') + if ~exist('x','var') disp(['No RMSE analysis is available for current options']) disp(['No GLUE file prepared']) return, diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m index 04266e61832b0e691fc8f43db081a52829133c92..4fe2cc55eb85da3279be57104318ae43a7119fa7 100644 --- a/matlab/dynare_solve.m +++ b/matlab/dynare_solve.m @@ -22,7 +22,7 @@ function [x, errorflag, fvec, fjac, errorcode] = dynare_solve(f, x, maxit, tolf, % -10 -> System of equation ill-behaved at the initial guess (Inf, Nans or complex numbers). % -11 -> Initial guess is a solution of the system of equations. -% Copyright © 2001-2022 Dynare Team +% Copyright © 2001-2023 Dynare Team % % This file is part of Dynare. % @@ -64,8 +64,9 @@ if jacobian_flag [fvec, fjac] = feval(f, x, varargin{:}); wrong_initial_guess_flag = false; if ~all(isfinite(fvec)) || any(isinf(fjac(:))) || any(isnan((fjac(:)))) || any(~isreal(fvec)) || any(~isreal(fjac(:))) - if ~ismember(options.solve_algo,[10,11]) && max(abs(fvec))< tolf + if ~ismember(options.solve_algo,[10,11]) && ~any(isnan(fvec)) && max(abs(fvec))< tolf % return if initial value solves the problem except if a mixed complementarity problem is to be solved (complementarity conditions may not be satisfied) + % max([NaN, 0])=0, so explicitly exclude the case where fvec contains a NaN errorcode = -11; return; end @@ -100,8 +101,9 @@ if jacobian_flag else fvec = feval(f, x, varargin{:}); fjac = zeros(nn, nn); - if ~ismember(options.solve_algo,[10,11]) && max(abs(fvec)) < tolf + if ~ismember(options.solve_algo,[10,11]) && ~any(isnan(fvec)) && max(abs(fvec)) < tolf % return if initial value solves the problem except if a mixed complementarity problem is to be solved (complementarity conditions may not be satisfied) + % max([NaN, 0])=0, so explicitly exclude the case where fvec contains a NaN errorcode = -11; return; end diff --git a/matlab/ep/extended_path_core.m b/matlab/ep/extended_path_core.m index 945b008cbe035a28fa2b1e0c7a8bed324978fba6..6cc5f8db91ea2fb6bb50a3a17468554002bdfecb 100644 --- a/matlab/ep/extended_path_core.m +++ b/matlab/ep/extended_path_core.m @@ -4,7 +4,7 @@ function [y, info_convergence, endogenousvariablespaths] = extended_path_core(pe debug,order,M,pfm,algo,solve_algo,stack_solve_algo,... olmmcp,options,oo,initialguess) -% Copyright © 2016-2020 Dynare Team +% Copyright © 2016-2023 Dynare Team % % This file is part of Dynare. % @@ -56,32 +56,25 @@ if order == 0 options.lmmcp = olmmcp; options.solve_algo = solve_algo; options.stack_solve_algo = stack_solve_algo; - tmp = perfect_foresight_solver_core(M, options, oo); - if ~tmp.deterministic_simulation.status - info_convergence = false; - else - info_convergence = true; - end + [endogenousvariablespaths, info_convergence] = perfect_foresight_solver_core(M, options, oo); else switch(algo) case 0 - [flag, tmp.endo_simul] = ... + [flag, endogenousvariablespaths] = ... solve_stochastic_perfect_foresight_model(endo_simul, exo_simul, pfm, ep.stochastic.quadrature.nodes, ep.stochastic.order); case 1 - [flag, tmp.endo_simul] = ... + [flag, endogenousvariablespaths] = ... solve_stochastic_perfect_foresight_model_1(endo_simul, exo_simul, options, pfm, ep.stochastic.order); end info_convergence = ~flag; end if ~info_convergence && ~options.no_homotopy - [info_convergence, tmp.endo_simul] = extended_path_homotopy(endo_simul, exo_simul, M, options, oo, pfm, ep, order, algo, 2, debug); + [info_convergence, endogenousvariablespaths] = extended_path_homotopy(endo_simul, exo_simul, M, options, oo, pfm, ep, order, algo, 2, debug); end if info_convergence - y = tmp.endo_simul(:,2); + y = endogenousvariablespaths(:,2); else y = NaN(size(endo_nbr,1)); end - -endogenousvariablespaths = tmp.endo_simul; diff --git a/matlab/ep/extended_path_homotopy.m b/matlab/ep/extended_path_homotopy.m index c6697dfe9811bd8f83a7a298fbb592f6c820a751..77fbf0e9f1d71b8447850a899c3724b6dd4a4e5b 100644 --- a/matlab/ep/extended_path_homotopy.m +++ b/matlab/ep/extended_path_homotopy.m @@ -1,6 +1,6 @@ function [info_convergence, endo_simul] = extended_path_homotopy(endo_simul, exo_simul, M, options, oo, pfm, ep, order, algo, method, debug) -% Copyright © 2016-2017 Dynare Team +% Copyright © 2016-2023 Dynare Team % % This file is part of Dynare. % @@ -35,20 +35,20 @@ if ismember(method, [1, 2]) oo.endo_simul(:,1) = oo.steady_state + weight*(endo_simul0(:,1) - oo.steady_state); oo.exo_simul = bsxfun(@plus, weight*exo_simul, (1-weight)*transpose(oo.exo_steady_state)); if order==0 - tmp = perfect_foresight_solver_core(M, options, oo); + [endo_simul_new, success] = perfect_foresight_solver_core(M, options, oo); else switch(algo) case 0 - [flag, tmp.endo_simul] = ... + [flag, endo_simul_new] = ... solve_stochastic_perfect_foresight_model(endo_simul, exo_simul, pfm, ep.stochastic.quadrature.nodes, ep.stochastic.order); case 1 - [flag, tmp.endo_simul] = ... + [flag, endo_simul_new] = ... solve_stochastic_perfect_foresight_model_1(endo_simul, exo_simul, options, pfm, ep.stochastic.order); end end if isequal(order, 0) % Logical variable flag is false iff the solver fails. - flag = ~tmp.deterministic_simulation.status; + flag = success; else % Fix convention issue on the value of flag. flag = ~flag; @@ -70,7 +70,7 @@ if ismember(method, [1, 2]) oldweight = weight; weight = min(weight*increase_factor, 1); increase_flag = true; - endo_simul = tmp.endo_simul; + endo_simul = endo_simul_new; else if increase_flag weight = oldweight + (weight-oldweight)/100; @@ -102,20 +102,20 @@ if isequal(method, 3) || (isequal(method, 2) && noconvergence) oo.endo_simul = endo_simul; oo.exo_simul = bsxfun(@plus, weight*exo_simul, (1-weight)*transpose(oo.exo_steady_state)); if order==0 - tmp = perfect_foresight_solver_core(M, options, oo); + [endo_simul_new, success] = perfect_foresight_solver_core(M, options, oo); else switch(algo) case 0 - [flag, tmp.endo_simul] = ... + [flag, endo_simul_new] = ... solve_stochastic_perfect_foresight_model(endo_simul, exo_simul, pfm, ep.stochastic.quadrature.nodes, ep.stochastic.order); case 1 - [flag, tmp.endo_simul] = ... + [flag, endo_simul_new] = ... solve_stochastic_perfect_foresight_model_1(endo_simul, exo_simul, options, pfm, ep.stochastic.order); end end if isequal(order, 0) % Logical variable flag is false iff the solver fails. - flag = ~tmp.deterministic_simulation.status; + flag = success; else % Fix convention issue on the value of flag. flag = ~flag; @@ -130,10 +130,10 @@ if isequal(method, 3) || (isequal(method, 2) && noconvergence) continue end index = index+1; - endo_simul = tmp.endo_simul; + endo_simul = endo_simul_new; else break end end info_convergence = ~noconvergence; -end \ No newline at end of file +end diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index b2be3d0545f1dbf427a3a4d29c85bcf3d9e6fbf0..c23f562adc7aab1c8f4fbc369dca0281e86df8b2 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -1,13 +1,13 @@ -function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadystate_check_flag) -% function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadystate_check_flag) +function [ys,params,info] = evaluate_steady_state(ys_init,exo_ss,M,options,steadystate_check_flag) +% function [ys,params,info] = evaluate_steady_state(ys_init,exo_ss,M,options,steadystate_check_flag) % Computes the steady state % % INPUTS % ys_init vector initial values used to compute the steady % state +% exo_ss vector exogenous steady state (incl. deterministic exogenous) % M struct model structure % options struct options -% oo struct output results % steadystate_check_flag boolean if true, check that the % steadystate verifies the % static model @@ -61,7 +61,6 @@ check = 0; steadystate_flag = options.steadystate_flag; params = M.params; -exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state]; if length(M.aux_vars) > 0 && ~steadystate_flag && M.set_auxiliary_variables h_set_auxiliary_variables = str2func([M.fname '.set_auxiliary_variables']); @@ -82,8 +81,7 @@ if options.ramsey_policy else [resids, ~ , jacob]= evaluate_static_model(ys,exo_ss,params,M,options); end - n_ramsey_equations=M.ramsey_eq_nbr; - nan_indices=find(isnan(resids(n_ramsey_equations+1:n_ramsey_equations+M.orig_eq_nbr))); % + nan_indices=find(isnan(resids(M.ramsey_orig_endo_nbr+(1:M.ramsey_orig_eq_nbr)))); if ~isempty(nan_indices) if options.debug @@ -106,7 +104,7 @@ if options.ramsey_policy return end - if any(imag(ys(n_ramsey_equations+1:n_ramsey_equations+M.orig_eq_nbr))) + if any(imag(ys(M.ramsey_orig_endo_nbr+(1:M.ramsey_orig_eq_nbr)))) if options.debug fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in complex numbers.\n') fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n') @@ -121,7 +119,7 @@ if options.ramsey_policy return end - if max(abs(resids(n_ramsey_equations+1:n_ramsey_equations+M.orig_eq_nbr))) > options.solve_tolf %does it solve for all variables except for the Lagrange multipliers + if max(abs(resids(M.ramsey_orig_endo_nbr+(1:M.ramsey_orig_eq_nbr)))) > options.solve_tolf %does it solve for all variables except for the Lagrange multipliers if options.debug fprintf('\nevaluate_steady_state: The steady state file does not solve the steady state for the Ramsey problem.\n') fprintf('evaluate_steady_state: Conditional on the following instrument values: \n') @@ -129,9 +127,9 @@ if options.ramsey_policy fprintf('\t %s \t %f \n',options.instruments{ii},ys_init(strmatch(options.instruments{ii},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: the following equations have non-zero residuals: \n') - for ii=n_ramsey_equations+1:M.endo_nbr + for ii=M.ramsey_orig_endo_nbr+1:M.endo_nbr if abs(resids(ii)) > options.solve_tolf - fprintf('\t Equation number %d: %f\n',ii-n_ramsey_equations, resids(ii)) + fprintf('\t Equation number %d: %f\n',ii-M.ramsey_orig_endo_nbr, resids(ii)) end end skipline(2) @@ -165,7 +163,7 @@ if options.ramsey_policy end end if steadystate_flag - nan_indices_mult=find(isnan(resids(1:n_ramsey_equations))); + nan_indices_mult=find(isnan(resids(1:M.ramsey_orig_endo_nbr))); if any(nan_indices_mult) fprintf('evaluate_steady_state: The steady state results NaN for auxiliary equation %u.\n',nan_indices_mult); fprintf('evaluate_steady_state: This is often a sign of problems.\n'); @@ -193,16 +191,15 @@ if options.ramsey_policy end %either if no steady state file or steady state file without problems - [ys,params,info] = dyn_ramsey_static(ys_init,M,options,oo); + [ys,params,info] = dyn_ramsey_static(ys_init,exo_ss,M,options); if info return end %check whether steady state really solves the model resids = evaluate_static_model(ys,exo_ss,params,M,options); - n_ramsey_equations=M.ramsey_eq_nbr; - nan_indices_multiplier=find(isnan(resids(1:n_ramsey_equations))); - nan_indices=find(isnan(resids(n_ramsey_equations+1:end))); + nan_indices_multiplier=find(isnan(resids(1:M.ramsey_orig_endo_nbr))); + nan_indices=find(isnan(resids(M.ramsey_orig_endo_nbr+1:end))); if ~isempty(nan_indices) if options.debug @@ -248,14 +245,14 @@ if options.ramsey_policy fprintf('\t %s \t %f \n',options.instruments{i},ys(strmatch(options.instruments{i},M.endo_names,'exact'))) end fprintf('evaluate_steady_state: The following equations have non-zero residuals: \n') - for ii=1:n_ramsey_equations + for ii=1:M.ramsey_orig_endo_nbr if abs(resids(ii)) > options.solve_tolf/100 fprintf('\t Auxiliary Ramsey equation number %d: %f\n',ii, resids(ii)) end end - for ii=n_ramsey_equations+1:M.endo_nbr + for ii=M.ramsey_orig_endo_nbr+1:M.endo_nbr if abs(resids(ii)) > options.solve_tolf/100 - fprintf('\t Equation number %d: %f\n',ii-n_ramsey_equations, resids(ii)) + fprintf('\t Equation number %d: %f\n',ii-M.ramsey_orig_endo_nbr, resids(ii)) end end skipline(2) @@ -364,7 +361,7 @@ elseif ~options.bytecode && options.block mfs_idx = M.block_structure_stat.block(b).variable(end-M.block_structure_stat.block(b).mfs+1:end); if options.solve_algo <= 4 || options.solve_algo >= 9 [ys(mfs_idx), errorflag] = dynare_solve(@block_mfs_steadystate, ys(mfs_idx), ... - options.simul.maxit, options.solve_tolf, options.solve_tolx, ... + options.steady.maxit, options.solve_tolf, options.solve_tolx, ... options, fh_static, b, ys, exo_ss, params, T, M); if errorflag check = 1; @@ -372,11 +369,11 @@ elseif ~options.bytecode && options.block end else nze = length(M.block_structure_stat.block(b).g1_sparse_rowval); - [ys, T, ~, info2] = solve_one_boundary(fh_static, ys, exo_ss, ... - params, [], T, mfs_idx, nze, 1, false, b, 0, options.simul.maxit, ... - options.solve_tolf, ... - 0, options.solve_algo, true, false, false, M, options, []); - if info2 + [ys, T, success] = solve_one_boundary(fh_static, ys, exo_ss, ... + params, [], T, mfs_idx, nze, 1, false, b, 0, options.steady.maxit, ... + options.solve_tolf, ... + 0, options.solve_algo, true, false, false, M, options); + if ~success check = 1; break end @@ -397,7 +394,10 @@ elseif options.bytecode ys = bytecode('static', ys_init, exo_ss, params); end catch ME - disp(ME.message); + if options.verbosity >= 1 + disp(ME.message); + end + ys = ys_init; check = 1; end elseif options.block @@ -408,7 +408,7 @@ elseif options.bytecode M.block_structure_stat.block(b).Simulation_Type ~= 2 mfs_idx = M.block_structure_stat.block(b).variable(end-M.block_structure_stat.block(b).mfs+1:end); [ys(mfs_idx), errorflag] = dynare_solve(@block_bytecode_mfs_steadystate, ... - ys(mfs_idx), options.simul.maxit, ... + ys(mfs_idx), options.steady.maxit, ... options.solve_tolf, options.solve_tolx, ... options, b, ys, exo_ss, params, T, M); if errorflag @@ -422,14 +422,16 @@ elseif options.bytecode [~, ~, ys, T] = bytecode(ys, exo_ss, params, ys, 1, ys, T, 'evaluate', 'static', ... 'block_decomposed', ['block = ' int2str(b)]); catch ME - disp(ME.message); + if options.verbosity >= 1 + disp(ME.message); + end check = 1; break end end else [ys, check] = dynare_solve(@bytecode_steadystate, ys_init, ... - options.simul.maxit, options.solve_tolf, options.solve_tolx, ... + options.steady.maxit, options.solve_tolf, options.solve_tolx, ... options, exo_ss, params); end end @@ -457,7 +459,7 @@ if M.static_and_dynamic_models_differ if options.bytecode z = repmat(ys,1,M.maximum_lead + M.maximum_lag + 1); zx = repmat([exo_ss'], M.maximum_lead + M.maximum_lag + 1, 1); - [r, ~]= bytecode('dynamic','evaluate', z, zx, params, ys, 1); + r = bytecode('dynamic','evaluate', z, zx, params, ys, 1); else r = feval([M.fname '.sparse.dynamic_resid'], repmat(ys, 3, 1), exo_ss, params, ys); end @@ -510,3 +512,4 @@ function [r, g1] = block_bytecode_mfs_steadystate(y, b, y_all, exo, params, T, M mfs_idx = M.block_structure_stat.block(b).variable(end-M.block_structure_stat.block(b).mfs+1:end); y_all(mfs_idx) = y; [r, g1] = bytecode(y_all, exo, params, y_all, 1, y_all, T, 'evaluate', 'static', 'block_decomposed', ['block = ' int2str(b) ]); +g1 = g1(:,end-M.block_structure_stat.block(b).mfs+1:end); % Make Jacobian square if mfs>0 diff --git a/matlab/evaluate_steady_state_file.m b/matlab/evaluate_steady_state_file.m index 485971ee7a110edba62ffcb899a231fe929c1b5f..4b6bfdc705423a17a19141624dcb669d61a33ae2 100644 --- a/matlab/evaluate_steady_state_file.m +++ b/matlab/evaluate_steady_state_file.m @@ -5,7 +5,7 @@ function [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,options, % INPUTS % ys_init vector initial values used to compute the steady % state -% exo_ss vector exogenous steady state +% exo_ss vector exogenous steady state (incl. deterministic exogenous) % M struct model parameters % options struct options % steady_state_checkflag boolean indicator whether to check steady state returned diff --git a/matlab/execute_prior_posterior_function.m b/matlab/execute_prior_posterior_function.m index 00cbe64e7dc10314adaf79987564641ef8f3c49f..3ac13f177edf5348d62b852de5f60e99349f917b 100644 --- a/matlab/execute_prior_posterior_function.m +++ b/matlab/execute_prior_posterior_function.m @@ -17,7 +17,7 @@ function oo_=execute_prior_posterior_function(posterior_function_name,M_,options % OUTPUTS % oo_ [structure] Matlab/Octave structure gathering the results (initialized by dynare, see @ref{oo_}). -% Copyright © 2013-2015 Dynare Team +% Copyright © 2013-2023 Dynare Team % % This file is part of Dynare. % @@ -47,21 +47,21 @@ end %Create function handle functionhandle=str2func(posterior_function_name); -prior = true; n_draws=options_.sampling_draws; -% Get informations about the _posterior_draws files. + if strcmpi(type,'posterior') - %% discard first mh_drop percent of the draws: + % Get informations about the _posterior_draws files. + % discard first mh_drop percent of the draws: CutSample(M_, options_, estim_params_); - %% initialize metropolis draws - options_.sub_draws=n_draws; %set draws for sampling; changed value is not returned to base workspace - [error_flag,~,options_]= metropolis_draw(1,options_,estim_params_,M_); + % initialize metropolis draws + options_.sub_draws = n_draws; % set draws for sampling; changed value is not returned to base workspace + [error_flag, ~, options_] = metropolis_draw(1, options_, estim_params_, M_); if error_flag error('EXECUTE_POSTERIOR_FUNCTION: The draws could not be initialized') end - n_draws=options_.sub_draws; - prior = false; + n_draws = options_.sub_draws; elseif strcmpi(type,'prior') + % Get informations about the prior distribution. if isempty(bayestopt_) if ~isempty(estim_params_) && ~(isfield(estim_params_,'nvx') && (size(estim_params_.var_exo,1)+size(estim_params_.var_endo,1)+size(estim_params_.corrx,1)+size(estim_params_.corrn,1)+size(estim_params_.param_vals,1))==0) [xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_); @@ -72,38 +72,36 @@ elseif strcmpi(type,'prior') if exist([M_.fname '_prior_restrictions.m']) warning('prior_function currently does not support endogenous prior restrictions. They will be ignored. Consider using a prior_function with nobs=1.') end - prior_draw(bayestopt_, options_.prior_trunc); + Prior = dprior(bayestopt_, options_.prior_trunc); else error('EXECUTE_POSTERIOR_FUNCTION: Unknown type!') end -%get draws for later use -first_draw=GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_); -parameter_mat=NaN(n_draws,length(first_draw)); -parameter_mat(1,:)=first_draw; -for draw_iter=2:n_draws - parameter_mat(draw_iter,:) = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_); +if strcmpi(type, 'prior') + parameter_mat = Prior.draws(n_draws); +else + parameter_mat = NaN(length(bayestopt_.p6), n_draws); + for i = 1:n_draws + parameter_mat(:,i) = GetOneDraw(type, M_, estim_params_, oo_, options_, bayestopt_); + end end -% get output size +% Get output size try - junk=functionhandle(parameter_mat(1,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info); + junk = functionhandle(parameter_mat(:,1), M_, options_, oo_, estim_params_, bayestopt_, dataset_, dataset_info); catch err fprintf('\nEXECUTE_POSTERIOR_FUNCTION: Execution of prior/posterior function led to an error. Execution cancelled.\n') rethrow(err) end -%initialize cell with number of columns -results_cell=cell(n_draws,size(junk,2)); +% Initialize cell with number of columns +results_cell = cell(n_draws, columns(junk)); -%% compute function on draws -for draw_iter = 1:n_draws - M_ = set_all_parameters(parameter_mat(draw_iter,:),estim_params_,M_); - [results_cell(draw_iter,:)]=functionhandle(parameter_mat(draw_iter,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info); +% Evaluate function on each draw +for i = 1:n_draws + M_ = set_all_parameters(parameter_mat(:,i), estim_params_, M_); + [results_cell(i,:)] = functionhandle(parameter_mat(:,i), M_, options_, oo_, estim_params_, bayestopt_, dataset_, dataset_info); end -if prior - oo_.prior_function_results = results_cell; -else - oo_.posterior_function_results = results_cell; -end +% Save results under oo_ +oo_.(sprintf('%s_function_results', type)) = results_cell; diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m index 93d1128256c239b0c5ba3311193c0ffd4e2a2b32..02549596cf5bbafcbd25deea1dc8ce289a5b1376 100644 --- a/matlab/gsa/filt_mc_.m +++ b/matlab/gsa/filt_mc_.m @@ -14,7 +14,7 @@ function [rmse_MC, ixx] = filt_mc_(OutDir,options_gsa_,dataset_,dataset_info) % marco.ratto@ec.europa.eu % Copyright © 2012-2016 European Commission -% Copyright © 2012-2022 Dynare Team +% Copyright © 2012-2023 Dynare Team % % This file is part of Dynare. % @@ -126,11 +126,11 @@ end if ~loadSA if exist('xparam1','var') M_ = set_all_parameters(xparam1,estim_params_,M_); - ys_mode=evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck); + ys_mode=evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,~options_.steadystate.nocheck); end if exist('xparam1_mean','var') M_ = set_all_parameters(xparam1_mean,estim_params_,M_); - ys_mean=evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck); + ys_mean=evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,~options_.steadystate.nocheck); end Y = transpose(dataset_.data); gend = dataset_.nobs; diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 325ca12b058a7a84e5b60e07fd8861ccd2eeefba..47adc09aa4efc12ec66980e59ddb4dbcb54fe7f6 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -20,7 +20,7 @@ function DynareResults = initial_estimation_checks(objective_function,xparam1,Dy % SPECIAL REQUIREMENTS % none -% Copyright © 2003-2022 Dynare Team +% Copyright © 2003-2023 Dynare Team % % This file is part of Dynare. % @@ -164,13 +164,13 @@ end old_steady_params=Model.params; %save initial parameters for check if steady state changes param values % % check if steady state solves static model (except if diffuse_filter == 1) -[DynareResults.steady_state, new_steady_params] = evaluate_steady_state(DynareResults.steady_state,Model,DynareOptions,DynareResults,DynareOptions.diffuse_filter==0); +[DynareResults.steady_state, new_steady_params] = evaluate_steady_state(DynareResults.steady_state,[DynareResults.exo_steady_state; DynareResults.exo_det_steady_state],Model,DynareOptions,DynareOptions.diffuse_filter==0); if isfield(EstimatedParameters,'param_vals') && ~isempty(EstimatedParameters.param_vals) %check whether steady state file changes estimated parameters Model_par_varied=Model; %store Model structure Model_par_varied.params(EstimatedParameters.param_vals(:,1))=Model_par_varied.params(EstimatedParameters.param_vals(:,1))*1.01; %vary parameters - [~, new_steady_params_2] = evaluate_steady_state(DynareResults.steady_state,Model_par_varied,DynareOptions,DynareResults,DynareOptions.diffuse_filter==0); + [~, new_steady_params_2] = evaluate_steady_state(DynareResults.steady_state,[DynareResults.exo_steady_state; DynareResults.exo_det_steady_state],Model_par_varied,DynareOptions,DynareOptions.diffuse_filter==0); changed_par_indices=find((old_steady_params(EstimatedParameters.param_vals(:,1))-new_steady_params(EstimatedParameters.param_vals(:,1))) ... | (Model_par_varied.params(EstimatedParameters.param_vals(:,1))-new_steady_params_2(EstimatedParameters.param_vals(:,1)))); @@ -228,20 +228,6 @@ if isfield(Model,'filter_initial_state') && ~isempty(Model.filter_initial_state) end end -if DynareOptions.ramsey_policy - %test whether specification matches - inst_nbr = size(DynareOptions.instruments,1); - if inst_nbr~=0 - orig_endo_aux_nbr = Model.orig_endo_nbr + min(find([Model.aux_vars.type] == 6)) - 1; - implied_inst_nbr = orig_endo_aux_nbr - Model.orig_eq_nbr; - if inst_nbr>implied_inst_nbr - error('You have specified more instruments than there are omitted equations') - elseif inst_nbr<implied_inst_nbr - error('You have specified fewer instruments than there are omitted equations') - end - end -end - if ~isreal(DynareDataset.data) error('initial_estimation_checks: the data contains complex values.') end @@ -329,4 +315,4 @@ end function evaluate_expression(expression,M_,oo_) % function evaluate_expression(expression,M_,oo_) %evaluates expressions relying on M_ and oo_ having their original names -eval(expression); \ No newline at end of file +eval(expression); diff --git a/matlab/dynamic_forward_model_for_simulation.m b/matlab/isprior.m similarity index 55% rename from matlab/dynamic_forward_model_for_simulation.m rename to matlab/isprior.m index 35e40dd318d13f6e1633bee7d5fad3cc6b3609df..a7a014b14b88b09057f67d91d50180f1f199662e 100644 --- a/matlab/dynamic_forward_model_for_simulation.m +++ b/matlab/isprior.m @@ -1,8 +1,8 @@ -function [r, J] = dynamic_forward_model_for_simulation(z, dynamicmodel, ylead, x, params, steady_state, it_) +function b = isprior(o) -% Dynamic routine's wrapper used by dynare_solve. +% Return True iff o is a dprior object. -% Copyright © 2022 Dynare Team +% Copyright © 2023 Dynare Team % % This file is part of Dynare. % @@ -19,11 +19,4 @@ function [r, J] = dynamic_forward_model_for_simulation(z, dynamicmodel, ylead, x % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -if nargout>1 - % Compute residuals and jacobian of the full dynamic model. - [r, J] = feval(dynamicmodel, [z; ylead], x, params, steady_state, it_); - J = J(:,1:length(z)); % Remove derivatives with respect to shocks. -else - % Compute residuals. - r = feval(dynamicmodel, [z; ylead], x, params, steady_state, it_); -end \ No newline at end of file +b = isa(o, 'dprior'); diff --git a/matlab/missing/mex/mjdgges/mjdgges.m b/matlab/missing/mex/mjdgges/mjdgges.m index 85f2b78a44282f74d928a607187ed6fb32d18a6b..b28214e9234bcaa17c28ea62b6be94601d9093fd 100644 --- a/matlab/missing/mex/mjdgges/mjdgges.m +++ b/matlab/missing/mex/mjdgges/mjdgges.m @@ -39,8 +39,8 @@ if nargin > 5 || nargin < 2 || nargout > 7 || nargout == 0 error('MJDGGES: takes 2, 3 or 4 input arguments and between 1 and 7 output arguments.') end -if isoctave - error('Octave unsupported, since it does not have real qz') +if isoctave && octave_ver_less_than('7') + error('Octave version 7 or higher is required (Octave 6 lacks the ordqz function)') end [me, ne] = size(e); @@ -56,7 +56,11 @@ end info = 0; try - [ss, tt, qq, zz] = qz(e, d, 'real'); + if isoctave && octave_ver_less_than('9') + [ss, tt, qq, zz] = qz(e, d); + else + [ss, tt, qq, zz] = qz(e, d, 'real'); + end eigval = ordeig(ss, tt); select = abs(eigval) < qz_criterium; sdim = sum(select); @@ -82,4 +86,4 @@ catch t(1) = 0; end T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m index 752d1416a8281100cc580512a68934ac0e4cc082..890a1bfaecb77ee574927c49f2aa29892286276b 100644 --- a/matlab/model_diagnostics.m +++ b/matlab/model_diagnostics.m @@ -41,8 +41,7 @@ if options.ramsey_policy %test whether specification matches inst_nbr = size(options.instruments,1); if inst_nbr~=0 - orig_endo_aux_nbr = M.orig_endo_nbr + min(find([M.aux_vars.type] == 6)) - 1; - implied_inst_nbr = orig_endo_aux_nbr - M.orig_eq_nbr; + implied_inst_nbr = M.ramsey_orig_endo_nbr - M.ramsey_orig_eq_nbr; if inst_nbr>implied_inst_nbr warning('You have specified more steady state instruments than there are omitted equations. While there are use cases for this setup, it is rather unusual. Check whether this is desired.') elseif inst_nbr<implied_inst_nbr @@ -112,7 +111,7 @@ if options.logged_steady_state %if steady state was previously logged, undo this oo.steady_state=exp(oo.steady_state); options.logged_steady_state=0; end -[dr.ys,M.params,check1]=evaluate_steady_state(oo.steady_state,M,options,oo,options.steadystate.nocheck); +[dr.ys,M.params,check1]=evaluate_steady_state(oo.steady_state,[oo.exo_steady_state; oo.exo_det_steady_state],M,options,options.steadystate.nocheck); % testing for problem if check1(1) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index 72c81ac028822bd0985c5b03d1f61b501efbcbeb..09846315f31dec7050bc1302eae7a07720dd253e 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit 72c81ac028822bd0985c5b03d1f61b501efbcbeb +Subproject commit 09846315f31dec7050bc1302eae7a07720dd253e diff --git a/matlab/modules/reporting b/matlab/modules/reporting index cfbeb9a12d6b859c4a1321225fab010a7f2f5046..8800d4459299fde7362dd2ccce64b0a96477aa68 160000 --- a/matlab/modules/reporting +++ b/matlab/modules/reporting @@ -1 +1 @@ -Subproject commit cfbeb9a12d6b859c4a1321225fab010a7f2f5046 +Subproject commit 8800d4459299fde7362dd2ccce64b0a96477aa68 diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 6a0ef6e857e85bd4ec26693b5680a70fe57626ff..5ad84e1ee9798d57d5a5e6f50733ff7fe1613472 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -353,9 +353,9 @@ switch minimizer_algorithm [opt_par_values,fval,exitflag] = fminsearch(objective_function,start_par_value,optim_options,varargin{:}); else % Under Octave, use a wrapper, since fminsearch() does not have a - % 4th arg, and only has two output args + % 4th arg. func = @(x) objective_function(x,varargin{:}); - [opt_par_values,fval] = fminsearch(func,start_par_value,optim_options); + [opt_par_values,fval,exitflag] = fminsearch(func,start_par_value,optim_options); end case 8 % Dynare implementation of the simplex algorithm. diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m index 1455c08cd56e68645742c1578b9495fea013f0e3..e9a7f8070fc2fc80d134a2120cc028423cd2cfa4 100644 --- a/matlab/parallel/masterParallel.m +++ b/matlab/parallel/masterParallel.m @@ -362,7 +362,7 @@ if parallel_recover ==0 itmp = bitset(itmp,cpus(icpu)); end hex_affinity = dec2hex(itmp); - token1 = ['start /B /D "',DyMo, '" /affinity ',hex_affinity,' /LOW ']; + token1 = ['start "" /B /D "',DyMo, '" /affinity ',hex_affinity,' /LOW ']; end if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=[token1,Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; @@ -378,7 +378,7 @@ if parallel_recover ==0 if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)) % Hybrid computing Windows <-> Unix! if ispc - token='start /B '; + token='start "" /B '; else token = ''; end @@ -444,7 +444,7 @@ if parallel_recover ==0 itmp = bitset(itmp,cpus(icpu)); end hex_affinity = dec2hex(itmp); - token1 = ['start /B /D "',DyMo, '" /affinity ',hex_affinity,' /LOW ']; + token1 = ['start "" /B /D "',DyMo, '" /affinity ',hex_affinity,' /LOW ']; end if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') command1=[token1,Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; @@ -464,7 +464,7 @@ if parallel_recover ==0 dynareParallelSendFiles(['slaveParallel_input',int2str(j),'.mat'],PRCDir,Parallel(indPC)) if (~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem)) % Hybrid computing Windows <-> Unix! if ispc - token='start /B '; + token='start "" /B '; else token = ''; end diff --git a/matlab/partial_information/PI_gensys.m b/matlab/partial_information/PI_gensys.m index 3fe2c16ba4b896b7104afc4b43e26fb42479df6a..42ee00f8abb8fb6a821f1c8a66eb4147b3d163a7 100644 --- a/matlab/partial_information/PI_gensys.m +++ b/matlab/partial_information/PI_gensys.m @@ -16,7 +16,7 @@ function [G1pi,C,impact,nmat,TT1,TT2,gev,eu, DD, E2, E5, GAMMA, FL_RANK ]=PI_gen % Corrected 10/28/96 by CAS % Copyright © 1996-2009 Christopher Sims -% Copyright © 2010-2017 Dynare Team +% Copyright © 2010-2023 Dynare Team % % This file is part of Dynare. % @@ -176,8 +176,8 @@ end G0pi=eye(n+FL_RANK+NX); try - if isoctave - % Need to force QZ complex on Octave (otherwise it returns the real one) + if isoctave && octave_ver_less_than('9') + % Need to force QZ complex on Octave ⩽ 8 (otherwise it returns the real one) [a b q z]=qz(complex(G0pi),complex(G1pi)); else [a b q z]=qz(G0pi,G1pi); diff --git a/matlab/particles b/matlab/particles index 7926e75aa525b73c91bbb944d19556c43a8fbbe6..bb16df7f2e6ddbc81e23b9661ee100f5e8dc675a 160000 --- a/matlab/particles +++ b/matlab/particles @@ -1 +1 @@ -Subproject commit 7926e75aa525b73c91bbb944d19556c43a8fbbe6 +Subproject commit bb16df7f2e6ddbc81e23b9661ee100f5e8dc675a diff --git a/matlab/perfect-foresight-models/det_cond_forecast.m b/matlab/perfect-foresight-models/det_cond_forecast.m index 623d2e565ede26b36841064a81f84d8ce83a9ce2..7d33f13f5dbfb9309f235cdfc503fc8fc28f9258 100644 --- a/matlab/perfect-foresight-models/det_cond_forecast.m +++ b/matlab/perfect-foresight-models/det_cond_forecast.m @@ -473,12 +473,12 @@ if pf && ~surprise data1 = M_; if (options_.bytecode) if options_.block - [zz, data1]= bytecode('dynamic','block_decomposed','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); + [~, data1]= bytecode('dynamic','block_decomposed','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); else - [zz, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); + [~, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); end else - [zz, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k); + [~, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k); data1.g1_x = g1b(:,end - M_.exo_nbr + 1:end); data1.g1 = g1b(:,1 : end - M_.exo_nbr); end @@ -740,12 +740,12 @@ else data1 = M_; if (options_.bytecode) if options_.block - [zz, data1]= bytecode('dynamic','block_decomposed','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); + [~, data1]= bytecode('dynamic','block_decomposed','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); else - [zz, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); + [~, data1]= bytecode('dynamic','evaluate', z, zx, M_.params, oo_.steady_state, k, data1); end else - [zz, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k); + [~, g1b] = feval([M_.fname '.dynamic'], z', zx, M_.params, oo_.steady_state, k); data1.g1_x = g1b(:,end - M_.exo_nbr + 1:end); data1.g1 = g1b(:,1 : end - M_.exo_nbr); end diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index db0e04fbf5483e383a97d51896621c15a75bd25a..f187b9dc2e38ddd6e7a7449b581c592d7d20c527 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -12,7 +12,7 @@ function perfect_foresight_setup() % SPECIAL REQUIREMENTS % none -% Copyright © 1996-2021 Dynare Team +% Copyright © 1996-2023 Dynare Team % % This file is part of Dynare. % @@ -64,5 +64,9 @@ if ~isempty(M_.det_shocks) && options_.periods<max([M_.det_shocks.periods]) error('PERFECT_FORESIGHT_SETUP: Please check the declaration of the shocks or increase the value of the periods option.') end +if options_.simul.endval_steady && M_.maximum_lead == 0 + error('PERFECT_FORESIGHT_SETUP: Option endval_steady cannot be used on a purely backward or static model.') +end + oo_ = make_ex_(M_,options_,oo_); -oo_ = make_y_(M_,options_,oo_); \ No newline at end of file +oo_ = make_y_(M_,options_,oo_); diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver.m b/matlab/perfect-foresight-models/perfect_foresight_solver.m index f11c069e3f4ca5f12e05bc5c557bd2d1d18ef3bb..d412afb30122659873708df3efbefbb9166657db 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver.m @@ -33,14 +33,8 @@ global M_ options_ oo_ ys0_ ex0_ check_input_arguments(options_, M_, oo_); -if isempty(options_.scalv) || options_.scalv == 0 - options_.scalv = oo_.steady_state; -end - periods = options_.periods; -options_.scalv= 1; - if options_.debug model_static = str2func([M_.fname,'.static']); for ii=1:size(oo_.exo_simul,1) @@ -57,192 +51,329 @@ if options_.debug end end -initperiods = 1:M_.maximum_lag; -lastperiods = (M_.maximum_lag+periods+1):(M_.maximum_lag+periods+M_.maximum_lead); +% Various sanity checks -oo_ = perfect_foresight_solver_core(M_,options_,oo_); +if options_.no_homotopy && (options_.simul.homotopy_initial_step_size ~= 1 ... + || options_.simul.homotopy_max_completion_share ~= 1 ... + || options_.simul.homotopy_linearization_fallback ... + || options_.simul.homotopy_marginal_linearization_fallback ~= 0) + error('perfect_foresight_solver: the no_homotopy option is incompatible with homotopy_initial_step_size, homotopy_max_completion_share, homotopy_linearization_fallback and homotopy_marginal_linearization_fallback options') +end -% If simulation failed try homotopy. -if ~oo_.deterministic_simulation.status && ~options_.no_homotopy +if options_.simul.homotopy_initial_step_size > 1 || options_.simul.homotopy_initial_step_size < 0 + error('perfect_foresight_solver: The value given to homotopy_initial_step_size option must be in the [0,1] interval') +end - if ~options_.noprint - fprintf('\nSimulation of the perfect foresight model failed!\n') - fprintf('Switching to a homotopy method...\n') - end +if options_.simul.homotopy_min_step_size > 1 || options_.simul.homotopy_min_step_size < 0 + error('perfect_foresight_solver: The value given to homotopy_min_step_size option must be in the [0,1] interval') +end - if ~M_.maximum_lag && M_.maximum_lead>0 - disp('Homotopy not implemented for purely forward models!') - disp('Failed to solve the model!') - disp('Return with empty oo_.endo_simul.') - oo_.endo_simul = []; - return - end +if options_.simul.homotopy_max_completion_share > 1 || options_.simul.homotopy_max_completion_share < 0 + error('perfect_foresight_solver: The value given to homotopy_max_completion_share option must be in the [0,1] interval') +end - if ~M_.maximum_lead && M_.maximum_lag>0 - disp('Homotopy not implemented for purely backward models!') - disp('Failed to solve the model!') - disp('Return with empty oo_.endo_simul.') - oo_.endo_simul = []; - return - end +if options_.simul.homotopy_marginal_linearization_fallback > 1 || options_.simul.homotopy_marginal_linearization_fallback < 0 + error('perfect_foresight_solver: The value given to homotopy_marginal_linearization_fallback option must be in the [0,1] interval') +end - if ~M_.maximum_lead && ~M_.maximum_lag - disp('Homotopy not implemented for purely static models!') - disp('Failed to solve the model!') - disp('Return with empty oo_.endo_simul.') - oo_.endo_simul = []; - return +if options_.simul.homotopy_initial_step_size < options_.simul.homotopy_min_step_size + error('perfect_foresight_solver: The value given to homotopy_initial_step_size option must be greater or equal to that given to homotopy_min_step_size option') +end + +if options_.simul.homotopy_linearization_fallback && options_.simul.homotopy_marginal_linearization_fallback > 0 + error('perfect_foresight_solver: Options homotopy_linearization_fallback and homotopy_marginal_linearization_fallback cannot be used together') +end + +if options_.simul.homotopy_max_completion_share < 1 && ~options_.simul.homotopy_linearization_fallback && options_.simul.homotopy_marginal_linearization_fallback == 0 + error('perfect_foresight_solver: Option homotopy_max_completion_share has a value less than 1, so you must also specify either homotopy_linearization_fallback or homotopy_marginal_linearization_fallback') +end + +initperiods = 1:M_.maximum_lag; +simperiods = M_.maximum_lag+(1:periods); +lastperiods = M_.maximum_lag+periods+(1:M_.maximum_lead); + +% Create base scenario for homotopy, which corresponds to the initial steady +% state (i.e. a known solution to the perfect foresight problem, assuming that +% oo_.steady_state/ys0_ effectively contains a steady state) +if isempty(ys0_) + endobase = repmat(oo_.steady_state, 1,M_.maximum_lag+periods+M_.maximum_lead); + exobase = repmat(oo_.exo_steady_state',M_.maximum_lag+periods+M_.maximum_lead,1); +else + endobase = repmat(ys0_, 1, M_.maximum_lag+periods+M_.maximum_lead); + exobase = repmat(ex0_', M_.maximum_lag+periods+M_.maximum_lead, 1); +end + +% Determine whether the terminal condition is not a steady state (typically +% because steady was not called after endval) +if ~options_.simul.endval_steady && ~isempty(ys0_) + terminal_condition_is_a_steady_state = true; + for j = lastperiods + endval_resid = evaluate_static_model(oo_.endo_simul(:,j), oo_.exo_simul(j,:), M_.params, M_, options_); + if norm(endval_resid, 'Inf') > options_.simul.steady_tolf + terminal_condition_is_a_steady_state = false; + break + end end +end - % Disable warnings if homotopy - warning_old_state = warning; - warning off all - % Do not print anything - oldverbositylevel = options_.verbosity; - options_.verbosity = 0; - - % Set initial paths for the endogenous and exogenous variables. - if ~options_.homotopy_alt_starting_point - endoinit = repmat(oo_.steady_state, 1,M_.maximum_lag+periods+M_.maximum_lead); - exoinit = repmat(oo_.exo_steady_state',M_.maximum_lag+periods+M_.maximum_lead,1); - else - if isempty(ys0_) || isempty(ex0_) - error('The homotopy_alt_starting_point option cannot be used without an endval block'); +% Copy the paths for the exogenous and endogenous variables, as given by perfect_foresight_setup +exoorig = oo_.exo_simul; +endoorig = oo_.endo_simul; + +current_share = 0; % Share of shock successfully completed so far +step = min(options_.simul.homotopy_initial_step_size, options_.simul.homotopy_max_completion_share); +success_counter = 0; +iteration = 0; + +function local_success = create_scenario(share) + % For a given share, updates the exogenous path and also the initial and + % terminal conditions for the endogenous path (but do not modify the initial + % guess for endogenous) + + % Compute convex combination for the path of exogenous + oo_.exo_simul = exoorig*share + exobase*(1-share); + + % Compute convex combination for the initial condition + % In most cases, the initial condition is a steady state and this does nothing + % This is for cases when the initial condition is out of equilibrium + oo_.endo_simul(:, initperiods) = share*endoorig(:, initperiods)+(1-share)*endobase(:, initperiods); + + % If there is a permanent shock, ensure that the rescaled terminal condition is + % a steady state (if the user asked for this recomputation, or if the original + % terminal condition is a steady state) + local_success = true; + if options_.simul.endval_steady || (~isempty(ys0_) && terminal_condition_is_a_steady_state) + + % Set “local” options for steady state computation (after saving the global values) + saved_steady_solve_algo = options_.solve_algo; + options_.solve_algo = options_.simul.steady_solve_algo; + saved_steady_maxit = options_.steady.maxit; + options_.steady.maxit = options_.simul.steady_maxit; + saved_steady_tolf = options_.solve_tolf; + options_.solve_tolf = options_.simul.steady_tolf; + saved_steady_tolx = options_.solve_tolx; + options_.solve_tolx = options_.simul.steady_tolx; + saved_steady_markowitz = options_.markowitz; + options_.markowitz = options_.simul.steady_markowitz; + + saved_ss = oo_.endo_simul(:, lastperiods); + % Effectively compute the terminal steady state + for j = lastperiods + % First use the terminal steady of the previous homotopy iteration as guess value (or the contents of the endval block if this is the first iteration) + [oo_.endo_simul(:, j), ~, info] = evaluate_steady_state(oo_.endo_simul(:, j), oo_.exo_simul(j, :), M_, options_, true); + if info(1) + % If this fails, then try again using the initial steady state as guess value + if isempty(ys0_) + guess_value = oo_.steady_state; + else + guess_value = ys0_; + end + [oo_.endo_simul(:, j), ~, info] = evaluate_steady_state(guess_value, oo_.exo_simul(j, :), M_, options_, true); + if info(1) + % If this fails again, give up and restore last periods in oo_.endo_simul + oo_.endo_simul(:, lastperiods) = saved_ss; + local_success = false; + break; + end + end end - endoinit = repmat(ys0_, 1, M_.maximum_lag+periods+M_.maximum_lead); - exoinit = repmat(ex0_', M_.maximum_lag+periods+M_.maximum_lead, 1); + + % The following is needed for the STEADY_STATE() operator to work properly + oo_.steady_state = oo_.endo_simul(:, end); + + options_.solve_algo = saved_steady_solve_algo; + options_.steady.maxit = saved_steady_maxit; + options_.solve_tolf = saved_steady_tolf; + options_.solve_tolx = saved_steady_tolx; + options_.markowitz = saved_steady_markowitz; + else + % The terminal condition is not a steady state, compute a convex combination + oo_.endo_simul(:, lastperiods) = share*endoorig(:, lastperiods)+(1-share)*endobase(:, lastperiods); end +end - % Copy the current paths for the exogenous and endogenous variables. - exosim = oo_.exo_simul; - endosim = oo_.endo_simul; +while step > options_.simul.homotopy_min_step_size - current_weight = 0; % Current weight of target point in convex combination. - step = .5; % Set default step size. - success_counter = 0; - iteration = 0; + iteration = iteration+1; - if ~options_.noprint - fprintf('Iter. \t | Lambda \t | status \t | Max. residual\n') - fprintf('++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n') + saved_endo_simul = oo_.endo_simul; + + new_share = current_share + step; % Try this share, and see if it succeeds + + if new_share > options_.simul.homotopy_max_completion_share + new_share = options_.simul.homotopy_max_completion_share; % Don't go beyond target point + step = new_share - current_share; end - while (step > options_.dynatol.x) - if ~isequal(step,1) - options_.verbosity = 0; + steady_success = create_scenario(new_share); + + if steady_success + % At the first iteration, use the initial guess given by + % perfect_foresight_setup or the user (but only if new_share=1, otherwise it + % does not make much sense). Afterwards, until a converging iteration has been obtained, + % use the rescaled terminal condition (or, if there is no lead, the base + % scenario / initial steady state). + if current_share == 0 + if iteration == 1 && new_share == 1 + oo_.endo_simul(:, simperiods) = endoorig(:, simperiods); + elseif M_.maximum_lead > 0 + oo_.endo_simul(:, simperiods) = repmat(oo_.endo_simul(:, lastperiods(1)), 1, options_.periods); + else + oo_.endo_simul(:, simperiods) = endobase(:, simperiods); + end end - iteration = iteration+1; - new_weight = current_weight + step; % Try this weight, and see if it succeeds + % Solve for the paths of the endogenous variables. + [oo_.endo_simul, success, maxerror, solver_iter, per_block_status] = perfect_foresight_solver_core(M_, options_, oo_); + else + success = false; + maxerror = NaN; + solver_iter = []; + per_block_status = []; + end - if new_weight >= 1 - new_weight = 1; % Don't go beyond target point - step = new_weight - current_weight; + if options_.no_homotopy || (iteration == 1 && success && new_share == 1) + % Skip homotopy + if success + current_share = new_share; end + did_homotopy = false; + break + end - % Compute convex combination for exo path and initial/terminal endo conditions - % But take care of not overwriting the computed part of oo_.endo_simul - oo_.exo_simul = exosim*new_weight + exoinit*(1-new_weight); - oo_.endo_simul(:,[initperiods, lastperiods]) = new_weight*endosim(:,[initperiods, lastperiods])+(1-new_weight)*endoinit(:,[initperiods, lastperiods]); - - % Detect Nans or complex numbers in the solution. - path_with_nans = any(any(isnan(oo_.endo_simul))); - path_with_cplx = any(any(~isreal(oo_.endo_simul))); - - if isequal(iteration, 1) - % First iteration, same initial guess as in the first call to perfect_foresight_solver_core routine. - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead) = endoinit(:,1:periods); - elseif path_with_nans || path_with_cplx - % If solver failed with NaNs or complex number, use previous solution as an initial guess. - oo_.endo_simul(:,M_.maximum_lag+1:end-M_.maximum_lead) = saved_endo_simul(:,1+M_.maximum_lag:end-M_.maximum_lead); - end + if iteration == 1 + % First iteration failed, so we enter homotopy + did_homotopy = true; - % Make a copy of the paths. - saved_endo_simul = oo_.endo_simul; + if ~options_.noprint + fprintf('\nEntering the homotopy method iterations...\n') + fprintf('\nIter. \t | Share \t | Status \t | Max. residual\n') + fprintf('++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n') + end - % Solve for the paths of the endogenous variables. - [oo_,me] = perfect_foresight_solver_core(M_,options_,oo_); + % Disable warnings if homotopy + warning_old_state = warning; + warning off all + % Do not print anything + oldverbositylevel = options_.verbosity; + options_.verbosity = 0; + end - if oo_.deterministic_simulation.status - current_weight = new_weight; - if current_weight >= 1 - if ~options_.noprint - fprintf('%i \t | %1.5f \t | %s \t | %e\n', iteration, new_weight, 'succeeded', me) - end - break - end - success_counter = success_counter + 1; - if success_counter >= 3 - success_counter = 0; - step = step * 2; - end - if ~options_.noprint - fprintf('%i \t | %1.5f \t | %s \t | %e\n', iteration, new_weight, 'succeeded', me) - end - else - % If solver failed, then go back. - oo_.endo_simul = saved_endo_simul; + if success + % Successful step + if ~options_.noprint + fprintf('%i \t | %1.5f \t | %s \t | %e\n', iteration, new_share, 'succeeded', maxerror) + end + current_share = new_share; + if current_share >= options_.simul.homotopy_max_completion_share + break + end + success_counter = success_counter + 1; + if options_.simul.homotopy_step_size_increase_success_count > 0 ... + && success_counter >= options_.simul.homotopy_step_size_increase_success_count success_counter = 0; - step = step / 2; - if ~options_.noprint - if isreal(me) - fprintf('%i \t | %1.5f \t | %s \t | %e\n', iteration, new_weight, 'failed', me) - else - fprintf('%i \t | %1.5f \t | %s \t | %s\n', iteration, new_weight, 'failed', 'Complex') - end + step = step * 2; + end + else + oo_.endo_simul = saved_endo_simul; + success_counter = 0; + step = step / 2; + if ~options_.noprint + if ~steady_success + fprintf('%i \t | %1.5f \t | %s\n', iteration, new_share, 'failed (in endval steady)') + elseif isreal(maxerror) + fprintf('%i \t | %1.5f \t | %s \t | %e\n', iteration, new_share, 'failed', maxerror) + else + fprintf('%i \t | %1.5f \t | %s \t | %s\n', iteration, new_share, 'failed', 'Complex') end end end - if ~options_.noprint - fprintf('++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n') - end - options_.verbosity = oldverbositylevel; - warning(warning_old_state); +end + +if did_homotopy && ~options_.noprint + fprintf('++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n') end %If simulated paths are complex, take real part and recompute the residuals to check whether this is actually a solution if ~isreal(oo_.endo_simul(:)) % cannot happen with bytecode or the perfect_foresight_problem DLL - ny = size(oo_.endo_simul, 1); - if M_.maximum_lag > 0 - y0 = real(oo_.endo_simul(:, M_.maximum_lag)); + real_simul = real(oo_.endo_simul); + real_maxerror = recompute_maxerror(real_simul, oo_, M_, options_); + if real_maxerror <= options_.dynatol.f + oo_.endo_simul = real_simul; + maxerror = real_maxerror; else - y0 = NaN(ny, 1); - end - if M_.maximum_lead > 0 - yT = real(oo_.endo_simul(:, M_.maximum_lag+periods+1)); - else - yT = NaN(ny, 1); - end - if M_.maximum_lag~=0 && M_.maximum_lead~=0 - yy = real(oo_.endo_simul(:,M_.maximum_lag+(1:periods))); - residuals = perfect_foresight_problem(yy(:), y0, yT, oo_.exo_simul, M_.params, oo_.steady_state, periods, M_, options_); - else - %The perfect_foresight_problem MEX only works on models with lags and leads - i_cols = find(M_.lead_lag_incidence'); - residuals=NaN(ny,periods); - yy=real(oo_.endo_simul); - for it = (M_.maximum_lag+1):(M_.maximum_lag+periods) - residuals(:,it) = feval([M_.fname '.dynamic'],yy(i_cols), oo_.exo_simul, M_.params, oo_.steady_state, it); - i_cols = i_cols + ny; - end - residuals=residuals(:); - end - - if max(abs(residuals))< options_.dynatol.f - oo_.deterministic_simulation.status = true; - oo_.endo_simul=real(oo_.endo_simul); - else - oo_.deterministic_simulation.status = false; + current_share = 0; disp('Simulation terminated with imaginary parts in the residuals or endogenous variables.') end end -if oo_.deterministic_simulation.status +% Put solver status information in oo_, and do linearization if needed and requested +if current_share == 1 if ~options_.noprint fprintf('Perfect foresight solution found.\n\n') end + oo_.deterministic_simulation.status = true; +elseif options_.simul.homotopy_linearization_fallback && current_share > 0 + oo_.endo_simul = endobase + (oo_.endo_simul - endobase)/current_share; + oo_.exo_simul = exoorig; + if options_.simul.endval_steady + % The following is needed for the STEADY_STATE() operator to work properly, + % and thus must come before computing the maximum error. + % This is not a true steady state, but it is the closest we can get to + oo_.steady_state = oo_.endo_simul(:, end); + end + maxerror = recompute_maxerror(oo_.endo_simul, oo_, M_, options_); + + if ~options_.noprint + fprintf('Perfect foresight solution found for %.1f%% of the shock, then extrapolation was performed using linearization\n\n', current_share*100) + end + oo_.deterministic_simulation.status = true; + oo_.deterministic_simulation.homotopy_linearization = true; +elseif options_.simul.homotopy_marginal_linearization_fallback > 0 && current_share > options_.simul.homotopy_marginal_linearization_fallback + saved_endo_simul = oo_.endo_simul; + new_share = current_share - options_.simul.homotopy_marginal_linearization_fallback; + new_success = create_scenario(new_share); + if new_success + [oo_.endo_simul, new_success] = perfect_foresight_solver_core(M_, options_, oo_); + end + if new_success + oo_.endo_simul = saved_endo_simul + (saved_endo_simul - oo_.endo_simul)*(1-current_share)/options_.simul.homotopy_marginal_linearization_fallback; + oo_.exo_simul = exoorig; + if options_.simul.endval_steady + % The following is needed for the STEADY_STATE() operator to work properly, + % and thus must come before computing the maximum error. + % This is not a true steady state, but it is the closest we can get to + oo_.steady_state = oo_.endo_simul(:, end); + end + maxerror = recompute_maxerror(oo_.endo_simul, oo_, M_, options_); + + if ~options_.noprint + fprintf('Perfect foresight solution found for %.1f%% of the shock, then extrapolation was performed using marginal linearization\n\n', current_share*100) + end + oo_.deterministic_simulation.homotopy_marginal_linearization = true; + else + fprintf('perfect_foresight_solver: marginal linearization failed, unable to find solution for %.1f%% of the shock. Try to modify the value of homotopy_marginal_linearization_fallback option\n\n', new_share*100) + end + oo_.deterministic_simulation.status = new_success; else fprintf('Failed to solve perfect foresight model\n\n') + oo_.deterministic_simulation.status = false; +end + +oo_.deterministic_simulation.error = maxerror; +oo_.deterministic_simulation.homotopy_completion_share = current_share; +oo_.deterministic_simulation.homotopy_iterations = iteration; +if ~isempty(solver_iter) + oo_.deterministic_simulation.iterations = solver_iter; +end +if ~isempty(per_block_status) + oo_.deterministic_simulation.block = per_block_status; +end + +% Must come after marginal linearization +if did_homotopy + options_.verbosity = oldverbositylevel; + warning(warning_old_state); end dyn2vec(M_, oo_, options_); @@ -264,6 +395,32 @@ end assignin('base', 'Simulated_time_series', ts); -if oo_.deterministic_simulation.status +if success oo_.gui.ran_perfect_foresight = true; end + +end + +function maxerror = recompute_maxerror(endo_simul, oo_, M_, options_) + % Computes ∞-norm of residuals for a given path of endogenous, + % given the exogenous path and parameters in oo_ and M_ + if options_.bytecode + residuals = bytecode('dynamic', 'evaluate', endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, 1); + else + ny = size(endo_simul, 1); + periods = size(endo_simul, 2) - M_.maximum_lag - M_.maximum_lead; + if M_.maximum_lag > 0 + y0 = endo_simul(:, M_.maximum_lag); + else + y0 = NaN(ny, 1); + end + if M_.maximum_lead > 0 + yT = endo_simul(:, M_.maximum_lag+periods+1); + else + yT = NaN(ny, 1); + end + yy = endo_simul(:,M_.maximum_lag+(1:periods)); + residuals = perfect_foresight_problem(yy(:), y0, yT, oo_.exo_simul, M_.params, oo_.steady_state, periods, M_, options_); + end + maxerror = norm(vec(residuals), 'Inf'); +end diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver_core.m b/matlab/perfect-foresight-models/perfect_foresight_solver_core.m index ecb3abba38c90194bb478c6befb4b2e3061aabda..a4e9ec584534ae323872795c271f38dd65896e5c 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver_core.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver_core.m @@ -1,4 +1,4 @@ -function [oo_, maxerror] = perfect_foresight_solver_core(M_, options_, oo_) +function [y, success, maxerror, iter, per_block_status] = perfect_foresight_solver_core(M_, options_, oo_) % Core function calling solvers for perfect foresight model % @@ -8,8 +8,11 @@ function [oo_, maxerror] = perfect_foresight_solver_core(M_, options_, oo_) % - oo_ [struct] contains results % % OUTPUTS -% - oo_ [struct] contains results +% - y [double array] path for the endogenous variables (solution) +% - success [logical] Whether a solution was found % - maxerror [double] contains the maximum absolute error +% - iter [integer] Number of iterations of the underlying nonlinear solver (empty for non-iterative methods) +% - per_block_status [struct] In the case of block decomposition, provides per-block solver status information (empty if no block decomposition) % Copyright © 2015-2023 Dynare Team % @@ -49,62 +52,60 @@ if options_.linear && (isequal(options_.stack_solve_algo, 0) || isequal(options_ options_.linear_approximation = true; end +maxerror = []; +iter = []; +per_block_status = []; + if options_.block if M_.block_structure.time_recursive error('Internal error: can''t perform stacked perfect foresight simulation with time-recursive block decomposition') end if options_.bytecode try - oo_.endo_simul = bytecode('dynamic', 'block_decomposed', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state,1, periods+2), periods); - oo_.deterministic_simulation.status = true; + y = bytecode('dynamic', 'block_decomposed', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state,1, periods+2), periods); + success = true; catch ME - disp(ME.message) - if options_.no_homotopy - error('Error in bytecode') + if options_.verbosity >= 1 + disp(ME.message) end - oo_.deterministic_simulation.status = false; + y = oo_.endo_simul; % Set something for y, need for computing maxerror + success = false; end else - oo_ = solve_block_decomposed_problem(options_, M_, oo_); + [y, success, maxerror, per_block_status] = solve_block_decomposed_problem(options_, M_, oo_); end else if options_.bytecode try - oo_.endo_simul = bytecode('dynamic', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state, 1, periods+2), periods); - oo_.deterministic_simulation.status = true; + y = bytecode('dynamic', oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state, 1, periods+2), periods); + success = true; catch ME - disp(ME.message) - if options_.no_homotopy - error('Error in bytecode') + if options_.verbosity >= 1 + disp(ME.message) end - oo_.deterministic_simulation.status = false; + y = oo_.endo_simul; % Set something for y, need for computing maxerror + success = false; end else if M_.maximum_endo_lead == 0 && M_.maximum_endo_lag>0 && ~options_.lmmcp.status % Purely backward model - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1_purely_backward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success] = sim1_purely_backward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); elseif M_.maximum_endo_lag == 0 && M_.maximum_endo_lead>0 && ~options_.lmmcp.status % Purely forward model - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success] = sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); elseif M_.maximum_endo_lag == 0 && M_.maximum_endo_lead == 0 && ~options_.lmmcp.status % Purely static model - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1_purely_static(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success] = sim1_purely_static(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); else % General case switch options_.stack_solve_algo case 0 if options_.linear_approximation - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1_linear(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); + [y, success, maxerror] = sim1_linear(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); else - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success, maxerror, iter] = sim1(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); end case {1 6} if options_.linear_approximation error('Invalid value of stack_solve_algo option!') end - [oo_.endo_simul, oo_.deterministic_simulation] = ... - sim1_lbj(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success, maxerror, iter] = sim1_lbj(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); case 7 if options_.linear_approximation if isequal(options_.solve_algo, 10) @@ -116,11 +117,9 @@ else warning('It would be more efficient to set option solve_algo equal to 0!') end end - [oo_.endo_simul, oo_.deterministic_simulation] = ... - solve_stacked_linear_problem(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); + [y, success] = solve_stacked_linear_problem(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); else - [oo_.endo_simul, oo_.deterministic_simulation, residuals] = ... - solve_stacked_problem(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success, maxerror] = solve_stacked_problem(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); end otherwise error('Invalid value of stack_solve_algo option!') @@ -129,29 +128,25 @@ else end end -if nargout>1 - if options_.lmmcp.status - maxerror = max(max(abs(residuals))); - elseif options_.block && ~options_.bytecode - maxerror = oo_.deterministic_simulation.error; +% Some solvers do not compute the maximum error, so do it here if needed +if nargout > 2 && isempty(maxerror) + if options_.bytecode + residuals = bytecode('dynamic', 'evaluate', y, oo_.exo_simul, M_.params, oo_.steady_state, periods); else - if options_.bytecode - residuals = bytecode('dynamic','evaluate', oo_.endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, 1); + ny = size(y, 1); + if M_.maximum_lag > 0 + y0 = y(:, M_.maximum_lag); else - if M_.maximum_lag > 0 - y0 = oo_.endo_simul(:, M_.maximum_lag); - else - y0 = NaN(ny, 1); - end - if M_.maximum_lead > 0 - yT = oo_.endo_simul(:, M_.maximum_lag+periods+1); - else - yT = NaN(ny, 1); - end - yy = oo_.endo_simul(:,M_.maximum_lag+(1:periods)); - - residuals = perfect_foresight_problem(yy(:), y0, yT, oo_.exo_simul, M_.params, oo_.steady_state, periods, M_, options_); + y0 = NaN(ny, 1); + end + if M_.maximum_lead > 0 + yT = y(:, M_.maximum_lag+periods+1); + else + yT = NaN(ny, 1); end - maxerror = max(max(abs(residuals))); + yy = y(:,M_.maximum_lag+(1:periods)); + + residuals = perfect_foresight_problem(yy(:), y0, yT, oo_.exo_simul, M_.params, oo_.steady_state, periods, M_, options_); end + maxerror = max(max(abs(residuals))); end diff --git a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m index 3b57d45590ea9f5a7b70f08f404bdcba7e9701bc..39ae5ede12e351ca4b96f925948a167e55311117 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m @@ -125,32 +125,14 @@ else end end -%% Compute the terminal steady state for all informational periods -oo_.pfwee.terminal_steady_state = NaN(M_.endo_nbr, periods); -orig_exo_steady_state = oo_.exo_steady_state; -for p = 1:periods - if p > 1 && all(oo_.pfwee.terminal_info(:, p) == oo_.pfwee.terminal_info(:, p-1)) - oo_.pfwee.terminal_steady_state(:, p) = oo_.pfwee.terminal_steady_state(:, p-1); - else - if p == 1 - init = oo_.steady_state; - else - init = oo_.pfwee.terminal_steady_state(:, p-1); - end - oo_.exo_steady_state = oo_.pfwee.terminal_info(:, p); - oo_.pfwee.terminal_steady_state(:, p) = evaluate_steady_state(init, M_, options_, oo_, true); - end -end -oo_.exo_steady_state = orig_exo_steady_state; - % Build initial paths for endos and exos (only initial conditions are set, the rest is NaN) if isempty(ys0_) - oo_.endo_simul = [repmat(oo_.steady_state, 1, M_.maximum_lag) NaN(M_.endo_nbr, periods+M_.maximum_lead)]; + oo_.endo_simul = repmat(oo_.steady_state, 1, M_.maximum_lag+periods+M_.maximum_lead); else - oo_.endo_simul = [repmat(ys0_, 1, M_.maximum_lag) NaN(M_.endo_nbr, periods+M_.maximum_lead)]; + oo_.endo_simul = [repmat(ys0_, 1, M_.maximum_lag) repmat(oo_.steady_state, 1, periods+M_.maximum_lead)]; end if isempty(ex0_) - oo_.exo_simul = [repmat(oo_.exo_steady_state',M_.maximum_lag,1); NaN(periods+M_.maximum_lead,M_.exo_nbr)]; + oo_.exo_simul = repmat(oo_.exo_steady_state', M_.maximum_lag+periods+M_.maximum_lead, 1); else - oo_.exo_simul = [repmat(ex0_',M_.maximum_lag,1); NaN(periods+M_.maximum_lead,M_.exo_nbr)]; + oo_.exo_simul = [repmat(ex0_', M_.maximum_lag, 1); repmat(oo_.exo_steady_state', periods+M_.maximum_lead, 1)]; end diff --git a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m index 0e9cd3f26c44c8a3364becdc3cf84c32f1cc67a2..5c05102ebae46623e2f32b679b22656cb714357f 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m +++ b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_solver.m @@ -19,33 +19,38 @@ function perfect_foresight_with_expectation_errors_solver global M_ oo_ options_ ys0_ -% Save original steady state, for restoring it at the end -orig_steady_state = oo_.steady_state; -orig_exo_steady_state = oo_.exo_steady_state; - % Same for periods (it will be modified before calling perfect_foresight_solver if constants_simulation_length option is false) periods = options_.periods; +% Save some options +orig_homotopy_max_completion_share = options_.simul.homotopy_max_completion_share; +orig_endval_steady = options_.simul.endval_steady; + % Retrieve initial paths built by pfwee_setup % (the versions in oo_ will be truncated before calling perfect_foresight_solver) endo_simul = oo_.endo_simul; exo_simul = oo_.exo_simul; +% Enforce the endval steady option in pf_solver +if M_.maximum_lead > 0 + options_.simul.endval_steady = true; +end + % Start main loop around informational periods info_period = 1; increment = 0; -if isempty(ys0_) - initial_steady_state = oo_.steady_state; -else - initial_steady_state = ys0_; -end while info_period <= periods + if ~options_.noprint + fprintf('perfect_foresight_with_expectations_errors_solver: computing solution for information available at period %d\n', info_period) + end + % Compute terminal steady state as anticipated oo_.exo_steady_state = oo_.pfwee.terminal_info(:, info_period); - oo_.steady_state = oo_.pfwee.terminal_steady_state(:, info_period); + % oo_.steady_state will be updated by pf_solver (since endval_steady=true) if options_.pfwee.constant_simulation_length && increment > 0 - endo_simul = [ endo_simul NaN(M_.endo_nbr, increment)]; + % Use previous terminal steady state as guess value for: simulation periods that don’t yet have an initial guess (i.e. are NaNs at this point); and also for the terminal steady state + endo_simul = [ endo_simul repmat(oo_.steady_state, 1, increment)]; exo_simul = [ exo_simul; NaN(increment, M_.exo_nbr)]; end @@ -55,17 +60,7 @@ while info_period <= periods else sim_length = periods - info_period + 1; end - if options_.pfwee.terminal_steady_state_as_guess_value - % Overwrite guess value with terminal steady state - oo_.endo_simul(:, M_.maximum_lag+(1:sim_length)) = repmat(oo_.steady_state, 1, sim_length); - elseif info_period == 1 - % Use initial steady state as guess value for first simulation if not using terminal steady state - oo_.endo_simul(:, M_.maximum_lag+(1:periods)) = repmat(initial_steady_state, 1, periods); - elseif options_.pfwee.constant_simulation_length && increment > M_.maximum_lead - % Use initial steady state as guess value for simulation periods that don’t yet have an initial guess (i.e. are NaNs) - oo_.endo_simul(:, M_.maximum_lag+periods-(0:increment-M_.maximum_lead-1)) = repmat(initial_steady_state, 1, increment-M_.maximum_lead); - end - oo_.endo_simul(:, end-M_.maximum_lead+1:end) = repmat(oo_.steady_state, 1, M_.maximum_lead); + oo_.exo_simul = exo_simul(info_period:end, :); oo_.exo_simul(M_.maximum_lag+(1:periods-info_period+1), :) = oo_.pfwee.shocks_info(:, info_period:end, info_period)'; oo_.exo_simul(M_.maximum_lag+periods-info_period+2:end, :) = repmat(oo_.exo_steady_state', sim_length+M_.maximum_lead-(periods-info_period+1), 1); @@ -74,6 +69,17 @@ while info_period <= periods perfect_foresight_solver; + if ~oo_.deterministic_simulation.status + error('perfect_foresight_with_expectation_errors_solver: failed to compute solution for information available at period %d\n', info_period) + end + + if info_period == 1 + homotopy_completion_share = oo_.deterministic_simulation.homotopy_completion_share; + options_.simul.homotopy_max_completion_share = homotopy_completion_share; + elseif oo_.deterministic_simulation.homotopy_completion_share ~= homotopy_completion_share + error('perfect_foresight_solver_with_expectation_errors: could not find a solution for information available at period %d with the same homotopy completion share as period 1\n', info_period) + end + endo_simul(:, info_period:end) = oo_.endo_simul; exo_simul(info_period:end, :) = oo_.exo_simul; @@ -91,7 +97,7 @@ end oo_.endo_simul = endo_simul; oo_.exo_simul = exo_simul; -% Restore some values -oo_.steady_state = orig_steady_state; -oo_.exo_steady_state = orig_exo_steady_state; +% Restore some options options_.periods = periods; +options_.simul.homotopy_max_completion_share = orig_homotopy_max_completion_share; +options_.simul.endval_steady = orig_endval_steady; diff --git a/matlab/perfect-foresight-models/sim1.m b/matlab/perfect-foresight-models/sim1.m index 8f0f65a90ed8aa338664a3d0818e4c3d8c24bce6..f9dafab9a29debb6b81bb07256534d3c82fd6b37 100644 --- a/matlab/perfect-foresight-models/sim1.m +++ b/matlab/perfect-foresight-models/sim1.m @@ -1,4 +1,4 @@ -function [endogenousvariables, info] = sim1(endogenousvariables, exogenousvariables, steadystate, M, options) +function [endogenousvariables, success, err, iter] = sim1(endogenousvariables, exogenousvariables, steadystate, M, options) % Performs deterministic simulations with lead or lag of one period, using % a basic Newton solver on sparse matrices. % Uses perfect_foresight_problem DLL to construct the stacked problem. @@ -11,9 +11,11 @@ function [endogenousvariables, info] = sim1(endogenousvariables, exogenousvariab % - options [struct] contains various options. % OUTPUTS % - endogenousvariables [double] N*(T+M.maximum_lag+M.maximum_lead) array, paths for the endogenous variables (solution of the perfect foresight model). -% - info [struct] contains informations about the results. +% - success [logical] Whether a solution was found +% - err [double] ∞-norm of the residual +% - iter [integer] Number of iterations -% Copyright © 1996-2021 Dynare Team +% Copyright © 1996-2023 Dynare Team % % This file is part of Dynare. % @@ -145,10 +147,7 @@ if stop % initial or terminal observations may contain % harmless NaN or Inf. We test only values computed above if any(any(isnan(y))) || any(any(isinf(y))) - info.status = false;% NaN or Inf occurred - info.error = err; - info.iterations = iter; - info.periods = vperiods(1:iter); + success = false; % NaN or Inf occurred if verbose skipline() fprintf('Total time of simulation: %g.\n', etime(clock,h1)) @@ -163,10 +162,7 @@ if stop fprintf('Total time of simulation: %g.\n', etime(clock,h1)) printline(56) end - info.status = true;% Convergency obtained. - info.error = err; - info.iterations = iter; - info.periods = vperiods(1:iter); + success = true; % Convergency obtained. end elseif ~stop if verbose @@ -175,10 +171,7 @@ elseif ~stop disp('Maximum number of iterations is reached (modify option maxit).') printline(62) end - info.status = false;% more iterations are needed. - info.error = err; - info.periods = vperiods(1:iter); - info.iterations = options.simul.maxit; + success = false; % more iterations are needed. end if verbose diff --git a/matlab/perfect-foresight-models/sim1_lbj.m b/matlab/perfect-foresight-models/sim1_lbj.m index 79c4b74adfb21c2dc3dc984acb4cb30361b29051..ce3e582f48ba7e26b79e942d153bf3775b22e931 100644 --- a/matlab/perfect-foresight-models/sim1_lbj.m +++ b/matlab/perfect-foresight-models/sim1_lbj.m @@ -1,4 +1,4 @@ -function [endogenousvariables, info] = sim1_lbj(endogenousvariables, exogenousvariables, steadystate, M, options) +function [endogenousvariables, success, err, iter] = sim1_lbj(endogenousvariables, exogenousvariables, steadystate, M, options) % Performs deterministic simulations with lead or lag on one period using the historical LBJ algorithm % @@ -63,11 +63,7 @@ h1 = clock; for iter = 1:options.simul.maxit h2 = clock; - if ~options.terminal_condition - c = zeros(ny*options.periods, nrc); - else - c = zeros(ny*(options.periods+1), nrc); - end + c = zeros(ny*options.periods, nrc); it_ = it_init; z = [endogenousvariables(iyp,it_-1) ; endogenousvariables(:,it_) ; endogenousvariables(iyf,it_+1)]; [d1, jacobian] = feval(dynamicmodel, z, exogenousvariables, M.params, steadystate, it_); @@ -84,20 +80,10 @@ for iter = 1:options.simul.maxit icp = icp + ny; c (ic,:) = jacobian(:,is)\jacobian(:,isf1); end - if options.terminal_condition == 1 - s = eye(ny); - s(:,isf) = s(:,isf)+c(ic,1:nyf); - ic = ic + ny; - c(ic,nrc) = s\c(ic,nrc); - c = bksup1(c, ny, nrc, iyf, options.periods); - c = reshape(c, ny, options.periods+1); - endogenousvariables(:,it_init+(0:options.periods)) = endogenousvariables(:,it_init+(0:options.periods))+c; - else - c = bksup1(c, ny, nrc, iyf, options.periods); - c = reshape(c, ny, options.periods); - endogenousvariables(:,it_init+(0:options.periods-1)) = endogenousvariables(:,it_init+(0:options.periods-1))+c; - end - err = max(max(abs(c./options.scalv'))); + c = bksup1(c, ny, nrc, iyf, options.periods); + c = reshape(c, ny, options.periods); + endogenousvariables(:,it_init+(0:options.periods-1)) = endogenousvariables(:,it_init+(0:options.periods-1))+c; + err = max(max(abs(c))); if verbose str = sprintf('Iter: %s,\t err. = %s, \t time = %s', num2str(iter), num2str(err), num2str(etime(clock, h2))); disp(str); @@ -108,9 +94,7 @@ for iter = 1:options.simul.maxit skipline() disp(sprintf('Total time of simulation: %s', num2str(etime(clock,h1)))) end - info.status = 1;% Convergency obtained. - info.error = err; - info.iterations = iter; + success = true; % Convergency obtained. break end end @@ -120,10 +104,7 @@ if ~stop disp(sprintf('Total time of simulation: %s.', num2str(etime(clock,h1)))) disp('Maximum number of iterations is reached (modify option maxit).') end - info.status = 0;% more iterations are needed. - info.error = err; - info.errors = c/abs(err); - info.iterations = options.simul.maxit; + success = false; % More iterations are needed. end if verbose diff --git a/matlab/perfect-foresight-models/sim1_linear.m b/matlab/perfect-foresight-models/sim1_linear.m index 3bffa6d42396253ae3ec96c566ef7e00481348d5..f6a67759bda4a746da531bb0614f766ff4100399 100644 --- a/matlab/perfect-foresight-models/sim1_linear.m +++ b/matlab/perfect-foresight-models/sim1_linear.m @@ -1,4 +1,4 @@ -function [endogenousvariables, info] = sim1_linear(endogenousvariables, exogenousvariables, steadystate_y, steadystate_x, M, options) +function [endogenousvariables, success, ERR] = sim1_linear(endogenousvariables, exogenousvariables, steadystate_y, steadystate_x, M, options) % Solves a linear approximation of a perfect foresight model using sparse matrix. % @@ -12,7 +12,8 @@ function [endogenousvariables, info] = sim1_linear(endogenousvariables, exogenou % % OUTPUTS % - endogenousvariables [double] N*T array, paths for the endogenous variables (solution of the perfect foresight model). -% - info [struct] contains informations about the results. +% - success [logical] Whether a solution was found +% - ERR [double] ∞-norm of the residual % % NOTATIONS % - N is the number of endogenous variables. @@ -38,7 +39,7 @@ function [endogenousvariables, info] = sim1_linear(endogenousvariables, exogenou % to center the variables around the deterministic steady state to solve the % perfect foresight model. -% Copyright © 2015-2020 Dynare Team +% Copyright © 2015-2023 Dynare Team % % This file is part of Dynare. % @@ -209,9 +210,8 @@ try catch % Normally, because the model is linear, the solution of the perfect foresight model should % be obtained in one Newton step. This is not the case if the model is singular. - info.status = false; - info.error = NaN; - info.iterations = 1; + success = false; + ERR = []; if verbose skipline() disp('Singularity problem! The jacobian matrix of the stacked model cannot be inverted.') @@ -238,9 +238,7 @@ if verbose end if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y)) || ~isreal(res) || ~isreal(Y) - info.status = false;% NaN or Inf occurred - info.error = ERR; - info.iterations = 1; + success = false; % NaN or Inf occurred endogenousvariables = reshape(Y, ny, periods+maximum_lag+M.maximum_lead); if verbose skipline() @@ -252,9 +250,7 @@ if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y)) || ~isre disp('There is most likely something wrong with your model. Try model_diagnostics or another simulation method.') end else - info.status = true;% Convergency obtained. - info.error = ERR; - info.iterations = 1; + success = true; % Convergency obtained. endogenousvariables = bsxfun(@plus, reshape(Y, ny, periods+maximum_lag+M.maximum_lead), steadystate_y); end diff --git a/matlab/perfect-foresight-models/sim1_purely_backward.m b/matlab/perfect-foresight-models/sim1_purely_backward.m index c22a2d7ac198143a7bb234a3bbec15c8d2dc6463..904b6e6471cd2c341787fcf6574bcd29f5b500ef 100644 --- a/matlab/perfect-foresight-models/sim1_purely_backward.m +++ b/matlab/perfect-foresight-models/sim1_purely_backward.m @@ -1,8 +1,8 @@ -function [endogenousvariables, info] = sim1_purely_backward(endogenousvariables, exogenousvariables, steadystate, M, options) +function [endogenousvariables, success] = sim1_purely_backward(endogenousvariables, exogenousvariables, steadystate, M, options) % Performs deterministic simulation of a purely backward model -% Copyright © 2012-2022 Dynare Team +% Copyright © 2012-2023 Dynare Team % % This file is part of Dynare. % @@ -19,18 +19,11 @@ function [endogenousvariables, info] = sim1_purely_backward(endogenousvariables, % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -ny0 = nnz(M.lead_lag_incidence(2,:)); % Number of variables at current period - -if ny0 ~= M.endo_nbr - error('All endogenous variables must appear at the current period!') -end - if ismember(options.solve_algo, [12,14]) [funcs, feedback_vars_idxs] = setup_time_recursive_block_simul(M); else - iyb = M.lead_lag_incidence(1,:)>0; % Logical vector (for lagged variables) - dynamicmodel = str2func(sprintf('%s.%s', M.fname, 'dynamic')); - dynamicmodel_s = str2func('dynamic_backward_model_for_simulation'); + dynamic_resid = str2func([M.fname '.sparse.dynamic_resid']); + dynamic_g1 = str2func([M.fname '.sparse.dynamic_g1']); end function [r, J] = block_wrapper(z, feedback_vars_idx, func, y_dynamic, x, sparse_rowval, sparse_colval, sparse_colptr, T) @@ -41,12 +34,12 @@ function [r, J] = block_wrapper(z, feedback_vars_idx, func, y_dynamic, x, sparse sparse_rowval, sparse_colval, sparse_colptr, T); end -info.status = true; +success = true; for it = M.maximum_lag + (1:options.periods) y = endogenousvariables(:,it-1); % Values at previous period, also used as guess value for current period + x = exogenousvariables(it,:); if ismember(options.solve_algo, [12,14]) - x = exogenousvariables(it,:); T = NaN(M.block_structure.dyn_tmp_nbr); y_dynamic = [y; y; NaN(M.endo_nbr, 1)]; for blk = 1:length(M.block_structure.block) @@ -59,7 +52,7 @@ for it = M.maximum_lag + (1:options.periods) options.dynatol.x, options, ... feedback_vars_idxs{blk}, funcs{blk}, y_dynamic, x, sparse_rowval, sparse_colval, sparse_colptr, T); if check - info.status = false; + success = false; if options.debug dprintf('sim1_purely_backward: Nonlinear solver routine failed with errorcode=%i in block %i and period %i.', errorcode, blk, it) end @@ -74,12 +67,11 @@ for it = M.maximum_lag + (1:options.periods) end endogenousvariables(:,it) = y_dynamic(M.endo_nbr+(1:M.endo_nbr)); else - ylag = y(iyb); - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, ... + [tmp, check, ~, ~, errorcode] = dynare_solve(@dynamic_backward_model_for_simulation, y, ... options.simul.maxit, options.dynatol.f, options.dynatol.x, ... - options, dynamicmodel, ylag, exogenousvariables, M.params, steadystate, it); + options, dynamic_resid, dynamic_g1, y, x, M.params, steadystate, M.dynamic_g1_sparse_rowval, M.dynamic_g1_sparse_colval, M.dynamic_g1_sparse_colptr); if check - info.status = false; + success = false; dprintf('sim1_purely_backward: Nonlinear solver routine failed with errorcode=%i in period %i', errorcode, it) break end diff --git a/matlab/perfect-foresight-models/sim1_purely_forward.m b/matlab/perfect-foresight-models/sim1_purely_forward.m index a71715e2a60340f41b0a3a7beef41f2bec938201..58778ec5754e8c82d996a3f822da34ec0fb47dec 100644 --- a/matlab/perfect-foresight-models/sim1_purely_forward.m +++ b/matlab/perfect-foresight-models/sim1_purely_forward.m @@ -1,7 +1,7 @@ -function [endogenousvariables, info] = sim1_purely_forward(endogenousvariables, exogenousvariables, steadystate, M, options) +function [endogenousvariables, success] = sim1_purely_forward(endogenousvariables, exogenousvariables, steadystate, M, options) % Performs deterministic simulation of a purely forward model -% Copyright © 2012-2022 Dynare Team +% Copyright © 2012-2023 Dynare Team % % This file is part of Dynare. % @@ -18,18 +18,11 @@ function [endogenousvariables, info] = sim1_purely_forward(endogenousvariables, % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -ny0 = nnz(M.lead_lag_incidence(1,:)); % Number of variables at current period - -if ny0 ~= M.endo_nbr - error('All endogenous variables must appear at the current period!') -end - if ismember(options.solve_algo, [12,14]) [funcs, feedback_vars_idxs] = setup_time_recursive_block_simul(M); else - iyf = find(M.lead_lag_incidence(2,:)>0); % Indices of variables at next period - dynamicmodel = str2func(sprintf('%s.%s', M.fname, 'dynamic')); - dynamicmodel_s = str2func('dynamic_forward_model_for_simulation'); + dynamic_resid = str2func([M.fname '.sparse.dynamic_resid']); + dynamic_g1 = str2func([M.fname '.sparse.dynamic_g1']); end function [r, J] = block_wrapper(z, feedback_vars_idx, func, y_dynamic, x, sparse_rowval, sparse_colval, sparse_colptr, T) @@ -40,12 +33,12 @@ function [r, J] = block_wrapper(z, feedback_vars_idx, func, y_dynamic, x, sparse sparse_rowval, sparse_colval, sparse_colptr, T); end -info.status = true; +success = true; for it = options.periods:-1:1 yf = endogenousvariables(:,it+1); % Values at next period, also used as guess value for current period + x = exogenousvariables(it,:); if ismember(options.solve_algo, [12,14]) - x = exogenousvariables(it,:); T = NaN(M.block_structure.dyn_tmp_nbr); y_dynamic = [NaN(M.endo_nbr, 1); yf; yf]; for blk = 1:length(M.block_structure.block) @@ -58,7 +51,7 @@ for it = options.periods:-1:1 options.dynatol.x, options, ... feedback_vars_idxs{blk}, funcs{blk}, y_dynamic, x, sparse_rowval, sparse_colval, sparse_colptr, T); if check - info.status = false; + success = false; if options.debug dprintf('sim1_purely_forward: Nonlinear solver routine failed with errorcode=%i in block %i and period %i.', errorcode, blk, it) end @@ -73,12 +66,11 @@ for it = options.periods:-1:1 end endogenousvariables(:,it) = y_dynamic(M.endo_nbr+(1:M.endo_nbr)); else - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, yf, ... + [tmp, check, ~, ~, errorcode] = dynare_solve(@dynamic_forward_model_for_simulation, yf, ... options.simul.maxit, options.dynatol.f, options.dynatol.x, ... - options, ... - dynamicmodel, yf(iyf), exogenousvariables, M.params, steadystate, it); + options, dynamic_resid, dynamic_g1, yf, x, M.params, steadystate, M.dynamic_g1_sparse_rowval, M.dynamic_g1_sparse_colval, M.dynamic_g1_sparse_colptr); if check - info.status = false; + success = false; dprintf('sim1_purely_forward: Nonlinear solver routine failed with errorcode=%i in period %i.', errorcode, it) break end @@ -87,3 +79,19 @@ for it = options.periods:-1:1 end end + +function [r, J] = dynamic_forward_model_for_simulation(z, dynamic_resid, dynamic_g1, ylead, x, params, steady_state, sparse_rowval, sparse_colval, sparse_colptr) + +endo_nbr = length(z); + +y = [ NaN(endo_nbr, 1); z; ylead]; + +[r, T_order, T] = dynamic_resid(y, x, params, steady_state); + +if nargout>1 + Jacobian = dynamic_g1(y, x, params, steady_state, sparse_rowval, ... + sparse_colval, sparse_colptr, T_order, T); + J = Jacobian(:, endo_nbr+(1:endo_nbr)); +end + +end diff --git a/matlab/perfect-foresight-models/sim1_purely_static.m b/matlab/perfect-foresight-models/sim1_purely_static.m index 9e0c6623b7f3c8a55b4e07ae0b5ebee1ad1aae7c..76913d74053a5f50ca8e6b5f14750835cb024a59 100644 --- a/matlab/perfect-foresight-models/sim1_purely_static.m +++ b/matlab/perfect-foresight-models/sim1_purely_static.m @@ -1,8 +1,8 @@ -function [endogenousvariables, info] = sim1_purely_static(endogenousvariables, exogenousvariables, steadystate, M, options) +function [endogenousvariables, success] = sim1_purely_static(endogenousvariables, exogenousvariables, steadystate, M, options) % Performs deterministic simulation of a purely static model -% Copyright © 2021-2022 Dynare Team +% Copyright © 2021-2023 Dynare Team % % This file is part of Dynare. % @@ -19,15 +19,11 @@ function [endogenousvariables, info] = sim1_purely_static(endogenousvariables, e % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -if nnz(M.lead_lag_incidence(1,:)) ~= M.endo_nbr - error('All endogenous variables must appear at the current period!') -end - if ismember(options.solve_algo, [12,14]) [funcs, feedback_vars_idxs] = setup_time_recursive_block_simul(M); else - dynamicmodel = str2func(sprintf('%s.%s', M.fname, 'dynamic')); - dynamicmodel_s = str2func('dynamic_static_model_for_simulation'); + dynamic_resid = str2func([M.fname '.sparse.dynamic_resid']); + dynamic_g1 = str2func([M.fname '.sparse.dynamic_g1']); end function [r, J] = block_wrapper(z, feedback_vars_idx, func, y_dynamic, x, sparse_rowval, sparse_colval, sparse_colptr, T) @@ -38,13 +34,13 @@ function [r, J] = block_wrapper(z, feedback_vars_idx, func, y_dynamic, x, sparse sparse_rowval, sparse_colval, sparse_colptr, T); end -info.status = true; +success = true; y = endogenousvariables(:,1); for it = 1:options.periods + x = exogenousvariables(it,:); if ismember(options.solve_algo, [12,14]) - x = exogenousvariables(it,:); T = NaN(M.block_structure.dyn_tmp_nbr); y_dynamic = [NaN(M.endo_nbr, 1); y; NaN(M.endo_nbr, 1)]; for blk = 1:length(M.block_structure.block) @@ -57,7 +53,7 @@ for it = 1:options.periods options.dynatol.x, options, ... feedback_vars_idxs{blk}, funcs{blk}, y_dynamic, x, sparse_rowval, sparse_colval, sparse_colptr, T); if check - info.status = false; + success = false; if options.debug dprintf('sim1_purely_static: Nonlinear solver routine failed with errorcode=%i in block %i and period %i.', errorcode, blk, it) end @@ -72,11 +68,11 @@ for it = 1:options.periods end endogenousvariables(:,it) = y_dynamic(M.endo_nbr+(1:M.endo_nbr)); else - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, ... + [tmp, check, ~, ~, errorcode] = dynare_solve(@dynamic_static_model_for_simulation, y, ... options.simul.maxit, options.dynatol.f, options.dynatol.x, ... - options, dynamicmodel, exogenousvariables, M.params, steadystate, it); + options, dynamic_resid, dynamic_g1, x, M.params, steadystate, M.dynamic_g1_sparse_rowval, M.dynamic_g1_sparse_colval, M.dynamic_g1_sparse_colptr); if check - info.status = false; + success = false; if options.debug dprintf('sim1_purely_static: Nonlinear solver routine failed with errorcode=%i in period %i.', errorcode, it) end @@ -87,3 +83,19 @@ for it = 1:options.periods end end + +function [r, J] = dynamic_static_model_for_simulation(z, dynamic_resid, dynamic_g1, x, params, steady_state, sparse_rowval, sparse_colval, sparse_colptr) + +endo_nbr = length(z); + +y = [ NaN(endo_nbr, 1); z; NaN(endo_nbr, 1)]; + +[r, T_order, T] = dynamic_resid(y, x, params, steady_state); + +if nargout>1 + Jacobian = dynamic_g1(y, x, params, steady_state, sparse_rowval, ... + sparse_colval, sparse_colptr, T_order, T); + J = Jacobian(:, endo_nbr+(1:endo_nbr)); +end + +end diff --git a/matlab/perfect-foresight-models/solve_block_decomposed_problem.m b/matlab/perfect-foresight-models/solve_block_decomposed_problem.m index 85989f652dc28b37f50374bc645ebce2c87b4594..ed6637f112dc07105a143de8b572b1de450c947a 100644 --- a/matlab/perfect-foresight-models/solve_block_decomposed_problem.m +++ b/matlab/perfect-foresight-models/solve_block_decomposed_problem.m @@ -1,4 +1,4 @@ -function oo_ = solve_block_decomposed_problem(options_, M_, oo_) +function [y, success, maxerror, per_block_status] = solve_block_decomposed_problem(options_, M_, oo_) % Computes deterministic simulation with block option without bytecode % Copyright © 2020-2023 Dynare Team @@ -41,23 +41,20 @@ end y=oo_.endo_simul; T=NaN(M_.block_structure.dyn_tmp_nbr, options_.periods+M_.maximum_lag+M_.maximum_lead); -oo_.deterministic_simulation.status = false; + +maxerror = 0; +nblocks = length(M_.block_structure.block); +per_block_status = struct('success', cell(1, nblocks), 'error', cell(1, nblocks), 'iterations', cell(1, nblocks)); funcname = [ M_.fname '.dynamic']; -for blk = 1:length(M_.block_structure.block) +for blk = 1:nblocks recursive_size = M_.block_structure.block(blk).endo_nbr - M_.block_structure.block(blk).mfs; y_index = M_.block_structure.block(blk).variable((recursive_size+1):end); fh_dynamic = str2func(sprintf('%s.sparse.block.dynamic_%d', M_.fname, blk)); if M_.block_structure.block(blk).Simulation_Type == 1 || ... % evaluateForward M_.block_structure.block(blk).Simulation_Type == 2 % evaluateBackward - oo_.deterministic_simulation.status = true; - oo_.deterministic_simulation.error = 0; - oo_.deterministic_simulation.iterations = 0; - oo_.deterministic_simulation.block(blk).status = true; - oo_.deterministic_simulation.block(blk).error = 0; - oo_.deterministic_simulation.block(blk).iterations = 0; if M_.block_structure.block(blk).Simulation_Type == 1 range = M_.maximum_lag+1:M_.maximum_lag+options_.periods; else @@ -79,28 +76,33 @@ for blk = 1:length(M_.block_structure.block) M_.block_structure.block(blk).g1_sparse_colptr, T(:, it_)); y(:, it_) = y3n(M_.endo_nbr+(1:M_.endo_nbr)); end + success = true; + maxblkerror = 0; + iter = []; elseif M_.block_structure.block(blk).Simulation_Type == 3 || ... % solveForwardSimple M_.block_structure.block(blk).Simulation_Type == 4 || ... % solveBackwardSimple M_.block_structure.block(blk).Simulation_Type == 6 || ... % solveForwardComplete M_.block_structure.block(blk).Simulation_Type == 7 % solveBackwardComplete is_forward = M_.block_structure.block(blk).Simulation_Type == 3 || M_.block_structure.block(blk).Simulation_Type == 6; - [y, T, oo_] = solve_one_boundary(fh_dynamic, y, oo_.exo_simul, M_.params, oo_.steady_state, T, y_index, M_.block_structure.block(blk).NNZDerivatives, options_.periods, M_.block_structure.block(blk).is_linear, blk, M_.maximum_lag, options_.simul.maxit, options_.dynatol.f, cutoff, options_.stack_solve_algo, is_forward, true, false, M_, options_, oo_); + [y, T, success, maxblkerror, iter] = solve_one_boundary(fh_dynamic, y, oo_.exo_simul, M_.params, oo_.steady_state, T, y_index, M_.block_structure.block(blk).NNZDerivatives, options_.periods, M_.block_structure.block(blk).is_linear, blk, M_.maximum_lag, options_.simul.maxit, options_.dynatol.f, cutoff, options_.stack_solve_algo, is_forward, true, false, M_, options_); elseif M_.block_structure.block(blk).Simulation_Type == 5 || ... % solveTwoBoundariesSimple M_.block_structure.block(blk).Simulation_Type == 8 % solveTwoBoundariesComplete - [y, T, oo_] = solve_two_boundaries(fh_dynamic, y, oo_.exo_simul, M_.params, oo_.steady_state, T, y_index, M_.block_structure.block(blk).NNZDerivatives, options_.periods, M_.block_structure.block(blk).is_linear, blk, M_.maximum_lag, options_.simul.maxit, options_.dynatol.f, cutoff, options_.stack_solve_algo, options_, M_, oo_); + [y, T, success, maxblkerror, iter] = solve_two_boundaries(fh_dynamic, y, oo_.exo_simul, M_.params, oo_.steady_state, T, y_index, M_.block_structure.block(blk).NNZDerivatives, options_.periods, M_.block_structure.block(blk).is_linear, blk, M_.maximum_lag, options_.simul.maxit, options_.dynatol.f, cutoff, options_.stack_solve_algo, options_, M_); end tmp = y(M_.block_structure.block(blk).variable, :); if any(isnan(tmp) | isinf(tmp)) disp(['Inf or Nan value during the resolution of block ' num2str(blk)]); - oo_.deterministic_simulation.status = false; - oo_.deterministic_simulation.error = 100; - oo_.deterministic_simulation.block(blk).status = false; - oo_.deterministic_simulation.block(blk).error = 100; + success = false; end - if ~oo_.deterministic_simulation.status + + per_block_status(blk).success = success; + per_block_status(blk).error = maxblkerror; + per_block_status(blk).iter = iter; + + maxerror = max(maxblkerror, maxerror); + + if ~success return end end - -oo_.endo_simul = y; diff --git a/matlab/perfect-foresight-models/solve_stacked_linear_problem.m b/matlab/perfect-foresight-models/solve_stacked_linear_problem.m index 80c876d13873b6c3b5268ac2fae31e021aa82ed3..c937fdfa8bac574ab7d6edd309610b8449d07c67 100644 --- a/matlab/perfect-foresight-models/solve_stacked_linear_problem.m +++ b/matlab/perfect-foresight-models/solve_stacked_linear_problem.m @@ -1,6 +1,6 @@ -function [endogenousvariables, info] = solve_stacked_linear_problem(endogenousvariables, exogenousvariables, steadystate_y, steadystate_x, M, options) +function [endogenousvariables, success] = solve_stacked_linear_problem(endogenousvariables, exogenousvariables, steadystate_y, steadystate_x, M, options) -% Copyright © 2015-2022 Dynare Team +% Copyright © 2015-2023 Dynare Team % % This file is part of Dynare. % @@ -60,11 +60,8 @@ end endogenousvariables = [y0 bsxfun(@plus,reshape(y,M.endo_nbr,options.periods), steadystate_y) yT]; -if check - info.status = false; - if options.debug - dprintf('solve_stacked_linear_problem: Nonlinear solver routine failed with errorcode=%i.', errorcode) - end -else - info.status = true; +success = ~check; + +if ~success && options.debug + dprintf('solve_stacked_linear_problem: Nonlinear solver routine failed with errorcode=%i.', errorcode) end diff --git a/matlab/perfect-foresight-models/solve_stacked_problem.m b/matlab/perfect-foresight-models/solve_stacked_problem.m index b93ec76141f40fe2beefa6b5908ab3be49fdf826..f9c2c4fcb947c0400970457a80dcb8b697363e09 100644 --- a/matlab/perfect-foresight-models/solve_stacked_problem.m +++ b/matlab/perfect-foresight-models/solve_stacked_problem.m @@ -1,4 +1,4 @@ -function [endogenousvariables, info, residuals] = solve_stacked_problem(endogenousvariables, exogenousvariables, steadystate, M, options) +function [endogenousvariables, success, maxerror] = solve_stacked_problem(endogenousvariables, exogenousvariables, steadystate, M, options) % Solves the perfect foresight model using dynare_solve % @@ -11,10 +11,10 @@ function [endogenousvariables, info, residuals] = solve_stacked_problem(endogeno % % OUTPUTS % - endogenousvariables [double] N*T array, paths for the endogenous variables (solution of the perfect foresight model). -% - info [struct] contains informations about the results. -% - residuals [double] N*T array, residuals of the equations (with 0 for initial condition) +% - success [logical] Whether a solution was found +% - maxerror [double] 1-norm of the residual -% Copyright © 2015-2022 Dynare Team +% Copyright © 2015-2023 Dynare Team % % This file is part of Dynare. % @@ -77,12 +77,9 @@ residuals(:, M.maximum_lag+(1:options.periods)) = reshape(res, M.endo_nbr, optio if (options.solve_algo == 10 || options.solve_algo == 11)% mixed complementarity problem residuals(eq_to_ignore,bsxfun(@le, endogenousvariables(eq_to_ignore,:), lb(eq_to_ignore)+eps) | bsxfun(@ge,endogenousvariables(eq_to_ignore,:),ub(eq_to_ignore)-eps))=0; end +maxerror = max(max(abs(residuals))); +success = ~check; -if check - info.status = false; - if options.debug - dprintf('solve_stacked_problem: Nonlinear solver routine failed with errorcode=%i.', errorcode) - end -else - info.status = true; +if ~success && options.debug + dprintf('solve_stacked_problem: Nonlinear solver routine failed with errorcode=%i.', errorcode) end diff --git a/matlab/posterior_sampler_core.m b/matlab/posterior_sampler_core.m index 7925f482b63098b3aaae4a30b40aa90476a2d938..0722858c4cdfa9a91d5c829a0fb322f1f7b315ea 100644 --- a/matlab/posterior_sampler_core.m +++ b/matlab/posterior_sampler_core.m @@ -36,7 +36,7 @@ function myoutput = posterior_sampler_core(myinputs,fblck,nblck,whoiam, ThisMatl % See the comments in the posterior_sampler.m funtion. -% Copyright © 2006-2017 Dynare Team +% Copyright © 2006-2023 Dynare Team % % This file is part of Dynare. % @@ -86,8 +86,6 @@ oo_ = myinputs.oo_; if whoiam % initialize persistent variables in priordens() priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, bayestopt_.p3,bayestopt_.p4,1); - % initialize persistent variables in prior_draw() - prior_draw(bayestopt_,options_.prior_trunc); end MetropolisFolder = CheckPath('metropolis',M_.dname); diff --git a/matlab/posterior_sampler_initialization.m b/matlab/posterior_sampler_initialization.m index 52ba42060acc6b7543f37ed79dd630e557d09f66..60a909d2c6d6993707dcf33bd667aa21c01a2f26 100644 --- a/matlab/posterior_sampler_initialization.m +++ b/matlab/posterior_sampler_initialization.m @@ -38,7 +38,7 @@ function [ ix2, ilogpo2, ModelName, MetropolisFolder, FirstBlock, FirstLine, npa % SPECIAL REQUIREMENTS % None. -% Copyright © 2006-2017 Dynare Team +% Copyright © 2006-2023 Dynare Team % % This file is part of Dynare. % @@ -113,7 +113,7 @@ if ~options_.load_mh_file && ~options_.mh_recover fprintf(fidlog,[' Number of simulations per block: ' int2str(nruns(1)) '\n']); fprintf(fidlog,' \n'); if isempty(d) - prior_draw(bayestopt_,options_.prior_trunc); + Prior = dprior(bayestopt_, options_.prior_trunc); end if options_.mh_initialize_from_previous_mcmc.status PreviousFolder0 = options_.mh_initialize_from_previous_mcmc.directory; @@ -132,7 +132,7 @@ if ~options_.load_mh_file && ~options_.mh_recover MetropolisFolder0 = fileparts(RecordFile0); PreviousFolder0=fileparts(MetropolisFolder0); [~, ModelName0]=fileparts(PreviousFolder0); - else + else %% check for proper filesep char in user defined paths PreviousFolder0=strrep(PreviousFolder0,'\',filesep); MetropolisFolder0 = [PreviousFolder0 filesep 'metropolis']; @@ -195,7 +195,7 @@ if ~options_.load_mh_file && ~options_.mh_recover trial = 1; while validate == 0 && trial <= 10 if isempty(d) - candidate = prior_draw(); + candidate = Prior.draw(); else if isfield(options_,'mh_init_scale') if trial==1 @@ -228,7 +228,7 @@ if ~options_.load_mh_file && ~options_.mh_recover if options_.nointeractive disp(['Estimation::mcmc: I reduce mh_init_scale_factor by 10 percent:']) if isfield(options_,'mh_init_scale') - options_.mh_init_scale = .9*options_.mh_init_scale; + options_.mh_init_scale = .9*options_.mh_init_scale; fprintf('Estimation::mcmc: Parameter mh_init_scale is now equal to %f.\n',options_.mh_init_scale) else options_.mh_init_scale_factor = .9*options_.mh_init_scale_factor; @@ -301,7 +301,6 @@ if ~options_.load_mh_file && ~options_.mh_recover if options_.mh_initialize_from_previous_mcmc.status record.InitialSeeds = record0.LastSeeds; else - for j=1:NumberOfBlocks % we set a different seed for the random generator for each block then we record the corresponding random generator state (vector) set_dynare_seed(options_.DynareRandomStreams.seed+j); @@ -502,7 +501,7 @@ elseif options_.mh_recover % How many mh-files are saved in this block? ExistingDrawsInLastMCFile=zeros(NumberOfBlocks,1); %initialize: no MCMC draws of current MCMC are in file from last run % Check whether last present file is a file included in the last MCMC run - + update_record=0; for k=1:NumberOfBlocks FirstBlock = k; diff --git a/matlab/prior_posterior_statistics_core.m b/matlab/prior_posterior_statistics_core.m index 7d04d28450e4df46fbf949220aa6eeaf5116c63f..64cf7685a7c77bb63390733fbdcffe44cfc577a9 100644 --- a/matlab/prior_posterior_statistics_core.m +++ b/matlab/prior_posterior_statistics_core.m @@ -30,7 +30,7 @@ function myoutput=prior_posterior_statistics_core(myinputs,fpar,B,whoiam, ThisMa % SPECIAL REQUIREMENTS. % None. -% Copyright © 2005-2020 Dynare Team +% Copyright © 2005-2023 Dynare Team % % This file is part of Dynare. % @@ -109,8 +109,8 @@ if ~strcmpi(type,'prior') logpost=myinputs.logpost; end else - x=(prior_draw(bayestopt_,options_.prior_trunc))'; - options_=select_qz_criterium_value(options_); + Prior = dprior(bayestopt_,options_.prior_trunc); + options_ = select_qz_criterium_value(options_); end if whoiam Parallel=myinputs.Parallel; @@ -180,9 +180,9 @@ end if naK stock_filter_step_ahead =NaN(length(options_.filter_step_ahead),endo_nbr,gend+max(options_.filter_step_ahead),MAX_naK); end -stock_param = NaN(MAX_nruns,size(x,2)); -stock_logpo = NaN(MAX_nruns,1); -stock_ys = NaN(MAX_nruns,endo_nbr); +stock_param = NaN(MAX_nruns, length(bayestopt_.p6)); +stock_logpo = NaN(MAX_nruns, 1); +stock_ys = NaN(MAX_nruns, endo_nbr); if filter_covariance stock_filter_covariance = zeros(endo_nbr,endo_nbr,gend+1,MAX_filter_covariance); end @@ -196,7 +196,8 @@ for b=fpar:B iter=1; logpo=[]; while (isempty(logpo) || isinf(logpo)) && iter<1000 - [deep, logpo] = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_); + deep = Prior.draw(); + logpo = evaluate_posterior_kernel(deep, M_, estim_params_, oo_, options_, bayestopt_) iter=iter+1; end if iter==1000 @@ -214,7 +215,7 @@ for b=fpar:B if run_smoother [dr,info,M_,oo_] =compute_decision_rules(M_,opts_local,oo_); - if ismember(info(1),[3,4]) + if ismember(info(1),[3,4]) opts_local.qz_criterium = 1 + (opts_local.qz_criterium-1)*10; %loosen tolerance, useful for big models where BK conditions were tested on restricted state space [dr,info,M_,oo_] =compute_decision_rules(M_,opts_local,oo_); end diff --git a/matlab/prior_sampler.m b/matlab/prior_sampler.m index 75b1896fd30c70f17eb76214eb1e6cd0713f0a33..1303cbcf02784a45d506f4f30e83aa26b3787263 100644 --- a/matlab/prior_sampler.m +++ b/matlab/prior_sampler.m @@ -13,7 +13,7 @@ function results = prior_sampler(drsave,M_,bayestopt_,options_,oo_,estim_params_ % SPECIAL REQUIREMENTS % none -% Copyright © 2009-2018 Dynare Team +% Copyright © 2009-2023 Dynare Team % % This file is part of Dynare. % @@ -31,7 +31,7 @@ function results = prior_sampler(drsave,M_,bayestopt_,options_,oo_,estim_params_ % along with Dynare. If not, see <https://www.gnu.org/licenses/>. % Initialization. -prior_draw(bayestopt_, options_.prior_trunc); +Prior = dprior(bayestopt_, options_.prior_trunc); PriorDirectoryName = CheckPath('prior/draws',M_.dname); work = ~drsave; iteration = 0; @@ -94,10 +94,10 @@ while iteration < NumberOfSimulations dyn_waitbar(iteration/NumberOfSimulations,hh,'Please wait. Prior sampler...'); end loop_indx = loop_indx+1; - params = prior_draw(); - M_ = set_all_parameters(params,estim_params_,M_); - [T,R,~,INFO,M_,oo_] = dynare_resolve(M_,options_,oo_,'restrict'); - dr=oo_.dr; + params = Prior.draw(); + M_ = set_all_parameters(params, estim_params_, M_); + [T, R, ~, INFO, M_, oo_] = dynare_resolve(M_, options_, oo_, 'restrict'); + dr = oo_.dr; if ~INFO(1) INFO=endogenous_prior_restrictions(T,R,M_,options_,oo_); end @@ -200,4 +200,4 @@ m1 = m0 + (newobs'-m0)/iter; qq = m1*m1'; s1 = s0 + ( (newobs'*newobs-qq-s0) + (iter-1)*(m0*m0'-qq') )/iter; mu = m1; -sigma = s1; \ No newline at end of file +sigma = s1; diff --git a/matlab/ramsey_policy.m b/matlab/ramsey_policy.m deleted file mode 100644 index a12e954c74105afe7443826f242933423a3dd782..0000000000000000000000000000000000000000 --- a/matlab/ramsey_policy.m +++ /dev/null @@ -1,57 +0,0 @@ -function info = ramsey_policy(var_list) - -% Copyright © 2007-2021 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/>. - -global options_ oo_ M_ - -options_.ramsey_policy = 1; -oldoptions = options_; - -%test whether specification matches -inst_nbr = size(options_.instruments,1); -if inst_nbr~=0 - orig_endo_aux_nbr = M_.orig_endo_nbr + min(find([M_.aux_vars.type] == 6)) - 1; - implied_inst_nbr = orig_endo_aux_nbr - M_.orig_eq_nbr; - if inst_nbr>implied_inst_nbr - error('You have specified more instruments than there are omitted equations') - elseif inst_nbr<implied_inst_nbr - error('You have specified fewer instruments than there are omitted equations') - end -else - if options_.steadystate_flag - error('You have specified a steady state file, but not provided an instrument. Either delete the steady state file or provide an instrument') - end -end - -[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list); - -oo_.steady_state = oo_.dr.ys; - -if ~options_.noprint - disp_steady_state(M_,oo_,options_) - for i=M_.orig_endo_nbr:M_.endo_nbr - if strmatch('mult_', M_.endo_names{i}) - disp(sprintf('%s \t\t %g', M_.endo_names{i}, oo_.dr.ys(i))); - end - end -end - - -oo_.planner_objective_value = evaluate_planner_objective(M_,options_,oo_); - -options_ = oldoptions; diff --git a/matlab/resol.m b/matlab/resol.m index 6c3fd30e5c55d1ef67b62862bdef5e9388747b7c..0726b309d4cfa874122b40bf8284a1de08002ce8 100644 --- a/matlab/resol.m +++ b/matlab/resol.m @@ -74,7 +74,7 @@ if M.exo_nbr == 0 oo.exo_steady_state = [] ; end -[dr.ys,M.params,info] = evaluate_steady_state(oo.steady_state,M,options,oo,~options.steadystate.nocheck); +[dr.ys,M.params,info] = evaluate_steady_state(oo.steady_state,[oo.exo_steady_state; oo.exo_det_steady_state],M,options,~options.steadystate.nocheck); if info(1) oo.dr = dr; diff --git a/matlab/slice_sampler.m b/matlab/slice_sampler.m index a50c12ab6c4944fd329379ba1b613e21d541d010..73fc6c3479a641dde7a861e86407a1269ec9506e 100644 --- a/matlab/slice_sampler.m +++ b/matlab/slice_sampler.m @@ -24,7 +24,7 @@ function [theta, fxsim, neval] = slice_sampler(objective_function,theta,thetapri % SPECIAL REQUIREMENTS % none -% Copyright © 2015-2017 Dynare Team +% Copyright © 2015-2023 Dynare Team % % This file is part of Dynare. % @@ -58,6 +58,8 @@ neval = zeros(npar,1); % % % fname0=fname; fname = [ int2str(sampler_options.curr_block)]; +Prior = dprior(varargin{6},varargin{3}.prior_trunc); + it=0; while it<npar it=it+1; @@ -80,8 +82,8 @@ while it<npar icount=0; while ~isfinite(fxold) && icount<1000 icount=icount+1; - theta = prior_draw(); - if all(theta(:) >= thetaprior(:,1)) && all(theta(:) <= thetaprior(:,2)) + theta = Prior.draw(); + if all(theta >= thetaprior(:,1)) && all(theta <= thetaprior(:,2)) fxold = -feval(objective_function,theta,varargin{:}); end end diff --git a/matlab/solve_one_boundary.m b/matlab/solve_one_boundary.m index 932d50ff8c284c502c4031bb4d3c678b02a51238..0d49b58f5c8786f718d75e94775f3abf00c86e64 100644 --- a/matlab/solve_one_boundary.m +++ b/matlab/solve_one_boundary.m @@ -1,5 +1,5 @@ -function [y, T, oo_, info] = solve_one_boundary(fh, y, x, params, steady_state, T, ... - y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, cutoff, stack_solve_algo, is_forward, is_dynamic, verbose, M, options, oo_) +function [y, T, success, max_res, iter] = solve_one_boundary(fh, y, x, params, steady_state, T, ... + y_index_eq, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, cutoff, stack_solve_algo, is_forward, is_dynamic, verbose, M, options) % Computes the deterministic simulation or the steady state for a block of equations containing % only lags or only leads (but not both). % @@ -25,17 +25,15 @@ function [y, T, oo_, info] = solve_one_boundary(fh, y, x, params, steady_state, % stack_solve_algo [integer] linear solver method used in the Newton algorithm % is_forward [logical] Whether the block has to be solved forward % If false, the block is solved backward -% is_dynamic [logical] If true, this is a deterministic simulation -% and the oo_.deterministic_simulation field is updated. -% If false, this is a steady state computation -% (oo_.detereministic_simulation remains unchanged). +% is_dynamic [logical] Whether this is a deterministic simulation % verbose [logical] Whether iterations are to be printed % % OUTPUTS -% y [matrix] All endogenous variables of the model -% T [matrix] Temporary terms -% info [integer] >=0 no error -% <0 error +% y [matrix] All endogenous variables of the model +% T [matrix] Temporary terms +% success [logical] Whether a solution was found +% max_res [double] ∞-norm of the residual +% iter [integer] Number of iterations % % ALGORITHM % Newton with LU or GMRES or BicGstab for dynamic block @@ -135,15 +133,7 @@ for it_=start:incr:finish if verbose disp('The singularity of the jacobian matrix could not be corrected') end - if is_dynamic - oo_.deterministic_simulation.status = false; - oo_.deterministic_simulation.error = max_res; - oo_.deterministic_simulation.iterations = iter; - oo_.deterministic_simulation.block(Block_Num).status = false;% Convergency failed. - oo_.deterministic_simulation.block(Block_Num).error = max_res; - oo_.deterministic_simulation.block(Block_Num).iterations = iter; - end - info = -Block_Num*10; + success = false; return end end @@ -162,20 +152,12 @@ for it_=start:incr:finish else if verbose if cutoff==0 - fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.simul.maxit".\n',Block_Num, it_, iter); + fprintf('Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "maxit".\n',Block_Num, it_, iter); else - fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.simul.maxit" or set "cutoff=0" in model options.\n',Block_Num, it_, iter); + fprintf('Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "maxit" or set "cutoff=0" in model options.\n',Block_Num, it_, iter); end end - if is_dynamic - oo_.deterministic_simulation.status = false; - oo_.deterministic_simulation.error = max_res; - oo_.deterministic_simulation.iterations = iter; - oo_.deterministic_simulation.block(Block_Num).status = false;% Convergency failed. - oo_.deterministic_simulation.block(Block_Num).error = max_res; - oo_.deterministic_simulation.block(Block_Num).iterations = iter; - end - info = -Block_Num*10; + success = false; return end else @@ -291,35 +273,18 @@ for it_=start:incr:finish if ~cvg if verbose if cutoff == 0 - fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.simul.maxit\".\n',Block_Num, it_,iter); + fprintf('Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "maxit".\n',Block_Num, it_,iter); else - fprintf('Error in simul: Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "options_.simul.maxit" or set "cutoff=0" in model options.\n',Block_Num, it_,iter); + fprintf('Convergence not achieved in block %d, at time %d, after %d iterations.\n Increase "maxit" or set "cutoff=0" in model options.\n',Block_Num, it_,iter); end end - if is_dynamic - oo_.deterministic_simulation.status = false; - oo_.deterministic_simulation.error = max_res; - oo_.deterministic_simulation.iterations = iter; - oo_.deterministic_simulation.block(Block_Num).status = false;% Convergency failed. - oo_.deterministic_simulation.block(Block_Num).error = max_res; - oo_.deterministic_simulation.block(Block_Num).iterations = iter; - end - info = -Block_Num*10; + success = false; return end end -if is_dynamic - info = 1; - oo_.deterministic_simulation.status = true; - oo_.deterministic_simulation.error = max_res; - oo_.deterministic_simulation.iterations = iter; - oo_.deterministic_simulation.block(Block_Num).status = true; - oo_.deterministic_simulation.block(Block_Num).error = max_res; - oo_.deterministic_simulation.block(Block_Num).iterations = iter; -else - info = 0; -end +success = true; + function y3n = dynendo(y, it_, M) if it_ > 1 && it_ < size(y, 2) diff --git a/matlab/solve_two_boundaries.m b/matlab/solve_two_boundaries.m index 7ad7a4f40c64acd75aa7bc2a7b6952e9e206d262..416d6fbb7b283848add3e990b3560e01ade6267c 100644 --- a/matlab/solve_two_boundaries.m +++ b/matlab/solve_two_boundaries.m @@ -1,4 +1,4 @@ -function [y, T, oo]= solve_two_boundaries(fh, y, x, params, steady_state, T, y_index, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, cutoff, stack_solve_algo,options,M, oo) +function [y, T, success, max_res, iter] = solve_two_boundaries(fh, y, x, params, steady_state, T, y_index, nze, periods, is_linear, Block_Num, y_kmin, maxit_, solve_tolf, cutoff, stack_solve_algo,options,M) % Computes the deterministic simulation of a block of equation containing % both lead and lag variables using relaxation methods % @@ -28,12 +28,13 @@ function [y, T, oo]= solve_two_boundaries(fh, y, x, params, steady_state, T, y_i % - 3 BicGStab % - 4 Optimal path length % M [structure] Model description -% oo [structure] Results % % OUTPUTS % y [matrix] All endogenous variables of the model % T [matrix] Temporary terms -% oo [structure] Results +% success [logical] Whether a solution was found +% max_res [double] ∞-norm of the residual +% iter [integer] Number of iterations % % ALGORITHM % Newton with LU or GMRES or BicGstab @@ -131,12 +132,7 @@ while ~(cvg || iter>maxit_) continue else disp('The singularity of the jacobian matrix could not be corrected'); - oo.deterministic_simulation.status = false; - oo.deterministic_simulation.error = max_res; - oo.deterministic_simulation.iterations = iter; - oo.deterministic_simulation.block(Block_Num).status = false;% Convergency failed. - oo.deterministic_simulation.block(Block_Num).error = max_res; - oo.deterministic_simulation.block(Block_Num).iterations = iter; + success = false; return end end @@ -151,17 +147,12 @@ while ~(cvg || iter>maxit_) else if verbose if cutoff==0 - fprintf('Error in simul: Convergence not achieved in block %d, after %d iterations.\n Increase "options_.simul.maxit".\n',Block_Num, iter); + fprintf('Convergence not achieved in block %d, after %d iterations.\n Increase "maxit".\n',Block_Num, iter); else - fprintf('Error in simul: Convergence not achieved in block %d, after %d iterations.\n Increase "options_.simul.maxit" or set "cutoff=0" in model options.\n',Block_Num, iter); + fprintf('Convergence not achieved in block %d, after %d iterations.\n Increase "maxit" or set "cutoff=0" in model options.\n',Block_Num, iter); end end - oo.deterministic_simulation.status = false; - oo.deterministic_simulation.error = max_res; - oo.deterministic_simulation.iterations = iter; - oo.deterministic_simulation.block(Block_Num).status = false;% Convergency failed. - oo.deterministic_simulation.block(Block_Num).error = max_res; - oo.deterministic_simulation.block(Block_Num).iterations = iter; + success = false; return end else @@ -333,21 +324,12 @@ if (iter>maxit_) printline(41) %disp(['No convergence after ' num2str(iter,'%4d') ' iterations in Block ' num2str(Block_Num,'%d')]) end - oo.deterministic_simulation.status = false; - oo.deterministic_simulation.error = max_res; - oo.deterministic_simulation.iterations = iter; - oo.deterministic_simulation.block(Block_Num).status = false;% Convergency failed. - oo.deterministic_simulation.block(Block_Num).error = max_res; - oo.deterministic_simulation.block(Block_Num).iterations = iter; + success = false; return end -oo.deterministic_simulation.status = true; -oo.deterministic_simulation.error = max_res; -oo.deterministic_simulation.iterations = iter; -oo.deterministic_simulation.block(Block_Num).status = true;% Convergency obtained. -oo.deterministic_simulation.block(Block_Num).error = max_res; -oo.deterministic_simulation.block(Block_Num).iterations = iter; +success = true; + function y3n = dynendo(y, it_, M) y3n = reshape(y(:, it_+(-1:1)), 3*M.endo_nbr, 1); diff --git a/matlab/static_model_for_inversion.m b/matlab/static_model_for_inversion.m deleted file mode 100644 index 7b1572dc1b5215d31b36249568b20828a47f315d..0000000000000000000000000000000000000000 --- a/matlab/static_model_for_inversion.m +++ /dev/null @@ -1,38 +0,0 @@ -function [r, J] = static_model_for_inversion(z, dynamicmodel, ycur, x, params, ModelInversion) - -% Copyright © 2019 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/>. - -% Set up y -y = zeros(ModelInversion.nyfree+ModelInversion.nyctrl, 1); - -y(ModelInversion.y_constrained_id) = ycur; -if ModelInversion.nyfree - y(ModelInversion.y_free_id) = z(1:ModelInversion.nyfree); -end - -% Update x -x(ModelInversion.x_free_id) = z(ModelInversion.nyfree+(1:ModelInversion.nxfree)); - -if nargout>1 - [r, Jacobian] = feval(dynamicmodel, y, x, params, [], 1); -else - r = feval(dynamicmodel, y, x, params, [], 1); - return -end - -J = Jacobian(:,ModelInversion.J_id); diff --git a/matlab/static_model_inversion.m b/matlab/static_model_inversion.m index 06bb20ba38ccaad2fa40abe17ec7a5c80ebe49c0..9549d37773bb9d60cb8d1a3c4c961b8010004d54 100644 --- a/matlab/static_model_inversion.m +++ b/matlab/static_model_inversion.m @@ -1,4 +1,4 @@ -function [endogenousvariables, exogenousvariables] = static_model_inversion(constraints, exogenousvariables, endo_names, exo_names, freeinnovations, DynareModel, DynareOptions, ~) +function [endogenousvariables, exogenousvariables] = static_model_inversion(constraints, exogenousvariables, endo_names, exo_names, freeinnovations, DynareModel, DynareOptions, DynareOutput) % INPUTS % - constraints [dseries] with N constrained endogenous variables from t1 to t2. @@ -13,7 +13,7 @@ function [endogenousvariables, exogenousvariables] = static_model_inversion(cons % % REMARKS -% Copyright © 2019-2022 Dynare Team +% Copyright © 2019-2023 Dynare Team % % This file is part of Dynare. % @@ -30,20 +30,17 @@ function [endogenousvariables, exogenousvariables] = static_model_inversion(cons % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. -% Get indices for the calibrated and free innovations. +% Get indices for the free innovations. freeinnovations_id = zeros(length(freeinnovations), 1); if length(freeinnovations)<DynareModel.exo_nbr for i=1:length(freeinnovations) freeinnovations_id(i) = find(strcmp(freeinnovations{i}, exo_names)); end - calibratedinnovations_id = setdiff(transpose(1:length(exo_names)), freeinnovations_id); else freeinnovations_id = transpose(1:length(exo_names)); - calibratedinnovations_id = []; end nxfree = length(freeinnovations_id); -nxcalb = length(calibratedinnovations_id); % Get indices for the the controlled and free endogenous variables. controlledendogenousvariables_id = zeros(length(freeinnovations), 1); @@ -60,25 +57,18 @@ end nyfree = length(freeendogenousvariables_id); nyctrl = length(controlledendogenousvariables_id); -% Get indices of variables appearing at time t-1. -% should be empty. iy1 = find(DynareModel.lead_lag_incidence(1,:)>0); - -% Get indices of variables appearing at time t. -% all variables appear at time t in a static model. iy0 = find(DynareModel.lead_lag_incidence(2,:)>0); - % Build structure to be passed to the objective function. ModelInversion.nyfree = nyfree; ModelInversion.nyctrl = nyctrl; ModelInversion.nxfree = nxfree; -ModelInversion.nxcalb = nxcalb; -ModelInversion.y_constrained_id = vec(DynareModel.lead_lag_incidence(controlledendogenousvariables_id)); -ModelInversion.y_free_id = vec(DynareModel.lead_lag_incidence(freeendogenousvariables_id)); +ModelInversion.y_constrained_id = controlledendogenousvariables_id; +ModelInversion.y_free_id = freeendogenousvariables_id; ModelInversion.x_free_id = freeinnovations_id; -ModelInversion.J_id = [ModelInversion.y_free_id ; sum(DynareModel.lead_lag_incidence(:)>0)+ModelInversion.x_free_id]; +ModelInversion.J_id = [DynareModel.endo_nbr+ModelInversion.y_free_id ; 3*DynareModel.endo_nbr+ModelInversion.x_free_id]; -% Get the name of the dynamic model routines. -model_dynamic = str2func([DynareModel.fname,'.dynamic']); -model_stransf = str2func('static_model_for_inversion'); +% Get function handles to the dynamic model routines. +dynamic_resid = str2func([DynareModel.fname '.sparse.dynamic_resid']); +dynamic_g1 = str2func([DynareModel.fname '.sparse.dynamic_g1']); % Initialization of the returned simulations (endogenous variables). Y = NaN(DynareModel.endo_nbr, nobs(constraints)); @@ -103,8 +93,9 @@ for t = 1:nobs(constraints) % values) and the free exogenous variables (initialized with 0). z = [Y(freeendogenousvariables_id,ity); zeros(nxfree, 1)]; % Solves for z. - [z, errorflag, ~, ~, errorcode] = dynare_solve(model_stransf, z, DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... - DynareOptions, model_dynamic, ycur, X(itx, :), DynareModel.params, ModelInversion); + [z, errorflag, ~, ~, errorcode] = dynare_solve(@static_model_for_inversion, z, DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... + DynareOptions, dynamic_resid, dynamic_g1, ycur, X(itx, :), DynareModel.params, DynareOutput.steady_state, DynareModel.dynamic_g1_sparse_rowval, DynareModel.dynamic_g1_sparse_colval, DynareModel.dynamic_g1_sparse_colptr, ModelInversion); + if errorflag error('Enable to solve the system of equations (with error code %i).', errorcode) end @@ -120,4 +111,28 @@ for t = 1:nobs(constraints) end endogenousvariables = dseries(Y', constraints.dates(1), endo_names); -exogenousvariables = dseries(X(find(exogenousvariables.dates==constraints.dates(1))+(0:(nobs(constraints)-1)),:), constraints.dates(1), exo_names); \ No newline at end of file +exogenousvariables = dseries(X(find(exogenousvariables.dates==constraints.dates(1))+(0:(nobs(constraints)-1)),:), constraints.dates(1), exo_names); + + +function [r, J] = static_model_for_inversion(z, dynamic_resid, dynamic_g1, ycur, x, params, steady_state, sparse_rowval, sparse_colval, sparse_colptr, ModelInversion) + +endo_nbr = ModelInversion.nyfree+ModelInversion.nyctrl; + +% Set up y +y = NaN(3*endo_nbr, 1); + +y(endo_nbr+ModelInversion.y_constrained_id) = ycur; +if ModelInversion.nyfree + y(endo_nbr+ModelInversion.y_free_id) = z(1:ModelInversion.nyfree); +end + +% Update x +x(ModelInversion.x_free_id) = z(ModelInversion.nyfree+(1:ModelInversion.nxfree)); + +[r, T_order, T] = dynamic_resid(y, x, params, steady_state); + +if nargout>1 + Jacobian = dynamic_g1(y, x, params, steady_state, sparse_rowval, ... + sparse_colval, sparse_colptr, T_order, T); + J = Jacobian(:, ModelInversion.J_id); +end diff --git a/matlab/steady.m b/matlab/steady.m index f40b742caccd404b38335a48eb5748e847df56f8..0c83bf8a0c54aa91f80bfad33579e920184321b1 100644 --- a/matlab/steady.m +++ b/matlab/steady.m @@ -77,7 +77,7 @@ if info(1) end end -[oo_.steady_state,M_.params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck); +[oo_.steady_state,M_.params,info] = evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,~options_.steadystate.nocheck); if info(1) == 0 if ~options_.noprint @@ -86,7 +86,7 @@ if info(1) == 0 else if ~options_.noprint if ~isempty(oo_.steady_state) - resid; + display_static_residuals; else skipline() disp('Residuals of the static equations cannot be computed because the steady state routine returned an empty vector.') @@ -170,7 +170,7 @@ for i=1:step_nbr+1 oo.exo_steady_state(values(ix,2)) = points(ix,i); oo.exo_det_steady_state(values(ixd,2)) = points(ixd,i); - [steady_state,M.params,info] = evaluate_steady_state(oo.steady_state,M,options,oo,~options.steadystate.nocheck); + [steady_state,M.params,info] = evaluate_steady_state(oo.steady_state,[oo.exo_steady_state; oo.exo_det_steady_state],M,options,~options.steadystate.nocheck); if info(1) == 0 % if homotopy step is not successful, current values of steady % state are not modified @@ -261,7 +261,7 @@ for i = 1:nv disp([ 'HOMOTOPY mode 2: lauching solver with ' varname ' = ' num2str(v) ' ...']) - oo_.steady_state = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck); + oo_.steady_state = evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,~options_.steadystate.nocheck); end end @@ -344,7 +344,7 @@ while iter <= step_nbr old_ss = oo.steady_state; - [steady_state,params,info] = evaluate_steady_state(old_ss,M,options,oo,~options.steadystate.nocheck); + [steady_state,params,info] = evaluate_steady_state(old_ss,[oo.exo_steady_state; oo.exo_det_steady_state],M,options,~options.steadystate.nocheck); if info(1) == 0 oo.steady_state = steady_state; M.params = params; diff --git a/matlab/stochastic_solvers.m b/matlab/stochastic_solvers.m index 024d807cd5d99566dc6426fb4c25a7509738e1ba..b30da096ccb5f3e3e0b8177e12fd211b965eae90 100644 --- a/matlab/stochastic_solvers.m +++ b/matlab/stochastic_solvers.m @@ -24,7 +24,7 @@ function [dr, info] = stochastic_solvers(dr, task, M_, options_, oo_) % info=6 -> The jacobian matrix evaluated at the steady state is complex. % info=9 -> k_order_pert was unable to compute the solution -% Copyright © 1996-2021 Dynare Team +% Copyright © 1996-2023 Dynare Team % % This file is part of Dynare. % @@ -115,9 +115,7 @@ if local_order == 1 end elseif local_order == 2 if (options_.bytecode) - [~, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ... - M_.params, dr.ys, 1); - jacobia_ = [loc_dr.g1 loc_dr.g1_x]; + error('Option "bytecode" is incompatible with order = 2') else [~,jacobia_,hessian1] = feval([M_.fname '.dynamic'],z(iyr0),... exo_simul, ... diff --git a/matlab/sylvester3.m b/matlab/sylvester3.m index b290b6220c1446639d1ad18b89b419c686ba7272..88e7af73264cf8b7dcc7a73c8c7560f41811e672 100644 --- a/matlab/sylvester3.m +++ b/matlab/sylvester3.m @@ -1,7 +1,7 @@ function x=sylvester3(a,b,c,d) % solves a*x+b*x*c=d where d is [n x m x p] -% Copyright © 2005-2017 Dynare Team +% Copyright © 2005-2023 Dynare Team % % This file is part of Dynare. % @@ -35,13 +35,13 @@ if m == 1 return end [u,t]=schur(c); -if isoctave +if isoctave && octave_ver_less_than('9') [aa,bb,qq,zz]=qz(full(a),full(b)); for j=1:p d(:,:,j)=qq*d(:,:,j)*u; end else - [aa,bb,qq,zz]=qz(full(a),full(b),'real'); % available in Matlab version 6.0 + [aa,bb,qq,zz]=qz(full(a),full(b),'real'); for j=1:p d(:,:,j)=qq*d(:,:,j)*u; end diff --git a/matlab/warning_config.m b/matlab/warning_config.m index 8f403fbef4e7504977122d6e2d091dbe720c7f3f..a195a773de607e26f11cf9bd048ed05aa376e41d 100644 --- a/matlab/warning_config.m +++ b/matlab/warning_config.m @@ -10,7 +10,7 @@ function warning_config() % SPECIAL REQUIREMENTS % none -% Copyright © 2008-2022 Dynare Team +% Copyright © 2008-2023 Dynare Team % % This file is part of Dynare. % @@ -49,6 +49,7 @@ if isoctave warning('off', 'Octave:fortran-indexing'); warning('off', 'Octave:classdef-to-struct'); warning('off', 'Octave:legacy-function'); % For strmatch and isdir + warning('off', 'Octave:qz:complex-default'); % Will likely be remove in Octave 11 % The following is necessary because of matlab/pac-tools/+pac/+bgp/{get,set}.m % which triggers this bug: https://savannah.gnu.org/bugs/?46849 diff --git a/mex/build/gensylv.am b/mex/build/gensylv.am index b664759aa953422e0a58a06bbd2b0310e9506b12..9ac05d7d1978f1909e80e4dc46a473a43592fcc0 100644 --- a/mex/build/gensylv.am +++ b/mex/build/gensylv.am @@ -1,8 +1,10 @@ mex_PROGRAMS = gensylv -gensylv_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/utils/cc +LIBKORDER_DIR = $(top_srcdir)/../../sources/libkorder -gensylv_LDADD = ../libdynare++/libdynare++.a +gensylv_CPPFLAGS = $(AM_CPPFLAGS) -I$(LIBKORDER_DIR)/sylv -I$(LIBKORDER_DIR)/utils + +gensylv_LDADD = ../libkorder/libkorder.a nodist_gensylv_SOURCES = gensylv.cc diff --git a/mex/build/k_order_perturbation.am b/mex/build/k_order_perturbation.am index 5da9f5c79148118b4f0f610997aa74040a0de0fc..7102bc77e0e4add348366b9fa570a4b1c318c8c1 100644 --- a/mex/build/k_order_perturbation.am +++ b/mex/build/k_order_perturbation.am @@ -1,11 +1,12 @@ mex_PROGRAMS = k_order_perturbation TOPDIR = $(top_srcdir)/../../sources/k_order_perturbation +LIBKORDER_DIR = $(top_srcdir)/../../sources/libkorder -k_order_perturbation_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/../../../dynare++/src -I$(top_srcdir)/../../../dynare++/kord -I$(top_srcdir)/../../../dynare++/tl/cc -I$(top_srcdir)/../../../dynare++/utils/cc -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/integ/cc -I$(TOPDIR) $(CPPFLAGS_MATIO) +k_order_perturbation_CPPFLAGS = $(AM_CPPFLAGS) -I$(LIBKORDER_DIR) -I$(LIBKORDER_DIR)/kord -I$(LIBKORDER_DIR)/tl -I$(LIBKORDER_DIR)/utils -I$(LIBKORDER_DIR)/sylv -I$(LIBKORDER_DIR)/integ -I$(TOPDIR) $(CPPFLAGS_MATIO) k_order_perturbation_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) -k_order_perturbation_LDADD = ../libdynare++/libdynare++.a ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) +k_order_perturbation_LDADD = ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) nodist_k_order_perturbation_SOURCES = k_order_perturbation.cc diff --git a/mex/build/k_order_welfare.am b/mex/build/k_order_welfare.am index f927020359d241fbd1cf9b9b864a3be273a13bf2..26f24226ab5ab633468df791e07fa3a0ee0edaf7 100644 --- a/mex/build/k_order_welfare.am +++ b/mex/build/k_order_welfare.am @@ -1,11 +1,12 @@ mex_PROGRAMS = k_order_welfare TOPDIR = $(top_srcdir)/../../sources/k_order_welfare +LIBKORDER_DIR = $(top_srcdir)/../../sources/libkorder -k_order_welfare_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(TOPDIR)/../k_order_perturbation -I$(top_srcdir)/../../../dynare++/tl/cc -I$(top_srcdir)/../../../dynare++/kord -I$(top_srcdir)/../../../dynare++/src -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/utils/cc $(CPPFLAGS_MATIO) +k_order_welfare_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(LIBKORDER_DIR) -I$(LIBKORDER_DIR)/tl -I$(LIBKORDER_DIR)/kord -I$(LIBKORDER_DIR)/sylv -I$(LIBKORDER_DIR)/utils $(CPPFLAGS_MATIO) k_order_welfare_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) -k_order_welfare_LDADD = ../libdynare++/libdynare++.a ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) +k_order_welfare_LDADD = ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) nodist_k_order_welfare_SOURCES = \ k_order_welfare.cc \ diff --git a/mex/build/libdynare++.am b/mex/build/libdynare++.am deleted file mode 100644 index bb062275bedf0fa57a92fae24228fcf808dbb98b..0000000000000000000000000000000000000000 --- a/mex/build/libdynare++.am +++ /dev/null @@ -1,101 +0,0 @@ -noinst_LIBRARIES = libdynare++.a - -TOPDIR = $(top_srcdir)/../../../dynare++ - -libdynare___a_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR)/src -I$(TOPDIR)/kord -I$(TOPDIR)/tl/cc -I$(TOPDIR)/utils/cc -I$(TOPDIR)/sylv/cc -I$(TOPDIR)/integ/cc $(CPPFLAGS_MATIO) - -# TODO: fix the codebase so that the following line is no longer needed -libdynare___a_CXXFLAGS = $(AM_CXXFLAGS) -Wno-unused-parameter - -KORD_SRCS = \ - approximation.cc \ - decision_rule.cc \ - dynamic_model.cc \ - faa_di_bruno.cc \ - first_order.cc \ - global_check.cc \ - korder.cc \ - korder_stoch.cc \ - journal.cc \ - normal_conjugate.cc \ - seed_generator.cc - -SYLV_SRCS = \ - BlockDiagonal.cc \ - GeneralMatrix.cc \ - GeneralSylvester.cc \ - IterativeSylvester.cc \ - KronUtils.cc \ - KronVector.cc \ - QuasiTriangular.cc \ - QuasiTriangularZero.cc \ - SchurDecomp.cc \ - SchurDecompEig.cc \ - SimilarityDecomp.cc \ - SylvException.cc \ - SylvMatrix.cc \ - SylvParams.cc \ - SymSchurDecomp.cc \ - TriangularSylvester.cc \ - Vector.cc - -TL_SRCS = \ - equivalence.cc \ - fine_container.cc \ - fs_tensor.cc \ - gs_tensor.cc \ - int_sequence.cc \ - kron_prod.cc \ - normal_moments.cc \ - permutation.cc \ - ps_tensor.cc \ - pyramid_prod.cc \ - pyramid_prod2.cc \ - rfs_tensor.cc \ - sparse_tensor.cc \ - stack_container.cc \ - symmetry.cc \ - t_container.cc \ - t_polynomial.cc \ - tensor.cc \ - tl_static.cc \ - twod_matrix.cc - -INTEG_SRCS = \ - quadrature.cc \ - quasi_mcarlo.cc \ - product.cc \ - smolyak.cc \ - vector_function.cc - -UTILS_SRCS = \ - pascal_triangle.cc \ - int_power.cc \ - sthread.cc - -OTHER_SRCS = \ - nlsolve.cc - -nodist_libdynare___a_SOURCES = \ - $(KORD_SRCS) \ - $(TL_SRCS) \ - $(SYLV_SRCS) \ - $(INTEG_SRCS) \ - $(UTILS_SRCS) \ - $(OTHER_SRCS) - -BUILT_SOURCES = $(nodist_libdynare___a_SOURCES) -CLEANFILES = $(nodist_libdynare___a_SOURCES) - -$(KORD_SRCS): %.cc: $(TOPDIR)/kord/%.cc - $(LN_S) -f $< $@ -$(TL_SRCS): %.cc: $(TOPDIR)/tl/cc/%.cc - $(LN_S) -f $< $@ -$(SYLV_SRCS): %.cc: $(TOPDIR)/sylv/cc/%.cc - $(LN_S) -f $< $@ -$(INTEG_SRCS): %.cc: $(TOPDIR)/integ/cc/%.cc - $(LN_S) -f $< $@ -$(UTILS_SRCS): %.cc: $(TOPDIR)/utils/cc/%.cc - $(LN_S) -f $< $@ -$(OTHER_SRCS): %.cc: $(TOPDIR)/src/%.cc - $(LN_S) -f $< $@ diff --git a/mex/build/libkorder.am b/mex/build/libkorder.am index 093b68819c52d4c69108a06287b27f776183fefa..6c7d573fc78b550b529662f41a96edd26857cc3d 100644 --- a/mex/build/libkorder.am +++ b/mex/build/libkorder.am @@ -1,16 +1,90 @@ noinst_LIBRARIES = libkorder.a -TOPDIR = $(top_srcdir)/../../sources/k_order_perturbation +TOPDIR = $(top_srcdir)/../../sources/libkorder -libkorder_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(top_srcdir)/../../../dynare++/tl/cc -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/src -I$(top_srcdir)/../../../dynare++/kord -I$(top_srcdir)/../../../dynare++/utils/cc $(CPPFLAGS_MATIO) +libkorder_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(TOPDIR)/tl -I$(TOPDIR)/sylv -I$(TOPDIR)/kord -I$(TOPDIR)/utils $(CPPFLAGS_MATIO) -nodist_libkorder_a_SOURCES = \ +# TODO: fix the codebase so that the following line is no longer needed +libkorder_a_CXXFLAGS = $(AM_CXXFLAGS) -Wno-unused-parameter + +KORD_SRCS = \ + approximation.cc \ + decision_rule.cc \ + dynamic_model.cc \ + faa_di_bruno.cc \ + first_order.cc \ + korder.cc \ + korder_stoch.cc \ + journal.cc + +SYLV_SRCS = \ + BlockDiagonal.cc \ + GeneralMatrix.cc \ + GeneralSylvester.cc \ + IterativeSylvester.cc \ + KronUtils.cc \ + KronVector.cc \ + QuasiTriangular.cc \ + QuasiTriangularZero.cc \ + SchurDecomp.cc \ + SchurDecompEig.cc \ + SimilarityDecomp.cc \ + SylvException.cc \ + SylvMatrix.cc \ + SylvParams.cc \ + SymSchurDecomp.cc \ + TriangularSylvester.cc \ + Vector.cc + +TL_SRCS = \ + equivalence.cc \ + fine_container.cc \ + fs_tensor.cc \ + gs_tensor.cc \ + int_sequence.cc \ + kron_prod.cc \ + normal_moments.cc \ + permutation.cc \ + ps_tensor.cc \ + pyramid_prod.cc \ + pyramid_prod2.cc \ + rfs_tensor.cc \ + sparse_tensor.cc \ + stack_container.cc \ + symmetry.cc \ + t_container.cc \ + t_polynomial.cc \ + tensor.cc \ + tl_static.cc \ + twod_matrix.cc + +UTILS_SRCS = \ + pascal_triangle.cc \ + int_power.cc \ + sthread.cc + +TOPDIR_SRCS = \ k_ord_dynare.cc \ dynamic_dll.cc \ dynamic_m.cc +nodist_libkorder_a_SOURCES = \ + $(KORD_SRCS) \ + $(TL_SRCS) \ + $(SYLV_SRCS) \ + $(UTILS_SRCS) \ + $(TOPDIR_SRCS) + BUILT_SOURCES = $(nodist_libkorder_a_SOURCES) CLEANFILES = $(nodist_libkorder_a_SOURCES) -%.cc: $(TOPDIR)/%.cc +$(TOPDIR_SRCS): %.cc: $(TOPDIR)/%.cc + $(LN_S) -f $< $@ +$(KORD_SRCS): %.cc: $(TOPDIR)/kord/%.cc + $(LN_S) -f $< $@ +$(TL_SRCS): %.cc: $(TOPDIR)/tl/%.cc + $(LN_S) -f $< $@ +$(SYLV_SRCS): %.cc: $(TOPDIR)/sylv/%.cc + $(LN_S) -f $< $@ +$(UTILS_SRCS): %.cc: $(TOPDIR)/utils/%.cc $(LN_S) -f $< $@ diff --git a/mex/build/matlab/Makefile.am b/mex/build/matlab/Makefile.am index 54a7dc1f6d965c7ca1943dc1b0dee125d190a099..78134214b5f0e0419c952812e03b667b6b5f81b3 100644 --- a/mex/build/matlab/Makefile.am +++ b/mex/build/matlab/Makefile.am @@ -1,11 +1,6 @@ ACLOCAL_AMFLAGS = -I ../../../m4 -SUBDIRS = mjdgges kronecker bytecode sobol perfect_foresight_problem num_procs block_trust_region disclyap_fast libkordersim local_state_space_iterations folded_to_unfolded_dr k_order_simul k_order_mean cycle_reduction logarithmic_reduction riccati_update - -# libdynare++ must come before gensylv and k_order_perturbation -if ENABLE_MEX_DYNAREPLUSPLUS -SUBDIRS += libdynare++ gensylv libkorder k_order_perturbation k_order_welfare -endif +SUBDIRS = mjdgges kronecker bytecode sobol perfect_foresight_problem num_procs block_trust_region disclyap_fast libkordersim local_state_space_iterations folded_to_unfolded_dr k_order_simul k_order_mean cycle_reduction logarithmic_reduction riccati_update libkorder gensylv k_order_perturbation k_order_welfare if ENABLE_MEX_MS_SBVAR SUBDIRS += ms_sbvar diff --git a/mex/build/matlab/configure.ac b/mex/build/matlab/configure.ac index 67fa9913e854d79722c89b6e4a34cc1e30a6544c..54cf3c717c4065e09eecff060a624f90b19de014 100644 --- a/mex/build/matlab/configure.ac +++ b/mex/build/matlab/configure.ac @@ -64,9 +64,6 @@ AC_SUBST([LIBADD_DLOPEN]) AC_ARG_ENABLE([mex-ms-sbvar], AS_HELP_STRING([--disable-mex-ms-sbvar], [disable compilation of the MS-SBVAR MEX]), [], [enable_mex_ms_sbvar=yes]) AM_CONDITIONAL([ENABLE_MEX_MS_SBVAR], [test "$enable_mex_ms_sbvar" = yes]) -AC_ARG_ENABLE([mex-dynare++], AS_HELP_STRING([--disable-mex-dynare++], [disable compilation of MEX based on Dynare++]), [], [enable_mex_dynareplusplus=yes]) -AM_CONDITIONAL([ENABLE_MEX_DYNAREPLUSPLUS], [test "$enable_mex_dynareplusplus" = yes]) - AC_ARG_ENABLE([mex-kalman-steady-state], AS_HELP_STRING([--disable-mex-kalman-steady-state], [disable compilation of the kalman_steady_state MEX]), [], [enable_mex_kalman_steady_state=yes]) AM_CONDITIONAL([ENABLE_MEX_KALMAN_STEADY_STATE], [test "$enable_mex_kalman_steady_state" = yes]) @@ -76,12 +73,6 @@ if test "$enable_mex_ms_sbvar" = yes; then test "$has_gsl" != yes && AC_MSG_ERROR([GSL cannot be found. If you want to skip the compilation of the MS-SBVAR MEX, pass the --disable-mex-ms-sbvar flag.]) fi -# Check for libmatio, needed by MEX files using Dynare++ code -if test "$enable_mex_dynareplusplus" = yes; then - AX_MATIO - test "$has_matio" != yes && AC_MSG_ERROR([libmatio cannot be found. If you want to skip the compilation of MEX files based Dynare++, pass the --disable-mex-dynare++ flag.]) -fi - # Check for libslicot, needed by kalman_steady_state if test "$enable_mex_kalman_steady_state" = yes; then # FCFLAGS must be temporarily modified, because otherwise -fno-underscoring is not @@ -98,7 +89,6 @@ fi case ${host_os} in *mingw32*) GSL_LIBS="-Wl,-Bstatic $GSL_LIBS -Wl,-Bdynamic" - LIBADD_MATIO="-Wl,-Bstatic $LIBADD_MATIO -Wl,-Bdynamic" LIBADD_SLICOT="-Wl,-Bstatic $LIBADD_SLICOT -Wl,-Bdynamic" ;; esac @@ -115,12 +105,6 @@ AC_SUBST([M2HTML]) AM_CONDITIONAL([HAVE_M2HTML], [test "x$M2HTML" != "x"]) # Construct final output message -if test "$enable_mex_dynareplusplus" = yes; then - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_MATLAB="yes" -else - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_MATLAB="no" -fi - if test "$enable_mex_kalman_steady_state" = yes; then BUILD_KALMAN_STEADY_STATE_MATLAB="yes" else @@ -139,7 +123,6 @@ Dynare is now configured for building the following components... Binaries (with "make"): MEX files for MATLAB (except those listed below): yes - Gensylv, k-order and dynare_simul MEX files for MATLAB: $BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_MATLAB MS-SBVAR MEX files for MATLAB: $BUILD_MS_SBVAR_MEX_MATLAB Kalman Steady State MEX file for MATLAB: $BUILD_KALMAN_STEADY_STATE_MATLAB M2HTML documentation: $BUILD_M2HTML @@ -150,7 +133,6 @@ AC_CONFIG_FILES([Makefile mjdgges/Makefile kronecker/Makefile bytecode/Makefile - libdynare++/Makefile gensylv/Makefile libkorder/Makefile k_order_perturbation/Makefile diff --git a/mex/build/matlab/libdynare++/Makefile.am b/mex/build/matlab/libdynare++/Makefile.am deleted file mode 100644 index c1283b13cdd77e87a6a1704503b546e05a267a65..0000000000000000000000000000000000000000 --- a/mex/build/matlab/libdynare++/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -include ../mex.am -include ../../libdynare++.am diff --git a/mex/build/matlab/mex.am b/mex/build/matlab/mex.am index 237762aec675d990aac679c148a3f4f96f28ebde..03bef38efa80b7ece8f749e44d825b74982f56fd 100644 --- a/mex/build/matlab/mex.am +++ b/mex/build/matlab/mex.am @@ -9,7 +9,7 @@ DEFS += -DMEXEXT=\"$(MEXEXT)\" AM_CFLAGS = $(MATLAB_CFLAGS) -Wall -Wno-parentheses # TODO: use same warnings as C++ AM_FCFLAGS = $(MATLAB_FCFLAGS) -Wall -Wimplicit-interface -AM_CXXFLAGS = -std=gnu++20 $(MATLAB_CXXFLAGS) -Wall -Wno-dangling-else -Wextra -Wold-style-cast +AM_CXXFLAGS = -std=gnu++20 $(MATLAB_CXXFLAGS) -Wall -Wextra -Wold-style-cast AM_LDFLAGS = $(MATLAB_LDFLAGS) LIBS += $(MATLAB_LIBS) diff --git a/mex/build/octave/Makefile.am b/mex/build/octave/Makefile.am index c89c9de0bf84933a506e9072fd98c15b6116e0bc..8e93bdd0a8de40ae693159b6f369bbe47c1e6139 100644 --- a/mex/build/octave/Makefile.am +++ b/mex/build/octave/Makefile.am @@ -1,11 +1,6 @@ ACLOCAL_AMFLAGS = -I ../../../m4 -SUBDIRS = mjdgges kronecker bytecode sobol perfect_foresight_problem num_procs block_trust_region disclyap_fast libkordersim local_state_space_iterations folded_to_unfolded_dr k_order_simul k_order_mean cycle_reduction logarithmic_reduction riccati_update - -# libdynare++ must come before gensylv and k_order_perturbation -if ENABLE_MEX_DYNAREPLUSPLUS -SUBDIRS += libdynare++ gensylv libkorder k_order_perturbation k_order_welfare -endif +SUBDIRS = mjdgges kronecker bytecode sobol perfect_foresight_problem num_procs block_trust_region disclyap_fast libkordersim local_state_space_iterations folded_to_unfolded_dr k_order_simul k_order_mean cycle_reduction logarithmic_reduction riccati_update libkorder gensylv k_order_perturbation k_order_welfare if ENABLE_MEX_MS_SBVAR SUBDIRS += ms_sbvar diff --git a/mex/build/octave/configure.ac b/mex/build/octave/configure.ac index 10a582e0842c3ba1aa67ecdebfc01cb5c2f05d17..56cbbaf4dfd437c15396c963ad952c6b673d0af2 100644 --- a/mex/build/octave/configure.ac +++ b/mex/build/octave/configure.ac @@ -32,12 +32,16 @@ CC=$($MKOCTFILE -p CC) CXX=$($MKOCTFILE -p CXX) AR=$($MKOCTFILE -p AR) RANLIB=$($MKOCTFILE -p RANLIB) +CPPFLAGS="$($MKOCTFILE -p CPPFLAGS) $($MKOCTFILE -p INCFLAGS)" CFLAGS=$($MKOCTFILE -p CFLAGS) CXXFLAGS=$($MKOCTFILE -p CXXFLAGS) # The --link-stand-alone is needed since Octave 7 to avoid inserting -shared, which # is undesirable for generic LDFLAGS. LDFLAGS=$($MKOCTFILE --link-stand-alone -p LDFLAGS) +FORTRAN_LIBS_FOR_CXXLINK="-lgfortran -lquadmath" +AC_SUBST([FORTRAN_LIBS_FOR_CXXLINK]) + AC_CANONICAL_HOST OCTAVE_VERSION=$($MKOCTFILE -v 2>&1 | sed 's/mkoctfile, version //') @@ -62,9 +66,6 @@ AC_SUBST([LIBADD_DLOPEN]) AC_ARG_ENABLE([mex-ms-sbvar], AS_HELP_STRING([--disable-mex-ms-sbvar], [disable compilation of the MS-SBVAR MEX]), [], [enable_mex_ms_sbvar=yes]) AM_CONDITIONAL([ENABLE_MEX_MS_SBVAR], [test "$enable_mex_ms_sbvar" = yes]) -AC_ARG_ENABLE([mex-dynare++], AS_HELP_STRING([--disable-mex-dynare++], [disable compilation of MEX based on Dynare++]), [], [enable_mex_dynareplusplus=yes]) -AM_CONDITIONAL([ENABLE_MEX_DYNAREPLUSPLUS], [test "$enable_mex_dynareplusplus" = yes]) - AC_ARG_ENABLE([mex-kalman-steady-state], AS_HELP_STRING([--disable-mex-kalman-steady-state], [disable compilation of the kalman_steady_state MEX]), [], [enable_mex_kalman_steady_state=yes]) AM_CONDITIONAL([ENABLE_MEX_KALMAN_STEADY_STATE], [test "$enable_mex_kalman_steady_state" = yes]) @@ -74,10 +75,10 @@ if test "$enable_mex_ms_sbvar" = yes; then test "$has_gsl" != yes && AC_MSG_ERROR([GSL cannot be found. If you want to skip the compilation of the MS-SBVAR MEX, pass the --disable-mex-ms-sbvar flag.]) fi -# Check for libmatio, needed by MEX files using Dynare++ code, and by ms-sbvar (the latter only under Octave, as an alternative to MATLAB's libmat) -if test "$enable_mex_dynareplusplus" = yes -o "$enable_mex_ms_sbvar" = yes; then +# Check for libmatio, needed by ms-sbvar (the latter only under Octave, as an alternative to MATLAB's libmat) +if test "$enable_mex_ms_sbvar" = yes; then AX_MATIO - test "$has_matio" != yes && AC_MSG_ERROR([libmatio cannot be found. If you want to skip the compilation of MS-SBVAR MEX and MEX files based Dynare++, pass the --disable-mex-dynare++ and --disable-mex-ms-sbvar flags.]) + test "$has_matio" != yes && AC_MSG_ERROR([libmatio cannot be found. If you want to skip the compilation of MS-SBVAR, pass the --disable-mex-ms-sbvar flags.]) fi # Check for libslicot, needed by kalman_steady_state @@ -87,6 +88,10 @@ if test "$enable_mex_kalman_steady_state" = yes; then fi # Check for UMFPACK, needed by bytecode +AC_CHECK_HEADERS([suitesparse/umfpack.h umfpack.h], [have_umfpack_h=yes]) +if test "$have_umfpack_h" != yes; then + AC_MSG_ERROR([Can't find umfpack.h]) +fi AC_CHECK_LIB([umfpack], [umfpack_dl_defaults], [LIBADD_UMFPACK="-lumfpack"], [AC_MSG_ERROR([Can't find UMFPACK])]) AC_SUBST([LIBADD_UMFPACK]) @@ -119,12 +124,6 @@ esac AM_CONDITIONAL([LINK_OCTAVE_LIBS], [test ${link_octave_libs} = yes]) # Construct final output message -if test "$enable_mex_dynareplusplus" = yes; then - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_OCTAVE="yes" -else - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_OCTAVE="no" -fi - if test "$enable_mex_kalman_steady_state" = yes; then BUILD_KALMAN_STEADY_STATE_OCTAVE="yes" else @@ -143,7 +142,6 @@ Dynare is now configured for building the following components... Binaries (with "make"): MEX files for Octave (except those listed below): yes - Gensylv, k-order and dynare_simul MEX for Octave: $BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_OCTAVE MS-SBVAR MEX files for Octave: $BUILD_MS_SBVAR_MEX_OCTAVE Kalman Steady State MEX file for Octave: $BUILD_KALMAN_STEADY_STATE_OCTAVE @@ -153,7 +151,6 @@ AC_CONFIG_FILES([Makefile mjdgges/Makefile kronecker/Makefile bytecode/Makefile - libdynare++/Makefile gensylv/Makefile libkorder/Makefile k_order_perturbation/Makefile diff --git a/mex/build/octave/libdynare++/Makefile.am b/mex/build/octave/libdynare++/Makefile.am deleted file mode 100644 index 6ab9e430a68704c91d3beabb29f78f14f67371b7..0000000000000000000000000000000000000000 --- a/mex/build/octave/libdynare++/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -EXEEXT = .mex -include ../mex.am -include ../../libdynare++.am diff --git a/mex/build/octave/mex.am b/mex/build/octave/mex.am index 7bd3e2c53728439ad958cc0632f4f93c6aa4fde2..0e77872e7836ba1a445afdd18c9d0f0d3daef90f 100644 --- a/mex/build/octave/mex.am +++ b/mex/build/octave/mex.am @@ -1,13 +1,11 @@ -AM_CPPFLAGS = $(shell $(MKOCTFILE) -p CPPFLAGS) -AM_CPPFLAGS += $(shell $(MKOCTFILE) -p INCFLAGS) -AM_CPPFLAGS += -I$(top_srcdir)/../../sources +AM_CPPFLAGS = -I$(top_srcdir)/../../sources DEFS += -DOCTAVE_MEX_FILE DEFS += -DMEXEXT=\".mex\" AM_CFLAGS = $(shell $(MKOCTFILE) -p CPICFLAG) -Wall -Wno-parentheses # TODO: use same warnings as C++ AM_FCFLAGS = $(shell $(MKOCTFILE) -p FPICFLAG) -Wall -Wimplicit-interface -AM_CXXFLAGS = -std=gnu++20 $(shell $(MKOCTFILE) -p CXXPICFLAG) -Wall -Wno-dangling-else -Wextra -Wold-style-cast +AM_CXXFLAGS = -std=gnu++20 $(shell $(MKOCTFILE) -p CXXPICFLAG) -Wall -Wextra -Wold-style-cast AM_LDFLAGS = $(shell $(MKOCTFILE) -p DL_LDFLAGS) # See the comments in configure.ac diff --git a/mex/build/qmc_sequence.am b/mex/build/qmc_sequence.am index 2cb09b2bfe9379a78650bf2d6f5a242fd1ad1814..2e9355b2e110eea565958e51acea7eef2d6cdeca 100644 --- a/mex/build/qmc_sequence.am +++ b/mex/build/qmc_sequence.am @@ -4,12 +4,15 @@ TOPDIR = $(top_srcdir)/../../sources/sobol qmc_sequence_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) qmc_sequence_CXXFLAGS = $(AM_CXXFLAGS) -fopenmp -qmc_sequence_LDADD = $(OPENMP_LIBS) +qmc_sequence_LDADD = $(OPENMP_LIBS) $(FORTRAN_LIBS_FOR_CXXLINK) -nodist_qmc_sequence_SOURCES = qmc_sequence.cc +nodist_qmc_sequence_SOURCES = qmc_sequence.cc sobol.f08 BUILT_SOURCES = $(nodist_qmc_sequence_SOURCES) CLEANFILES = $(nodist_qmc_sequence_SOURCES) %.cc: $(TOPDIR)/%.cc $(LN_S) -f $< $@ + +%.f08: $(TOPDIR)/%.f08 + $(LN_S) -f $< $@ diff --git a/mex/sources/blas_lapack.F08 b/mex/sources/blas_lapack.F08 index 6b981f3e2cb8bb8a2db6841aabe63fb88d1219a8..3d683d4c15658427b84868da9e26e74d1210b856 100644 --- a/mex/sources/blas_lapack.F08 +++ b/mex/sources/blas_lapack.F08 @@ -1,4 +1,4 @@ -! Copyright © 2019-2021 Dynare Team +! Copyright © 2019-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -17,7 +17,7 @@ module blas use iso_fortran_env - implicit none + implicit none (type, external) #if defined(MATLAB_MEX_FILE) && __SIZEOF_POINTER__ == 8 integer, parameter :: blint = int64 @@ -30,17 +30,17 @@ module blas interface subroutine dgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc) import :: blint, real64 + implicit none character, intent(in) :: transa, transb integer(blint), intent(in) :: m, n, k, lda, ldb, ldc real(real64), dimension(*), intent(in) :: a, b real(real64), intent(in) :: alpha, beta real(real64), dimension(*), intent(inout) :: c end subroutine dgemm - end interface - interface subroutine dgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy) import :: blint, real64 + implicit none character, intent(in) :: trans integer(blint), intent(in) :: m, n, lda, incx, incy real(real64), dimension(*), intent(in) :: a, x @@ -103,23 +103,23 @@ end module blas module lapack use blas - implicit none + implicit none (type, external) interface subroutine dgesv(n, nrhs, a, lda, ipiv, b, ldb, info) import :: blint, real64 + implicit none integer(blint), intent(in) :: n, nrhs, lda, ldb real(real64), dimension(*), intent(inout) :: a, b integer(blint), dimension(*), intent(out) :: ipiv integer(blint), intent(out) :: info end subroutine dgesv - end interface - interface subroutine dgges(jobvsl, jobvsr, sort, selctg, n, a, lda, b, ldb, sdim, & alphar, alphai, beta, vsl, ldvsl, vsr, ldvsr, work, lwork, bwork, & info) import :: blint, bllog, real64 + implicit none character, intent(in) :: jobvsl, jobvsr, sort interface logical(bllog) function selctg(alphar, alphai, beta) @@ -133,21 +133,19 @@ module lapack logical(bllog), dimension(*), intent(out) :: bwork integer(blint), intent(out) :: sdim, info end subroutine dgges - end interface - interface subroutine dpotrf(uplo, n, a, lda, info) import :: blint, real64 + implicit none character, intent(in) :: uplo integer(blint), intent(in) :: n, lda real(real64), dimension(*), intent(inout) :: a integer(blint), intent(out) :: info end subroutine dpotrf - end interface - interface function dlange(norm, m, n, a, lda, work) import :: blint, real64 + implicit none character, intent(in) :: norm integer(blint), intent(in) :: m, n, lda real(real64), dimension(*), intent(in) :: a diff --git a/mex/sources/block_trust_region/dulmage_mendelsohn.f08 b/mex/sources/block_trust_region/dulmage_mendelsohn.f08 index aa49c472807790569a18f464135035f17462aa38..68260d757ee29aae466f6f3d2d764dd86b32a3dc 100644 --- a/mex/sources/block_trust_region/dulmage_mendelsohn.f08 +++ b/mex/sources/block_trust_region/dulmage_mendelsohn.f08 @@ -1,7 +1,7 @@ ! Wrapper around MATLAB’s dmperm to compute the Dulmage-Mendelsohn ! decomposition -! Copyright © 2020 Dynare Team +! Copyright © 2020-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -21,7 +21,7 @@ module dulmage_mendelsohn use iso_fortran_env use matlab_mex - implicit none + implicit none (type, external) ! Represents a block in the fine DM decomposition type :: dm_block diff --git a/mex/sources/block_trust_region/matlab_fcn_closure.F08 b/mex/sources/block_trust_region/matlab_fcn_closure.F08 index e066cf1b616b184c35a52ca2a57e118a522dea34..dfdf609e74bfb46d351830f0ccd67b7aa1dc921b 100644 --- a/mex/sources/block_trust_region/matlab_fcn_closure.F08 +++ b/mex/sources/block_trust_region/matlab_fcn_closure.F08 @@ -34,7 +34,7 @@ module matlab_fcn_closure use iso_c_binding use ieee_arithmetic use matlab_mex - implicit none + implicit none (type, external) private public :: func, extra_args, f_indices, x_indices, x_all, matlab_fcn diff --git a/mex/sources/block_trust_region/mexFunction.f08 b/mex/sources/block_trust_region/mexFunction.f08 index 11f9fccf209d330a87fc8c30fe9e9b725e6d6b76..6f1cbd107ec4bb943320f3f274ed352b6b7a7694 100644 --- a/mex/sources/block_trust_region/mexFunction.f08 +++ b/mex/sources/block_trust_region/mexFunction.f08 @@ -1,4 +1,4 @@ -! Copyright © 2019-2022 Dynare Team +! Copyright © 2019-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -22,7 +22,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use matlab_mex use matlab_fcn_closure use trust_region - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs diff --git a/mex/sources/block_trust_region/test/dulmage_mendelsohn_test.f08 b/mex/sources/block_trust_region/test/dulmage_mendelsohn_test.f08 index 43c7f428cb36c6e1ebb0fd2cd053454cf77e25b2..9ba1701a1a146464c657681aafcd07e702580da5 100644 --- a/mex/sources/block_trust_region/test/dulmage_mendelsohn_test.f08 +++ b/mex/sources/block_trust_region/test/dulmage_mendelsohn_test.f08 @@ -1,7 +1,7 @@ program dmperm_test use iso_fortran_env use dulmage_mendelsohn - implicit none + implicit none (type, external) real(real64), dimension(12, 11) :: M integer, dimension(size(M, 1)) :: row_order diff --git a/mex/sources/block_trust_region/test/trust_region_test.f08 b/mex/sources/block_trust_region/test/trust_region_test.f08 index 8ec263b05df5ec204ff39c4427c1711f09d51086..cc3a3136939690a4c6d3860ffb2dd0296d25195e 100644 --- a/mex/sources/block_trust_region/test/trust_region_test.f08 +++ b/mex/sources/block_trust_region/test/trust_region_test.f08 @@ -1,7 +1,7 @@ program trust_region_test use trust_region use iso_fortran_env - implicit none + implicit none (type, external) real(real64), dimension(2), parameter :: rosenbrock_guess = [ -10**4, 1 ] real(real64), dimension(2), parameter :: rosenbrock_solution = [ 1, 1 ] diff --git a/mex/sources/block_trust_region/trust_region.f08 b/mex/sources/block_trust_region/trust_region.f08 index 635eecad68a1aefe6cb9d0df743931f98edbf971..25744dd5197dba16781efa6743134d8a4d7c5705 100644 --- a/mex/sources/block_trust_region/trust_region.f08 +++ b/mex/sources/block_trust_region/trust_region.f08 @@ -2,7 +2,7 @@ ! ! Implementation heavily inspired from the hybrj function from MINPACK -! Copyright © 2019-2021 Dynare Team +! Copyright © 2019-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -22,7 +22,7 @@ module trust_region use iso_fortran_env use lapack - implicit none + implicit none (type, external) private public :: trust_region_solve diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh index 0af66aee3453e2b0c3b5426802bd96fb4e6810c5..99f84729545878464955c7da956951154646ba87 100644 --- a/mex/sources/bytecode/ErrorHandling.hh +++ b/mex/sources/bytecode/ErrorHandling.hh @@ -33,57 +33,45 @@ struct GeneralException struct FloatingPointException : public GeneralException { - FloatingPointException(const string &details) : - GeneralException {"Floating point error: " + details} + const string location; + FloatingPointException(const string &details, string location_arg) : + GeneralException {"Floating point error: " + details}, + location {move(location_arg)} { } }; -struct LogException : public FloatingPointException +struct UnaryOpException : public FloatingPointException { - LogException(double value) : + UnaryOpException(const string &op, double value, string location_arg) : FloatingPointException { [=] { // We don’t use std::to_string(), because it uses fixed formatting ostringstream s; - s << "log(X) with X=" << defaultfloat << value; + s << op << "(X) with X=" << defaultfloat << value; return s.str(); - }() } - { - } -}; - -struct Log10Exception : public FloatingPointException -{ - Log10Exception(double value) : - FloatingPointException { [=] - { - // We don’t use std::to_string(), because it uses fixed formatting - ostringstream s; - s << "log10(X) with X=" << defaultfloat << value; - return s.str(); - }() } + }(), move(location_arg) } { } }; struct DivideException : public FloatingPointException { - DivideException(double divisor) : + DivideException(double v1, double v2, string location_arg) : FloatingPointException { [=] { // We don’t use std::to_string(), because it uses fixed formatting ostringstream s; - s << "a/X with X=" << defaultfloat << divisor; + s << "a/X with a=" << defaultfloat << v1 << " and X= " << v2; return s.str(); - }() } + }(), move(location_arg) } { } }; struct PowException : public FloatingPointException { - PowException(double base, double exponent) : + PowException(double base, double exponent, string location_arg) : FloatingPointException { [=] { // We don’t use std::to_string(), because it uses fixed formatting @@ -92,7 +80,7 @@ struct PowException : public FloatingPointException if (fabs(base) <= 1e-10) s << " and a=" << exponent; return s.str(); - }() } + }(), move(location_arg) } { } }; diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc index e4b324211b0efad49a706f69f027571f31cff0b5..8a7581622f44323eb62e907be74efd529290df2c 100644 --- a/mex/sources/bytecode/Evaluate.cc +++ b/mex/sources/bytecode/Evaluate.cc @@ -21,6 +21,8 @@ #include <cmath> #include <limits> #include <stack> +#include <cfenv> +#include <numbers> #include <dynmex.h> @@ -28,18 +30,9 @@ #include "CommonEnums.hh" #include "ErrorHandling.hh" -Evaluate::Evaluate(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool steady_state_arg, int periods_arg, BasicSymbolTable &symbol_table_arg) : - symbol_table {symbol_table_arg} -{ - y_size = y_size_arg; - y_kmin = y_kmin_arg; - y_kmax = y_kmax_arg; - periods = periods_arg; - steady_state = steady_state_arg; -} - -void -Evaluate::loadCodeFile(const filesystem::path &codfile) +Evaluate::Evaluate(const filesystem::path &codfile, bool steady_state_arg, const BasicSymbolTable &symbol_table_arg) : + symbol_table {symbol_table_arg}, + steady_state {steady_state_arg} { ifstream CompiledCode {codfile, ios::in | ios::binary | ios::ate}; if (!CompiledCode.is_open()) @@ -304,7 +297,7 @@ Evaluate::loadCodeFile(const filesystem::path &codfile) } string -Evaluate::error_location(it_code_type expr_begin, it_code_type faulty_op, bool steady_state, int it_) const +Evaluate::error_location(it_code_type expr_begin, it_code_type faulty_op, int it_) const { ostringstream Error_loc; switch (EQN_type) @@ -322,8 +315,8 @@ Evaluate::error_location(it_code_type expr_begin, it_code_type faulty_op, bool s break; } Error_loc << " " << EQN_equation+1; - if (EQN_block_number > 1) - Error_loc << " in block " << EQN_block+1; + if (nb_blocks > 1) + Error_loc << " in block " << block_num+1; switch (EQN_type) { case ExpressionType::TemporaryTerm: @@ -642,27 +635,27 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio case UnaryOpcode::sin: return "sin"; case UnaryOpcode::tan: - return "tan"; + return it_code == faulty_op ? "{tan}" : "tan"; case UnaryOpcode::acos: - return "acos"; + return it_code == faulty_op ? "{acos}" : "acos"; case UnaryOpcode::asin: - return "asin"; + return it_code == faulty_op ? "{asin}" : "asin"; case UnaryOpcode::atan: return "atan"; case UnaryOpcode::cosh: - return "cosh"; + return it_code == faulty_op ? "{cosh}" : "cosh"; case UnaryOpcode::sinh: - return "sinh"; + return it_code == faulty_op ? "{sinh}" : "sinh"; case UnaryOpcode::tanh: return "tanh"; case UnaryOpcode::acosh: - return "acosh"; + return it_code == faulty_op ? "{acosh}" : "acosh"; case UnaryOpcode::asinh: return "asinh"; case UnaryOpcode::atanh: - return "atanh"; + return it_code == faulty_op ? "{atanh}" : "atanh"; case UnaryOpcode::sqrt: - return "sqrt"; + return it_code == faulty_op ? "{sqrt}" : "sqrt"; case UnaryOpcode::cbrt: return "cbrt"; case UnaryOpcode::erf: @@ -987,64 +980,8 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio return { get<0>(Stack.top()), it_code }; } -double -Evaluate::pow1(double a, double b) -{ - double r = pow(a, b); - if (isnan(r) || isinf(r)) - { - res1 = std::numeric_limits<double>::quiet_NaN(); - r = 0.0000000000000000000000001; - if (print_error) - throw PowException{a, b}; - } - return r; -} - -double -Evaluate::divide(double a, double b) -{ - double r = a / b; - if (isnan(r) || isinf(r)) - { - res1 = std::numeric_limits<double>::quiet_NaN(); - r = 1e70; - if (print_error) - throw DivideException{b}; - } - return r; -} - -double -Evaluate::log1(double a) -{ - double r = log(a); - if (isnan(r) || isinf(r)) - { - res1 = std::numeric_limits<double>::quiet_NaN(); - r = -1e70; - if (print_error) - throw LogException{a}; - } - return r; -} - -double -Evaluate::log10_1(double a) -{ - double r = log(a); - if (isnan(r) || isinf(r)) - { - res1 = std::numeric_limits<double>::quiet_NaN(); - r = -1e70; - if (print_error) - throw Log10Exception{a}; - } - return r; -} - void -Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) +Evaluate::evaluateBlock(int it_, double *__restrict__ y, const double *__restrict__ ya, int y_size, double *__restrict__ x, int nb_row_x, double *__restrict__ params, const double *__restrict__ steady_y, double *__restrict__ u, int Per_u_, double *__restrict__ T, int T_nrows, map<int, double> &TEF, map<pair<int, int>, double> &TEFD, map<tuple<int, int, int>, double> &TEFDD, double *__restrict__ r, double *__restrict__ g1, double *__restrict__ jacob, double *__restrict__ jacob_exo, double *__restrict__ jacob_exo_det, bool evaluate, bool no_derivatives) { auto it_code { currentBlockBeginning() }; int var{0}, lag{0}; @@ -1059,24 +996,10 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) bool go_on = true; double ll; double rr; - double *jacob = nullptr, *jacob_exo = nullptr, *jacob_exo_det = nullptr; - EQN_block = block_num; stack<double> Stack; ExternalFunctionCallType call_type{ExternalFunctionCallType::levelWithoutDerivative}; it_code_type it_code_expr; -#ifdef DEBUG - mexPrintf("compute_block_time\n"); -#endif - if (evaluate) - { - jacob = mxGetPr(jacobian_block[block_num]); - if (!steady_state) - { - jacob_exo = mxGetPr(jacobian_exo_block[block_num]); - jacob_exo_det = mxGetPr(jacobian_det_exo_block[block_num]); - } - } #ifdef MATLAB_MEX_FILE if (utIsInterruptPending()) throw UserException{}; @@ -1276,10 +1199,10 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) //load a temporary variable in the processor var = static_cast<FLDT_ *>(*it_code)->get_pos(); #ifdef DEBUG - mexPrintf("FLDT T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%f\n", it_, var, y_kmin, y_kmax, var*(periods+y_kmin+y_kmax)+it_, T[var*(periods+y_kmin+y_kmax)+it_]); - tmp_out << " T[" << it_ << ", " << var << "](" << T[var*(periods+y_kmin+y_kmax)+it_] << ")"; + mexPrintf("FLDT T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%f\n", it_, var, y_kmin, y_kmax, var*T_nrows+it_, T[var*T_nrows+it_]); + tmp_out << " T[" << it_ << ", " << var << "](" << T[var*T_nrows+it_] << ")"; #endif - Stack.push(T[var*(periods+y_kmin+y_kmax)+it_]); + Stack.push(T[var*T_nrows+it_]); break; case Tags::FLDST: //load a temporary variable in the processor @@ -1424,10 +1347,10 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) mexPrintf("FSTPT\n"); #endif var = static_cast<FSTPT_ *>(*it_code)->get_pos(); - T[var*(periods+y_kmin+y_kmax)+it_] = Stack.top(); + T[var*T_nrows+it_] = Stack.top(); #ifdef DEBUG tmp_out << "=>"; - mexPrintf(" T[%d, %d](%f)=%s\n", it_, var, T[var*(periods+y_kmin+y_kmax)+it_], tmp_out.str().c_str()); + mexPrintf(" T[%d, %d](%f)=%s\n", it_, var, T[var*T_nrows+it_], tmp_out.str().c_str()); tmp_out.str(""); #endif @@ -1619,20 +1542,13 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) #endif break; case BinaryOpcode::divide: - double tmp; -#ifdef DEBUG - mexPrintf("v1=%f / v2=%f\n", v1, v2); -#endif - try - { - tmp = divide(v1, v2); - } - catch (FloatingPointException &fpeh) - { - mexPrintf("%s\n %s\n", fpeh.message.c_str(), error_location(it_code_expr, it_code, steady_state, it_).c_str()); - go_on = false; - } - Stack.push(tmp); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {v1 / v2}; + if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)) + throw DivideException{v1, v2, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |" << v1 << "/" << v2 << "|"; #endif @@ -1674,20 +1590,13 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) #endif break; case BinaryOpcode::power: -#ifdef DEBUG - mexPrintf("pow\n"); -#endif - try - { - tmp = pow1(v1, v2); - } - catch (FloatingPointException &fpeh) - { - mexPrintf("%s\n %s\n", fpeh.message.c_str(), error_location(it_code_expr, it_code, steady_state, it_).c_str()); - go_on = false; - } - Stack.push(tmp); - + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {pow(v1, v2)}; + if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)) + throw PowException{v1, v2, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |" << v1 << "^" << v2 << "|"; #endif @@ -1704,7 +1613,10 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) Stack.push(0.0); else { - double dxp = pow1(v1, v2-derivOrder); + feclearexcept(FE_ALL_EXCEPT); + double dxp {pow(v1, v2-derivOrder)}; + if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)) + throw PowException{v1, v2-derivOrder, error_location(it_code_expr, it_code, it_)}; for (int i = 0; i < derivOrder; i++) dxp *= v2--; Stack.push(dxp); @@ -1712,7 +1624,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) } catch (FloatingPointException &fpeh) { - mexPrintf("%s\n %s\n", fpeh.message.c_str(), error_location(it_code_expr, it_code, steady_state, it_).c_str()); + mexPrintf("%s\n %s\n", fpeh.message.c_str(), error_location(it_code_expr, it_code, it_).c_str()); go_on = false; } } @@ -1736,12 +1648,6 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) case BinaryOpcode::equal: // Nothing to do break; - default: - { - mexPrintf("Error\n"); - throw FatalException{"In compute_block_time, unknown binary operator " - + to_string(static_cast<int>(op2))}; - } } break; case Tags::FUNARY: @@ -1767,33 +1673,25 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) #endif break; case UnaryOpcode::log: - double tmp; - try - { - tmp = log1(v1); - } - catch (FloatingPointException &fpeh) - { - mexPrintf("%s\n %s\n", fpeh.message.c_str(), error_location(it_code_expr, it_code, steady_state, it_).c_str()); - go_on = false; - } - Stack.push(tmp); - + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {log(v1)}; + if (fetestexcept(FE_DIVBYZERO | FE_INVALID)) + throw UnaryOpException{"log", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |log(" << v1 << ")|"; #endif break; case UnaryOpcode::log10: - try - { - tmp = log10_1(v1); - } - catch (FloatingPointException &fpeh) - { - mexPrintf("%s\n %s\n", fpeh.message.c_str(), error_location(it_code_expr, it_code, steady_state, it_).c_str()); - go_on = false; - } - Stack.push(tmp); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {log10(v1)}; + if (fetestexcept(FE_DIVBYZERO | FE_INVALID)) + throw UnaryOpException{"log10", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |log10(" << v1 << ")|"; #endif @@ -1811,19 +1709,37 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) #endif break; case UnaryOpcode::tan: - Stack.push(tan(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {tan(v1)}; + if (fetestexcept(FE_OVERFLOW)) + throw UnaryOpException{"tan", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |tan(" << v1 << ")|"; #endif break; case UnaryOpcode::acos: - Stack.push(acos(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {acos(v1)}; + if (fetestexcept(FE_INVALID)) + throw UnaryOpException{"acos", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |acos(" << v1 << ")|"; #endif break; case UnaryOpcode::asin: - Stack.push(asin(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {asin(v1)}; + if (fetestexcept(FE_INVALID)) + throw UnaryOpException{"asin", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |asin(" << v1 << ")|"; #endif @@ -1835,13 +1751,25 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) #endif break; case UnaryOpcode::cosh: - Stack.push(cosh(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {cosh(v1)}; + if (fetestexcept(FE_OVERFLOW)) + throw UnaryOpException{"cosh", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |cosh(" << v1 << ")|"; #endif break; case UnaryOpcode::sinh: - Stack.push(sinh(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {sinh(v1)}; + if (fetestexcept(FE_OVERFLOW)) + throw UnaryOpException{"sinh", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |sinh(" << v1 << ")|"; #endif @@ -1853,7 +1781,13 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) #endif break; case UnaryOpcode::acosh: - Stack.push(acosh(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {acosh(v1)}; + if (fetestexcept(FE_INVALID)) + throw UnaryOpException{"acosh", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |acosh(" << v1 << ")|"; #endif @@ -1865,13 +1799,25 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) #endif break; case UnaryOpcode::atanh: - Stack.push(atanh(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {atanh(v1)}; + if (fetestexcept(FE_INVALID | FE_DIVBYZERO)) + throw UnaryOpException{"atanh", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |atanh(" << v1 << ")|"; #endif break; case UnaryOpcode::sqrt: - Stack.push(sqrt(v1)); + { + feclearexcept(FE_ALL_EXCEPT); + double tmp {sqrt(v1)}; + if (fetestexcept(FE_INVALID)) + throw UnaryOpException{"sqrt", v1, error_location(it_code_expr, it_code, it_)}; + Stack.push(tmp); + } #ifdef DEBUG tmp_out << " |sqrt(" << v1 << ")|"; #endif @@ -1887,14 +1833,38 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) Stack.push(erfc(v1)); #ifdef DEBUG tmp_out << " |erfc(" << v1 << ")|"; - #endif break; - default: - { - mexPrintf("Error\n"); - throw FatalException{"In compute_block_time, unknown unary operator " + to_string(static_cast<int>(op1))}; - } + case UnaryOpcode::cbrt: + Stack.push(cbrt(v1)); +#ifdef DEBUG + tmp_out << " |cbrt(" << v1 << ")|"; +#endif + break; + case UnaryOpcode::abs: + Stack.push(abs(v1)); +#ifdef DEBUG + tmp_out << " |abs(" << v1 << ")|"; +#endif + break; + case UnaryOpcode::sign: + Stack.push((v1 > 0) ? 1 : ((v1 < 0) ? -1 : 0)); +#ifdef DEBUG + tmp_out << " |sign(" << v1 << ")|"; +#endif + break; + case UnaryOpcode::steadyState: + throw FatalException {"Internal error: operator steady_state should not appear"}; + case UnaryOpcode::steadyStateParamDeriv: + throw FatalException {"Internal error: 1st derivative w.r.t. parameters of operator steady_state should not appear"}; + case UnaryOpcode::steadyStateParam2ndDeriv: + throw FatalException {"Internal error: 2nd derivative w.r.t. parameters of operator steady_state should not appear"}; + case UnaryOpcode::expectation: + throw FatalException {"Internal error: operator expectation should not appear"}; + case UnaryOpcode::diff: + throw FatalException {"Internal error: operator diff should not appear"}; + case UnaryOpcode::adl: + throw FatalException {"Internal error: operator adl should not appear"}; } break; case Tags::FTRINARY: @@ -1908,22 +1878,17 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) switch (op3) { case TrinaryOpcode::normcdf: - Stack.push(0.5*(1+erf((v1-v2)/v3/M_SQRT2))); + Stack.push(0.5*(1+erf((v1-v2)/v3/numbers::sqrt2))); #ifdef DEBUG tmp_out << " |normcdf(" << v1 << ", " << v2 << ", " << v3 << ")|"; #endif break; case TrinaryOpcode::normpdf: - Stack.push(1/(v3*sqrt(2*M_PI)*exp(pow((v1-v2)/v3, 2)/2))); + Stack.push(1/(v3*sqrt(2*numbers::pi)*exp(pow((v1-v2)/v3, 2)/2))); #ifdef DEBUG tmp_out << " |normpdf(" << v1 << ", " << v2 << ", " << v3 << ")|"; #endif break; - default: - { - mexPrintf("Error\n"); - throw FatalException{"In compute_block_time, unknown trinary operator " + to_string(static_cast<int>(op3))}; - } } break; @@ -2222,7 +2187,7 @@ Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative) mexPrintf("Impossible case in Bytecode\n"); break; case Tags::FENDEQU: - if (no_derivative) + if (no_derivatives) go_on = false; break; case Tags::FJMPIFEVAL: @@ -2262,12 +2227,7 @@ Evaluate::gotoBlock(int block) if (fb->op_code != Tags::FBEGINBLOCK) throw FatalException {"Evaluate::gotoBlock: internal inconsistency"}; - Block_Contain = fb->get_Block_Contain(); size = fb->get_size(); - type = fb->get_type(); - is_linear = fb->get_is_linear(); - symbol_table_endo_nbr = fb->get_endo_nbr(); - u_count_int = fb->get_u_count_int(); } void @@ -2302,46 +2262,22 @@ Evaluate::printCurrentBlock() } } -void -Evaluate::initializeTemporaryTerms(bool global_temporary_terms) +int +Evaluate::getNumberOfTemporaryTerms() const { BytecodeInstruction *instr {instructions_list.front()}; - if (instr->op_code == Tags::FDIMT) + if (steady_state) { - int ntt {reinterpret_cast<FDIMT_ *>(instr)->get_size()}; -#ifdef DEBUG - mexPrintf("FDIMT size=%d\n", ntt); -#endif - if (T) - mxFree(T); - T = static_cast<double *>(mxMalloc(ntt*(periods+y_kmin+y_kmax)*sizeof(double))); - test_mxMalloc(T, __LINE__, __FILE__, __func__, ntt*(periods+y_kmin+y_kmax)*sizeof(double)); + if (instr->op_code == Tags::FDIMST) + return reinterpret_cast<FDIMST_ *>(instr)->get_size(); + else + throw FatalException {"Evaluate::getNumberOfTemporaryTerms: static .cod file does not begin with FDIMST!"}; } - else if (instr->op_code == Tags::FDIMST) + else { - int ntt {reinterpret_cast<FDIMST_ *>(instr)->get_size()}; -#ifdef DEBUG - mexPrintf("FDIMST size=%d\n", ntt); -#endif - if (T) - mxFree(T); - if (global_temporary_terms) - { - if (!GlobalTemporaryTerms) - { - mexPrintf("GlobalTemporaryTerms is nullptr\n"); - mexEvalString("drawnow;"); - } - if (ntt != static_cast<int>(mxGetNumberOfElements(GlobalTemporaryTerms))) - GlobalTemporaryTerms = mxCreateDoubleMatrix(ntt, 1, mxREAL); - T = mxGetPr(GlobalTemporaryTerms); - } + if (instr->op_code == Tags::FDIMT) + return reinterpret_cast<FDIMT_ *>(instr)->get_size(); else - { - T = static_cast<double *>(mxMalloc(ntt*sizeof(double))); - test_mxMalloc(T, __LINE__, __FILE__, __func__, ntt*sizeof(double)); - } + throw FatalException {"Evaluate::getNumberOfTemporaryTerms: dynamic .cod file does not begin with FDIMT!"}; } - else - throw FatalException {"Evaluate::initializeTemporaryTerms: .cod file does not begin with FDIMT or FDIMST!"}; } diff --git a/mex/sources/bytecode/Evaluate.hh b/mex/sources/bytecode/Evaluate.hh index 16b22aa326218daa8c6543ee9dd44b411f915052..dcb004d7c498286f02e011594c810a85ae4fe4c0 100644 --- a/mex/sources/bytecode/Evaluate.hh +++ b/mex/sources/bytecode/Evaluate.hh @@ -36,6 +36,9 @@ private: using instructions_list_t = vector<BytecodeInstruction *>; using it_code_type = instructions_list_t::const_iterator; + const BasicSymbolTable &symbol_table; + const bool steady_state; // Whether this is a static or dynamic .cod file + // Memory copy of the contents of the .cod file unique_ptr<char[]> raw_bytecode; @@ -53,14 +56,21 @@ private: // Index of beginnings of blocks within instructions_list vector<size_t> begin_block; + int block_num; // Index of the current block + int size; // Size of the current block + ExpressionType EQN_type; - int EQN_equation, EQN_block, EQN_dvar1; + int EQN_equation, EQN_dvar1; int EQN_lag1, EQN_lag2, EQN_lag3; - map<int, double> TEF; - map<pair<int, int>, double> TEFD; - map<tuple<int, int, int>, double> TEFDD; - string error_location(it_code_type expr_begin, it_code_type faulty_op, bool steady_state, int it_) const; + string error_location(it_code_type expr_begin, it_code_type faulty_op, int it_) const; + + /* Prints a bytecode expression in human readable form. + If faulty_op is not default constructed, it should point to a tag within + the expression that created a floating point exception, in which case the + corresponding mathematical operator will be printed within braces. + The second output argument points to the tag past the expression. */ + pair<string, it_code_type> print_expression(const it_code_type &expr_begin, const optional<it_code_type> &faulty_op = nullopt) const; FBEGINBLOCK_ * currentBlockTag() const @@ -75,52 +85,43 @@ private: return instructions_list.begin() + begin_block[block_num] + 1; } -protected: - BasicSymbolTable &symbol_table; - int EQN_block_number; - double *y, *ya; - int y_size; - double *T; - int nb_row_x; - int y_kmin, y_kmax, periods; - double *x, *params; - double *u; - double *steady_y; - double *g1, *r, *res; - vector<mxArray *> jacobian_block, jacobian_exo_block, jacobian_det_exo_block; - mxArray *GlobalTemporaryTerms; - double pow1(double a, double b); - double divide(double a, double b); - double log1(double a); - double log10_1(double a); - void compute_block_time(int Per_u_, bool evaluate, bool no_derivatives); - int it_; - bool print_error; - double res1; - - int block_num; // Index of the current block - int size; // Size of the current block - BlockSimulationType type; - bool is_linear; - int symbol_table_endo_nbr, u_count_int; - vector<Block_contain_type> Block_Contain; +public: + Evaluate(const filesystem::path &codfile, bool steady_state_arg, const BasicSymbolTable &symbol_table_arg); - bool steady_state; - - /* Prints a bytecode expression in human readable form. - If faulty_op is not default constructed, it should point to a tag within - the expression that created a floating point exception, in which case the - corresponding mathematical operator will be printed within braces. - The second output argument points to the tag past the expression. */ - pair<string, it_code_type> print_expression(const it_code_type &expr_begin, const optional<it_code_type> &faulty_op = nullopt) const; + void evaluateBlock(int it_, double *__restrict__ y, const double *__restrict__ ya, int y_size, double *__restrict__ x, int nb_row_x, double *__restrict__ params, const double *__restrict__ steady_y, double *__restrict__ u, int Per_u_, double *__restrict__ T, int T_nrows, map<int, double> &TEF, map<pair<int, int>, double> &TEFD, map<tuple<int, int, int>, double> &TEFDD, double *__restrict__ r, double *__restrict__ g1, double *__restrict__ jacob, double *__restrict__ jacob_exo, double *__restrict__ jacob_exo_det, bool evaluate, bool no_derivatives); // Prints current block void printCurrentBlock(); void gotoBlock(int block); - void initializeTemporaryTerms(bool global_temporary_terms); + int getNumberOfTemporaryTerms() const; + auto + getCurrentBlockSize() const + { + return currentBlockTag()->get_size(); + } + auto + getCurrentBlockType() const + { + return currentBlockTag()->get_type(); + } + auto + isCurrentBlockLinear() const + { + return currentBlockTag()->get_is_linear(); + } + auto + getCurrentBlockEquationsAndVariables() const + { + return currentBlockTag()->get_Block_Contain(); + } + auto + getCurrentBlockUCount() const + { + return currentBlockTag()->get_u_count_int(); + } auto getCurrentBlockExogenous() const { @@ -147,11 +148,6 @@ protected: return currentBlockTag()->get_det_exo_size(); } -public: - Evaluate(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool steady_state_arg, int periods_arg, BasicSymbolTable &symbol_table_arg); - // TODO: integrate into the constructor - void loadCodeFile(const filesystem::path &codfile); - int get_block_number() const { diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index 8f4e069710dcdeda96f90fefbe381db7d2bbe5f1..b213c54e2b677f88c73e1e3c4840e2910467ae83 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -19,22 +19,22 @@ #include <sstream> #include <algorithm> -#include <cstring> #include <filesystem> #include <numeric> +#include <cfenv> #include "Interpreter.hh" constexpr double BIG = 1.0e+8, SMALL = 1.0e-5; -Interpreter::Interpreter(double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg, +Interpreter::Interpreter(Evaluate &evaluator_arg, double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg, double *direction_arg, size_t y_size_arg, size_t nb_row_x_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, - int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_arg, int y_decal_arg, double markowitz_c_arg, + int maxit_arg_, double solve_tolf_arg, int y_decal_arg, double markowitz_c_arg, string &filename_arg, int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg, - bool global_temporary_terms_arg, bool print_arg, bool print_error_arg, mxArray *GlobalTemporaryTerms_arg, - bool steady_state_arg, bool block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, BasicSymbolTable &symbol_table_arg) -: dynSparseMatrix {y_size_arg, y_kmin_arg, y_kmax_arg, print_it_arg, steady_state_arg, block_decomposed_arg, periods_arg, minimal_solving_periods_arg, symbol_table_arg} + bool global_temporary_terms_arg, bool print_arg, mxArray *GlobalTemporaryTerms_arg, + bool steady_state_arg, bool block_decomposed_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg, int verbosity_arg) +: dynSparseMatrix {evaluator_arg, y_size_arg, y_kmin_arg, y_kmax_arg, steady_state_arg, block_decomposed_arg, periods_arg, minimal_solving_periods_arg, symbol_table_arg, verbosity_arg} { params = params_arg; y = y_arg; @@ -46,7 +46,6 @@ Interpreter::Interpreter(double *params_arg, double *y_arg, double *ya_arg, doub periods = periods_arg; maxit_ = maxit_arg_; solve_tolf = solve_tolf_arg; - size_of_direction = size_of_direction_arg; slowc = 1; slowc_save = 1; y_decal = y_decal_arg; @@ -61,8 +60,6 @@ Interpreter::Interpreter(double *params_arg, double *y_arg, double *ya_arg, doub col_x = col_x_arg; col_y = col_y_arg; GlobalTemporaryTerms = GlobalTemporaryTerms_arg; - print_error = print_error_arg; - print_it = print_it_arg; } void @@ -95,7 +92,7 @@ Interpreter::solve_simple_one_periods() double ya; double slowc = 1; res1 = 0; - while (!(cvg || iter > maxit_)) + while (!(cvg || iter >= maxit_)) { Per_y_ = it_*y_size; ya = y[Block_Contain[0].Variable + Per_y_]; @@ -109,8 +106,16 @@ Interpreter::solve_simple_one_periods() if (!isfinite(res1)) { slowc /= 1.5; - mexPrintf("Reducing the path length in Newton step slowc=%f\n", slowc); - y[Block_Contain[0].Variable + Per_y_] = ya - slowc * divide(r[0], g1[0]); + if (verbosity >= 2) + mexPrintf("Reducing the path length in Newton step slowc=%f\n", slowc); + feclearexcept(FE_ALL_EXCEPT); + y[Block_Contain[0].Variable + Per_y_] = ya - slowc * (r[0] / g1[0]); + if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)) + { + res1 = numeric_limits<double>::quiet_NaN(); + if (verbosity >= 1) + mexPrintf(" Singularity in block %d", block_num+1); + } } } } @@ -119,14 +124,13 @@ Interpreter::solve_simple_one_periods() cvg = (fabs(rr) < solve_tolf); if (cvg) continue; - try + feclearexcept(FE_ALL_EXCEPT); + y[Block_Contain[0].Variable + Per_y_] += -slowc * (rr / g1[0]); + if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)) { - y[Block_Contain[0].Variable + Per_y_] += -slowc *divide(rr, g1[0]); - } - catch (FloatingPointException &fpeh) - { - mexPrintf("%s\n \n", fpeh.message.c_str()); - mexPrintf(" Singularity in block %d", block_num+1); + res1 = numeric_limits<double>::quiet_NaN(); + if (verbosity >= 1) + mexPrintf(" Singularity in block %d", block_num+1); } iter++; } @@ -224,10 +228,10 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri compute_block_time(0, true, false); if (single_block) for (int j = 0; j < size; j++) - residual[it_*size+j] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; + residual[(it_-y_kmin)*size+j] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; else for (int j = 0; j < size; j++) - residual[it_*size+Block_Contain[j].Equation] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; + residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; } } break; @@ -254,10 +258,10 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri compute_block_time(0, true, false); if (!single_block) for (int j = 0; j < size; j++) - residual[Per_y_+Block_Contain[j].Equation] = r[j]; + residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j]; else for (int j = 0; j < size; j++) - residual[it_*size+j] = r[j]; + residual[(it_-y_kmin)*size+j] = r[j]; } } mxFree(g1); @@ -292,10 +296,10 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri compute_block_time(0, true, false); if (!single_block) for (int j = 0; j < size; j++) - residual[it_*y_size+Block_Contain[j].Equation] = r[j]; + residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j]; else for (int j = 0; j < size; j++) - residual[it_*size+j] = r[j]; + residual[(it_-y_kmin)*size+j] = r[j]; } } mxFree(r); @@ -319,10 +323,10 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri compute_block_time(0, true, false); if (single_block) for (int j = 0; j < size; j++) - residual[it_*size+j] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; + residual[(it_-y_kmin)*size+j] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; else for (int j = 0; j < size; j++) - residual[it_*size+Block_Contain[j].Equation] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; + residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable]; } } break; @@ -349,10 +353,10 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri compute_block_time(0, true, false); if (!single_block) for (int j = 0; j < size; j++) - residual[Per_y_+Block_Contain[j].Equation] = r[j]; + residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j]; else for (int j = 0; j < size; j++) - residual[it_*size+j] = r[j]; + residual[(it_-y_kmin)*size+j] = r[j]; } } mxFree(g1); @@ -384,10 +388,10 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri compute_block_time(0, true, false); if (!single_block) for (int j = 0; j < size; j++) - residual[Per_y_+Block_Contain[j].Equation] = r[j]; + residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j]; else for (int j = 0; j < size; j++) - residual[it_*size+j] = r[j]; + residual[(it_-y_kmin)*size+j] = r[j]; } } mxFree(r); @@ -409,10 +413,10 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri compute_block_time(Per_u_, true, false); if (!single_block) for (int j = 0; j < size; j++) - residual[it_*y_size+Block_Contain[j].Equation] = r[j]; + residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j]; else for (int j = 0; j < size; j++) - residual[it_*size+j] = r[j]; + residual[(it_-y_kmin)*size+j] = r[j]; } mxFree(r); break; @@ -481,7 +485,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ mxFree(u); mxFree(index_equa); mxFree(index_vara); - memset(direction, 0, size_of_direction); + fill_n(direction, y_size*col_y, 0); End_Solver(); break; case BlockSimulationType::solveBackwardComplete: @@ -502,7 +506,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ mxFree(index_equa); mxFree(index_vara); - memset(direction, 0, size_of_direction); + fill_n(direction, y_size*col_y, 0); mxFree(u); End_Solver(); break; @@ -514,7 +518,8 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ #endif if (steady_state) { - mexPrintf("SOLVE TWO BOUNDARIES in a steady state model: impossible case\n"); + if (verbosity >= 1) + mexPrintf("SOLVE TWO BOUNDARIES in a steady state model: impossible case\n"); return ERROR_ON_EXIT; } if (vector_table_conditional_local.size()) @@ -541,7 +546,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ glambda2 = g0 = very_big; try_at_iteration = 0; int u_count_saved = u_count; - while (!(cvg || (iter > maxit_))) + while (!(cvg || (iter >= maxit_))) { res2 = 0; res1 = 0; @@ -559,7 +564,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ copy_n(y_save, y_size*(periods+y_kmax+y_kmin), y); u_count = u_count_saved; int prev_iter = iter; - Simulate_Newton_Two_Boundaries(block_num, symbol_table_endo_nbr, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local); + Simulate_Newton_Two_Boundaries(block_num, y_size, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local); iter++; if (iter > prev_iter) { @@ -583,7 +588,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ compute_complete_2b(false, &res1, &res2, &max_res, &max_res_idx); cvg = false; - Simulate_Newton_Two_Boundaries(block_num, symbol_table_endo_nbr, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local); + Simulate_Newton_Two_Boundaries(block_num, y_size, y_kmin, y_kmax, size, periods, cvg, minimal_solving_periods, stack_solve_algo, vector_table_conditional_local); max_res = 0; max_res_idx = 0; } slowc = 1; // slowc is modified when stack_solve_algo=4, so restore it @@ -599,7 +604,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ mxFree(index_equa); if (res) mxFree(res); - memset(direction, 0, size_of_direction); + fill_n(direction, y_size*col_y, 0); End_Solver(); break; default: @@ -609,21 +614,11 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_ return NO_ERROR_ON_EXIT; } -void -Interpreter::ReadCodeFile(const string &file_name) -{ - filesystem::path codfile {file_name + "/model/bytecode/" + (block_decomposed ? "block/" : "") - + (steady_state ? "static" : "dynamic") + ".cod"}; - - loadCodeFile(codfile); - EQN_block_number = get_block_number(); -} - void Interpreter::check_for_controlled_exo_validity(int current_block, const vector<s_plan> &sconstrained_extended_path) { - vector<int> exogenous {getCurrentBlockExogenous()}; - vector<int> endogenous {getCurrentBlockEndogenous()}; + vector<int> exogenous {evaluator.getCurrentBlockExogenous()}; + vector<int> endogenous {evaluator.getCurrentBlockEndogenous()}; for (auto & it : sconstrained_extended_path) { if (find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end() @@ -655,23 +650,25 @@ Interpreter::MainLoop(const string &bin_basename, bool evaluate, int block, bool { initializeTemporaryTerms(global_temporary_terms); - if (block >= get_block_number()) + int nb_blocks {evaluator.get_block_number()}; + + if (block >= nb_blocks) throw FatalException {"Interpreter::MainLoop: Input argument block = " + to_string(block+1) + " is greater than the number of blocks in the model (" - + to_string(get_block_number()) + " see M_.block_structure" + (steady_state ? "_stat" : "") + ".block)"}; + + to_string(nb_blocks) + " see M_.block_structure" + (steady_state ? "_stat" : "") + ".block)"}; vector<int> blocks; if (block < 0) { - blocks.resize(get_block_number()); + blocks.resize(nb_blocks); iota(blocks.begin(), blocks.end(), 0); } else blocks.push_back(block); - jacobian_block.resize(get_block_number()); - jacobian_exo_block.resize(get_block_number()); - jacobian_det_exo_block.resize(get_block_number()); + jacobian_block.resize(nb_blocks); + jacobian_exo_block.resize(nb_blocks); + jacobian_det_exo_block.resize(nb_blocks); double max_res_local = 0; int max_res_idx_local = 0; @@ -681,12 +678,18 @@ Interpreter::MainLoop(const string &bin_basename, bool evaluate, int block, bool if (steady_state) residual = vector<double>(y_size); else - residual = vector<double>(y_size*(periods+y_kmin)); + residual = vector<double>(y_size*periods); } for (int current_block : blocks) { - gotoBlock(current_block); + evaluator.gotoBlock(current_block); + block_num = current_block; + size = evaluator.getCurrentBlockSize(); + type = evaluator.getCurrentBlockType(); + is_linear = evaluator.isCurrentBlockLinear(); + Block_Contain = evaluator.getCurrentBlockEquationsAndVariables(); + u_count_int = evaluator.getCurrentBlockUCount(); if (constrained) check_for_controlled_exo_validity(current_block, sconstrained_extended_path); @@ -695,47 +698,47 @@ Interpreter::MainLoop(const string &bin_basename, bool evaluate, int block, bool if (steady_state) residual = vector<double>(size); else - residual = vector<double>(size*(periods+y_kmin)); - printCurrentBlock(); + residual = vector<double>(size*periods); + evaluator.printCurrentBlock(); } else if (evaluate) { #ifdef DEBUG mexPrintf("jacobian_block=mxCreateDoubleMatrix(%d, %d, mxREAL)\n", size, getCurrentBlockNbColJacob()); #endif - jacobian_block[current_block] = mxCreateDoubleMatrix(size, getCurrentBlockNbColJacob(), mxREAL); + jacobian_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockNbColJacob(), mxREAL); if (!steady_state) { #ifdef DEBUG - mexPrintf("allocates jacobian_exo_block( %d, %d, mxREAL)\n", size, getCurrentBlockExoSize()); + mexPrintf("allocates jacobian_exo_block( %d, %d, mxREAL)\n", size, evaluator.getCurrentBlockExoSize()); mexPrintf("(0) Allocating Jacobian\n"); #endif - jacobian_exo_block[current_block] = mxCreateDoubleMatrix(size, getCurrentBlockExoSize(), mxREAL); - jacobian_det_exo_block[current_block] = mxCreateDoubleMatrix(size, getCurrentBlockExoDetSize(), mxREAL); + jacobian_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoSize(), mxREAL); + jacobian_det_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoDetSize(), mxREAL); } if (block >= 0) { if (steady_state) residual = vector<double>(size); else - residual = vector<double>(size*(periods+y_kmin)); + residual = vector<double>(size*periods); } evaluate_a_block(true, block >= 0, bin_basename); } else { #ifdef DEBUG - mexPrintf("endo in block %d, size=%d, type=%d, steady_state=%d, print_it=%d, is_linear=%d, endo_nbr=%d, u_count_int=%d\n", - current_block+1, size, type, steady_state, print_it, is_linear, symbol_table_endo_nbr, u_count_int); + mexPrintf("endo in block %d, size=%d, type=%d, steady_state=%d, is_linear=%d, endo_nbr=%d, u_count_int=%d\n", + current_block+1, size, type, steady_state, is_linear, symbol_table_endo_nbr, u_count_int); #endif bool result; if (sconstrained_extended_path.size()) { - jacobian_block[current_block] = mxCreateDoubleMatrix(size, getCurrentBlockNbColJacob(), mxREAL); - jacobian_exo_block[current_block] = mxCreateDoubleMatrix(size, getCurrentBlockExoSize(), mxREAL); - jacobian_det_exo_block[current_block] = mxCreateDoubleMatrix(size, getCurrentBlockExoDetSize(), mxREAL); - residual = vector<double>(size*(periods+y_kmin)); + jacobian_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockNbColJacob(), mxREAL); + jacobian_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoSize(), mxREAL); + jacobian_det_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoDetSize(), mxREAL); + residual = vector<double>(size*periods); result = simulate_a_block(vector_table_conditional_local, block >= 0, bin_basename); } else @@ -799,7 +802,6 @@ Interpreter::elastic(string str, unsigned int len, bool left) pair<bool, vector<int>> Interpreter::extended_path(const string &file_name, bool evaluate, int block, int nb_periods, const vector<s_plan> &sextended_path, const vector<s_plan> &sconstrained_extended_path, const vector<string> &dates, const table_conditional_global_type &table_conditional_global) { - ReadCodeFile(file_name); size_t size_of_direction = y_size*col_y*sizeof(double); auto *y_save = static_cast<double *>(mxMalloc(size_of_direction)); test_mxMalloc(y_save, __LINE__, __FILE__, __func__, size_of_direction); @@ -821,8 +823,8 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in y_save[i] = y[i]; if (endo_name_length_l < 8) endo_name_length_l = 8; - bool old_print_it = print_it; - print_it = false; + int old_verbosity {verbosity}; + verbosity = 0; ostringstream res1; res1 << std::scientific << 2.54656875434865131; int real_max_length = res1.str().length(); @@ -831,7 +833,7 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in string line; line.insert(line.begin(), table_length, '-'); line.insert(line.length(), "\n"); - if (old_print_it) + if (old_verbosity >= 1) { mexPrintf("\nExtended Path simulation:\n"); mexPrintf("-------------------------\n"); @@ -845,7 +847,7 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in for (int t = 0; t < nb_periods; t++) { previous_block_exogenous.clear(); - if (old_print_it) + if (old_verbosity >= 1) { mexPrintf("|%s|", elastic(dates[t], date_length+2, false).c_str()); mexEvalString("drawnow;"); @@ -870,7 +872,7 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in x[y_kmin + j * nb_row_x] = x_save[t + 1 + y_kmin + j * nb_row_x]; } - if (old_print_it) + if (old_verbosity >= 1) { ostringstream res1; res1 << std::scientific << max_res; @@ -879,7 +881,7 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in mexEvalString("drawnow;"); } } - print_it = old_print_it; + verbosity = old_verbosity; for (int i = 0; i < y_size * col_y; i++) y[i] = y_save[i]; for (int j = 0; j < col_x * nb_row_x; j++) @@ -896,8 +898,6 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in pair<bool, vector<int>> Interpreter::compute_blocks(const string &file_name, bool evaluate, int block) { - ReadCodeFile(file_name); - //The big loop on intructions vector<s_plan> s_plan_junk; vector_table_conditional_local_type vector_table_conditional_local_junk; @@ -908,3 +908,38 @@ Interpreter::compute_blocks(const string &file_name, bool evaluate, int block) mxFree(T); return {true, blocks}; } + +void +Interpreter::initializeTemporaryTerms(bool global_temporary_terms) +{ + int ntt { evaluator.getNumberOfTemporaryTerms() }; + + if (steady_state) + { + if (T) + mxFree(T); + if (global_temporary_terms) + { + if (!GlobalTemporaryTerms) + { + mexPrintf("GlobalTemporaryTerms is nullptr\n"); + mexEvalString("drawnow;"); + } + if (ntt != static_cast<int>(mxGetNumberOfElements(GlobalTemporaryTerms))) + GlobalTemporaryTerms = mxCreateDoubleMatrix(ntt, 1, mxREAL); + T = mxGetPr(GlobalTemporaryTerms); + } + else + { + T = static_cast<double *>(mxMalloc(ntt*sizeof(double))); + test_mxMalloc(T, __LINE__, __FILE__, __func__, ntt*sizeof(double)); + } + } + else + { + if (T) + mxFree(T); + T = static_cast<double *>(mxMalloc(ntt*(periods+y_kmin+y_kmax)*sizeof(double))); + test_mxMalloc(T, __LINE__, __FILE__, __func__, ntt*(periods+y_kmin+y_kmax)*sizeof(double)); + } +} diff --git a/mex/sources/bytecode/Interpreter.hh b/mex/sources/bytecode/Interpreter.hh index f383868138d91f18952176dcd8215a75d9fe3eff..5de6f5601261f575fcf4625ab1b22e7c0da6b428 100644 --- a/mex/sources/bytecode/Interpreter.hh +++ b/mex/sources/bytecode/Interpreter.hh @@ -37,31 +37,31 @@ class Interpreter : public dynSparseMatrix { private: vector<int> previous_block_exogenous; - int size_of_direction; bool global_temporary_terms; - bool print; + bool print; // Whether the “print” command is requested int col_x, col_y; + vector<double> residual; void evaluate_over_periods(bool forward); void solve_simple_one_periods(); void solve_simple_over_periods(bool forward); void compute_complete_2b(bool no_derivatives, double *_res1, double *_res2, double *_max_res, int *_max_res_idx); + void initializeTemporaryTerms(bool global_temporary_terms); protected: void evaluate_a_block(bool initialization, bool single_block, const string &bin_base_name); int simulate_a_block(const vector_table_conditional_local_type &vector_table_conditional_local, bool single_block, const string &bin_base_name); string elastic(string str, unsigned int len, bool left); public: - Interpreter(double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg, + Interpreter(Evaluate &evaluator_arg, double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg, double *direction_arg, size_t y_size_arg, size_t nb_row_x_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, - int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_arg, int y_decal_arg, double markowitz_c_arg, + int maxit_arg_, double solve_tolf_arg, int y_decal_arg, double markowitz_c_arg, string &filename_arg, int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg, - bool global_temporary_terms_arg, bool print_arg, bool print_error_arg, mxArray *GlobalTemporaryTerms_arg, - bool steady_state_arg, bool block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, BasicSymbolTable &symbol_table_arg); + bool global_temporary_terms_arg, bool print_arg, mxArray *GlobalTemporaryTerms_arg, + bool steady_state_arg, bool block_decomposed_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg, int verbosity_arg); pair<bool, vector<int>> extended_path(const string &file_name, bool evaluate, int block, int nb_periods, const vector<s_plan> &sextended_path, const vector<s_plan> &sconstrained_extended_path, const vector<string> &dates, const table_conditional_global_type &table_conditional_global); pair<bool, vector<int>> compute_blocks(const string &file_name, bool evaluate, int block); void check_for_controlled_exo_validity(int current_block, const vector<s_plan> &sconstrained_extended_path); pair<bool, vector<int>> MainLoop(const string &bin_basename, bool evaluate, int block, bool constrained, const vector<s_plan> &sconstrained_extended_path, const vector_table_conditional_local_type &vector_table_conditional_local); - void ReadCodeFile(const string &file_name); inline mxArray * get_jacob(int block_num) const diff --git a/mex/sources/bytecode/SparseMatrix.cc b/mex/sources/bytecode/SparseMatrix.cc index 5cc4f27f58373b85a4d11f5b5934b776fc432a4d..47f3adc4267928caa5ca32c0aec9c2093bc7271f 100644 --- a/mex/sources/bytecode/SparseMatrix.cc +++ b/mex/sources/bytecode/SparseMatrix.cc @@ -21,15 +21,22 @@ #include <algorithm> #include <filesystem> #include <type_traits> +#include <chrono> #include "SparseMatrix.hh" -dynSparseMatrix::dynSparseMatrix(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, bool block_decomposed_arg, int periods_arg, - int minimal_solving_periods_arg, BasicSymbolTable &symbol_table_arg) : - Evaluate {y_size_arg, y_kmin_arg, y_kmax_arg, steady_state_arg, periods_arg, symbol_table_arg}, +dynSparseMatrix::dynSparseMatrix(Evaluate &evaluator_arg, int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool steady_state_arg, bool block_decomposed_arg, int periods_arg, + int minimal_solving_periods_arg, const BasicSymbolTable &symbol_table_arg, int verbosity_arg) : + symbol_table {symbol_table_arg}, + steady_state {steady_state_arg}, block_decomposed {block_decomposed_arg}, + evaluator {evaluator_arg}, minimal_solving_periods {minimal_solving_periods_arg}, - print_it {print_it_arg} + y_size {y_size_arg}, + y_kmin {y_kmin_arg}, + y_kmax {y_kmax_arg}, + periods {periods_arg}, + verbosity {verbosity_arg} { pivotva = nullptr; g_save_op = nullptr; @@ -675,9 +682,6 @@ dynSparseMatrix::Init_UMFPACK_Sparse(int periods, int y_kmin, int y_kmax, int Si throw FatalException{"In Init_UMFPACK_Sparse, can't retrieve Ax matrix"}; for (int i = 0; i < y_size*(periods+y_kmin); i++) ya[i] = y[i]; -#ifdef DEBUG - unsigned int max_nze = prior_nz; //mxGetNzmax(A_m); -#endif unsigned int NZE = 0; int last_var = 0; for (int i = 0; i < periods*Size; i++) @@ -787,8 +791,8 @@ dynSparseMatrix::Init_UMFPACK_Sparse(int periods, int y_kmin, int y_kmax, int Si if (lag <= ti_new_y_kmax && lag >= ti_new_y_kmin) /*Build the index for sparse matrix containing the jacobian : u*/ { #ifdef DEBUG - if (NZE >= max_nze) - throw FatalException{"In Init_UMFPACK_Sparse, exceeds the capacity of A_m sparse matrix"}; + if (NZE >= prior_nz) + throw FatalException{"In Init_UMFPACK_Sparse, exceeds the capacity of allocated sparse matrix"}; #endif if (!fliped) { @@ -923,9 +927,6 @@ dynSparseMatrix::Init_Matlab_Sparse(int periods, int y_kmin, int y_kmax, int Siz for (int i = 0; i < y_size*(periods+y_kmin); i++) ya[i] = y[i]; -#ifdef DEBUG - unsigned int max_nze = mxGetNzmax(A_m); -#endif unsigned int NZE = 0; int last_var = 0; for (int i = 0; i < periods*Size; i++) @@ -962,8 +963,8 @@ dynSparseMatrix::Init_Matlab_Sparse(int periods, int y_kmin, int y_kmax, int Siz + ") out of range for u vector max = " + to_string(Size+Size*Size) + " allocated = " + to_string(u_count_alloc)}; - if (NZE >= max_nze) - throw FatalException{"In Init_Matlab_Sparse, exceeds the capacity of A_m sparse matrix"}; + if (NZE >= prior_nz) + throw FatalException{"In Init_Matlab_Sparse, exceeds the capacity of allocated sparse matrix"}; #endif A[NZE] = u[index]; Ai[NZE] = eq - lag * Size; @@ -1530,44 +1531,6 @@ dynSparseMatrix::simple_bksub(int it_, int Size, double slowc_l) } } -void -dynSparseMatrix::Check_the_Solution(int periods, int y_kmin, int y_kmax, int Size, double *u, int *pivot, int *b) -{ - constexpr double epsilon = 1e-10; - Init_GE(periods, y_kmin, y_kmax, Size, IM_i); - int cal_y = y_kmin*Size; - mexPrintf(" "); - for (int i = 0; i < Size; i++) - mexPrintf(" %8d", i); - mexPrintf("\n"); - for (int t = y_kmin; t < periods+y_kmin; t++) - { - mexPrintf("t=%5d", t); - for (int i = 0; i < Size; i++) - mexPrintf(" %d %1.6f", t*y_size+index_vara[i], y[t*y_size+index_vara[i]]); - mexPrintf("\n"); - } - for (int i = 0; i < Size*periods; i++) - { - double res = 0; - int pos = pivot[i]; - mexPrintf("pos[%d]=%d", i, pos); - NonZeroElem *first; - int nb_var = At_Row(pos, &first); - mexPrintf(" nb_var=%d\n", nb_var); - for (int j = 0; j < nb_var; j++) - { - mexPrintf("(y[%d]=%f)*(u[%d]=%f)(r=%d, c=%d)\n", index_vara[first->c_index]+cal_y, y[index_vara[first->c_index]+cal_y], first->u_index, u[first->u_index], first->r_index, first->c_index); - res += y[index_vara[first->c_index]+cal_y]*u[first->u_index]; - first = first->NZE_R_N; - } - double tmp_ = res; - res += u[b[pos]]; - if (abs(res) > epsilon) - mexPrintf("Error for equation %d => res=%f y[%d]=%f u[b[%d]]=%f somme(y*u)=%f\n", pos, res, pos, y[index_vara[pos]], pos, u[b[pos]], tmp_); - } -} - mxArray * dynSparseMatrix::subtract_A_B(const mxArray *A_m, const mxArray *B_m) { @@ -1824,6 +1787,35 @@ dynSparseMatrix::Sparse_transpose(const mxArray *A_m) return C_m; } +void +dynSparseMatrix::compute_block_time(int Per_u_, bool evaluate, bool no_derivatives) +{ +#ifdef DEBUG + mexPrintf("compute_block_time\n"); +#endif + double *jacob {nullptr}, *jacob_exo {nullptr}, *jacob_exo_det {nullptr}; + if (evaluate) + { + jacob = mxGetPr(jacobian_block[block_num]); + if (!steady_state) + { + jacob_exo = mxGetPr(jacobian_exo_block[block_num]); + jacob_exo_det = mxGetPr(jacobian_det_exo_block[block_num]); + } + } + + try + { + evaluator.evaluateBlock(it_, y, ya, y_size, x, nb_row_x, params, steady_y, u, Per_u_, T, periods+y_kmin+y_kmax, TEF, TEFD, TEFDD, r, g1, jacob, jacob_exo, jacob_exo_det, evaluate, no_derivatives); + } + catch (FloatingPointException &e) + { + res1 = numeric_limits<double>::quiet_NaN(); + if (verbosity >= 2) + mexPrintf("%s\n %s\n", e.message.c_str(), e.location.c_str()); + } +} + bool dynSparseMatrix::compute_complete(bool no_derivatives, double &_res1, double &_res2, double &_max_res, int &_max_res_idx) { @@ -1901,7 +1893,8 @@ dynSparseMatrix::compute_complete(double lambda, double *crit) } it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state } - mexPrintf(" lambda=%e, res2=%e\n", lambda, res2_); + if (verbosity >= 2) + mexPrintf(" lambda=%e, res2=%e\n", lambda, res2_); *crit = res2_/2; return true; } @@ -1915,7 +1908,8 @@ dynSparseMatrix::mnbrak(double *ax, double *bx, double *cx, double *fa, double * auto sign = [](double a, double b) { return b >= 0.0 ? fabs(a) : -fabs(a); }; - mexPrintf("bracketing *ax=%f, *bx=%f\n", *ax, *bx); + if (verbosity >= 2) + mexPrintf("bracketing *ax=%f, *bx=%f\n", *ax, *bx); if (!compute_complete(*ax, fa)) return false; if (!compute_complete(*bx, fb)) @@ -2000,7 +1994,8 @@ dynSparseMatrix::golden(double ax, double bx, double cx, double tol, double solv { const double R = 0.61803399; const double C = (1.0-R); - mexPrintf("golden\n"); + if (verbosity >= 2) + mexPrintf("golden\n"); int iter = 0, max_iter = 100; double f1, f2, x1, x2; double x0 = ax; @@ -2309,42 +2304,19 @@ dynSparseMatrix::Solve_Matlab_Relaxation(mxArray *A_m, mxArray *b_m, unsigned in mxDestroyArray(d1); } -void -dynSparseMatrix::Solve_Matlab_LU_UMFPack(mxArray *A_m, mxArray *b_m, int Size, double slowc_l, bool is_two_boundaries, int it_) -{ - size_t n = mxGetM(A_m); - mxArray *z; - mxArray *rhs[] = { A_m, b_m }; - mexCallMATLAB(1, &z, std::extent_v<decltype(rhs)>, rhs, "mldivide"); - double *res = mxGetPr(z); - if (is_two_boundaries) - for (int i = 0; i < static_cast<int>(n); i++) - { - int eq = index_vara[i+Size*y_kmin]; - double yy = -(res[i] + y[eq]); - direction[eq] = yy; - y[eq] += slowc_l * yy; - } - else - for (int i = 0; i < static_cast<int>(n); i++) - { - int eq = index_vara[i]; - double yy = -(res[i] + y[eq+it_*y_size]); - direction[eq] = yy; - y[eq+it_*y_size] += slowc_l * yy; - } - mxDestroyArray(A_m); - mxDestroyArray(b_m); - mxDestroyArray(z); -} - void dynSparseMatrix::End_Matlab_LU_UMFPack() { if (Symbolic) - umfpack_dl_free_symbolic(&Symbolic); + { + umfpack_dl_free_symbolic(&Symbolic); + Symbolic = nullptr; + } if (Numeric) - umfpack_dl_free_numeric(&Numeric); + { + umfpack_dl_free_numeric(&Numeric); + Numeric = nullptr; + } } void @@ -2389,22 +2361,23 @@ dynSparseMatrix::Solve_LU_UMFPack(SuiteSparse_long *Ap, SuiteSparse_long *Ai, do double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO], res[n]; umfpack_dl_defaults(Control); - Control[UMFPACK_PRL] = 5; SuiteSparse_long status = 0; if (iter == 0) { + if (Symbolic) + umfpack_dl_free_symbolic(&Symbolic); status = umfpack_dl_symbolic(n, n, Ap, Ai, Ax, &Symbolic, Control, Info); - if (status < 0) + if (status != UMFPACK_OK) { umfpack_dl_report_info(Control, Info); umfpack_dl_report_status(Control, status); throw FatalException{"umfpack_dl_symbolic failed"}; } } - if (iter > 0) + if (Numeric) umfpack_dl_free_numeric(&Numeric); status = umfpack_dl_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info); - if (status < 0) + if (status != UMFPACK_OK) { umfpack_dl_report_info(Control, Info); umfpack_dl_report_status(Control, status); @@ -2496,22 +2469,23 @@ dynSparseMatrix::Solve_LU_UMFPack(SuiteSparse_long *Ap, SuiteSparse_long *Ai, do double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO], res[n]; umfpack_dl_defaults(Control); - Control[UMFPACK_PRL] = 5; SuiteSparse_long status = 0; if (iter == 0) { + if (Symbolic) + umfpack_dl_free_symbolic(&Symbolic); status = umfpack_dl_symbolic(n, n, Ap, Ai, Ax, &Symbolic, Control, Info); - if (status < 0) + if (status != UMFPACK_OK) { umfpack_dl_report_info(Control, Info); umfpack_dl_report_status(Control, status); throw FatalException{"umfpack_dl_symbolic failed"}; } } - if (iter > 0) + if (Numeric) umfpack_dl_free_numeric(&Numeric); status = umfpack_dl_numeric(Ap, Ai, Ax, Symbolic, &Numeric, Control, Info); - if (status < 0) + if (status != UMFPACK_OK) { umfpack_dl_report_info(Control, Info); umfpack_dl_report_status(Control, status); @@ -2611,6 +2585,7 @@ dynSparseMatrix::Solve_Matlab_GMRES(mxArray *A_m, mxArray *b_m, int Size, double } mxDestroyArray(A_m); mxDestroyArray(b_m); + mxDestroyArray(x0_m); mxDestroyArray(z); mxDestroyArray(flag); } @@ -2770,6 +2745,7 @@ dynSparseMatrix::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, int Size, dou } mxDestroyArray(A_m); mxDestroyArray(b_m); + mxDestroyArray(x0_m); mxDestroyArray(z); } @@ -2916,10 +2892,13 @@ dynSparseMatrix::Solve_ByteCode_Sparse_GaussianElimination(int Size, int blck, i mxFree(bc); if (steady_state) { - if (blck > 1) - mexPrintf("Error: singular system in Simulate_NG in block %d\n", blck+1); - else - mexPrintf("Error: singular system in Simulate_NG"); + if (verbosity >= 1) + { + if (blck > 1) + mexPrintf("Error: singular system in Simulate_NG in block %d\n", blck+1); + else + mexPrintf("Error: singular system in Simulate_NG"); + } return true; } else @@ -3243,9 +3222,9 @@ dynSparseMatrix::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(int Size, bo NR_max = NR[j]; } } - if (fabs(piv) < eps) + if (fabs(piv) < eps && verbosity >= 1) mexPrintf("==> Error NR_max=%d, N_max=%d and piv=%f, piv_abs=%f, markovitz_max=%f\n", NR_max, N_max, piv, piv_abs, markovitz_max); - if (NR_max == 0) + if (NR_max == 0 && verbosity >= 1) mexPrintf("==> Error NR_max=0 and piv=%f, markovitz_max=%f\n", piv, markovitz_max); pivot[i] = pivj; pivot_save[i] = pivj; @@ -3702,7 +3681,8 @@ dynSparseMatrix::Check_and_Correct_Previous_Iteration(int y_size, int size) } compute_complete(true, res1, res2, max_res, max_res_idx); } - mexPrintf("Error: Simulation diverging, trying to correct it using slowc=%f\n", slowc_save); + if (verbosity >= 2) + mexPrintf("Error: Simulation diverging, trying to correct it using slowc=%f\n", slowc_save); for (int i = 0; i < size; i++) { int eq = index_vara[i]; @@ -3752,11 +3732,14 @@ dynSparseMatrix::Simulate_One_Boundary(int block_num, int y_size, int size) #endif if (steady_state) { - if (iter == 0) - mexPrintf(" the initial values of endogenous variables are too far from the solution.\nChange them!\n"); - else - mexPrintf(" dynare cannot improve the simulation in block %d at time %d (variable %d)\n", block_num+1, it_+1, index_vara[max_res_idx]+1); - mexEvalString("drawnow;"); + if (verbosity >= 1) + { + if (iter == 0) + mexPrintf(" the initial values of endogenous variables are too far from the solution.\nChange them!\n"); + else + mexPrintf(" dynare cannot improve the simulation in block %d at time %d (variable %d)\n", block_num+1, it_+1, index_vara[max_res_idx]+1); + mexEvalString("drawnow;"); + } } else { @@ -3769,17 +3752,17 @@ dynSparseMatrix::Simulate_One_Boundary(int block_num, int y_size, int size) } } - if (print_it) + if (verbosity >= 1) { if (steady_state) { switch (solve_algo) { case 5: - mexPrintf("MODEL STEADY STATE: (method=ByteCode own solver)\n"); + mexPrintf("MODEL STEADY STATE: (method=Sparse Gaussian Elimination)\n"); break; case 6: - mexPrintf("MODEL STEADY STATE: Sparse LU\n"); + mexPrintf("MODEL STEADY STATE: (method=Sparse LU)\n"); break; case 7: mexPrintf(preconditioner_print_out("MODEL STEADY STATE: (method=GMRES)\n", preconditioner, true).c_str()); @@ -3790,12 +3773,12 @@ dynSparseMatrix::Simulate_One_Boundary(int block_num, int y_size, int size) } } - mexPrintf("-----------------------------------\n"); - mexPrintf(" Simulate iteration no %d \n", iter+1); - mexPrintf(" max. error=%.10e \n", static_cast<double>(max_res)); - mexPrintf(" sqr. error=%.10e \n", static_cast<double>(res2)); - mexPrintf(" abs. error=%.10e \n", static_cast<double>(res1)); - mexPrintf("-----------------------------------\n"); + mexPrintf("------------------------------------\n"); + mexPrintf(" Iteration no. %d\n", iter+1); + mexPrintf(" Inf-norm error = %.3e\n", static_cast<double>(max_res)); + mexPrintf(" 2-norm error = %.3e\n", static_cast<double>(sqrt(res2))); + mexPrintf(" 1-norm error = %.3e\n", static_cast<double>(res1)); + mexPrintf("------------------------------------\n"); } bool zero_solution; @@ -3803,12 +3786,6 @@ dynSparseMatrix::Simulate_One_Boundary(int block_num, int y_size, int size) Simple_Init(size, IM_i, zero_solution); else { - b_m = mxCreateDoubleMatrix(size, 1, mxREAL); - if (!b_m) - throw FatalException{"In Simulate_One_Boundary, can't allocate b_m vector"}; - A_m = mxCreateSparse(size, size, min(static_cast<int>(IM_i.size()*2), size * size), mxREAL); - if (!A_m) - throw FatalException{"In Simulate_One_Boundary, can't allocate A_m matrix"}; x0_m = mxCreateDoubleMatrix(size, 1, mxREAL); if (!x0_m) throw FatalException{"In Simulate_One_Boundary, can't allocate x0_m vector"}; @@ -3816,6 +3793,12 @@ dynSparseMatrix::Simulate_One_Boundary(int block_num, int y_size, int size) || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4 || stack_solve_algo == 6) && !steady_state))) { + b_m = mxCreateDoubleMatrix(size, 1, mxREAL); + if (!b_m) + throw FatalException{"In Simulate_One_Boundary, can't allocate b_m vector"}; + A_m = mxCreateSparse(size, size, min(static_cast<int>(IM_i.size()*2), size * size), mxREAL); + if (!A_m) + throw FatalException{"In Simulate_One_Boundary, can't allocate A_m matrix"}; Init_Matlab_Sparse_Simple(size, IM_i, A_m, b_m, zero_solution, x0_m); A_m_save = mxDuplicateArray(A_m); b_m_save = mxDuplicateArray(b_m); @@ -3855,7 +3838,10 @@ dynSparseMatrix::Simulate_One_Boundary(int block_num, int y_size, int size) else if ((solve_algo == 8 && steady_state) || (stack_solve_algo == 3 && !steady_state)) Solve_Matlab_BiCGStab(A_m, b_m, size, slowc, block_num, false, it_, x0_m, preconditioner); else if ((solve_algo == 6 && steady_state) || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4 || stack_solve_algo == 6) && !steady_state)) - Solve_LU_UMFPack(Ap, Ai, Ax, b, size, size, slowc, false, it_); + { + Solve_LU_UMFPack(Ap, Ai, Ax, b, size, size, slowc, false, it_); + mxDestroyArray(x0_m); + } } return singular_system; } @@ -3871,7 +3857,7 @@ dynSparseMatrix::solve_linear(int block_num, int y_size, int size, int iter) if (iter) Check_and_Correct_Previous_Iteration(y_size, size); bool singular_system = Simulate_One_Boundary(block_num, y_size, size); - if (singular_system) + if (singular_system && verbosity >= 1) Singular_display(block_num, size); } return cvg; @@ -4001,26 +3987,18 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin if (start_compare == 0) start_compare = y_kmin; u_count_alloc_save = u_count_alloc; - clock_t t1 = clock(); + auto t1 { chrono::high_resolution_clock::now() }; nop1 = 0; mxArray *b_m = nullptr, *A_m = nullptr, *x0_m = nullptr; double *Ax = nullptr, *b; SuiteSparse_long *Ap = nullptr, *Ai = nullptr; - if (iter > 0) - { - if (print_it) - { - mexPrintf("Sim : %f ms\n", (1000.0*(static_cast<double>(clock())-static_cast<double>(time00)))/static_cast<double>(CLOCKS_PER_SEC)); - mexEvalString("drawnow;"); - } - time00 = clock(); - } if (isnan(res1) || isinf(res1) || (res2 > 12*g0 && iter > 0)) { if (iter == 0 || fabs(slowc_save) < 1e-8) { - mexPrintf("res1 = %f, res2 = %f g0 = %f iter = %d\n", res1, res2, g0, iter); + if (verbosity >= 2) + mexPrintf("res1 = %f, res2 = %f g0 = %f iter = %d\n", res1, res2, g0, iter); for (int j = 0; j < y_size; j++) { bool select = false; @@ -4030,10 +4008,13 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin select = true; break; } - if (select) - mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n", symbol_table.getName(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]); - else - mexPrintf(" variable %s (%d) at time %d = %f direction = %f\n", symbol_table.getName(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]); + if (verbosity >= 2) + { + if (select) + mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n", symbol_table.getName(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]); + else + mexPrintf(" variable %s (%d) at time %d = %f direction = %f\n", symbol_table.getName(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]); + } } if (iter == 0) throw FatalException{"In Simulate_Newton_Two_Boundaries, the initial values of endogenous variables are too far from the solution. Change them!"}; @@ -4083,7 +4064,7 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin prev_slowc_save = slowc_save; slowc_save /= 1.05; } - if (print_it) + if (verbosity >= 2) { if (isnan(res1) || isinf(res1)) mexPrintf("The model cannot be evaluated, trying to correct it using slowc=%f\n", slowc_save); @@ -4100,7 +4081,8 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin { if (alt_symbolic && alt_symbolic_count < alt_symbolic_count_max) { - mexPrintf("Pivoting method will be applied only to the first periods.\n"); + if (verbosity >= 2) + mexPrintf("Pivoting method will be applied only to the first periods.\n"); alt_symbolic = false; symbolic = true; markowitz_c = markowitz_c_s; @@ -4110,7 +4092,8 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin { if (restart > 2) { - mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next iteration, pivoting method will be applied to all periods.\n"); + if (verbosity >= 2) + mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next iteration, pivoting method will be applied to all periods.\n"); symbolic = false; alt_symbolic = true; markowitz_c_s = markowitz_c; @@ -4118,7 +4101,8 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin } else { - mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next iteration, pivoting method will be applied for a longer period.\n"); + if (verbosity >= 2) + mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next iteration, pivoting method will be applied for a longer period.\n"); start_compare = min(tbreak_g, periods); restart++; } @@ -4130,7 +4114,7 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin } } res1a = res1; - if (print_it) + if (verbosity >= 1) { if (iter == 0) { @@ -4153,16 +4137,16 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin mexPrintf("MODEL SIMULATION: (method=Sparse LU & optimal path length)\n"); break; case 5: - mexPrintf("MODEL SIMULATION: (method=ByteCode own solver)\n"); + mexPrintf("MODEL SIMULATION: (method=Sparse Gaussian Elimination)\n"); break; } } - mexPrintf("-----------------------------------\n"); - mexPrintf(" Simulate iteration no %d \n", iter+1); - mexPrintf(" max. error=%.10e \n", static_cast<double>(max_res)); - mexPrintf(" sqr. error=%.10e \n", static_cast<double>(res2)); - mexPrintf(" abs. error=%.10e \n", static_cast<double>(res1)); - mexPrintf("-----------------------------------\n"); + mexPrintf("------------------------------------\n"); + mexPrintf(" Iteration no. %d\n", iter+1); + mexPrintf(" Inf-norm error = %.3e\n", static_cast<double>(max_res)); + mexPrintf(" 2-norm error = %.3e\n", static_cast<double>(sqrt(res2))); + mexPrintf(" 1-norm error = %.3e\n", static_cast<double>(res1)); + mexPrintf("------------------------------------\n"); mexEvalString("drawnow;"); } if (cvg) @@ -4173,28 +4157,35 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin Init_GE(periods, y_kmin, y_kmax, Size, IM_i); else { - b_m = mxCreateDoubleMatrix(periods*Size, 1, mxREAL); - if (!b_m) - throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate b_m vector"}; x0_m = mxCreateDoubleMatrix(periods*Size, 1, mxREAL); if (!x0_m) throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate x0_m vector"}; - if (stack_solve_algo != 0 && stack_solve_algo != 4) - { - A_m = mxCreateSparse(periods*Size, periods*Size, IM_i.size()* periods*2, mxREAL); - if (!A_m) - throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate A_m matrix"}; - } if (stack_solve_algo == 0 || stack_solve_algo == 4) Init_UMFPACK_Sparse(periods, y_kmin, y_kmax, Size, IM_i, &Ap, &Ai, &Ax, &b, x0_m, vector_table_conditional_local, blck); else - Init_Matlab_Sparse(periods, y_kmin, y_kmax, Size, IM_i, A_m, b_m, x0_m); - + { + b_m = mxCreateDoubleMatrix(periods*Size, 1, mxREAL); + if (!b_m) + throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate b_m vector"}; + if (stack_solve_algo != 0 && stack_solve_algo != 4) + { + A_m = mxCreateSparse(periods*Size, periods*Size, IM_i.size()* periods*2, mxREAL); + if (!A_m) + throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate A_m matrix"}; + } + Init_Matlab_Sparse(periods, y_kmin, y_kmax, Size, IM_i, A_m, b_m, x0_m); + } } if (stack_solve_algo == 0 || stack_solve_algo == 4) - Solve_LU_UMFPack(Ap, Ai, Ax, b, Size * periods, Size, slowc, true, 0, vector_table_conditional_local); + { + Solve_LU_UMFPack(Ap, Ai, Ax, b, Size * periods, Size, slowc, true, 0, vector_table_conditional_local); + mxDestroyArray(x0_m); + } else if (stack_solve_algo == 1 || stack_solve_algo == 6) - Solve_Matlab_Relaxation(A_m, b_m, Size, slowc); + { + Solve_Matlab_Relaxation(A_m, b_m, Size, slowc); + mxDestroyArray(x0_m); + } else if (stack_solve_algo == 2) Solve_Matlab_GMRES(A_m, b_m, Size, slowc, blck, true, 0, x0_m); else if (stack_solve_algo == 3) @@ -4202,15 +4193,15 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin else if (stack_solve_algo == 5) Solve_ByteCode_Symbolic_Sparse_GaussianElimination(Size, symbolic, blck); } - if (print_it) + using FloatSeconds = chrono::duration<double, chrono::seconds::period>; + auto t2 { chrono::high_resolution_clock::now() }; + if (verbosity >= 1) { - clock_t t2 = clock(); - mexPrintf("(** %f milliseconds **)\n", 1000.0*(static_cast<double>(t2) - static_cast<double>(t1))/static_cast<double>(CLOCKS_PER_SEC)); + mexPrintf("(** %.2f seconds **)\n", FloatSeconds{t2 - t1}.count()); mexEvalString("drawnow;"); } if (!steady_state && stack_solve_algo == 4) { - clock_t t2 = clock(); double ax = -0.1, bx = 1.1, cx = 0.5, fa, fb, fc, xmin; if (!mnbrak(&ax, &bx, &cx, &fa, &fb, &fc)) @@ -4218,11 +4209,13 @@ dynSparseMatrix::Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin if (!golden(ax, bx, cx, 1e-1, solve_tolf, &xmin)) return; slowc = xmin; - clock_t t3 = clock(); - mexPrintf("(** %f milliseconds **)\n", 1000.0*(static_cast<double>(t3) - static_cast<double>(t2))/static_cast<double>(CLOCKS_PER_SEC)); - mexEvalString("drawnow;"); + if (verbosity >= 1) + { + auto t3 { chrono::high_resolution_clock::now() }; + mexPrintf("(** %.2f seconds **)\n", FloatSeconds{t3 - t2}.count()); + mexEvalString("drawnow;"); + } } - time00 = clock(); if (tbreak_g == 0) tbreak_g = periods; } diff --git a/mex/sources/bytecode/SparseMatrix.hh b/mex/sources/bytecode/SparseMatrix.hh index e8eb2013fe46eab93edb596c1f719caa8959324e..52a56fab964bda28785ae3f7e54ec0a51b4ccc3b 100644 --- a/mex/sources/bytecode/SparseMatrix.hh +++ b/mex/sources/bytecode/SparseMatrix.hh @@ -27,7 +27,6 @@ #include <stack> #include <fstream> #include <string> -#include <ctime> #include "dynumfpack.h" #include "dynmex.h" @@ -65,10 +64,10 @@ constexpr double eps = 1e-15, very_big = 1e24; constexpr int alt_symbolic_count_max = 1; constexpr double mem_increasing_factor = 1.1; -class dynSparseMatrix : public Evaluate +class dynSparseMatrix { public: - dynSparseMatrix(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool print_it_arg, bool steady_state_arg, bool block_decomposed_arg, int periods_arg, int minimal_solving_periods_arg, BasicSymbolTable &symbol_table_arg); + dynSparseMatrix(Evaluate &evaluator_arg, int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool steady_state_arg, bool block_decomposed_arg, int periods_arg, int minimal_solving_periods_arg, const BasicSymbolTable &symbol_table_arg, int verbosity_arg); void Simulate_Newton_Two_Boundaries(int blck, int y_size, int y_kmin, int y_kmax, int Size, int periods, bool cvg, int minimal_solving_periods, int stack_solve_algo, const vector_table_conditional_local_type &vector_table_conditional_local); void Simulate_Newton_One_Boundary(bool forward); void fixe_u(double **u, int u_count_int, int max_lag_plus_max_lead_plus_1); @@ -94,7 +93,6 @@ private: void Solve_ByteCode_Symbolic_Sparse_GaussianElimination(int Size, bool symbolic, int Block_number); bool Solve_ByteCode_Sparse_GaussianElimination(int Size, int blck, int it_); void Solve_Matlab_Relaxation(mxArray *A_m, mxArray *b_m, unsigned int Size, double slowc_l); - void Solve_Matlab_LU_UMFPack(mxArray *A_m, mxArray *b_m, int Size, double slowc_l, bool is_two_boundaries, int it_); static void Print_UMFPack(const SuiteSparse_long *Ap, const SuiteSparse_long *Ai, const double *Ax, int n); static void Printfull_UMFPack(const SuiteSparse_long *Ap, const SuiteSparse_long *Ai, const double *Ax, const double *b, int n); static void PrintM(int n, const double *Ax, const mwIndex *Ap, const mwIndex *Ai); @@ -124,8 +122,7 @@ private: void Delete_u(int pos); void Clear_u(); void Print_u() const; - void *Symbolic, *Numeric; - void Check_the_Solution(int periods, int y_kmin, int y_kmax, int Size, double *u, int *pivot, int *b); + void *Symbolic {nullptr}, *Numeric {nullptr}; int complete(int beg_t, int Size, int periods, int *b); void bksub(int tbreak, int last_period, int Size, double slowc_l); void simple_bksub(int it_, int Size, double slowc_l); @@ -142,9 +139,14 @@ private: // Computes A−B where A and B are dense. The result is dense. static mxArray *subtract_A_B(const mxArray *A_m, const mxArray *B_m); protected: + const BasicSymbolTable &symbol_table; + const bool steady_state; // Whether this is a static or dynamic model + // Whether to use the block-decomposed version of the bytecode file bool block_decomposed; + Evaluate &evaluator; + stack<double> Stack; int nb_prologue_table_u, nb_first_table_u, nb_middle_table_u, nb_last_table_u; int nb_prologue_table_y, nb_first_table_y, nb_middle_table_y, nb_last_table_y; @@ -152,7 +154,6 @@ protected: fstream SaveCode; string filename; int max_u, min_u; - clock_t time00; Mem_Mngr mem_mngr; vector<int> u_liste; @@ -174,7 +175,6 @@ protected: double res1a; long int nop_all, nop1, nop2; map<tuple<int, int, int>, int> IM_i; - vector<double> residual; int u_count_alloc, u_count_alloc_save; vector<double *> jac; double *jcb; @@ -194,15 +194,42 @@ protected: int stack_solve_algo, solve_algo; int minimal_solving_periods; - bool print_it; int Per_u_, Per_y_; int maxit_; double *direction; double solve_tolf; - double res2, max_res; + // 1-norm error, square of 2-norm error, ∞-norm error + double res1, res2, max_res; int max_res_idx; int *index_vara; + double *y, *ya; + int y_size; + double *T; + int nb_row_x; + int y_kmin, y_kmax, periods; + double *x, *params; + double *u; + double *steady_y; + double *g1, *r, *res; + vector<mxArray *> jacobian_block, jacobian_exo_block, jacobian_det_exo_block; + mxArray *GlobalTemporaryTerms; + int it_; + map<int, double> TEF; + map<pair<int, int>, double> TEFD; + map<tuple<int, int, int>, double> TEFDD; + + // Information about the current block + int block_num; // Index of the current block + int size; // Size of the current block + BlockSimulationType type; + bool is_linear; + int u_count_int; + vector<Block_contain_type> Block_Contain; + + int verbosity; // Corresponds to options_.verbosity + + void compute_block_time(int Per_u_, bool evaluate, bool no_derivatives); bool compute_complete(bool no_derivatives, double &res1, double &res2, double &max_res, int &max_res_idx); bool compute_complete(double lambda, double *crit); diff --git a/mex/sources/bytecode/bytecode.cc b/mex/sources/bytecode/bytecode.cc index 71e24f2239209737bd89175cd1120ec1e5a10fbd..9620ef8a8c3c456c01ba6593e81600528f27c299 100644 --- a/mex/sources/bytecode/bytecode.cc +++ b/mex/sources/bytecode/bytecode.cc @@ -17,10 +17,9 @@ * along with Dynare. If not, see <https://www.gnu.org/licenses/>. */ -#include <ctime> #include <cmath> -#include <cstring> #include <type_traits> +#include <algorithm> #include "Interpreter.hh" #include "ErrorHandling.hh" @@ -63,7 +62,6 @@ Get_Arguments_and_global_variables(int nrhs, bool &evaluate, int &block, mxArray *M_[], mxArray *oo_[], mxArray *options_[], bool &global_temporary_terms, bool &print, - bool &print_error, mxArray *GlobalTemporaryTerms[], string *plan_struct_name, string *pfplan_struct_name, bool *extended_path, mxArray *ep_struct[]) { @@ -126,8 +124,6 @@ Get_Arguments_and_global_variables(int nrhs, global_temporary_terms = true; else if (Get_Argument(prhs[i]) == "print") print = true; - else if (Get_Argument(prhs[i]) == "no_print_error") - print_error = false; else { pos = 0; @@ -178,7 +174,7 @@ Get_Arguments_and_global_variables(int nrhs, if (count_array_argument == 3 && steady_state) periods = 1; else - throw FatalException{"In main, missing arguments. All the following arguments have to be indicated y, x, params, it_, ys"}; + throw FatalException{"In main, missing arguments. All the following arguments have to be indicated y, x, params, ys, periods"}; } *M_ = mexGetVariable("global", "M_"); if (!*M_) @@ -215,7 +211,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) double *yd = nullptr, *xd = nullptr; int count_array_argument = 0; bool global_temporary_terms = false; - bool print = false, print_error = true, print_it = false; + bool print = false; // Whether the “print” command is requested + int verbosity {1}; // Corresponds to options_.verbosity double *steady_yd = nullptr; string plan, pfplan; bool extended_path; @@ -244,7 +241,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) &block_structur, steady_state, block_decomposed, evaluate, block, &M_, &oo_, &options_, global_temporary_terms, - print, print_error, &GlobalTemporaryTerms, + print, &GlobalTemporaryTerms, &plan, &pfplan, &extended_path, &extended_path_struct); } catch (GeneralException &feh) @@ -449,19 +446,20 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) splan[i].per_value[j] = { ceil(per_value[j]), per_value[j + num_shocks] }; } } - int i = 0; - for (auto & it : splan) - { - mexPrintf("----------------------------------------------------------------------------------------------------\n"); - mexPrintf("surprise #%d\n", i+1); - if (it.exo.length()) - mexPrintf(" plan fliping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num, it.exo.c_str(), it.exo_num); - else - mexPrintf(" plan shocks on var=%s for the following periods and with the following values:\n", it.var.c_str()); - for (auto &[period, value]: it.per_value) - mexPrintf(" %3d %10.5f\n", period, value); - i++; - } + if (verbosity >= 1) + for (int i {0}; + auto & it : splan) + { + mexPrintf("----------------------------------------------------------------------------------------------------\n"); + mexPrintf("surprise #%d\n", i+1); + if (it.exo.length()) + mexPrintf(" plan fliping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num, it.exo.c_str(), it.exo_num); + else + mexPrintf(" plan shocks on var=%s for the following periods and with the following values:\n", it.var.c_str()); + for (auto &[period, value]: it.per_value) + mexPrintf(" %3d %10.5f\n", period, value); + i++; + } } if (pfplan.length() > 0) @@ -509,19 +507,20 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) spfplan[i].per_value[j] = { ceil(per_value[j]), per_value[j+ num_shocks] }; } } - int i = 0; - for (auto & it : spfplan) - { - mexPrintf("----------------------------------------------------------------------------------------------------\n"); - mexPrintf("perfect foresight #%d\n", i+1); - if (it.exo.length()) - mexPrintf(" plan flipping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num, it.exo.c_str(), it.exo_num); - else - mexPrintf(" plan shocks on var=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num); - for (auto &[period, value] : it.per_value) - mexPrintf(" %3d %10.5f\n", period, value); - i++; - } + if (verbosity >= 1) + for (int i {0}; + auto & it : spfplan) + { + mexPrintf("----------------------------------------------------------------------------------------------------\n"); + mexPrintf("perfect foresight #%d\n", i+1); + if (it.exo.length()) + mexPrintf(" plan flipping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num, it.exo.c_str(), it.exo_num); + else + mexPrintf(" plan shocks on var=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num); + for (auto &[period, value] : it.per_value) + mexPrintf(" %3d %10.5f\n", period, value); + i++; + } } int field_steady_state = mxGetFieldNumber(oo_, "steady_state"); @@ -601,13 +600,11 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) } } int field = mxGetFieldNumber(options_, "verbosity"); - int verbose = 0; if (field >= 0) - verbose = static_cast<int>(*mxGetPr((mxGetFieldByNumber(options_, 0, field)))); + verbosity = static_cast<int>(mxGetScalar(mxGetFieldByNumber(options_, 0, field))); else mexErrMsgTxt("verbosity is not a field of options_"); - if (verbose) - print_it = true; + if (!steady_state) field = mxGetFieldNumber(options_, "simul"); else @@ -702,97 +699,56 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) test_mxMalloc(ya, __LINE__, __FILE__, __func__, size_of_direction); direction = static_cast<double *>(mxMalloc(size_of_direction)); test_mxMalloc(direction, __LINE__, __FILE__, __func__, size_of_direction); - memset(direction, 0, size_of_direction); auto *x = static_cast<double *>(mxMalloc(col_x*row_x*sizeof(double))); test_mxMalloc(x, __LINE__, __FILE__, __func__, col_x*row_x*sizeof(double)); - for (i = 0; i < row_x*col_x; i++) - x[i] = static_cast<double>(xd[i]); - for (i = 0; i < row_y*col_y; i++) - { - y[i] = static_cast<double>(yd[i]); - ya[i] = static_cast<double>(yd[i]); - } - size_t y_size = row_y; - size_t nb_row_x = row_x; - clock_t t0 = clock(); - Interpreter interprete {params, y, ya, x, steady_yd, direction, y_size, nb_row_x, - periods, y_kmin, y_kmax, maxit_, solve_tolf, size_of_direction, y_decal, + fill_n(direction, row_y*col_y, 0); + copy_n(xd, row_x*col_x, x); + copy_n(yd, row_y*col_y, y); + copy_n(yd, row_y*col_y, ya); + + const filesystem::path codfile {file_name + "/model/bytecode/" + (block_decomposed ? "block/" : "") + + (steady_state ? "static" : "dynamic") + ".cod"}; + Evaluate evaluator {codfile, steady_state, symbol_table}; + + Interpreter interprete {evaluator, params, y, ya, x, steady_yd, direction, row_y, row_x, + periods, y_kmin, y_kmax, maxit_, solve_tolf, y_decal, markowitz_c, file_name, minimal_solving_periods, stack_solve_algo, - solve_algo, global_temporary_terms, print, print_error, GlobalTemporaryTerms, - steady_state, block_decomposed, print_it, col_x, col_y, symbol_table}; + solve_algo, global_temporary_terms, print, GlobalTemporaryTerms, + steady_state, block_decomposed, col_x, col_y, symbol_table, verbosity}; double *pind; bool r; vector<int> blocks; - if (extended_path) + try { - try - { - tie(r, blocks) = interprete.extended_path(file_name, evaluate, block, max_periods, sextended_path, sconditional_extended_path, dates, table_conditional_global); - } - catch (GeneralException &feh) - { - // Release the lock on dynamic.bin for MATLAB+Windows, see #1815 - interprete.Close_SaveCode(); - mexErrMsgTxt(feh.message.c_str()); - } + if (extended_path) + tie(r, blocks) = interprete.extended_path(file_name, evaluate, block, max_periods, sextended_path, sconditional_extended_path, dates, table_conditional_global); + else + tie(r, blocks) = interprete.compute_blocks(file_name, evaluate, block); } - else + catch (GeneralException &feh) { - try - { - tie(r, blocks) = interprete.compute_blocks(file_name, evaluate, block); - } - catch (GeneralException &feh) - { - // Release the lock on dynamic.bin for MATLAB+Windows, see #1815 - interprete.Close_SaveCode(); - mexErrMsgTxt(feh.message.c_str()); - } + // Release the lock on dynamic.bin for MATLAB+Windows, see #1815 + interprete.Close_SaveCode(); + mexErrMsgTxt(feh.message.c_str()); } - clock_t t1 = clock(); - if (!steady_state && !evaluate && print) - mexPrintf("Simulation Time=%f milliseconds\n", - 1000.0*(static_cast<double>(t1)-static_cast<double>(t0))/static_cast<double>(CLOCKS_PER_SEC)); bool dont_store_a_structure = false; if (nlhs > 0) { - if (block >= 0) + if (evaluate) { - if (evaluate) - { - vector<double> residual = interprete.get_residual(); - plhs[0] = mxCreateDoubleMatrix(static_cast<int>(residual.size()/static_cast<double>(col_y)), - static_cast<int>(col_y), mxREAL); - pind = mxGetPr(plhs[0]); - for (i = 0; i < residual.size(); i++) - pind[i] = residual[i]; - } - else - { - int out_periods = extended_path ? max_periods + y_kmin : row_y; - plhs[0] = mxCreateDoubleMatrix(out_periods, static_cast<int>(col_y), mxREAL); - pind = mxGetPr(plhs[0]); - for (i = 0; i < out_periods*col_y; i++) - pind[i] = y[i]; - } + vector<double> residual = interprete.get_residual(); + plhs[0] = mxCreateDoubleMatrix(static_cast<int>(residual.size()/periods), + static_cast<int>(periods), mxREAL); + std::copy(residual.begin(), residual.end(), mxGetPr(plhs[0])); } else { int out_periods = extended_path ? max_periods + y_kmin : col_y; plhs[0] = mxCreateDoubleMatrix(static_cast<int>(row_y), out_periods, mxREAL); - pind = mxGetPr(plhs[0]); - if (evaluate) - { - vector<double> residual = interprete.get_residual(); - for (i = 0; i < residual.size(); i++) - pind[i] = residual[i]; - } - else - for (i = 0; i < row_y*out_periods; i++) - pind[i] = y[i]; + std::copy_n(y, row_y*out_periods, mxGetPr(plhs[0])); } if (nlhs > 1) { diff --git a/mex/sources/cycle_reduction/mexFunction.f08 b/mex/sources/cycle_reduction/mexFunction.f08 index cf39944f19aeb94a10c4d22be7eb4ef17e688a7c..6f569c8da9ef4f90dbb1eef29ebc30b0f75305cb 100644 --- a/mex/sources/cycle_reduction/mexFunction.f08 +++ b/mex/sources/cycle_reduction/mexFunction.f08 @@ -1,4 +1,4 @@ -! Copyright © 2022 Dynare Team +! Copyright © 2022-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -22,7 +22,7 @@ module c_reduction use lapack use blas use matlab_mex - implicit none + implicit none (type, external) contains @@ -111,7 +111,7 @@ end module c_reduction subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use c_reduction - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs @@ -191,4 +191,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') end if end if -end subroutine mexFunction \ No newline at end of file +end subroutine mexFunction diff --git a/mex/sources/disclyap_fast/disclyap_fast.f08 b/mex/sources/disclyap_fast/disclyap_fast.f08 index bc96f6300dc71d6b2d93010ea721b8810078518c..85cc51c49a01a11e81bcda0d918594bf70d64318 100644 --- a/mex/sources/disclyap_fast/disclyap_fast.f08 +++ b/mex/sources/disclyap_fast/disclyap_fast.f08 @@ -20,7 +20,7 @@ ! This is a Fortran translation of a code originally written by Joe Pearlman ! and Alejandro Justiniano. -! Copyright © 2020-2022 Dynare Team +! Copyright © 2020-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -42,7 +42,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use ieee_arithmetic use matlab_mex use lapack - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs diff --git a/mex/sources/dynblas.h b/mex/sources/dynblas.h index be0586b061b45a9545c967e62df6f9f1840c3057..57e0d3432da15dba8ffc3d6abc5f5f3d40e7b76d 100644 --- a/mex/sources/dynblas.h +++ b/mex/sources/dynblas.h @@ -8,7 +8,7 @@ * and MATLAB_VERSION (for version 7.4, define it to 0x0704). * * - * Copyright © 2009-2020 Dynare Team + * Copyright © 2009-2023 Dynare Team * * This file is part of Dynare. * @@ -29,18 +29,18 @@ #ifndef _DYNBLAS_H #define _DYNBLAS_H -#if defined(MATLAB_MEX_FILE) +#if defined(MATLAB_MEX_FILE) && __SIZEOF_POINTER__ == 8 # ifdef __cplusplus -# include <cstddef> +# include <cstdint> # else -# include <stddef.h> +# include <stdint.h> # endif -typedef ptrdiff_t blas_int; +typedef int64_t blas_int; #else typedef int blas_int; #endif -#if defined(MATLAB_MEX_FILE) && defined(_WIN32) && !defined(_MSC_VER) +#if defined(MATLAB_MEX_FILE) && defined(_WIN32) # define FORTRAN_WRAPPER(x) x #else # define FORTRAN_WRAPPER(x) x ## _ diff --git a/mex/sources/dynlapack.h b/mex/sources/dynlapack.h index 2b95919e0c646e691888bb48792b743312455775..59d394241c9b52c28469c55aa3f6cb38a4286be7 100644 --- a/mex/sources/dynlapack.h +++ b/mex/sources/dynlapack.h @@ -8,7 +8,7 @@ * and MATLAB_VERSION (for version 7.4, define it to 0x0704). * * - * Copyright © 2009-2020 Dynare Team + * Copyright © 2009-2023 Dynare Team * * This file is part of Dynare. * @@ -29,13 +29,13 @@ #ifndef _DYNLAPACK_H #define _DYNLAPACK_H -#if defined(MATLAB_MEX_FILE) +#if defined(MATLAB_MEX_FILE) && __SIZEOF_POINTER__ == 8 # ifdef __cplusplus -# include <cstddef> +# include <cstdint> # else -# include <stddef.h> +# include <stdint.h> # endif -typedef ptrdiff_t lapack_int; +typedef int64_t lapack_int; #else typedef int lapack_int; #endif diff --git a/mex/sources/dynmex.h b/mex/sources/dynmex.h index 2bd07760c91e93de87ec0cc8256220c9a85dc453..a4a635e838f47ed8b30f2a719743fb9eef6205c8 100644 --- a/mex/sources/dynmex.h +++ b/mex/sources/dynmex.h @@ -1,5 +1,5 @@ /* - * Copyright © 2009-2020 Dynare Team + * Copyright © 2009-2023 Dynare Team * * This file is part of Dynare. * @@ -30,4 +30,18 @@ # define mxIsScalar(x) (mxGetM(x) == 1 && mxGetN(x) == 1) #endif +/* The int64_T and uint64_T type are broken under MinGW for MATLAB < R2015b + (they actually alias long integer types, which are 32-bit) */ +#if defined(MATLAB_MEX_FILE) && defined(__MINGW64__) && MATLAB_VERSION < 0x0806 +# define int64_T long long +# define uint64_T unsigned long long +#endif +#ifdef __cplusplus +static_assert(sizeof(int64_T) == 8, "The int64_T type is buggy"); +static_assert(sizeof(uint64_T) == 8, "The uint64_T type is buggy"); +#else +_Static_assert(sizeof(int64_T) == 8, "The int64_T type is buggy"); +_Static_assert(sizeof(uint64_T) == 8, "The uint64_T type is buggy"); +#endif + #endif diff --git a/mex/sources/dynumfpack.h b/mex/sources/dynumfpack.h index 4da0fb04af687733828a27bea9edf002cc4ed76a..c2d5ebb4d2355b77b28e5d50e65ba325ad69bde6 100644 --- a/mex/sources/dynumfpack.h +++ b/mex/sources/dynumfpack.h @@ -3,7 +3,7 @@ */ /* - * Copyright © 2013-2017 Dynare Team + * Copyright © 2013-2023 Dynare Team * * This file is part of Dynare. * @@ -24,9 +24,21 @@ #ifndef _DYNUMFPACK_H #define _DYNUMFPACK_H -#ifdef __cplusplus +#ifdef OCTAVE_MEX_FILE +# ifdef HAVE_SUITESPARSE_UMFPACK_H +# include <suitesparse/umfpack.h> +# endif +# ifdef HAVE_UMFPACK_H +# include <umfpack.h> +# endif +#else + +/* Under MATLAB, we have to provide our own header file for functions in + libmwumfpack, since there is no associated header */ + +# ifdef __cplusplus extern "C" { -#endif +# endif /* -------------------------------------------------------------------------- */ /* size of Info and Control arrays */ @@ -35,19 +47,24 @@ extern "C" { /* These might be larger in future versions, since there are only 3 unused * entries in Info, and no unused entries in Control. */ -#define UMFPACK_INFO 90 -#define UMFPACK_CONTROL 20 +# define UMFPACK_INFO 90 +# define UMFPACK_CONTROL 20 /* used in all UMFPACK_report_* routines: */ -#define UMFPACK_PRL 0 /* print level */ +# define UMFPACK_PRL 0 /* print level */ /* returned by all routines that use Info: */ -#define UMFPACK_OK (0) -#define UMFPACK_STATUS 0 /* UMFPACK_OK, or other result */ - -#ifdef _WIN64 - typedef long long int SuiteSparse_long; -#else +# define UMFPACK_OK (0) +# define UMFPACK_STATUS 0 /* UMFPACK_OK, or other result */ + +# ifdef _WIN64 +# ifdef __cplusplus +# include <cstdint> +# else +# include <stdint.h> +# endif + typedef int64_t SuiteSparse_long; +# else typedef long SuiteSparse_long; -#endif +# endif void umfpack_dl_defaults(double Control[UMFPACK_CONTROL]); @@ -83,8 +100,9 @@ extern "C" { SuiteSparse_long umfpack_dl_save_numeric(void *Numeric, char *filename); -#ifdef __cplusplus +# ifdef __cplusplus } /* extern "C" */ -#endif +# endif +#endif // OCTAVE_MEX_FILE #endif /* DYNUMFPACK */ diff --git a/mex/sources/folded_to_unfolded_dr/mexFunction.f08 b/mex/sources/folded_to_unfolded_dr/mexFunction.f08 index 7e772abd47cfce2a4870d6809d754dad5d9dd088..988c6c2dc63c4392a704fb1d92048cd2a2a5044a 100644 --- a/mex/sources/folded_to_unfolded_dr/mexFunction.f08 +++ b/mex/sources/folded_to_unfolded_dr/mexFunction.f08 @@ -1,4 +1,4 @@ -! Copyright © 2021 Dynare Team +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -22,7 +22,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use simulation use matlab_mex use partitions - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs @@ -98,4 +98,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') end do end if -end subroutine mexFunction \ No newline at end of file +end subroutine mexFunction diff --git a/mex/sources/k_order_mean/mexFunction.f08 b/mex/sources/k_order_mean/mexFunction.f08 index bdd8d2ea2bb1c41e93134c435226bcbfc27c5351..d34c7fe490d74a39ba4714ec17b6747c7a67dceb 100644 --- a/mex/sources/k_order_mean/mexFunction.f08 +++ b/mex/sources/k_order_mean/mexFunction.f08 @@ -1,4 +1,4 @@ -! Copyright © 2021-2022 Dynare Team +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -39,7 +39,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use matlab_mex use partitions use simulation - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs diff --git a/mex/sources/k_order_simul/mexFunction.f08 b/mex/sources/k_order_simul/mexFunction.f08 index 01d47d4e3c7b61c4b4d1b8627475be46fe58827f..30dc61d711d327b39e741c58afbb05eac95ba68c 100644 --- a/mex/sources/k_order_simul/mexFunction.f08 +++ b/mex/sources/k_order_simul/mexFunction.f08 @@ -1,4 +1,4 @@ -! Copyright © 2021-2022 Dynare Team +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -36,7 +36,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use matlab_mex use partitions use simulation - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs diff --git a/mex/sources/kronecker/A_times_B_kronecker_C.f08 b/mex/sources/kronecker/A_times_B_kronecker_C.f08 index ace52a808790c9c9cc713f012cd359158aa34f47..60cc3a7ab1df7f1decd3ca95b353fa65b8c86f15 100644 --- a/mex/sources/kronecker/A_times_B_kronecker_C.f08 +++ b/mex/sources/kronecker/A_times_B_kronecker_C.f08 @@ -1,7 +1,7 @@ ! This MEX file computes A·(B⊗C) or A·(B⊗B) without explicitly building B⊗C or ! B⊗B, so that one can consider large matrices B and/or C. -! Copyright © 2007-2022 Dynare Team +! Copyright © 2007-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -23,7 +23,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use iso_c_binding use matlab_mex use blas - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs diff --git a/mex/sources/k_order_perturbation/dynamic_abstract_class.hh b/mex/sources/libkorder/dynamic_abstract_class.hh similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_abstract_class.hh rename to mex/sources/libkorder/dynamic_abstract_class.hh diff --git a/mex/sources/k_order_perturbation/dynamic_dll.cc b/mex/sources/libkorder/dynamic_dll.cc similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_dll.cc rename to mex/sources/libkorder/dynamic_dll.cc diff --git a/mex/sources/k_order_perturbation/dynamic_dll.hh b/mex/sources/libkorder/dynamic_dll.hh similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_dll.hh rename to mex/sources/libkorder/dynamic_dll.hh diff --git a/mex/sources/k_order_perturbation/dynamic_m.cc b/mex/sources/libkorder/dynamic_m.cc similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_m.cc rename to mex/sources/libkorder/dynamic_m.cc diff --git a/mex/sources/k_order_perturbation/dynamic_m.hh b/mex/sources/libkorder/dynamic_m.hh similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_m.hh rename to mex/sources/libkorder/dynamic_m.hh diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.cc b/mex/sources/libkorder/k_ord_dynare.cc similarity index 100% rename from mex/sources/k_order_perturbation/k_ord_dynare.cc rename to mex/sources/libkorder/k_ord_dynare.cc diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.hh b/mex/sources/libkorder/k_ord_dynare.hh similarity index 100% rename from mex/sources/k_order_perturbation/k_ord_dynare.hh rename to mex/sources/libkorder/k_ord_dynare.hh diff --git a/dynare++/kord/approximation.cc b/mex/sources/libkorder/kord/approximation.cc similarity index 98% rename from dynare++/kord/approximation.cc rename to mex/sources/libkorder/kord/approximation.cc index 6934ec6d281676e17498fba86d772d5695fe668f..9c0efe7f2ac507b0fbb24189c63d71615d8ebdc5 100644 --- a/dynare++/kord/approximation.cc +++ b/mex/sources/libkorder/kord/approximation.cc @@ -1,6 +1,6 @@ /* * Copyright © 2005 Ondra Kamenik - * Copyright © 2019-2021 Dynare Team + * Copyright © 2019-2023 Dynare Team * * This file is part of Dynare. * @@ -40,10 +40,12 @@ ZAuxContainer::itype ZAuxContainer::getType(int i, const Symmetry &s) const { if (i == 0) - if (s[2] > 0) - return itype::zero; - else - return itype::matrix; + { + if (s[2] > 0) + return itype::zero; + else + return itype::matrix; + } return itype::zero; } diff --git a/dynare++/kord/approximation.hh b/mex/sources/libkorder/kord/approximation.hh similarity index 100% rename from dynare++/kord/approximation.hh rename to mex/sources/libkorder/kord/approximation.hh diff --git a/mex/sources/libkorder/kord/decision_rule.cc b/mex/sources/libkorder/kord/decision_rule.cc new file mode 100644 index 0000000000000000000000000000000000000000..b433a72652960b20e77723a7e2b683e32a7ca53e --- /dev/null +++ b/mex/sources/libkorder/kord/decision_rule.cc @@ -0,0 +1,45 @@ +/* + * Copyright © 2004 Ondra Kamenik + * Copyright © 2019-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/>. + */ + +#include "kord_exception.hh" +#include "decision_rule.hh" +#include "dynamic_model.hh" + +#include "SymSchurDecomp.hh" + +#include <memory> + +// FoldDecisionRule conversion from UnfoldDecisionRule +FoldDecisionRule::FoldDecisionRule(const UnfoldDecisionRule &udr) + : DecisionRuleImpl<Storage::fold>(ctraits<Storage::fold>::Tpol(udr.nrows(), udr.nvars()), + udr.ypart, udr.nu, udr.ysteady) +{ + for (const auto &it : udr) + insert(std::make_unique<ctraits<Storage::fold>::Ttensym>(*(it.second))); +} + +// UnfoldDecisionRule conversion from FoldDecisionRule +UnfoldDecisionRule::UnfoldDecisionRule(const FoldDecisionRule &fdr) + : DecisionRuleImpl<Storage::unfold>(ctraits<Storage::unfold>::Tpol(fdr.nrows(), fdr.nvars()), + fdr.ypart, fdr.nu, fdr.ysteady) +{ + for (const auto &it : fdr) + insert(std::make_unique<ctraits<Storage::unfold>::Ttensym>(*(it.second))); +} diff --git a/dynare++/kord/decision_rule.hh b/mex/sources/libkorder/kord/decision_rule.hh similarity index 62% rename from dynare++/kord/decision_rule.hh rename to mex/sources/libkorder/kord/decision_rule.hh index 2736ab4cc4cc092d120a833faee9b71fc5a97919..1e07e1d09b204b091e4da81eba74bf4535f8ced6 100644 --- a/dynare++/kord/decision_rule.hh +++ b/mex/sources/libkorder/kord/decision_rule.hh @@ -1,6 +1,6 @@ /* * Copyright © 2004 Ondra Kamenik - * Copyright © 2019-2021 Dynare Team + * Copyright © 2019-2023 Dynare Team * * This file is part of Dynare. * @@ -35,27 +35,13 @@ #ifndef DECISION_RULE_H #define DECISION_RULE_H -#include <matio.h> - #include "kord_exception.hh" #include "korder.hh" -#include "normal_conjugate.hh" #include <memory> #include <random> #include <string> -/* This is a general interface to a shock realizations. The interface has only - one method returning the shock realizations at the given time. This method - is not constant, since it may change a state of the object. */ -class ShockRealization -{ -public: - virtual ~ShockRealization() = default; - virtual void get(int n, Vector &out) = 0; - virtual int numShocks() const = 0; -}; - /* This class is an abstract interface to decision rule. Its main purpose is to define a common interface for simulation of a decision rule. We need only a simulate, evaluate, centralized clone and output method. */ @@ -65,10 +51,6 @@ public: enum class emethod { horner, trad }; virtual ~DecisionRule() = default; - // simulates the rule for a given realization of the shocks - virtual TwoDMatrix simulate(emethod em, int np, const ConstVector &ystart, - ShockRealization &sr) const = 0; - /* primitive evaluation (it takes a vector of state variables (predetermined, both and shocks) and returns the next period variables. Both input and output are in deviations from the rule's steady. */ @@ -79,9 +61,6 @@ public: virtual void evaluate(emethod em, Vector &out, const ConstVector &ys, const ConstVector &u) const = 0; - // writes the decision rule to the MAT file - virtual void writeMat(mat_t *fd, const std::string &prefix) const = 0; - /* returns a new copy of the decision rule, which is centralized about provided fix-point */ virtual std::unique_ptr<DecisionRule> centralizedClone(const Vector &fixpoint) const = 0; @@ -167,12 +146,9 @@ public: { return ysteady; } - TwoDMatrix simulate(emethod em, int np, const ConstVector &ystart, - ShockRealization &sr) const override; void evaluate(emethod em, Vector &out, const ConstVector &ys, const ConstVector &u) const override; std::unique_ptr<DecisionRule> centralizedClone(const Vector &fixpoint) const override; - void writeMat(mat_t *fd, const std::string &prefix) const override; int nexog() const override @@ -352,79 +328,6 @@ DecisionRuleImpl<t>::centralize(const DecisionRuleImpl &dr) } } -/* Here we evaluate repeatedly the polynomial storing results in the created - matrix. For exogenous shocks, we use ShockRealization class, for - predetermined variables, we use ‘ystart’ as the first state. The ‘ystart’ - vector is required to be all state variables ypart.ny(), although only the - predetermined part of ‘ystart’ is used. - - We simulate in terms of Δy, this is, at the beginning the ‘ysteady’ is - canceled from ‘ystart’, we simulate, and at the end ‘ysteady’ is added to - all columns of the result. */ - -template<Storage t> -TwoDMatrix -DecisionRuleImpl<t>::simulate(emethod em, int np, const ConstVector &ystart, - ShockRealization &sr) const -{ - KORD_RAISE_IF(ysteady.length() != ystart.length(), - "Start and steady lengths differ in DecisionRuleImpl::simulate"); - TwoDMatrix res(ypart.ny(), np); - - // initialize vectors and subvectors for simulation - /* Here allocate the stack vector (Δy*,u), define the subvectors ‘dy’, and - ‘u’, then we pickup predetermined parts of ‘ystart’ and ‘ysteady’. */ - Vector dyu(ypart.nys()+nu); - ConstVector ystart_pred(ystart, ypart.nstat, ypart.nys()); - ConstVector ysteady_pred(ysteady, ypart.nstat, ypart.nys()); - Vector dy(dyu, 0, ypart.nys()); - Vector u(dyu, ypart.nys(), nu); - - // perform the first step of simulation - /* We cancel ‘ysteady’ from ‘ystart’, get realization to ‘u’, and evaluate - the polynomial. */ - dy = ystart_pred; - dy.add(-1.0, ysteady_pred); - sr.get(0, u); - Vector out{res.getCol(0)}; - eval(em, out, dyu); - - // perform all other steps of simulations - /* Also clear. If the result at some period is not finite, we pad the rest of - the matrix with zeros. */ - int i = 1; - while (i < np) - { - ConstVector ym{res.getCol(i-1)}; - ConstVector dym(ym, ypart.nstat, ypart.nys()); - dy = dym; - sr.get(i, u); - Vector out{res.getCol(i)}; - eval(em, out, dyu); - if (!out.isFinite()) - { - if (i+1 < np) - { - TwoDMatrix rest(res, i+1, np-i-1); - rest.zeros(); - } - break; - } - i++; - } - - // add the steady state to columns of ‘res’ - /* Even clearer. We add the steady state to the numbers computed above and - leave the padded columns to zero. */ - for (int j = 0; j < i; j++) - { - Vector col{res.getCol(j)}; - col.add(1.0, ysteady); - } - - return res; -} - /* This is one period evaluation of the decision rule. The simulation is a sequence of repeated one period evaluations with a difference, that the steady state (fix point) is cancelled and added once. Hence we have two @@ -473,18 +376,6 @@ DecisionRuleImpl<t>::eval(emethod em, Vector &out, const ConstVector &v) const _Tpol::evalTrad(out, v); } -/* Write the decision rule and steady state to the MAT file. */ - -template<Storage t> -void -DecisionRuleImpl<t>::writeMat(mat_t *fd, const std::string &prefix) const -{ - ctraits<t>::Tpol::writeMat(fd, prefix); - TwoDMatrix dum(ysteady.length(), 1); - dum.getData() = ysteady; - ConstTwoDMatrix(dum).writeMat(fd, prefix + "_ss"); -} - /* This is exactly the same as DecisionRuleImpl<Storage::fold>. The only difference is that we have a conversion from UnfoldDecisionRule, which is exactly DecisionRuleImpl<Storage::unfold>. */ @@ -786,354 +677,4 @@ DRFixPoint<t>::calcFixPoint(emethod em, Vector &out) return converged; } -/* This is a basically a number of matrices of the same dimensions, which can - be obtained as simulation results from a given decision rule and shock - realizations. We also store the realizations of shocks and the starting - point of each simulation. */ - -class ExplicitShockRealization; -class SimResults -{ -protected: - int num_y; - int num_per; - int num_burn; - std::vector<TwoDMatrix> data; - std::vector<ExplicitShockRealization> shocks; - std::vector<ConstVector> start; -public: - SimResults(int ny, int nper, int nburn = 0) - : num_y(ny), num_per(nper), num_burn(nburn) - { - } - void simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov, Journal &journal); - void simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov); - int - getNumPer() const - { - return num_per; - } - int - getNumBurn() const - { - return num_burn; - } - int - getNumSets() const - { - return static_cast<int>(data.size()); - } - const TwoDMatrix & - getData(int i) const - { - return data[i]; - } - const ExplicitShockRealization & - getShocks(int i) const - { - return shocks[i]; - } - const ConstVector & - getStart(int i) const - { - return start[i]; - } - - bool addDataSet(const TwoDMatrix &d, const ExplicitShockRealization &sr, const ConstVector &st); - void writeMat(const std::string &base, const std::string &lname) const; - void writeMat(mat_t *fd, const std::string &lname) const; -}; - -/* This does the same as SimResults plus it calculates means and covariances of - the simulated data. */ - -class SimResultsStats : public SimResults -{ -protected: - Vector mean; - TwoDMatrix vcov; -public: - SimResultsStats(int ny, int nper, int nburn = 0) - : SimResults(ny, nper, nburn), mean(ny), vcov(ny, ny) - { - } - void simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov, Journal &journal); - void writeMat(mat_t *fd, const std::string &lname) const; -protected: - void calcMean(); - void calcVcov(); -}; - -/* This does the similar thing as SimResultsStats but the statistics are not - calculated over all periods but only within each period. Then we do not - calculate covariances with periods but only variances. */ - -class SimResultsDynamicStats : public SimResults -{ -protected: - TwoDMatrix mean; - TwoDMatrix variance; -public: - SimResultsDynamicStats(int ny, int nper, int nburn = 0) - : SimResults(ny, nper, nburn), mean(ny, nper), variance(ny, nper) - { - } - void simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov, Journal &journal); - void writeMat(mat_t *fd, const std::string &lname) const; -protected: - void calcMean(); - void calcVariance(); -}; - -/* This goes through control simulation results, and for each control it adds a - given impulse to a given shock and runs a simulation. The control simulation - is then cancelled and the result is stored. After that these results are - averaged with variances calculated. - - The means and the variances are then written to the MAT file. */ - -class SimulationIRFWorker; -class SimResultsIRF : public SimResults -{ - friend class SimulationIRFWorker; -protected: - const SimResults &control; - int ishock; - double imp; - TwoDMatrix means; - TwoDMatrix variances; -public: - SimResultsIRF(const SimResults &cntl, int ny, int nper, int i, double impulse) - : SimResults(ny, nper, 0), control(cntl), - ishock(i), imp(impulse), - means(ny, nper), variances(ny, nper) - { - } - void simulate(const DecisionRule &dr, Journal &journal); - void simulate(const DecisionRule &dr); - void writeMat(mat_t *fd, const std::string &lname) const; -protected: - void calcMeans(); - void calcVariances(); -}; - -/* This simulates and gathers all statistics from the real time simulations. In - the simulate() method, it runs RTSimulationWorker’s which accummulate - information from their own estimates. The estimation is done by means of - NormalConj class, which is a conjugate family of densities for normal - distibutions. */ - -class RTSimulationWorker; -class RTSimResultsStats -{ - friend class RTSimulationWorker; -protected: - Vector mean; - TwoDMatrix vcov; - int num_per; - int num_burn; - NormalConj nc; - int incomplete_simulations; - int thrown_periods; -public: - RTSimResultsStats(int ny, int nper, int nburn = 0) - : mean(ny), vcov(ny, ny), - num_per(nper), num_burn(nburn), nc(ny), - incomplete_simulations(0), thrown_periods(0) - { - } - void simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov, Journal &journal); - void simulate(int num_sim, const DecisionRule &dr, const Vector &start, - const TwoDMatrix &vcov); - void writeMat(mat_t *fd, const std::string &lname); -}; - -/* For each shock, this simulates plus and minus impulse. The class maintains a - vector of simulation results, each gets a particular shock and sign - (positive/negative). The results of type SimResultsIRF are stored in a - vector so that even ones are positive, odd ones are negative. - - The constructor takes a reference to the control simulations, which must be - finished before the constructor is called. The control simulations are - passed to all SimResultsIRF’s. - - The constructor also takes the vector of indices of exogenous variables - (‘ili’) for which the IRFs are generated. The list is kept (as - ‘irf_list_ind’) for other methods. */ - -class DynamicModel; -class IRFResults -{ - std::vector<SimResultsIRF> irf_res; - const DynamicModel &model; - std::vector<int> irf_list_ind; -public: - IRFResults(const DynamicModel &mod, const DecisionRule &dr, - const SimResults &control, std::vector<int> ili, - Journal &journal); - void writeMat(mat_t *fd, const std::string &prefix) const; -}; - -/* This worker simulates the given decision rule and inserts the result to - SimResults. */ - -class SimulationWorker : public sthread::detach_thread -{ -protected: - SimResults &res; - const DecisionRule &dr; - DecisionRule::emethod em; - int np; - const Vector &st; - ShockRealization &sr; -public: - SimulationWorker(SimResults &sim_res, - const DecisionRule &dec_rule, - DecisionRule::emethod emet, int num_per, - const Vector &start, ShockRealization &shock_r) - : res(sim_res), dr(dec_rule), em(emet), np(num_per), st(start), sr(shock_r) - { - } - void operator()(std::mutex &mut) override; -}; - -/* This worker simulates a given impulse ‘imp’ to a given shock ‘ishock’ based - on a given control simulation with index ‘idata’. The control simulations - are contained in SimResultsIRF which is passed to the constructor. */ - -class SimulationIRFWorker : public sthread::detach_thread -{ - SimResultsIRF &res; - const DecisionRule &dr; - DecisionRule::emethod em; - int np; - int idata; - int ishock; - double imp; -public: - SimulationIRFWorker(SimResultsIRF &sim_res, - const DecisionRule &dec_rule, - DecisionRule::emethod emet, int num_per, - int id, int ishck, double impulse) - : res(sim_res), dr(dec_rule), em(emet), np(num_per), - idata(id), ishock(ishck), imp(impulse) - { - } - void operator()(std::mutex &mut) override; -}; - -/* This class does the real time simulation job for RTSimResultsStats. It - simulates the model period by period. It accummulates the information in - ‘RTSimResultsStats::nc’. If NaN or Inf is observed, it ends the simulation - and adds to the ‘thrown_periods’ of RTSimResultsStats. */ - -class RTSimulationWorker : public sthread::detach_thread -{ -protected: - RTSimResultsStats &res; - const DecisionRule &dr; - DecisionRule::emethod em; - int np; - const Vector &ystart; - ShockRealization &sr; -public: - RTSimulationWorker(RTSimResultsStats &sim_res, - const DecisionRule &dec_rule, - DecisionRule::emethod emet, int num_per, - const Vector &start, ShockRealization &shock_r) - : res(sim_res), dr(dec_rule), em(emet), np(num_per), ystart(start), sr(shock_r) - { - } - void operator()(std::mutex &mut) override; -}; - -/* This class generates draws from Gaussian distribution with zero mean and the - given variance-covariance matrix. It stores the factor of vcov V matrix, - yielding FFᵀ = V. */ - -class RandomShockRealization : virtual public ShockRealization -{ -protected: - std::mt19937 mtwister; - std::normal_distribution<> dis; - TwoDMatrix factor; -public: - RandomShockRealization(const ConstTwoDMatrix &v, decltype(mtwister)::result_type iseed) - : mtwister(iseed), factor(v.nrows(), v.nrows()) - { - schurFactor(v); - } - void get(int n, Vector &out) override; - int - numShocks() const override - { - return factor.nrows(); - } -protected: - void choleskyFactor(const ConstTwoDMatrix &v); - void schurFactor(const ConstTwoDMatrix &v); -}; - -/* This is just a matrix of finite numbers. It can be constructed from any - ShockRealization with a given number of periods. */ - -class ExplicitShockRealization : virtual public ShockRealization -{ - TwoDMatrix shocks; -public: - explicit ExplicitShockRealization(const ConstTwoDMatrix &sh) - : shocks(sh) - { - } - ExplicitShockRealization(ShockRealization &sr, int num_per); - void get(int n, Vector &out) override; - int - numShocks() const override - { - return shocks.nrows(); - } - const TwoDMatrix & - getShocks() const - { - return shocks; - } - void addToShock(int ishock, int iper, double val); - void - print() const - { - shocks.print(); - } -}; - -/* This represents a user given shock realization. The first matrix of the - constructor is a covariance matrix of shocks, the second matrix is a - rectangular matrix, where columns correspond to periods, rows to shocks. If - an element of the matrix is NaN or ±∞, then the random shock is taken - instead of that element. - - In this way it is a generalization of both RandomShockRealization and - ExplicitShockRealization. */ - -class GenShockRealization : public RandomShockRealization, public ExplicitShockRealization -{ -public: - GenShockRealization(const ConstTwoDMatrix &v, const ConstTwoDMatrix &sh, int seed) - : RandomShockRealization(v, seed), ExplicitShockRealization(sh) - { - KORD_RAISE_IF(sh.nrows() != v.nrows() || v.nrows() != v.ncols(), - "Wrong dimension of input matrix in GenShockRealization constructor"); - } - void get(int n, Vector &out) override; - int - numShocks() const override - { - return RandomShockRealization::numShocks(); - } -}; - #endif diff --git a/dynare++/kord/seed_generator.hh b/mex/sources/libkorder/kord/dynamic_model.cc similarity index 69% rename from dynare++/kord/seed_generator.hh rename to mex/sources/libkorder/kord/dynamic_model.cc index 5679ad2a9fd97726211c7f9228bf7d4bf88bc621..f392144473b3830af0fb9f32126d5f42e854265f 100644 --- a/dynare++/kord/seed_generator.hh +++ b/mex/sources/libkorder/kord/dynamic_model.cc @@ -1,4 +1,5 @@ /* + * Copyright © 2005 Ondra Kamenik * Copyright © 2019 Dynare Team * * This file is part of Dynare. @@ -17,18 +18,14 @@ * along with Dynare. If not, see <https://www.gnu.org/licenses/>. */ -#ifndef RANDOM_H -#define RANDOM_H +#include "dynamic_model.hh" -#include <random> +#include <iostream> +#include <algorithm> -namespace seed_generator +void +NameList::print() const { - // Produces seeds that can be used with Mersenne-Twister generators (thread-safe) - std::mt19937::result_type get_new_seed(); - - // Sets the seed for the seed generator (!) - void set_meta_seed(std::mt19937::result_type s); -}; - -#endif + for (int i = 0; i < getNum(); i++) + std::cout << getName(i) << '\n'; +} diff --git a/dynare++/kord/dynamic_model.hh b/mex/sources/libkorder/kord/dynamic_model.hh similarity index 97% rename from dynare++/kord/dynamic_model.hh rename to mex/sources/libkorder/kord/dynamic_model.hh index 9ceb02cac037296ce98c159ffc13a8075cc68e60..2171027d58796c5d480be888b5b7021088fe7a8e 100644 --- a/dynare++/kord/dynamic_model.hh +++ b/mex/sources/libkorder/kord/dynamic_model.hh @@ -48,8 +48,6 @@ public: virtual int getNum() const = 0; virtual const std::string &getName(int i) const = 0; void print() const; - void writeMat(mat_t *fd, const std::string &vname) const; - void writeMatIndices(mat_t *fd, const std::string &prefix) const; }; /* This is the interface to an information on a generic DSGE model. It is diff --git a/dynare++/kord/faa_di_bruno.cc b/mex/sources/libkorder/kord/faa_di_bruno.cc similarity index 100% rename from dynare++/kord/faa_di_bruno.cc rename to mex/sources/libkorder/kord/faa_di_bruno.cc diff --git a/dynare++/kord/faa_di_bruno.hh b/mex/sources/libkorder/kord/faa_di_bruno.hh similarity index 100% rename from dynare++/kord/faa_di_bruno.hh rename to mex/sources/libkorder/kord/faa_di_bruno.hh diff --git a/dynare++/kord/first_order.cc b/mex/sources/libkorder/kord/first_order.cc similarity index 100% rename from dynare++/kord/first_order.cc rename to mex/sources/libkorder/kord/first_order.cc diff --git a/dynare++/kord/first_order.hh b/mex/sources/libkorder/kord/first_order.hh similarity index 100% rename from dynare++/kord/first_order.hh rename to mex/sources/libkorder/kord/first_order.hh diff --git a/dynare++/kord/journal.cc b/mex/sources/libkorder/kord/journal.cc similarity index 100% rename from dynare++/kord/journal.cc rename to mex/sources/libkorder/kord/journal.cc diff --git a/dynare++/kord/journal.hh b/mex/sources/libkorder/kord/journal.hh similarity index 100% rename from dynare++/kord/journal.hh rename to mex/sources/libkorder/kord/journal.hh diff --git a/dynare++/kord/kord_exception.hh b/mex/sources/libkorder/kord/kord_exception.hh similarity index 100% rename from dynare++/kord/kord_exception.hh rename to mex/sources/libkorder/kord/kord_exception.hh diff --git a/dynare++/kord/korder.cc b/mex/sources/libkorder/kord/korder.cc similarity index 100% rename from dynare++/kord/korder.cc rename to mex/sources/libkorder/kord/korder.cc diff --git a/dynare++/kord/korder.hh b/mex/sources/libkorder/kord/korder.hh similarity index 100% rename from dynare++/kord/korder.hh rename to mex/sources/libkorder/kord/korder.hh diff --git a/dynare++/kord/korder_stoch.cc b/mex/sources/libkorder/kord/korder_stoch.cc similarity index 100% rename from dynare++/kord/korder_stoch.cc rename to mex/sources/libkorder/kord/korder_stoch.cc diff --git a/dynare++/kord/korder_stoch.hh b/mex/sources/libkorder/kord/korder_stoch.hh similarity index 96% rename from dynare++/kord/korder_stoch.hh rename to mex/sources/libkorder/kord/korder_stoch.hh index d4152d4f436ff81cb0c32608225546dd25ae935e..857bcc65db27ff07ee1c465c1551e0af2820fefe 100644 --- a/dynare++/kord/korder_stoch.hh +++ b/mex/sources/libkorder/kord/korder_stoch.hh @@ -1,6 +1,6 @@ /* * Copyright © 2005 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team + * Copyright © 2019-2023 Dynare Team * * This file is part of Dynare. * @@ -285,19 +285,23 @@ typename GXContainer<_Ttype>::itype GXContainer<_Ttype>::getType(int i, const Symmetry &s) const { if (i == 0) - if (s[2] > 0) - return itype::zero; - else - return itype::matrix; + { + if (s[2] > 0) + return itype::zero; + else + return itype::matrix; + } if (i == 1) return itype::zero; if (i == 2) return itype::zero; if (i == 3) - if (s == Symmetry{0, 0, 0, 1}) - return itype::unit; - else - return itype::zero; + { + if (s == Symmetry{0, 0, 0, 1}) + return itype::unit; + else + return itype::zero; + } KORD_RAISE("Wrong stack index in GXContainer::getType"); } @@ -331,25 +335,33 @@ typename ZXContainer<_Ttype>::itype ZXContainer<_Ttype>::getType(int i, const Symmetry &s) const { if (i == 0) - if (s[2] > 0) - return itype::zero; - else - return itype::matrix; + { + if (s[2] > 0) + return itype::zero; + else + return itype::matrix; + } if (i == 1) - if (s[2] > 0) - return itype::zero; - else - return itype::matrix; + { + if (s[2] > 0) + return itype::zero; + else + return itype::matrix; + } if (i == 2) - if (s == Symmetry{1, 0, 0, 0}) - return itype::unit; - else - return itype::zero; + { + if (s == Symmetry{1, 0, 0, 0}) + return itype::unit; + else + return itype::zero; + } if (i == 3) - if (s == Symmetry{0, 1, 0, 0}) - return itype::unit; - else - return itype::zero; + { + if (s == Symmetry{0, 1, 0, 0}) + return itype::unit; + else + return itype::zero; + } KORD_RAISE("Wrong stack index in ZXContainer::getType"); } diff --git a/mex/sources/libkorder/kord/tests/Makefile.am b/mex/sources/libkorder/kord/tests/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..14d4022280a3b1ce0c8fa65ad0491b7e945a3e12 --- /dev/null +++ b/mex/sources/libkorder/kord/tests/Makefile.am @@ -0,0 +1,11 @@ +check_PROGRAMS = tests + +tests_SOURCES = tests.cc +tests_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -I../utils/cc -I$(top_srcdir)/mex/sources +tests_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) +tests_LDADD = libkord.a ../tl/cc/libtl.a ../sylv/cc/libsylv.a ../utils/cc/libutils.a $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) $(LIBADD_MATIO) + +check-local: + ./tests + +CLEANFILES = out.txt diff --git a/dynare++/kord/tests.cc b/mex/sources/libkorder/kord/tests/tests.cc similarity index 100% rename from dynare++/kord/tests.cc rename to mex/sources/libkorder/kord/tests/tests.cc diff --git a/dynare++/sylv/cc/BlockDiagonal.cc b/mex/sources/libkorder/sylv/BlockDiagonal.cc similarity index 100% rename from dynare++/sylv/cc/BlockDiagonal.cc rename to mex/sources/libkorder/sylv/BlockDiagonal.cc diff --git a/dynare++/sylv/cc/BlockDiagonal.hh b/mex/sources/libkorder/sylv/BlockDiagonal.hh similarity index 100% rename from dynare++/sylv/cc/BlockDiagonal.hh rename to mex/sources/libkorder/sylv/BlockDiagonal.hh diff --git a/dynare++/sylv/cc/GeneralMatrix.cc b/mex/sources/libkorder/sylv/GeneralMatrix.cc similarity index 100% rename from dynare++/sylv/cc/GeneralMatrix.cc rename to mex/sources/libkorder/sylv/GeneralMatrix.cc diff --git a/dynare++/sylv/cc/GeneralMatrix.hh b/mex/sources/libkorder/sylv/GeneralMatrix.hh similarity index 100% rename from dynare++/sylv/cc/GeneralMatrix.hh rename to mex/sources/libkorder/sylv/GeneralMatrix.hh diff --git a/dynare++/sylv/cc/GeneralSylvester.cc b/mex/sources/libkorder/sylv/GeneralSylvester.cc similarity index 100% rename from dynare++/sylv/cc/GeneralSylvester.cc rename to mex/sources/libkorder/sylv/GeneralSylvester.cc diff --git a/dynare++/sylv/cc/GeneralSylvester.hh b/mex/sources/libkorder/sylv/GeneralSylvester.hh similarity index 100% rename from dynare++/sylv/cc/GeneralSylvester.hh rename to mex/sources/libkorder/sylv/GeneralSylvester.hh diff --git a/dynare++/sylv/cc/IterativeSylvester.cc b/mex/sources/libkorder/sylv/IterativeSylvester.cc similarity index 100% rename from dynare++/sylv/cc/IterativeSylvester.cc rename to mex/sources/libkorder/sylv/IterativeSylvester.cc diff --git a/dynare++/sylv/cc/IterativeSylvester.hh b/mex/sources/libkorder/sylv/IterativeSylvester.hh similarity index 100% rename from dynare++/sylv/cc/IterativeSylvester.hh rename to mex/sources/libkorder/sylv/IterativeSylvester.hh diff --git a/dynare++/sylv/cc/KronUtils.cc b/mex/sources/libkorder/sylv/KronUtils.cc similarity index 100% rename from dynare++/sylv/cc/KronUtils.cc rename to mex/sources/libkorder/sylv/KronUtils.cc diff --git a/dynare++/sylv/cc/KronUtils.hh b/mex/sources/libkorder/sylv/KronUtils.hh similarity index 100% rename from dynare++/sylv/cc/KronUtils.hh rename to mex/sources/libkorder/sylv/KronUtils.hh diff --git a/dynare++/sylv/cc/KronVector.cc b/mex/sources/libkorder/sylv/KronVector.cc similarity index 100% rename from dynare++/sylv/cc/KronVector.cc rename to mex/sources/libkorder/sylv/KronVector.cc diff --git a/dynare++/sylv/cc/KronVector.hh b/mex/sources/libkorder/sylv/KronVector.hh similarity index 100% rename from dynare++/sylv/cc/KronVector.hh rename to mex/sources/libkorder/sylv/KronVector.hh diff --git a/dynare++/sylv/cc/QuasiTriangular.cc b/mex/sources/libkorder/sylv/QuasiTriangular.cc similarity index 100% rename from dynare++/sylv/cc/QuasiTriangular.cc rename to mex/sources/libkorder/sylv/QuasiTriangular.cc diff --git a/dynare++/sylv/cc/QuasiTriangular.hh b/mex/sources/libkorder/sylv/QuasiTriangular.hh similarity index 100% rename from dynare++/sylv/cc/QuasiTriangular.hh rename to mex/sources/libkorder/sylv/QuasiTriangular.hh diff --git a/dynare++/sylv/cc/QuasiTriangularZero.cc b/mex/sources/libkorder/sylv/QuasiTriangularZero.cc similarity index 100% rename from dynare++/sylv/cc/QuasiTriangularZero.cc rename to mex/sources/libkorder/sylv/QuasiTriangularZero.cc diff --git a/dynare++/sylv/cc/QuasiTriangularZero.hh b/mex/sources/libkorder/sylv/QuasiTriangularZero.hh similarity index 100% rename from dynare++/sylv/cc/QuasiTriangularZero.hh rename to mex/sources/libkorder/sylv/QuasiTriangularZero.hh diff --git a/dynare++/sylv/cc/SchurDecomp.cc b/mex/sources/libkorder/sylv/SchurDecomp.cc similarity index 100% rename from dynare++/sylv/cc/SchurDecomp.cc rename to mex/sources/libkorder/sylv/SchurDecomp.cc diff --git a/dynare++/sylv/cc/SchurDecomp.hh b/mex/sources/libkorder/sylv/SchurDecomp.hh similarity index 100% rename from dynare++/sylv/cc/SchurDecomp.hh rename to mex/sources/libkorder/sylv/SchurDecomp.hh diff --git a/dynare++/sylv/cc/SchurDecompEig.cc b/mex/sources/libkorder/sylv/SchurDecompEig.cc similarity index 100% rename from dynare++/sylv/cc/SchurDecompEig.cc rename to mex/sources/libkorder/sylv/SchurDecompEig.cc diff --git a/dynare++/sylv/cc/SchurDecompEig.hh b/mex/sources/libkorder/sylv/SchurDecompEig.hh similarity index 100% rename from dynare++/sylv/cc/SchurDecompEig.hh rename to mex/sources/libkorder/sylv/SchurDecompEig.hh diff --git a/dynare++/sylv/cc/SimilarityDecomp.cc b/mex/sources/libkorder/sylv/SimilarityDecomp.cc similarity index 100% rename from dynare++/sylv/cc/SimilarityDecomp.cc rename to mex/sources/libkorder/sylv/SimilarityDecomp.cc diff --git a/dynare++/sylv/cc/SimilarityDecomp.hh b/mex/sources/libkorder/sylv/SimilarityDecomp.hh similarity index 100% rename from dynare++/sylv/cc/SimilarityDecomp.hh rename to mex/sources/libkorder/sylv/SimilarityDecomp.hh diff --git a/dynare++/sylv/cc/SylvException.cc b/mex/sources/libkorder/sylv/SylvException.cc similarity index 100% rename from dynare++/sylv/cc/SylvException.cc rename to mex/sources/libkorder/sylv/SylvException.cc diff --git a/dynare++/sylv/cc/SylvException.hh b/mex/sources/libkorder/sylv/SylvException.hh similarity index 100% rename from dynare++/sylv/cc/SylvException.hh rename to mex/sources/libkorder/sylv/SylvException.hh diff --git a/dynare++/sylv/cc/SylvMatrix.cc b/mex/sources/libkorder/sylv/SylvMatrix.cc similarity index 100% rename from dynare++/sylv/cc/SylvMatrix.cc rename to mex/sources/libkorder/sylv/SylvMatrix.cc diff --git a/dynare++/sylv/cc/SylvMatrix.hh b/mex/sources/libkorder/sylv/SylvMatrix.hh similarity index 100% rename from dynare++/sylv/cc/SylvMatrix.hh rename to mex/sources/libkorder/sylv/SylvMatrix.hh diff --git a/dynare++/sylv/cc/SylvParams.cc b/mex/sources/libkorder/sylv/SylvParams.cc similarity index 100% rename from dynare++/sylv/cc/SylvParams.cc rename to mex/sources/libkorder/sylv/SylvParams.cc diff --git a/dynare++/sylv/cc/SylvParams.hh b/mex/sources/libkorder/sylv/SylvParams.hh similarity index 100% rename from dynare++/sylv/cc/SylvParams.hh rename to mex/sources/libkorder/sylv/SylvParams.hh diff --git a/dynare++/sylv/cc/SylvesterSolver.hh b/mex/sources/libkorder/sylv/SylvesterSolver.hh similarity index 100% rename from dynare++/sylv/cc/SylvesterSolver.hh rename to mex/sources/libkorder/sylv/SylvesterSolver.hh diff --git a/dynare++/sylv/cc/SymSchurDecomp.cc b/mex/sources/libkorder/sylv/SymSchurDecomp.cc similarity index 100% rename from dynare++/sylv/cc/SymSchurDecomp.cc rename to mex/sources/libkorder/sylv/SymSchurDecomp.cc diff --git a/dynare++/sylv/cc/SymSchurDecomp.hh b/mex/sources/libkorder/sylv/SymSchurDecomp.hh similarity index 100% rename from dynare++/sylv/cc/SymSchurDecomp.hh rename to mex/sources/libkorder/sylv/SymSchurDecomp.hh diff --git a/dynare++/sylv/cc/TriangularSylvester.cc b/mex/sources/libkorder/sylv/TriangularSylvester.cc similarity index 100% rename from dynare++/sylv/cc/TriangularSylvester.cc rename to mex/sources/libkorder/sylv/TriangularSylvester.cc diff --git a/dynare++/sylv/cc/TriangularSylvester.hh b/mex/sources/libkorder/sylv/TriangularSylvester.hh similarity index 100% rename from dynare++/sylv/cc/TriangularSylvester.hh rename to mex/sources/libkorder/sylv/TriangularSylvester.hh diff --git a/dynare++/sylv/cc/Vector.cc b/mex/sources/libkorder/sylv/Vector.cc similarity index 100% rename from dynare++/sylv/cc/Vector.cc rename to mex/sources/libkorder/sylv/Vector.cc diff --git a/dynare++/sylv/cc/Vector.hh b/mex/sources/libkorder/sylv/Vector.hh similarity index 100% rename from dynare++/sylv/cc/Vector.hh rename to mex/sources/libkorder/sylv/Vector.hh diff --git a/dynare++/sylv/testing/MMMatrix.cc b/mex/sources/libkorder/sylv/tests/MMMatrix.cc similarity index 100% rename from dynare++/sylv/testing/MMMatrix.cc rename to mex/sources/libkorder/sylv/tests/MMMatrix.cc diff --git a/dynare++/sylv/testing/MMMatrix.hh b/mex/sources/libkorder/sylv/tests/MMMatrix.hh similarity index 100% rename from dynare++/sylv/testing/MMMatrix.hh rename to mex/sources/libkorder/sylv/tests/MMMatrix.hh diff --git a/dynare++/sylv/testing/Makefile.am b/mex/sources/libkorder/sylv/tests/Makefile.am similarity index 100% rename from dynare++/sylv/testing/Makefile.am rename to mex/sources/libkorder/sylv/tests/Makefile.am diff --git a/dynare++/sylv/testing/a20x20.mm b/mex/sources/libkorder/sylv/tests/a20x20.mm similarity index 100% rename from dynare++/sylv/testing/a20x20.mm rename to mex/sources/libkorder/sylv/tests/a20x20.mm diff --git a/dynare++/sylv/testing/a2x2.mm b/mex/sources/libkorder/sylv/tests/a2x2.mm similarity index 100% rename from dynare++/sylv/testing/a2x2.mm rename to mex/sources/libkorder/sylv/tests/a2x2.mm diff --git a/dynare++/sylv/testing/a30x30.mm b/mex/sources/libkorder/sylv/tests/a30x30.mm similarity index 100% rename from dynare++/sylv/testing/a30x30.mm rename to mex/sources/libkorder/sylv/tests/a30x30.mm diff --git a/dynare++/sylv/testing/b20x15.mm b/mex/sources/libkorder/sylv/tests/b20x15.mm similarity index 100% rename from dynare++/sylv/testing/b20x15.mm rename to mex/sources/libkorder/sylv/tests/b20x15.mm diff --git a/dynare++/sylv/testing/b20x4.mm b/mex/sources/libkorder/sylv/tests/b20x4.mm similarity index 100% rename from dynare++/sylv/testing/b20x4.mm rename to mex/sources/libkorder/sylv/tests/b20x4.mm diff --git a/dynare++/sylv/testing/b2x1.mm b/mex/sources/libkorder/sylv/tests/b2x1.mm similarity index 100% rename from dynare++/sylv/testing/b2x1.mm rename to mex/sources/libkorder/sylv/tests/b2x1.mm diff --git a/dynare++/sylv/testing/b30x25.mm b/mex/sources/libkorder/sylv/tests/b30x25.mm similarity index 100% rename from dynare++/sylv/testing/b30x25.mm rename to mex/sources/libkorder/sylv/tests/b30x25.mm diff --git a/dynare++/sylv/testing/c20x20.mm b/mex/sources/libkorder/sylv/tests/c20x20.mm similarity index 100% rename from dynare++/sylv/testing/c20x20.mm rename to mex/sources/libkorder/sylv/tests/c20x20.mm diff --git a/dynare++/sylv/testing/c3x3.mm b/mex/sources/libkorder/sylv/tests/c3x3.mm similarity index 100% rename from dynare++/sylv/testing/c3x3.mm rename to mex/sources/libkorder/sylv/tests/c3x3.mm diff --git a/dynare++/sylv/testing/c50x50.mm b/mex/sources/libkorder/sylv/tests/c50x50.mm similarity index 100% rename from dynare++/sylv/testing/c50x50.mm rename to mex/sources/libkorder/sylv/tests/c50x50.mm diff --git a/dynare++/sylv/testing/c50x50sing.mm b/mex/sources/libkorder/sylv/tests/c50x50sing.mm similarity index 100% rename from dynare++/sylv/testing/c50x50sing.mm rename to mex/sources/libkorder/sylv/tests/c50x50sing.mm diff --git a/dynare++/sylv/testing/d20x125000.mm b/mex/sources/libkorder/sylv/tests/d20x125000.mm similarity index 100% rename from dynare++/sylv/testing/d20x125000.mm rename to mex/sources/libkorder/sylv/tests/d20x125000.mm diff --git a/dynare++/sylv/testing/d2x9.mm b/mex/sources/libkorder/sylv/tests/d2x9.mm similarity index 100% rename from dynare++/sylv/testing/d2x9.mm rename to mex/sources/libkorder/sylv/tests/d2x9.mm diff --git a/dynare++/sylv/testing/d30x400.mm b/mex/sources/libkorder/sylv/tests/d30x400.mm similarity index 100% rename from dynare++/sylv/testing/d30x400.mm rename to mex/sources/libkorder/sylv/tests/d30x400.mm diff --git a/dynare++/sylv/testing/ill_cond15x15.mm b/mex/sources/libkorder/sylv/tests/ill_cond15x15.mm similarity index 100% rename from dynare++/sylv/testing/ill_cond15x15.mm rename to mex/sources/libkorder/sylv/tests/ill_cond15x15.mm diff --git a/dynare++/sylv/testing/qt250x250.mm b/mex/sources/libkorder/sylv/tests/qt250x250.mm similarity index 100% rename from dynare++/sylv/testing/qt250x250.mm rename to mex/sources/libkorder/sylv/tests/qt250x250.mm diff --git a/dynare++/sylv/testing/qt2x2.mm b/mex/sources/libkorder/sylv/tests/qt2x2.mm similarity index 100% rename from dynare++/sylv/testing/qt2x2.mm rename to mex/sources/libkorder/sylv/tests/qt2x2.mm diff --git a/dynare++/sylv/testing/qt30x30.mm b/mex/sources/libkorder/sylv/tests/qt30x30.mm similarity index 100% rename from dynare++/sylv/testing/qt30x30.mm rename to mex/sources/libkorder/sylv/tests/qt30x30.mm diff --git a/dynare++/sylv/testing/qt30x30eig011-095.mm b/mex/sources/libkorder/sylv/tests/qt30x30eig011-095.mm similarity index 100% rename from dynare++/sylv/testing/qt30x30eig011-095.mm rename to mex/sources/libkorder/sylv/tests/qt30x30eig011-095.mm diff --git a/dynare++/sylv/testing/qt3x3.mm b/mex/sources/libkorder/sylv/tests/qt3x3.mm similarity index 100% rename from dynare++/sylv/testing/qt3x3.mm rename to mex/sources/libkorder/sylv/tests/qt3x3.mm diff --git a/dynare++/sylv/testing/qt40x40.mm b/mex/sources/libkorder/sylv/tests/qt40x40.mm similarity index 100% rename from dynare++/sylv/testing/qt40x40.mm rename to mex/sources/libkorder/sylv/tests/qt40x40.mm diff --git a/dynare++/sylv/testing/qt5x5.mm b/mex/sources/libkorder/sylv/tests/qt5x5.mm similarity index 100% rename from dynare++/sylv/testing/qt5x5.mm rename to mex/sources/libkorder/sylv/tests/qt5x5.mm diff --git a/dynare++/sylv/testing/qt7x7.mm b/mex/sources/libkorder/sylv/tests/qt7x7.mm similarity index 100% rename from dynare++/sylv/testing/qt7x7.mm rename to mex/sources/libkorder/sylv/tests/qt7x7.mm diff --git a/dynare++/sylv/testing/qt7x7eig06-09.mm b/mex/sources/libkorder/sylv/tests/qt7x7eig06-09.mm similarity index 100% rename from dynare++/sylv/testing/qt7x7eig06-09.mm rename to mex/sources/libkorder/sylv/tests/qt7x7eig06-09.mm diff --git a/dynare++/sylv/testing/qt_eps3x3.mm b/mex/sources/libkorder/sylv/tests/qt_eps3x3.mm similarity index 100% rename from dynare++/sylv/testing/qt_eps3x3.mm rename to mex/sources/libkorder/sylv/tests/qt_eps3x3.mm diff --git a/dynare++/sylv/testing/qt_frank12x12.mm b/mex/sources/libkorder/sylv/tests/qt_frank12x12.mm similarity index 100% rename from dynare++/sylv/testing/qt_frank12x12.mm rename to mex/sources/libkorder/sylv/tests/qt_frank12x12.mm diff --git a/dynare++/sylv/testing/tests.cc b/mex/sources/libkorder/sylv/tests/tests.cc similarity index 100% rename from dynare++/sylv/testing/tests.cc rename to mex/sources/libkorder/sylv/tests/tests.cc diff --git a/dynare++/sylv/testing/tr2x2.mm b/mex/sources/libkorder/sylv/tests/tr2x2.mm similarity index 100% rename from dynare++/sylv/testing/tr2x2.mm rename to mex/sources/libkorder/sylv/tests/tr2x2.mm diff --git a/dynare++/sylv/testing/tr300x300.mm b/mex/sources/libkorder/sylv/tests/tr300x300.mm similarity index 100% rename from dynare++/sylv/testing/tr300x300.mm rename to mex/sources/libkorder/sylv/tests/tr300x300.mm diff --git a/dynare++/sylv/testing/tr5x5.mm b/mex/sources/libkorder/sylv/tests/tr5x5.mm similarity index 100% rename from dynare++/sylv/testing/tr5x5.mm rename to mex/sources/libkorder/sylv/tests/tr5x5.mm diff --git a/dynare++/sylv/testing/v12r.mm b/mex/sources/libkorder/sylv/tests/v12r.mm similarity index 100% rename from dynare++/sylv/testing/v12r.mm rename to mex/sources/libkorder/sylv/tests/v12r.mm diff --git a/dynare++/sylv/testing/v1715.mm b/mex/sources/libkorder/sylv/tests/v1715.mm similarity index 100% rename from dynare++/sylv/testing/v1715.mm rename to mex/sources/libkorder/sylv/tests/v1715.mm diff --git a/dynare++/sylv/testing/v1920000.mm b/mex/sources/libkorder/sylv/tests/v1920000.mm similarity index 100% rename from dynare++/sylv/testing/v1920000.mm rename to mex/sources/libkorder/sylv/tests/v1920000.mm diff --git a/dynare++/sylv/testing/v2.mm b/mex/sources/libkorder/sylv/tests/v2.mm similarity index 100% rename from dynare++/sylv/testing/v2.mm rename to mex/sources/libkorder/sylv/tests/v2.mm diff --git a/dynare++/sylv/testing/v24.mm b/mex/sources/libkorder/sylv/tests/v24.mm similarity index 100% rename from dynare++/sylv/testing/v24.mm rename to mex/sources/libkorder/sylv/tests/v24.mm diff --git a/dynare++/sylv/testing/v245.mm b/mex/sources/libkorder/sylv/tests/v245.mm similarity index 100% rename from dynare++/sylv/testing/v245.mm rename to mex/sources/libkorder/sylv/tests/v245.mm diff --git a/dynare++/sylv/testing/v245r.mm b/mex/sources/libkorder/sylv/tests/v245r.mm similarity index 100% rename from dynare++/sylv/testing/v245r.mm rename to mex/sources/libkorder/sylv/tests/v245r.mm diff --git a/dynare++/sylv/testing/v250.mm b/mex/sources/libkorder/sylv/tests/v250.mm similarity index 100% rename from dynare++/sylv/testing/v250.mm rename to mex/sources/libkorder/sylv/tests/v250.mm diff --git a/dynare++/sylv/testing/v300.mm b/mex/sources/libkorder/sylv/tests/v300.mm similarity index 100% rename from dynare++/sylv/testing/v300.mm rename to mex/sources/libkorder/sylv/tests/v300.mm diff --git a/dynare++/sylv/testing/v48000.mm b/mex/sources/libkorder/sylv/tests/v48000.mm similarity index 100% rename from dynare++/sylv/testing/v48000.mm rename to mex/sources/libkorder/sylv/tests/v48000.mm diff --git a/dynare++/sylv/testing/v490.mm b/mex/sources/libkorder/sylv/tests/v490.mm similarity index 100% rename from dynare++/sylv/testing/v490.mm rename to mex/sources/libkorder/sylv/tests/v490.mm diff --git a/dynare++/sylv/testing/v5.mm b/mex/sources/libkorder/sylv/tests/v5.mm similarity index 100% rename from dynare++/sylv/testing/v5.mm rename to mex/sources/libkorder/sylv/tests/v5.mm diff --git a/dynare++/sylv/testing/v7.mm b/mex/sources/libkorder/sylv/tests/v7.mm similarity index 100% rename from dynare++/sylv/testing/v7.mm rename to mex/sources/libkorder/sylv/tests/v7.mm diff --git a/dynare++/sylv/testing/vcheck1715.mm b/mex/sources/libkorder/sylv/tests/vcheck1715.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715.mm diff --git a/dynare++/sylv/testing/vcheck1715a.mm b/mex/sources/libkorder/sylv/tests/vcheck1715a.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715a.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715a.mm diff --git a/dynare++/sylv/testing/vcheck1715b.mm b/mex/sources/libkorder/sylv/tests/vcheck1715b.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715b.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715b.mm diff --git a/dynare++/sylv/testing/vcheck1715c.mm b/mex/sources/libkorder/sylv/tests/vcheck1715c.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715c.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715c.mm diff --git a/dynare++/sylv/testing/vcheck1715d.mm b/mex/sources/libkorder/sylv/tests/vcheck1715d.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715d.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715d.mm diff --git a/dynare++/sylv/testing/vcheck2.mm b/mex/sources/libkorder/sylv/tests/vcheck2.mm similarity index 100% rename from dynare++/sylv/testing/vcheck2.mm rename to mex/sources/libkorder/sylv/tests/vcheck2.mm diff --git a/dynare++/sylv/testing/vcheck24.mm b/mex/sources/libkorder/sylv/tests/vcheck24.mm similarity index 100% rename from dynare++/sylv/testing/vcheck24.mm rename to mex/sources/libkorder/sylv/tests/vcheck24.mm diff --git a/dynare++/sylv/testing/vcheck245.mm b/mex/sources/libkorder/sylv/tests/vcheck245.mm similarity index 100% rename from dynare++/sylv/testing/vcheck245.mm rename to mex/sources/libkorder/sylv/tests/vcheck245.mm diff --git a/dynare++/sylv/testing/vcheck245a.mm b/mex/sources/libkorder/sylv/tests/vcheck245a.mm similarity index 100% rename from dynare++/sylv/testing/vcheck245a.mm rename to mex/sources/libkorder/sylv/tests/vcheck245a.mm diff --git a/dynare++/sylv/testing/vcheck24q.mm b/mex/sources/libkorder/sylv/tests/vcheck24q.mm similarity index 100% rename from dynare++/sylv/testing/vcheck24q.mm rename to mex/sources/libkorder/sylv/tests/vcheck24q.mm diff --git a/dynare++/sylv/testing/vcheck2a.mm b/mex/sources/libkorder/sylv/tests/vcheck2a.mm similarity index 100% rename from dynare++/sylv/testing/vcheck2a.mm rename to mex/sources/libkorder/sylv/tests/vcheck2a.mm diff --git a/dynare++/sylv/testing/vcheck490.mm b/mex/sources/libkorder/sylv/tests/vcheck490.mm similarity index 100% rename from dynare++/sylv/testing/vcheck490.mm rename to mex/sources/libkorder/sylv/tests/vcheck490.mm diff --git a/dynare++/sylv/testing/vcheck490q.mm b/mex/sources/libkorder/sylv/tests/vcheck490q.mm similarity index 100% rename from dynare++/sylv/testing/vcheck490q.mm rename to mex/sources/libkorder/sylv/tests/vcheck490q.mm diff --git a/dynare++/tl/cc/equivalence.cc b/mex/sources/libkorder/tl/equivalence.cc similarity index 100% rename from dynare++/tl/cc/equivalence.cc rename to mex/sources/libkorder/tl/equivalence.cc diff --git a/dynare++/tl/cc/equivalence.hh b/mex/sources/libkorder/tl/equivalence.hh similarity index 100% rename from dynare++/tl/cc/equivalence.hh rename to mex/sources/libkorder/tl/equivalence.hh diff --git a/dynare++/tl/cc/fine_container.cc b/mex/sources/libkorder/tl/fine_container.cc similarity index 100% rename from dynare++/tl/cc/fine_container.cc rename to mex/sources/libkorder/tl/fine_container.cc diff --git a/dynare++/tl/cc/fine_container.hh b/mex/sources/libkorder/tl/fine_container.hh similarity index 100% rename from dynare++/tl/cc/fine_container.hh rename to mex/sources/libkorder/tl/fine_container.hh diff --git a/dynare++/tl/cc/fs_tensor.cc b/mex/sources/libkorder/tl/fs_tensor.cc similarity index 100% rename from dynare++/tl/cc/fs_tensor.cc rename to mex/sources/libkorder/tl/fs_tensor.cc diff --git a/dynare++/tl/cc/fs_tensor.hh b/mex/sources/libkorder/tl/fs_tensor.hh similarity index 100% rename from dynare++/tl/cc/fs_tensor.hh rename to mex/sources/libkorder/tl/fs_tensor.hh diff --git a/dynare++/tl/cc/gs_tensor.cc b/mex/sources/libkorder/tl/gs_tensor.cc similarity index 100% rename from dynare++/tl/cc/gs_tensor.cc rename to mex/sources/libkorder/tl/gs_tensor.cc diff --git a/dynare++/tl/cc/gs_tensor.hh b/mex/sources/libkorder/tl/gs_tensor.hh similarity index 100% rename from dynare++/tl/cc/gs_tensor.hh rename to mex/sources/libkorder/tl/gs_tensor.hh diff --git a/dynare++/tl/cc/int_sequence.cc b/mex/sources/libkorder/tl/int_sequence.cc similarity index 100% rename from dynare++/tl/cc/int_sequence.cc rename to mex/sources/libkorder/tl/int_sequence.cc diff --git a/dynare++/tl/cc/int_sequence.hh b/mex/sources/libkorder/tl/int_sequence.hh similarity index 100% rename from dynare++/tl/cc/int_sequence.hh rename to mex/sources/libkorder/tl/int_sequence.hh diff --git a/dynare++/tl/cc/kron_prod.cc b/mex/sources/libkorder/tl/kron_prod.cc similarity index 100% rename from dynare++/tl/cc/kron_prod.cc rename to mex/sources/libkorder/tl/kron_prod.cc diff --git a/dynare++/tl/cc/kron_prod.hh b/mex/sources/libkorder/tl/kron_prod.hh similarity index 100% rename from dynare++/tl/cc/kron_prod.hh rename to mex/sources/libkorder/tl/kron_prod.hh diff --git a/dynare++/tl/cc/normal_moments.cc b/mex/sources/libkorder/tl/normal_moments.cc similarity index 100% rename from dynare++/tl/cc/normal_moments.cc rename to mex/sources/libkorder/tl/normal_moments.cc diff --git a/dynare++/tl/cc/normal_moments.hh b/mex/sources/libkorder/tl/normal_moments.hh similarity index 100% rename from dynare++/tl/cc/normal_moments.hh rename to mex/sources/libkorder/tl/normal_moments.hh diff --git a/dynare++/tl/cc/permutation.cc b/mex/sources/libkorder/tl/permutation.cc similarity index 100% rename from dynare++/tl/cc/permutation.cc rename to mex/sources/libkorder/tl/permutation.cc diff --git a/dynare++/tl/cc/permutation.hh b/mex/sources/libkorder/tl/permutation.hh similarity index 98% rename from dynare++/tl/cc/permutation.hh rename to mex/sources/libkorder/tl/permutation.hh index fb5c2d5a73ac7feedb2972bdfeeb11318658f4d5..19c4a50ac442f89797c9ef8572026c2c663b7512 100644 --- a/dynare++/tl/cc/permutation.hh +++ b/mex/sources/libkorder/tl/permutation.hh @@ -1,6 +1,6 @@ /* * Copyright © 2004 Ondra Kamenik - * Copyright © 2019 Dynare Team + * Copyright © 2019-2023 Dynare Team * * This file is part of Dynare. * @@ -101,7 +101,7 @@ public: { } bool - operator==(const Permutation &p) + operator==(const Permutation &p) const { return permap == p.permap; } diff --git a/dynare++/tl/cc/ps_tensor.cc b/mex/sources/libkorder/tl/ps_tensor.cc similarity index 100% rename from dynare++/tl/cc/ps_tensor.cc rename to mex/sources/libkorder/tl/ps_tensor.cc diff --git a/dynare++/tl/cc/ps_tensor.hh b/mex/sources/libkorder/tl/ps_tensor.hh similarity index 99% rename from dynare++/tl/cc/ps_tensor.hh rename to mex/sources/libkorder/tl/ps_tensor.hh index 5018549c786eef13b808963ab8117c28dcdb09db..e981f31a8d221cc83012dab4dfef9d4f47086c35 100644 --- a/dynare++/tl/cc/ps_tensor.hh +++ b/mex/sources/libkorder/tl/ps_tensor.hh @@ -1,6 +1,6 @@ /* * Copyright © 2004 Ondra Kamenik - * Copyright © 2019 Dynare Team + * Copyright © 2019-2023 Dynare Team * * This file is part of Dynare. * @@ -116,7 +116,7 @@ public: per.apply(nvmax); } bool - operator==(const PerTensorDimens &td) + operator==(const PerTensorDimens &td) const { return TensorDimens::operator==(td) && per == td.per; } diff --git a/dynare++/tl/cc/pyramid_prod.cc b/mex/sources/libkorder/tl/pyramid_prod.cc similarity index 100% rename from dynare++/tl/cc/pyramid_prod.cc rename to mex/sources/libkorder/tl/pyramid_prod.cc diff --git a/dynare++/tl/cc/pyramid_prod.hh b/mex/sources/libkorder/tl/pyramid_prod.hh similarity index 100% rename from dynare++/tl/cc/pyramid_prod.hh rename to mex/sources/libkorder/tl/pyramid_prod.hh diff --git a/dynare++/tl/cc/pyramid_prod2.cc b/mex/sources/libkorder/tl/pyramid_prod2.cc similarity index 100% rename from dynare++/tl/cc/pyramid_prod2.cc rename to mex/sources/libkorder/tl/pyramid_prod2.cc diff --git a/dynare++/tl/cc/pyramid_prod2.hh b/mex/sources/libkorder/tl/pyramid_prod2.hh similarity index 100% rename from dynare++/tl/cc/pyramid_prod2.hh rename to mex/sources/libkorder/tl/pyramid_prod2.hh diff --git a/dynare++/tl/cc/rfs_tensor.cc b/mex/sources/libkorder/tl/rfs_tensor.cc similarity index 100% rename from dynare++/tl/cc/rfs_tensor.cc rename to mex/sources/libkorder/tl/rfs_tensor.cc diff --git a/dynare++/tl/cc/rfs_tensor.hh b/mex/sources/libkorder/tl/rfs_tensor.hh similarity index 100% rename from dynare++/tl/cc/rfs_tensor.hh rename to mex/sources/libkorder/tl/rfs_tensor.hh diff --git a/dynare++/tl/cc/sparse_tensor.cc b/mex/sources/libkorder/tl/sparse_tensor.cc similarity index 100% rename from dynare++/tl/cc/sparse_tensor.cc rename to mex/sources/libkorder/tl/sparse_tensor.cc diff --git a/dynare++/tl/cc/sparse_tensor.hh b/mex/sources/libkorder/tl/sparse_tensor.hh similarity index 100% rename from dynare++/tl/cc/sparse_tensor.hh rename to mex/sources/libkorder/tl/sparse_tensor.hh diff --git a/dynare++/tl/cc/stack_container.cc b/mex/sources/libkorder/tl/stack_container.cc similarity index 100% rename from dynare++/tl/cc/stack_container.cc rename to mex/sources/libkorder/tl/stack_container.cc diff --git a/dynare++/tl/cc/stack_container.hh b/mex/sources/libkorder/tl/stack_container.hh similarity index 96% rename from dynare++/tl/cc/stack_container.hh rename to mex/sources/libkorder/tl/stack_container.hh index dd0c32752876e32f684b6c483995b740b1798c0a..e5903a5509b6ae54fe1a8112dbeb9057b76f7865 100644 --- a/dynare++/tl/cc/stack_container.hh +++ b/mex/sources/libkorder/tl/stack_container.hh @@ -1,6 +1,6 @@ /* * Copyright © 2004 Ondra Kamenik - * Copyright © 2019 Dynare Team + * Copyright © 2019-2023 Dynare Team * * This file is part of Dynare. * @@ -365,10 +365,12 @@ public: getType(int i, const Symmetry &s) const override { if (i==0) - if (s[2] > 0) - return itype::zero; - else - return itype::matrix; + { + if (s[2] > 0) + return itype::zero; + else + return itype::matrix; + } TL_RAISE("Wrong stack index in XContainer::getType"); } @@ -433,20 +435,26 @@ public: if (i == 0) return itype::matrix; if (i == 1) - if (s[2] > 0) - return itype::zero; - else - return itype::matrix; + { + if (s[2] > 0) + return itype::zero; + else + return itype::matrix; + } if (i == 2) - if (s == Symmetry{1, 0, 0, 0}) - return itype::unit; - else - return itype::zero; + { + if (s == Symmetry{1, 0, 0, 0}) + return itype::unit; + else + return itype::zero; + } if (i == 3) - if (s == Symmetry{0, 1, 0, 0}) - return itype::unit; - else - return itype::zero; + { + if (s == Symmetry{0, 1, 0, 0}) + return itype::unit; + else + return itype::zero; + } TL_RAISE("Wrong stack index in ZContainer::getType"); } @@ -512,22 +520,28 @@ public: getType(int i, const Symmetry &s) const override { if (i == 0) - if (s[2] > 0 || s == Symmetry{0, 0, 0, 1}) - return itype::zero; - else - return itype::matrix; + { + if (s[2] > 0 || s == Symmetry{0, 0, 0, 1}) + return itype::zero; + else + return itype::matrix; + } if (i == 1) - if (s == Symmetry{0, 0, 1, 0}) - return itype::unit; - else - return itype::zero; + { + if (s == Symmetry{0, 0, 1, 0}) + return itype::unit; + else + return itype::zero; + } if (i == 2) return itype::zero; if (i == 3) - if (s == Symmetry{0, 0, 0, 1}) - return itype::unit; - else - return itype::zero; + { + if (s == Symmetry{0, 0, 0, 1}) + return itype::unit; + else + return itype::zero; + } TL_RAISE("Wrong stack index in GContainer::getType"); } diff --git a/dynare++/tl/cc/symmetry.cc b/mex/sources/libkorder/tl/symmetry.cc similarity index 100% rename from dynare++/tl/cc/symmetry.cc rename to mex/sources/libkorder/tl/symmetry.cc diff --git a/dynare++/tl/cc/symmetry.hh b/mex/sources/libkorder/tl/symmetry.hh similarity index 100% rename from dynare++/tl/cc/symmetry.hh rename to mex/sources/libkorder/tl/symmetry.hh diff --git a/dynare++/tl/cc/t_container.cc b/mex/sources/libkorder/tl/t_container.cc similarity index 100% rename from dynare++/tl/cc/t_container.cc rename to mex/sources/libkorder/tl/t_container.cc diff --git a/dynare++/tl/cc/t_container.hh b/mex/sources/libkorder/tl/t_container.hh similarity index 96% rename from dynare++/tl/cc/t_container.hh rename to mex/sources/libkorder/tl/t_container.hh index 884131eb8f86c539899cf81e3e975b93efded395..8aef209f38e487436f5c30ba30bf7f317ec3064d 100644 --- a/dynare++/tl/cc/t_container.hh +++ b/mex/sources/libkorder/tl/t_container.hh @@ -75,8 +75,6 @@ #include <memory> #include <utility> -#include <matio.h> - // ltsym predicate /* We need a predicate on strict weak ordering of symmetries. */ @@ -225,21 +223,6 @@ public: } } - /* Output to the MAT file. */ - void - writeMat(mat_t *fd, const std::string &prefix) const - { - for (auto &it : *this) - { - std::string lname = prefix + "_g"; - const Symmetry &sym = it.first; - for (int i = 0; i < sym.num(); i++) - lname += '_' + std::to_string(sym[i]); - ConstTwoDMatrix m(*(it.second)); - m.writeMat(fd, lname); - } - } - /* Output to the Memory Map. */ void writeMMap(std::map<std::string, ConstTwoDMatrix> &mm, const std::string &prefix) const diff --git a/dynare++/tl/cc/t_polynomial.cc b/mex/sources/libkorder/tl/t_polynomial.cc similarity index 100% rename from dynare++/tl/cc/t_polynomial.cc rename to mex/sources/libkorder/tl/t_polynomial.cc diff --git a/dynare++/tl/cc/t_polynomial.hh b/mex/sources/libkorder/tl/t_polynomial.hh similarity index 100% rename from dynare++/tl/cc/t_polynomial.hh rename to mex/sources/libkorder/tl/t_polynomial.hh diff --git a/dynare++/tl/cc/tensor.cc b/mex/sources/libkorder/tl/tensor.cc similarity index 100% rename from dynare++/tl/cc/tensor.cc rename to mex/sources/libkorder/tl/tensor.cc diff --git a/dynare++/tl/cc/tensor.hh b/mex/sources/libkorder/tl/tensor.hh similarity index 97% rename from dynare++/tl/cc/tensor.hh rename to mex/sources/libkorder/tl/tensor.hh index 76396e83a336c7acd191edaad09ddaf118a6659c..0d4150394144f084896eea463a4e366c628a1e97 100644 --- a/dynare++/tl/cc/tensor.hh +++ b/mex/sources/libkorder/tl/tensor.hh @@ -1,6 +1,6 @@ /* * Copyright © 2004 Ondra Kamenik - * Copyright © 2019 Dynare Team + * Copyright © 2019-2023 Dynare Team * * This file is part of Dynare. * @@ -256,6 +256,11 @@ public: UTensor &operator=(const UTensor &) = delete; UTensor &operator=(UTensor &&) = delete; + // Ensure that the methods of the parent class are not overloaded + using Tensor::increment; + using Tensor::decrement; + using Tensor::getOffset; + static void increment(IntSequence &v, int nv); static void decrement(IntSequence &v, int nv); static void increment(IntSequence &v, const IntSequence &nvmx); @@ -292,6 +297,10 @@ public: FTensor &operator=(const FTensor &) = delete; FTensor &operator=(FTensor &&) = delete; + // Ensure that the methods of the parent class are not overloaded + using Tensor::decrement; + using Tensor::getOffset; + static void decrement(IntSequence &v, int nv); static int getOffset(const IntSequence &v, int nv) diff --git a/dynare++/tl/testing/Makefile.am b/mex/sources/libkorder/tl/tests/Makefile.am similarity index 100% rename from dynare++/tl/testing/Makefile.am rename to mex/sources/libkorder/tl/tests/Makefile.am diff --git a/dynare++/tl/testing/factory.cc b/mex/sources/libkorder/tl/tests/factory.cc similarity index 100% rename from dynare++/tl/testing/factory.cc rename to mex/sources/libkorder/tl/tests/factory.cc diff --git a/dynare++/tl/testing/factory.hh b/mex/sources/libkorder/tl/tests/factory.hh similarity index 100% rename from dynare++/tl/testing/factory.hh rename to mex/sources/libkorder/tl/tests/factory.hh diff --git a/dynare++/tl/testing/monoms.cc b/mex/sources/libkorder/tl/tests/monoms.cc similarity index 100% rename from dynare++/tl/testing/monoms.cc rename to mex/sources/libkorder/tl/tests/monoms.cc diff --git a/dynare++/tl/testing/monoms.hh b/mex/sources/libkorder/tl/tests/monoms.hh similarity index 100% rename from dynare++/tl/testing/monoms.hh rename to mex/sources/libkorder/tl/tests/monoms.hh diff --git a/dynare++/tl/testing/tests.cc b/mex/sources/libkorder/tl/tests/tests.cc similarity index 100% rename from dynare++/tl/testing/tests.cc rename to mex/sources/libkorder/tl/tests/tests.cc diff --git a/dynare++/tl/cc/tl_exception.hh b/mex/sources/libkorder/tl/tl_exception.hh similarity index 100% rename from dynare++/tl/cc/tl_exception.hh rename to mex/sources/libkorder/tl/tl_exception.hh diff --git a/dynare++/tl/cc/tl_static.cc b/mex/sources/libkorder/tl/tl_static.cc similarity index 100% rename from dynare++/tl/cc/tl_static.cc rename to mex/sources/libkorder/tl/tl_static.cc diff --git a/dynare++/tl/cc/tl_static.hh b/mex/sources/libkorder/tl/tl_static.hh similarity index 100% rename from dynare++/tl/cc/tl_static.hh rename to mex/sources/libkorder/tl/tl_static.hh diff --git a/dynare++/tl/cc/twod_matrix.cc b/mex/sources/libkorder/tl/twod_matrix.cc similarity index 85% rename from dynare++/tl/cc/twod_matrix.cc rename to mex/sources/libkorder/tl/twod_matrix.cc index 327445eafd745d5ff8c03072b9ff7ea0e05bbb43..1e308dc08fc9b1437b308d52814604c45cb816b2 100644 --- a/dynare++/tl/cc/twod_matrix.cc +++ b/mex/sources/libkorder/tl/twod_matrix.cc @@ -51,25 +51,6 @@ ConstTwoDMatrix::ConstTwoDMatrix(int first_row, int num, const ConstTwoDMatrix & { } -void -ConstTwoDMatrix::writeMat(mat_t *fd, const std::string &vname) const -{ - size_t dims[2]; - dims[0] = nrows(); - dims[1] = ncols(); - auto data = std::make_unique<double[]>(nrows()*ncols()); - - for (int j = 0; j < ncols(); j++) - for (int i = 0; i < nrows(); i++) - data[j*nrows()+i] = get(i, j); - - matvar_t *v = Mat_VarCreate(vname.c_str(), MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, data.get(), 0); - - Mat_VarWrite(fd, v, MAT_COMPRESSION_NONE); - - Mat_VarFree(v); -} - TwoDMatrix & TwoDMatrix::operator=(const ConstTwoDMatrix &m) { diff --git a/dynare++/tl/cc/twod_matrix.hh b/mex/sources/libkorder/tl/twod_matrix.hh similarity index 96% rename from dynare++/tl/cc/twod_matrix.hh rename to mex/sources/libkorder/tl/twod_matrix.hh index 1099c031fb772f96a9f922194a563bb25e89a8e0..728a7691ce27fa64a7092dbacd4cde3077d7ec2b 100644 --- a/dynare++/tl/cc/twod_matrix.hh +++ b/mex/sources/libkorder/tl/twod_matrix.hh @@ -34,8 +34,6 @@ #include "GeneralMatrix.hh" -#include <matio.h> - #include <string> #include <utility> @@ -75,8 +73,6 @@ public: ConstTwoDMatrix &operator=(const ConstTwoDMatrix &v) = delete; ConstTwoDMatrix &operator=(ConstTwoDMatrix &&v) = delete; - - void writeMat(mat_t *fd, const std::string &vname) const; }; class TwoDMatrix : public GeneralMatrix @@ -200,12 +196,6 @@ public: // Saves the matrix to a text file void save(const std::string &fname) const; - - void - writeMat(mat_t *fd, const std::string &vname) const - { - ConstTwoDMatrix(*this).writeMat(fd, vname); - } }; #endif diff --git a/dynare++/src/dynare_exception.hh b/mex/sources/libkorder/utils/dynare_exception.hh similarity index 100% rename from dynare++/src/dynare_exception.hh rename to mex/sources/libkorder/utils/dynare_exception.hh diff --git a/dynare++/utils/cc/exception.hh b/mex/sources/libkorder/utils/exception.hh similarity index 100% rename from dynare++/utils/cc/exception.hh rename to mex/sources/libkorder/utils/exception.hh diff --git a/dynare++/utils/cc/int_power.cc b/mex/sources/libkorder/utils/int_power.cc similarity index 100% rename from dynare++/utils/cc/int_power.cc rename to mex/sources/libkorder/utils/int_power.cc diff --git a/dynare++/utils/cc/int_power.hh b/mex/sources/libkorder/utils/int_power.hh similarity index 100% rename from dynare++/utils/cc/int_power.hh rename to mex/sources/libkorder/utils/int_power.hh diff --git a/dynare++/utils/cc/pascal_triangle.cc b/mex/sources/libkorder/utils/pascal_triangle.cc similarity index 100% rename from dynare++/utils/cc/pascal_triangle.cc rename to mex/sources/libkorder/utils/pascal_triangle.cc diff --git a/dynare++/utils/cc/pascal_triangle.hh b/mex/sources/libkorder/utils/pascal_triangle.hh similarity index 100% rename from dynare++/utils/cc/pascal_triangle.hh rename to mex/sources/libkorder/utils/pascal_triangle.hh diff --git a/dynare++/utils/cc/sthread.cc b/mex/sources/libkorder/utils/sthread.cc similarity index 100% rename from dynare++/utils/cc/sthread.cc rename to mex/sources/libkorder/utils/sthread.cc diff --git a/dynare++/utils/cc/sthread.hh b/mex/sources/libkorder/utils/sthread.hh similarity index 100% rename from dynare++/utils/cc/sthread.hh rename to mex/sources/libkorder/utils/sthread.hh diff --git a/mex/sources/libkordersim/partitions.f08 b/mex/sources/libkordersim/partitions.f08 index 5272d4bb98016db12a7198a348d7ae1d93c04c5a..878cea43c3382cc1db716dc8eb22e134618a8ee3 100644 --- a/mex/sources/libkordersim/partitions.f08 +++ b/mex/sources/libkordersim/partitions.f08 @@ -1,8 +1,8 @@ ! Provides subroutines to manipulate indexes representing elements of ! a partition for a given integer ! i.e. elements p = (α₁,…,αₘ) where each αᵢ ∈ { 0, ..., n-1 } -! -! Copyright © 2021 Dynare Team + +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -23,7 +23,7 @@ module partitions use pascal use sort use iso_fortran_env - implicit none + implicit none (type, external) ! index represents the aforementioned (α₁,…,αₘ) objects type index @@ -354,7 +354,7 @@ end module partitions ! program test ! use partitions ! use pascal -! implicit none +! implicit none (type, external) ! type(index) :: uidx, fidx, i1, i2 ! integer, dimension(:), allocatable :: folded ! integer :: i, uj, n, d, j, nb_folded_idcs @@ -425,4 +425,4 @@ end module partitions ! print '(i3)', (nbeq(i), i=1,nb_folded_idcs) ! print '(i4)', (off(i), i=1,nb_folded_idcs) -! end program test \ No newline at end of file +! end program test diff --git a/mex/sources/libkordersim/pascal.f08 b/mex/sources/libkordersim/pascal.f08 index 11978b1ad7afaf6590f516132dcef7ab7450333a..57fa680557f1374346bc08d7d538956f2abe18f3 100644 --- a/mex/sources/libkordersim/pascal.f08 +++ b/mex/sources/libkordersim/pascal.f08 @@ -1,6 +1,6 @@ ! Provides a subroutine to build Pascal's triangle -! -! Copyright © 2021 Dynare Team + +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -18,7 +18,7 @@ ! along with Dynare. If not, see <https://www.gnu.org/licenses/>. module pascal - implicit none + implicit none (type, external) type line integer, dimension(:), allocatable :: coeffs @@ -107,4 +107,4 @@ end module pascal ! print '(i2)', multinomial([1,2,3], d, p) ! should print 60 ! print '(i2)', multinomial([0,0,0,3], d, p) ! should print 20 -! end program test \ No newline at end of file +! end program test diff --git a/mex/sources/libkordersim/simulation.f08 b/mex/sources/libkordersim/simulation.f08 index 387f09bcf613e6a7143e31e8391c00a8605e4d2d..4a81f51a9031406f6074572814f57d20e382038a 100644 --- a/mex/sources/libkordersim/simulation.f08 +++ b/mex/sources/libkordersim/simulation.f08 @@ -1,7 +1,8 @@ ! Necessary routines and functions to carry out simulations ! ! A first step is to get the associated -! Copyright © 2021 Dynare Team + +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -22,7 +23,7 @@ module simulation use iso_fortran_env use partitions use lapack - implicit none + implicit none (type, external) ! Used to store the folded decision rule tensors type :: pol diff --git a/mex/sources/libkordersim/sort.f08 b/mex/sources/libkordersim/sort.f08 index 225f37852af5eaf7544fbb6173e3c7f8f2627abc..a5e9dc11339fb3d5fbd847789665076b1d0c4b4a 100644 --- a/mex/sources/libkordersim/sort.f08 +++ b/mex/sources/libkordersim/sort.f08 @@ -1,7 +1,7 @@ ! Provides a subroutine to sort integer arrays in ascending order ! As the addressed arrays are small, I use the insertion sort algorithm -! -! Copyright © 2021 Dynare Team + +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -19,7 +19,7 @@ ! along with Dynare. If not, see <https://www.gnu.org/licenses/>. module sort - implicit none + implicit none (type, external) contains subroutine sort_int(l) @@ -36,4 +36,4 @@ contains end do end subroutine sort_int -end module sort \ No newline at end of file +end module sort diff --git a/mex/sources/libkordersim/struct.f08 b/mex/sources/libkordersim/struct.f08 index c2a8e03370bb34f0f0148679584ea2197eb487df..a88b386d0b8a5447ed10cb25e736de6cc4eb46ae 100644 --- a/mex/sources/libkordersim/struct.f08 +++ b/mex/sources/libkordersim/struct.f08 @@ -1,4 +1,4 @@ -! Copyright © 2021 Dynare Team +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -14,11 +14,12 @@ ! ! You should have received a copy of the GNU General Public License ! along with Dynare. If not, see <https://www.gnu.org/licenses/>. + module struct use iso_fortran_env use iso_c_binding use matlab_mex - implicit none + implicit none (type, external) contains @@ -33,4 +34,4 @@ module struct get_int_field = int(mxGetScalar(tmp)) end function get_int_field -end module struct \ No newline at end of file +end module struct diff --git a/mex/sources/local_state_space_iterations/local_state_space_iteration_3.f08 b/mex/sources/local_state_space_iterations/local_state_space_iteration_3.f08 index 64a567fcbc11447a90dfb1abe6c2fbac96241943..588b495c24aeb906ff1a42283aacd52d18007e73 100644 --- a/mex/sources/local_state_space_iterations/local_state_space_iteration_3.f08 +++ b/mex/sources/local_state_space_iterations/local_state_space_iteration_3.f08 @@ -1,4 +1,4 @@ -! Copyright © 2022 Dynare Team +! Copyright © 2022-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -20,7 +20,7 @@ module pparticle_3 use matlab_mex use partitions - implicit none + implicit none (type, external) type tdata_3 integer :: n, m, s, q, numthreads, xx_size, uu_size, xxx_size, uuu_size @@ -71,15 +71,15 @@ contains ! + first n folded indices for (1/6)ghxxx·ŷ⊗ŷ⊗ŷ do j=1,td3%n td3%y3(im,is) = td3%y3(im,is)+& - &(0.5*td3%ghxss(j,im)+td3%ghx(j,im))*td3%yhat3(j,is)+& - &(0.5*td3%ghxx(j,im)+(1./6.)*td3%ghxxx(j,im)*td3%yhat3(1, is))*& + &(0.5_real64*td3%ghxss(j,im)+td3%ghx(j,im))*td3%yhat3(j,is)+& + &(0.5_real64*td3%ghxx(j,im)+(1._real64/6._real64)*td3%ghxxx(j,im)*td3%yhat3(1, is))*& &td3%yhat3(1, is)*td3%yhat3(j,is) ! y3 += ghxu·ŷ⊗ε ! + first n*q folded indices of (3/6)·ghxxu·ŷ⊗ŷ⊗ε do k=1,td3%q td3%y3(im,is) = td3%y3(im,is) + & &(td3%ghxu(td3%q*(j-1)+k,im)+& - &0.5*td3%ghxxu(td3%q*(j-1)+k,im)*td3%yhat3(1, is))*& + &0.5_real64*td3%ghxxu(td3%q*(j-1)+k,im)*td3%yhat3(1, is))*& &td3%yhat3(j, is)*td3%e(k, is) end do end do @@ -88,12 +88,12 @@ contains ! + first n*q folded indices of (3/6)·ghxuu·ŷ⊗ε⊗ε do j=1,td3%q td3%y3(im,is) = td3%y3(im,is) + & - &(0.5*td3%ghuss(j,im)+td3%ghu(j,im))*td3%e(j,is) + & - &(0.5*td3%ghuu(j,im)+(1./6.)*td3%ghuuu(j,im)*& + &(0.5_real64*td3%ghuss(j,im)+td3%ghu(j,im))*td3%e(j,is) + & + &(0.5_real64*td3%ghuu(j,im)+(1._real64/6._real64)*td3%ghuuu(j,im)*& &td3%e(1, is))*td3%e(1, is)*td3%e(j, is) do k=1,td3%n td3%y3(im,is) = td3%y3(im,is) + & - &0.5*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& + &0.5_real64*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& &td3%yhat3(k, is)*td3%e(1, is)*td3%e(j, is) end do end do @@ -103,12 +103,12 @@ contains ! + remaining terms of (3/6)·ghxxu·ŷ⊗ŷ⊗ε do j=td3%n+1,td3%xx_size td3%y3(im,is) = td3%y3(im,is) + & - &(0.5*td3%ghxx(j,im)+(1./6.)*td3%ghxxx(j,im)*td3%yhat3(1, is))*& + &(0.5_real64*td3%ghxx(j,im)+(1._real64/6._real64)*td3%ghxxx(j,im)*td3%yhat3(1, is))*& &td3%yhat3(td3%xx_idcs(j)%coor(1), is)*& &td3%yhat3(td3%xx_idcs(j)%coor(2), is) do k=1,td3%q td3%y3(im,is) = td3%y3(im,is)+& - &0.5*td3%ghxxu(td3%q*(j-1)+k,im)*& + &0.5_real64*td3%ghxxu(td3%q*(j-1)+k,im)*& &td3%yhat3(td3%xx_idcs(j)%coor(1), is)*& &td3%yhat3(td3%xx_idcs(j)%coor(2), is)*& &td3%e(k, is) @@ -120,12 +120,12 @@ contains ! + remaining terms of (3/6)·ghxuu·ŷ⊗ε⊗ε do j=td3%q+1,td3%uu_size td3%y3(im,is) = td3%y3(im,is) + & - &(0.5*td3%ghuu(j,im)+(1./6.)*td3%ghuuu(j,im)*td3%e(1, is))*& + &(0.5_real64*td3%ghuu(j,im)+(1._real64/6._real64)*td3%ghuuu(j,im)*td3%e(1, is))*& &td3%e(td3%uu_idcs(j)%coor(1), is)*& &td3%e(td3%uu_idcs(j)%coor(2), is) do k=1,td3%n td3%y3(im,is) = td3%y3(im,is) + & - &0.5*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& + &0.5_real64*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& &td3%yhat3(k, is)*& &td3%e(td3%uu_idcs(j)%coor(1), is)*& &td3%e(td3%uu_idcs(j)%coor(2), is) @@ -134,7 +134,7 @@ contains ! y3 += remaining (1/6)·ghxxx·ŷ⊗ŷ⊗ŷ terms do j=td3%xx_size+1,td3%xxx_size td3%y3(im,is) = td3%y3(im,is)+& - &(1./6.)*td3%ghxxx(j,im)*& + &(1._real64/6._real64)*td3%ghxxx(j,im)*& &td3%yhat3(td3%xxx_idcs(j)%coor(1), is)*& &td3%yhat3(td3%xxx_idcs(j)%coor(2), is)*& &td3%yhat3(td3%xxx_idcs(j)%coor(3), is) @@ -142,7 +142,7 @@ contains ! y3 += remaining (1/6)ghuuu·ε⊗ε⊗ε terms do j=td3%uu_size+1,td3%uuu_size td3%y3(im,is) = td3%y3(im,is) + & - &(1./6.)*td3%ghuuu(j,im)*& + &(1._real64/6._real64)*td3%ghuuu(j,im)*& &td3%e(td3%uuu_idcs(j)%coor(1), is)*& &td3%e(td3%uuu_idcs(j)%coor(2), is)*& &td3%e(td3%uuu_idcs(j)%coor(3), is) @@ -198,11 +198,11 @@ contains do j=1,td3%n td3%y1(im,is) = td3%y1(im,is) + td3%ghx(j,im)*td3%yhat1(j,is) td3%y2(im,is) = td3%y2(im,is) + td3%ghx(j,im)*td3%yhat2(j,is) +& - &0.5*td3%ghxx(j,im)*td3%yhat1(1, is)*td3%yhat1(j, is) + &0.5_real64*td3%ghxx(j,im)*td3%yhat1(1, is)*td3%yhat1(j, is) td3%y3(im,is) = td3%y3(im,is) + td3%ghx(j,im)*td3%yhat3(j,is) +& - &0.5*td3%ghxss(j,im)*td3%yhat1(j,is) +& + &0.5_real64*td3%ghxss(j,im)*td3%yhat1(j,is) +& &td3%ghxx(j,im)*td3%yhat1(1, is)*td3%yhat2(j, is)+& - &(1./6.)*td3%ghxxx(j,im)*td3%yhat1(1, is)*& + &(1._real64/6._real64)*td3%ghxxx(j,im)*td3%yhat1(1, is)*& &td3%yhat1(1, is)*td3%yhat1(j,is) ! y2 += + ghxu·ŷ1⊗ε ! y3 += + ghxu·ŷ1⊗ε + ghxu·ŷ2⊗ε @@ -214,7 +214,7 @@ contains td3%y3(im,is) = td3%y3(im,is)+& &td3%ghxu(td3%q*(j-1)+k,im)*& &(td3%yhat1(j, is)+td3%yhat2(j, is))*td3%e(k, is)+& - &0.5*td3%ghxxu(td3%q*(j-1)+k,im)*td3%yhat1(1, is)*& + &0.5_real64*td3%ghxxu(td3%q*(j-1)+k,im)*td3%yhat1(1, is)*& &td3%yhat1(j, is)*td3%e(k, is) end do end do @@ -227,14 +227,14 @@ contains x = td3%ghu(j,im)*td3%e(j,is) y = td3%ghuu(j,im)*td3%e(1, is)*td3%e(j, is) td3%y1(im,is) = td3%y1(im,is) + x - td3%y2(im,is) = td3%y2(im,is) + x + 0.5*y + td3%y2(im,is) = td3%y2(im,is) + x + 0.5_real64*y td3%y3(im,is) = td3%y3(im,is) + x + y +& &td3%ghuss(j,im)*td3%e(j,is)+& - &(1./6.)*td3%ghuuu(j,im)*td3%e(1, is)*td3%e(1, is)*& + &(1._real64/6._real64)*td3%ghuuu(j,im)*td3%e(1, is)*td3%e(1, is)*& &td3%e(j, is) do k=1,td3%n td3%y3(im,is) = td3%y3(im,is) + & - &0.5*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& + &0.5_real64*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& &td3%yhat1(k, is)*td3%e(1, is)*td3%e(j, is) end do end do @@ -245,19 +245,19 @@ contains ! + remaining terms of (3/6)·ghxxu·ŷ1⊗ŷ1⊗ε do j=td3%n+1,td3%xx_size td3%y2(im,is) = td3%y2(im,is) + & - &0.5*td3%ghxx(j,im)*& + &0.5_real64*td3%ghxx(j,im)*& &td3%yhat1(td3%xx_idcs(j)%coor(1), is)*& &td3%yhat1(td3%xx_idcs(j)%coor(2), is) td3%y3(im,is) = td3%y3(im,is) + & &td3%ghxx(j,im)*& &td3%yhat1(td3%xx_idcs(j)%coor(1), is)*& &td3%yhat2(td3%xx_idcs(j)%coor(2), is)+& - &(1./6.)*td3%ghxxx(j,im)*td3%yhat1(1, is)*& + &(1._real64/6._real64)*td3%ghxxx(j,im)*td3%yhat1(1, is)*& &td3%yhat1(td3%xx_idcs(j)%coor(1), is)*& &td3%yhat1(td3%xx_idcs(j)%coor(2), is) do k=1,td3%n td3%y3(im,is) = td3%y3(im,is) + & - &0.5*td3%ghxxu(td3%q*(j-1)+k,im)*& + &0.5_real64*td3%ghxxu(td3%q*(j-1)+k,im)*& &td3%yhat1(td3%xx_idcs(j)%coor(1), is)*& &td3%yhat1(td3%xx_idcs(j)%coor(2), is)*& &td3%e(k, is) @@ -272,14 +272,14 @@ contains x = td3%ghuu(j,im)*& &td3%e(td3%uu_idcs(j)%coor(1), is)*& &td3%e(td3%uu_idcs(j)%coor(2), is) - td3%y2(im,is) = td3%y2(im,is)+0.5*x + td3%y2(im,is) = td3%y2(im,is)+0.5_real64*x td3%y3(im,is) = td3%y3(im,is)+x+& - &(1./6.)*td3%ghuuu(j,im)*td3%e(1, is)*& + &(1._real64/6._real64)*td3%ghuuu(j,im)*td3%e(1, is)*& &td3%e(td3%uu_idcs(j)%coor(1), is)*& &td3%e(td3%uu_idcs(j)%coor(2), is) do k=1,td3%n td3%y3(im,is) = td3%y3(im,is) + & - &0.5*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& + &0.5_real64*td3%ghxuu(td3%uu_size*(k-1)+j,im)*& &td3%yhat1(k, is)*& &td3%e(td3%uu_idcs(j)%coor(1), is)*& &td3%e(td3%uu_idcs(j)%coor(2), is) @@ -288,7 +288,7 @@ contains ! y3 += remaining (1/6)·ghxxx·ŷ⊗ŷ⊗ŷ terms do j=td3%xx_size+1,td3%xxx_size td3%y3(im,is) = td3%y3(im,is)+& - &(1./6.)*td3%ghxxx(j,im)*& + &(1._real64/6._real64)*td3%ghxxx(j,im)*& &td3%yhat1(td3%xxx_idcs(j)%coor(1), is)*& &td3%yhat1(td3%xxx_idcs(j)%coor(2), is)*& &td3%yhat1(td3%xxx_idcs(j)%coor(3), is) @@ -296,7 +296,7 @@ contains ! y3 += remaining (1/6)ghuuu·ε⊗ε⊗ε terms do j=td3%uu_size+1,td3%uuu_size td3%y3(im,is) = td3%y3(im,is) + & - &(1./6.)*td3%ghuuu(j,im)*& + &(1._real64/6._real64)*td3%ghuuu(j,im)*& &td3%e(td3%uuu_idcs(j)%coor(1), is)*& &td3%e(td3%uuu_idcs(j)%coor(2), is)*& &td3%e(td3%uuu_idcs(j)%coor(3), is) @@ -340,7 +340,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use partitions use pthread use pparticle_3 - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs @@ -577,4 +577,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') end do end if -end subroutine mexFunction \ No newline at end of file +end subroutine mexFunction diff --git a/mex/sources/local_state_space_iterations/local_state_space_iteration_k.f08 b/mex/sources/local_state_space_iterations/local_state_space_iteration_k.f08 index b1632da6744d057ee2cb7ecfdae984a7484592c6..ce59cc47b5e7c82e8251f0247c43dd62a04b9e64 100644 --- a/mex/sources/local_state_space_iterations/local_state_space_iteration_k.f08 +++ b/mex/sources/local_state_space_iterations/local_state_space_iteration_k.f08 @@ -1,4 +1,4 @@ -! Copyright © 2021-2022 Dynare Team +! Copyright © 2021-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -21,7 +21,7 @@ module pparticle use simulation use matlab_mex - implicit none + implicit none (type, external) type tdata integer :: nm, nys, endo_nbr, nvar, order, nrestricted, nparticles @@ -94,7 +94,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use matlab_mex use pthread use pparticle - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs diff --git a/mex/sources/logarithmic_reduction/mexFunction.f08 b/mex/sources/logarithmic_reduction/mexFunction.f08 index 2142e185477a36e1e1b8bd2cc0098b9d3d1462ae..08a8b8a648e66f52c6902a86f7b58659ba960d2c 100644 --- a/mex/sources/logarithmic_reduction/mexFunction.f08 +++ b/mex/sources/logarithmic_reduction/mexFunction.f08 @@ -1,4 +1,4 @@ -! Copyright © 2022 Dynare Team +! Copyright © 2022-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -22,7 +22,7 @@ module l_reduction use lapack use blas use matlab_mex - implicit none + implicit none (type, external) contains @@ -126,7 +126,7 @@ end module l_reduction subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use l_reduction - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs @@ -210,4 +210,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') end if end if -end subroutine mexFunction \ No newline at end of file +end subroutine mexFunction diff --git a/mex/sources/matlab_mex.F08 b/mex/sources/matlab_mex.F08 index 601b78e59f2e7b6f9c3850a788dd9b67a58c34d4..fd8664e72ff049db36fa8caa33e88c518220ad9e 100644 --- a/mex/sources/matlab_mex.F08 +++ b/mex/sources/matlab_mex.F08 @@ -1,4 +1,4 @@ -! Fortran 2008 interface for a subset of MEX functions +! Fortran 2018 interface for a subset of MEX functions ! ! For some functions, exposing the C interface directly is not convenient (e.g. ! when they use C strings, since those need to be null-terminated, or when they @@ -28,7 +28,7 @@ ! Fortran compiler better optimize the code (in some cases, this will avoid ! array copies) -! Copyright © 2019-2022 Dynare Team +! Copyright © 2019-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -66,7 +66,7 @@ module matlab_mat use iso_fortran_env use iso_c_binding - implicit none + implicit none (type, external) !! C Data Types integer, parameter :: mwSize = c_size_t @@ -411,7 +411,7 @@ end module matlab_mat !!! Listed in same order as https://fr.mathworks.com/help/matlab/call-mex-files-1.html module matlab_mex use matlab_mat - implicit none + implicit none (type, external) interface integer(c_int) function mexCallMATLAB_internal(nlhs, plhs, nrhs, prhs, functionName) bind(c, name="mexCallMATLAB"//API_VER) diff --git a/mex/sources/mjdgges/mjdgges.F08 b/mex/sources/mjdgges/mjdgges.F08 index a821fa83b7d9e6c2ab99e9c871433d0dedee34f3..215a584d969533dd9e271af77d5fe67dfccd92dd 100644 --- a/mex/sources/mjdgges/mjdgges.F08 +++ b/mex/sources/mjdgges/mjdgges.F08 @@ -18,7 +18,7 @@ ! eigval [complex] (n×1) vector of generalized eigenvalues ! info [integer] scalar, error code of dgges (or 30 if eigenvalue close to 0÷0) -! Copyright © 2006-2022 Dynare Team +! Copyright © 2006-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -39,7 +39,7 @@ module select_fct_mod use iso_fortran_env - implicit none + implicit none (type, external) real(real64) :: criterium contains @@ -58,7 +58,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use select_fct_mod use matlab_mex use lapack - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs diff --git a/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc b/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc index ff7eb159c94802be592523e96875c69fc0b47b92..bcad9f6cd30717c11dacbef1d0e631cc2fbb9513 100644 --- a/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc +++ b/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc @@ -129,8 +129,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) mexErrMsgTxt("M_.dynamic_g1_sparse_colval should have the same length as M_.dynamic_g1_sparse_rowval"); const mxArray *g1_sparse_colptr_mx {mxGetField(M_mx, 0, "dynamic_g1_sparse_colptr")}; - if (!(mxIsInt32(g1_sparse_colptr_mx) && mxGetNumberOfElements(g1_sparse_colptr_mx) != 3*static_cast<size_t>(ny)+1)) - mexErrMsgTxt(("M_.dynamic_g1_sparse_colptr should be an int32 vector with " + std::to_string(3*ny+1) + " elements").c_str()); + if (!(mxIsInt32(g1_sparse_colptr_mx) && mxGetNumberOfElements(g1_sparse_colptr_mx) == static_cast<size_t>(3*ny+nx+1))) + mexErrMsgTxt(("M_.dynamic_g1_sparse_colptr should be an int32 vector with " + std::to_string(3*ny+nx+1) + " elements").c_str()); #if MX_HAS_INTERLEAVED_COMPLEX const int32_T *g1_sparse_colptr {mxGetInt32s(g1_sparse_colptr_mx)}; #else diff --git a/mex/sources/pthread.F08 b/mex/sources/pthread.F08 index cf7289c40e8b914841ae863beb70030324fa4625..b522bf72e1bde6eaaff37d3742e5fb8bd569502e 100644 --- a/mex/sources/pthread.F08 +++ b/mex/sources/pthread.F08 @@ -1,4 +1,4 @@ -! Copyright © 2022 Dynare Team +! Copyright © 2022-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -18,7 +18,7 @@ ! Wrapper around pthread_create and pthread_join C routines for POSIX multithreading module pthread use iso_c_binding - implicit none + implicit none (type, external) private public :: c_pthread_create diff --git a/mex/sources/riccati_update/mexFunction.f08 b/mex/sources/riccati_update/mexFunction.f08 index f77555897a31237e3cb8ffd31353828fdea23148..7443a604c7320117c6d3bd497858ba6e42034394 100644 --- a/mex/sources/riccati_update/mexFunction.f08 +++ b/mex/sources/riccati_update/mexFunction.f08 @@ -1,4 +1,4 @@ -! Copyright © 2022 Dynare Team +! Copyright © 2022-2023 Dynare Team ! ! This file is part of Dynare. ! @@ -28,7 +28,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') use matlab_mex use blas - implicit none + implicit none (type, external) type(c_ptr), dimension(*), intent(in), target :: prhs type(c_ptr), dimension(*), intent(out) :: plhs @@ -36,7 +36,7 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') real(real64), dimension(:,:), pointer, contiguous :: P, T, K, Z, Q, Pnew real(real64), dimension(:,:), allocatable :: tmp1, tmp2 - integer :: i, j, n, r + integer :: i, n, r character(kind=c_char, len=2) :: num2str ! 0. Checking the consistency and validity of input arguments @@ -95,4 +95,4 @@ subroutine mexFunction(nlhs, plhs, nrhs, prhs) bind(c, name='mexFunction') ! Pnew <- tmp1*T' + Pnew call matmul_add("N", "T", 1._real64, tmp1, T, 1._real64, Pnew) -end subroutine mexFunction \ No newline at end of file +end subroutine mexFunction diff --git a/mex/sources/sobol/gaussian.hh b/mex/sources/sobol/gaussian.hh index 4339161143ac923b2b96a1e4951dd62b6612fcab..7352f50f801919ab47f93db452009ece686d0054 100644 --- a/mex/sources/sobol/gaussian.hh +++ b/mex/sources/sobol/gaussian.hh @@ -2,7 +2,7 @@ ** ** Pseudo code of the algorithm is given at http://home.online.no/~pjacklam/notes/invnorm ** -** Copyright © 2010-2019 Dynare Team +** Copyright © 2010-2023 Dynare Team ** ** This file is part of Dynare. ** @@ -25,6 +25,7 @@ #include <cmath> #include <limits> #include <algorithm> +#include <numbers> #include <omp.h> @@ -106,7 +107,7 @@ icdf(const T uniform) { T tmp, tmp_; tmp = .5*erfc(-gaussian/sqrt(2.0))-uniform; - tmp_ = tmp*sqrt(2*M_PI)*exp(.5*gaussian*gaussian); + tmp_ = tmp*sqrt(2*numbers::pi)*exp(.5*gaussian*gaussian); gaussian = gaussian - tmp_/(1+.5*gaussian*tmp_); } if (uniform == 0) diff --git a/mex/sources/sobol/initialize_v_array.hh b/mex/sources/sobol/initialize_v_array.hh deleted file mode 100644 index a5b367193855f24febe0553a108abbc6d1bd52d7..0000000000000000000000000000000000000000 --- a/mex/sources/sobol/initialize_v_array.hh +++ /dev/null @@ -1,28 +0,0 @@ -template<typename T> -int -initialize_v_array(int dim_max, int log_max, T **v) -/* -** This function initializes the v array used in the sobol routine. -** -** Original files downloaded from http://people.sc.fsu.edu/~burkardt/cpp_src/sobol/ (version 17-Feb-2009 09:46) -** -** Copyright © 2009 John Burkardt -** Copyright © 2010-2017 Dynare Team -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU Lesser General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program 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 Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ -{ -#include "initialize_v_array.inc" - return 1; -} diff --git a/mex/sources/sobol/initialize_v_array.inc b/mex/sources/sobol/initialize_v_array.inc deleted file mode 100644 index a4b888381e810695a8c4188ed2cf452071d4398f..0000000000000000000000000000000000000000 --- a/mex/sources/sobol/initialize_v_array.inc +++ /dev/null @@ -1,13259 +0,0 @@ -/* -** Copyright © 2009 John Burkardt -** Copyright © 2010-2011 Dynare Team -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU Lesser General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program 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 Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ - - for (int i = 0; i < dim_max; i++) - { - for (int j = 0; j < log_max; j++) - v[i][j] = 0; - } - v[0][0] = 1; - v[1][0] = 1; - v[2][0] = 1; - v[3][0] = 1; - v[4][0] = 1; - v[5][0] = 1; - v[6][0] = 1; - v[7][0] = 1; - v[8][0] = 1; - v[9][0] = 1; - v[10][0] = 1; - v[11][0] = 1; - v[12][0] = 1; - v[13][0] = 1; - v[14][0] = 1; - v[15][0] = 1; - v[16][0] = 1; - v[17][0] = 1; - v[18][0] = 1; - v[19][0] = 1; - v[20][0] = 1; - v[21][0] = 1; - v[22][0] = 1; - v[23][0] = 1; - v[24][0] = 1; - v[25][0] = 1; - v[26][0] = 1; - v[27][0] = 1; - v[28][0] = 1; - v[29][0] = 1; - v[30][0] = 1; - v[31][0] = 1; - v[32][0] = 1; - v[33][0] = 1; - v[34][0] = 1; - v[35][0] = 1; - v[36][0] = 1; - v[37][0] = 1; - v[38][0] = 1; - v[39][0] = 1; - v[40][0] = 1; - v[41][0] = 1; - v[42][0] = 1; - v[43][0] = 1; - v[44][0] = 1; - v[45][0] = 1; - v[46][0] = 1; - v[47][0] = 1; - v[48][0] = 1; - v[49][0] = 1; - v[50][0] = 1; - v[51][0] = 1; - v[52][0] = 1; - v[53][0] = 1; - v[54][0] = 1; - v[55][0] = 1; - v[56][0] = 1; - v[57][0] = 1; - v[58][0] = 1; - v[59][0] = 1; - v[60][0] = 1; - v[61][0] = 1; - v[62][0] = 1; - v[63][0] = 1; - v[64][0] = 1; - v[65][0] = 1; - v[66][0] = 1; - v[67][0] = 1; - v[68][0] = 1; - v[69][0] = 1; - v[70][0] = 1; - v[71][0] = 1; - v[72][0] = 1; - v[73][0] = 1; - v[74][0] = 1; - v[75][0] = 1; - v[76][0] = 1; - v[77][0] = 1; - v[78][0] = 1; - v[79][0] = 1; - v[80][0] = 1; - v[81][0] = 1; - v[82][0] = 1; - v[83][0] = 1; - v[84][0] = 1; - v[85][0] = 1; - v[86][0] = 1; - v[87][0] = 1; - v[88][0] = 1; - v[89][0] = 1; - v[90][0] = 1; - v[91][0] = 1; - v[92][0] = 1; - v[93][0] = 1; - v[94][0] = 1; - v[95][0] = 1; - v[96][0] = 1; - v[97][0] = 1; - v[98][0] = 1; - v[99][0] = 1; - v[100][0] = 1; - v[101][0] = 1; - v[102][0] = 1; - v[103][0] = 1; - v[104][0] = 1; - v[105][0] = 1; - v[106][0] = 1; - v[107][0] = 1; - v[108][0] = 1; - v[109][0] = 1; - v[110][0] = 1; - v[111][0] = 1; - v[112][0] = 1; - v[113][0] = 1; - v[114][0] = 1; - v[115][0] = 1; - v[116][0] = 1; - v[117][0] = 1; - v[118][0] = 1; - v[119][0] = 1; - v[120][0] = 1; - v[121][0] = 1; - v[122][0] = 1; - v[123][0] = 1; - v[124][0] = 1; - v[125][0] = 1; - v[126][0] = 1; - v[127][0] = 1; - v[128][0] = 1; - v[129][0] = 1; - v[130][0] = 1; - v[131][0] = 1; - v[132][0] = 1; - v[133][0] = 1; - v[134][0] = 1; - v[135][0] = 1; - v[136][0] = 1; - v[137][0] = 1; - v[138][0] = 1; - v[139][0] = 1; - v[140][0] = 1; - v[141][0] = 1; - v[142][0] = 1; - v[143][0] = 1; - v[144][0] = 1; - v[145][0] = 1; - v[146][0] = 1; - v[147][0] = 1; - v[148][0] = 1; - v[149][0] = 1; - v[150][0] = 1; - v[151][0] = 1; - v[152][0] = 1; - v[153][0] = 1; - v[154][0] = 1; - v[155][0] = 1; - v[156][0] = 1; - v[157][0] = 1; - v[158][0] = 1; - v[159][0] = 1; - v[160][0] = 1; - v[161][0] = 1; - v[162][0] = 1; - v[163][0] = 1; - v[164][0] = 1; - v[165][0] = 1; - v[166][0] = 1; - v[167][0] = 1; - v[168][0] = 1; - v[169][0] = 1; - v[170][0] = 1; - v[171][0] = 1; - v[172][0] = 1; - v[173][0] = 1; - v[174][0] = 1; - v[175][0] = 1; - v[176][0] = 1; - v[177][0] = 1; - v[178][0] = 1; - v[179][0] = 1; - v[180][0] = 1; - v[181][0] = 1; - v[182][0] = 1; - v[183][0] = 1; - v[184][0] = 1; - v[185][0] = 1; - v[186][0] = 1; - v[187][0] = 1; - v[188][0] = 1; - v[189][0] = 1; - v[190][0] = 1; - v[191][0] = 1; - v[192][0] = 1; - v[193][0] = 1; - v[194][0] = 1; - v[195][0] = 1; - v[196][0] = 1; - v[197][0] = 1; - v[198][0] = 1; - v[199][0] = 1; - v[200][0] = 1; - v[201][0] = 1; - v[202][0] = 1; - v[203][0] = 1; - v[204][0] = 1; - v[205][0] = 1; - v[206][0] = 1; - v[207][0] = 1; - v[208][0] = 1; - v[209][0] = 1; - v[210][0] = 1; - v[211][0] = 1; - v[212][0] = 1; - v[213][0] = 1; - v[214][0] = 1; - v[215][0] = 1; - v[216][0] = 1; - v[217][0] = 1; - v[218][0] = 1; - v[219][0] = 1; - v[220][0] = 1; - v[221][0] = 1; - v[222][0] = 1; - v[223][0] = 1; - v[224][0] = 1; - v[225][0] = 1; - v[226][0] = 1; - v[227][0] = 1; - v[228][0] = 1; - v[229][0] = 1; - v[230][0] = 1; - v[231][0] = 1; - v[232][0] = 1; - v[233][0] = 1; - v[234][0] = 1; - v[235][0] = 1; - v[236][0] = 1; - v[237][0] = 1; - v[238][0] = 1; - v[239][0] = 1; - v[240][0] = 1; - v[241][0] = 1; - v[242][0] = 1; - v[243][0] = 1; - v[244][0] = 1; - v[245][0] = 1; - v[246][0] = 1; - v[247][0] = 1; - v[248][0] = 1; - v[249][0] = 1; - v[250][0] = 1; - v[251][0] = 1; - v[252][0] = 1; - v[253][0] = 1; - v[254][0] = 1; - v[255][0] = 1; - v[256][0] = 1; - v[257][0] = 1; - v[258][0] = 1; - v[259][0] = 1; - v[260][0] = 1; - v[261][0] = 1; - v[262][0] = 1; - v[263][0] = 1; - v[264][0] = 1; - v[265][0] = 1; - v[266][0] = 1; - v[267][0] = 1; - v[268][0] = 1; - v[269][0] = 1; - v[270][0] = 1; - v[271][0] = 1; - v[272][0] = 1; - v[273][0] = 1; - v[274][0] = 1; - v[275][0] = 1; - v[276][0] = 1; - v[277][0] = 1; - v[278][0] = 1; - v[279][0] = 1; - v[280][0] = 1; - v[281][0] = 1; - v[282][0] = 1; - v[283][0] = 1; - v[284][0] = 1; - v[285][0] = 1; - v[286][0] = 1; - v[287][0] = 1; - v[288][0] = 1; - v[289][0] = 1; - v[290][0] = 1; - v[291][0] = 1; - v[292][0] = 1; - v[293][0] = 1; - v[294][0] = 1; - v[295][0] = 1; - v[296][0] = 1; - v[297][0] = 1; - v[298][0] = 1; - v[299][0] = 1; - v[300][0] = 1; - v[301][0] = 1; - v[302][0] = 1; - v[303][0] = 1; - v[304][0] = 1; - v[305][0] = 1; - v[306][0] = 1; - v[307][0] = 1; - v[308][0] = 1; - v[309][0] = 1; - v[310][0] = 1; - v[311][0] = 1; - v[312][0] = 1; - v[313][0] = 1; - v[314][0] = 1; - v[315][0] = 1; - v[316][0] = 1; - v[317][0] = 1; - v[318][0] = 1; - v[319][0] = 1; - v[320][0] = 1; - v[321][0] = 1; - v[322][0] = 1; - v[323][0] = 1; - v[324][0] = 1; - v[325][0] = 1; - v[326][0] = 1; - v[327][0] = 1; - v[328][0] = 1; - v[329][0] = 1; - v[330][0] = 1; - v[331][0] = 1; - v[332][0] = 1; - v[333][0] = 1; - v[334][0] = 1; - v[335][0] = 1; - v[336][0] = 1; - v[337][0] = 1; - v[338][0] = 1; - v[339][0] = 1; - v[340][0] = 1; - v[341][0] = 1; - v[342][0] = 1; - v[343][0] = 1; - v[344][0] = 1; - v[345][0] = 1; - v[346][0] = 1; - v[347][0] = 1; - v[348][0] = 1; - v[349][0] = 1; - v[350][0] = 1; - v[351][0] = 1; - v[352][0] = 1; - v[353][0] = 1; - v[354][0] = 1; - v[355][0] = 1; - v[356][0] = 1; - v[357][0] = 1; - v[358][0] = 1; - v[359][0] = 1; - v[360][0] = 1; - v[361][0] = 1; - v[362][0] = 1; - v[363][0] = 1; - v[364][0] = 1; - v[365][0] = 1; - v[366][0] = 1; - v[367][0] = 1; - v[368][0] = 1; - v[369][0] = 1; - v[370][0] = 1; - v[371][0] = 1; - v[372][0] = 1; - v[373][0] = 1; - v[374][0] = 1; - v[375][0] = 1; - v[376][0] = 1; - v[377][0] = 1; - v[378][0] = 1; - v[379][0] = 1; - v[380][0] = 1; - v[381][0] = 1; - v[382][0] = 1; - v[383][0] = 1; - v[384][0] = 1; - v[385][0] = 1; - v[386][0] = 1; - v[387][0] = 1; - v[388][0] = 1; - v[389][0] = 1; - v[390][0] = 1; - v[391][0] = 1; - v[392][0] = 1; - v[393][0] = 1; - v[394][0] = 1; - v[395][0] = 1; - v[396][0] = 1; - v[397][0] = 1; - v[398][0] = 1; - v[399][0] = 1; - v[400][0] = 1; - v[401][0] = 1; - v[402][0] = 1; - v[403][0] = 1; - v[404][0] = 1; - v[405][0] = 1; - v[406][0] = 1; - v[407][0] = 1; - v[408][0] = 1; - v[409][0] = 1; - v[410][0] = 1; - v[411][0] = 1; - v[412][0] = 1; - v[413][0] = 1; - v[414][0] = 1; - v[415][0] = 1; - v[416][0] = 1; - v[417][0] = 1; - v[418][0] = 1; - v[419][0] = 1; - v[420][0] = 1; - v[421][0] = 1; - v[422][0] = 1; - v[423][0] = 1; - v[424][0] = 1; - v[425][0] = 1; - v[426][0] = 1; - v[427][0] = 1; - v[428][0] = 1; - v[429][0] = 1; - v[430][0] = 1; - v[431][0] = 1; - v[432][0] = 1; - v[433][0] = 1; - v[434][0] = 1; - v[435][0] = 1; - v[436][0] = 1; - v[437][0] = 1; - v[438][0] = 1; - v[439][0] = 1; - v[440][0] = 1; - v[441][0] = 1; - v[442][0] = 1; - v[443][0] = 1; - v[444][0] = 1; - v[445][0] = 1; - v[446][0] = 1; - v[447][0] = 1; - v[448][0] = 1; - v[449][0] = 1; - v[450][0] = 1; - v[451][0] = 1; - v[452][0] = 1; - v[453][0] = 1; - v[454][0] = 1; - v[455][0] = 1; - v[456][0] = 1; - v[457][0] = 1; - v[458][0] = 1; - v[459][0] = 1; - v[460][0] = 1; - v[461][0] = 1; - v[462][0] = 1; - v[463][0] = 1; - v[464][0] = 1; - v[465][0] = 1; - v[466][0] = 1; - v[467][0] = 1; - v[468][0] = 1; - v[469][0] = 1; - v[470][0] = 1; - v[471][0] = 1; - v[472][0] = 1; - v[473][0] = 1; - v[474][0] = 1; - v[475][0] = 1; - v[476][0] = 1; - v[477][0] = 1; - v[478][0] = 1; - v[479][0] = 1; - v[480][0] = 1; - v[481][0] = 1; - v[482][0] = 1; - v[483][0] = 1; - v[484][0] = 1; - v[485][0] = 1; - v[486][0] = 1; - v[487][0] = 1; - v[488][0] = 1; - v[489][0] = 1; - v[490][0] = 1; - v[491][0] = 1; - v[492][0] = 1; - v[493][0] = 1; - v[494][0] = 1; - v[495][0] = 1; - v[496][0] = 1; - v[497][0] = 1; - v[498][0] = 1; - v[499][0] = 1; - v[500][0] = 1; - v[501][0] = 1; - v[502][0] = 1; - v[503][0] = 1; - v[504][0] = 1; - v[505][0] = 1; - v[506][0] = 1; - v[507][0] = 1; - v[508][0] = 1; - v[509][0] = 1; - v[510][0] = 1; - v[511][0] = 1; - v[512][0] = 1; - v[513][0] = 1; - v[514][0] = 1; - v[515][0] = 1; - v[516][0] = 1; - v[517][0] = 1; - v[518][0] = 1; - v[519][0] = 1; - v[520][0] = 1; - v[521][0] = 1; - v[522][0] = 1; - v[523][0] = 1; - v[524][0] = 1; - v[525][0] = 1; - v[526][0] = 1; - v[527][0] = 1; - v[528][0] = 1; - v[529][0] = 1; - v[530][0] = 1; - v[531][0] = 1; - v[532][0] = 1; - v[533][0] = 1; - v[534][0] = 1; - v[535][0] = 1; - v[536][0] = 1; - v[537][0] = 1; - v[538][0] = 1; - v[539][0] = 1; - v[540][0] = 1; - v[541][0] = 1; - v[542][0] = 1; - v[543][0] = 1; - v[544][0] = 1; - v[545][0] = 1; - v[546][0] = 1; - v[547][0] = 1; - v[548][0] = 1; - v[549][0] = 1; - v[550][0] = 1; - v[551][0] = 1; - v[552][0] = 1; - v[553][0] = 1; - v[554][0] = 1; - v[555][0] = 1; - v[556][0] = 1; - v[557][0] = 1; - v[558][0] = 1; - v[559][0] = 1; - v[560][0] = 1; - v[561][0] = 1; - v[562][0] = 1; - v[563][0] = 1; - v[564][0] = 1; - v[565][0] = 1; - v[566][0] = 1; - v[567][0] = 1; - v[568][0] = 1; - v[569][0] = 1; - v[570][0] = 1; - v[571][0] = 1; - v[572][0] = 1; - v[573][0] = 1; - v[574][0] = 1; - v[575][0] = 1; - v[576][0] = 1; - v[577][0] = 1; - v[578][0] = 1; - v[579][0] = 1; - v[580][0] = 1; - v[581][0] = 1; - v[582][0] = 1; - v[583][0] = 1; - v[584][0] = 1; - v[585][0] = 1; - v[586][0] = 1; - v[587][0] = 1; - v[588][0] = 1; - v[589][0] = 1; - v[590][0] = 1; - v[591][0] = 1; - v[592][0] = 1; - v[593][0] = 1; - v[594][0] = 1; - v[595][0] = 1; - v[596][0] = 1; - v[597][0] = 1; - v[598][0] = 1; - v[599][0] = 1; - v[600][0] = 1; - v[601][0] = 1; - v[602][0] = 1; - v[603][0] = 1; - v[604][0] = 1; - v[605][0] = 1; - v[606][0] = 1; - v[607][0] = 1; - v[608][0] = 1; - v[609][0] = 1; - v[610][0] = 1; - v[611][0] = 1; - v[612][0] = 1; - v[613][0] = 1; - v[614][0] = 1; - v[615][0] = 1; - v[616][0] = 1; - v[617][0] = 1; - v[618][0] = 1; - v[619][0] = 1; - v[620][0] = 1; - v[621][0] = 1; - v[622][0] = 1; - v[623][0] = 1; - v[624][0] = 1; - v[625][0] = 1; - v[626][0] = 1; - v[627][0] = 1; - v[628][0] = 1; - v[629][0] = 1; - v[630][0] = 1; - v[631][0] = 1; - v[632][0] = 1; - v[633][0] = 1; - v[634][0] = 1; - v[635][0] = 1; - v[636][0] = 1; - v[637][0] = 1; - v[638][0] = 1; - v[639][0] = 1; - v[640][0] = 1; - v[641][0] = 1; - v[642][0] = 1; - v[643][0] = 1; - v[644][0] = 1; - v[645][0] = 1; - v[646][0] = 1; - v[647][0] = 1; - v[648][0] = 1; - v[649][0] = 1; - v[650][0] = 1; - v[651][0] = 1; - v[652][0] = 1; - v[653][0] = 1; - v[654][0] = 1; - v[655][0] = 1; - v[656][0] = 1; - v[657][0] = 1; - v[658][0] = 1; - v[659][0] = 1; - v[660][0] = 1; - v[661][0] = 1; - v[662][0] = 1; - v[663][0] = 1; - v[664][0] = 1; - v[665][0] = 1; - v[666][0] = 1; - v[667][0] = 1; - v[668][0] = 1; - v[669][0] = 1; - v[670][0] = 1; - v[671][0] = 1; - v[672][0] = 1; - v[673][0] = 1; - v[674][0] = 1; - v[675][0] = 1; - v[676][0] = 1; - v[677][0] = 1; - v[678][0] = 1; - v[679][0] = 1; - v[680][0] = 1; - v[681][0] = 1; - v[682][0] = 1; - v[683][0] = 1; - v[684][0] = 1; - v[685][0] = 1; - v[686][0] = 1; - v[687][0] = 1; - v[688][0] = 1; - v[689][0] = 1; - v[690][0] = 1; - v[691][0] = 1; - v[692][0] = 1; - v[693][0] = 1; - v[694][0] = 1; - v[695][0] = 1; - v[696][0] = 1; - v[697][0] = 1; - v[698][0] = 1; - v[699][0] = 1; - v[700][0] = 1; - v[701][0] = 1; - v[702][0] = 1; - v[703][0] = 1; - v[704][0] = 1; - v[705][0] = 1; - v[706][0] = 1; - v[707][0] = 1; - v[708][0] = 1; - v[709][0] = 1; - v[710][0] = 1; - v[711][0] = 1; - v[712][0] = 1; - v[713][0] = 1; - v[714][0] = 1; - v[715][0] = 1; - v[716][0] = 1; - v[717][0] = 1; - v[718][0] = 1; - v[719][0] = 1; - v[720][0] = 1; - v[721][0] = 1; - v[722][0] = 1; - v[723][0] = 1; - v[724][0] = 1; - v[725][0] = 1; - v[726][0] = 1; - v[727][0] = 1; - v[728][0] = 1; - v[729][0] = 1; - v[730][0] = 1; - v[731][0] = 1; - v[732][0] = 1; - v[733][0] = 1; - v[734][0] = 1; - v[735][0] = 1; - v[736][0] = 1; - v[737][0] = 1; - v[738][0] = 1; - v[739][0] = 1; - v[740][0] = 1; - v[741][0] = 1; - v[742][0] = 1; - v[743][0] = 1; - v[744][0] = 1; - v[745][0] = 1; - v[746][0] = 1; - v[747][0] = 1; - v[748][0] = 1; - v[749][0] = 1; - v[750][0] = 1; - v[751][0] = 1; - v[752][0] = 1; - v[753][0] = 1; - v[754][0] = 1; - v[755][0] = 1; - v[756][0] = 1; - v[757][0] = 1; - v[758][0] = 1; - v[759][0] = 1; - v[760][0] = 1; - v[761][0] = 1; - v[762][0] = 1; - v[763][0] = 1; - v[764][0] = 1; - v[765][0] = 1; - v[766][0] = 1; - v[767][0] = 1; - v[768][0] = 1; - v[769][0] = 1; - v[770][0] = 1; - v[771][0] = 1; - v[772][0] = 1; - v[773][0] = 1; - v[774][0] = 1; - v[775][0] = 1; - v[776][0] = 1; - v[777][0] = 1; - v[778][0] = 1; - v[779][0] = 1; - v[780][0] = 1; - v[781][0] = 1; - v[782][0] = 1; - v[783][0] = 1; - v[784][0] = 1; - v[785][0] = 1; - v[786][0] = 1; - v[787][0] = 1; - v[788][0] = 1; - v[789][0] = 1; - v[790][0] = 1; - v[791][0] = 1; - v[792][0] = 1; - v[793][0] = 1; - v[794][0] = 1; - v[795][0] = 1; - v[796][0] = 1; - v[797][0] = 1; - v[798][0] = 1; - v[799][0] = 1; - v[800][0] = 1; - v[801][0] = 1; - v[802][0] = 1; - v[803][0] = 1; - v[804][0] = 1; - v[805][0] = 1; - v[806][0] = 1; - v[807][0] = 1; - v[808][0] = 1; - v[809][0] = 1; - v[810][0] = 1; - v[811][0] = 1; - v[812][0] = 1; - v[813][0] = 1; - v[814][0] = 1; - v[815][0] = 1; - v[816][0] = 1; - v[817][0] = 1; - v[818][0] = 1; - v[819][0] = 1; - v[820][0] = 1; - v[821][0] = 1; - v[822][0] = 1; - v[823][0] = 1; - v[824][0] = 1; - v[825][0] = 1; - v[826][0] = 1; - v[827][0] = 1; - v[828][0] = 1; - v[829][0] = 1; - v[830][0] = 1; - v[831][0] = 1; - v[832][0] = 1; - v[833][0] = 1; - v[834][0] = 1; - v[835][0] = 1; - v[836][0] = 1; - v[837][0] = 1; - v[838][0] = 1; - v[839][0] = 1; - v[840][0] = 1; - v[841][0] = 1; - v[842][0] = 1; - v[843][0] = 1; - v[844][0] = 1; - v[845][0] = 1; - v[846][0] = 1; - v[847][0] = 1; - v[848][0] = 1; - v[849][0] = 1; - v[850][0] = 1; - v[851][0] = 1; - v[852][0] = 1; - v[853][0] = 1; - v[854][0] = 1; - v[855][0] = 1; - v[856][0] = 1; - v[857][0] = 1; - v[858][0] = 1; - v[859][0] = 1; - v[860][0] = 1; - v[861][0] = 1; - v[862][0] = 1; - v[863][0] = 1; - v[864][0] = 1; - v[865][0] = 1; - v[866][0] = 1; - v[867][0] = 1; - v[868][0] = 1; - v[869][0] = 1; - v[870][0] = 1; - v[871][0] = 1; - v[872][0] = 1; - v[873][0] = 1; - v[874][0] = 1; - v[875][0] = 1; - v[876][0] = 1; - v[877][0] = 1; - v[878][0] = 1; - v[879][0] = 1; - v[880][0] = 1; - v[881][0] = 1; - v[882][0] = 1; - v[883][0] = 1; - v[884][0] = 1; - v[885][0] = 1; - v[886][0] = 1; - v[887][0] = 1; - v[888][0] = 1; - v[889][0] = 1; - v[890][0] = 1; - v[891][0] = 1; - v[892][0] = 1; - v[893][0] = 1; - v[894][0] = 1; - v[895][0] = 1; - v[896][0] = 1; - v[897][0] = 1; - v[898][0] = 1; - v[899][0] = 1; - v[900][0] = 1; - v[901][0] = 1; - v[902][0] = 1; - v[903][0] = 1; - v[904][0] = 1; - v[905][0] = 1; - v[906][0] = 1; - v[907][0] = 1; - v[908][0] = 1; - v[909][0] = 1; - v[910][0] = 1; - v[911][0] = 1; - v[912][0] = 1; - v[913][0] = 1; - v[914][0] = 1; - v[915][0] = 1; - v[916][0] = 1; - v[917][0] = 1; - v[918][0] = 1; - v[919][0] = 1; - v[920][0] = 1; - v[921][0] = 1; - v[922][0] = 1; - v[923][0] = 1; - v[924][0] = 1; - v[925][0] = 1; - v[926][0] = 1; - v[927][0] = 1; - v[928][0] = 1; - v[929][0] = 1; - v[930][0] = 1; - v[931][0] = 1; - v[932][0] = 1; - v[933][0] = 1; - v[934][0] = 1; - v[935][0] = 1; - v[936][0] = 1; - v[937][0] = 1; - v[938][0] = 1; - v[939][0] = 1; - v[940][0] = 1; - v[941][0] = 1; - v[942][0] = 1; - v[943][0] = 1; - v[944][0] = 1; - v[945][0] = 1; - v[946][0] = 1; - v[947][0] = 1; - v[948][0] = 1; - v[949][0] = 1; - v[950][0] = 1; - v[951][0] = 1; - v[952][0] = 1; - v[953][0] = 1; - v[954][0] = 1; - v[955][0] = 1; - v[956][0] = 1; - v[957][0] = 1; - v[958][0] = 1; - v[959][0] = 1; - v[960][0] = 1; - v[961][0] = 1; - v[962][0] = 1; - v[963][0] = 1; - v[964][0] = 1; - v[965][0] = 1; - v[966][0] = 1; - v[967][0] = 1; - v[968][0] = 1; - v[969][0] = 1; - v[970][0] = 1; - v[971][0] = 1; - v[972][0] = 1; - v[973][0] = 1; - v[974][0] = 1; - v[975][0] = 1; - v[976][0] = 1; - v[977][0] = 1; - v[978][0] = 1; - v[979][0] = 1; - v[980][0] = 1; - v[981][0] = 1; - v[982][0] = 1; - v[983][0] = 1; - v[984][0] = 1; - v[985][0] = 1; - v[986][0] = 1; - v[987][0] = 1; - v[988][0] = 1; - v[989][0] = 1; - v[990][0] = 1; - v[991][0] = 1; - v[992][0] = 1; - v[993][0] = 1; - v[994][0] = 1; - v[995][0] = 1; - v[996][0] = 1; - v[997][0] = 1; - v[998][0] = 1; - v[999][0] = 1; - v[1000][0] = 1; - v[1001][0] = 1; - v[1002][0] = 1; - v[1003][0] = 1; - v[1004][0] = 1; - v[1005][0] = 1; - v[1006][0] = 1; - v[1007][0] = 1; - v[1008][0] = 1; - v[1009][0] = 1; - v[1010][0] = 1; - v[1011][0] = 1; - v[1012][0] = 1; - v[1013][0] = 1; - v[1014][0] = 1; - v[1015][0] = 1; - v[1016][0] = 1; - v[1017][0] = 1; - v[1018][0] = 1; - v[1019][0] = 1; - v[1020][0] = 1; - v[1021][0] = 1; - v[1022][0] = 1; - v[1023][0] = 1; - v[1024][0] = 1; - v[1025][0] = 1; - v[1026][0] = 1; - v[1027][0] = 1; - v[1028][0] = 1; - v[1029][0] = 1; - v[1030][0] = 1; - v[1031][0] = 1; - v[1032][0] = 1; - v[1033][0] = 1; - v[1034][0] = 1; - v[1035][0] = 1; - v[1036][0] = 1; - v[1037][0] = 1; - v[1038][0] = 1; - v[1039][0] = 1; - v[1040][0] = 1; - v[1041][0] = 1; - v[1042][0] = 1; - v[1043][0] = 1; - v[1044][0] = 1; - v[1045][0] = 1; - v[1046][0] = 1; - v[1047][0] = 1; - v[1048][0] = 1; - v[1049][0] = 1; - v[1050][0] = 1; - v[1051][0] = 1; - v[1052][0] = 1; - v[1053][0] = 1; - v[1054][0] = 1; - v[1055][0] = 1; - v[1056][0] = 1; - v[1057][0] = 1; - v[1058][0] = 1; - v[1059][0] = 1; - v[1060][0] = 1; - v[1061][0] = 1; - v[1062][0] = 1; - v[1063][0] = 1; - v[1064][0] = 1; - v[1065][0] = 1; - v[1066][0] = 1; - v[1067][0] = 1; - v[1068][0] = 1; - v[1069][0] = 1; - v[1070][0] = 1; - v[1071][0] = 1; - v[1072][0] = 1; - v[1073][0] = 1; - v[1074][0] = 1; - v[1075][0] = 1; - v[1076][0] = 1; - v[1077][0] = 1; - v[1078][0] = 1; - v[1079][0] = 1; - v[1080][0] = 1; - v[1081][0] = 1; - v[1082][0] = 1; - v[1083][0] = 1; - v[1084][0] = 1; - v[1085][0] = 1; - v[1086][0] = 1; - v[1087][0] = 1; - v[1088][0] = 1; - v[1089][0] = 1; - v[1090][0] = 1; - v[1091][0] = 1; - v[1092][0] = 1; - v[1093][0] = 1; - v[1094][0] = 1; - v[1095][0] = 1; - v[1096][0] = 1; - v[1097][0] = 1; - v[1098][0] = 1; - v[1099][0] = 1; - v[1100][0] = 1; - v[1101][0] = 1; - v[1102][0] = 1; - v[1103][0] = 1; - v[1104][0] = 1; - v[1105][0] = 1; - v[1106][0] = 1; - v[1107][0] = 1; - v[1108][0] = 1; - v[1109][0] = 1; - v[1110][0] = 1; - - v[2][1] = 1; - v[3][1] = 3; - v[4][1] = 1; - v[5][1] = 3; - v[6][1] = 1; - v[7][1] = 3; - v[8][1] = 3; - v[9][1] = 1; - v[10][1] = 3; - v[11][1] = 1; - v[12][1] = 3; - v[13][1] = 1; - v[14][1] = 3; - v[15][1] = 1; - v[16][1] = 1; - v[17][1] = 3; - v[18][1] = 1; - v[19][1] = 3; - v[20][1] = 1; - v[21][1] = 3; - v[22][1] = 1; - v[23][1] = 3; - v[24][1] = 3; - v[25][1] = 1; - v[26][1] = 1; - v[27][1] = 1; - v[28][1] = 3; - v[29][1] = 1; - v[30][1] = 3; - v[31][1] = 1; - v[32][1] = 3; - v[33][1] = 3; - v[34][1] = 1; - v[35][1] = 3; - v[36][1] = 1; - v[37][1] = 1; - v[38][1] = 1; - v[39][1] = 3; - v[40][1] = 1; - v[41][1] = 3; - v[42][1] = 1; - v[43][1] = 1; - v[44][1] = 1; - v[45][1] = 3; - v[46][1] = 3; - v[47][1] = 1; - v[48][1] = 3; - v[49][1] = 3; - v[50][1] = 1; - v[51][1] = 1; - v[52][1] = 3; - v[53][1] = 3; - v[54][1] = 1; - v[55][1] = 3; - v[56][1] = 3; - v[57][1] = 3; - v[58][1] = 1; - v[59][1] = 3; - v[60][1] = 1; - v[61][1] = 3; - v[62][1] = 1; - v[63][1] = 1; - v[64][1] = 3; - v[65][1] = 3; - v[66][1] = 1; - v[67][1] = 1; - v[68][1] = 1; - v[69][1] = 1; - v[70][1] = 3; - v[71][1] = 1; - v[72][1] = 1; - v[73][1] = 3; - v[74][1] = 1; - v[75][1] = 1; - v[76][1] = 1; - v[77][1] = 3; - v[78][1] = 3; - v[79][1] = 1; - v[80][1] = 3; - v[81][1] = 3; - v[82][1] = 1; - v[83][1] = 3; - v[84][1] = 3; - v[85][1] = 3; - v[86][1] = 1; - v[87][1] = 3; - v[88][1] = 3; - v[89][1] = 3; - v[90][1] = 1; - v[91][1] = 3; - v[92][1] = 3; - v[93][1] = 1; - v[94][1] = 3; - v[95][1] = 3; - v[96][1] = 3; - v[97][1] = 1; - v[98][1] = 3; - v[99][1] = 1; - v[100][1] = 3; - v[101][1] = 1; - v[102][1] = 1; - v[103][1] = 3; - v[104][1] = 3; - v[105][1] = 1; - v[106][1] = 3; - v[107][1] = 3; - v[108][1] = 1; - v[109][1] = 1; - v[110][1] = 1; - v[111][1] = 3; - v[112][1] = 3; - v[113][1] = 1; - v[114][1] = 3; - v[115][1] = 3; - v[116][1] = 1; - v[117][1] = 3; - v[118][1] = 1; - v[119][1] = 1; - v[120][1] = 3; - v[121][1] = 3; - v[122][1] = 3; - v[123][1] = 1; - v[124][1] = 1; - v[125][1] = 1; - v[126][1] = 3; - v[127][1] = 1; - v[128][1] = 1; - v[129][1] = 3; - v[130][1] = 1; - v[131][1] = 1; - v[132][1] = 3; - v[133][1] = 3; - v[134][1] = 1; - v[135][1] = 3; - v[136][1] = 1; - v[137][1] = 3; - v[138][1] = 3; - v[139][1] = 3; - v[140][1] = 3; - v[141][1] = 1; - v[142][1] = 1; - v[143][1] = 1; - v[144][1] = 3; - v[145][1] = 3; - v[146][1] = 1; - v[147][1] = 1; - v[148][1] = 3; - v[149][1] = 1; - v[150][1] = 1; - v[151][1] = 1; - v[152][1] = 1; - v[153][1] = 1; - v[154][1] = 1; - v[155][1] = 3; - v[156][1] = 1; - v[157][1] = 3; - v[158][1] = 1; - v[159][1] = 1; - v[160][1] = 1; - v[161][1] = 3; - v[162][1] = 1; - v[163][1] = 3; - v[164][1] = 1; - v[165][1] = 3; - v[166][1] = 3; - v[167][1] = 3; - v[168][1] = 1; - v[169][1] = 1; - v[170][1] = 3; - v[171][1] = 3; - v[172][1] = 1; - v[173][1] = 3; - v[174][1] = 1; - v[175][1] = 3; - v[176][1] = 1; - v[177][1] = 1; - v[178][1] = 3; - v[179][1] = 1; - v[180][1] = 3; - v[181][1] = 1; - v[182][1] = 3; - v[183][1] = 1; - v[184][1] = 3; - v[185][1] = 1; - v[186][1] = 1; - v[187][1] = 1; - v[188][1] = 3; - v[189][1] = 3; - v[190][1] = 1; - v[191][1] = 3; - v[192][1] = 3; - v[193][1] = 1; - v[194][1] = 3; - v[195][1] = 1; - v[196][1] = 1; - v[197][1] = 1; - v[198][1] = 3; - v[199][1] = 1; - v[200][1] = 3; - v[201][1] = 1; - v[202][1] = 1; - v[203][1] = 3; - v[204][1] = 1; - v[205][1] = 1; - v[206][1] = 3; - v[207][1] = 3; - v[208][1] = 1; - v[209][1] = 1; - v[210][1] = 3; - v[211][1] = 3; - v[212][1] = 3; - v[213][1] = 1; - v[214][1] = 3; - v[215][1] = 3; - v[216][1] = 3; - v[217][1] = 1; - v[218][1] = 3; - v[219][1] = 1; - v[220][1] = 3; - v[221][1] = 1; - v[222][1] = 1; - v[223][1] = 1; - v[224][1] = 3; - v[225][1] = 1; - v[226][1] = 1; - v[227][1] = 1; - v[228][1] = 3; - v[229][1] = 1; - v[230][1] = 1; - v[231][1] = 1; - v[232][1] = 1; - v[233][1] = 1; - v[234][1] = 3; - v[235][1] = 3; - v[236][1] = 3; - v[237][1] = 1; - v[238][1] = 1; - v[239][1] = 1; - v[240][1] = 1; - v[241][1] = 3; - v[242][1] = 3; - v[243][1] = 3; - v[244][1] = 1; - v[245][1] = 3; - v[246][1] = 3; - v[247][1] = 1; - v[248][1] = 1; - v[249][1] = 1; - v[250][1] = 1; - v[251][1] = 3; - v[252][1] = 1; - v[253][1] = 1; - v[254][1] = 3; - v[255][1] = 1; - v[256][1] = 3; - v[257][1] = 3; - v[258][1] = 1; - v[259][1] = 1; - v[260][1] = 3; - v[261][1] = 3; - v[262][1] = 1; - v[263][1] = 1; - v[264][1] = 1; - v[265][1] = 1; - v[266][1] = 3; - v[267][1] = 1; - v[268][1] = 3; - v[269][1] = 3; - v[270][1] = 1; - v[271][1] = 3; - v[272][1] = 3; - v[273][1] = 1; - v[274][1] = 1; - v[275][1] = 1; - v[276][1] = 3; - v[277][1] = 3; - v[278][1] = 3; - v[279][1] = 1; - v[280][1] = 3; - v[281][1] = 3; - v[282][1] = 1; - v[283][1] = 3; - v[284][1] = 3; - v[285][1] = 1; - v[286][1] = 3; - v[287][1] = 1; - v[288][1] = 3; - v[289][1] = 3; - v[290][1] = 3; - v[291][1] = 1; - v[292][1] = 3; - v[293][1] = 1; - v[294][1] = 1; - v[295][1] = 3; - v[296][1] = 1; - v[297][1] = 3; - v[298][1] = 1; - v[299][1] = 1; - v[300][1] = 1; - v[301][1] = 3; - v[302][1] = 3; - v[303][1] = 3; - v[304][1] = 1; - v[305][1] = 1; - v[306][1] = 3; - v[307][1] = 1; - v[308][1] = 3; - v[309][1] = 1; - v[310][1] = 1; - v[311][1] = 1; - v[312][1] = 1; - v[313][1] = 1; - v[314][1] = 1; - v[315][1] = 3; - v[316][1] = 1; - v[317][1] = 1; - v[318][1] = 3; - v[319][1] = 1; - v[320][1] = 3; - v[321][1] = 3; - v[322][1] = 1; - v[323][1] = 1; - v[324][1] = 1; - v[325][1] = 1; - v[326][1] = 3; - v[327][1] = 1; - v[328][1] = 3; - v[329][1] = 1; - v[330][1] = 3; - v[331][1] = 1; - v[332][1] = 1; - v[333][1] = 1; - v[334][1] = 1; - v[335][1] = 3; - v[336][1] = 3; - v[337][1] = 1; - v[338][1] = 1; - v[339][1] = 1; - v[340][1] = 1; - v[341][1] = 1; - v[342][1] = 3; - v[343][1] = 3; - v[344][1] = 3; - v[345][1] = 1; - v[346][1] = 1; - v[347][1] = 3; - v[348][1] = 3; - v[349][1] = 3; - v[350][1] = 3; - v[351][1] = 3; - v[352][1] = 1; - v[353][1] = 3; - v[354][1] = 3; - v[355][1] = 1; - v[356][1] = 3; - v[357][1] = 3; - v[358][1] = 3; - v[359][1] = 3; - v[360][1] = 1; - v[361][1] = 1; - v[362][1] = 1; - v[363][1] = 1; - v[364][1] = 1; - v[365][1] = 1; - v[366][1] = 3; - v[367][1] = 1; - v[368][1] = 1; - v[369][1] = 3; - v[370][1] = 1; - v[371][1] = 1; - v[372][1] = 1; - v[373][1] = 3; - v[374][1] = 1; - v[375][1] = 1; - v[376][1] = 1; - v[377][1] = 3; - v[378][1] = 3; - v[379][1] = 3; - v[380][1] = 1; - v[381][1] = 3; - v[382][1] = 1; - v[383][1] = 1; - v[384][1] = 3; - v[385][1] = 3; - v[386][1] = 3; - v[387][1] = 1; - v[388][1] = 3; - v[389][1] = 3; - v[390][1] = 1; - v[391][1] = 3; - v[392][1] = 1; - v[393][1] = 3; - v[394][1] = 3; - v[395][1] = 1; - v[396][1] = 3; - v[397][1] = 3; - v[398][1] = 3; - v[399][1] = 1; - v[400][1] = 1; - v[401][1] = 3; - v[402][1] = 3; - v[403][1] = 1; - v[404][1] = 3; - v[405][1] = 1; - v[406][1] = 3; - v[407][1] = 1; - v[408][1] = 1; - v[409][1] = 1; - v[410][1] = 3; - v[411][1] = 3; - v[412][1] = 3; - v[413][1] = 3; - v[414][1] = 1; - v[415][1] = 3; - v[416][1] = 1; - v[417][1] = 1; - v[418][1] = 3; - v[419][1] = 1; - v[420][1] = 3; - v[421][1] = 1; - v[422][1] = 1; - v[423][1] = 1; - v[424][1] = 3; - v[425][1] = 1; - v[426][1] = 3; - v[427][1] = 1; - v[428][1] = 3; - v[429][1] = 1; - v[430][1] = 3; - v[431][1] = 3; - v[432][1] = 3; - v[433][1] = 3; - v[434][1] = 3; - v[435][1] = 3; - v[436][1] = 3; - v[437][1] = 3; - v[438][1] = 1; - v[439][1] = 3; - v[440][1] = 3; - v[441][1] = 3; - v[442][1] = 3; - v[443][1] = 3; - v[444][1] = 1; - v[445][1] = 3; - v[446][1] = 1; - v[447][1] = 3; - v[448][1] = 3; - v[449][1] = 3; - v[450][1] = 1; - v[451][1] = 3; - v[452][1] = 1; - v[453][1] = 3; - v[454][1] = 1; - v[455][1] = 3; - v[456][1] = 3; - v[457][1] = 1; - v[458][1] = 3; - v[459][1] = 3; - v[460][1] = 3; - v[461][1] = 3; - v[462][1] = 3; - v[463][1] = 3; - v[464][1] = 3; - v[465][1] = 3; - v[466][1] = 3; - v[467][1] = 1; - v[468][1] = 1; - v[469][1] = 1; - v[470][1] = 1; - v[471][1] = 1; - v[472][1] = 1; - v[473][1] = 3; - v[474][1] = 3; - v[475][1] = 1; - v[476][1] = 1; - v[477][1] = 3; - v[478][1] = 3; - v[479][1] = 1; - v[480][1] = 1; - v[481][1] = 1; - v[482][1] = 3; - v[483][1] = 3; - v[484][1] = 1; - v[485][1] = 1; - v[486][1] = 3; - v[487][1] = 3; - v[488][1] = 3; - v[489][1] = 3; - v[490][1] = 1; - v[491][1] = 1; - v[492][1] = 3; - v[493][1] = 1; - v[494][1] = 3; - v[495][1] = 3; - v[496][1] = 1; - v[497][1] = 3; - v[498][1] = 3; - v[499][1] = 1; - v[500][1] = 1; - v[501][1] = 1; - v[502][1] = 3; - v[503][1] = 3; - v[504][1] = 3; - v[505][1] = 1; - v[506][1] = 1; - v[507][1] = 3; - v[508][1] = 3; - v[509][1] = 3; - v[510][1] = 3; - v[511][1] = 3; - v[512][1] = 1; - v[513][1] = 1; - v[514][1] = 1; - v[515][1] = 3; - v[516][1] = 1; - v[517][1] = 3; - v[518][1] = 3; - v[519][1] = 1; - v[520][1] = 3; - v[521][1] = 3; - v[522][1] = 3; - v[523][1] = 3; - v[524][1] = 1; - v[525][1] = 1; - v[526][1] = 3; - v[527][1] = 1; - v[528][1] = 1; - v[529][1] = 3; - v[530][1] = 1; - v[531][1] = 3; - v[532][1] = 1; - v[533][1] = 3; - v[534][1] = 1; - v[535][1] = 3; - v[536][1] = 3; - v[537][1] = 1; - v[538][1] = 1; - v[539][1] = 3; - v[540][1] = 3; - v[541][1] = 1; - v[542][1] = 3; - v[543][1] = 3; - v[544][1] = 1; - v[545][1] = 3; - v[546][1] = 3; - v[547][1] = 1; - v[548][1] = 1; - v[549][1] = 3; - v[550][1] = 1; - v[551][1] = 3; - v[552][1] = 3; - v[553][1] = 1; - v[554][1] = 1; - v[555][1] = 3; - v[556][1] = 1; - v[557][1] = 3; - v[558][1] = 1; - v[559][1] = 3; - v[560][1] = 1; - v[561][1] = 1; - v[562][1] = 3; - v[563][1] = 3; - v[564][1] = 1; - v[565][1] = 1; - v[566][1] = 1; - v[567][1] = 3; - v[568][1] = 3; - v[569][1] = 1; - v[570][1] = 3; - v[571][1] = 1; - v[572][1] = 1; - v[573][1] = 3; - v[574][1] = 3; - v[575][1] = 1; - v[576][1] = 1; - v[577][1] = 3; - v[578][1] = 1; - v[579][1] = 3; - v[580][1] = 1; - v[581][1] = 1; - v[582][1] = 1; - v[583][1] = 1; - v[584][1] = 1; - v[585][1] = 3; - v[586][1] = 1; - v[587][1] = 1; - v[588][1] = 1; - v[589][1] = 1; - v[590][1] = 3; - v[591][1] = 1; - v[592][1] = 3; - v[593][1] = 1; - v[594][1] = 1; - v[595][1] = 3; - v[596][1] = 3; - v[597][1] = 1; - v[598][1] = 1; - v[599][1] = 3; - v[600][1] = 1; - v[601][1] = 3; - v[602][1] = 1; - v[603][1] = 3; - v[604][1] = 3; - v[605][1] = 3; - v[606][1] = 1; - v[607][1] = 3; - v[608][1] = 3; - v[609][1] = 3; - v[610][1] = 1; - v[611][1] = 1; - v[612][1] = 3; - v[613][1] = 3; - v[614][1] = 3; - v[615][1] = 1; - v[616][1] = 1; - v[617][1] = 1; - v[618][1] = 1; - v[619][1] = 3; - v[620][1] = 1; - v[621][1] = 3; - v[622][1] = 1; - v[623][1] = 3; - v[624][1] = 1; - v[625][1] = 1; - v[626][1] = 3; - v[627][1] = 3; - v[628][1] = 1; - v[629][1] = 1; - v[630][1] = 1; - v[631][1] = 3; - v[632][1] = 3; - v[633][1] = 1; - v[634][1] = 3; - v[635][1] = 1; - v[636][1] = 3; - v[637][1] = 1; - v[638][1] = 1; - v[639][1] = 1; - v[640][1] = 1; - v[641][1] = 1; - v[642][1] = 1; - v[643][1] = 3; - v[644][1] = 1; - v[645][1] = 3; - v[646][1] = 3; - v[647][1] = 1; - v[648][1] = 3; - v[649][1] = 3; - v[650][1] = 3; - v[651][1] = 1; - v[652][1] = 3; - v[653][1] = 1; - v[654][1] = 1; - v[655][1] = 3; - v[656][1] = 3; - v[657][1] = 1; - v[658][1] = 1; - v[659][1] = 3; - v[660][1] = 3; - v[661][1] = 1; - v[662][1] = 1; - v[663][1] = 1; - v[664][1] = 3; - v[665][1] = 1; - v[666][1] = 3; - v[667][1] = 3; - v[668][1] = 1; - v[669][1] = 1; - v[670][1] = 3; - v[671][1] = 1; - v[672][1] = 1; - v[673][1] = 3; - v[674][1] = 1; - v[675][1] = 3; - v[676][1] = 1; - v[677][1] = 1; - v[678][1] = 1; - v[679][1] = 3; - v[680][1] = 3; - v[681][1] = 3; - v[682][1] = 3; - v[683][1] = 1; - v[684][1] = 1; - v[685][1] = 3; - v[686][1] = 3; - v[687][1] = 1; - v[688][1] = 1; - v[689][1] = 1; - v[690][1] = 1; - v[691][1] = 3; - v[692][1] = 1; - v[693][1] = 1; - v[694][1] = 3; - v[695][1] = 3; - v[696][1] = 3; - v[697][1] = 1; - v[698][1] = 1; - v[699][1] = 3; - v[700][1] = 3; - v[701][1] = 1; - v[702][1] = 3; - v[703][1] = 3; - v[704][1] = 1; - v[705][1] = 1; - v[706][1] = 3; - v[707][1] = 3; - v[708][1] = 3; - v[709][1] = 3; - v[710][1] = 3; - v[711][1] = 3; - v[712][1] = 3; - v[713][1] = 1; - v[714][1] = 3; - v[715][1] = 3; - v[716][1] = 1; - v[717][1] = 3; - v[718][1] = 1; - v[719][1] = 3; - v[720][1] = 1; - v[721][1] = 1; - v[722][1] = 3; - v[723][1] = 3; - v[724][1] = 1; - v[725][1] = 1; - v[726][1] = 1; - v[727][1] = 3; - v[728][1] = 1; - v[729][1] = 3; - v[730][1] = 3; - v[731][1] = 1; - v[732][1] = 3; - v[733][1] = 3; - v[734][1] = 1; - v[735][1] = 3; - v[736][1] = 1; - v[737][1] = 1; - v[738][1] = 3; - v[739][1] = 3; - v[740][1] = 3; - v[741][1] = 1; - v[742][1] = 1; - v[743][1] = 1; - v[744][1] = 3; - v[745][1] = 1; - v[746][1] = 1; - v[747][1] = 1; - v[748][1] = 3; - v[749][1] = 3; - v[750][1] = 3; - v[751][1] = 1; - v[752][1] = 3; - v[753][1] = 3; - v[754][1] = 1; - v[755][1] = 3; - v[756][1] = 1; - v[757][1] = 1; - v[758][1] = 3; - v[759][1] = 3; - v[760][1] = 3; - v[761][1] = 1; - v[762][1] = 3; - v[763][1] = 3; - v[764][1] = 1; - v[765][1] = 1; - v[766][1] = 1; - v[767][1] = 3; - v[768][1] = 1; - v[769][1] = 3; - v[770][1] = 3; - v[771][1] = 3; - v[772][1] = 3; - v[773][1] = 3; - v[774][1] = 3; - v[775][1] = 3; - v[776][1] = 3; - v[777][1] = 1; - v[778][1] = 3; - v[779][1] = 3; - v[780][1] = 1; - v[781][1] = 3; - v[782][1] = 1; - v[783][1] = 1; - v[784][1] = 3; - v[785][1] = 3; - v[786][1] = 3; - v[787][1] = 1; - v[788][1] = 3; - v[789][1] = 3; - v[790][1] = 3; - v[791][1] = 3; - v[792][1] = 3; - v[793][1] = 1; - v[794][1] = 3; - v[795][1] = 3; - v[796][1] = 3; - v[797][1] = 1; - v[798][1] = 1; - v[799][1] = 1; - v[800][1] = 3; - v[801][1] = 3; - v[802][1] = 1; - v[803][1] = 3; - v[804][1] = 3; - v[805][1] = 1; - v[806][1] = 3; - v[807][1] = 1; - v[808][1] = 3; - v[809][1] = 1; - v[810][1] = 3; - v[811][1] = 1; - v[812][1] = 3; - v[813][1] = 3; - v[814][1] = 3; - v[815][1] = 3; - v[816][1] = 3; - v[817][1] = 3; - v[818][1] = 1; - v[819][1] = 1; - v[820][1] = 3; - v[821][1] = 1; - v[822][1] = 3; - v[823][1] = 1; - v[824][1] = 1; - v[825][1] = 1; - v[826][1] = 1; - v[827][1] = 1; - v[828][1] = 3; - v[829][1] = 1; - v[830][1] = 1; - v[831][1] = 1; - v[832][1] = 3; - v[833][1] = 1; - v[834][1] = 3; - v[835][1] = 1; - v[836][1] = 1; - v[837][1] = 3; - v[838][1] = 3; - v[839][1] = 3; - v[840][1] = 1; - v[841][1] = 3; - v[842][1] = 1; - v[843][1] = 3; - v[844][1] = 1; - v[845][1] = 1; - v[846][1] = 3; - v[847][1] = 1; - v[848][1] = 3; - v[849][1] = 3; - v[850][1] = 1; - v[851][1] = 3; - v[852][1] = 1; - v[853][1] = 3; - v[854][1] = 3; - v[855][1] = 1; - v[856][1] = 3; - v[857][1] = 3; - v[858][1] = 1; - v[859][1] = 3; - v[860][1] = 3; - v[861][1] = 3; - v[862][1] = 3; - v[863][1] = 3; - v[864][1] = 3; - v[865][1] = 1; - v[866][1] = 3; - v[867][1] = 1; - v[868][1] = 1; - v[869][1] = 3; - v[870][1] = 3; - v[871][1] = 3; - v[872][1] = 1; - v[873][1] = 1; - v[874][1] = 3; - v[875][1] = 3; - v[876][1] = 3; - v[877][1] = 3; - v[878][1] = 3; - v[879][1] = 3; - v[880][1] = 3; - v[881][1] = 1; - v[882][1] = 3; - v[883][1] = 3; - v[884][1] = 3; - v[885][1] = 3; - v[886][1] = 1; - v[887][1] = 3; - v[888][1] = 1; - v[889][1] = 3; - v[890][1] = 3; - v[891][1] = 3; - v[892][1] = 1; - v[893][1] = 3; - v[894][1] = 1; - v[895][1] = 3; - v[896][1] = 1; - v[897][1] = 1; - v[898][1] = 1; - v[899][1] = 3; - v[900][1] = 3; - v[901][1] = 1; - v[902][1] = 3; - v[903][1] = 1; - v[904][1] = 1; - v[905][1] = 3; - v[906][1] = 3; - v[907][1] = 1; - v[908][1] = 3; - v[909][1] = 1; - v[910][1] = 1; - v[911][1] = 1; - v[912][1] = 1; - v[913][1] = 3; - v[914][1] = 1; - v[915][1] = 3; - v[916][1] = 1; - v[917][1] = 1; - v[918][1] = 3; - v[919][1] = 1; - v[920][1] = 3; - v[921][1] = 1; - v[922][1] = 3; - v[923][1] = 3; - v[924][1] = 3; - v[925][1] = 3; - v[926][1] = 3; - v[927][1] = 3; - v[928][1] = 1; - v[929][1] = 3; - v[930][1] = 3; - v[931][1] = 3; - v[932][1] = 3; - v[933][1] = 1; - v[934][1] = 3; - v[935][1] = 3; - v[936][1] = 1; - v[937][1] = 3; - v[938][1] = 3; - v[939][1] = 3; - v[940][1] = 3; - v[941][1] = 3; - v[942][1] = 1; - v[943][1] = 1; - v[944][1] = 1; - v[945][1] = 1; - v[946][1] = 3; - v[947][1] = 3; - v[948][1] = 3; - v[949][1] = 1; - v[950][1] = 3; - v[951][1] = 3; - v[952][1] = 1; - v[953][1] = 1; - v[954][1] = 3; - v[955][1] = 3; - v[956][1] = 1; - v[957][1] = 1; - v[958][1] = 3; - v[959][1] = 3; - v[960][1] = 1; - v[961][1] = 3; - v[962][1] = 1; - v[963][1] = 1; - v[964][1] = 3; - v[965][1] = 1; - v[966][1] = 3; - v[967][1] = 3; - v[968][1] = 3; - v[969][1] = 3; - v[970][1] = 3; - v[971][1] = 1; - v[972][1] = 3; - v[973][1] = 1; - v[974][1] = 1; - v[975][1] = 3; - v[976][1] = 3; - v[977][1] = 3; - v[978][1] = 3; - v[979][1] = 1; - v[980][1] = 3; - v[981][1] = 1; - v[982][1] = 1; - v[983][1] = 3; - v[984][1] = 3; - v[985][1] = 3; - v[986][1] = 3; - v[987][1] = 3; - v[988][1] = 3; - v[989][1] = 1; - v[990][1] = 1; - v[991][1] = 3; - v[992][1] = 1; - v[993][1] = 3; - v[994][1] = 1; - v[995][1] = 1; - v[996][1] = 3; - v[997][1] = 1; - v[998][1] = 1; - v[999][1] = 1; - v[1000][1] = 1; - v[1001][1] = 3; - v[1002][1] = 3; - v[1003][1] = 1; - v[1004][1] = 1; - v[1005][1] = 3; - v[1006][1] = 1; - v[1007][1] = 1; - v[1008][1] = 1; - v[1009][1] = 3; - v[1010][1] = 1; - v[1011][1] = 3; - v[1012][1] = 1; - v[1013][1] = 1; - v[1014][1] = 3; - v[1015][1] = 3; - v[1016][1] = 1; - v[1017][1] = 3; - v[1018][1] = 1; - v[1019][1] = 1; - v[1020][1] = 3; - v[1021][1] = 3; - v[1022][1] = 3; - v[1023][1] = 3; - v[1024][1] = 3; - v[1025][1] = 1; - v[1026][1] = 3; - v[1027][1] = 1; - v[1028][1] = 1; - v[1029][1] = 1; - v[1030][1] = 3; - v[1031][1] = 1; - v[1032][1] = 1; - v[1033][1] = 1; - v[1034][1] = 3; - v[1035][1] = 1; - v[1036][1] = 1; - v[1037][1] = 3; - v[1038][1] = 1; - v[1039][1] = 3; - v[1040][1] = 3; - v[1041][1] = 3; - v[1042][1] = 3; - v[1043][1] = 3; - v[1044][1] = 1; - v[1045][1] = 1; - v[1046][1] = 1; - v[1047][1] = 3; - v[1048][1] = 3; - v[1049][1] = 3; - v[1050][1] = 3; - v[1051][1] = 1; - v[1052][1] = 3; - v[1053][1] = 3; - v[1054][1] = 3; - v[1055][1] = 3; - v[1056][1] = 1; - v[1057][1] = 1; - v[1058][1] = 3; - v[1059][1] = 3; - v[1060][1] = 3; - v[1061][1] = 1; - v[1062][1] = 3; - v[1063][1] = 1; - v[1064][1] = 1; - v[1065][1] = 3; - v[1066][1] = 3; - v[1067][1] = 1; - v[1068][1] = 3; - v[1069][1] = 3; - v[1070][1] = 1; - v[1071][1] = 1; - v[1072][1] = 1; - v[1073][1] = 1; - v[1074][1] = 1; - v[1075][1] = 3; - v[1076][1] = 1; - v[1077][1] = 1; - v[1078][1] = 3; - v[1079][1] = 3; - v[1080][1] = 1; - v[1081][1] = 1; - v[1082][1] = 1; - v[1083][1] = 3; - v[1084][1] = 1; - v[1085][1] = 1; - v[1086][1] = 3; - v[1087][1] = 3; - v[1088][1] = 1; - v[1089][1] = 3; - v[1090][1] = 3; - v[1091][1] = 3; - v[1092][1] = 3; - v[1093][1] = 3; - v[1094][1] = 3; - v[1095][1] = 3; - v[1096][1] = 3; - v[1097][1] = 1; - v[1098][1] = 1; - v[1099][1] = 3; - v[1100][1] = 3; - v[1101][1] = 1; - v[1102][1] = 1; - v[1103][1] = 3; - v[1104][1] = 1; - v[1105][1] = 3; - v[1106][1] = 3; - v[1107][1] = 3; - v[1108][1] = 3; - v[1109][1] = 3; - v[1110][1] = 1; - - v[3][2] = 7; - v[4][2] = 5; - v[5][2] = 1; - v[6][2] = 3; - v[7][2] = 3; - v[8][2] = 7; - v[9][2] = 5; - v[10][2] = 5; - v[11][2] = 7; - v[12][2] = 7; - v[13][2] = 1; - v[14][2] = 3; - v[15][2] = 3; - v[16][2] = 7; - v[17][2] = 5; - v[18][2] = 1; - v[19][2] = 1; - v[20][2] = 5; - v[21][2] = 3; - v[22][2] = 7; - v[23][2] = 1; - v[24][2] = 7; - v[25][2] = 5; - v[26][2] = 1; - v[27][2] = 3; - v[28][2] = 7; - v[29][2] = 7; - v[30][2] = 1; - v[31][2] = 1; - v[32][2] = 1; - v[33][2] = 5; - v[34][2] = 7; - v[35][2] = 7; - v[36][2] = 5; - v[37][2] = 1; - v[38][2] = 3; - v[39][2] = 3; - v[40][2] = 7; - v[41][2] = 5; - v[42][2] = 5; - v[43][2] = 5; - v[44][2] = 3; - v[45][2] = 3; - v[46][2] = 3; - v[47][2] = 1; - v[48][2] = 1; - v[49][2] = 5; - v[50][2] = 1; - v[51][2] = 1; - v[52][2] = 5; - v[53][2] = 3; - v[54][2] = 3; - v[55][2] = 3; - v[56][2] = 3; - v[57][2] = 1; - v[58][2] = 3; - v[59][2] = 7; - v[60][2] = 5; - v[61][2] = 7; - v[62][2] = 3; - v[63][2] = 7; - v[64][2] = 1; - v[65][2] = 3; - v[66][2] = 3; - v[67][2] = 5; - v[68][2] = 1; - v[69][2] = 3; - v[70][2] = 5; - v[71][2] = 5; - v[72][2] = 7; - v[73][2] = 7; - v[74][2] = 7; - v[75][2] = 1; - v[76][2] = 1; - v[77][2] = 3; - v[78][2] = 3; - v[79][2] = 1; - v[80][2] = 1; - v[81][2] = 5; - v[82][2] = 1; - v[83][2] = 5; - v[84][2] = 7; - v[85][2] = 5; - v[86][2] = 1; - v[87][2] = 7; - v[88][2] = 5; - v[89][2] = 3; - v[90][2] = 3; - v[91][2] = 1; - v[92][2] = 5; - v[93][2] = 7; - v[94][2] = 1; - v[95][2] = 7; - v[96][2] = 5; - v[97][2] = 1; - v[98][2] = 7; - v[99][2] = 3; - v[100][2] = 1; - v[101][2] = 7; - v[102][2] = 1; - v[103][2] = 7; - v[104][2] = 3; - v[105][2] = 3; - v[106][2] = 5; - v[107][2] = 7; - v[108][2] = 3; - v[109][2] = 3; - v[110][2] = 5; - v[111][2] = 1; - v[112][2] = 3; - v[113][2] = 3; - v[114][2] = 1; - v[115][2] = 3; - v[116][2] = 5; - v[117][2] = 1; - v[118][2] = 3; - v[119][2] = 3; - v[120][2] = 3; - v[121][2] = 7; - v[122][2] = 1; - v[123][2] = 1; - v[124][2] = 7; - v[125][2] = 3; - v[126][2] = 1; - v[127][2] = 3; - v[128][2] = 7; - v[129][2] = 5; - v[130][2] = 5; - v[131][2] = 7; - v[132][2] = 5; - v[133][2] = 5; - v[134][2] = 3; - v[135][2] = 1; - v[136][2] = 3; - v[137][2] = 3; - v[138][2] = 3; - v[139][2] = 1; - v[140][2] = 3; - v[141][2] = 3; - v[142][2] = 7; - v[143][2] = 3; - v[144][2] = 3; - v[145][2] = 1; - v[146][2] = 7; - v[147][2] = 5; - v[148][2] = 1; - v[149][2] = 7; - v[150][2] = 7; - v[151][2] = 5; - v[152][2] = 7; - v[153][2] = 5; - v[154][2] = 1; - v[155][2] = 3; - v[156][2] = 1; - v[157][2] = 7; - v[158][2] = 3; - v[159][2] = 7; - v[160][2] = 3; - v[161][2] = 5; - v[162][2] = 7; - v[163][2] = 3; - v[164][2] = 1; - v[165][2] = 3; - v[166][2] = 3; - v[167][2] = 3; - v[168][2] = 1; - v[169][2] = 5; - v[170][2] = 7; - v[171][2] = 3; - v[172][2] = 3; - v[173][2] = 7; - v[174][2] = 7; - v[175][2] = 7; - v[176][2] = 5; - v[177][2] = 3; - v[178][2] = 1; - v[179][2] = 7; - v[180][2] = 1; - v[181][2] = 3; - v[182][2] = 7; - v[183][2] = 5; - v[184][2] = 3; - v[185][2] = 3; - v[186][2] = 3; - v[187][2] = 7; - v[188][2] = 1; - v[189][2] = 1; - v[190][2] = 3; - v[191][2] = 1; - v[192][2] = 5; - v[193][2] = 7; - v[194][2] = 1; - v[195][2] = 3; - v[196][2] = 5; - v[197][2] = 3; - v[198][2] = 5; - v[199][2] = 3; - v[200][2] = 3; - v[201][2] = 7; - v[202][2] = 5; - v[203][2] = 5; - v[204][2] = 3; - v[205][2] = 3; - v[206][2] = 1; - v[207][2] = 3; - v[208][2] = 7; - v[209][2] = 7; - v[210][2] = 7; - v[211][2] = 1; - v[212][2] = 5; - v[213][2] = 7; - v[214][2] = 1; - v[215][2] = 3; - v[216][2] = 1; - v[217][2] = 1; - v[218][2] = 7; - v[219][2] = 1; - v[220][2] = 3; - v[221][2] = 1; - v[222][2] = 7; - v[223][2] = 1; - v[224][2] = 5; - v[225][2] = 3; - v[226][2] = 5; - v[227][2] = 3; - v[228][2] = 1; - v[229][2] = 1; - v[230][2] = 5; - v[231][2] = 5; - v[232][2] = 3; - v[233][2] = 3; - v[234][2] = 5; - v[235][2] = 7; - v[236][2] = 1; - v[237][2] = 5; - v[238][2] = 3; - v[239][2] = 7; - v[240][2] = 7; - v[241][2] = 3; - v[242][2] = 5; - v[243][2] = 3; - v[244][2] = 3; - v[245][2] = 1; - v[246][2] = 7; - v[247][2] = 3; - v[248][2] = 1; - v[249][2] = 3; - v[250][2] = 5; - v[251][2] = 7; - v[252][2] = 1; - v[253][2] = 3; - v[254][2] = 7; - v[255][2] = 1; - v[256][2] = 5; - v[257][2] = 1; - v[258][2] = 3; - v[259][2] = 1; - v[260][2] = 5; - v[261][2] = 3; - v[262][2] = 1; - v[263][2] = 7; - v[264][2] = 1; - v[265][2] = 5; - v[266][2] = 5; - v[267][2] = 5; - v[268][2] = 3; - v[269][2] = 7; - v[270][2] = 1; - v[271][2] = 1; - v[272][2] = 7; - v[273][2] = 3; - v[274][2] = 1; - v[275][2] = 1; - v[276][2] = 7; - v[277][2] = 5; - v[278][2] = 7; - v[279][2] = 5; - v[280][2] = 7; - v[281][2] = 7; - v[282][2] = 3; - v[283][2] = 7; - v[284][2] = 1; - v[285][2] = 3; - v[286][2] = 7; - v[287][2] = 7; - v[288][2] = 3; - v[289][2] = 5; - v[290][2] = 1; - v[291][2] = 1; - v[292][2] = 7; - v[293][2] = 1; - v[294][2] = 5; - v[295][2] = 5; - v[296][2] = 5; - v[297][2] = 1; - v[298][2] = 5; - v[299][2] = 1; - v[300][2] = 7; - v[301][2] = 5; - v[302][2] = 5; - v[303][2] = 7; - v[304][2] = 1; - v[305][2] = 1; - v[306][2] = 7; - v[307][2] = 1; - v[308][2] = 7; - v[309][2] = 7; - v[310][2] = 1; - v[311][2] = 1; - v[312][2] = 3; - v[313][2] = 3; - v[314][2] = 3; - v[315][2] = 7; - v[316][2] = 7; - v[317][2] = 5; - v[318][2] = 3; - v[319][2] = 7; - v[320][2] = 3; - v[321][2] = 1; - v[322][2] = 3; - v[323][2] = 7; - v[324][2] = 5; - v[325][2] = 3; - v[326][2] = 3; - v[327][2] = 5; - v[328][2] = 7; - v[329][2] = 1; - v[330][2] = 1; - v[331][2] = 5; - v[332][2] = 5; - v[333][2] = 7; - v[334][2] = 7; - v[335][2] = 1; - v[336][2] = 1; - v[337][2] = 1; - v[338][2] = 1; - v[339][2] = 5; - v[340][2] = 5; - v[341][2] = 5; - v[342][2] = 7; - v[343][2] = 5; - v[344][2] = 7; - v[345][2] = 1; - v[346][2] = 1; - v[347][2] = 3; - v[348][2] = 5; - v[349][2] = 1; - v[350][2] = 3; - v[351][2] = 3; - v[352][2] = 7; - v[353][2] = 3; - v[354][2] = 7; - v[355][2] = 5; - v[356][2] = 3; - v[357][2] = 5; - v[358][2] = 3; - v[359][2] = 1; - v[360][2] = 7; - v[361][2] = 1; - v[362][2] = 7; - v[363][2] = 7; - v[364][2] = 1; - v[365][2] = 1; - v[366][2] = 7; - v[367][2] = 7; - v[368][2] = 7; - v[369][2] = 5; - v[370][2] = 5; - v[371][2] = 1; - v[372][2] = 1; - v[373][2] = 7; - v[374][2] = 5; - v[375][2] = 5; - v[376][2] = 7; - v[377][2] = 5; - v[378][2] = 1; - v[379][2] = 1; - v[380][2] = 5; - v[381][2] = 5; - v[382][2] = 5; - v[383][2] = 5; - v[384][2] = 5; - v[385][2] = 5; - v[386][2] = 1; - v[387][2] = 3; - v[388][2] = 1; - v[389][2] = 5; - v[390][2] = 7; - v[391][2] = 3; - v[392][2] = 3; - v[393][2] = 5; - v[394][2] = 7; - v[395][2] = 3; - v[396][2] = 7; - v[397][2] = 1; - v[398][2] = 7; - v[399][2] = 7; - v[400][2] = 1; - v[401][2] = 3; - v[402][2] = 5; - v[403][2] = 1; - v[404][2] = 5; - v[405][2] = 5; - v[406][2] = 3; - v[407][2] = 7; - v[408][2] = 3; - v[409][2] = 7; - v[410][2] = 7; - v[411][2] = 5; - v[412][2] = 7; - v[413][2] = 5; - v[414][2] = 7; - v[415][2] = 1; - v[416][2] = 1; - v[417][2] = 5; - v[418][2] = 3; - v[419][2] = 5; - v[420][2] = 1; - v[421][2] = 5; - v[422][2] = 3; - v[423][2] = 7; - v[424][2] = 1; - v[425][2] = 5; - v[426][2] = 7; - v[427][2] = 7; - v[428][2] = 3; - v[429][2] = 5; - v[430][2] = 1; - v[431][2] = 3; - v[432][2] = 5; - v[433][2] = 1; - v[434][2] = 5; - v[435][2] = 3; - v[436][2] = 3; - v[437][2] = 3; - v[438][2] = 7; - v[439][2] = 3; - v[440][2] = 5; - v[441][2] = 1; - v[442][2] = 3; - v[443][2] = 7; - v[444][2] = 7; - v[445][2] = 3; - v[446][2] = 7; - v[447][2] = 5; - v[448][2] = 3; - v[449][2] = 3; - v[450][2] = 1; - v[451][2] = 7; - v[452][2] = 5; - v[453][2] = 1; - v[454][2] = 1; - v[455][2] = 3; - v[456][2] = 7; - v[457][2] = 1; - v[458][2] = 7; - v[459][2] = 1; - v[460][2] = 7; - v[461][2] = 3; - v[462][2] = 7; - v[463][2] = 3; - v[464][2] = 5; - v[465][2] = 7; - v[466][2] = 3; - v[467][2] = 5; - v[468][2] = 3; - v[469][2] = 1; - v[470][2] = 1; - v[471][2] = 1; - v[472][2] = 5; - v[473][2] = 7; - v[474][2] = 7; - v[475][2] = 3; - v[476][2] = 3; - v[477][2] = 1; - v[478][2] = 1; - v[479][2] = 1; - v[480][2] = 5; - v[481][2] = 5; - v[482][2] = 7; - v[483][2] = 3; - v[484][2] = 1; - v[485][2] = 1; - v[486][2] = 3; - v[487][2] = 3; - v[488][2] = 7; - v[489][2] = 3; - v[490][2] = 3; - v[491][2] = 5; - v[492][2] = 1; - v[493][2] = 3; - v[494][2] = 7; - v[495][2] = 3; - v[496][2] = 3; - v[497][2] = 7; - v[498][2] = 3; - v[499][2] = 5; - v[500][2] = 7; - v[501][2] = 5; - v[502][2] = 7; - v[503][2] = 7; - v[504][2] = 3; - v[505][2] = 3; - v[506][2] = 5; - v[507][2] = 1; - v[508][2] = 3; - v[509][2] = 5; - v[510][2] = 3; - v[511][2] = 1; - v[512][2] = 3; - v[513][2] = 5; - v[514][2] = 1; - v[515][2] = 1; - v[516][2] = 3; - v[517][2] = 7; - v[518][2] = 7; - v[519][2] = 1; - v[520][2] = 5; - v[521][2] = 1; - v[522][2] = 3; - v[523][2] = 7; - v[524][2] = 3; - v[525][2] = 7; - v[526][2] = 3; - v[527][2] = 5; - v[528][2] = 1; - v[529][2] = 7; - v[530][2] = 1; - v[531][2] = 1; - v[532][2] = 3; - v[533][2] = 5; - v[534][2] = 3; - v[535][2] = 7; - v[536][2] = 1; - v[537][2] = 5; - v[538][2] = 5; - v[539][2] = 1; - v[540][2] = 1; - v[541][2] = 3; - v[542][2] = 1; - v[543][2] = 3; - v[544][2] = 3; - v[545][2] = 7; - v[546][2] = 1; - v[547][2] = 7; - v[548][2] = 3; - v[549][2] = 1; - v[550][2] = 7; - v[551][2] = 3; - v[552][2] = 1; - v[553][2] = 7; - v[554][2] = 3; - v[555][2] = 5; - v[556][2] = 3; - v[557][2] = 5; - v[558][2] = 7; - v[559][2] = 3; - v[560][2] = 3; - v[561][2] = 3; - v[562][2] = 5; - v[563][2] = 1; - v[564][2] = 7; - v[565][2] = 7; - v[566][2] = 1; - v[567][2] = 3; - v[568][2] = 1; - v[569][2] = 3; - v[570][2] = 7; - v[571][2] = 7; - v[572][2] = 1; - v[573][2] = 3; - v[574][2] = 7; - v[575][2] = 3; - v[576][2] = 1; - v[577][2] = 5; - v[578][2] = 3; - v[579][2] = 1; - v[580][2] = 1; - v[581][2] = 1; - v[582][2] = 5; - v[583][2] = 3; - v[584][2] = 3; - v[585][2] = 7; - v[586][2] = 1; - v[587][2] = 5; - v[588][2] = 3; - v[589][2] = 5; - v[590][2] = 1; - v[591][2] = 3; - v[592][2] = 1; - v[593][2] = 3; - v[594][2] = 1; - v[595][2] = 5; - v[596][2] = 7; - v[597][2] = 7; - v[598][2] = 1; - v[599][2] = 1; - v[600][2] = 5; - v[601][2] = 3; - v[602][2] = 1; - v[603][2] = 5; - v[604][2] = 1; - v[605][2] = 1; - v[606][2] = 7; - v[607][2] = 7; - v[608][2] = 3; - v[609][2] = 5; - v[610][2] = 5; - v[611][2] = 1; - v[612][2] = 7; - v[613][2] = 1; - v[614][2] = 5; - v[615][2] = 1; - v[616][2] = 1; - v[617][2] = 3; - v[618][2] = 1; - v[619][2] = 5; - v[620][2] = 7; - v[621][2] = 5; - v[622][2] = 7; - v[623][2] = 7; - v[624][2] = 1; - v[625][2] = 5; - v[626][2] = 1; - v[627][2] = 1; - v[628][2] = 3; - v[629][2] = 5; - v[630][2] = 1; - v[631][2] = 5; - v[632][2] = 5; - v[633][2] = 3; - v[634][2] = 1; - v[635][2] = 3; - v[636][2] = 1; - v[637][2] = 5; - v[638][2] = 5; - v[639][2] = 3; - v[640][2] = 3; - v[641][2] = 3; - v[642][2] = 3; - v[643][2] = 1; - v[644][2] = 1; - v[645][2] = 3; - v[646][2] = 1; - v[647][2] = 3; - v[648][2] = 5; - v[649][2] = 5; - v[650][2] = 7; - v[651][2] = 5; - v[652][2] = 5; - v[653][2] = 7; - v[654][2] = 5; - v[655][2] = 7; - v[656][2] = 1; - v[657][2] = 3; - v[658][2] = 7; - v[659][2] = 7; - v[660][2] = 3; - v[661][2] = 5; - v[662][2] = 5; - v[663][2] = 7; - v[664][2] = 5; - v[665][2] = 5; - v[666][2] = 3; - v[667][2] = 3; - v[668][2] = 3; - v[669][2] = 1; - v[670][2] = 7; - v[671][2] = 1; - v[672][2] = 5; - v[673][2] = 5; - v[674][2] = 5; - v[675][2] = 3; - v[676][2] = 3; - v[677][2] = 5; - v[678][2] = 1; - v[679][2] = 3; - v[680][2] = 1; - v[681][2] = 3; - v[682][2] = 3; - v[683][2] = 3; - v[684][2] = 7; - v[685][2] = 1; - v[686][2] = 7; - v[687][2] = 7; - v[688][2] = 3; - v[689][2] = 7; - v[690][2] = 1; - v[691][2] = 1; - v[692][2] = 5; - v[693][2] = 7; - v[694][2] = 1; - v[695][2] = 7; - v[696][2] = 1; - v[697][2] = 7; - v[698][2] = 7; - v[699][2] = 1; - v[700][2] = 3; - v[701][2] = 7; - v[702][2] = 5; - v[703][2] = 1; - v[704][2] = 3; - v[705][2] = 5; - v[706][2] = 5; - v[707][2] = 5; - v[708][2] = 1; - v[709][2] = 1; - v[710][2] = 7; - v[711][2] = 1; - v[712][2] = 7; - v[713][2] = 1; - v[714][2] = 7; - v[715][2] = 7; - v[716][2] = 3; - v[717][2] = 1; - v[718][2] = 1; - v[719][2] = 5; - v[720][2] = 1; - v[721][2] = 5; - v[722][2] = 1; - v[723][2] = 5; - v[724][2] = 3; - v[725][2] = 5; - v[726][2] = 5; - v[727][2] = 5; - v[728][2] = 5; - v[729][2] = 5; - v[730][2] = 3; - v[731][2] = 3; - v[732][2] = 7; - v[733][2] = 3; - v[734][2] = 3; - v[735][2] = 5; - v[736][2] = 5; - v[737][2] = 3; - v[738][2] = 7; - v[739][2] = 1; - v[740][2] = 5; - v[741][2] = 7; - v[742][2] = 5; - v[743][2] = 1; - v[744][2] = 5; - v[745][2] = 5; - v[746][2] = 3; - v[747][2] = 5; - v[748][2] = 5; - v[749][2] = 7; - v[750][2] = 5; - v[751][2] = 3; - v[752][2] = 5; - v[753][2] = 5; - v[754][2] = 5; - v[755][2] = 1; - v[756][2] = 5; - v[757][2] = 5; - v[758][2] = 5; - v[759][2] = 5; - v[760][2] = 1; - v[761][2] = 3; - v[762][2] = 5; - v[763][2] = 3; - v[764][2] = 1; - v[765][2] = 7; - v[766][2] = 5; - v[767][2] = 5; - v[768][2] = 7; - v[769][2] = 1; - v[770][2] = 5; - v[771][2] = 3; - v[772][2] = 3; - v[773][2] = 1; - v[774][2] = 5; - v[775][2] = 3; - v[776][2] = 7; - v[777][2] = 1; - v[778][2] = 7; - v[779][2] = 5; - v[780][2] = 1; - v[781][2] = 1; - v[782][2] = 3; - v[783][2] = 1; - v[784][2] = 1; - v[785][2] = 7; - v[786][2] = 1; - v[787][2] = 5; - v[788][2] = 5; - v[789][2] = 3; - v[790][2] = 7; - v[791][2] = 3; - v[792][2] = 7; - v[793][2] = 5; - v[794][2] = 3; - v[795][2] = 1; - v[796][2] = 1; - v[797][2] = 3; - v[798][2] = 1; - v[799][2] = 3; - v[800][2] = 5; - v[801][2] = 5; - v[802][2] = 7; - v[803][2] = 5; - v[804][2] = 3; - v[805][2] = 7; - v[806][2] = 7; - v[807][2] = 7; - v[808][2] = 3; - v[809][2] = 7; - v[810][2] = 3; - v[811][2] = 7; - v[812][2] = 1; - v[813][2] = 3; - v[814][2] = 1; - v[815][2] = 7; - v[816][2] = 7; - v[817][2] = 1; - v[818][2] = 7; - v[819][2] = 3; - v[820][2] = 7; - v[821][2] = 3; - v[822][2] = 7; - v[823][2] = 3; - v[824][2] = 7; - v[825][2] = 3; - v[826][2] = 5; - v[827][2] = 1; - v[828][2] = 1; - v[829][2] = 7; - v[830][2] = 3; - v[831][2] = 1; - v[832][2] = 5; - v[833][2] = 5; - v[834][2] = 7; - v[835][2] = 1; - v[836][2] = 5; - v[837][2] = 5; - v[838][2] = 5; - v[839][2] = 7; - v[840][2] = 1; - v[841][2] = 5; - v[842][2] = 5; - v[843][2] = 1; - v[844][2] = 5; - v[845][2] = 5; - v[846][2] = 3; - v[847][2] = 1; - v[848][2] = 3; - v[849][2] = 1; - v[850][2] = 7; - v[851][2] = 3; - v[852][2] = 1; - v[853][2] = 3; - v[854][2] = 5; - v[855][2] = 7; - v[856][2] = 7; - v[857][2] = 7; - v[858][2] = 1; - v[859][2] = 1; - v[860][2] = 7; - v[861][2] = 3; - v[862][2] = 1; - v[863][2] = 5; - v[864][2] = 5; - v[865][2] = 5; - v[866][2] = 1; - v[867][2] = 1; - v[868][2] = 1; - v[869][2] = 1; - v[870][2] = 1; - v[871][2] = 5; - v[872][2] = 3; - v[873][2] = 5; - v[874][2] = 1; - v[875][2] = 3; - v[876][2] = 5; - v[877][2] = 3; - v[878][2] = 1; - v[879][2] = 1; - v[880][2] = 1; - v[881][2] = 1; - v[882][2] = 3; - v[883][2] = 7; - v[884][2] = 3; - v[885][2] = 7; - v[886][2] = 5; - v[887][2] = 7; - v[888][2] = 1; - v[889][2] = 5; - v[890][2] = 5; - v[891][2] = 7; - v[892][2] = 5; - v[893][2] = 3; - v[894][2] = 3; - v[895][2] = 7; - v[896][2] = 5; - v[897][2] = 3; - v[898][2] = 1; - v[899][2] = 1; - v[900][2] = 3; - v[901][2] = 1; - v[902][2] = 3; - v[903][2] = 1; - v[904][2] = 1; - v[905][2] = 3; - v[906][2] = 7; - v[907][2] = 1; - v[908][2] = 7; - v[909][2] = 1; - v[910][2] = 1; - v[911][2] = 5; - v[912][2] = 1; - v[913][2] = 7; - v[914][2] = 5; - v[915][2] = 3; - v[916][2] = 7; - v[917][2] = 3; - v[918][2] = 5; - v[919][2] = 3; - v[920][2] = 1; - v[921][2] = 1; - v[922][2] = 5; - v[923][2] = 5; - v[924][2] = 1; - v[925][2] = 7; - v[926][2] = 7; - v[927][2] = 3; - v[928][2] = 7; - v[929][2] = 3; - v[930][2] = 7; - v[931][2] = 1; - v[932][2] = 5; - v[933][2] = 1; - v[934][2] = 5; - v[935][2] = 3; - v[936][2] = 7; - v[937][2] = 3; - v[938][2] = 5; - v[939][2] = 7; - v[940][2] = 7; - v[941][2] = 7; - v[942][2] = 3; - v[943][2] = 3; - v[944][2] = 1; - v[945][2] = 1; - v[946][2] = 5; - v[947][2] = 5; - v[948][2] = 3; - v[949][2] = 7; - v[950][2] = 1; - v[951][2] = 1; - v[952][2] = 1; - v[953][2] = 3; - v[954][2] = 5; - v[955][2] = 3; - v[956][2] = 1; - v[957][2] = 1; - v[958][2] = 3; - v[959][2] = 3; - v[960][2] = 7; - v[961][2] = 5; - v[962][2] = 1; - v[963][2] = 1; - v[964][2] = 3; - v[965][2] = 7; - v[966][2] = 1; - v[967][2] = 5; - v[968][2] = 7; - v[969][2] = 3; - v[970][2] = 7; - v[971][2] = 5; - v[972][2] = 5; - v[973][2] = 7; - v[974][2] = 3; - v[975][2] = 5; - v[976][2] = 3; - v[977][2] = 1; - v[978][2] = 5; - v[979][2] = 3; - v[980][2] = 1; - v[981][2] = 1; - v[982][2] = 7; - v[983][2] = 5; - v[984][2] = 1; - v[985][2] = 7; - v[986][2] = 3; - v[987][2] = 7; - v[988][2] = 5; - v[989][2] = 1; - v[990][2] = 7; - v[991][2] = 1; - v[992][2] = 7; - v[993][2] = 7; - v[994][2] = 1; - v[995][2] = 1; - v[996][2] = 7; - v[997][2] = 1; - v[998][2] = 5; - v[999][2] = 5; - v[1000][2] = 1; - v[1001][2] = 1; - v[1002][2] = 7; - v[1003][2] = 5; - v[1004][2] = 7; - v[1005][2] = 1; - v[1006][2] = 5; - v[1007][2] = 3; - v[1008][2] = 5; - v[1009][2] = 3; - v[1010][2] = 3; - v[1011][2] = 7; - v[1012][2] = 1; - v[1013][2] = 5; - v[1014][2] = 1; - v[1015][2] = 1; - v[1016][2] = 5; - v[1017][2] = 5; - v[1018][2] = 3; - v[1019][2] = 3; - v[1020][2] = 7; - v[1021][2] = 5; - v[1022][2] = 5; - v[1023][2] = 1; - v[1024][2] = 1; - v[1025][2] = 1; - v[1026][2] = 3; - v[1027][2] = 1; - v[1028][2] = 5; - v[1029][2] = 7; - v[1030][2] = 7; - v[1031][2] = 1; - v[1032][2] = 7; - v[1033][2] = 5; - v[1034][2] = 7; - v[1035][2] = 3; - v[1036][2] = 7; - v[1037][2] = 3; - v[1038][2] = 1; - v[1039][2] = 3; - v[1040][2] = 7; - v[1041][2] = 3; - v[1042][2] = 1; - v[1043][2] = 5; - v[1044][2] = 5; - v[1045][2] = 3; - v[1046][2] = 5; - v[1047][2] = 1; - v[1048][2] = 3; - v[1049][2] = 5; - v[1050][2] = 5; - v[1051][2] = 5; - v[1052][2] = 1; - v[1053][2] = 1; - v[1054][2] = 7; - v[1055][2] = 7; - v[1056][2] = 1; - v[1057][2] = 5; - v[1058][2] = 5; - v[1059][2] = 1; - v[1060][2] = 3; - v[1061][2] = 5; - v[1062][2] = 1; - v[1063][2] = 5; - v[1064][2] = 3; - v[1065][2] = 5; - v[1066][2] = 3; - v[1067][2] = 3; - v[1068][2] = 7; - v[1069][2] = 5; - v[1070][2] = 7; - v[1071][2] = 3; - v[1072][2] = 7; - v[1073][2] = 3; - v[1074][2] = 1; - v[1075][2] = 3; - v[1076][2] = 7; - v[1077][2] = 7; - v[1078][2] = 3; - v[1079][2] = 3; - v[1080][2] = 1; - v[1081][2] = 1; - v[1082][2] = 3; - v[1083][2] = 3; - v[1084][2] = 3; - v[1085][2] = 3; - v[1086][2] = 3; - v[1087][2] = 5; - v[1088][2] = 5; - v[1089][2] = 3; - v[1090][2] = 3; - v[1091][2] = 3; - v[1092][2] = 1; - v[1093][2] = 3; - v[1094][2] = 5; - v[1095][2] = 7; - v[1096][2] = 7; - v[1097][2] = 1; - v[1098][2] = 5; - v[1099][2] = 7; - v[1100][2] = 3; - v[1101][2] = 7; - v[1102][2] = 1; - v[1103][2] = 1; - v[1104][2] = 3; - v[1105][2] = 5; - v[1106][2] = 7; - v[1107][2] = 5; - v[1108][2] = 3; - v[1109][2] = 3; - v[1110][2] = 3; - - v[5][3] = 1; - v[6][3] = 7; - v[7][3] = 9; - v[8][3] = 13; - v[9][3] = 11; - v[10][3] = 1; - v[11][3] = 3; - v[12][3] = 7; - v[13][3] = 9; - v[14][3] = 5; - v[15][3] = 13; - v[16][3] = 13; - v[17][3] = 11; - v[18][3] = 3; - v[19][3] = 15; - v[20][3] = 5; - v[21][3] = 3; - v[22][3] = 15; - v[23][3] = 7; - v[24][3] = 9; - v[25][3] = 13; - v[26][3] = 9; - v[27][3] = 1; - v[28][3] = 11; - v[29][3] = 7; - v[30][3] = 5; - v[31][3] = 15; - v[32][3] = 1; - v[33][3] = 15; - v[34][3] = 11; - v[35][3] = 5; - v[36][3] = 11; - v[37][3] = 1; - v[38][3] = 7; - v[39][3] = 9; - v[40][3] = 7; - v[41][3] = 7; - v[42][3] = 1; - v[43][3] = 15; - v[44][3] = 15; - v[45][3] = 15; - v[46][3] = 13; - v[47][3] = 3; - v[48][3] = 3; - v[49][3] = 15; - v[50][3] = 5; - v[51][3] = 9; - v[52][3] = 7; - v[53][3] = 13; - v[54][3] = 3; - v[55][3] = 7; - v[56][3] = 5; - v[57][3] = 11; - v[58][3] = 9; - v[59][3] = 1; - v[60][3] = 9; - v[61][3] = 1; - v[62][3] = 5; - v[63][3] = 7; - v[64][3] = 13; - v[65][3] = 9; - v[66][3] = 9; - v[67][3] = 1; - v[68][3] = 7; - v[69][3] = 3; - v[70][3] = 5; - v[71][3] = 1; - v[72][3] = 11; - v[73][3] = 11; - v[74][3] = 13; - v[75][3] = 7; - v[76][3] = 7; - v[77][3] = 9; - v[78][3] = 9; - v[79][3] = 1; - v[80][3] = 1; - v[81][3] = 3; - v[82][3] = 9; - v[83][3] = 15; - v[84][3] = 1; - v[85][3] = 5; - v[86][3] = 13; - v[87][3] = 1; - v[88][3] = 9; - v[89][3] = 9; - v[90][3] = 9; - v[91][3] = 9; - v[92][3] = 9; - v[93][3] = 13; - v[94][3] = 11; - v[95][3] = 3; - v[96][3] = 5; - v[97][3] = 11; - v[98][3] = 11; - v[99][3] = 13; - v[100][3] = 5; - v[101][3] = 3; - v[102][3] = 15; - v[103][3] = 1; - v[104][3] = 11; - v[105][3] = 11; - v[106][3] = 7; - v[107][3] = 13; - v[108][3] = 15; - v[109][3] = 11; - v[110][3] = 13; - v[111][3] = 9; - v[112][3] = 11; - v[113][3] = 15; - v[114][3] = 15; - v[115][3] = 13; - v[116][3] = 3; - v[117][3] = 15; - v[118][3] = 7; - v[119][3] = 9; - v[120][3] = 11; - v[121][3] = 13; - v[122][3] = 11; - v[123][3] = 9; - v[124][3] = 9; - v[125][3] = 5; - v[126][3] = 13; - v[127][3] = 9; - v[128][3] = 1; - v[129][3] = 13; - v[130][3] = 7; - v[131][3] = 7; - v[132][3] = 7; - v[133][3] = 7; - v[134][3] = 7; - v[135][3] = 5; - v[136][3] = 9; - v[137][3] = 7; - v[138][3] = 13; - v[139][3] = 11; - v[140][3] = 9; - v[141][3] = 11; - v[142][3] = 15; - v[143][3] = 3; - v[144][3] = 13; - v[145][3] = 11; - v[146][3] = 1; - v[147][3] = 11; - v[148][3] = 3; - v[149][3] = 3; - v[150][3] = 9; - v[151][3] = 11; - v[152][3] = 1; - v[153][3] = 7; - v[154][3] = 1; - v[155][3] = 15; - v[156][3] = 15; - v[157][3] = 3; - v[158][3] = 1; - v[159][3] = 9; - v[160][3] = 1; - v[161][3] = 7; - v[162][3] = 13; - v[163][3] = 11; - v[164][3] = 3; - v[165][3] = 13; - v[166][3] = 11; - v[167][3] = 7; - v[168][3] = 3; - v[169][3] = 3; - v[170][3] = 5; - v[171][3] = 13; - v[172][3] = 11; - v[173][3] = 5; - v[174][3] = 11; - v[175][3] = 1; - v[176][3] = 3; - v[177][3] = 9; - v[178][3] = 7; - v[179][3] = 15; - v[180][3] = 7; - v[181][3] = 5; - v[182][3] = 13; - v[183][3] = 7; - v[184][3] = 9; - v[185][3] = 13; - v[186][3] = 15; - v[187][3] = 13; - v[188][3] = 9; - v[189][3] = 7; - v[190][3] = 15; - v[191][3] = 7; - v[192][3] = 9; - v[193][3] = 5; - v[194][3] = 11; - v[195][3] = 11; - v[196][3] = 13; - v[197][3] = 13; - v[198][3] = 9; - v[199][3] = 3; - v[200][3] = 5; - v[201][3] = 13; - v[202][3] = 9; - v[203][3] = 11; - v[204][3] = 15; - v[205][3] = 11; - v[206][3] = 7; - v[207][3] = 1; - v[208][3] = 7; - v[209][3] = 13; - v[210][3] = 3; - v[211][3] = 13; - v[212][3] = 3; - v[213][3] = 13; - v[214][3] = 9; - v[215][3] = 15; - v[216][3] = 7; - v[217][3] = 13; - v[218][3] = 13; - v[219][3] = 3; - v[220][3] = 13; - v[221][3] = 15; - v[222][3] = 15; - v[223][3] = 11; - v[224][3] = 9; - v[225][3] = 13; - v[226][3] = 9; - v[227][3] = 15; - v[228][3] = 1; - v[229][3] = 1; - v[230][3] = 15; - v[231][3] = 11; - v[232][3] = 11; - v[233][3] = 7; - v[234][3] = 1; - v[235][3] = 11; - v[236][3] = 13; - v[237][3] = 9; - v[238][3] = 13; - v[239][3] = 3; - v[240][3] = 5; - v[241][3] = 11; - v[242][3] = 13; - v[243][3] = 9; - v[244][3] = 9; - v[245][3] = 13; - v[246][3] = 1; - v[247][3] = 11; - v[248][3] = 15; - v[249][3] = 13; - v[250][3] = 3; - v[251][3] = 13; - v[252][3] = 7; - v[253][3] = 15; - v[254][3] = 1; - v[255][3] = 15; - v[256][3] = 3; - v[257][3] = 3; - v[258][3] = 11; - v[259][3] = 7; - v[260][3] = 13; - v[261][3] = 7; - v[262][3] = 7; - v[263][3] = 9; - v[264][3] = 7; - v[265][3] = 5; - v[266][3] = 15; - v[267][3] = 9; - v[268][3] = 5; - v[269][3] = 5; - v[270][3] = 7; - v[271][3] = 15; - v[272][3] = 13; - v[273][3] = 15; - v[274][3] = 5; - v[275][3] = 15; - v[276][3] = 5; - v[277][3] = 3; - v[278][3] = 1; - v[279][3] = 11; - v[280][3] = 7; - v[281][3] = 1; - v[282][3] = 5; - v[283][3] = 7; - v[284][3] = 9; - v[285][3] = 3; - v[286][3] = 11; - v[287][3] = 1; - v[288][3] = 15; - v[289][3] = 1; - v[290][3] = 3; - v[291][3] = 15; - v[292][3] = 11; - v[293][3] = 13; - v[294][3] = 5; - v[295][3] = 13; - v[296][3] = 1; - v[297][3] = 7; - v[298][3] = 1; - v[299][3] = 15; - v[300][3] = 7; - v[301][3] = 5; - v[302][3] = 1; - v[303][3] = 1; - v[304][3] = 15; - v[305][3] = 13; - v[306][3] = 11; - v[307][3] = 11; - v[308][3] = 13; - v[309][3] = 5; - v[310][3] = 11; - v[311][3] = 7; - v[312][3] = 9; - v[313][3] = 7; - v[314][3] = 1; - v[315][3] = 5; - v[316][3] = 3; - v[317][3] = 9; - v[318][3] = 5; - v[319][3] = 5; - v[320][3] = 11; - v[321][3] = 5; - v[322][3] = 1; - v[323][3] = 7; - v[324][3] = 1; - v[325][3] = 11; - v[326][3] = 7; - v[327][3] = 9; - v[328][3] = 13; - v[329][3] = 15; - v[330][3] = 13; - v[331][3] = 3; - v[332][3] = 1; - v[333][3] = 11; - v[334][3] = 13; - v[335][3] = 15; - v[336][3] = 1; - v[337][3] = 1; - v[338][3] = 11; - v[339][3] = 9; - v[340][3] = 13; - v[341][3] = 3; - v[342][3] = 13; - v[343][3] = 11; - v[344][3] = 15; - v[345][3] = 13; - v[346][3] = 9; - v[347][3] = 9; - v[348][3] = 9; - v[349][3] = 5; - v[350][3] = 5; - v[351][3] = 5; - v[352][3] = 5; - v[353][3] = 1; - v[354][3] = 15; - v[355][3] = 5; - v[356][3] = 9; - v[357][3] = 11; - v[358][3] = 7; - v[359][3] = 15; - v[360][3] = 5; - v[361][3] = 3; - v[362][3] = 13; - v[363][3] = 5; - v[364][3] = 3; - v[365][3] = 11; - v[366][3] = 5; - v[367][3] = 1; - v[368][3] = 11; - v[369][3] = 13; - v[370][3] = 9; - v[371][3] = 11; - v[372][3] = 3; - v[373][3] = 7; - v[374][3] = 13; - v[375][3] = 15; - v[376][3] = 1; - v[377][3] = 7; - v[378][3] = 11; - v[379][3] = 1; - v[380][3] = 13; - v[381][3] = 1; - v[382][3] = 15; - v[383][3] = 1; - v[384][3] = 9; - v[385][3] = 7; - v[386][3] = 3; - v[387][3] = 9; - v[388][3] = 11; - v[389][3] = 1; - v[390][3] = 9; - v[391][3] = 13; - v[392][3] = 13; - v[393][3] = 3; - v[394][3] = 11; - v[395][3] = 7; - v[396][3] = 9; - v[397][3] = 1; - v[398][3] = 7; - v[399][3] = 15; - v[400][3] = 9; - v[401][3] = 1; - v[402][3] = 5; - v[403][3] = 13; - v[404][3] = 5; - v[405][3] = 11; - v[406][3] = 3; - v[407][3] = 9; - v[408][3] = 15; - v[409][3] = 11; - v[410][3] = 13; - v[411][3] = 5; - v[412][3] = 1; - v[413][3] = 7; - v[414][3] = 7; - v[415][3] = 5; - v[416][3] = 13; - v[417][3] = 7; - v[418][3] = 7; - v[419][3] = 9; - v[420][3] = 5; - v[421][3] = 11; - v[422][3] = 11; - v[423][3] = 1; - v[424][3] = 1; - v[425][3] = 15; - v[426][3] = 3; - v[427][3] = 13; - v[428][3] = 9; - v[429][3] = 13; - v[430][3] = 9; - v[431][3] = 9; - v[432][3] = 11; - v[433][3] = 5; - v[434][3] = 5; - v[435][3] = 13; - v[436][3] = 15; - v[437][3] = 3; - v[438][3] = 9; - v[439][3] = 15; - v[440][3] = 3; - v[441][3] = 11; - v[442][3] = 11; - v[443][3] = 15; - v[444][3] = 15; - v[445][3] = 3; - v[446][3] = 11; - v[447][3] = 15; - v[448][3] = 15; - v[449][3] = 3; - v[450][3] = 1; - v[451][3] = 3; - v[452][3] = 1; - v[453][3] = 3; - v[454][3] = 3; - v[455][3] = 1; - v[456][3] = 3; - v[457][3] = 13; - v[458][3] = 1; - v[459][3] = 11; - v[460][3] = 5; - v[461][3] = 15; - v[462][3] = 7; - v[463][3] = 15; - v[464][3] = 9; - v[465][3] = 1; - v[466][3] = 7; - v[467][3] = 1; - v[468][3] = 9; - v[469][3] = 11; - v[470][3] = 15; - v[471][3] = 1; - v[472][3] = 13; - v[473][3] = 9; - v[474][3] = 13; - v[475][3] = 11; - v[476][3] = 7; - v[477][3] = 3; - v[478][3] = 7; - v[479][3] = 3; - v[480][3] = 13; - v[481][3] = 7; - v[482][3] = 9; - v[483][3] = 7; - v[484][3] = 7; - v[485][3] = 3; - v[486][3] = 3; - v[487][3] = 9; - v[488][3] = 9; - v[489][3] = 7; - v[490][3] = 5; - v[491][3] = 11; - v[492][3] = 13; - v[493][3] = 13; - v[494][3] = 7; - v[495][3] = 7; - v[496][3] = 15; - v[497][3] = 9; - v[498][3] = 5; - v[499][3] = 5; - v[500][3] = 3; - v[501][3] = 3; - v[502][3] = 13; - v[503][3] = 3; - v[504][3] = 9; - v[505][3] = 3; - v[506][3] = 1; - v[507][3] = 11; - v[508][3] = 1; - v[509][3] = 3; - v[510][3] = 11; - v[511][3] = 15; - v[512][3] = 11; - v[513][3] = 11; - v[514][3] = 11; - v[515][3] = 9; - v[516][3] = 13; - v[517][3] = 7; - v[518][3] = 9; - v[519][3] = 15; - v[520][3] = 9; - v[521][3] = 11; - v[522][3] = 1; - v[523][3] = 3; - v[524][3] = 3; - v[525][3] = 9; - v[526][3] = 7; - v[527][3] = 15; - v[528][3] = 13; - v[529][3] = 13; - v[530][3] = 7; - v[531][3] = 15; - v[532][3] = 9; - v[533][3] = 13; - v[534][3] = 9; - v[535][3] = 15; - v[536][3] = 13; - v[537][3] = 15; - v[538][3] = 9; - v[539][3] = 13; - v[540][3] = 1; - v[541][3] = 11; - v[542][3] = 7; - v[543][3] = 11; - v[544][3] = 3; - v[545][3] = 13; - v[546][3] = 5; - v[547][3] = 1; - v[548][3] = 7; - v[549][3] = 15; - v[550][3] = 3; - v[551][3] = 13; - v[552][3] = 7; - v[553][3] = 13; - v[554][3] = 13; - v[555][3] = 11; - v[556][3] = 3; - v[557][3] = 5; - v[558][3] = 3; - v[559][3] = 13; - v[560][3] = 11; - v[561][3] = 9; - v[562][3] = 9; - v[563][3] = 3; - v[564][3] = 11; - v[565][3] = 11; - v[566][3] = 7; - v[567][3] = 9; - v[568][3] = 13; - v[569][3] = 11; - v[570][3] = 7; - v[571][3] = 15; - v[572][3] = 13; - v[573][3] = 7; - v[574][3] = 5; - v[575][3] = 3; - v[576][3] = 1; - v[577][3] = 5; - v[578][3] = 15; - v[579][3] = 15; - v[580][3] = 3; - v[581][3] = 11; - v[582][3] = 1; - v[583][3] = 7; - v[584][3] = 3; - v[585][3] = 15; - v[586][3] = 11; - v[587][3] = 5; - v[588][3] = 5; - v[589][3] = 3; - v[590][3] = 5; - v[591][3] = 5; - v[592][3] = 1; - v[593][3] = 15; - v[594][3] = 5; - v[595][3] = 1; - v[596][3] = 5; - v[597][3] = 3; - v[598][3] = 7; - v[599][3] = 5; - v[600][3] = 11; - v[601][3] = 3; - v[602][3] = 13; - v[603][3] = 9; - v[604][3] = 13; - v[605][3] = 15; - v[606][3] = 5; - v[607][3] = 3; - v[608][3] = 5; - v[609][3] = 9; - v[610][3] = 5; - v[611][3] = 3; - v[612][3] = 11; - v[613][3] = 1; - v[614][3] = 13; - v[615][3] = 9; - v[616][3] = 15; - v[617][3] = 3; - v[618][3] = 5; - v[619][3] = 11; - v[620][3] = 9; - v[621][3] = 1; - v[622][3] = 3; - v[623][3] = 15; - v[624][3] = 9; - v[625][3] = 9; - v[626][3] = 9; - v[627][3] = 11; - v[628][3] = 7; - v[629][3] = 5; - v[630][3] = 13; - v[631][3] = 1; - v[632][3] = 15; - v[633][3] = 3; - v[634][3] = 13; - v[635][3] = 9; - v[636][3] = 13; - v[637][3] = 5; - v[638][3] = 1; - v[639][3] = 5; - v[640][3] = 1; - v[641][3] = 13; - v[642][3] = 13; - v[643][3] = 7; - v[644][3] = 7; - v[645][3] = 1; - v[646][3] = 9; - v[647][3] = 5; - v[648][3] = 11; - v[649][3] = 9; - v[650][3] = 11; - v[651][3] = 13; - v[652][3] = 3; - v[653][3] = 15; - v[654][3] = 15; - v[655][3] = 13; - v[656][3] = 15; - v[657][3] = 7; - v[658][3] = 5; - v[659][3] = 7; - v[660][3] = 9; - v[661][3] = 7; - v[662][3] = 9; - v[663][3] = 9; - v[664][3] = 9; - v[665][3] = 11; - v[666][3] = 9; - v[667][3] = 3; - v[668][3] = 11; - v[669][3] = 15; - v[670][3] = 13; - v[671][3] = 13; - v[672][3] = 5; - v[673][3] = 9; - v[674][3] = 15; - v[675][3] = 1; - v[676][3] = 1; - v[677][3] = 9; - v[678][3] = 5; - v[679][3] = 13; - v[680][3] = 3; - v[681][3] = 13; - v[682][3] = 15; - v[683][3] = 3; - v[684][3] = 1; - v[685][3] = 3; - v[686][3] = 11; - v[687][3] = 13; - v[688][3] = 1; - v[689][3] = 15; - v[690][3] = 9; - v[691][3] = 9; - v[692][3] = 3; - v[693][3] = 1; - v[694][3] = 9; - v[695][3] = 1; - v[696][3] = 9; - v[697][3] = 1; - v[698][3] = 13; - v[699][3] = 11; - v[700][3] = 15; - v[701][3] = 7; - v[702][3] = 11; - v[703][3] = 15; - v[704][3] = 13; - v[705][3] = 15; - v[706][3] = 1; - v[707][3] = 9; - v[708][3] = 9; - v[709][3] = 7; - v[710][3] = 3; - v[711][3] = 5; - v[712][3] = 11; - v[713][3] = 7; - v[714][3] = 3; - v[715][3] = 9; - v[716][3] = 5; - v[717][3] = 15; - v[718][3] = 7; - v[719][3] = 5; - v[720][3] = 3; - v[721][3] = 13; - v[722][3] = 7; - v[723][3] = 1; - v[724][3] = 1; - v[725][3] = 9; - v[726][3] = 15; - v[727][3] = 15; - v[728][3] = 15; - v[729][3] = 11; - v[730][3] = 3; - v[731][3] = 5; - v[732][3] = 15; - v[733][3] = 13; - v[734][3] = 7; - v[735][3] = 15; - v[736][3] = 15; - v[737][3] = 11; - v[738][3] = 11; - v[739][3] = 9; - v[740][3] = 5; - v[741][3] = 15; - v[742][3] = 9; - v[743][3] = 7; - v[744][3] = 3; - v[745][3] = 13; - v[746][3] = 1; - v[747][3] = 1; - v[748][3] = 5; - v[749][3] = 1; - v[750][3] = 3; - v[751][3] = 1; - v[752][3] = 7; - v[753][3] = 1; - v[754][3] = 1; - v[755][3] = 5; - v[756][3] = 1; - v[757][3] = 11; - v[758][3] = 11; - v[759][3] = 9; - v[760][3] = 9; - v[761][3] = 5; - v[762][3] = 13; - v[763][3] = 7; - v[764][3] = 7; - v[765][3] = 7; - v[766][3] = 1; - v[767][3] = 1; - v[768][3] = 9; - v[769][3] = 9; - v[770][3] = 11; - v[771][3] = 11; - v[772][3] = 15; - v[773][3] = 7; - v[774][3] = 5; - v[775][3] = 5; - v[776][3] = 3; - v[777][3] = 11; - v[778][3] = 1; - v[779][3] = 3; - v[780][3] = 7; - v[781][3] = 13; - v[782][3] = 7; - v[783][3] = 7; - v[784][3] = 7; - v[785][3] = 3; - v[786][3] = 15; - v[787][3] = 15; - v[788][3] = 11; - v[789][3] = 9; - v[790][3] = 3; - v[791][3] = 9; - v[792][3] = 3; - v[793][3] = 15; - v[794][3] = 13; - v[795][3] = 5; - v[796][3] = 3; - v[797][3] = 3; - v[798][3] = 3; - v[799][3] = 5; - v[800][3] = 9; - v[801][3] = 15; - v[802][3] = 9; - v[803][3] = 9; - v[804][3] = 1; - v[805][3] = 5; - v[806][3] = 9; - v[807][3] = 9; - v[808][3] = 15; - v[809][3] = 5; - v[810][3] = 15; - v[811][3] = 7; - v[812][3] = 9; - v[813][3] = 1; - v[814][3] = 9; - v[815][3] = 9; - v[816][3] = 5; - v[817][3] = 11; - v[818][3] = 5; - v[819][3] = 15; - v[820][3] = 15; - v[821][3] = 11; - v[822][3] = 7; - v[823][3] = 7; - v[824][3] = 7; - v[825][3] = 1; - v[826][3] = 1; - v[827][3] = 11; - v[828][3] = 11; - v[829][3] = 13; - v[830][3] = 15; - v[831][3] = 3; - v[832][3] = 13; - v[833][3] = 5; - v[834][3] = 1; - v[835][3] = 7; - v[836][3] = 1; - v[837][3] = 11; - v[838][3] = 3; - v[839][3] = 13; - v[840][3] = 15; - v[841][3] = 3; - v[842][3] = 5; - v[843][3] = 3; - v[844][3] = 5; - v[845][3] = 7; - v[846][3] = 3; - v[847][3] = 9; - v[848][3] = 9; - v[849][3] = 5; - v[850][3] = 1; - v[851][3] = 7; - v[852][3] = 11; - v[853][3] = 9; - v[854][3] = 3; - v[855][3] = 5; - v[856][3] = 11; - v[857][3] = 13; - v[858][3] = 13; - v[859][3] = 13; - v[860][3] = 9; - v[861][3] = 15; - v[862][3] = 5; - v[863][3] = 7; - v[864][3] = 1; - v[865][3] = 15; - v[866][3] = 11; - v[867][3] = 9; - v[868][3] = 15; - v[869][3] = 15; - v[870][3] = 13; - v[871][3] = 13; - v[872][3] = 13; - v[873][3] = 1; - v[874][3] = 11; - v[875][3] = 9; - v[876][3] = 15; - v[877][3] = 9; - v[878][3] = 5; - v[879][3] = 15; - v[880][3] = 5; - v[881][3] = 7; - v[882][3] = 3; - v[883][3] = 11; - v[884][3] = 3; - v[885][3] = 15; - v[886][3] = 7; - v[887][3] = 13; - v[888][3] = 11; - v[889][3] = 7; - v[890][3] = 3; - v[891][3] = 7; - v[892][3] = 13; - v[893][3] = 5; - v[894][3] = 13; - v[895][3] = 15; - v[896][3] = 5; - v[897][3] = 13; - v[898][3] = 9; - v[899][3] = 1; - v[900][3] = 15; - v[901][3] = 11; - v[902][3] = 5; - v[903][3] = 5; - v[904][3] = 1; - v[905][3] = 11; - v[906][3] = 3; - v[907][3] = 3; - v[908][3] = 7; - v[909][3] = 1; - v[910][3] = 9; - v[911][3] = 7; - v[912][3] = 15; - v[913][3] = 9; - v[914][3] = 9; - v[915][3] = 3; - v[916][3] = 11; - v[917][3] = 15; - v[918][3] = 7; - v[919][3] = 1; - v[920][3] = 3; - v[921][3] = 1; - v[922][3] = 1; - v[923][3] = 1; - v[924][3] = 9; - v[925][3] = 1; - v[926][3] = 5; - v[927][3] = 15; - v[928][3] = 15; - v[929][3] = 7; - v[930][3] = 5; - v[931][3] = 5; - v[932][3] = 7; - v[933][3] = 9; - v[934][3] = 7; - v[935][3] = 15; - v[936][3] = 13; - v[937][3] = 13; - v[938][3] = 11; - v[939][3] = 1; - v[940][3] = 9; - v[941][3] = 11; - v[942][3] = 1; - v[943][3] = 13; - v[944][3] = 1; - v[945][3] = 7; - v[946][3] = 15; - v[947][3] = 15; - v[948][3] = 5; - v[949][3] = 5; - v[950][3] = 1; - v[951][3] = 11; - v[952][3] = 3; - v[953][3] = 9; - v[954][3] = 11; - v[955][3] = 9; - v[956][3] = 9; - v[957][3] = 9; - v[958][3] = 1; - v[959][3] = 9; - v[960][3] = 3; - v[961][3] = 5; - v[962][3] = 15; - v[963][3] = 1; - v[964][3] = 1; - v[965][3] = 9; - v[966][3] = 7; - v[967][3] = 3; - v[968][3] = 3; - v[969][3] = 1; - v[970][3] = 9; - v[971][3] = 9; - v[972][3] = 11; - v[973][3] = 9; - v[974][3] = 9; - v[975][3] = 13; - v[976][3] = 13; - v[977][3] = 3; - v[978][3] = 13; - v[979][3] = 11; - v[980][3] = 13; - v[981][3] = 5; - v[982][3] = 1; - v[983][3] = 5; - v[984][3] = 5; - v[985][3] = 9; - v[986][3] = 9; - v[987][3] = 3; - v[988][3] = 13; - v[989][3] = 13; - v[990][3] = 9; - v[991][3] = 15; - v[992][3] = 9; - v[993][3] = 11; - v[994][3] = 7; - v[995][3] = 11; - v[996][3] = 9; - v[997][3] = 13; - v[998][3] = 9; - v[999][3] = 1; - v[1000][3] = 15; - v[1001][3] = 9; - v[1002][3] = 7; - v[1003][3] = 7; - v[1004][3] = 1; - v[1005][3] = 7; - v[1006][3] = 9; - v[1007][3] = 9; - v[1008][3] = 15; - v[1009][3] = 1; - v[1010][3] = 11; - v[1011][3] = 1; - v[1012][3] = 13; - v[1013][3] = 13; - v[1014][3] = 15; - v[1015][3] = 9; - v[1016][3] = 13; - v[1017][3] = 7; - v[1018][3] = 15; - v[1019][3] = 3; - v[1020][3] = 9; - v[1021][3] = 3; - v[1022][3] = 1; - v[1023][3] = 13; - v[1024][3] = 7; - v[1025][3] = 5; - v[1026][3] = 9; - v[1027][3] = 3; - v[1028][3] = 1; - v[1029][3] = 7; - v[1030][3] = 1; - v[1031][3] = 1; - v[1032][3] = 13; - v[1033][3] = 3; - v[1034][3] = 3; - v[1035][3] = 11; - v[1036][3] = 1; - v[1037][3] = 7; - v[1038][3] = 13; - v[1039][3] = 15; - v[1040][3] = 15; - v[1041][3] = 5; - v[1042][3] = 7; - v[1043][3] = 13; - v[1044][3] = 13; - v[1045][3] = 15; - v[1046][3] = 11; - v[1047][3] = 13; - v[1048][3] = 1; - v[1049][3] = 13; - v[1050][3] = 13; - v[1051][3] = 3; - v[1052][3] = 9; - v[1053][3] = 15; - v[1054][3] = 15; - v[1055][3] = 11; - v[1056][3] = 15; - v[1057][3] = 9; - v[1058][3] = 15; - v[1059][3] = 1; - v[1060][3] = 13; - v[1061][3] = 15; - v[1062][3] = 1; - v[1063][3] = 1; - v[1064][3] = 5; - v[1065][3] = 11; - v[1066][3] = 5; - v[1067][3] = 1; - v[1068][3] = 11; - v[1069][3] = 11; - v[1070][3] = 5; - v[1071][3] = 3; - v[1072][3] = 9; - v[1073][3] = 1; - v[1074][3] = 3; - v[1075][3] = 5; - v[1076][3] = 13; - v[1077][3] = 9; - v[1078][3] = 7; - v[1079][3] = 7; - v[1080][3] = 1; - v[1081][3] = 9; - v[1082][3] = 9; - v[1083][3] = 15; - v[1084][3] = 7; - v[1085][3] = 5; - v[1086][3] = 5; - v[1087][3] = 15; - v[1088][3] = 13; - v[1089][3] = 9; - v[1090][3] = 7; - v[1091][3] = 13; - v[1092][3] = 3; - v[1093][3] = 13; - v[1094][3] = 11; - v[1095][3] = 13; - v[1096][3] = 7; - v[1097][3] = 9; - v[1098][3] = 13; - v[1099][3] = 13; - v[1100][3] = 13; - v[1101][3] = 15; - v[1102][3] = 9; - v[1103][3] = 5; - v[1104][3] = 5; - v[1105][3] = 3; - v[1106][3] = 3; - v[1107][3] = 3; - v[1108][3] = 1; - v[1109][3] = 3; - v[1110][3] = 15; - - v[7][4] = 9; - v[8][4] = 3; - v[9][4] = 27; - v[10][4] = 15; - v[11][4] = 29; - v[12][4] = 21; - v[13][4] = 23; - v[14][4] = 19; - v[15][4] = 11; - v[16][4] = 25; - v[17][4] = 7; - v[18][4] = 13; - v[19][4] = 17; - v[20][4] = 1; - v[21][4] = 25; - v[22][4] = 29; - v[23][4] = 3; - v[24][4] = 31; - v[25][4] = 11; - v[26][4] = 5; - v[27][4] = 23; - v[28][4] = 27; - v[29][4] = 19; - v[30][4] = 21; - v[31][4] = 5; - v[32][4] = 1; - v[33][4] = 17; - v[34][4] = 13; - v[35][4] = 7; - v[36][4] = 15; - v[37][4] = 9; - v[38][4] = 31; - v[39][4] = 25; - v[40][4] = 3; - v[41][4] = 5; - v[42][4] = 23; - v[43][4] = 7; - v[44][4] = 3; - v[45][4] = 17; - v[46][4] = 23; - v[47][4] = 3; - v[48][4] = 3; - v[49][4] = 21; - v[50][4] = 25; - v[51][4] = 25; - v[52][4] = 23; - v[53][4] = 11; - v[54][4] = 19; - v[55][4] = 3; - v[56][4] = 11; - v[57][4] = 31; - v[58][4] = 7; - v[59][4] = 9; - v[60][4] = 5; - v[61][4] = 17; - v[62][4] = 23; - v[63][4] = 17; - v[64][4] = 17; - v[65][4] = 25; - v[66][4] = 13; - v[67][4] = 11; - v[68][4] = 31; - v[69][4] = 27; - v[70][4] = 19; - v[71][4] = 17; - v[72][4] = 23; - v[73][4] = 7; - v[74][4] = 5; - v[75][4] = 11; - v[76][4] = 19; - v[77][4] = 19; - v[78][4] = 7; - v[79][4] = 13; - v[80][4] = 21; - v[81][4] = 21; - v[82][4] = 7; - v[83][4] = 9; - v[84][4] = 11; - v[85][4] = 1; - v[86][4] = 5; - v[87][4] = 21; - v[88][4] = 11; - v[89][4] = 13; - v[90][4] = 25; - v[91][4] = 9; - v[92][4] = 7; - v[93][4] = 7; - v[94][4] = 27; - v[95][4] = 15; - v[96][4] = 25; - v[97][4] = 15; - v[98][4] = 21; - v[99][4] = 17; - v[100][4] = 19; - v[101][4] = 19; - v[102][4] = 21; - v[103][4] = 5; - v[104][4] = 11; - v[105][4] = 3; - v[106][4] = 5; - v[107][4] = 29; - v[108][4] = 31; - v[109][4] = 29; - v[110][4] = 5; - v[111][4] = 5; - v[112][4] = 1; - v[113][4] = 31; - v[114][4] = 27; - v[115][4] = 11; - v[116][4] = 13; - v[117][4] = 1; - v[118][4] = 3; - v[119][4] = 7; - v[120][4] = 11; - v[121][4] = 7; - v[122][4] = 3; - v[123][4] = 23; - v[124][4] = 13; - v[125][4] = 31; - v[126][4] = 17; - v[127][4] = 1; - v[128][4] = 27; - v[129][4] = 11; - v[130][4] = 25; - v[131][4] = 1; - v[132][4] = 23; - v[133][4] = 29; - v[134][4] = 17; - v[135][4] = 25; - v[136][4] = 7; - v[137][4] = 25; - v[138][4] = 27; - v[139][4] = 17; - v[140][4] = 13; - v[141][4] = 17; - v[142][4] = 23; - v[143][4] = 5; - v[144][4] = 17; - v[145][4] = 5; - v[146][4] = 13; - v[147][4] = 11; - v[148][4] = 21; - v[149][4] = 5; - v[150][4] = 11; - v[151][4] = 5; - v[152][4] = 9; - v[153][4] = 31; - v[154][4] = 19; - v[155][4] = 17; - v[156][4] = 9; - v[157][4] = 9; - v[158][4] = 27; - v[159][4] = 21; - v[160][4] = 15; - v[161][4] = 15; - v[162][4] = 1; - v[163][4] = 1; - v[164][4] = 29; - v[165][4] = 5; - v[166][4] = 31; - v[167][4] = 11; - v[168][4] = 17; - v[169][4] = 23; - v[170][4] = 19; - v[171][4] = 21; - v[172][4] = 25; - v[173][4] = 15; - v[174][4] = 11; - v[175][4] = 5; - v[176][4] = 5; - v[177][4] = 1; - v[178][4] = 19; - v[179][4] = 19; - v[180][4] = 19; - v[181][4] = 7; - v[182][4] = 13; - v[183][4] = 21; - v[184][4] = 17; - v[185][4] = 17; - v[186][4] = 25; - v[187][4] = 23; - v[188][4] = 19; - v[189][4] = 23; - v[190][4] = 15; - v[191][4] = 13; - v[192][4] = 5; - v[193][4] = 19; - v[194][4] = 25; - v[195][4] = 9; - v[196][4] = 7; - v[197][4] = 3; - v[198][4] = 21; - v[199][4] = 17; - v[200][4] = 25; - v[201][4] = 1; - v[202][4] = 27; - v[203][4] = 25; - v[204][4] = 27; - v[205][4] = 25; - v[206][4] = 9; - v[207][4] = 13; - v[208][4] = 3; - v[209][4] = 17; - v[210][4] = 25; - v[211][4] = 23; - v[212][4] = 9; - v[213][4] = 25; - v[214][4] = 9; - v[215][4] = 13; - v[216][4] = 17; - v[217][4] = 17; - v[218][4] = 3; - v[219][4] = 15; - v[220][4] = 7; - v[221][4] = 7; - v[222][4] = 29; - v[223][4] = 3; - v[224][4] = 19; - v[225][4] = 29; - v[226][4] = 29; - v[227][4] = 19; - v[228][4] = 29; - v[229][4] = 13; - v[230][4] = 15; - v[231][4] = 25; - v[232][4] = 27; - v[233][4] = 1; - v[234][4] = 3; - v[235][4] = 9; - v[236][4] = 9; - v[237][4] = 13; - v[238][4] = 31; - v[239][4] = 29; - v[240][4] = 31; - v[241][4] = 5; - v[242][4] = 15; - v[243][4] = 29; - v[244][4] = 1; - v[245][4] = 19; - v[246][4] = 5; - v[247][4] = 9; - v[248][4] = 19; - v[249][4] = 5; - v[250][4] = 15; - v[251][4] = 3; - v[252][4] = 5; - v[253][4] = 7; - v[254][4] = 15; - v[255][4] = 17; - v[256][4] = 17; - v[257][4] = 23; - v[258][4] = 11; - v[259][4] = 9; - v[260][4] = 23; - v[261][4] = 19; - v[262][4] = 3; - v[263][4] = 17; - v[264][4] = 1; - v[265][4] = 27; - v[266][4] = 9; - v[267][4] = 9; - v[268][4] = 17; - v[269][4] = 13; - v[270][4] = 25; - v[271][4] = 29; - v[272][4] = 23; - v[273][4] = 29; - v[274][4] = 11; - v[275][4] = 31; - v[276][4] = 25; - v[277][4] = 21; - v[278][4] = 29; - v[279][4] = 19; - v[280][4] = 27; - v[281][4] = 31; - v[282][4] = 3; - v[283][4] = 5; - v[284][4] = 3; - v[285][4] = 3; - v[286][4] = 13; - v[287][4] = 21; - v[288][4] = 9; - v[289][4] = 29; - v[290][4] = 3; - v[291][4] = 17; - v[292][4] = 11; - v[293][4] = 11; - v[294][4] = 9; - v[295][4] = 21; - v[296][4] = 19; - v[297][4] = 7; - v[298][4] = 17; - v[299][4] = 31; - v[300][4] = 25; - v[301][4] = 1; - v[302][4] = 27; - v[303][4] = 5; - v[304][4] = 15; - v[305][4] = 27; - v[306][4] = 29; - v[307][4] = 29; - v[308][4] = 29; - v[309][4] = 25; - v[310][4] = 27; - v[311][4] = 25; - v[312][4] = 3; - v[313][4] = 21; - v[314][4] = 17; - v[315][4] = 25; - v[316][4] = 13; - v[317][4] = 15; - v[318][4] = 17; - v[319][4] = 13; - v[320][4] = 23; - v[321][4] = 9; - v[322][4] = 3; - v[323][4] = 11; - v[324][4] = 7; - v[325][4] = 9; - v[326][4] = 9; - v[327][4] = 7; - v[328][4] = 17; - v[329][4] = 7; - v[330][4] = 1; - v[331][4] = 27; - v[332][4] = 1; - v[333][4] = 9; - v[334][4] = 5; - v[335][4] = 31; - v[336][4] = 21; - v[337][4] = 25; - v[338][4] = 25; - v[339][4] = 21; - v[340][4] = 11; - v[341][4] = 1; - v[342][4] = 23; - v[343][4] = 19; - v[344][4] = 27; - v[345][4] = 15; - v[346][4] = 3; - v[347][4] = 5; - v[348][4] = 23; - v[349][4] = 9; - v[350][4] = 25; - v[351][4] = 7; - v[352][4] = 29; - v[353][4] = 11; - v[354][4] = 9; - v[355][4] = 13; - v[356][4] = 5; - v[357][4] = 11; - v[358][4] = 1; - v[359][4] = 3; - v[360][4] = 31; - v[361][4] = 27; - v[362][4] = 3; - v[363][4] = 17; - v[364][4] = 27; - v[365][4] = 11; - v[366][4] = 13; - v[367][4] = 15; - v[368][4] = 29; - v[369][4] = 15; - v[370][4] = 1; - v[371][4] = 15; - v[372][4] = 23; - v[373][4] = 25; - v[374][4] = 13; - v[375][4] = 21; - v[376][4] = 15; - v[377][4] = 3; - v[378][4] = 29; - v[379][4] = 29; - v[380][4] = 5; - v[381][4] = 25; - v[382][4] = 17; - v[383][4] = 11; - v[384][4] = 7; - v[385][4] = 15; - v[386][4] = 5; - v[387][4] = 21; - v[388][4] = 7; - v[389][4] = 31; - v[390][4] = 13; - v[391][4] = 11; - v[392][4] = 23; - v[393][4] = 5; - v[394][4] = 7; - v[395][4] = 23; - v[396][4] = 27; - v[397][4] = 21; - v[398][4] = 29; - v[399][4] = 15; - v[400][4] = 7; - v[401][4] = 27; - v[402][4] = 27; - v[403][4] = 19; - v[404][4] = 7; - v[405][4] = 15; - v[406][4] = 27; - v[407][4] = 27; - v[408][4] = 19; - v[409][4] = 19; - v[410][4] = 9; - v[411][4] = 15; - v[412][4] = 1; - v[413][4] = 3; - v[414][4] = 29; - v[415][4] = 29; - v[416][4] = 5; - v[417][4] = 27; - v[418][4] = 31; - v[419][4] = 9; - v[420][4] = 1; - v[421][4] = 7; - v[422][4] = 3; - v[423][4] = 19; - v[424][4] = 19; - v[425][4] = 29; - v[426][4] = 9; - v[427][4] = 3; - v[428][4] = 21; - v[429][4] = 31; - v[430][4] = 29; - v[431][4] = 25; - v[432][4] = 1; - v[433][4] = 3; - v[434][4] = 9; - v[435][4] = 27; - v[436][4] = 5; - v[437][4] = 27; - v[438][4] = 25; - v[439][4] = 21; - v[440][4] = 11; - v[441][4] = 29; - v[442][4] = 31; - v[443][4] = 27; - v[444][4] = 21; - v[445][4] = 29; - v[446][4] = 17; - v[447][4] = 9; - v[448][4] = 17; - v[449][4] = 13; - v[450][4] = 11; - v[451][4] = 25; - v[452][4] = 15; - v[453][4] = 21; - v[454][4] = 11; - v[455][4] = 19; - v[456][4] = 31; - v[457][4] = 3; - v[458][4] = 19; - v[459][4] = 5; - v[460][4] = 3; - v[461][4] = 3; - v[462][4] = 9; - v[463][4] = 13; - v[464][4] = 13; - v[465][4] = 3; - v[466][4] = 29; - v[467][4] = 7; - v[468][4] = 5; - v[469][4] = 9; - v[470][4] = 23; - v[471][4] = 13; - v[472][4] = 21; - v[473][4] = 23; - v[474][4] = 21; - v[475][4] = 31; - v[476][4] = 11; - v[477][4] = 7; - v[478][4] = 7; - v[479][4] = 3; - v[480][4] = 23; - v[481][4] = 1; - v[482][4] = 23; - v[483][4] = 5; - v[484][4] = 9; - v[485][4] = 17; - v[486][4] = 21; - v[487][4] = 1; - v[488][4] = 17; - v[489][4] = 29; - v[490][4] = 7; - v[491][4] = 5; - v[492][4] = 17; - v[493][4] = 13; - v[494][4] = 25; - v[495][4] = 17; - v[496][4] = 9; - v[497][4] = 19; - v[498][4] = 9; - v[499][4] = 5; - v[500][4] = 7; - v[501][4] = 21; - v[502][4] = 19; - v[503][4] = 13; - v[504][4] = 9; - v[505][4] = 7; - v[506][4] = 3; - v[507][4] = 9; - v[508][4] = 3; - v[509][4] = 15; - v[510][4] = 31; - v[511][4] = 29; - v[512][4] = 29; - v[513][4] = 25; - v[514][4] = 13; - v[515][4] = 9; - v[516][4] = 21; - v[517][4] = 9; - v[518][4] = 31; - v[519][4] = 7; - v[520][4] = 15; - v[521][4] = 5; - v[522][4] = 31; - v[523][4] = 7; - v[524][4] = 15; - v[525][4] = 27; - v[526][4] = 25; - v[527][4] = 19; - v[528][4] = 9; - v[529][4] = 9; - v[530][4] = 25; - v[531][4] = 25; - v[532][4] = 23; - v[533][4] = 1; - v[534][4] = 9; - v[535][4] = 7; - v[536][4] = 11; - v[537][4] = 15; - v[538][4] = 19; - v[539][4] = 15; - v[540][4] = 27; - v[541][4] = 17; - v[542][4] = 11; - v[543][4] = 11; - v[544][4] = 31; - v[545][4] = 13; - v[546][4] = 25; - v[547][4] = 25; - v[548][4] = 9; - v[549][4] = 7; - v[550][4] = 13; - v[551][4] = 29; - v[552][4] = 19; - v[553][4] = 5; - v[554][4] = 19; - v[555][4] = 31; - v[556][4] = 25; - v[557][4] = 13; - v[558][4] = 25; - v[559][4] = 15; - v[560][4] = 5; - v[561][4] = 9; - v[562][4] = 29; - v[563][4] = 31; - v[564][4] = 9; - v[565][4] = 29; - v[566][4] = 27; - v[567][4] = 25; - v[568][4] = 27; - v[569][4] = 11; - v[570][4] = 17; - v[571][4] = 5; - v[572][4] = 17; - v[573][4] = 3; - v[574][4] = 23; - v[575][4] = 15; - v[576][4] = 9; - v[577][4] = 9; - v[578][4] = 17; - v[579][4] = 17; - v[580][4] = 31; - v[581][4] = 11; - v[582][4] = 19; - v[583][4] = 25; - v[584][4] = 13; - v[585][4] = 23; - v[586][4] = 15; - v[587][4] = 25; - v[588][4] = 21; - v[589][4] = 31; - v[590][4] = 19; - v[591][4] = 3; - v[592][4] = 11; - v[593][4] = 25; - v[594][4] = 7; - v[595][4] = 15; - v[596][4] = 19; - v[597][4] = 7; - v[598][4] = 5; - v[599][4] = 3; - v[600][4] = 13; - v[601][4] = 13; - v[602][4] = 1; - v[603][4] = 23; - v[604][4] = 5; - v[605][4] = 25; - v[606][4] = 11; - v[607][4] = 25; - v[608][4] = 15; - v[609][4] = 13; - v[610][4] = 21; - v[611][4] = 11; - v[612][4] = 23; - v[613][4] = 29; - v[614][4] = 5; - v[615][4] = 17; - v[616][4] = 27; - v[617][4] = 9; - v[618][4] = 19; - v[619][4] = 15; - v[620][4] = 5; - v[621][4] = 29; - v[622][4] = 23; - v[623][4] = 19; - v[624][4] = 1; - v[625][4] = 27; - v[626][4] = 3; - v[627][4] = 23; - v[628][4] = 21; - v[629][4] = 19; - v[630][4] = 27; - v[631][4] = 11; - v[632][4] = 17; - v[633][4] = 13; - v[634][4] = 27; - v[635][4] = 11; - v[636][4] = 31; - v[637][4] = 23; - v[638][4] = 5; - v[639][4] = 9; - v[640][4] = 21; - v[641][4] = 31; - v[642][4] = 29; - v[643][4] = 11; - v[644][4] = 21; - v[645][4] = 17; - v[646][4] = 15; - v[647][4] = 7; - v[648][4] = 15; - v[649][4] = 7; - v[650][4] = 9; - v[651][4] = 21; - v[652][4] = 27; - v[653][4] = 25; - v[654][4] = 29; - v[655][4] = 11; - v[656][4] = 3; - v[657][4] = 21; - v[658][4] = 13; - v[659][4] = 23; - v[660][4] = 19; - v[661][4] = 27; - v[662][4] = 17; - v[663][4] = 29; - v[664][4] = 25; - v[665][4] = 17; - v[666][4] = 9; - v[667][4] = 1; - v[668][4] = 19; - v[669][4] = 23; - v[670][4] = 5; - v[671][4] = 23; - v[672][4] = 1; - v[673][4] = 17; - v[674][4] = 17; - v[675][4] = 13; - v[676][4] = 27; - v[677][4] = 23; - v[678][4] = 7; - v[679][4] = 7; - v[680][4] = 11; - v[681][4] = 13; - v[682][4] = 17; - v[683][4] = 13; - v[684][4] = 11; - v[685][4] = 21; - v[686][4] = 13; - v[687][4] = 23; - v[688][4] = 1; - v[689][4] = 27; - v[690][4] = 13; - v[691][4] = 9; - v[692][4] = 7; - v[693][4] = 1; - v[694][4] = 27; - v[695][4] = 29; - v[696][4] = 5; - v[697][4] = 13; - v[698][4] = 25; - v[699][4] = 21; - v[700][4] = 3; - v[701][4] = 31; - v[702][4] = 15; - v[703][4] = 13; - v[704][4] = 3; - v[705][4] = 19; - v[706][4] = 13; - v[707][4] = 1; - v[708][4] = 27; - v[709][4] = 15; - v[710][4] = 17; - v[711][4] = 1; - v[712][4] = 3; - v[713][4] = 13; - v[714][4] = 13; - v[715][4] = 13; - v[716][4] = 31; - v[717][4] = 29; - v[718][4] = 27; - v[719][4] = 7; - v[720][4] = 7; - v[721][4] = 21; - v[722][4] = 29; - v[723][4] = 15; - v[724][4] = 17; - v[725][4] = 17; - v[726][4] = 21; - v[727][4] = 19; - v[728][4] = 17; - v[729][4] = 3; - v[730][4] = 15; - v[731][4] = 5; - v[732][4] = 27; - v[733][4] = 27; - v[734][4] = 3; - v[735][4] = 31; - v[736][4] = 31; - v[737][4] = 7; - v[738][4] = 21; - v[739][4] = 3; - v[740][4] = 13; - v[741][4] = 11; - v[742][4] = 17; - v[743][4] = 27; - v[744][4] = 25; - v[745][4] = 1; - v[746][4] = 9; - v[747][4] = 7; - v[748][4] = 29; - v[749][4] = 27; - v[750][4] = 21; - v[751][4] = 23; - v[752][4] = 13; - v[753][4] = 25; - v[754][4] = 29; - v[755][4] = 15; - v[756][4] = 17; - v[757][4] = 29; - v[758][4] = 9; - v[759][4] = 15; - v[760][4] = 3; - v[761][4] = 21; - v[762][4] = 15; - v[763][4] = 17; - v[764][4] = 17; - v[765][4] = 31; - v[766][4] = 9; - v[767][4] = 9; - v[768][4] = 23; - v[769][4] = 19; - v[770][4] = 25; - v[771][4] = 3; - v[772][4] = 1; - v[773][4] = 11; - v[774][4] = 27; - v[775][4] = 29; - v[776][4] = 1; - v[777][4] = 31; - v[778][4] = 29; - v[779][4] = 25; - v[780][4] = 29; - v[781][4] = 1; - v[782][4] = 23; - v[783][4] = 29; - v[784][4] = 25; - v[785][4] = 13; - v[786][4] = 3; - v[787][4] = 31; - v[788][4] = 25; - v[789][4] = 5; - v[790][4] = 5; - v[791][4] = 11; - v[792][4] = 3; - v[793][4] = 21; - v[794][4] = 9; - v[795][4] = 23; - v[796][4] = 7; - v[797][4] = 11; - v[798][4] = 23; - v[799][4] = 11; - v[800][4] = 1; - v[801][4] = 1; - v[802][4] = 3; - v[803][4] = 23; - v[804][4] = 25; - v[805][4] = 23; - v[806][4] = 1; - v[807][4] = 23; - v[808][4] = 3; - v[809][4] = 27; - v[810][4] = 9; - v[811][4] = 27; - v[812][4] = 3; - v[813][4] = 23; - v[814][4] = 25; - v[815][4] = 19; - v[816][4] = 29; - v[817][4] = 29; - v[818][4] = 13; - v[819][4] = 27; - v[820][4] = 5; - v[821][4] = 9; - v[822][4] = 29; - v[823][4] = 29; - v[824][4] = 13; - v[825][4] = 17; - v[826][4] = 3; - v[827][4] = 23; - v[828][4] = 19; - v[829][4] = 7; - v[830][4] = 13; - v[831][4] = 3; - v[832][4] = 19; - v[833][4] = 23; - v[834][4] = 5; - v[835][4] = 29; - v[836][4] = 29; - v[837][4] = 13; - v[838][4] = 13; - v[839][4] = 5; - v[840][4] = 19; - v[841][4] = 5; - v[842][4] = 17; - v[843][4] = 9; - v[844][4] = 11; - v[845][4] = 11; - v[846][4] = 29; - v[847][4] = 27; - v[848][4] = 23; - v[849][4] = 19; - v[850][4] = 17; - v[851][4] = 25; - v[852][4] = 13; - v[853][4] = 1; - v[854][4] = 13; - v[855][4] = 3; - v[856][4] = 11; - v[857][4] = 1; - v[858][4] = 17; - v[859][4] = 29; - v[860][4] = 1; - v[861][4] = 13; - v[862][4] = 17; - v[863][4] = 9; - v[864][4] = 17; - v[865][4] = 21; - v[866][4] = 1; - v[867][4] = 11; - v[868][4] = 1; - v[869][4] = 1; - v[870][4] = 25; - v[871][4] = 5; - v[872][4] = 7; - v[873][4] = 29; - v[874][4] = 29; - v[875][4] = 19; - v[876][4] = 19; - v[877][4] = 1; - v[878][4] = 29; - v[879][4] = 13; - v[880][4] = 3; - v[881][4] = 1; - v[882][4] = 31; - v[883][4] = 15; - v[884][4] = 13; - v[885][4] = 3; - v[886][4] = 1; - v[887][4] = 11; - v[888][4] = 19; - v[889][4] = 5; - v[890][4] = 29; - v[891][4] = 13; - v[892][4] = 29; - v[893][4] = 23; - v[894][4] = 3; - v[895][4] = 1; - v[896][4] = 31; - v[897][4] = 13; - v[898][4] = 19; - v[899][4] = 17; - v[900][4] = 5; - v[901][4] = 5; - v[902][4] = 1; - v[903][4] = 29; - v[904][4] = 23; - v[905][4] = 3; - v[906][4] = 19; - v[907][4] = 25; - v[908][4] = 19; - v[909][4] = 27; - v[910][4] = 9; - v[911][4] = 27; - v[912][4] = 13; - v[913][4] = 15; - v[914][4] = 29; - v[915][4] = 23; - v[916][4] = 13; - v[917][4] = 25; - v[918][4] = 25; - v[919][4] = 17; - v[920][4] = 19; - v[921][4] = 17; - v[922][4] = 15; - v[923][4] = 27; - v[924][4] = 3; - v[925][4] = 25; - v[926][4] = 17; - v[927][4] = 27; - v[928][4] = 3; - v[929][4] = 27; - v[930][4] = 31; - v[931][4] = 23; - v[932][4] = 13; - v[933][4] = 31; - v[934][4] = 11; - v[935][4] = 15; - v[936][4] = 7; - v[937][4] = 21; - v[938][4] = 19; - v[939][4] = 27; - v[940][4] = 19; - v[941][4] = 21; - v[942][4] = 29; - v[943][4] = 7; - v[944][4] = 31; - v[945][4] = 13; - v[946][4] = 9; - v[947][4] = 9; - v[948][4] = 7; - v[949][4] = 21; - v[950][4] = 13; - v[951][4] = 11; - v[952][4] = 9; - v[953][4] = 11; - v[954][4] = 29; - v[955][4] = 19; - v[956][4] = 11; - v[957][4] = 19; - v[958][4] = 21; - v[959][4] = 5; - v[960][4] = 29; - v[961][4] = 13; - v[962][4] = 7; - v[963][4] = 19; - v[964][4] = 19; - v[965][4] = 27; - v[966][4] = 23; - v[967][4] = 31; - v[968][4] = 1; - v[969][4] = 27; - v[970][4] = 21; - v[971][4] = 7; - v[972][4] = 3; - v[973][4] = 7; - v[974][4] = 11; - v[975][4] = 23; - v[976][4] = 13; - v[977][4] = 29; - v[978][4] = 11; - v[979][4] = 31; - v[980][4] = 19; - v[981][4] = 1; - v[982][4] = 5; - v[983][4] = 5; - v[984][4] = 11; - v[985][4] = 5; - v[986][4] = 3; - v[987][4] = 27; - v[988][4] = 5; - v[989][4] = 7; - v[990][4] = 11; - v[991][4] = 31; - v[992][4] = 1; - v[993][4] = 27; - v[994][4] = 31; - v[995][4] = 31; - v[996][4] = 23; - v[997][4] = 5; - v[998][4] = 21; - v[999][4] = 27; - v[1000][4] = 9; - v[1001][4] = 25; - v[1002][4] = 3; - v[1003][4] = 15; - v[1004][4] = 19; - v[1005][4] = 1; - v[1006][4] = 19; - v[1007][4] = 9; - v[1008][4] = 5; - v[1009][4] = 25; - v[1010][4] = 21; - v[1011][4] = 15; - v[1012][4] = 25; - v[1013][4] = 29; - v[1014][4] = 15; - v[1015][4] = 21; - v[1016][4] = 11; - v[1017][4] = 19; - v[1018][4] = 15; - v[1019][4] = 3; - v[1020][4] = 7; - v[1021][4] = 13; - v[1022][4] = 11; - v[1023][4] = 25; - v[1024][4] = 17; - v[1025][4] = 1; - v[1026][4] = 5; - v[1027][4] = 31; - v[1028][4] = 13; - v[1029][4] = 29; - v[1030][4] = 23; - v[1031][4] = 9; - v[1032][4] = 5; - v[1033][4] = 29; - v[1034][4] = 7; - v[1035][4] = 17; - v[1036][4] = 27; - v[1037][4] = 7; - v[1038][4] = 17; - v[1039][4] = 31; - v[1040][4] = 9; - v[1041][4] = 31; - v[1042][4] = 9; - v[1043][4] = 9; - v[1044][4] = 7; - v[1045][4] = 21; - v[1046][4] = 3; - v[1047][4] = 3; - v[1048][4] = 3; - v[1049][4] = 9; - v[1050][4] = 11; - v[1051][4] = 21; - v[1052][4] = 11; - v[1053][4] = 31; - v[1054][4] = 9; - v[1055][4] = 25; - v[1056][4] = 5; - v[1057][4] = 1; - v[1058][4] = 31; - v[1059][4] = 13; - v[1060][4] = 29; - v[1061][4] = 9; - v[1062][4] = 29; - v[1063][4] = 1; - v[1064][4] = 11; - v[1065][4] = 19; - v[1066][4] = 7; - v[1067][4] = 27; - v[1068][4] = 13; - v[1069][4] = 31; - v[1070][4] = 7; - v[1071][4] = 31; - v[1072][4] = 7; - v[1073][4] = 25; - v[1074][4] = 23; - v[1075][4] = 21; - v[1076][4] = 29; - v[1077][4] = 11; - v[1078][4] = 11; - v[1079][4] = 13; - v[1080][4] = 11; - v[1081][4] = 27; - v[1082][4] = 1; - v[1083][4] = 23; - v[1084][4] = 31; - v[1085][4] = 21; - v[1086][4] = 23; - v[1087][4] = 21; - v[1088][4] = 19; - v[1089][4] = 31; - v[1090][4] = 5; - v[1091][4] = 31; - v[1092][4] = 25; - v[1093][4] = 25; - v[1094][4] = 19; - v[1095][4] = 17; - v[1096][4] = 11; - v[1097][4] = 25; - v[1098][4] = 7; - v[1099][4] = 13; - v[1100][4] = 1; - v[1101][4] = 29; - v[1102][4] = 17; - v[1103][4] = 23; - v[1104][4] = 15; - v[1105][4] = 7; - v[1106][4] = 29; - v[1107][4] = 17; - v[1108][4] = 13; - v[1109][4] = 3; - v[1110][4] = 17; - - v[13][5] = 37; - v[14][5] = 33; - v[15][5] = 7; - v[16][5] = 5; - v[17][5] = 11; - v[18][5] = 39; - v[19][5] = 63; - v[20][5] = 59; - v[21][5] = 17; - v[22][5] = 15; - v[23][5] = 23; - v[24][5] = 29; - v[25][5] = 3; - v[26][5] = 21; - v[27][5] = 13; - v[28][5] = 31; - v[29][5] = 25; - v[30][5] = 9; - v[31][5] = 49; - v[32][5] = 33; - v[33][5] = 19; - v[34][5] = 29; - v[35][5] = 11; - v[36][5] = 19; - v[37][5] = 27; - v[38][5] = 15; - v[39][5] = 25; - v[40][5] = 63; - v[41][5] = 55; - v[42][5] = 17; - v[43][5] = 63; - v[44][5] = 49; - v[45][5] = 19; - v[46][5] = 41; - v[47][5] = 59; - v[48][5] = 3; - v[49][5] = 57; - v[50][5] = 33; - v[51][5] = 49; - v[52][5] = 53; - v[53][5] = 57; - v[54][5] = 57; - v[55][5] = 39; - v[56][5] = 21; - v[57][5] = 7; - v[58][5] = 53; - v[59][5] = 9; - v[60][5] = 55; - v[61][5] = 15; - v[62][5] = 59; - v[63][5] = 19; - v[64][5] = 49; - v[65][5] = 31; - v[66][5] = 3; - v[67][5] = 39; - v[68][5] = 5; - v[69][5] = 5; - v[70][5] = 41; - v[71][5] = 9; - v[72][5] = 19; - v[73][5] = 9; - v[74][5] = 57; - v[75][5] = 25; - v[76][5] = 1; - v[77][5] = 15; - v[78][5] = 51; - v[79][5] = 11; - v[80][5] = 19; - v[81][5] = 61; - v[82][5] = 53; - v[83][5] = 29; - v[84][5] = 19; - v[85][5] = 11; - v[86][5] = 9; - v[87][5] = 21; - v[88][5] = 19; - v[89][5] = 43; - v[90][5] = 13; - v[91][5] = 13; - v[92][5] = 41; - v[93][5] = 25; - v[94][5] = 31; - v[95][5] = 9; - v[96][5] = 11; - v[97][5] = 19; - v[98][5] = 5; - v[99][5] = 53; - v[100][5] = 37; - v[101][5] = 7; - v[102][5] = 51; - v[103][5] = 45; - v[104][5] = 7; - v[105][5] = 7; - v[106][5] = 61; - v[107][5] = 23; - v[108][5] = 45; - v[109][5] = 7; - v[110][5] = 59; - v[111][5] = 41; - v[112][5] = 1; - v[113][5] = 29; - v[114][5] = 61; - v[115][5] = 37; - v[116][5] = 27; - v[117][5] = 47; - v[118][5] = 15; - v[119][5] = 31; - v[120][5] = 35; - v[121][5] = 31; - v[122][5] = 17; - v[123][5] = 51; - v[124][5] = 13; - v[125][5] = 25; - v[126][5] = 45; - v[127][5] = 5; - v[128][5] = 5; - v[129][5] = 33; - v[130][5] = 39; - v[131][5] = 5; - v[132][5] = 47; - v[133][5] = 29; - v[134][5] = 35; - v[135][5] = 47; - v[136][5] = 63; - v[137][5] = 45; - v[138][5] = 37; - v[139][5] = 47; - v[140][5] = 59; - v[141][5] = 21; - v[142][5] = 59; - v[143][5] = 33; - v[144][5] = 51; - v[145][5] = 9; - v[146][5] = 27; - v[147][5] = 13; - v[148][5] = 25; - v[149][5] = 43; - v[150][5] = 3; - v[151][5] = 17; - v[152][5] = 21; - v[153][5] = 59; - v[154][5] = 61; - v[155][5] = 27; - v[156][5] = 47; - v[157][5] = 57; - v[158][5] = 11; - v[159][5] = 17; - v[160][5] = 39; - v[161][5] = 1; - v[162][5] = 63; - v[163][5] = 21; - v[164][5] = 59; - v[165][5] = 17; - v[166][5] = 13; - v[167][5] = 31; - v[168][5] = 3; - v[169][5] = 31; - v[170][5] = 7; - v[171][5] = 9; - v[172][5] = 27; - v[173][5] = 37; - v[174][5] = 23; - v[175][5] = 31; - v[176][5] = 9; - v[177][5] = 45; - v[178][5] = 43; - v[179][5] = 31; - v[180][5] = 63; - v[181][5] = 21; - v[182][5] = 39; - v[183][5] = 51; - v[184][5] = 27; - v[185][5] = 7; - v[186][5] = 53; - v[187][5] = 11; - v[188][5] = 1; - v[189][5] = 59; - v[190][5] = 39; - v[191][5] = 23; - v[192][5] = 49; - v[193][5] = 23; - v[194][5] = 7; - v[195][5] = 55; - v[196][5] = 59; - v[197][5] = 3; - v[198][5] = 19; - v[199][5] = 35; - v[200][5] = 13; - v[201][5] = 9; - v[202][5] = 13; - v[203][5] = 15; - v[204][5] = 23; - v[205][5] = 9; - v[206][5] = 7; - v[207][5] = 43; - v[208][5] = 55; - v[209][5] = 3; - v[210][5] = 19; - v[211][5] = 9; - v[212][5] = 27; - v[213][5] = 33; - v[214][5] = 27; - v[215][5] = 49; - v[216][5] = 23; - v[217][5] = 47; - v[218][5] = 19; - v[219][5] = 7; - v[220][5] = 11; - v[221][5] = 55; - v[222][5] = 27; - v[223][5] = 35; - v[224][5] = 5; - v[225][5] = 5; - v[226][5] = 55; - v[227][5] = 35; - v[228][5] = 37; - v[229][5] = 9; - v[230][5] = 33; - v[231][5] = 29; - v[232][5] = 47; - v[233][5] = 25; - v[234][5] = 11; - v[235][5] = 47; - v[236][5] = 53; - v[237][5] = 61; - v[238][5] = 59; - v[239][5] = 3; - v[240][5] = 53; - v[241][5] = 47; - v[242][5] = 5; - v[243][5] = 19; - v[244][5] = 59; - v[245][5] = 5; - v[246][5] = 47; - v[247][5] = 23; - v[248][5] = 45; - v[249][5] = 53; - v[250][5] = 3; - v[251][5] = 49; - v[252][5] = 61; - v[253][5] = 47; - v[254][5] = 39; - v[255][5] = 29; - v[256][5] = 17; - v[257][5] = 57; - v[258][5] = 5; - v[259][5] = 17; - v[260][5] = 31; - v[261][5] = 23; - v[262][5] = 41; - v[263][5] = 39; - v[264][5] = 5; - v[265][5] = 27; - v[266][5] = 7; - v[267][5] = 29; - v[268][5] = 29; - v[269][5] = 33; - v[270][5] = 31; - v[271][5] = 41; - v[272][5] = 31; - v[273][5] = 29; - v[274][5] = 17; - v[275][5] = 29; - v[276][5] = 29; - v[277][5] = 9; - v[278][5] = 9; - v[279][5] = 31; - v[280][5] = 27; - v[281][5] = 53; - v[282][5] = 35; - v[283][5] = 5; - v[284][5] = 61; - v[285][5] = 1; - v[286][5] = 49; - v[287][5] = 13; - v[288][5] = 57; - v[289][5] = 29; - v[290][5] = 5; - v[291][5] = 21; - v[292][5] = 43; - v[293][5] = 25; - v[294][5] = 57; - v[295][5] = 49; - v[296][5] = 37; - v[297][5] = 27; - v[298][5] = 11; - v[299][5] = 61; - v[300][5] = 37; - v[301][5] = 49; - v[302][5] = 5; - v[303][5] = 63; - v[304][5] = 63; - v[305][5] = 3; - v[306][5] = 45; - v[307][5] = 37; - v[308][5] = 63; - v[309][5] = 21; - v[310][5] = 21; - v[311][5] = 19; - v[312][5] = 27; - v[313][5] = 59; - v[314][5] = 21; - v[315][5] = 45; - v[316][5] = 23; - v[317][5] = 13; - v[318][5] = 15; - v[319][5] = 3; - v[320][5] = 43; - v[321][5] = 63; - v[322][5] = 39; - v[323][5] = 19; - v[324][5] = 63; - v[325][5] = 31; - v[326][5] = 41; - v[327][5] = 41; - v[328][5] = 15; - v[329][5] = 43; - v[330][5] = 63; - v[331][5] = 53; - v[332][5] = 1; - v[333][5] = 63; - v[334][5] = 31; - v[335][5] = 7; - v[336][5] = 17; - v[337][5] = 11; - v[338][5] = 61; - v[339][5] = 31; - v[340][5] = 51; - v[341][5] = 37; - v[342][5] = 29; - v[343][5] = 59; - v[344][5] = 25; - v[345][5] = 63; - v[346][5] = 59; - v[347][5] = 47; - v[348][5] = 15; - v[349][5] = 27; - v[350][5] = 19; - v[351][5] = 29; - v[352][5] = 45; - v[353][5] = 35; - v[354][5] = 55; - v[355][5] = 39; - v[356][5] = 19; - v[357][5] = 43; - v[358][5] = 21; - v[359][5] = 19; - v[360][5] = 13; - v[361][5] = 17; - v[362][5] = 51; - v[363][5] = 37; - v[364][5] = 5; - v[365][5] = 33; - v[366][5] = 35; - v[367][5] = 49; - v[368][5] = 25; - v[369][5] = 45; - v[370][5] = 1; - v[371][5] = 63; - v[372][5] = 47; - v[373][5] = 9; - v[374][5] = 63; - v[375][5] = 15; - v[376][5] = 25; - v[377][5] = 25; - v[378][5] = 15; - v[379][5] = 41; - v[380][5] = 13; - v[381][5] = 3; - v[382][5] = 19; - v[383][5] = 51; - v[384][5] = 49; - v[385][5] = 37; - v[386][5] = 25; - v[387][5] = 49; - v[388][5] = 13; - v[389][5] = 53; - v[390][5] = 47; - v[391][5] = 23; - v[392][5] = 35; - v[393][5] = 29; - v[394][5] = 33; - v[395][5] = 21; - v[396][5] = 35; - v[397][5] = 23; - v[398][5] = 3; - v[399][5] = 43; - v[400][5] = 31; - v[401][5] = 63; - v[402][5] = 9; - v[403][5] = 1; - v[404][5] = 61; - v[405][5] = 43; - v[406][5] = 3; - v[407][5] = 11; - v[408][5] = 55; - v[409][5] = 11; - v[410][5] = 35; - v[411][5] = 1; - v[412][5] = 63; - v[413][5] = 35; - v[414][5] = 49; - v[415][5] = 19; - v[416][5] = 45; - v[417][5] = 9; - v[418][5] = 57; - v[419][5] = 51; - v[420][5] = 1; - v[421][5] = 47; - v[422][5] = 41; - v[423][5] = 9; - v[424][5] = 11; - v[425][5] = 37; - v[426][5] = 19; - v[427][5] = 55; - v[428][5] = 23; - v[429][5] = 55; - v[430][5] = 55; - v[431][5] = 13; - v[432][5] = 7; - v[433][5] = 47; - v[434][5] = 37; - v[435][5] = 11; - v[436][5] = 43; - v[437][5] = 17; - v[438][5] = 3; - v[439][5] = 25; - v[440][5] = 19; - v[441][5] = 55; - v[442][5] = 59; - v[443][5] = 37; - v[444][5] = 33; - v[445][5] = 43; - v[446][5] = 1; - v[447][5] = 5; - v[448][5] = 21; - v[449][5] = 5; - v[450][5] = 63; - v[451][5] = 49; - v[452][5] = 61; - v[453][5] = 21; - v[454][5] = 51; - v[455][5] = 15; - v[456][5] = 19; - v[457][5] = 43; - v[458][5] = 47; - v[459][5] = 17; - v[460][5] = 9; - v[461][5] = 53; - v[462][5] = 45; - v[463][5] = 11; - v[464][5] = 51; - v[465][5] = 25; - v[466][5] = 11; - v[467][5] = 25; - v[468][5] = 47; - v[469][5] = 47; - v[470][5] = 1; - v[471][5] = 43; - v[472][5] = 29; - v[473][5] = 17; - v[474][5] = 31; - v[475][5] = 15; - v[476][5] = 59; - v[477][5] = 27; - v[478][5] = 63; - v[479][5] = 11; - v[480][5] = 41; - v[481][5] = 51; - v[482][5] = 29; - v[483][5] = 7; - v[484][5] = 27; - v[485][5] = 63; - v[486][5] = 31; - v[487][5] = 43; - v[488][5] = 3; - v[489][5] = 29; - v[490][5] = 39; - v[491][5] = 3; - v[492][5] = 59; - v[493][5] = 59; - v[494][5] = 1; - v[495][5] = 53; - v[496][5] = 63; - v[497][5] = 23; - v[498][5] = 63; - v[499][5] = 47; - v[500][5] = 51; - v[501][5] = 23; - v[502][5] = 61; - v[503][5] = 39; - v[504][5] = 47; - v[505][5] = 21; - v[506][5] = 39; - v[507][5] = 15; - v[508][5] = 3; - v[509][5] = 9; - v[510][5] = 57; - v[511][5] = 61; - v[512][5] = 39; - v[513][5] = 37; - v[514][5] = 21; - v[515][5] = 51; - v[516][5] = 1; - v[517][5] = 23; - v[518][5] = 43; - v[519][5] = 27; - v[520][5] = 25; - v[521][5] = 11; - v[522][5] = 13; - v[523][5] = 21; - v[524][5] = 43; - v[525][5] = 7; - v[526][5] = 11; - v[527][5] = 33; - v[528][5] = 55; - v[529][5] = 1; - v[530][5] = 37; - v[531][5] = 35; - v[532][5] = 27; - v[533][5] = 61; - v[534][5] = 39; - v[535][5] = 5; - v[536][5] = 19; - v[537][5] = 61; - v[538][5] = 61; - v[539][5] = 57; - v[540][5] = 59; - v[541][5] = 21; - v[542][5] = 59; - v[543][5] = 61; - v[544][5] = 57; - v[545][5] = 25; - v[546][5] = 55; - v[547][5] = 27; - v[548][5] = 31; - v[549][5] = 41; - v[550][5] = 33; - v[551][5] = 63; - v[552][5] = 19; - v[553][5] = 57; - v[554][5] = 35; - v[555][5] = 13; - v[556][5] = 63; - v[557][5] = 35; - v[558][5] = 17; - v[559][5] = 11; - v[560][5] = 11; - v[561][5] = 49; - v[562][5] = 41; - v[563][5] = 55; - v[564][5] = 5; - v[565][5] = 45; - v[566][5] = 17; - v[567][5] = 35; - v[568][5] = 5; - v[569][5] = 31; - v[570][5] = 31; - v[571][5] = 37; - v[572][5] = 17; - v[573][5] = 45; - v[574][5] = 51; - v[575][5] = 1; - v[576][5] = 39; - v[577][5] = 49; - v[578][5] = 55; - v[579][5] = 19; - v[580][5] = 41; - v[581][5] = 13; - v[582][5] = 5; - v[583][5] = 51; - v[584][5] = 5; - v[585][5] = 49; - v[586][5] = 1; - v[587][5] = 21; - v[588][5] = 13; - v[589][5] = 17; - v[590][5] = 59; - v[591][5] = 51; - v[592][5] = 11; - v[593][5] = 3; - v[594][5] = 61; - v[595][5] = 1; - v[596][5] = 33; - v[597][5] = 37; - v[598][5] = 33; - v[599][5] = 61; - v[600][5] = 25; - v[601][5] = 27; - v[602][5] = 59; - v[603][5] = 7; - v[604][5] = 49; - v[605][5] = 13; - v[606][5] = 63; - v[607][5] = 3; - v[608][5] = 33; - v[609][5] = 3; - v[610][5] = 15; - v[611][5] = 9; - v[612][5] = 13; - v[613][5] = 35; - v[614][5] = 39; - v[615][5] = 11; - v[616][5] = 59; - v[617][5] = 59; - v[618][5] = 1; - v[619][5] = 57; - v[620][5] = 11; - v[621][5] = 5; - v[622][5] = 57; - v[623][5] = 13; - v[624][5] = 31; - v[625][5] = 13; - v[626][5] = 11; - v[627][5] = 55; - v[628][5] = 45; - v[629][5] = 9; - v[630][5] = 55; - v[631][5] = 55; - v[632][5] = 19; - v[633][5] = 25; - v[634][5] = 41; - v[635][5] = 23; - v[636][5] = 45; - v[637][5] = 29; - v[638][5] = 63; - v[639][5] = 59; - v[640][5] = 27; - v[641][5] = 39; - v[642][5] = 21; - v[643][5] = 37; - v[644][5] = 7; - v[645][5] = 61; - v[646][5] = 49; - v[647][5] = 35; - v[648][5] = 39; - v[649][5] = 9; - v[650][5] = 29; - v[651][5] = 7; - v[652][5] = 25; - v[653][5] = 23; - v[654][5] = 57; - v[655][5] = 5; - v[656][5] = 19; - v[657][5] = 15; - v[658][5] = 33; - v[659][5] = 49; - v[660][5] = 37; - v[661][5] = 25; - v[662][5] = 17; - v[663][5] = 45; - v[664][5] = 29; - v[665][5] = 15; - v[666][5] = 25; - v[667][5] = 3; - v[668][5] = 3; - v[669][5] = 49; - v[670][5] = 11; - v[671][5] = 39; - v[672][5] = 15; - v[673][5] = 19; - v[674][5] = 57; - v[675][5] = 39; - v[676][5] = 15; - v[677][5] = 11; - v[678][5] = 3; - v[679][5] = 57; - v[680][5] = 31; - v[681][5] = 55; - v[682][5] = 61; - v[683][5] = 19; - v[684][5] = 5; - v[685][5] = 41; - v[686][5] = 35; - v[687][5] = 59; - v[688][5] = 61; - v[689][5] = 39; - v[690][5] = 41; - v[691][5] = 53; - v[692][5] = 53; - v[693][5] = 63; - v[694][5] = 31; - v[695][5] = 9; - v[696][5] = 59; - v[697][5] = 13; - v[698][5] = 35; - v[699][5] = 55; - v[700][5] = 41; - v[701][5] = 49; - v[702][5] = 5; - v[703][5] = 41; - v[704][5] = 25; - v[705][5] = 27; - v[706][5] = 43; - v[707][5] = 5; - v[708][5] = 5; - v[709][5] = 43; - v[710][5] = 5; - v[711][5] = 5; - v[712][5] = 17; - v[713][5] = 5; - v[714][5] = 15; - v[715][5] = 27; - v[716][5] = 29; - v[717][5] = 17; - v[718][5] = 9; - v[719][5] = 3; - v[720][5] = 55; - v[721][5] = 31; - v[722][5] = 1; - v[723][5] = 45; - v[724][5] = 45; - v[725][5] = 13; - v[726][5] = 57; - v[727][5] = 17; - v[728][5] = 3; - v[729][5] = 61; - v[730][5] = 15; - v[731][5] = 49; - v[732][5] = 15; - v[733][5] = 47; - v[734][5] = 9; - v[735][5] = 37; - v[736][5] = 45; - v[737][5] = 9; - v[738][5] = 51; - v[739][5] = 61; - v[740][5] = 21; - v[741][5] = 33; - v[742][5] = 11; - v[743][5] = 21; - v[744][5] = 63; - v[745][5] = 63; - v[746][5] = 47; - v[747][5] = 57; - v[748][5] = 61; - v[749][5] = 49; - v[750][5] = 9; - v[751][5] = 59; - v[752][5] = 19; - v[753][5] = 29; - v[754][5] = 21; - v[755][5] = 23; - v[756][5] = 55; - v[757][5] = 23; - v[758][5] = 43; - v[759][5] = 41; - v[760][5] = 57; - v[761][5] = 9; - v[762][5] = 39; - v[763][5] = 27; - v[764][5] = 41; - v[765][5] = 35; - v[766][5] = 61; - v[767][5] = 29; - v[768][5] = 57; - v[769][5] = 63; - v[770][5] = 21; - v[771][5] = 31; - v[772][5] = 59; - v[773][5] = 35; - v[774][5] = 49; - v[775][5] = 3; - v[776][5] = 49; - v[777][5] = 47; - v[778][5] = 49; - v[779][5] = 33; - v[780][5] = 21; - v[781][5] = 19; - v[782][5] = 21; - v[783][5] = 35; - v[784][5] = 11; - v[785][5] = 17; - v[786][5] = 37; - v[787][5] = 23; - v[788][5] = 59; - v[789][5] = 13; - v[790][5] = 37; - v[791][5] = 35; - v[792][5] = 55; - v[793][5] = 57; - v[794][5] = 1; - v[795][5] = 29; - v[796][5] = 45; - v[797][5] = 11; - v[798][5] = 1; - v[799][5] = 15; - v[800][5] = 9; - v[801][5] = 33; - v[802][5] = 19; - v[803][5] = 53; - v[804][5] = 43; - v[805][5] = 39; - v[806][5] = 23; - v[807][5] = 7; - v[808][5] = 13; - v[809][5] = 13; - v[810][5] = 1; - v[811][5] = 19; - v[812][5] = 41; - v[813][5] = 55; - v[814][5] = 1; - v[815][5] = 13; - v[816][5] = 15; - v[817][5] = 59; - v[818][5] = 55; - v[819][5] = 15; - v[820][5] = 3; - v[821][5] = 57; - v[822][5] = 37; - v[823][5] = 31; - v[824][5] = 17; - v[825][5] = 1; - v[826][5] = 3; - v[827][5] = 21; - v[828][5] = 29; - v[829][5] = 25; - v[830][5] = 55; - v[831][5] = 9; - v[832][5] = 37; - v[833][5] = 33; - v[834][5] = 53; - v[835][5] = 41; - v[836][5] = 51; - v[837][5] = 19; - v[838][5] = 57; - v[839][5] = 13; - v[840][5] = 63; - v[841][5] = 43; - v[842][5] = 19; - v[843][5] = 7; - v[844][5] = 13; - v[845][5] = 37; - v[846][5] = 33; - v[847][5] = 19; - v[848][5] = 15; - v[849][5] = 63; - v[850][5] = 51; - v[851][5] = 11; - v[852][5] = 49; - v[853][5] = 23; - v[854][5] = 57; - v[855][5] = 47; - v[856][5] = 51; - v[857][5] = 15; - v[858][5] = 53; - v[859][5] = 41; - v[860][5] = 1; - v[861][5] = 15; - v[862][5] = 37; - v[863][5] = 61; - v[864][5] = 11; - v[865][5] = 35; - v[866][5] = 29; - v[867][5] = 33; - v[868][5] = 23; - v[869][5] = 55; - v[870][5] = 11; - v[871][5] = 59; - v[872][5] = 19; - v[873][5] = 61; - v[874][5] = 61; - v[875][5] = 45; - v[876][5] = 13; - v[877][5] = 49; - v[878][5] = 13; - v[879][5] = 63; - v[880][5] = 5; - v[881][5] = 61; - v[882][5] = 5; - v[883][5] = 31; - v[884][5] = 17; - v[885][5] = 61; - v[886][5] = 63; - v[887][5] = 13; - v[888][5] = 27; - v[889][5] = 57; - v[890][5] = 1; - v[891][5] = 21; - v[892][5] = 5; - v[893][5] = 11; - v[894][5] = 39; - v[895][5] = 57; - v[896][5] = 51; - v[897][5] = 53; - v[898][5] = 39; - v[899][5] = 25; - v[900][5] = 41; - v[901][5] = 39; - v[902][5] = 37; - v[903][5] = 23; - v[904][5] = 31; - v[905][5] = 25; - v[906][5] = 33; - v[907][5] = 17; - v[908][5] = 57; - v[909][5] = 29; - v[910][5] = 27; - v[911][5] = 23; - v[912][5] = 47; - v[913][5] = 41; - v[914][5] = 29; - v[915][5] = 19; - v[916][5] = 47; - v[917][5] = 41; - v[918][5] = 25; - v[919][5] = 5; - v[920][5] = 51; - v[921][5] = 43; - v[922][5] = 39; - v[923][5] = 29; - v[924][5] = 7; - v[925][5] = 31; - v[926][5] = 45; - v[927][5] = 51; - v[928][5] = 49; - v[929][5] = 55; - v[930][5] = 17; - v[931][5] = 43; - v[932][5] = 49; - v[933][5] = 45; - v[934][5] = 9; - v[935][5] = 29; - v[936][5] = 3; - v[937][5] = 5; - v[938][5] = 47; - v[939][5] = 9; - v[940][5] = 15; - v[941][5] = 19; - v[942][5] = 51; - v[943][5] = 45; - v[944][5] = 57; - v[945][5] = 63; - v[946][5] = 9; - v[947][5] = 21; - v[948][5] = 59; - v[949][5] = 3; - v[950][5] = 9; - v[951][5] = 13; - v[952][5] = 45; - v[953][5] = 23; - v[954][5] = 15; - v[955][5] = 31; - v[956][5] = 21; - v[957][5] = 15; - v[958][5] = 51; - v[959][5] = 35; - v[960][5] = 9; - v[961][5] = 11; - v[962][5] = 61; - v[963][5] = 23; - v[964][5] = 53; - v[965][5] = 29; - v[966][5] = 51; - v[967][5] = 45; - v[968][5] = 31; - v[969][5] = 29; - v[970][5] = 5; - v[971][5] = 35; - v[972][5] = 29; - v[973][5] = 53; - v[974][5] = 35; - v[975][5] = 17; - v[976][5] = 59; - v[977][5] = 55; - v[978][5] = 27; - v[979][5] = 51; - v[980][5] = 59; - v[981][5] = 27; - v[982][5] = 47; - v[983][5] = 15; - v[984][5] = 29; - v[985][5] = 37; - v[986][5] = 7; - v[987][5] = 49; - v[988][5] = 55; - v[989][5] = 5; - v[990][5] = 19; - v[991][5] = 45; - v[992][5] = 29; - v[993][5] = 19; - v[994][5] = 57; - v[995][5] = 33; - v[996][5] = 53; - v[997][5] = 45; - v[998][5] = 21; - v[999][5] = 9; - v[1000][5] = 3; - v[1001][5] = 35; - v[1002][5] = 29; - v[1003][5] = 43; - v[1004][5] = 31; - v[1005][5] = 39; - v[1006][5] = 3; - v[1007][5] = 45; - v[1008][5] = 1; - v[1009][5] = 41; - v[1010][5] = 29; - v[1011][5] = 5; - v[1012][5] = 59; - v[1013][5] = 41; - v[1014][5] = 33; - v[1015][5] = 35; - v[1016][5] = 27; - v[1017][5] = 19; - v[1018][5] = 13; - v[1019][5] = 25; - v[1020][5] = 27; - v[1021][5] = 43; - v[1022][5] = 33; - v[1023][5] = 35; - v[1024][5] = 17; - v[1025][5] = 17; - v[1026][5] = 23; - v[1027][5] = 7; - v[1028][5] = 35; - v[1029][5] = 15; - v[1030][5] = 61; - v[1031][5] = 61; - v[1032][5] = 53; - v[1033][5] = 5; - v[1034][5] = 15; - v[1035][5] = 23; - v[1036][5] = 11; - v[1037][5] = 13; - v[1038][5] = 43; - v[1039][5] = 55; - v[1040][5] = 47; - v[1041][5] = 25; - v[1042][5] = 43; - v[1043][5] = 15; - v[1044][5] = 57; - v[1045][5] = 45; - v[1046][5] = 1; - v[1047][5] = 49; - v[1048][5] = 63; - v[1049][5] = 57; - v[1050][5] = 15; - v[1051][5] = 31; - v[1052][5] = 31; - v[1053][5] = 7; - v[1054][5] = 53; - v[1055][5] = 27; - v[1056][5] = 15; - v[1057][5] = 47; - v[1058][5] = 23; - v[1059][5] = 7; - v[1060][5] = 29; - v[1061][5] = 53; - v[1062][5] = 47; - v[1063][5] = 9; - v[1064][5] = 53; - v[1065][5] = 3; - v[1066][5] = 25; - v[1067][5] = 55; - v[1068][5] = 45; - v[1069][5] = 63; - v[1070][5] = 21; - v[1071][5] = 17; - v[1072][5] = 23; - v[1073][5] = 31; - v[1074][5] = 27; - v[1075][5] = 27; - v[1076][5] = 43; - v[1077][5] = 63; - v[1078][5] = 55; - v[1079][5] = 63; - v[1080][5] = 45; - v[1081][5] = 51; - v[1082][5] = 15; - v[1083][5] = 27; - v[1084][5] = 5; - v[1085][5] = 37; - v[1086][5] = 43; - v[1087][5] = 11; - v[1088][5] = 27; - v[1089][5] = 5; - v[1090][5] = 27; - v[1091][5] = 59; - v[1092][5] = 21; - v[1093][5] = 7; - v[1094][5] = 39; - v[1095][5] = 27; - v[1096][5] = 63; - v[1097][5] = 35; - v[1098][5] = 47; - v[1099][5] = 55; - v[1100][5] = 17; - v[1101][5] = 17; - v[1102][5] = 17; - v[1103][5] = 3; - v[1104][5] = 19; - v[1105][5] = 21; - v[1106][5] = 13; - v[1107][5] = 49; - v[1108][5] = 61; - v[1109][5] = 39; - v[1110][5] = 15; - - v[19][6] = 13; - v[20][6] = 33; - v[21][6] = 115; - v[22][6] = 41; - v[23][6] = 79; - v[24][6] = 17; - v[25][6] = 29; - v[26][6] = 119; - v[27][6] = 75; - v[28][6] = 73; - v[29][6] = 105; - v[30][6] = 7; - v[31][6] = 59; - v[32][6] = 65; - v[33][6] = 21; - v[34][6] = 3; - v[35][6] = 113; - v[36][6] = 61; - v[37][6] = 89; - v[38][6] = 45; - v[39][6] = 107; - v[40][6] = 21; - v[41][6] = 71; - v[42][6] = 79; - v[43][6] = 19; - v[44][6] = 71; - v[45][6] = 61; - v[46][6] = 41; - v[47][6] = 57; - v[48][6] = 121; - v[49][6] = 87; - v[50][6] = 119; - v[51][6] = 55; - v[52][6] = 85; - v[53][6] = 121; - v[54][6] = 119; - v[55][6] = 11; - v[56][6] = 23; - v[57][6] = 61; - v[58][6] = 11; - v[59][6] = 35; - v[60][6] = 33; - v[61][6] = 43; - v[62][6] = 107; - v[63][6] = 113; - v[64][6] = 101; - v[65][6] = 29; - v[66][6] = 87; - v[67][6] = 119; - v[68][6] = 97; - v[69][6] = 29; - v[70][6] = 17; - v[71][6] = 89; - v[72][6] = 5; - v[73][6] = 127; - v[74][6] = 89; - v[75][6] = 119; - v[76][6] = 117; - v[77][6] = 103; - v[78][6] = 105; - v[79][6] = 41; - v[80][6] = 83; - v[81][6] = 25; - v[82][6] = 41; - v[83][6] = 55; - v[84][6] = 69; - v[85][6] = 117; - v[86][6] = 49; - v[87][6] = 127; - v[88][6] = 29; - v[89][6] = 1; - v[90][6] = 99; - v[91][6] = 53; - v[92][6] = 83; - v[93][6] = 15; - v[94][6] = 31; - v[95][6] = 73; - v[96][6] = 115; - v[97][6] = 35; - v[98][6] = 21; - v[99][6] = 89; - v[100][6] = 5; - v[101][6] = 1; - v[102][6] = 91; - v[103][6] = 53; - v[104][6] = 35; - v[105][6] = 95; - v[106][6] = 83; - v[107][6] = 19; - v[108][6] = 85; - v[109][6] = 55; - v[110][6] = 51; - v[111][6] = 101; - v[112][6] = 33; - v[113][6] = 41; - v[114][6] = 55; - v[115][6] = 45; - v[116][6] = 95; - v[117][6] = 61; - v[118][6] = 27; - v[119][6] = 37; - v[120][6] = 89; - v[121][6] = 75; - v[122][6] = 57; - v[123][6] = 61; - v[124][6] = 15; - v[125][6] = 117; - v[126][6] = 15; - v[127][6] = 21; - v[128][6] = 27; - v[129][6] = 25; - v[130][6] = 27; - v[131][6] = 123; - v[132][6] = 39; - v[133][6] = 109; - v[134][6] = 93; - v[135][6] = 51; - v[136][6] = 21; - v[137][6] = 91; - v[138][6] = 109; - v[139][6] = 107; - v[140][6] = 45; - v[141][6] = 15; - v[142][6] = 93; - v[143][6] = 127; - v[144][6] = 3; - v[145][6] = 53; - v[146][6] = 81; - v[147][6] = 79; - v[148][6] = 107; - v[149][6] = 79; - v[150][6] = 87; - v[151][6] = 35; - v[152][6] = 109; - v[153][6] = 73; - v[154][6] = 35; - v[155][6] = 83; - v[156][6] = 107; - v[157][6] = 1; - v[158][6] = 51; - v[159][6] = 7; - v[160][6] = 59; - v[161][6] = 33; - v[162][6] = 115; - v[163][6] = 43; - v[164][6] = 111; - v[165][6] = 45; - v[166][6] = 121; - v[167][6] = 105; - v[168][6] = 125; - v[169][6] = 87; - v[170][6] = 101; - v[171][6] = 41; - v[172][6] = 95; - v[173][6] = 75; - v[174][6] = 1; - v[175][6] = 57; - v[176][6] = 117; - v[177][6] = 21; - v[178][6] = 27; - v[179][6] = 67; - v[180][6] = 29; - v[181][6] = 53; - v[182][6] = 117; - v[183][6] = 63; - v[184][6] = 1; - v[185][6] = 77; - v[186][6] = 89; - v[187][6] = 115; - v[188][6] = 49; - v[189][6] = 127; - v[190][6] = 15; - v[191][6] = 79; - v[192][6] = 81; - v[193][6] = 29; - v[194][6] = 65; - v[195][6] = 103; - v[196][6] = 33; - v[197][6] = 73; - v[198][6] = 79; - v[199][6] = 29; - v[200][6] = 21; - v[201][6] = 113; - v[202][6] = 31; - v[203][6] = 33; - v[204][6] = 107; - v[205][6] = 95; - v[206][6] = 111; - v[207][6] = 59; - v[208][6] = 99; - v[209][6] = 117; - v[210][6] = 63; - v[211][6] = 63; - v[212][6] = 99; - v[213][6] = 39; - v[214][6] = 9; - v[215][6] = 35; - v[216][6] = 63; - v[217][6] = 125; - v[218][6] = 99; - v[219][6] = 45; - v[220][6] = 93; - v[221][6] = 33; - v[222][6] = 93; - v[223][6] = 9; - v[224][6] = 105; - v[225][6] = 75; - v[226][6] = 51; - v[227][6] = 115; - v[228][6] = 11; - v[229][6] = 37; - v[230][6] = 17; - v[231][6] = 41; - v[232][6] = 21; - v[233][6] = 43; - v[234][6] = 73; - v[235][6] = 19; - v[236][6] = 93; - v[237][6] = 7; - v[238][6] = 95; - v[239][6] = 81; - v[240][6] = 93; - v[241][6] = 79; - v[242][6] = 81; - v[243][6] = 55; - v[244][6] = 9; - v[245][6] = 51; - v[246][6] = 63; - v[247][6] = 45; - v[248][6] = 89; - v[249][6] = 73; - v[250][6] = 19; - v[251][6] = 115; - v[252][6] = 39; - v[253][6] = 47; - v[254][6] = 81; - v[255][6] = 39; - v[256][6] = 5; - v[257][6] = 5; - v[258][6] = 45; - v[259][6] = 53; - v[260][6] = 65; - v[261][6] = 49; - v[262][6] = 17; - v[263][6] = 105; - v[264][6] = 13; - v[265][6] = 107; - v[266][6] = 5; - v[267][6] = 5; - v[268][6] = 19; - v[269][6] = 73; - v[270][6] = 59; - v[271][6] = 43; - v[272][6] = 83; - v[273][6] = 97; - v[274][6] = 115; - v[275][6] = 27; - v[276][6] = 1; - v[277][6] = 69; - v[278][6] = 103; - v[279][6] = 3; - v[280][6] = 99; - v[281][6] = 103; - v[282][6] = 63; - v[283][6] = 67; - v[284][6] = 25; - v[285][6] = 121; - v[286][6] = 97; - v[287][6] = 77; - v[288][6] = 13; - v[289][6] = 83; - v[290][6] = 103; - v[291][6] = 41; - v[292][6] = 11; - v[293][6] = 27; - v[294][6] = 81; - v[295][6] = 37; - v[296][6] = 33; - v[297][6] = 125; - v[298][6] = 71; - v[299][6] = 41; - v[300][6] = 41; - v[301][6] = 59; - v[302][6] = 41; - v[303][6] = 87; - v[304][6] = 123; - v[305][6] = 43; - v[306][6] = 101; - v[307][6] = 63; - v[308][6] = 45; - v[309][6] = 39; - v[310][6] = 21; - v[311][6] = 97; - v[312][6] = 15; - v[313][6] = 97; - v[314][6] = 111; - v[315][6] = 21; - v[316][6] = 49; - v[317][6] = 13; - v[318][6] = 17; - v[319][6] = 79; - v[320][6] = 91; - v[321][6] = 65; - v[322][6] = 105; - v[323][6] = 75; - v[324][6] = 1; - v[325][6] = 45; - v[326][6] = 67; - v[327][6] = 83; - v[328][6] = 107; - v[329][6] = 125; - v[330][6] = 87; - v[331][6] = 15; - v[332][6] = 81; - v[333][6] = 95; - v[334][6] = 105; - v[335][6] = 65; - v[336][6] = 45; - v[337][6] = 59; - v[338][6] = 103; - v[339][6] = 23; - v[340][6] = 103; - v[341][6] = 99; - v[342][6] = 67; - v[343][6] = 99; - v[344][6] = 47; - v[345][6] = 117; - v[346][6] = 71; - v[347][6] = 89; - v[348][6] = 35; - v[349][6] = 53; - v[350][6] = 73; - v[351][6] = 9; - v[352][6] = 115; - v[353][6] = 49; - v[354][6] = 37; - v[355][6] = 1; - v[356][6] = 35; - v[357][6] = 9; - v[358][6] = 45; - v[359][6] = 81; - v[360][6] = 19; - v[361][6] = 127; - v[362][6] = 17; - v[363][6] = 17; - v[364][6] = 105; - v[365][6] = 89; - v[366][6] = 49; - v[367][6] = 101; - v[368][6] = 7; - v[369][6] = 37; - v[370][6] = 33; - v[371][6] = 11; - v[372][6] = 95; - v[373][6] = 95; - v[374][6] = 17; - v[375][6] = 111; - v[376][6] = 105; - v[377][6] = 41; - v[378][6] = 115; - v[379][6] = 5; - v[380][6] = 69; - v[381][6] = 101; - v[382][6] = 27; - v[383][6] = 27; - v[384][6] = 101; - v[385][6] = 103; - v[386][6] = 53; - v[387][6] = 9; - v[388][6] = 21; - v[389][6] = 43; - v[390][6] = 79; - v[391][6] = 91; - v[392][6] = 65; - v[393][6] = 117; - v[394][6] = 87; - v[395][6] = 125; - v[396][6] = 55; - v[397][6] = 45; - v[398][6] = 63; - v[399][6] = 85; - v[400][6] = 83; - v[401][6] = 97; - v[402][6] = 45; - v[403][6] = 83; - v[404][6] = 87; - v[405][6] = 113; - v[406][6] = 93; - v[407][6] = 95; - v[408][6] = 5; - v[409][6] = 17; - v[410][6] = 77; - v[411][6] = 77; - v[412][6] = 127; - v[413][6] = 123; - v[414][6] = 45; - v[415][6] = 81; - v[416][6] = 85; - v[417][6] = 121; - v[418][6] = 119; - v[419][6] = 27; - v[420][6] = 85; - v[421][6] = 41; - v[422][6] = 49; - v[423][6] = 15; - v[424][6] = 107; - v[425][6] = 21; - v[426][6] = 51; - v[427][6] = 119; - v[428][6] = 11; - v[429][6] = 87; - v[430][6] = 101; - v[431][6] = 115; - v[432][6] = 63; - v[433][6] = 63; - v[434][6] = 37; - v[435][6] = 121; - v[436][6] = 109; - v[437][6] = 7; - v[438][6] = 43; - v[439][6] = 69; - v[440][6] = 19; - v[441][6] = 77; - v[442][6] = 49; - v[443][6] = 71; - v[444][6] = 59; - v[445][6] = 35; - v[446][6] = 7; - v[447][6] = 13; - v[448][6] = 55; - v[449][6] = 101; - v[450][6] = 127; - v[451][6] = 103; - v[452][6] = 85; - v[453][6] = 109; - v[454][6] = 29; - v[455][6] = 61; - v[456][6] = 67; - v[457][6] = 21; - v[458][6] = 111; - v[459][6] = 67; - v[460][6] = 23; - v[461][6] = 57; - v[462][6] = 75; - v[463][6] = 71; - v[464][6] = 101; - v[465][6] = 123; - v[466][6] = 41; - v[467][6] = 107; - v[468][6] = 101; - v[469][6] = 107; - v[470][6] = 125; - v[471][6] = 27; - v[472][6] = 47; - v[473][6] = 119; - v[474][6] = 41; - v[475][6] = 19; - v[476][6] = 127; - v[477][6] = 33; - v[478][6] = 31; - v[479][6] = 109; - v[480][6] = 7; - v[481][6] = 91; - v[482][6] = 91; - v[483][6] = 39; - v[484][6] = 125; - v[485][6] = 105; - v[486][6] = 47; - v[487][6] = 125; - v[488][6] = 123; - v[489][6] = 91; - v[490][6] = 9; - v[491][6] = 103; - v[492][6] = 45; - v[493][6] = 23; - v[494][6] = 117; - v[495][6] = 9; - v[496][6] = 125; - v[497][6] = 73; - v[498][6] = 11; - v[499][6] = 37; - v[500][6] = 61; - v[501][6] = 79; - v[502][6] = 21; - v[503][6] = 5; - v[504][6] = 47; - v[505][6] = 117; - v[506][6] = 67; - v[507][6] = 53; - v[508][6] = 85; - v[509][6] = 33; - v[510][6] = 81; - v[511][6] = 121; - v[512][6] = 47; - v[513][6] = 61; - v[514][6] = 51; - v[515][6] = 127; - v[516][6] = 29; - v[517][6] = 65; - v[518][6] = 45; - v[519][6] = 41; - v[520][6] = 95; - v[521][6] = 57; - v[522][6] = 73; - v[523][6] = 33; - v[524][6] = 117; - v[525][6] = 61; - v[526][6] = 111; - v[527][6] = 59; - v[528][6] = 123; - v[529][6] = 65; - v[530][6] = 47; - v[531][6] = 105; - v[532][6] = 23; - v[533][6] = 29; - v[534][6] = 107; - v[535][6] = 37; - v[536][6] = 81; - v[537][6] = 67; - v[538][6] = 29; - v[539][6] = 115; - v[540][6] = 119; - v[541][6] = 75; - v[542][6] = 73; - v[543][6] = 99; - v[544][6] = 103; - v[545][6] = 7; - v[546][6] = 57; - v[547][6] = 45; - v[548][6] = 61; - v[549][6] = 95; - v[550][6] = 49; - v[551][6] = 101; - v[552][6] = 101; - v[553][6] = 35; - v[554][6] = 47; - v[555][6] = 119; - v[556][6] = 39; - v[557][6] = 67; - v[558][6] = 31; - v[559][6] = 103; - v[560][6] = 7; - v[561][6] = 61; - v[562][6] = 127; - v[563][6] = 87; - v[564][6] = 3; - v[565][6] = 35; - v[566][6] = 29; - v[567][6] = 73; - v[568][6] = 95; - v[569][6] = 103; - v[570][6] = 71; - v[571][6] = 75; - v[572][6] = 51; - v[573][6] = 87; - v[574][6] = 57; - v[575][6] = 97; - v[576][6] = 11; - v[577][6] = 105; - v[578][6] = 87; - v[579][6] = 41; - v[580][6] = 73; - v[581][6] = 109; - v[582][6] = 69; - v[583][6] = 35; - v[584][6] = 121; - v[585][6] = 39; - v[586][6] = 111; - v[587][6] = 1; - v[588][6] = 77; - v[589][6] = 39; - v[590][6] = 47; - v[591][6] = 53; - v[592][6] = 91; - v[593][6] = 3; - v[594][6] = 17; - v[595][6] = 51; - v[596][6] = 83; - v[597][6] = 39; - v[598][6] = 125; - v[599][6] = 85; - v[600][6] = 111; - v[601][6] = 21; - v[602][6] = 69; - v[603][6] = 85; - v[604][6] = 29; - v[605][6] = 55; - v[606][6] = 11; - v[607][6] = 117; - v[608][6] = 1; - v[609][6] = 47; - v[610][6] = 17; - v[611][6] = 65; - v[612][6] = 63; - v[613][6] = 47; - v[614][6] = 117; - v[615][6] = 17; - v[616][6] = 115; - v[617][6] = 51; - v[618][6] = 25; - v[619][6] = 33; - v[620][6] = 123; - v[621][6] = 123; - v[622][6] = 83; - v[623][6] = 51; - v[624][6] = 113; - v[625][6] = 95; - v[626][6] = 121; - v[627][6] = 51; - v[628][6] = 91; - v[629][6] = 109; - v[630][6] = 43; - v[631][6] = 55; - v[632][6] = 35; - v[633][6] = 55; - v[634][6] = 87; - v[635][6] = 33; - v[636][6] = 37; - v[637][6] = 5; - v[638][6] = 3; - v[639][6] = 45; - v[640][6] = 21; - v[641][6] = 105; - v[642][6] = 127; - v[643][6] = 35; - v[644][6] = 17; - v[645][6] = 35; - v[646][6] = 37; - v[647][6] = 97; - v[648][6] = 97; - v[649][6] = 21; - v[650][6] = 77; - v[651][6] = 123; - v[652][6] = 17; - v[653][6] = 89; - v[654][6] = 53; - v[655][6] = 105; - v[656][6] = 75; - v[657][6] = 25; - v[658][6] = 125; - v[659][6] = 13; - v[660][6] = 47; - v[661][6] = 21; - v[662][6] = 125; - v[663][6] = 23; - v[664][6] = 55; - v[665][6] = 63; - v[666][6] = 61; - v[667][6] = 5; - v[668][6] = 17; - v[669][6] = 93; - v[670][6] = 57; - v[671][6] = 121; - v[672][6] = 69; - v[673][6] = 73; - v[674][6] = 93; - v[675][6] = 121; - v[676][6] = 105; - v[677][6] = 75; - v[678][6] = 91; - v[679][6] = 67; - v[680][6] = 95; - v[681][6] = 75; - v[682][6] = 9; - v[683][6] = 69; - v[684][6] = 97; - v[685][6] = 99; - v[686][6] = 93; - v[687][6] = 11; - v[688][6] = 53; - v[689][6] = 19; - v[690][6] = 73; - v[691][6] = 5; - v[692][6] = 33; - v[693][6] = 79; - v[694][6] = 107; - v[695][6] = 65; - v[696][6] = 69; - v[697][6] = 79; - v[698][6] = 125; - v[699][6] = 25; - v[700][6] = 93; - v[701][6] = 55; - v[702][6] = 61; - v[703][6] = 17; - v[704][6] = 117; - v[705][6] = 69; - v[706][6] = 97; - v[707][6] = 87; - v[708][6] = 111; - v[709][6] = 37; - v[710][6] = 93; - v[711][6] = 59; - v[712][6] = 79; - v[713][6] = 95; - v[714][6] = 53; - v[715][6] = 115; - v[716][6] = 53; - v[717][6] = 85; - v[718][6] = 85; - v[719][6] = 65; - v[720][6] = 59; - v[721][6] = 23; - v[722][6] = 75; - v[723][6] = 21; - v[724][6] = 67; - v[725][6] = 27; - v[726][6] = 99; - v[727][6] = 79; - v[728][6] = 27; - v[729][6] = 3; - v[730][6] = 95; - v[731][6] = 27; - v[732][6] = 69; - v[733][6] = 19; - v[734][6] = 75; - v[735][6] = 47; - v[736][6] = 59; - v[737][6] = 41; - v[738][6] = 85; - v[739][6] = 77; - v[740][6] = 99; - v[741][6] = 55; - v[742][6] = 49; - v[743][6] = 93; - v[744][6] = 93; - v[745][6] = 119; - v[746][6] = 51; - v[747][6] = 125; - v[748][6] = 63; - v[749][6] = 13; - v[750][6] = 15; - v[751][6] = 45; - v[752][6] = 61; - v[753][6] = 19; - v[754][6] = 105; - v[755][6] = 115; - v[756][6] = 17; - v[757][6] = 83; - v[758][6] = 7; - v[759][6] = 7; - v[760][6] = 11; - v[761][6] = 61; - v[762][6] = 37; - v[763][6] = 63; - v[764][6] = 89; - v[765][6] = 95; - v[766][6] = 119; - v[767][6] = 113; - v[768][6] = 67; - v[769][6] = 123; - v[770][6] = 91; - v[771][6] = 33; - v[772][6] = 37; - v[773][6] = 99; - v[774][6] = 43; - v[775][6] = 11; - v[776][6] = 33; - v[777][6] = 65; - v[778][6] = 81; - v[779][6] = 79; - v[780][6] = 81; - v[781][6] = 107; - v[782][6] = 63; - v[783][6] = 63; - v[784][6] = 55; - v[785][6] = 89; - v[786][6] = 91; - v[787][6] = 25; - v[788][6] = 93; - v[789][6] = 101; - v[790][6] = 27; - v[791][6] = 55; - v[792][6] = 75; - v[793][6] = 121; - v[794][6] = 79; - v[795][6] = 43; - v[796][6] = 125; - v[797][6] = 73; - v[798][6] = 27; - v[799][6] = 109; - v[800][6] = 35; - v[801][6] = 21; - v[802][6] = 71; - v[803][6] = 113; - v[804][6] = 89; - v[805][6] = 59; - v[806][6] = 95; - v[807][6] = 41; - v[808][6] = 45; - v[809][6] = 113; - v[810][6] = 119; - v[811][6] = 113; - v[812][6] = 39; - v[813][6] = 59; - v[814][6] = 73; - v[815][6] = 15; - v[816][6] = 13; - v[817][6] = 59; - v[818][6] = 67; - v[819][6] = 121; - v[820][6] = 27; - v[821][6] = 7; - v[822][6] = 105; - v[823][6] = 15; - v[824][6] = 59; - v[825][6] = 59; - v[826][6] = 35; - v[827][6] = 91; - v[828][6] = 89; - v[829][6] = 23; - v[830][6] = 125; - v[831][6] = 97; - v[832][6] = 53; - v[833][6] = 41; - v[834][6] = 91; - v[835][6] = 111; - v[836][6] = 29; - v[837][6] = 31; - v[838][6] = 3; - v[839][6] = 103; - v[840][6] = 61; - v[841][6] = 71; - v[842][6] = 35; - v[843][6] = 7; - v[844][6] = 119; - v[845][6] = 29; - v[846][6] = 45; - v[847][6] = 49; - v[848][6] = 111; - v[849][6] = 41; - v[850][6] = 109; - v[851][6] = 59; - v[852][6] = 125; - v[853][6] = 13; - v[854][6] = 27; - v[855][6] = 19; - v[856][6] = 79; - v[857][6] = 9; - v[858][6] = 75; - v[859][6] = 83; - v[860][6] = 81; - v[861][6] = 33; - v[862][6] = 91; - v[863][6] = 109; - v[864][6] = 33; - v[865][6] = 29; - v[866][6] = 107; - v[867][6] = 111; - v[868][6] = 101; - v[869][6] = 107; - v[870][6] = 109; - v[871][6] = 65; - v[872][6] = 59; - v[873][6] = 43; - v[874][6] = 37; - v[875][6] = 1; - v[876][6] = 9; - v[877][6] = 15; - v[878][6] = 109; - v[879][6] = 37; - v[880][6] = 111; - v[881][6] = 113; - v[882][6] = 119; - v[883][6] = 79; - v[884][6] = 73; - v[885][6] = 65; - v[886][6] = 71; - v[887][6] = 93; - v[888][6] = 17; - v[889][6] = 101; - v[890][6] = 87; - v[891][6] = 97; - v[892][6] = 43; - v[893][6] = 23; - v[894][6] = 75; - v[895][6] = 109; - v[896][6] = 41; - v[897][6] = 49; - v[898][6] = 53; - v[899][6] = 31; - v[900][6] = 97; - v[901][6] = 105; - v[902][6] = 109; - v[903][6] = 119; - v[904][6] = 51; - v[905][6] = 9; - v[906][6] = 53; - v[907][6] = 113; - v[908][6] = 97; - v[909][6] = 73; - v[910][6] = 89; - v[911][6] = 79; - v[912][6] = 49; - v[913][6] = 61; - v[914][6] = 105; - v[915][6] = 13; - v[916][6] = 99; - v[917][6] = 53; - v[918][6] = 71; - v[919][6] = 7; - v[920][6] = 87; - v[921][6] = 21; - v[922][6] = 101; - v[923][6] = 5; - v[924][6] = 71; - v[925][6] = 31; - v[926][6] = 123; - v[927][6] = 121; - v[928][6] = 121; - v[929][6] = 73; - v[930][6] = 79; - v[931][6] = 115; - v[932][6] = 13; - v[933][6] = 39; - v[934][6] = 101; - v[935][6] = 19; - v[936][6] = 37; - v[937][6] = 51; - v[938][6] = 83; - v[939][6] = 97; - v[940][6] = 55; - v[941][6] = 81; - v[942][6] = 91; - v[943][6] = 127; - v[944][6] = 105; - v[945][6] = 89; - v[946][6] = 63; - v[947][6] = 47; - v[948][6] = 49; - v[949][6] = 75; - v[950][6] = 37; - v[951][6] = 77; - v[952][6] = 15; - v[953][6] = 49; - v[954][6] = 107; - v[955][6] = 23; - v[956][6] = 23; - v[957][6] = 35; - v[958][6] = 19; - v[959][6] = 69; - v[960][6] = 17; - v[961][6] = 59; - v[962][6] = 63; - v[963][6] = 73; - v[964][6] = 29; - v[965][6] = 125; - v[966][6] = 61; - v[967][6] = 65; - v[968][6] = 95; - v[969][6] = 101; - v[970][6] = 81; - v[971][6] = 57; - v[972][6] = 69; - v[973][6] = 83; - v[974][6] = 37; - v[975][6] = 11; - v[976][6] = 37; - v[977][6] = 95; - v[978][6] = 1; - v[979][6] = 73; - v[980][6] = 27; - v[981][6] = 29; - v[982][6] = 57; - v[983][6] = 7; - v[984][6] = 65; - v[985][6] = 83; - v[986][6] = 99; - v[987][6] = 69; - v[988][6] = 19; - v[989][6] = 103; - v[990][6] = 43; - v[991][6] = 95; - v[992][6] = 25; - v[993][6] = 19; - v[994][6] = 103; - v[995][6] = 41; - v[996][6] = 125; - v[997][6] = 97; - v[998][6] = 71; - v[999][6] = 105; - v[1000][6] = 83; - v[1001][6] = 83; - v[1002][6] = 61; - v[1003][6] = 39; - v[1004][6] = 9; - v[1005][6] = 45; - v[1006][6] = 117; - v[1007][6] = 63; - v[1008][6] = 31; - v[1009][6] = 5; - v[1010][6] = 117; - v[1011][6] = 67; - v[1012][6] = 125; - v[1013][6] = 41; - v[1014][6] = 117; - v[1015][6] = 43; - v[1016][6] = 77; - v[1017][6] = 97; - v[1018][6] = 15; - v[1019][6] = 29; - v[1020][6] = 5; - v[1021][6] = 59; - v[1022][6] = 25; - v[1023][6] = 63; - v[1024][6] = 87; - v[1025][6] = 39; - v[1026][6] = 39; - v[1027][6] = 77; - v[1028][6] = 85; - v[1029][6] = 37; - v[1030][6] = 81; - v[1031][6] = 73; - v[1032][6] = 89; - v[1033][6] = 29; - v[1034][6] = 125; - v[1035][6] = 109; - v[1036][6] = 21; - v[1037][6] = 23; - v[1038][6] = 119; - v[1039][6] = 105; - v[1040][6] = 43; - v[1041][6] = 93; - v[1042][6] = 97; - v[1043][6] = 15; - v[1044][6] = 125; - v[1045][6] = 29; - v[1046][6] = 51; - v[1047][6] = 69; - v[1048][6] = 37; - v[1049][6] = 45; - v[1050][6] = 31; - v[1051][6] = 75; - v[1052][6] = 109; - v[1053][6] = 119; - v[1054][6] = 53; - v[1055][6] = 5; - v[1056][6] = 101; - v[1057][6] = 125; - v[1058][6] = 121; - v[1059][6] = 35; - v[1060][6] = 29; - v[1061][6] = 7; - v[1062][6] = 63; - v[1063][6] = 17; - v[1064][6] = 63; - v[1065][6] = 13; - v[1066][6] = 69; - v[1067][6] = 15; - v[1068][6] = 105; - v[1069][6] = 51; - v[1070][6] = 127; - v[1071][6] = 105; - v[1072][6] = 9; - v[1073][6] = 57; - v[1074][6] = 95; - v[1075][6] = 59; - v[1076][6] = 109; - v[1077][6] = 35; - v[1078][6] = 49; - v[1079][6] = 23; - v[1080][6] = 33; - v[1081][6] = 107; - v[1082][6] = 55; - v[1083][6] = 33; - v[1084][6] = 57; - v[1085][6] = 79; - v[1086][6] = 73; - v[1087][6] = 69; - v[1088][6] = 59; - v[1089][6] = 107; - v[1090][6] = 55; - v[1091][6] = 11; - v[1092][6] = 63; - v[1093][6] = 95; - v[1094][6] = 103; - v[1095][6] = 23; - v[1096][6] = 125; - v[1097][6] = 91; - v[1098][6] = 31; - v[1099][6] = 91; - v[1100][6] = 51; - v[1101][6] = 65; - v[1102][6] = 61; - v[1103][6] = 75; - v[1104][6] = 69; - v[1105][6] = 107; - v[1106][6] = 65; - v[1107][6] = 101; - v[1108][6] = 59; - v[1109][6] = 35; - v[1110][6] = 15; - - v[37][7] = 7; - v[38][7] = 23; - v[39][7] = 39; - v[40][7] = 217; - v[41][7] = 141; - v[42][7] = 27; - v[43][7] = 53; - v[44][7] = 181; - v[45][7] = 169; - v[46][7] = 35; - v[47][7] = 15; - v[48][7] = 207; - v[49][7] = 45; - v[50][7] = 247; - v[51][7] = 185; - v[52][7] = 117; - v[53][7] = 41; - v[54][7] = 81; - v[55][7] = 223; - v[56][7] = 151; - v[57][7] = 81; - v[58][7] = 189; - v[59][7] = 61; - v[60][7] = 95; - v[61][7] = 185; - v[62][7] = 23; - v[63][7] = 73; - v[64][7] = 113; - v[65][7] = 239; - v[66][7] = 85; - v[67][7] = 9; - v[68][7] = 201; - v[69][7] = 83; - v[70][7] = 53; - v[71][7] = 183; - v[72][7] = 203; - v[73][7] = 91; - v[74][7] = 149; - v[75][7] = 101; - v[76][7] = 13; - v[77][7] = 111; - v[78][7] = 239; - v[79][7] = 3; - v[80][7] = 205; - v[81][7] = 253; - v[82][7] = 247; - v[83][7] = 121; - v[84][7] = 189; - v[85][7] = 169; - v[86][7] = 179; - v[87][7] = 197; - v[88][7] = 175; - v[89][7] = 217; - v[90][7] = 249; - v[91][7] = 195; - v[92][7] = 95; - v[93][7] = 63; - v[94][7] = 19; - v[95][7] = 7; - v[96][7] = 5; - v[97][7] = 75; - v[98][7] = 217; - v[99][7] = 245; - v[100][7] = 111; - v[101][7] = 189; - v[102][7] = 165; - v[103][7] = 169; - v[104][7] = 141; - v[105][7] = 221; - v[106][7] = 249; - v[107][7] = 159; - v[108][7] = 253; - v[109][7] = 207; - v[110][7] = 249; - v[111][7] = 219; - v[112][7] = 23; - v[113][7] = 49; - v[114][7] = 127; - v[115][7] = 237; - v[116][7] = 5; - v[117][7] = 25; - v[118][7] = 177; - v[119][7] = 37; - v[120][7] = 103; - v[121][7] = 65; - v[122][7] = 167; - v[123][7] = 81; - v[124][7] = 87; - v[125][7] = 119; - v[126][7] = 45; - v[127][7] = 79; - v[128][7] = 143; - v[129][7] = 57; - v[130][7] = 79; - v[131][7] = 187; - v[132][7] = 143; - v[133][7] = 183; - v[134][7] = 75; - v[135][7] = 97; - v[136][7] = 211; - v[137][7] = 149; - v[138][7] = 175; - v[139][7] = 37; - v[140][7] = 135; - v[141][7] = 189; - v[142][7] = 225; - v[143][7] = 241; - v[144][7] = 63; - v[145][7] = 33; - v[146][7] = 43; - v[147][7] = 13; - v[148][7] = 73; - v[149][7] = 213; - v[150][7] = 57; - v[151][7] = 239; - v[152][7] = 183; - v[153][7] = 117; - v[154][7] = 21; - v[155][7] = 29; - v[156][7] = 115; - v[157][7] = 43; - v[158][7] = 205; - v[159][7] = 223; - v[160][7] = 15; - v[161][7] = 3; - v[162][7] = 159; - v[163][7] = 51; - v[164][7] = 101; - v[165][7] = 127; - v[166][7] = 99; - v[167][7] = 239; - v[168][7] = 171; - v[169][7] = 113; - v[170][7] = 171; - v[171][7] = 119; - v[172][7] = 189; - v[173][7] = 245; - v[174][7] = 201; - v[175][7] = 27; - v[176][7] = 185; - v[177][7] = 229; - v[178][7] = 105; - v[179][7] = 153; - v[180][7] = 189; - v[181][7] = 33; - v[182][7] = 35; - v[183][7] = 137; - v[184][7] = 77; - v[185][7] = 97; - v[186][7] = 17; - v[187][7] = 181; - v[188][7] = 55; - v[189][7] = 197; - v[190][7] = 201; - v[191][7] = 155; - v[192][7] = 37; - v[193][7] = 197; - v[194][7] = 137; - v[195][7] = 223; - v[196][7] = 25; - v[197][7] = 179; - v[198][7] = 91; - v[199][7] = 23; - v[200][7] = 235; - v[201][7] = 53; - v[202][7] = 253; - v[203][7] = 49; - v[204][7] = 181; - v[205][7] = 249; - v[206][7] = 53; - v[207][7] = 173; - v[208][7] = 97; - v[209][7] = 247; - v[210][7] = 67; - v[211][7] = 115; - v[212][7] = 103; - v[213][7] = 159; - v[214][7] = 239; - v[215][7] = 69; - v[216][7] = 173; - v[217][7] = 217; - v[218][7] = 95; - v[219][7] = 221; - v[220][7] = 247; - v[221][7] = 97; - v[222][7] = 91; - v[223][7] = 123; - v[224][7] = 223; - v[225][7] = 213; - v[226][7] = 129; - v[227][7] = 181; - v[228][7] = 87; - v[229][7] = 239; - v[230][7] = 85; - v[231][7] = 89; - v[232][7] = 249; - v[233][7] = 141; - v[234][7] = 39; - v[235][7] = 57; - v[236][7] = 249; - v[237][7] = 71; - v[238][7] = 101; - v[239][7] = 159; - v[240][7] = 33; - v[241][7] = 137; - v[242][7] = 189; - v[243][7] = 71; - v[244][7] = 253; - v[245][7] = 205; - v[246][7] = 171; - v[247][7] = 13; - v[248][7] = 249; - v[249][7] = 109; - v[250][7] = 131; - v[251][7] = 199; - v[252][7] = 189; - v[253][7] = 179; - v[254][7] = 31; - v[255][7] = 99; - v[256][7] = 113; - v[257][7] = 41; - v[258][7] = 173; - v[259][7] = 23; - v[260][7] = 189; - v[261][7] = 197; - v[262][7] = 3; - v[263][7] = 135; - v[264][7] = 9; - v[265][7] = 95; - v[266][7] = 195; - v[267][7] = 27; - v[268][7] = 183; - v[269][7] = 1; - v[270][7] = 123; - v[271][7] = 73; - v[272][7] = 53; - v[273][7] = 99; - v[274][7] = 197; - v[275][7] = 59; - v[276][7] = 27; - v[277][7] = 101; - v[278][7] = 55; - v[279][7] = 193; - v[280][7] = 31; - v[281][7] = 61; - v[282][7] = 119; - v[283][7] = 11; - v[284][7] = 7; - v[285][7] = 255; - v[286][7] = 233; - v[287][7] = 53; - v[288][7] = 157; - v[289][7] = 193; - v[290][7] = 97; - v[291][7] = 83; - v[292][7] = 65; - v[293][7] = 81; - v[294][7] = 239; - v[295][7] = 167; - v[296][7] = 69; - v[297][7] = 71; - v[298][7] = 109; - v[299][7] = 97; - v[300][7] = 137; - v[301][7] = 71; - v[302][7] = 193; - v[303][7] = 189; - v[304][7] = 115; - v[305][7] = 79; - v[306][7] = 205; - v[307][7] = 37; - v[308][7] = 227; - v[309][7] = 53; - v[310][7] = 33; - v[311][7] = 91; - v[312][7] = 229; - v[313][7] = 245; - v[314][7] = 105; - v[315][7] = 77; - v[316][7] = 229; - v[317][7] = 161; - v[318][7] = 103; - v[319][7] = 93; - v[320][7] = 13; - v[321][7] = 161; - v[322][7] = 229; - v[323][7] = 223; - v[324][7] = 69; - v[325][7] = 15; - v[326][7] = 25; - v[327][7] = 23; - v[328][7] = 233; - v[329][7] = 93; - v[330][7] = 25; - v[331][7] = 217; - v[332][7] = 247; - v[333][7] = 61; - v[334][7] = 75; - v[335][7] = 27; - v[336][7] = 9; - v[337][7] = 223; - v[338][7] = 213; - v[339][7] = 55; - v[340][7] = 197; - v[341][7] = 145; - v[342][7] = 89; - v[343][7] = 199; - v[344][7] = 41; - v[345][7] = 201; - v[346][7] = 5; - v[347][7] = 149; - v[348][7] = 35; - v[349][7] = 119; - v[350][7] = 183; - v[351][7] = 53; - v[352][7] = 11; - v[353][7] = 13; - v[354][7] = 3; - v[355][7] = 179; - v[356][7] = 229; - v[357][7] = 43; - v[358][7] = 55; - v[359][7] = 187; - v[360][7] = 233; - v[361][7] = 47; - v[362][7] = 133; - v[363][7] = 91; - v[364][7] = 47; - v[365][7] = 71; - v[366][7] = 93; - v[367][7] = 105; - v[368][7] = 145; - v[369][7] = 45; - v[370][7] = 255; - v[371][7] = 221; - v[372][7] = 115; - v[373][7] = 175; - v[374][7] = 19; - v[375][7] = 129; - v[376][7] = 5; - v[377][7] = 209; - v[378][7] = 197; - v[379][7] = 57; - v[380][7] = 177; - v[381][7] = 115; - v[382][7] = 187; - v[383][7] = 119; - v[384][7] = 77; - v[385][7] = 211; - v[386][7] = 111; - v[387][7] = 33; - v[388][7] = 113; - v[389][7] = 23; - v[390][7] = 87; - v[391][7] = 137; - v[392][7] = 41; - v[393][7] = 7; - v[394][7] = 83; - v[395][7] = 43; - v[396][7] = 121; - v[397][7] = 145; - v[398][7] = 5; - v[399][7] = 219; - v[400][7] = 27; - v[401][7] = 11; - v[402][7] = 111; - v[403][7] = 207; - v[404][7] = 55; - v[405][7] = 97; - v[406][7] = 63; - v[407][7] = 229; - v[408][7] = 53; - v[409][7] = 33; - v[410][7] = 149; - v[411][7] = 23; - v[412][7] = 187; - v[413][7] = 153; - v[414][7] = 91; - v[415][7] = 193; - v[416][7] = 183; - v[417][7] = 59; - v[418][7] = 211; - v[419][7] = 93; - v[420][7] = 139; - v[421][7] = 59; - v[422][7] = 179; - v[423][7] = 163; - v[424][7] = 209; - v[425][7] = 77; - v[426][7] = 39; - v[427][7] = 111; - v[428][7] = 79; - v[429][7] = 229; - v[430][7] = 85; - v[431][7] = 237; - v[432][7] = 199; - v[433][7] = 137; - v[434][7] = 147; - v[435][7] = 25; - v[436][7] = 73; - v[437][7] = 121; - v[438][7] = 129; - v[439][7] = 83; - v[440][7] = 87; - v[441][7] = 93; - v[442][7] = 205; - v[443][7] = 167; - v[444][7] = 53; - v[445][7] = 107; - v[446][7] = 229; - v[447][7] = 213; - v[448][7] = 95; - v[449][7] = 219; - v[450][7] = 109; - v[451][7] = 175; - v[452][7] = 13; - v[453][7] = 209; - v[454][7] = 97; - v[455][7] = 61; - v[456][7] = 147; - v[457][7] = 19; - v[458][7] = 13; - v[459][7] = 123; - v[460][7] = 73; - v[461][7] = 35; - v[462][7] = 141; - v[463][7] = 81; - v[464][7] = 19; - v[465][7] = 171; - v[466][7] = 255; - v[467][7] = 111; - v[468][7] = 107; - v[469][7] = 233; - v[470][7] = 113; - v[471][7] = 133; - v[472][7] = 89; - v[473][7] = 9; - v[474][7] = 231; - v[475][7] = 95; - v[476][7] = 69; - v[477][7] = 33; - v[478][7] = 1; - v[479][7] = 253; - v[480][7] = 219; - v[481][7] = 253; - v[482][7] = 247; - v[483][7] = 129; - v[484][7] = 11; - v[485][7] = 251; - v[486][7] = 221; - v[487][7] = 153; - v[488][7] = 35; - v[489][7] = 103; - v[490][7] = 239; - v[491][7] = 7; - v[492][7] = 27; - v[493][7] = 235; - v[494][7] = 181; - v[495][7] = 5; - v[496][7] = 207; - v[497][7] = 53; - v[498][7] = 149; - v[499][7] = 155; - v[500][7] = 225; - v[501][7] = 165; - v[502][7] = 137; - v[503][7] = 155; - v[504][7] = 201; - v[505][7] = 97; - v[506][7] = 245; - v[507][7] = 203; - v[508][7] = 47; - v[509][7] = 39; - v[510][7] = 35; - v[511][7] = 105; - v[512][7] = 239; - v[513][7] = 49; - v[514][7] = 15; - v[515][7] = 253; - v[516][7] = 7; - v[517][7] = 237; - v[518][7] = 213; - v[519][7] = 55; - v[520][7] = 87; - v[521][7] = 199; - v[522][7] = 27; - v[523][7] = 175; - v[524][7] = 49; - v[525][7] = 41; - v[526][7] = 229; - v[527][7] = 85; - v[528][7] = 3; - v[529][7] = 149; - v[530][7] = 179; - v[531][7] = 129; - v[532][7] = 185; - v[533][7] = 249; - v[534][7] = 197; - v[535][7] = 15; - v[536][7] = 97; - v[537][7] = 197; - v[538][7] = 139; - v[539][7] = 203; - v[540][7] = 63; - v[541][7] = 33; - v[542][7] = 251; - v[543][7] = 217; - v[544][7] = 199; - v[545][7] = 199; - v[546][7] = 99; - v[547][7] = 249; - v[548][7] = 33; - v[549][7] = 229; - v[550][7] = 177; - v[551][7] = 13; - v[552][7] = 209; - v[553][7] = 147; - v[554][7] = 97; - v[555][7] = 31; - v[556][7] = 125; - v[557][7] = 177; - v[558][7] = 137; - v[559][7] = 187; - v[560][7] = 11; - v[561][7] = 91; - v[562][7] = 223; - v[563][7] = 29; - v[564][7] = 169; - v[565][7] = 231; - v[566][7] = 59; - v[567][7] = 31; - v[568][7] = 163; - v[569][7] = 41; - v[570][7] = 57; - v[571][7] = 87; - v[572][7] = 247; - v[573][7] = 25; - v[574][7] = 127; - v[575][7] = 101; - v[576][7] = 207; - v[577][7] = 187; - v[578][7] = 73; - v[579][7] = 61; - v[580][7] = 105; - v[581][7] = 27; - v[582][7] = 91; - v[583][7] = 171; - v[584][7] = 243; - v[585][7] = 33; - v[586][7] = 3; - v[587][7] = 1; - v[588][7] = 21; - v[589][7] = 229; - v[590][7] = 93; - v[591][7] = 71; - v[592][7] = 61; - v[593][7] = 37; - v[594][7] = 183; - v[595][7] = 65; - v[596][7] = 211; - v[597][7] = 53; - v[598][7] = 11; - v[599][7] = 151; - v[600][7] = 165; - v[601][7] = 47; - v[602][7] = 5; - v[603][7] = 129; - v[604][7] = 79; - v[605][7] = 101; - v[606][7] = 147; - v[607][7] = 169; - v[608][7] = 181; - v[609][7] = 19; - v[610][7] = 95; - v[611][7] = 77; - v[612][7] = 139; - v[613][7] = 197; - v[614][7] = 219; - v[615][7] = 97; - v[616][7] = 239; - v[617][7] = 183; - v[618][7] = 143; - v[619][7] = 9; - v[620][7] = 13; - v[621][7] = 209; - v[622][7] = 23; - v[623][7] = 215; - v[624][7] = 53; - v[625][7] = 137; - v[626][7] = 203; - v[627][7] = 19; - v[628][7] = 151; - v[629][7] = 171; - v[630][7] = 133; - v[631][7] = 219; - v[632][7] = 231; - v[633][7] = 3; - v[634][7] = 15; - v[635][7] = 253; - v[636][7] = 225; - v[637][7] = 33; - v[638][7] = 111; - v[639][7] = 183; - v[640][7] = 213; - v[641][7] = 169; - v[642][7] = 119; - v[643][7] = 111; - v[644][7] = 15; - v[645][7] = 201; - v[646][7] = 123; - v[647][7] = 121; - v[648][7] = 225; - v[649][7] = 113; - v[650][7] = 113; - v[651][7] = 225; - v[652][7] = 161; - v[653][7] = 165; - v[654][7] = 1; - v[655][7] = 139; - v[656][7] = 55; - v[657][7] = 3; - v[658][7] = 93; - v[659][7] = 217; - v[660][7] = 193; - v[661][7] = 97; - v[662][7] = 29; - v[663][7] = 69; - v[664][7] = 231; - v[665][7] = 161; - v[666][7] = 93; - v[667][7] = 69; - v[668][7] = 143; - v[669][7] = 137; - v[670][7] = 9; - v[671][7] = 87; - v[672][7] = 183; - v[673][7] = 113; - v[674][7] = 183; - v[675][7] = 73; - v[676][7] = 215; - v[677][7] = 137; - v[678][7] = 89; - v[679][7] = 251; - v[680][7] = 163; - v[681][7] = 41; - v[682][7] = 227; - v[683][7] = 145; - v[684][7] = 57; - v[685][7] = 81; - v[686][7] = 57; - v[687][7] = 11; - v[688][7] = 135; - v[689][7] = 145; - v[690][7] = 161; - v[691][7] = 175; - v[692][7] = 159; - v[693][7] = 25; - v[694][7] = 55; - v[695][7] = 167; - v[696][7] = 157; - v[697][7] = 211; - v[698][7] = 97; - v[699][7] = 247; - v[700][7] = 249; - v[701][7] = 23; - v[702][7] = 129; - v[703][7] = 159; - v[704][7] = 71; - v[705][7] = 197; - v[706][7] = 127; - v[707][7] = 141; - v[708][7] = 219; - v[709][7] = 5; - v[710][7] = 233; - v[711][7] = 131; - v[712][7] = 217; - v[713][7] = 101; - v[714][7] = 131; - v[715][7] = 33; - v[716][7] = 157; - v[717][7] = 173; - v[718][7] = 69; - v[719][7] = 207; - v[720][7] = 239; - v[721][7] = 81; - v[722][7] = 205; - v[723][7] = 11; - v[724][7] = 41; - v[725][7] = 169; - v[726][7] = 65; - v[727][7] = 193; - v[728][7] = 77; - v[729][7] = 201; - v[730][7] = 173; - v[731][7] = 1; - v[732][7] = 221; - v[733][7] = 157; - v[734][7] = 1; - v[735][7] = 15; - v[736][7] = 113; - v[737][7] = 147; - v[738][7] = 137; - v[739][7] = 205; - v[740][7] = 225; - v[741][7] = 73; - v[742][7] = 45; - v[743][7] = 49; - v[744][7] = 149; - v[745][7] = 113; - v[746][7] = 253; - v[747][7] = 99; - v[748][7] = 17; - v[749][7] = 119; - v[750][7] = 105; - v[751][7] = 117; - v[752][7] = 129; - v[753][7] = 243; - v[754][7] = 75; - v[755][7] = 203; - v[756][7] = 53; - v[757][7] = 29; - v[758][7] = 247; - v[759][7] = 35; - v[760][7] = 247; - v[761][7] = 171; - v[762][7] = 31; - v[763][7] = 199; - v[764][7] = 213; - v[765][7] = 29; - v[766][7] = 251; - v[767][7] = 7; - v[768][7] = 251; - v[769][7] = 187; - v[770][7] = 91; - v[771][7] = 11; - v[772][7] = 149; - v[773][7] = 13; - v[774][7] = 205; - v[775][7] = 37; - v[776][7] = 249; - v[777][7] = 137; - v[778][7] = 139; - v[779][7] = 9; - v[780][7] = 7; - v[781][7] = 113; - v[782][7] = 183; - v[783][7] = 205; - v[784][7] = 187; - v[785][7] = 39; - v[786][7] = 3; - v[787][7] = 79; - v[788][7] = 155; - v[789][7] = 227; - v[790][7] = 89; - v[791][7] = 185; - v[792][7] = 51; - v[793][7] = 127; - v[794][7] = 63; - v[795][7] = 83; - v[796][7] = 41; - v[797][7] = 133; - v[798][7] = 183; - v[799][7] = 181; - v[800][7] = 127; - v[801][7] = 19; - v[802][7] = 255; - v[803][7] = 219; - v[804][7] = 59; - v[805][7] = 251; - v[806][7] = 3; - v[807][7] = 187; - v[808][7] = 57; - v[809][7] = 217; - v[810][7] = 115; - v[811][7] = 217; - v[812][7] = 229; - v[813][7] = 181; - v[814][7] = 185; - v[815][7] = 149; - v[816][7] = 83; - v[817][7] = 115; - v[818][7] = 11; - v[819][7] = 123; - v[820][7] = 19; - v[821][7] = 109; - v[822][7] = 165; - v[823][7] = 103; - v[824][7] = 123; - v[825][7] = 219; - v[826][7] = 129; - v[827][7] = 155; - v[828][7] = 207; - v[829][7] = 177; - v[830][7] = 9; - v[831][7] = 49; - v[832][7] = 181; - v[833][7] = 231; - v[834][7] = 33; - v[835][7] = 233; - v[836][7] = 67; - v[837][7] = 155; - v[838][7] = 41; - v[839][7] = 9; - v[840][7] = 95; - v[841][7] = 123; - v[842][7] = 65; - v[843][7] = 117; - v[844][7] = 249; - v[845][7] = 85; - v[846][7] = 169; - v[847][7] = 129; - v[848][7] = 241; - v[849][7] = 173; - v[850][7] = 251; - v[851][7] = 225; - v[852][7] = 147; - v[853][7] = 165; - v[854][7] = 69; - v[855][7] = 81; - v[856][7] = 239; - v[857][7] = 95; - v[858][7] = 23; - v[859][7] = 83; - v[860][7] = 227; - v[861][7] = 249; - v[862][7] = 143; - v[863][7] = 171; - v[864][7] = 193; - v[865][7] = 9; - v[866][7] = 21; - v[867][7] = 57; - v[868][7] = 73; - v[869][7] = 97; - v[870][7] = 57; - v[871][7] = 29; - v[872][7] = 239; - v[873][7] = 151; - v[874][7] = 159; - v[875][7] = 191; - v[876][7] = 47; - v[877][7] = 51; - v[878][7] = 1; - v[879][7] = 223; - v[880][7] = 251; - v[881][7] = 251; - v[882][7] = 151; - v[883][7] = 41; - v[884][7] = 119; - v[885][7] = 127; - v[886][7] = 131; - v[887][7] = 33; - v[888][7] = 209; - v[889][7] = 123; - v[890][7] = 53; - v[891][7] = 241; - v[892][7] = 25; - v[893][7] = 31; - v[894][7] = 183; - v[895][7] = 107; - v[896][7] = 25; - v[897][7] = 115; - v[898][7] = 39; - v[899][7] = 11; - v[900][7] = 213; - v[901][7] = 239; - v[902][7] = 219; - v[903][7] = 109; - v[904][7] = 185; - v[905][7] = 35; - v[906][7] = 133; - v[907][7] = 123; - v[908][7] = 185; - v[909][7] = 27; - v[910][7] = 55; - v[911][7] = 245; - v[912][7] = 61; - v[913][7] = 75; - v[914][7] = 205; - v[915][7] = 213; - v[916][7] = 169; - v[917][7] = 163; - v[918][7] = 63; - v[919][7] = 55; - v[920][7] = 49; - v[921][7] = 83; - v[922][7] = 195; - v[923][7] = 51; - v[924][7] = 31; - v[925][7] = 41; - v[926][7] = 15; - v[927][7] = 203; - v[928][7] = 41; - v[929][7] = 63; - v[930][7] = 127; - v[931][7] = 161; - v[932][7] = 5; - v[933][7] = 143; - v[934][7] = 7; - v[935][7] = 199; - v[936][7] = 251; - v[937][7] = 95; - v[938][7] = 75; - v[939][7] = 101; - v[940][7] = 15; - v[941][7] = 43; - v[942][7] = 237; - v[943][7] = 197; - v[944][7] = 117; - v[945][7] = 167; - v[946][7] = 155; - v[947][7] = 21; - v[948][7] = 83; - v[949][7] = 205; - v[950][7] = 255; - v[951][7] = 49; - v[952][7] = 101; - v[953][7] = 213; - v[954][7] = 237; - v[955][7] = 135; - v[956][7] = 135; - v[957][7] = 21; - v[958][7] = 73; - v[959][7] = 93; - v[960][7] = 115; - v[961][7] = 7; - v[962][7] = 85; - v[963][7] = 223; - v[964][7] = 237; - v[965][7] = 79; - v[966][7] = 89; - v[967][7] = 5; - v[968][7] = 57; - v[969][7] = 239; - v[970][7] = 67; - v[971][7] = 65; - v[972][7] = 201; - v[973][7] = 155; - v[974][7] = 71; - v[975][7] = 85; - v[976][7] = 195; - v[977][7] = 89; - v[978][7] = 181; - v[979][7] = 119; - v[980][7] = 135; - v[981][7] = 147; - v[982][7] = 237; - v[983][7] = 173; - v[984][7] = 41; - v[985][7] = 155; - v[986][7] = 67; - v[987][7] = 113; - v[988][7] = 111; - v[989][7] = 21; - v[990][7] = 183; - v[991][7] = 23; - v[992][7] = 103; - v[993][7] = 207; - v[994][7] = 253; - v[995][7] = 69; - v[996][7] = 219; - v[997][7] = 205; - v[998][7] = 195; - v[999][7] = 43; - v[1000][7] = 197; - v[1001][7] = 229; - v[1002][7] = 139; - v[1003][7] = 177; - v[1004][7] = 129; - v[1005][7] = 69; - v[1006][7] = 97; - v[1007][7] = 201; - v[1008][7] = 163; - v[1009][7] = 189; - v[1010][7] = 11; - v[1011][7] = 99; - v[1012][7] = 91; - v[1013][7] = 253; - v[1014][7] = 239; - v[1015][7] = 91; - v[1016][7] = 145; - v[1017][7] = 19; - v[1018][7] = 179; - v[1019][7] = 231; - v[1020][7] = 121; - v[1021][7] = 7; - v[1022][7] = 225; - v[1023][7] = 237; - v[1024][7] = 125; - v[1025][7] = 191; - v[1026][7] = 119; - v[1027][7] = 59; - v[1028][7] = 175; - v[1029][7] = 237; - v[1030][7] = 131; - v[1031][7] = 79; - v[1032][7] = 43; - v[1033][7] = 45; - v[1034][7] = 205; - v[1035][7] = 199; - v[1036][7] = 251; - v[1037][7] = 153; - v[1038][7] = 207; - v[1039][7] = 37; - v[1040][7] = 179; - v[1041][7] = 113; - v[1042][7] = 255; - v[1043][7] = 107; - v[1044][7] = 217; - v[1045][7] = 61; - v[1046][7] = 7; - v[1047][7] = 181; - v[1048][7] = 247; - v[1049][7] = 31; - v[1050][7] = 13; - v[1051][7] = 113; - v[1052][7] = 145; - v[1053][7] = 107; - v[1054][7] = 233; - v[1055][7] = 233; - v[1056][7] = 43; - v[1057][7] = 79; - v[1058][7] = 23; - v[1059][7] = 169; - v[1060][7] = 137; - v[1061][7] = 129; - v[1062][7] = 183; - v[1063][7] = 53; - v[1064][7] = 91; - v[1065][7] = 55; - v[1066][7] = 103; - v[1067][7] = 223; - v[1068][7] = 87; - v[1069][7] = 177; - v[1070][7] = 157; - v[1071][7] = 79; - v[1072][7] = 213; - v[1073][7] = 139; - v[1074][7] = 183; - v[1075][7] = 231; - v[1076][7] = 205; - v[1077][7] = 143; - v[1078][7] = 129; - v[1079][7] = 243; - v[1080][7] = 205; - v[1081][7] = 93; - v[1082][7] = 59; - v[1083][7] = 15; - v[1084][7] = 89; - v[1085][7] = 9; - v[1086][7] = 11; - v[1087][7] = 47; - v[1088][7] = 133; - v[1089][7] = 227; - v[1090][7] = 75; - v[1091][7] = 9; - v[1092][7] = 91; - v[1093][7] = 19; - v[1094][7] = 171; - v[1095][7] = 163; - v[1096][7] = 79; - v[1097][7] = 7; - v[1098][7] = 103; - v[1099][7] = 5; - v[1100][7] = 119; - v[1101][7] = 155; - v[1102][7] = 75; - v[1103][7] = 11; - v[1104][7] = 71; - v[1105][7] = 95; - v[1106][7] = 17; - v[1107][7] = 13; - v[1108][7] = 243; - v[1109][7] = 207; - v[1110][7] = 187; - - v[53][8] = 235; - v[54][8] = 307; - v[55][8] = 495; - v[56][8] = 417; - v[57][8] = 57; - v[58][8] = 151; - v[59][8] = 19; - v[60][8] = 119; - v[61][8] = 375; - v[62][8] = 451; - v[63][8] = 55; - v[64][8] = 449; - v[65][8] = 501; - v[66][8] = 53; - v[67][8] = 185; - v[68][8] = 317; - v[69][8] = 17; - v[70][8] = 21; - v[71][8] = 487; - v[72][8] = 13; - v[73][8] = 347; - v[74][8] = 393; - v[75][8] = 15; - v[76][8] = 391; - v[77][8] = 307; - v[78][8] = 189; - v[79][8] = 381; - v[80][8] = 71; - v[81][8] = 163; - v[82][8] = 99; - v[83][8] = 467; - v[84][8] = 167; - v[85][8] = 433; - v[86][8] = 337; - v[87][8] = 257; - v[88][8] = 179; - v[89][8] = 47; - v[90][8] = 385; - v[91][8] = 23; - v[92][8] = 117; - v[93][8] = 369; - v[94][8] = 425; - v[95][8] = 207; - v[96][8] = 433; - v[97][8] = 301; - v[98][8] = 147; - v[99][8] = 333; - v[100][8] = 85; - v[101][8] = 221; - v[102][8] = 423; - v[103][8] = 49; - v[104][8] = 3; - v[105][8] = 43; - v[106][8] = 229; - v[107][8] = 227; - v[108][8] = 201; - v[109][8] = 383; - v[110][8] = 281; - v[111][8] = 229; - v[112][8] = 207; - v[113][8] = 21; - v[114][8] = 343; - v[115][8] = 251; - v[116][8] = 397; - v[117][8] = 173; - v[118][8] = 507; - v[119][8] = 421; - v[120][8] = 443; - v[121][8] = 399; - v[122][8] = 53; - v[123][8] = 345; - v[124][8] = 77; - v[125][8] = 385; - v[126][8] = 317; - v[127][8] = 155; - v[128][8] = 187; - v[129][8] = 269; - v[130][8] = 501; - v[131][8] = 19; - v[132][8] = 169; - v[133][8] = 235; - v[134][8] = 415; - v[135][8] = 61; - v[136][8] = 247; - v[137][8] = 183; - v[138][8] = 5; - v[139][8] = 257; - v[140][8] = 401; - v[141][8] = 451; - v[142][8] = 95; - v[143][8] = 455; - v[144][8] = 49; - v[145][8] = 489; - v[146][8] = 75; - v[147][8] = 459; - v[148][8] = 377; - v[149][8] = 87; - v[150][8] = 463; - v[151][8] = 155; - v[152][8] = 233; - v[153][8] = 115; - v[154][8] = 429; - v[155][8] = 211; - v[156][8] = 419; - v[157][8] = 143; - v[158][8] = 487; - v[159][8] = 195; - v[160][8] = 209; - v[161][8] = 461; - v[162][8] = 193; - v[163][8] = 157; - v[164][8] = 193; - v[165][8] = 363; - v[166][8] = 181; - v[167][8] = 271; - v[168][8] = 445; - v[169][8] = 381; - v[170][8] = 231; - v[171][8] = 135; - v[172][8] = 327; - v[173][8] = 403; - v[174][8] = 171; - v[175][8] = 197; - v[176][8] = 181; - v[177][8] = 343; - v[178][8] = 113; - v[179][8] = 313; - v[180][8] = 393; - v[181][8] = 311; - v[182][8] = 415; - v[183][8] = 267; - v[184][8] = 247; - v[185][8] = 425; - v[186][8] = 233; - v[187][8] = 289; - v[188][8] = 55; - v[189][8] = 39; - v[190][8] = 247; - v[191][8] = 327; - v[192][8] = 141; - v[193][8] = 5; - v[194][8] = 189; - v[195][8] = 183; - v[196][8] = 27; - v[197][8] = 337; - v[198][8] = 341; - v[199][8] = 327; - v[200][8] = 87; - v[201][8] = 429; - v[202][8] = 357; - v[203][8] = 265; - v[204][8] = 251; - v[205][8] = 437; - v[206][8] = 201; - v[207][8] = 29; - v[208][8] = 339; - v[209][8] = 257; - v[210][8] = 377; - v[211][8] = 17; - v[212][8] = 53; - v[213][8] = 327; - v[214][8] = 47; - v[215][8] = 375; - v[216][8] = 393; - v[217][8] = 369; - v[218][8] = 403; - v[219][8] = 125; - v[220][8] = 429; - v[221][8] = 257; - v[222][8] = 157; - v[223][8] = 217; - v[224][8] = 85; - v[225][8] = 267; - v[226][8] = 117; - v[227][8] = 337; - v[228][8] = 447; - v[229][8] = 219; - v[230][8] = 501; - v[231][8] = 41; - v[232][8] = 41; - v[233][8] = 193; - v[234][8] = 509; - v[235][8] = 131; - v[236][8] = 207; - v[237][8] = 505; - v[238][8] = 421; - v[239][8] = 149; - v[240][8] = 111; - v[241][8] = 177; - v[242][8] = 167; - v[243][8] = 223; - v[244][8] = 291; - v[245][8] = 91; - v[246][8] = 29; - v[247][8] = 305; - v[248][8] = 151; - v[249][8] = 177; - v[250][8] = 337; - v[251][8] = 183; - v[252][8] = 361; - v[253][8] = 435; - v[254][8] = 307; - v[255][8] = 507; - v[256][8] = 77; - v[257][8] = 181; - v[258][8] = 507; - v[259][8] = 315; - v[260][8] = 145; - v[261][8] = 423; - v[262][8] = 71; - v[263][8] = 103; - v[264][8] = 493; - v[265][8] = 271; - v[266][8] = 469; - v[267][8] = 339; - v[268][8] = 237; - v[269][8] = 437; - v[270][8] = 483; - v[271][8] = 31; - v[272][8] = 219; - v[273][8] = 61; - v[274][8] = 131; - v[275][8] = 391; - v[276][8] = 233; - v[277][8] = 219; - v[278][8] = 69; - v[279][8] = 57; - v[280][8] = 459; - v[281][8] = 225; - v[282][8] = 421; - v[283][8] = 7; - v[284][8] = 461; - v[285][8] = 111; - v[286][8] = 451; - v[287][8] = 277; - v[288][8] = 185; - v[289][8] = 193; - v[290][8] = 125; - v[291][8] = 251; - v[292][8] = 199; - v[293][8] = 73; - v[294][8] = 71; - v[295][8] = 7; - v[296][8] = 409; - v[297][8] = 417; - v[298][8] = 149; - v[299][8] = 193; - v[300][8] = 53; - v[301][8] = 437; - v[302][8] = 29; - v[303][8] = 467; - v[304][8] = 229; - v[305][8] = 31; - v[306][8] = 35; - v[307][8] = 75; - v[308][8] = 105; - v[309][8] = 503; - v[310][8] = 75; - v[311][8] = 317; - v[312][8] = 401; - v[313][8] = 367; - v[314][8] = 131; - v[315][8] = 365; - v[316][8] = 441; - v[317][8] = 433; - v[318][8] = 93; - v[319][8] = 377; - v[320][8] = 405; - v[321][8] = 465; - v[322][8] = 259; - v[323][8] = 283; - v[324][8] = 443; - v[325][8] = 143; - v[326][8] = 445; - v[327][8] = 3; - v[328][8] = 461; - v[329][8] = 329; - v[330][8] = 309; - v[331][8] = 77; - v[332][8] = 323; - v[333][8] = 155; - v[334][8] = 347; - v[335][8] = 45; - v[336][8] = 381; - v[337][8] = 315; - v[338][8] = 463; - v[339][8] = 207; - v[340][8] = 321; - v[341][8] = 157; - v[342][8] = 109; - v[343][8] = 479; - v[344][8] = 313; - v[345][8] = 345; - v[346][8] = 167; - v[347][8] = 439; - v[348][8] = 307; - v[349][8] = 235; - v[350][8] = 473; - v[351][8] = 79; - v[352][8] = 101; - v[353][8] = 245; - v[354][8] = 19; - v[355][8] = 381; - v[356][8] = 251; - v[357][8] = 35; - v[358][8] = 25; - v[359][8] = 107; - v[360][8] = 187; - v[361][8] = 115; - v[362][8] = 113; - v[363][8] = 321; - v[364][8] = 115; - v[365][8] = 445; - v[366][8] = 61; - v[367][8] = 77; - v[368][8] = 293; - v[369][8] = 405; - v[370][8] = 13; - v[371][8] = 53; - v[372][8] = 17; - v[373][8] = 171; - v[374][8] = 299; - v[375][8] = 41; - v[376][8] = 79; - v[377][8] = 3; - v[378][8] = 485; - v[379][8] = 331; - v[380][8] = 13; - v[381][8] = 257; - v[382][8] = 59; - v[383][8] = 201; - v[384][8] = 497; - v[385][8] = 81; - v[386][8] = 451; - v[387][8] = 199; - v[388][8] = 171; - v[389][8] = 81; - v[390][8] = 253; - v[391][8] = 365; - v[392][8] = 75; - v[393][8] = 451; - v[394][8] = 149; - v[395][8] = 483; - v[396][8] = 81; - v[397][8] = 453; - v[398][8] = 469; - v[399][8] = 485; - v[400][8] = 305; - v[401][8] = 163; - v[402][8] = 401; - v[403][8] = 15; - v[404][8] = 91; - v[405][8] = 3; - v[406][8] = 129; - v[407][8] = 35; - v[408][8] = 239; - v[409][8] = 355; - v[410][8] = 211; - v[411][8] = 387; - v[412][8] = 101; - v[413][8] = 299; - v[414][8] = 67; - v[415][8] = 375; - v[416][8] = 405; - v[417][8] = 357; - v[418][8] = 267; - v[419][8] = 363; - v[420][8] = 79; - v[421][8] = 83; - v[422][8] = 437; - v[423][8] = 457; - v[424][8] = 39; - v[425][8] = 97; - v[426][8] = 473; - v[427][8] = 289; - v[428][8] = 179; - v[429][8] = 57; - v[430][8] = 23; - v[431][8] = 49; - v[432][8] = 79; - v[433][8] = 71; - v[434][8] = 341; - v[435][8] = 287; - v[436][8] = 95; - v[437][8] = 229; - v[438][8] = 271; - v[439][8] = 475; - v[440][8] = 49; - v[441][8] = 241; - v[442][8] = 261; - v[443][8] = 495; - v[444][8] = 353; - v[445][8] = 381; - v[446][8] = 13; - v[447][8] = 291; - v[448][8] = 37; - v[449][8] = 251; - v[450][8] = 105; - v[451][8] = 399; - v[452][8] = 81; - v[453][8] = 89; - v[454][8] = 265; - v[455][8] = 507; - v[456][8] = 205; - v[457][8] = 145; - v[458][8] = 331; - v[459][8] = 129; - v[460][8] = 119; - v[461][8] = 503; - v[462][8] = 249; - v[463][8] = 1; - v[464][8] = 289; - v[465][8] = 463; - v[466][8] = 163; - v[467][8] = 443; - v[468][8] = 63; - v[469][8] = 123; - v[470][8] = 361; - v[471][8] = 261; - v[472][8] = 49; - v[473][8] = 429; - v[474][8] = 137; - v[475][8] = 355; - v[476][8] = 175; - v[477][8] = 507; - v[478][8] = 59; - v[479][8] = 277; - v[480][8] = 391; - v[481][8] = 25; - v[482][8] = 185; - v[483][8] = 381; - v[484][8] = 197; - v[485][8] = 39; - v[486][8] = 5; - v[487][8] = 429; - v[488][8] = 119; - v[489][8] = 247; - v[490][8] = 177; - v[491][8] = 329; - v[492][8] = 465; - v[493][8] = 421; - v[494][8] = 271; - v[495][8] = 467; - v[496][8] = 151; - v[497][8] = 45; - v[498][8] = 429; - v[499][8] = 137; - v[500][8] = 471; - v[501][8] = 11; - v[502][8] = 17; - v[503][8] = 409; - v[504][8] = 347; - v[505][8] = 199; - v[506][8] = 463; - v[507][8] = 177; - v[508][8] = 11; - v[509][8] = 51; - v[510][8] = 361; - v[511][8] = 95; - v[512][8] = 497; - v[513][8] = 163; - v[514][8] = 351; - v[515][8] = 127; - v[516][8] = 395; - v[517][8] = 511; - v[518][8] = 327; - v[519][8] = 353; - v[520][8] = 49; - v[521][8] = 105; - v[522][8] = 151; - v[523][8] = 321; - v[524][8] = 331; - v[525][8] = 329; - v[526][8] = 509; - v[527][8] = 107; - v[528][8] = 109; - v[529][8] = 303; - v[530][8] = 467; - v[531][8] = 287; - v[532][8] = 161; - v[533][8] = 45; - v[534][8] = 385; - v[535][8] = 289; - v[536][8] = 363; - v[537][8] = 331; - v[538][8] = 265; - v[539][8] = 407; - v[540][8] = 37; - v[541][8] = 433; - v[542][8] = 315; - v[543][8] = 343; - v[544][8] = 63; - v[545][8] = 51; - v[546][8] = 185; - v[547][8] = 71; - v[548][8] = 27; - v[549][8] = 267; - v[550][8] = 503; - v[551][8] = 239; - v[552][8] = 293; - v[553][8] = 245; - v[554][8] = 281; - v[555][8] = 297; - v[556][8] = 75; - v[557][8] = 461; - v[558][8] = 371; - v[559][8] = 129; - v[560][8] = 189; - v[561][8] = 189; - v[562][8] = 339; - v[563][8] = 287; - v[564][8] = 111; - v[565][8] = 111; - v[566][8] = 379; - v[567][8] = 93; - v[568][8] = 27; - v[569][8] = 185; - v[570][8] = 347; - v[571][8] = 337; - v[572][8] = 247; - v[573][8] = 507; - v[574][8] = 161; - v[575][8] = 231; - v[576][8] = 43; - v[577][8] = 499; - v[578][8] = 73; - v[579][8] = 327; - v[580][8] = 263; - v[581][8] = 331; - v[582][8] = 249; - v[583][8] = 493; - v[584][8] = 37; - v[585][8] = 25; - v[586][8] = 115; - v[587][8] = 3; - v[588][8] = 167; - v[589][8] = 197; - v[590][8] = 127; - v[591][8] = 357; - v[592][8] = 497; - v[593][8] = 103; - v[594][8] = 125; - v[595][8] = 191; - v[596][8] = 165; - v[597][8] = 55; - v[598][8] = 101; - v[599][8] = 95; - v[600][8] = 79; - v[601][8] = 351; - v[602][8] = 341; - v[603][8] = 43; - v[604][8] = 125; - v[605][8] = 135; - v[606][8] = 173; - v[607][8] = 289; - v[608][8] = 373; - v[609][8] = 133; - v[610][8] = 421; - v[611][8] = 241; - v[612][8] = 281; - v[613][8] = 213; - v[614][8] = 177; - v[615][8] = 363; - v[616][8] = 151; - v[617][8] = 227; - v[618][8] = 145; - v[619][8] = 363; - v[620][8] = 239; - v[621][8] = 431; - v[622][8] = 81; - v[623][8] = 397; - v[624][8] = 241; - v[625][8] = 67; - v[626][8] = 291; - v[627][8] = 255; - v[628][8] = 405; - v[629][8] = 421; - v[630][8] = 399; - v[631][8] = 75; - v[632][8] = 399; - v[633][8] = 105; - v[634][8] = 329; - v[635][8] = 41; - v[636][8] = 425; - v[637][8] = 7; - v[638][8] = 283; - v[639][8] = 375; - v[640][8] = 475; - v[641][8] = 427; - v[642][8] = 277; - v[643][8] = 209; - v[644][8] = 411; - v[645][8] = 3; - v[646][8] = 137; - v[647][8] = 195; - v[648][8] = 289; - v[649][8] = 509; - v[650][8] = 121; - v[651][8] = 55; - v[652][8] = 147; - v[653][8] = 275; - v[654][8] = 251; - v[655][8] = 19; - v[656][8] = 129; - v[657][8] = 285; - v[658][8] = 415; - v[659][8] = 487; - v[660][8] = 491; - v[661][8] = 193; - v[662][8] = 219; - v[663][8] = 403; - v[664][8] = 23; - v[665][8] = 97; - v[666][8] = 65; - v[667][8] = 285; - v[668][8] = 75; - v[669][8] = 21; - v[670][8] = 373; - v[671][8] = 261; - v[672][8] = 339; - v[673][8] = 239; - v[674][8] = 495; - v[675][8] = 415; - v[676][8] = 333; - v[677][8] = 107; - v[678][8] = 435; - v[679][8] = 297; - v[680][8] = 213; - v[681][8] = 149; - v[682][8] = 463; - v[683][8] = 199; - v[684][8] = 323; - v[685][8] = 45; - v[686][8] = 19; - v[687][8] = 301; - v[688][8] = 121; - v[689][8] = 499; - v[690][8] = 187; - v[691][8] = 229; - v[692][8] = 63; - v[693][8] = 425; - v[694][8] = 99; - v[695][8] = 281; - v[696][8] = 35; - v[697][8] = 125; - v[698][8] = 349; - v[699][8] = 87; - v[700][8] = 101; - v[701][8] = 59; - v[702][8] = 195; - v[703][8] = 511; - v[704][8] = 355; - v[705][8] = 73; - v[706][8] = 263; - v[707][8] = 243; - v[708][8] = 101; - v[709][8] = 165; - v[710][8] = 141; - v[711][8] = 11; - v[712][8] = 389; - v[713][8] = 219; - v[714][8] = 187; - v[715][8] = 449; - v[716][8] = 447; - v[717][8] = 393; - v[718][8] = 477; - v[719][8] = 305; - v[720][8] = 221; - v[721][8] = 51; - v[722][8] = 355; - v[723][8] = 209; - v[724][8] = 499; - v[725][8] = 479; - v[726][8] = 265; - v[727][8] = 377; - v[728][8] = 145; - v[729][8] = 411; - v[730][8] = 173; - v[731][8] = 11; - v[732][8] = 433; - v[733][8] = 483; - v[734][8] = 135; - v[735][8] = 385; - v[736][8] = 341; - v[737][8] = 89; - v[738][8] = 209; - v[739][8] = 391; - v[740][8] = 33; - v[741][8] = 395; - v[742][8] = 319; - v[743][8] = 451; - v[744][8] = 119; - v[745][8] = 341; - v[746][8] = 227; - v[747][8] = 375; - v[748][8] = 61; - v[749][8] = 331; - v[750][8] = 493; - v[751][8] = 411; - v[752][8] = 293; - v[753][8] = 47; - v[754][8] = 203; - v[755][8] = 375; - v[756][8] = 167; - v[757][8] = 395; - v[758][8] = 155; - v[759][8] = 5; - v[760][8] = 237; - v[761][8] = 361; - v[762][8] = 489; - v[763][8] = 127; - v[764][8] = 21; - v[765][8] = 345; - v[766][8] = 101; - v[767][8] = 371; - v[768][8] = 233; - v[769][8] = 431; - v[770][8] = 109; - v[771][8] = 119; - v[772][8] = 277; - v[773][8] = 125; - v[774][8] = 263; - v[775][8] = 73; - v[776][8] = 135; - v[777][8] = 123; - v[778][8] = 83; - v[779][8] = 123; - v[780][8] = 405; - v[781][8] = 69; - v[782][8] = 75; - v[783][8] = 287; - v[784][8] = 401; - v[785][8] = 23; - v[786][8] = 283; - v[787][8] = 393; - v[788][8] = 41; - v[789][8] = 379; - v[790][8] = 431; - v[791][8] = 11; - v[792][8] = 475; - v[793][8] = 505; - v[794][8] = 19; - v[795][8] = 365; - v[796][8] = 265; - v[797][8] = 271; - v[798][8] = 499; - v[799][8] = 489; - v[800][8] = 443; - v[801][8] = 165; - v[802][8] = 91; - v[803][8] = 83; - v[804][8] = 291; - v[805][8] = 319; - v[806][8] = 199; - v[807][8] = 107; - v[808][8] = 245; - v[809][8] = 389; - v[810][8] = 143; - v[811][8] = 137; - v[812][8] = 89; - v[813][8] = 125; - v[814][8] = 281; - v[815][8] = 381; - v[816][8] = 215; - v[817][8] = 131; - v[818][8] = 299; - v[819][8] = 249; - v[820][8] = 375; - v[821][8] = 455; - v[822][8] = 43; - v[823][8] = 73; - v[824][8] = 281; - v[825][8] = 217; - v[826][8] = 297; - v[827][8] = 229; - v[828][8] = 431; - v[829][8] = 357; - v[830][8] = 81; - v[831][8] = 357; - v[832][8] = 171; - v[833][8] = 451; - v[834][8] = 481; - v[835][8] = 13; - v[836][8] = 387; - v[837][8] = 491; - v[838][8] = 489; - v[839][8] = 439; - v[840][8] = 385; - v[841][8] = 487; - v[842][8] = 177; - v[843][8] = 393; - v[844][8] = 33; - v[845][8] = 71; - v[846][8] = 375; - v[847][8] = 443; - v[848][8] = 129; - v[849][8] = 407; - v[850][8] = 395; - v[851][8] = 127; - v[852][8] = 65; - v[853][8] = 333; - v[854][8] = 309; - v[855][8] = 119; - v[856][8] = 197; - v[857][8] = 435; - v[858][8] = 497; - v[859][8] = 373; - v[860][8] = 71; - v[861][8] = 379; - v[862][8] = 509; - v[863][8] = 387; - v[864][8] = 159; - v[865][8] = 265; - v[866][8] = 477; - v[867][8] = 463; - v[868][8] = 449; - v[869][8] = 47; - v[870][8] = 353; - v[871][8] = 249; - v[872][8] = 335; - v[873][8] = 505; - v[874][8] = 89; - v[875][8] = 141; - v[876][8] = 55; - v[877][8] = 235; - v[878][8] = 187; - v[879][8] = 87; - v[880][8] = 363; - v[881][8] = 93; - v[882][8] = 363; - v[883][8] = 101; - v[884][8] = 67; - v[885][8] = 215; - v[886][8] = 321; - v[887][8] = 331; - v[888][8] = 305; - v[889][8] = 261; - v[890][8] = 411; - v[891][8] = 491; - v[892][8] = 479; - v[893][8] = 65; - v[894][8] = 307; - v[895][8] = 469; - v[896][8] = 415; - v[897][8] = 131; - v[898][8] = 315; - v[899][8] = 487; - v[900][8] = 83; - v[901][8] = 455; - v[902][8] = 19; - v[903][8] = 113; - v[904][8] = 163; - v[905][8] = 503; - v[906][8] = 99; - v[907][8] = 499; - v[908][8] = 251; - v[909][8] = 239; - v[910][8] = 81; - v[911][8] = 167; - v[912][8] = 391; - v[913][8] = 255; - v[914][8] = 317; - v[915][8] = 363; - v[916][8] = 359; - v[917][8] = 395; - v[918][8] = 419; - v[919][8] = 307; - v[920][8] = 251; - v[921][8] = 267; - v[922][8] = 171; - v[923][8] = 461; - v[924][8] = 183; - v[925][8] = 465; - v[926][8] = 165; - v[927][8] = 163; - v[928][8] = 293; - v[929][8] = 477; - v[930][8] = 223; - v[931][8] = 403; - v[932][8] = 389; - v[933][8] = 97; - v[934][8] = 335; - v[935][8] = 357; - v[936][8] = 297; - v[937][8] = 19; - v[938][8] = 469; - v[939][8] = 501; - v[940][8] = 249; - v[941][8] = 85; - v[942][8] = 213; - v[943][8] = 311; - v[944][8] = 265; - v[945][8] = 379; - v[946][8] = 297; - v[947][8] = 283; - v[948][8] = 393; - v[949][8] = 449; - v[950][8] = 463; - v[951][8] = 289; - v[952][8] = 159; - v[953][8] = 289; - v[954][8] = 499; - v[955][8] = 407; - v[956][8] = 129; - v[957][8] = 137; - v[958][8] = 221; - v[959][8] = 43; - v[960][8] = 89; - v[961][8] = 403; - v[962][8] = 271; - v[963][8] = 75; - v[964][8] = 83; - v[965][8] = 445; - v[966][8] = 453; - v[967][8] = 389; - v[968][8] = 149; - v[969][8] = 143; - v[970][8] = 423; - v[971][8] = 499; - v[972][8] = 317; - v[973][8] = 445; - v[974][8] = 157; - v[975][8] = 137; - v[976][8] = 453; - v[977][8] = 163; - v[978][8] = 87; - v[979][8] = 23; - v[980][8] = 391; - v[981][8] = 119; - v[982][8] = 427; - v[983][8] = 323; - v[984][8] = 173; - v[985][8] = 89; - v[986][8] = 259; - v[987][8] = 377; - v[988][8] = 511; - v[989][8] = 249; - v[990][8] = 31; - v[991][8] = 363; - v[992][8] = 229; - v[993][8] = 353; - v[994][8] = 329; - v[995][8] = 493; - v[996][8] = 427; - v[997][8] = 57; - v[998][8] = 205; - v[999][8] = 389; - v[1000][8] = 91; - v[1001][8] = 83; - v[1002][8] = 13; - v[1003][8] = 219; - v[1004][8] = 439; - v[1005][8] = 45; - v[1006][8] = 35; - v[1007][8] = 371; - v[1008][8] = 441; - v[1009][8] = 17; - v[1010][8] = 267; - v[1011][8] = 501; - v[1012][8] = 53; - v[1013][8] = 25; - v[1014][8] = 333; - v[1015][8] = 17; - v[1016][8] = 201; - v[1017][8] = 475; - v[1018][8] = 257; - v[1019][8] = 417; - v[1020][8] = 345; - v[1021][8] = 381; - v[1022][8] = 377; - v[1023][8] = 55; - v[1024][8] = 403; - v[1025][8] = 77; - v[1026][8] = 389; - v[1027][8] = 347; - v[1028][8] = 363; - v[1029][8] = 211; - v[1030][8] = 413; - v[1031][8] = 419; - v[1032][8] = 5; - v[1033][8] = 167; - v[1034][8] = 219; - v[1035][8] = 201; - v[1036][8] = 285; - v[1037][8] = 425; - v[1038][8] = 11; - v[1039][8] = 77; - v[1040][8] = 269; - v[1041][8] = 489; - v[1042][8] = 281; - v[1043][8] = 403; - v[1044][8] = 79; - v[1045][8] = 425; - v[1046][8] = 125; - v[1047][8] = 81; - v[1048][8] = 331; - v[1049][8] = 437; - v[1050][8] = 271; - v[1051][8] = 397; - v[1052][8] = 299; - v[1053][8] = 475; - v[1054][8] = 271; - v[1055][8] = 249; - v[1056][8] = 413; - v[1057][8] = 233; - v[1058][8] = 261; - v[1059][8] = 495; - v[1060][8] = 171; - v[1061][8] = 69; - v[1062][8] = 27; - v[1063][8] = 409; - v[1064][8] = 21; - v[1065][8] = 421; - v[1066][8] = 367; - v[1067][8] = 81; - v[1068][8] = 483; - v[1069][8] = 255; - v[1070][8] = 15; - v[1071][8] = 219; - v[1072][8] = 365; - v[1073][8] = 497; - v[1074][8] = 181; - v[1075][8] = 75; - v[1076][8] = 431; - v[1077][8] = 99; - v[1078][8] = 325; - v[1079][8] = 407; - v[1080][8] = 229; - v[1081][8] = 281; - v[1082][8] = 63; - v[1083][8] = 83; - v[1084][8] = 493; - v[1085][8] = 5; - v[1086][8] = 113; - v[1087][8] = 15; - v[1088][8] = 271; - v[1089][8] = 37; - v[1090][8] = 87; - v[1091][8] = 451; - v[1092][8] = 299; - v[1093][8] = 83; - v[1094][8] = 451; - v[1095][8] = 311; - v[1096][8] = 441; - v[1097][8] = 47; - v[1098][8] = 455; - v[1099][8] = 47; - v[1100][8] = 253; - v[1101][8] = 13; - v[1102][8] = 109; - v[1103][8] = 369; - v[1104][8] = 347; - v[1105][8] = 11; - v[1106][8] = 409; - v[1107][8] = 275; - v[1108][8] = 63; - v[1109][8] = 441; - v[1110][8] = 15; - - v[101][9] = 519; - v[102][9] = 307; - v[103][9] = 931; - v[104][9] = 1023; - v[105][9] = 517; - v[106][9] = 771; - v[107][9] = 151; - v[108][9] = 1023; - v[109][9] = 539; - v[110][9] = 725; - v[111][9] = 45; - v[112][9] = 927; - v[113][9] = 707; - v[114][9] = 29; - v[115][9] = 125; - v[116][9] = 371; - v[117][9] = 275; - v[118][9] = 279; - v[119][9] = 817; - v[120][9] = 389; - v[121][9] = 453; - v[122][9] = 989; - v[123][9] = 1015; - v[124][9] = 29; - v[125][9] = 169; - v[126][9] = 743; - v[127][9] = 99; - v[128][9] = 923; - v[129][9] = 981; - v[130][9] = 181; - v[131][9] = 693; - v[132][9] = 309; - v[133][9] = 227; - v[134][9] = 111; - v[135][9] = 219; - v[136][9] = 897; - v[137][9] = 377; - v[138][9] = 425; - v[139][9] = 609; - v[140][9] = 227; - v[141][9] = 19; - v[142][9] = 221; - v[143][9] = 143; - v[144][9] = 581; - v[145][9] = 147; - v[146][9] = 919; - v[147][9] = 127; - v[148][9] = 725; - v[149][9] = 793; - v[150][9] = 289; - v[151][9] = 411; - v[152][9] = 835; - v[153][9] = 921; - v[154][9] = 957; - v[155][9] = 443; - v[156][9] = 349; - v[157][9] = 813; - v[158][9] = 5; - v[159][9] = 105; - v[160][9] = 457; - v[161][9] = 393; - v[162][9] = 539; - v[163][9] = 101; - v[164][9] = 197; - v[165][9] = 697; - v[166][9] = 27; - v[167][9] = 343; - v[168][9] = 515; - v[169][9] = 69; - v[170][9] = 485; - v[171][9] = 383; - v[172][9] = 855; - v[173][9] = 693; - v[174][9] = 133; - v[175][9] = 87; - v[176][9] = 743; - v[177][9] = 747; - v[178][9] = 475; - v[179][9] = 87; - v[180][9] = 469; - v[181][9] = 763; - v[182][9] = 721; - v[183][9] = 345; - v[184][9] = 479; - v[185][9] = 965; - v[186][9] = 527; - v[187][9] = 121; - v[188][9] = 271; - v[189][9] = 353; - v[190][9] = 467; - v[191][9] = 177; - v[192][9] = 245; - v[193][9] = 627; - v[194][9] = 113; - v[195][9] = 357; - v[196][9] = 7; - v[197][9] = 691; - v[198][9] = 725; - v[199][9] = 355; - v[200][9] = 889; - v[201][9] = 635; - v[202][9] = 737; - v[203][9] = 429; - v[204][9] = 545; - v[205][9] = 925; - v[206][9] = 357; - v[207][9] = 873; - v[208][9] = 187; - v[209][9] = 351; - v[210][9] = 677; - v[211][9] = 999; - v[212][9] = 921; - v[213][9] = 477; - v[214][9] = 233; - v[215][9] = 765; - v[216][9] = 495; - v[217][9] = 81; - v[218][9] = 953; - v[219][9] = 479; - v[220][9] = 89; - v[221][9] = 173; - v[222][9] = 473; - v[223][9] = 131; - v[224][9] = 961; - v[225][9] = 411; - v[226][9] = 291; - v[227][9] = 967; - v[228][9] = 65; - v[229][9] = 511; - v[230][9] = 13; - v[231][9] = 805; - v[232][9] = 945; - v[233][9] = 369; - v[234][9] = 827; - v[235][9] = 295; - v[236][9] = 163; - v[237][9] = 835; - v[238][9] = 259; - v[239][9] = 207; - v[240][9] = 331; - v[241][9] = 29; - v[242][9] = 315; - v[243][9] = 999; - v[244][9] = 133; - v[245][9] = 967; - v[246][9] = 41; - v[247][9] = 117; - v[248][9] = 677; - v[249][9] = 471; - v[250][9] = 717; - v[251][9] = 881; - v[252][9] = 755; - v[253][9] = 351; - v[254][9] = 723; - v[255][9] = 259; - v[256][9] = 879; - v[257][9] = 455; - v[258][9] = 721; - v[259][9] = 289; - v[260][9] = 149; - v[261][9] = 199; - v[262][9] = 805; - v[263][9] = 987; - v[264][9] = 851; - v[265][9] = 423; - v[266][9] = 597; - v[267][9] = 129; - v[268][9] = 11; - v[269][9] = 733; - v[270][9] = 549; - v[271][9] = 153; - v[272][9] = 285; - v[273][9] = 451; - v[274][9] = 559; - v[275][9] = 377; - v[276][9] = 109; - v[277][9] = 357; - v[278][9] = 143; - v[279][9] = 693; - v[280][9] = 615; - v[281][9] = 677; - v[282][9] = 701; - v[283][9] = 475; - v[284][9] = 767; - v[285][9] = 85; - v[286][9] = 229; - v[287][9] = 509; - v[288][9] = 547; - v[289][9] = 151; - v[290][9] = 389; - v[291][9] = 711; - v[292][9] = 785; - v[293][9] = 657; - v[294][9] = 319; - v[295][9] = 509; - v[296][9] = 99; - v[297][9] = 1007; - v[298][9] = 775; - v[299][9] = 359; - v[300][9] = 697; - v[301][9] = 677; - v[302][9] = 85; - v[303][9] = 497; - v[304][9] = 105; - v[305][9] = 615; - v[306][9] = 891; - v[307][9] = 71; - v[308][9] = 449; - v[309][9] = 835; - v[310][9] = 609; - v[311][9] = 377; - v[312][9] = 693; - v[313][9] = 665; - v[314][9] = 627; - v[315][9] = 215; - v[316][9] = 911; - v[317][9] = 503; - v[318][9] = 729; - v[319][9] = 131; - v[320][9] = 19; - v[321][9] = 895; - v[322][9] = 199; - v[323][9] = 161; - v[324][9] = 239; - v[325][9] = 633; - v[326][9] = 1013; - v[327][9] = 537; - v[328][9] = 255; - v[329][9] = 23; - v[330][9] = 149; - v[331][9] = 679; - v[332][9] = 1021; - v[333][9] = 595; - v[334][9] = 199; - v[335][9] = 557; - v[336][9] = 659; - v[337][9] = 251; - v[338][9] = 829; - v[339][9] = 727; - v[340][9] = 439; - v[341][9] = 495; - v[342][9] = 647; - v[343][9] = 223; - v[344][9] = 949; - v[345][9] = 625; - v[346][9] = 87; - v[347][9] = 481; - v[348][9] = 85; - v[349][9] = 799; - v[350][9] = 917; - v[351][9] = 769; - v[352][9] = 949; - v[353][9] = 739; - v[354][9] = 115; - v[355][9] = 499; - v[356][9] = 945; - v[357][9] = 547; - v[358][9] = 225; - v[359][9] = 1015; - v[360][9] = 469; - v[361][9] = 737; - v[362][9] = 495; - v[363][9] = 353; - v[364][9] = 103; - v[365][9] = 17; - v[366][9] = 665; - v[367][9] = 639; - v[368][9] = 525; - v[369][9] = 75; - v[370][9] = 447; - v[371][9] = 185; - v[372][9] = 43; - v[373][9] = 729; - v[374][9] = 577; - v[375][9] = 863; - v[376][9] = 735; - v[377][9] = 317; - v[378][9] = 99; - v[379][9] = 17; - v[380][9] = 477; - v[381][9] = 893; - v[382][9] = 537; - v[383][9] = 519; - v[384][9] = 1017; - v[385][9] = 375; - v[386][9] = 297; - v[387][9] = 325; - v[388][9] = 999; - v[389][9] = 353; - v[390][9] = 343; - v[391][9] = 729; - v[392][9] = 135; - v[393][9] = 489; - v[394][9] = 859; - v[395][9] = 267; - v[396][9] = 141; - v[397][9] = 831; - v[398][9] = 141; - v[399][9] = 893; - v[400][9] = 249; - v[401][9] = 807; - v[402][9] = 53; - v[403][9] = 613; - v[404][9] = 131; - v[405][9] = 547; - v[406][9] = 977; - v[407][9] = 131; - v[408][9] = 999; - v[409][9] = 175; - v[410][9] = 31; - v[411][9] = 341; - v[412][9] = 739; - v[413][9] = 467; - v[414][9] = 675; - v[415][9] = 241; - v[416][9] = 645; - v[417][9] = 247; - v[418][9] = 391; - v[419][9] = 583; - v[420][9] = 183; - v[421][9] = 973; - v[422][9] = 433; - v[423][9] = 367; - v[424][9] = 131; - v[425][9] = 467; - v[426][9] = 571; - v[427][9] = 309; - v[428][9] = 385; - v[429][9] = 977; - v[430][9] = 111; - v[431][9] = 917; - v[432][9] = 935; - v[433][9] = 473; - v[434][9] = 345; - v[435][9] = 411; - v[436][9] = 313; - v[437][9] = 97; - v[438][9] = 149; - v[439][9] = 959; - v[440][9] = 841; - v[441][9] = 839; - v[442][9] = 669; - v[443][9] = 431; - v[444][9] = 51; - v[445][9] = 41; - v[446][9] = 301; - v[447][9] = 247; - v[448][9] = 1015; - v[449][9] = 377; - v[450][9] = 329; - v[451][9] = 945; - v[452][9] = 269; - v[453][9] = 67; - v[454][9] = 979; - v[455][9] = 581; - v[456][9] = 643; - v[457][9] = 823; - v[458][9] = 557; - v[459][9] = 91; - v[460][9] = 405; - v[461][9] = 117; - v[462][9] = 801; - v[463][9] = 509; - v[464][9] = 347; - v[465][9] = 893; - v[466][9] = 303; - v[467][9] = 227; - v[468][9] = 783; - v[469][9] = 555; - v[470][9] = 867; - v[471][9] = 99; - v[472][9] = 703; - v[473][9] = 111; - v[474][9] = 797; - v[475][9] = 873; - v[476][9] = 541; - v[477][9] = 919; - v[478][9] = 513; - v[479][9] = 343; - v[480][9] = 319; - v[481][9] = 517; - v[482][9] = 135; - v[483][9] = 871; - v[484][9] = 917; - v[485][9] = 285; - v[486][9] = 663; - v[487][9] = 301; - v[488][9] = 15; - v[489][9] = 763; - v[490][9] = 89; - v[491][9] = 323; - v[492][9] = 757; - v[493][9] = 317; - v[494][9] = 807; - v[495][9] = 309; - v[496][9] = 1013; - v[497][9] = 345; - v[498][9] = 499; - v[499][9] = 279; - v[500][9] = 711; - v[501][9] = 915; - v[502][9] = 411; - v[503][9] = 281; - v[504][9] = 193; - v[505][9] = 739; - v[506][9] = 365; - v[507][9] = 315; - v[508][9] = 375; - v[509][9] = 809; - v[510][9] = 469; - v[511][9] = 487; - v[512][9] = 621; - v[513][9] = 857; - v[514][9] = 975; - v[515][9] = 537; - v[516][9] = 939; - v[517][9] = 585; - v[518][9] = 129; - v[519][9] = 625; - v[520][9] = 447; - v[521][9] = 129; - v[522][9] = 1017; - v[523][9] = 133; - v[524][9] = 83; - v[525][9] = 3; - v[526][9] = 415; - v[527][9] = 661; - v[528][9] = 53; - v[529][9] = 115; - v[530][9] = 903; - v[531][9] = 49; - v[532][9] = 79; - v[533][9] = 55; - v[534][9] = 385; - v[535][9] = 261; - v[536][9] = 345; - v[537][9] = 297; - v[538][9] = 199; - v[539][9] = 385; - v[540][9] = 617; - v[541][9] = 25; - v[542][9] = 515; - v[543][9] = 275; - v[544][9] = 849; - v[545][9] = 401; - v[546][9] = 471; - v[547][9] = 377; - v[548][9] = 661; - v[549][9] = 535; - v[550][9] = 505; - v[551][9] = 939; - v[552][9] = 465; - v[553][9] = 225; - v[554][9] = 929; - v[555][9] = 219; - v[556][9] = 955; - v[557][9] = 659; - v[558][9] = 441; - v[559][9] = 117; - v[560][9] = 527; - v[561][9] = 427; - v[562][9] = 515; - v[563][9] = 287; - v[564][9] = 191; - v[565][9] = 33; - v[566][9] = 389; - v[567][9] = 197; - v[568][9] = 825; - v[569][9] = 63; - v[570][9] = 417; - v[571][9] = 949; - v[572][9] = 35; - v[573][9] = 571; - v[574][9] = 9; - v[575][9] = 131; - v[576][9] = 609; - v[577][9] = 439; - v[578][9] = 95; - v[579][9] = 19; - v[580][9] = 569; - v[581][9] = 893; - v[582][9] = 451; - v[583][9] = 397; - v[584][9] = 971; - v[585][9] = 801; - v[586][9] = 125; - v[587][9] = 471; - v[588][9] = 187; - v[589][9] = 257; - v[590][9] = 67; - v[591][9] = 949; - v[592][9] = 621; - v[593][9] = 453; - v[594][9] = 411; - v[595][9] = 621; - v[596][9] = 955; - v[597][9] = 309; - v[598][9] = 783; - v[599][9] = 893; - v[600][9] = 597; - v[601][9] = 377; - v[602][9] = 753; - v[603][9] = 145; - v[604][9] = 637; - v[605][9] = 941; - v[606][9] = 593; - v[607][9] = 317; - v[608][9] = 555; - v[609][9] = 375; - v[610][9] = 575; - v[611][9] = 175; - v[612][9] = 403; - v[613][9] = 571; - v[614][9] = 555; - v[615][9] = 109; - v[616][9] = 377; - v[617][9] = 931; - v[618][9] = 499; - v[619][9] = 649; - v[620][9] = 653; - v[621][9] = 329; - v[622][9] = 279; - v[623][9] = 271; - v[624][9] = 647; - v[625][9] = 721; - v[626][9] = 665; - v[627][9] = 429; - v[628][9] = 957; - v[629][9] = 803; - v[630][9] = 767; - v[631][9] = 425; - v[632][9] = 477; - v[633][9] = 995; - v[634][9] = 105; - v[635][9] = 495; - v[636][9] = 575; - v[637][9] = 687; - v[638][9] = 385; - v[639][9] = 227; - v[640][9] = 923; - v[641][9] = 563; - v[642][9] = 723; - v[643][9] = 481; - v[644][9] = 717; - v[645][9] = 111; - v[646][9] = 633; - v[647][9] = 113; - v[648][9] = 369; - v[649][9] = 955; - v[650][9] = 253; - v[651][9] = 321; - v[652][9] = 409; - v[653][9] = 909; - v[654][9] = 367; - v[655][9] = 33; - v[656][9] = 967; - v[657][9] = 453; - v[658][9] = 863; - v[659][9] = 449; - v[660][9] = 539; - v[661][9] = 781; - v[662][9] = 911; - v[663][9] = 113; - v[664][9] = 7; - v[665][9] = 219; - v[666][9] = 725; - v[667][9] = 1015; - v[668][9] = 971; - v[669][9] = 1021; - v[670][9] = 525; - v[671][9] = 785; - v[672][9] = 873; - v[673][9] = 191; - v[674][9] = 893; - v[675][9] = 297; - v[676][9] = 507; - v[677][9] = 215; - v[678][9] = 21; - v[679][9] = 153; - v[680][9] = 645; - v[681][9] = 913; - v[682][9] = 755; - v[683][9] = 371; - v[684][9] = 881; - v[685][9] = 113; - v[686][9] = 903; - v[687][9] = 225; - v[688][9] = 49; - v[689][9] = 587; - v[690][9] = 201; - v[691][9] = 927; - v[692][9] = 429; - v[693][9] = 599; - v[694][9] = 513; - v[695][9] = 97; - v[696][9] = 319; - v[697][9] = 331; - v[698][9] = 833; - v[699][9] = 325; - v[700][9] = 887; - v[701][9] = 139; - v[702][9] = 927; - v[703][9] = 399; - v[704][9] = 163; - v[705][9] = 307; - v[706][9] = 803; - v[707][9] = 169; - v[708][9] = 1019; - v[709][9] = 869; - v[710][9] = 537; - v[711][9] = 907; - v[712][9] = 479; - v[713][9] = 335; - v[714][9] = 697; - v[715][9] = 479; - v[716][9] = 353; - v[717][9] = 769; - v[718][9] = 787; - v[719][9] = 1023; - v[720][9] = 855; - v[721][9] = 493; - v[722][9] = 883; - v[723][9] = 521; - v[724][9] = 735; - v[725][9] = 297; - v[726][9] = 1011; - v[727][9] = 991; - v[728][9] = 879; - v[729][9] = 855; - v[730][9] = 591; - v[731][9] = 415; - v[732][9] = 917; - v[733][9] = 375; - v[734][9] = 453; - v[735][9] = 553; - v[736][9] = 189; - v[737][9] = 841; - v[738][9] = 339; - v[739][9] = 211; - v[740][9] = 601; - v[741][9] = 57; - v[742][9] = 765; - v[743][9] = 745; - v[744][9] = 621; - v[745][9] = 209; - v[746][9] = 875; - v[747][9] = 639; - v[748][9] = 7; - v[749][9] = 595; - v[750][9] = 971; - v[751][9] = 263; - v[752][9] = 1009; - v[753][9] = 201; - v[754][9] = 23; - v[755][9] = 77; - v[756][9] = 621; - v[757][9] = 33; - v[758][9] = 535; - v[759][9] = 963; - v[760][9] = 661; - v[761][9] = 523; - v[762][9] = 263; - v[763][9] = 917; - v[764][9] = 103; - v[765][9] = 623; - v[766][9] = 231; - v[767][9] = 47; - v[768][9] = 301; - v[769][9] = 549; - v[770][9] = 337; - v[771][9] = 675; - v[772][9] = 189; - v[773][9] = 357; - v[774][9] = 1005; - v[775][9] = 789; - v[776][9] = 189; - v[777][9] = 319; - v[778][9] = 721; - v[779][9] = 1005; - v[780][9] = 525; - v[781][9] = 675; - v[782][9] = 539; - v[783][9] = 191; - v[784][9] = 813; - v[785][9] = 917; - v[786][9] = 51; - v[787][9] = 167; - v[788][9] = 415; - v[789][9] = 579; - v[790][9] = 755; - v[791][9] = 605; - v[792][9] = 721; - v[793][9] = 837; - v[794][9] = 529; - v[795][9] = 31; - v[796][9] = 327; - v[797][9] = 799; - v[798][9] = 961; - v[799][9] = 279; - v[800][9] = 409; - v[801][9] = 847; - v[802][9] = 649; - v[803][9] = 241; - v[804][9] = 285; - v[805][9] = 545; - v[806][9] = 407; - v[807][9] = 161; - v[808][9] = 591; - v[809][9] = 73; - v[810][9] = 313; - v[811][9] = 811; - v[812][9] = 17; - v[813][9] = 663; - v[814][9] = 269; - v[815][9] = 261; - v[816][9] = 37; - v[817][9] = 783; - v[818][9] = 127; - v[819][9] = 917; - v[820][9] = 231; - v[821][9] = 577; - v[822][9] = 975; - v[823][9] = 793; - v[824][9] = 921; - v[825][9] = 343; - v[826][9] = 751; - v[827][9] = 139; - v[828][9] = 221; - v[829][9] = 79; - v[830][9] = 817; - v[831][9] = 393; - v[832][9] = 545; - v[833][9] = 11; - v[834][9] = 781; - v[835][9] = 71; - v[836][9] = 1; - v[837][9] = 699; - v[838][9] = 767; - v[839][9] = 917; - v[840][9] = 9; - v[841][9] = 107; - v[842][9] = 341; - v[843][9] = 587; - v[844][9] = 903; - v[845][9] = 965; - v[846][9] = 599; - v[847][9] = 507; - v[848][9] = 843; - v[849][9] = 739; - v[850][9] = 579; - v[851][9] = 397; - v[852][9] = 397; - v[853][9] = 325; - v[854][9] = 775; - v[855][9] = 565; - v[856][9] = 925; - v[857][9] = 75; - v[858][9] = 55; - v[859][9] = 979; - v[860][9] = 931; - v[861][9] = 93; - v[862][9] = 957; - v[863][9] = 857; - v[864][9] = 753; - v[865][9] = 965; - v[866][9] = 795; - v[867][9] = 67; - v[868][9] = 5; - v[869][9] = 87; - v[870][9] = 909; - v[871][9] = 97; - v[872][9] = 995; - v[873][9] = 271; - v[874][9] = 875; - v[875][9] = 671; - v[876][9] = 613; - v[877][9] = 33; - v[878][9] = 351; - v[879][9] = 69; - v[880][9] = 811; - v[881][9] = 669; - v[882][9] = 729; - v[883][9] = 401; - v[884][9] = 647; - v[885][9] = 241; - v[886][9] = 435; - v[887][9] = 447; - v[888][9] = 721; - v[889][9] = 271; - v[890][9] = 745; - v[891][9] = 53; - v[892][9] = 775; - v[893][9] = 99; - v[894][9] = 343; - v[895][9] = 451; - v[896][9] = 427; - v[897][9] = 593; - v[898][9] = 339; - v[899][9] = 845; - v[900][9] = 243; - v[901][9] = 345; - v[902][9] = 17; - v[903][9] = 573; - v[904][9] = 421; - v[905][9] = 517; - v[906][9] = 971; - v[907][9] = 499; - v[908][9] = 435; - v[909][9] = 769; - v[910][9] = 75; - v[911][9] = 203; - v[912][9] = 793; - v[913][9] = 985; - v[914][9] = 343; - v[915][9] = 955; - v[916][9] = 735; - v[917][9] = 523; - v[918][9] = 659; - v[919][9] = 703; - v[920][9] = 303; - v[921][9] = 421; - v[922][9] = 951; - v[923][9] = 405; - v[924][9] = 631; - v[925][9] = 825; - v[926][9] = 735; - v[927][9] = 433; - v[928][9] = 841; - v[929][9] = 485; - v[930][9] = 49; - v[931][9] = 749; - v[932][9] = 107; - v[933][9] = 669; - v[934][9] = 211; - v[935][9] = 497; - v[936][9] = 143; - v[937][9] = 99; - v[938][9] = 57; - v[939][9] = 277; - v[940][9] = 969; - v[941][9] = 107; - v[942][9] = 397; - v[943][9] = 563; - v[944][9] = 551; - v[945][9] = 447; - v[946][9] = 381; - v[947][9] = 187; - v[948][9] = 57; - v[949][9] = 405; - v[950][9] = 731; - v[951][9] = 769; - v[952][9] = 923; - v[953][9] = 955; - v[954][9] = 915; - v[955][9] = 737; - v[956][9] = 595; - v[957][9] = 341; - v[958][9] = 253; - v[959][9] = 823; - v[960][9] = 197; - v[961][9] = 321; - v[962][9] = 315; - v[963][9] = 181; - v[964][9] = 885; - v[965][9] = 497; - v[966][9] = 159; - v[967][9] = 571; - v[968][9] = 981; - v[969][9] = 899; - v[970][9] = 785; - v[971][9] = 947; - v[972][9] = 217; - v[973][9] = 217; - v[974][9] = 135; - v[975][9] = 753; - v[976][9] = 623; - v[977][9] = 565; - v[978][9] = 717; - v[979][9] = 903; - v[980][9] = 581; - v[981][9] = 955; - v[982][9] = 621; - v[983][9] = 361; - v[984][9] = 869; - v[985][9] = 87; - v[986][9] = 943; - v[987][9] = 907; - v[988][9] = 853; - v[989][9] = 353; - v[990][9] = 335; - v[991][9] = 197; - v[992][9] = 771; - v[993][9] = 433; - v[994][9] = 743; - v[995][9] = 195; - v[996][9] = 91; - v[997][9] = 1023; - v[998][9] = 63; - v[999][9] = 301; - v[1000][9] = 647; - v[1001][9] = 205; - v[1002][9] = 485; - v[1003][9] = 927; - v[1004][9] = 1003; - v[1005][9] = 987; - v[1006][9] = 359; - v[1007][9] = 577; - v[1008][9] = 147; - v[1009][9] = 141; - v[1010][9] = 1017; - v[1011][9] = 701; - v[1012][9] = 273; - v[1013][9] = 89; - v[1014][9] = 589; - v[1015][9] = 487; - v[1016][9] = 859; - v[1017][9] = 343; - v[1018][9] = 91; - v[1019][9] = 847; - v[1020][9] = 341; - v[1021][9] = 173; - v[1022][9] = 287; - v[1023][9] = 1003; - v[1024][9] = 289; - v[1025][9] = 639; - v[1026][9] = 983; - v[1027][9] = 685; - v[1028][9] = 697; - v[1029][9] = 35; - v[1030][9] = 701; - v[1031][9] = 645; - v[1032][9] = 911; - v[1033][9] = 501; - v[1034][9] = 705; - v[1035][9] = 873; - v[1036][9] = 763; - v[1037][9] = 745; - v[1038][9] = 657; - v[1039][9] = 559; - v[1040][9] = 699; - v[1041][9] = 315; - v[1042][9] = 347; - v[1043][9] = 429; - v[1044][9] = 197; - v[1045][9] = 165; - v[1046][9] = 955; - v[1047][9] = 859; - v[1048][9] = 167; - v[1049][9] = 303; - v[1050][9] = 833; - v[1051][9] = 531; - v[1052][9] = 473; - v[1053][9] = 635; - v[1054][9] = 641; - v[1055][9] = 195; - v[1056][9] = 589; - v[1057][9] = 821; - v[1058][9] = 205; - v[1059][9] = 3; - v[1060][9] = 635; - v[1061][9] = 371; - v[1062][9] = 891; - v[1063][9] = 249; - v[1064][9] = 123; - v[1065][9] = 77; - v[1066][9] = 623; - v[1067][9] = 993; - v[1068][9] = 401; - v[1069][9] = 525; - v[1070][9] = 427; - v[1071][9] = 71; - v[1072][9] = 655; - v[1073][9] = 951; - v[1074][9] = 357; - v[1075][9] = 851; - v[1076][9] = 899; - v[1077][9] = 535; - v[1078][9] = 493; - v[1079][9] = 323; - v[1080][9] = 1003; - v[1081][9] = 343; - v[1082][9] = 515; - v[1083][9] = 859; - v[1084][9] = 1017; - v[1085][9] = 5; - v[1086][9] = 423; - v[1087][9] = 315; - v[1088][9] = 1011; - v[1089][9] = 703; - v[1090][9] = 41; - v[1091][9] = 777; - v[1092][9] = 163; - v[1093][9] = 95; - v[1094][9] = 831; - v[1095][9] = 79; - v[1096][9] = 975; - v[1097][9] = 235; - v[1098][9] = 633; - v[1099][9] = 723; - v[1100][9] = 297; - v[1101][9] = 589; - v[1102][9] = 317; - v[1103][9] = 679; - v[1104][9] = 981; - v[1105][9] = 195; - v[1106][9] = 399; - v[1107][9] = 1003; - v[1108][9] = 121; - v[1109][9] = 501; - v[1110][9] = 155; - - v[161][10] = 7; - v[162][10] = 2011; - v[163][10] = 1001; - v[164][10] = 49; - v[165][10] = 825; - v[166][10] = 415; - v[167][10] = 1441; - v[168][10] = 383; - v[169][10] = 1581; - v[170][10] = 623; - v[171][10] = 1621; - v[172][10] = 1319; - v[173][10] = 1387; - v[174][10] = 619; - v[175][10] = 839; - v[176][10] = 217; - v[177][10] = 75; - v[178][10] = 1955; - v[179][10] = 505; - v[180][10] = 281; - v[181][10] = 1629; - v[182][10] = 1379; - v[183][10] = 53; - v[184][10] = 1111; - v[185][10] = 1399; - v[186][10] = 301; - v[187][10] = 209; - v[188][10] = 49; - v[189][10] = 155; - v[190][10] = 1647; - v[191][10] = 631; - v[192][10] = 129; - v[193][10] = 1569; - v[194][10] = 335; - v[195][10] = 67; - v[196][10] = 1955; - v[197][10] = 1611; - v[198][10] = 2021; - v[199][10] = 1305; - v[200][10] = 121; - v[201][10] = 37; - v[202][10] = 877; - v[203][10] = 835; - v[204][10] = 1457; - v[205][10] = 669; - v[206][10] = 1405; - v[207][10] = 935; - v[208][10] = 1735; - v[209][10] = 665; - v[210][10] = 551; - v[211][10] = 789; - v[212][10] = 1543; - v[213][10] = 1267; - v[214][10] = 1027; - v[215][10] = 1; - v[216][10] = 1911; - v[217][10] = 163; - v[218][10] = 1929; - v[219][10] = 67; - v[220][10] = 1975; - v[221][10] = 1681; - v[222][10] = 1413; - v[223][10] = 191; - v[224][10] = 1711; - v[225][10] = 1307; - v[226][10] = 401; - v[227][10] = 725; - v[228][10] = 1229; - v[229][10] = 1403; - v[230][10] = 1609; - v[231][10] = 2035; - v[232][10] = 917; - v[233][10] = 921; - v[234][10] = 1789; - v[235][10] = 41; - v[236][10] = 2003; - v[237][10] = 187; - v[238][10] = 67; - v[239][10] = 1635; - v[240][10] = 717; - v[241][10] = 1449; - v[242][10] = 277; - v[243][10] = 1903; - v[244][10] = 1179; - v[245][10] = 363; - v[246][10] = 1211; - v[247][10] = 1231; - v[248][10] = 647; - v[249][10] = 1261; - v[250][10] = 1029; - v[251][10] = 1485; - v[252][10] = 1309; - v[253][10] = 1149; - v[254][10] = 317; - v[255][10] = 1335; - v[256][10] = 171; - v[257][10] = 243; - v[258][10] = 271; - v[259][10] = 1055; - v[260][10] = 1601; - v[261][10] = 1129; - v[262][10] = 1653; - v[263][10] = 205; - v[264][10] = 1463; - v[265][10] = 1681; - v[266][10] = 1621; - v[267][10] = 197; - v[268][10] = 951; - v[269][10] = 573; - v[270][10] = 1697; - v[271][10] = 1265; - v[272][10] = 1321; - v[273][10] = 1805; - v[274][10] = 1235; - v[275][10] = 1853; - v[276][10] = 1307; - v[277][10] = 945; - v[278][10] = 1197; - v[279][10] = 1411; - v[280][10] = 833; - v[281][10] = 273; - v[282][10] = 1517; - v[283][10] = 1747; - v[284][10] = 1095; - v[285][10] = 1345; - v[286][10] = 869; - v[287][10] = 57; - v[288][10] = 1383; - v[289][10] = 221; - v[290][10] = 1713; - v[291][10] = 335; - v[292][10] = 1751; - v[293][10] = 1141; - v[294][10] = 839; - v[295][10] = 523; - v[296][10] = 1861; - v[297][10] = 1105; - v[298][10] = 389; - v[299][10] = 1177; - v[300][10] = 1877; - v[301][10] = 805; - v[302][10] = 93; - v[303][10] = 1591; - v[304][10] = 423; - v[305][10] = 1835; - v[306][10] = 99; - v[307][10] = 1781; - v[308][10] = 1515; - v[309][10] = 1909; - v[310][10] = 1011; - v[311][10] = 303; - v[312][10] = 385; - v[313][10] = 1635; - v[314][10] = 357; - v[315][10] = 973; - v[316][10] = 1781; - v[317][10] = 1707; - v[318][10] = 1363; - v[319][10] = 1053; - v[320][10] = 649; - v[321][10] = 1469; - v[322][10] = 623; - v[323][10] = 1429; - v[324][10] = 1241; - v[325][10] = 1151; - v[326][10] = 1055; - v[327][10] = 503; - v[328][10] = 921; - v[329][10] = 3; - v[330][10] = 349; - v[331][10] = 1149; - v[332][10] = 293; - v[333][10] = 45; - v[334][10] = 303; - v[335][10] = 877; - v[336][10] = 1565; - v[337][10] = 1583; - v[338][10] = 1001; - v[339][10] = 663; - v[340][10] = 1535; - v[341][10] = 395; - v[342][10] = 1141; - v[343][10] = 1481; - v[344][10] = 1797; - v[345][10] = 643; - v[346][10] = 1507; - v[347][10] = 465; - v[348][10] = 2027; - v[349][10] = 1695; - v[350][10] = 367; - v[351][10] = 937; - v[352][10] = 719; - v[353][10] = 545; - v[354][10] = 1991; - v[355][10] = 83; - v[356][10] = 819; - v[357][10] = 239; - v[358][10] = 1791; - v[359][10] = 1461; - v[360][10] = 1647; - v[361][10] = 1501; - v[362][10] = 1161; - v[363][10] = 1629; - v[364][10] = 139; - v[365][10] = 1595; - v[366][10] = 1921; - v[367][10] = 1267; - v[368][10] = 1415; - v[369][10] = 509; - v[370][10] = 347; - v[371][10] = 777; - v[372][10] = 1083; - v[373][10] = 363; - v[374][10] = 269; - v[375][10] = 1015; - v[376][10] = 1809; - v[377][10] = 1105; - v[378][10] = 1429; - v[379][10] = 1471; - v[380][10] = 2019; - v[381][10] = 381; - v[382][10] = 2025; - v[383][10] = 1223; - v[384][10] = 827; - v[385][10] = 1733; - v[386][10] = 887; - v[387][10] = 1321; - v[388][10] = 803; - v[389][10] = 1951; - v[390][10] = 1297; - v[391][10] = 1995; - v[392][10] = 833; - v[393][10] = 1107; - v[394][10] = 1135; - v[395][10] = 1181; - v[396][10] = 1251; - v[397][10] = 983; - v[398][10] = 1389; - v[399][10] = 1565; - v[400][10] = 273; - v[401][10] = 137; - v[402][10] = 71; - v[403][10] = 735; - v[404][10] = 1005; - v[405][10] = 933; - v[406][10] = 67; - v[407][10] = 1471; - v[408][10] = 551; - v[409][10] = 457; - v[410][10] = 1667; - v[411][10] = 1729; - v[412][10] = 919; - v[413][10] = 285; - v[414][10] = 1629; - v[415][10] = 1815; - v[416][10] = 653; - v[417][10] = 1919; - v[418][10] = 1039; - v[419][10] = 531; - v[420][10] = 393; - v[421][10] = 1411; - v[422][10] = 359; - v[423][10] = 221; - v[424][10] = 699; - v[425][10] = 1485; - v[426][10] = 471; - v[427][10] = 1357; - v[428][10] = 1715; - v[429][10] = 595; - v[430][10] = 1677; - v[431][10] = 153; - v[432][10] = 1903; - v[433][10] = 1281; - v[434][10] = 215; - v[435][10] = 781; - v[436][10] = 543; - v[437][10] = 293; - v[438][10] = 1807; - v[439][10] = 965; - v[440][10] = 1695; - v[441][10] = 443; - v[442][10] = 1985; - v[443][10] = 321; - v[444][10] = 879; - v[445][10] = 1227; - v[446][10] = 1915; - v[447][10] = 839; - v[448][10] = 1945; - v[449][10] = 1993; - v[450][10] = 1165; - v[451][10] = 51; - v[452][10] = 557; - v[453][10] = 723; - v[454][10] = 1491; - v[455][10] = 817; - v[456][10] = 1237; - v[457][10] = 947; - v[458][10] = 1215; - v[459][10] = 1911; - v[460][10] = 1225; - v[461][10] = 1965; - v[462][10] = 1889; - v[463][10] = 1503; - v[464][10] = 1177; - v[465][10] = 73; - v[466][10] = 1767; - v[467][10] = 303; - v[468][10] = 177; - v[469][10] = 1897; - v[470][10] = 1401; - v[471][10] = 321; - v[472][10] = 921; - v[473][10] = 217; - v[474][10] = 1779; - v[475][10] = 327; - v[476][10] = 1889; - v[477][10] = 333; - v[478][10] = 615; - v[479][10] = 1665; - v[480][10] = 1825; - v[481][10] = 1639; - v[482][10] = 237; - v[483][10] = 1205; - v[484][10] = 361; - v[485][10] = 129; - v[486][10] = 1655; - v[487][10] = 983; - v[488][10] = 1089; - v[489][10] = 1171; - v[490][10] = 401; - v[491][10] = 677; - v[492][10] = 643; - v[493][10] = 749; - v[494][10] = 303; - v[495][10] = 1407; - v[496][10] = 1873; - v[497][10] = 1579; - v[498][10] = 1491; - v[499][10] = 1393; - v[500][10] = 1247; - v[501][10] = 789; - v[502][10] = 763; - v[503][10] = 49; - v[504][10] = 5; - v[505][10] = 1607; - v[506][10] = 1891; - v[507][10] = 735; - v[508][10] = 1557; - v[509][10] = 1909; - v[510][10] = 1765; - v[511][10] = 1777; - v[512][10] = 1127; - v[513][10] = 813; - v[514][10] = 695; - v[515][10] = 97; - v[516][10] = 731; - v[517][10] = 1503; - v[518][10] = 1751; - v[519][10] = 333; - v[520][10] = 769; - v[521][10] = 865; - v[522][10] = 693; - v[523][10] = 377; - v[524][10] = 1919; - v[525][10] = 957; - v[526][10] = 1359; - v[527][10] = 1627; - v[528][10] = 1039; - v[529][10] = 1783; - v[530][10] = 1065; - v[531][10] = 1665; - v[532][10] = 1917; - v[533][10] = 1947; - v[534][10] = 991; - v[535][10] = 1997; - v[536][10] = 841; - v[537][10] = 459; - v[538][10] = 221; - v[539][10] = 327; - v[540][10] = 1595; - v[541][10] = 1881; - v[542][10] = 1269; - v[543][10] = 1007; - v[544][10] = 129; - v[545][10] = 1413; - v[546][10] = 475; - v[547][10] = 1105; - v[548][10] = 791; - v[549][10] = 1983; - v[550][10] = 1359; - v[551][10] = 503; - v[552][10] = 691; - v[553][10] = 659; - v[554][10] = 691; - v[555][10] = 343; - v[556][10] = 1375; - v[557][10] = 1919; - v[558][10] = 263; - v[559][10] = 1373; - v[560][10] = 603; - v[561][10] = 1383; - v[562][10] = 297; - v[563][10] = 781; - v[564][10] = 145; - v[565][10] = 285; - v[566][10] = 767; - v[567][10] = 1739; - v[568][10] = 1715; - v[569][10] = 715; - v[570][10] = 317; - v[571][10] = 1333; - v[572][10] = 85; - v[573][10] = 831; - v[574][10] = 1615; - v[575][10] = 81; - v[576][10] = 1667; - v[577][10] = 1467; - v[578][10] = 1457; - v[579][10] = 1453; - v[580][10] = 1825; - v[581][10] = 109; - v[582][10] = 387; - v[583][10] = 1207; - v[584][10] = 2039; - v[585][10] = 213; - v[586][10] = 1351; - v[587][10] = 1329; - v[588][10] = 1173; - v[589][10] = 57; - v[590][10] = 1769; - v[591][10] = 951; - v[592][10] = 183; - v[593][10] = 23; - v[594][10] = 451; - v[595][10] = 1155; - v[596][10] = 1551; - v[597][10] = 2037; - v[598][10] = 811; - v[599][10] = 635; - v[600][10] = 1671; - v[601][10] = 1451; - v[602][10] = 863; - v[603][10] = 1499; - v[604][10] = 1673; - v[605][10] = 363; - v[606][10] = 1029; - v[607][10] = 1077; - v[608][10] = 1525; - v[609][10] = 277; - v[610][10] = 1023; - v[611][10] = 655; - v[612][10] = 665; - v[613][10] = 1869; - v[614][10] = 1255; - v[615][10] = 965; - v[616][10] = 277; - v[617][10] = 1601; - v[618][10] = 329; - v[619][10] = 1603; - v[620][10] = 1901; - v[621][10] = 395; - v[622][10] = 65; - v[623][10] = 1307; - v[624][10] = 2029; - v[625][10] = 21; - v[626][10] = 1321; - v[627][10] = 543; - v[628][10] = 1569; - v[629][10] = 1185; - v[630][10] = 1905; - v[631][10] = 1701; - v[632][10] = 413; - v[633][10] = 2041; - v[634][10] = 1697; - v[635][10] = 725; - v[636][10] = 1417; - v[637][10] = 1847; - v[638][10] = 411; - v[639][10] = 211; - v[640][10] = 915; - v[641][10] = 1891; - v[642][10] = 17; - v[643][10] = 1877; - v[644][10] = 1699; - v[645][10] = 687; - v[646][10] = 1089; - v[647][10] = 1973; - v[648][10] = 1809; - v[649][10] = 851; - v[650][10] = 1495; - v[651][10] = 1257; - v[652][10] = 63; - v[653][10] = 1323; - v[654][10] = 1307; - v[655][10] = 609; - v[656][10] = 881; - v[657][10] = 1543; - v[658][10] = 177; - v[659][10] = 617; - v[660][10] = 1505; - v[661][10] = 1747; - v[662][10] = 1537; - v[663][10] = 925; - v[664][10] = 183; - v[665][10] = 77; - v[666][10] = 1723; - v[667][10] = 1877; - v[668][10] = 1703; - v[669][10] = 397; - v[670][10] = 459; - v[671][10] = 521; - v[672][10] = 257; - v[673][10] = 1177; - v[674][10] = 389; - v[675][10] = 1947; - v[676][10] = 1553; - v[677][10] = 1583; - v[678][10] = 1831; - v[679][10] = 261; - v[680][10] = 485; - v[681][10] = 289; - v[682][10] = 1281; - v[683][10] = 1543; - v[684][10] = 1591; - v[685][10] = 1123; - v[686][10] = 573; - v[687][10] = 821; - v[688][10] = 1065; - v[689][10] = 1933; - v[690][10] = 1373; - v[691][10] = 2005; - v[692][10] = 905; - v[693][10] = 207; - v[694][10] = 173; - v[695][10] = 1573; - v[696][10] = 1597; - v[697][10] = 573; - v[698][10] = 1883; - v[699][10] = 1795; - v[700][10] = 1499; - v[701][10] = 1743; - v[702][10] = 553; - v[703][10] = 335; - v[704][10] = 333; - v[705][10] = 1645; - v[706][10] = 791; - v[707][10] = 871; - v[708][10] = 1157; - v[709][10] = 969; - v[710][10] = 557; - v[711][10] = 141; - v[712][10] = 223; - v[713][10] = 1129; - v[714][10] = 1685; - v[715][10] = 423; - v[716][10] = 1069; - v[717][10] = 391; - v[718][10] = 99; - v[719][10] = 95; - v[720][10] = 1847; - v[721][10] = 531; - v[722][10] = 1859; - v[723][10] = 1833; - v[724][10] = 1833; - v[725][10] = 341; - v[726][10] = 237; - v[727][10] = 1997; - v[728][10] = 1799; - v[729][10] = 409; - v[730][10] = 431; - v[731][10] = 1917; - v[732][10] = 363; - v[733][10] = 335; - v[734][10] = 1039; - v[735][10] = 1085; - v[736][10] = 1657; - v[737][10] = 1975; - v[738][10] = 1527; - v[739][10] = 1111; - v[740][10] = 659; - v[741][10] = 389; - v[742][10] = 899; - v[743][10] = 595; - v[744][10] = 1439; - v[745][10] = 1861; - v[746][10] = 1979; - v[747][10] = 1569; - v[748][10] = 1087; - v[749][10] = 1009; - v[750][10] = 165; - v[751][10] = 1895; - v[752][10] = 1481; - v[753][10] = 1583; - v[754][10] = 29; - v[755][10] = 1193; - v[756][10] = 1673; - v[757][10] = 1075; - v[758][10] = 301; - v[759][10] = 1081; - v[760][10] = 1377; - v[761][10] = 1747; - v[762][10] = 1497; - v[763][10] = 1103; - v[764][10] = 1789; - v[765][10] = 887; - v[766][10] = 739; - v[767][10] = 1577; - v[768][10] = 313; - v[769][10] = 1367; - v[770][10] = 1299; - v[771][10] = 1801; - v[772][10] = 1131; - v[773][10] = 1837; - v[774][10] = 73; - v[775][10] = 1865; - v[776][10] = 1065; - v[777][10] = 843; - v[778][10] = 635; - v[779][10] = 55; - v[780][10] = 1655; - v[781][10] = 913; - v[782][10] = 1037; - v[783][10] = 223; - v[784][10] = 1871; - v[785][10] = 1161; - v[786][10] = 461; - v[787][10] = 479; - v[788][10] = 511; - v[789][10] = 1721; - v[790][10] = 1107; - v[791][10] = 389; - v[792][10] = 151; - v[793][10] = 35; - v[794][10] = 375; - v[795][10] = 1099; - v[796][10] = 937; - v[797][10] = 1185; - v[798][10] = 1701; - v[799][10] = 769; - v[800][10] = 639; - v[801][10] = 1633; - v[802][10] = 1609; - v[803][10] = 379; - v[804][10] = 1613; - v[805][10] = 2031; - v[806][10] = 685; - v[807][10] = 289; - v[808][10] = 975; - v[809][10] = 671; - v[810][10] = 1599; - v[811][10] = 1447; - v[812][10] = 871; - v[813][10] = 647; - v[814][10] = 99; - v[815][10] = 139; - v[816][10] = 1427; - v[817][10] = 959; - v[818][10] = 89; - v[819][10] = 117; - v[820][10] = 841; - v[821][10] = 891; - v[822][10] = 1959; - v[823][10] = 223; - v[824][10] = 1697; - v[825][10] = 1145; - v[826][10] = 499; - v[827][10] = 1435; - v[828][10] = 1809; - v[829][10] = 1413; - v[830][10] = 1445; - v[831][10] = 1675; - v[832][10] = 171; - v[833][10] = 1073; - v[834][10] = 1349; - v[835][10] = 1545; - v[836][10] = 2039; - v[837][10] = 1027; - v[838][10] = 1563; - v[839][10] = 859; - v[840][10] = 215; - v[841][10] = 1673; - v[842][10] = 1919; - v[843][10] = 1633; - v[844][10] = 779; - v[845][10] = 411; - v[846][10] = 1845; - v[847][10] = 1477; - v[848][10] = 1489; - v[849][10] = 447; - v[850][10] = 1545; - v[851][10] = 351; - v[852][10] = 1989; - v[853][10] = 495; - v[854][10] = 183; - v[855][10] = 1639; - v[856][10] = 1385; - v[857][10] = 1805; - v[858][10] = 1097; - v[859][10] = 1249; - v[860][10] = 1431; - v[861][10] = 1571; - v[862][10] = 591; - v[863][10] = 697; - v[864][10] = 1509; - v[865][10] = 709; - v[866][10] = 31; - v[867][10] = 1563; - v[868][10] = 165; - v[869][10] = 513; - v[870][10] = 1425; - v[871][10] = 1299; - v[872][10] = 1081; - v[873][10] = 145; - v[874][10] = 1841; - v[875][10] = 1211; - v[876][10] = 941; - v[877][10] = 609; - v[878][10] = 845; - v[879][10] = 1169; - v[880][10] = 1865; - v[881][10] = 1593; - v[882][10] = 347; - v[883][10] = 293; - v[884][10] = 1277; - v[885][10] = 157; - v[886][10] = 211; - v[887][10] = 93; - v[888][10] = 1679; - v[889][10] = 1799; - v[890][10] = 527; - v[891][10] = 41; - v[892][10] = 473; - v[893][10] = 563; - v[894][10] = 187; - v[895][10] = 1525; - v[896][10] = 575; - v[897][10] = 1579; - v[898][10] = 857; - v[899][10] = 703; - v[900][10] = 1211; - v[901][10] = 647; - v[902][10] = 709; - v[903][10] = 981; - v[904][10] = 285; - v[905][10] = 697; - v[906][10] = 163; - v[907][10] = 981; - v[908][10] = 153; - v[909][10] = 1515; - v[910][10] = 47; - v[911][10] = 1553; - v[912][10] = 599; - v[913][10] = 225; - v[914][10] = 1147; - v[915][10] = 381; - v[916][10] = 135; - v[917][10] = 821; - v[918][10] = 1965; - v[919][10] = 609; - v[920][10] = 1033; - v[921][10] = 983; - v[922][10] = 503; - v[923][10] = 1117; - v[924][10] = 327; - v[925][10] = 453; - v[926][10] = 2005; - v[927][10] = 1257; - v[928][10] = 343; - v[929][10] = 1649; - v[930][10] = 1199; - v[931][10] = 599; - v[932][10] = 1877; - v[933][10] = 569; - v[934][10] = 695; - v[935][10] = 1587; - v[936][10] = 1475; - v[937][10] = 187; - v[938][10] = 973; - v[939][10] = 233; - v[940][10] = 511; - v[941][10] = 51; - v[942][10] = 1083; - v[943][10] = 665; - v[944][10] = 1321; - v[945][10] = 531; - v[946][10] = 1875; - v[947][10] = 1939; - v[948][10] = 859; - v[949][10] = 1507; - v[950][10] = 1979; - v[951][10] = 1203; - v[952][10] = 1965; - v[953][10] = 737; - v[954][10] = 921; - v[955][10] = 1565; - v[956][10] = 1943; - v[957][10] = 819; - v[958][10] = 223; - v[959][10] = 365; - v[960][10] = 167; - v[961][10] = 1705; - v[962][10] = 413; - v[963][10] = 1577; - v[964][10] = 745; - v[965][10] = 1573; - v[966][10] = 655; - v[967][10] = 1633; - v[968][10] = 1003; - v[969][10] = 91; - v[970][10] = 1123; - v[971][10] = 477; - v[972][10] = 1741; - v[973][10] = 1663; - v[974][10] = 35; - v[975][10] = 715; - v[976][10] = 37; - v[977][10] = 1513; - v[978][10] = 815; - v[979][10] = 941; - v[980][10] = 1379; - v[981][10] = 263; - v[982][10] = 1831; - v[983][10] = 1735; - v[984][10] = 1111; - v[985][10] = 1449; - v[986][10] = 353; - v[987][10] = 1941; - v[988][10] = 1655; - v[989][10] = 1349; - v[990][10] = 877; - v[991][10] = 285; - v[992][10] = 1723; - v[993][10] = 125; - v[994][10] = 1753; - v[995][10] = 985; - v[996][10] = 723; - v[997][10] = 175; - v[998][10] = 439; - v[999][10] = 791; - v[1000][10] = 1051; - v[1001][10] = 1261; - v[1002][10] = 717; - v[1003][10] = 1555; - v[1004][10] = 1757; - v[1005][10] = 1777; - v[1006][10] = 577; - v[1007][10] = 1583; - v[1008][10] = 1957; - v[1009][10] = 873; - v[1010][10] = 331; - v[1011][10] = 1163; - v[1012][10] = 313; - v[1013][10] = 1; - v[1014][10] = 1963; - v[1015][10] = 963; - v[1016][10] = 1905; - v[1017][10] = 821; - v[1018][10] = 1677; - v[1019][10] = 185; - v[1020][10] = 709; - v[1021][10] = 545; - v[1022][10] = 1723; - v[1023][10] = 215; - v[1024][10] = 1885; - v[1025][10] = 1249; - v[1026][10] = 583; - v[1027][10] = 1803; - v[1028][10] = 839; - v[1029][10] = 885; - v[1030][10] = 485; - v[1031][10] = 413; - v[1032][10] = 1767; - v[1033][10] = 425; - v[1034][10] = 129; - v[1035][10] = 1035; - v[1036][10] = 329; - v[1037][10] = 1263; - v[1038][10] = 1881; - v[1039][10] = 1779; - v[1040][10] = 1565; - v[1041][10] = 359; - v[1042][10] = 367; - v[1043][10] = 453; - v[1044][10] = 707; - v[1045][10] = 1419; - v[1046][10] = 831; - v[1047][10] = 1889; - v[1048][10] = 887; - v[1049][10] = 1871; - v[1050][10] = 1869; - v[1051][10] = 747; - v[1052][10] = 223; - v[1053][10] = 1547; - v[1054][10] = 1799; - v[1055][10] = 433; - v[1056][10] = 1441; - v[1057][10] = 553; - v[1058][10] = 2021; - v[1059][10] = 1303; - v[1060][10] = 1505; - v[1061][10] = 1735; - v[1062][10] = 1619; - v[1063][10] = 1065; - v[1064][10] = 1161; - v[1065][10] = 2047; - v[1066][10] = 347; - v[1067][10] = 867; - v[1068][10] = 881; - v[1069][10] = 1447; - v[1070][10] = 329; - v[1071][10] = 781; - v[1072][10] = 1065; - v[1073][10] = 219; - v[1074][10] = 589; - v[1075][10] = 645; - v[1076][10] = 1257; - v[1077][10] = 1833; - v[1078][10] = 749; - v[1079][10] = 1841; - v[1080][10] = 1733; - v[1081][10] = 1179; - v[1082][10] = 1191; - v[1083][10] = 1025; - v[1084][10] = 1639; - v[1085][10] = 1955; - v[1086][10] = 1423; - v[1087][10] = 1685; - v[1088][10] = 1711; - v[1089][10] = 493; - v[1090][10] = 549; - v[1091][10] = 783; - v[1092][10] = 1653; - v[1093][10] = 397; - v[1094][10] = 895; - v[1095][10] = 233; - v[1096][10] = 759; - v[1097][10] = 1505; - v[1098][10] = 677; - v[1099][10] = 1449; - v[1100][10] = 1573; - v[1101][10] = 1297; - v[1102][10] = 1821; - v[1103][10] = 1691; - v[1104][10] = 791; - v[1105][10] = 289; - v[1106][10] = 1187; - v[1107][10] = 867; - v[1108][10] = 1535; - v[1109][10] = 575; - v[1110][10] = 183; - - v[337][11] = 3915; - v[338][11] = 97; - v[339][11] = 3047; - v[340][11] = 937; - v[341][11] = 2897; - v[342][11] = 953; - v[343][11] = 127; - v[344][11] = 1201; - v[345][11] = 3819; - v[346][11] = 193; - v[347][11] = 2053; - v[348][11] = 3061; - v[349][11] = 3759; - v[350][11] = 1553; - v[351][11] = 2007; - v[352][11] = 2493; - v[353][11] = 603; - v[354][11] = 3343; - v[355][11] = 3751; - v[356][11] = 1059; - v[357][11] = 783; - v[358][11] = 1789; - v[359][11] = 1589; - v[360][11] = 283; - v[361][11] = 1093; - v[362][11] = 3919; - v[363][11] = 2747; - v[364][11] = 277; - v[365][11] = 2605; - v[366][11] = 2169; - v[367][11] = 2905; - v[368][11] = 721; - v[369][11] = 4069; - v[370][11] = 233; - v[371][11] = 261; - v[372][11] = 1137; - v[373][11] = 3993; - v[374][11] = 3619; - v[375][11] = 2881; - v[376][11] = 1275; - v[377][11] = 3865; - v[378][11] = 1299; - v[379][11] = 3757; - v[380][11] = 1193; - v[381][11] = 733; - v[382][11] = 993; - v[383][11] = 1153; - v[384][11] = 2945; - v[385][11] = 3163; - v[386][11] = 3179; - v[387][11] = 437; - v[388][11] = 271; - v[389][11] = 3493; - v[390][11] = 3971; - v[391][11] = 1005; - v[392][11] = 2615; - v[393][11] = 2253; - v[394][11] = 1131; - v[395][11] = 585; - v[396][11] = 2775; - v[397][11] = 2171; - v[398][11] = 2383; - v[399][11] = 2937; - v[400][11] = 2447; - v[401][11] = 1745; - v[402][11] = 663; - v[403][11] = 1515; - v[404][11] = 3767; - v[405][11] = 2709; - v[406][11] = 1767; - v[407][11] = 3185; - v[408][11] = 3017; - v[409][11] = 2815; - v[410][11] = 1829; - v[411][11] = 87; - v[412][11] = 3341; - v[413][11] = 793; - v[414][11] = 2627; - v[415][11] = 2169; - v[416][11] = 1875; - v[417][11] = 3745; - v[418][11] = 367; - v[419][11] = 3783; - v[420][11] = 783; - v[421][11] = 827; - v[422][11] = 3253; - v[423][11] = 2639; - v[424][11] = 2955; - v[425][11] = 3539; - v[426][11] = 1579; - v[427][11] = 2109; - v[428][11] = 379; - v[429][11] = 2939; - v[430][11] = 3019; - v[431][11] = 1999; - v[432][11] = 2253; - v[433][11] = 2911; - v[434][11] = 3733; - v[435][11] = 481; - v[436][11] = 1767; - v[437][11] = 1055; - v[438][11] = 4019; - v[439][11] = 4085; - v[440][11] = 105; - v[441][11] = 1829; - v[442][11] = 2097; - v[443][11] = 2379; - v[444][11] = 1567; - v[445][11] = 2713; - v[446][11] = 737; - v[447][11] = 3423; - v[448][11] = 3941; - v[449][11] = 2659; - v[450][11] = 3961; - v[451][11] = 1755; - v[452][11] = 3613; - v[453][11] = 1937; - v[454][11] = 1559; - v[455][11] = 2287; - v[456][11] = 2743; - v[457][11] = 67; - v[458][11] = 2859; - v[459][11] = 325; - v[460][11] = 2601; - v[461][11] = 1149; - v[462][11] = 3259; - v[463][11] = 2403; - v[464][11] = 3947; - v[465][11] = 2011; - v[466][11] = 175; - v[467][11] = 3389; - v[468][11] = 3915; - v[469][11] = 1315; - v[470][11] = 2447; - v[471][11] = 141; - v[472][11] = 359; - v[473][11] = 3609; - v[474][11] = 3933; - v[475][11] = 729; - v[476][11] = 2051; - v[477][11] = 1755; - v[478][11] = 2149; - v[479][11] = 2107; - v[480][11] = 1741; - v[481][11] = 1051; - v[482][11] = 3681; - v[483][11] = 471; - v[484][11] = 1055; - v[485][11] = 845; - v[486][11] = 257; - v[487][11] = 1559; - v[488][11] = 1061; - v[489][11] = 2803; - v[490][11] = 2219; - v[491][11] = 1315; - v[492][11] = 1369; - v[493][11] = 3211; - v[494][11] = 4027; - v[495][11] = 105; - v[496][11] = 11; - v[497][11] = 1077; - v[498][11] = 2857; - v[499][11] = 337; - v[500][11] = 3553; - v[501][11] = 3503; - v[502][11] = 3917; - v[503][11] = 2665; - v[504][11] = 3823; - v[505][11] = 3403; - v[506][11] = 3711; - v[507][11] = 2085; - v[508][11] = 1103; - v[509][11] = 1641; - v[510][11] = 701; - v[511][11] = 4095; - v[512][11] = 2883; - v[513][11] = 1435; - v[514][11] = 653; - v[515][11] = 2363; - v[516][11] = 1597; - v[517][11] = 767; - v[518][11] = 869; - v[519][11] = 1825; - v[520][11] = 1117; - v[521][11] = 1297; - v[522][11] = 501; - v[523][11] = 505; - v[524][11] = 149; - v[525][11] = 873; - v[526][11] = 2673; - v[527][11] = 551; - v[528][11] = 1499; - v[529][11] = 2793; - v[530][11] = 3277; - v[531][11] = 2143; - v[532][11] = 3663; - v[533][11] = 533; - v[534][11] = 3991; - v[535][11] = 575; - v[536][11] = 1877; - v[537][11] = 1009; - v[538][11] = 3929; - v[539][11] = 473; - v[540][11] = 3009; - v[541][11] = 2595; - v[542][11] = 3249; - v[543][11] = 675; - v[544][11] = 3593; - v[545][11] = 2453; - v[546][11] = 1567; - v[547][11] = 973; - v[548][11] = 595; - v[549][11] = 1335; - v[550][11] = 1715; - v[551][11] = 589; - v[552][11] = 85; - v[553][11] = 2265; - v[554][11] = 3069; - v[555][11] = 461; - v[556][11] = 1659; - v[557][11] = 2627; - v[558][11] = 1307; - v[559][11] = 1731; - v[560][11] = 1501; - v[561][11] = 1699; - v[562][11] = 3545; - v[563][11] = 3803; - v[564][11] = 2157; - v[565][11] = 453; - v[566][11] = 2813; - v[567][11] = 2047; - v[568][11] = 2999; - v[569][11] = 3841; - v[570][11] = 2361; - v[571][11] = 1079; - v[572][11] = 573; - v[573][11] = 69; - v[574][11] = 1363; - v[575][11] = 1597; - v[576][11] = 3427; - v[577][11] = 2899; - v[578][11] = 2771; - v[579][11] = 1327; - v[580][11] = 1117; - v[581][11] = 1523; - v[582][11] = 3521; - v[583][11] = 2393; - v[584][11] = 2537; - v[585][11] = 1979; - v[586][11] = 3179; - v[587][11] = 683; - v[588][11] = 2453; - v[589][11] = 453; - v[590][11] = 1227; - v[591][11] = 779; - v[592][11] = 671; - v[593][11] = 3483; - v[594][11] = 2135; - v[595][11] = 3139; - v[596][11] = 3381; - v[597][11] = 3945; - v[598][11] = 57; - v[599][11] = 1541; - v[600][11] = 3405; - v[601][11] = 3381; - v[602][11] = 2371; - v[603][11] = 2879; - v[604][11] = 1985; - v[605][11] = 987; - v[606][11] = 3017; - v[607][11] = 3031; - v[608][11] = 3839; - v[609][11] = 1401; - v[610][11] = 3749; - v[611][11] = 2977; - v[612][11] = 681; - v[613][11] = 1175; - v[614][11] = 1519; - v[615][11] = 3355; - v[616][11] = 907; - v[617][11] = 117; - v[618][11] = 771; - v[619][11] = 3741; - v[620][11] = 3337; - v[621][11] = 1743; - v[622][11] = 1227; - v[623][11] = 3335; - v[624][11] = 2755; - v[625][11] = 1909; - v[626][11] = 3603; - v[627][11] = 2397; - v[628][11] = 653; - v[629][11] = 87; - v[630][11] = 2025; - v[631][11] = 2617; - v[632][11] = 3257; - v[633][11] = 287; - v[634][11] = 3051; - v[635][11] = 3809; - v[636][11] = 897; - v[637][11] = 2215; - v[638][11] = 63; - v[639][11] = 2043; - v[640][11] = 1757; - v[641][11] = 3671; - v[642][11] = 297; - v[643][11] = 3131; - v[644][11] = 1305; - v[645][11] = 293; - v[646][11] = 3865; - v[647][11] = 3173; - v[648][11] = 3397; - v[649][11] = 2269; - v[650][11] = 3673; - v[651][11] = 717; - v[652][11] = 3041; - v[653][11] = 3341; - v[654][11] = 3595; - v[655][11] = 3819; - v[656][11] = 2871; - v[657][11] = 3973; - v[658][11] = 1129; - v[659][11] = 513; - v[660][11] = 871; - v[661][11] = 1485; - v[662][11] = 3977; - v[663][11] = 2473; - v[664][11] = 1171; - v[665][11] = 1143; - v[666][11] = 3063; - v[667][11] = 3547; - v[668][11] = 2183; - v[669][11] = 3993; - v[670][11] = 133; - v[671][11] = 2529; - v[672][11] = 2699; - v[673][11] = 233; - v[674][11] = 2355; - v[675][11] = 231; - v[676][11] = 3241; - v[677][11] = 611; - v[678][11] = 1309; - v[679][11] = 3829; - v[680][11] = 1839; - v[681][11] = 1495; - v[682][11] = 301; - v[683][11] = 1169; - v[684][11] = 1613; - v[685][11] = 2673; - v[686][11] = 243; - v[687][11] = 3601; - v[688][11] = 3669; - v[689][11] = 2813; - v[690][11] = 2671; - v[691][11] = 2679; - v[692][11] = 3463; - v[693][11] = 2477; - v[694][11] = 1795; - v[695][11] = 617; - v[696][11] = 2317; - v[697][11] = 1855; - v[698][11] = 1057; - v[699][11] = 1703; - v[700][11] = 1761; - v[701][11] = 2515; - v[702][11] = 801; - v[703][11] = 1205; - v[704][11] = 1311; - v[705][11] = 473; - v[706][11] = 3963; - v[707][11] = 697; - v[708][11] = 1221; - v[709][11] = 251; - v[710][11] = 381; - v[711][11] = 3887; - v[712][11] = 1761; - v[713][11] = 3093; - v[714][11] = 3721; - v[715][11] = 2079; - v[716][11] = 4085; - v[717][11] = 379; - v[718][11] = 3601; - v[719][11] = 3845; - v[720][11] = 433; - v[721][11] = 1781; - v[722][11] = 29; - v[723][11] = 1897; - v[724][11] = 1599; - v[725][11] = 2163; - v[726][11] = 75; - v[727][11] = 3475; - v[728][11] = 3957; - v[729][11] = 1641; - v[730][11] = 3911; - v[731][11] = 2959; - v[732][11] = 2833; - v[733][11] = 1279; - v[734][11] = 1099; - v[735][11] = 403; - v[736][11] = 799; - v[737][11] = 2183; - v[738][11] = 2699; - v[739][11] = 1711; - v[740][11] = 2037; - v[741][11] = 727; - v[742][11] = 289; - v[743][11] = 1785; - v[744][11] = 1575; - v[745][11] = 3633; - v[746][11] = 2367; - v[747][11] = 1261; - v[748][11] = 3953; - v[749][11] = 1735; - v[750][11] = 171; - v[751][11] = 1959; - v[752][11] = 2867; - v[753][11] = 859; - v[754][11] = 2951; - v[755][11] = 3211; - v[756][11] = 15; - v[757][11] = 1279; - v[758][11] = 1323; - v[759][11] = 599; - v[760][11] = 1651; - v[761][11] = 3951; - v[762][11] = 1011; - v[763][11] = 315; - v[764][11] = 3513; - v[765][11] = 3351; - v[766][11] = 1725; - v[767][11] = 3793; - v[768][11] = 2399; - v[769][11] = 287; - v[770][11] = 4017; - v[771][11] = 3571; - v[772][11] = 1007; - v[773][11] = 541; - v[774][11] = 3115; - v[775][11] = 429; - v[776][11] = 1585; - v[777][11] = 1285; - v[778][11] = 755; - v[779][11] = 1211; - v[780][11] = 3047; - v[781][11] = 915; - v[782][11] = 3611; - v[783][11] = 2697; - v[784][11] = 2129; - v[785][11] = 3669; - v[786][11] = 81; - v[787][11] = 3939; - v[788][11] = 2437; - v[789][11] = 915; - v[790][11] = 779; - v[791][11] = 3567; - v[792][11] = 3701; - v[793][11] = 2479; - v[794][11] = 3807; - v[795][11] = 1893; - v[796][11] = 3927; - v[797][11] = 2619; - v[798][11] = 2543; - v[799][11] = 3633; - v[800][11] = 2007; - v[801][11] = 3857; - v[802][11] = 3837; - v[803][11] = 487; - v[804][11] = 1769; - v[805][11] = 3759; - v[806][11] = 3105; - v[807][11] = 2727; - v[808][11] = 3155; - v[809][11] = 2479; - v[810][11] = 1341; - v[811][11] = 1657; - v[812][11] = 2767; - v[813][11] = 2541; - v[814][11] = 577; - v[815][11] = 2105; - v[816][11] = 799; - v[817][11] = 17; - v[818][11] = 2871; - v[819][11] = 3637; - v[820][11] = 953; - v[821][11] = 65; - v[822][11] = 69; - v[823][11] = 2897; - v[824][11] = 3841; - v[825][11] = 3559; - v[826][11] = 4067; - v[827][11] = 2335; - v[828][11] = 3409; - v[829][11] = 1087; - v[830][11] = 425; - v[831][11] = 2813; - v[832][11] = 1705; - v[833][11] = 1701; - v[834][11] = 1237; - v[835][11] = 821; - v[836][11] = 1375; - v[837][11] = 3673; - v[838][11] = 2693; - v[839][11] = 3925; - v[840][11] = 1541; - v[841][11] = 1871; - v[842][11] = 2285; - v[843][11] = 847; - v[844][11] = 4035; - v[845][11] = 1101; - v[846][11] = 2029; - v[847][11] = 855; - v[848][11] = 2733; - v[849][11] = 2503; - v[850][11] = 121; - v[851][11] = 2855; - v[852][11] = 1069; - v[853][11] = 3463; - v[854][11] = 3505; - v[855][11] = 1539; - v[856][11] = 607; - v[857][11] = 1349; - v[858][11] = 575; - v[859][11] = 2301; - v[860][11] = 2321; - v[861][11] = 1101; - v[862][11] = 333; - v[863][11] = 291; - v[864][11] = 2171; - v[865][11] = 4085; - v[866][11] = 2173; - v[867][11] = 2541; - v[868][11] = 1195; - v[869][11] = 925; - v[870][11] = 4039; - v[871][11] = 1379; - v[872][11] = 699; - v[873][11] = 1979; - v[874][11] = 275; - v[875][11] = 953; - v[876][11] = 1755; - v[877][11] = 1643; - v[878][11] = 325; - v[879][11] = 101; - v[880][11] = 2263; - v[881][11] = 3329; - v[882][11] = 3673; - v[883][11] = 3413; - v[884][11] = 1977; - v[885][11] = 2727; - v[886][11] = 2313; - v[887][11] = 1419; - v[888][11] = 887; - v[889][11] = 609; - v[890][11] = 2475; - v[891][11] = 591; - v[892][11] = 2613; - v[893][11] = 2081; - v[894][11] = 3805; - v[895][11] = 3435; - v[896][11] = 2409; - v[897][11] = 111; - v[898][11] = 3557; - v[899][11] = 3607; - v[900][11] = 903; - v[901][11] = 231; - v[902][11] = 3059; - v[903][11] = 473; - v[904][11] = 2959; - v[905][11] = 2925; - v[906][11] = 3861; - v[907][11] = 2043; - v[908][11] = 3887; - v[909][11] = 351; - v[910][11] = 2865; - v[911][11] = 369; - v[912][11] = 1377; - v[913][11] = 2639; - v[914][11] = 1261; - v[915][11] = 3625; - v[916][11] = 3279; - v[917][11] = 2201; - v[918][11] = 2949; - v[919][11] = 3049; - v[920][11] = 449; - v[921][11] = 1297; - v[922][11] = 897; - v[923][11] = 1891; - v[924][11] = 411; - v[925][11] = 2773; - v[926][11] = 749; - v[927][11] = 2753; - v[928][11] = 1825; - v[929][11] = 853; - v[930][11] = 2775; - v[931][11] = 3547; - v[932][11] = 3923; - v[933][11] = 3923; - v[934][11] = 987; - v[935][11] = 3723; - v[936][11] = 2189; - v[937][11] = 3877; - v[938][11] = 3577; - v[939][11] = 297; - v[940][11] = 2763; - v[941][11] = 1845; - v[942][11] = 3083; - v[943][11] = 2951; - v[944][11] = 483; - v[945][11] = 2169; - v[946][11] = 3985; - v[947][11] = 245; - v[948][11] = 3655; - v[949][11] = 3441; - v[950][11] = 1023; - v[951][11] = 235; - v[952][11] = 835; - v[953][11] = 3693; - v[954][11] = 3585; - v[955][11] = 327; - v[956][11] = 1003; - v[957][11] = 543; - v[958][11] = 3059; - v[959][11] = 2637; - v[960][11] = 2923; - v[961][11] = 87; - v[962][11] = 3617; - v[963][11] = 1031; - v[964][11] = 1043; - v[965][11] = 903; - v[966][11] = 2913; - v[967][11] = 2177; - v[968][11] = 2641; - v[969][11] = 3279; - v[970][11] = 389; - v[971][11] = 2009; - v[972][11] = 525; - v[973][11] = 4085; - v[974][11] = 3299; - v[975][11] = 987; - v[976][11] = 2409; - v[977][11] = 813; - v[978][11] = 2683; - v[979][11] = 373; - v[980][11] = 2695; - v[981][11] = 3775; - v[982][11] = 2375; - v[983][11] = 1119; - v[984][11] = 2791; - v[985][11] = 223; - v[986][11] = 325; - v[987][11] = 587; - v[988][11] = 1379; - v[989][11] = 2877; - v[990][11] = 2867; - v[991][11] = 3793; - v[992][11] = 655; - v[993][11] = 831; - v[994][11] = 3425; - v[995][11] = 1663; - v[996][11] = 1681; - v[997][11] = 2657; - v[998][11] = 1865; - v[999][11] = 3943; - v[1000][11] = 2977; - v[1001][11] = 1979; - v[1002][11] = 2271; - v[1003][11] = 3247; - v[1004][11] = 1267; - v[1005][11] = 1747; - v[1006][11] = 811; - v[1007][11] = 159; - v[1008][11] = 429; - v[1009][11] = 2001; - v[1010][11] = 1195; - v[1011][11] = 3065; - v[1012][11] = 553; - v[1013][11] = 1499; - v[1014][11] = 3529; - v[1015][11] = 1081; - v[1016][11] = 2877; - v[1017][11] = 3077; - v[1018][11] = 845; - v[1019][11] = 1793; - v[1020][11] = 2409; - v[1021][11] = 3995; - v[1022][11] = 2559; - v[1023][11] = 4081; - v[1024][11] = 1195; - v[1025][11] = 2955; - v[1026][11] = 1117; - v[1027][11] = 1409; - v[1028][11] = 785; - v[1029][11] = 287; - v[1030][11] = 1521; - v[1031][11] = 1607; - v[1032][11] = 85; - v[1033][11] = 3055; - v[1034][11] = 3123; - v[1035][11] = 2533; - v[1036][11] = 2329; - v[1037][11] = 3477; - v[1038][11] = 799; - v[1039][11] = 3683; - v[1040][11] = 3715; - v[1041][11] = 337; - v[1042][11] = 3139; - v[1043][11] = 3311; - v[1044][11] = 431; - v[1045][11] = 3511; - v[1046][11] = 2299; - v[1047][11] = 365; - v[1048][11] = 2941; - v[1049][11] = 3067; - v[1050][11] = 1331; - v[1051][11] = 1081; - v[1052][11] = 1097; - v[1053][11] = 2853; - v[1054][11] = 2299; - v[1055][11] = 495; - v[1056][11] = 1745; - v[1057][11] = 749; - v[1058][11] = 3819; - v[1059][11] = 619; - v[1060][11] = 1059; - v[1061][11] = 3559; - v[1062][11] = 183; - v[1063][11] = 3743; - v[1064][11] = 723; - v[1065][11] = 949; - v[1066][11] = 3501; - v[1067][11] = 733; - v[1068][11] = 2599; - v[1069][11] = 3983; - v[1070][11] = 3961; - v[1071][11] = 911; - v[1072][11] = 1899; - v[1073][11] = 985; - v[1074][11] = 2493; - v[1075][11] = 1795; - v[1076][11] = 653; - v[1077][11] = 157; - v[1078][11] = 433; - v[1079][11] = 2361; - v[1080][11] = 3093; - v[1081][11] = 3119; - v[1082][11] = 3679; - v[1083][11] = 2367; - v[1084][11] = 1701; - v[1085][11] = 1445; - v[1086][11] = 1321; - v[1087][11] = 2397; - v[1088][11] = 1241; - v[1089][11] = 3305; - v[1090][11] = 3985; - v[1091][11] = 2349; - v[1092][11] = 4067; - v[1093][11] = 3805; - v[1094][11] = 3073; - v[1095][11] = 2837; - v[1096][11] = 1567; - v[1097][11] = 3783; - v[1098][11] = 451; - v[1099][11] = 2441; - v[1100][11] = 1181; - v[1101][11] = 487; - v[1102][11] = 543; - v[1103][11] = 1201; - v[1104][11] = 3735; - v[1105][11] = 2517; - v[1106][11] = 733; - v[1107][11] = 1535; - v[1108][11] = 2175; - v[1109][11] = 3613; - v[1110][11] = 3019; - - v[481][12] = 2319; - v[482][12] = 653; - v[483][12] = 1379; - v[484][12] = 1675; - v[485][12] = 1951; - v[486][12] = 7075; - v[487][12] = 2087; - v[488][12] = 7147; - v[489][12] = 1427; - v[490][12] = 893; - v[491][12] = 171; - v[492][12] = 2019; - v[493][12] = 7235; - v[494][12] = 5697; - v[495][12] = 3615; - v[496][12] = 1961; - v[497][12] = 7517; - v[498][12] = 6849; - v[499][12] = 2893; - v[500][12] = 1883; - v[501][12] = 2863; - v[502][12] = 2173; - v[503][12] = 4543; - v[504][12] = 73; - v[505][12] = 381; - v[506][12] = 3893; - v[507][12] = 6045; - v[508][12] = 1643; - v[509][12] = 7669; - v[510][12] = 1027; - v[511][12] = 1549; - v[512][12] = 3983; - v[513][12] = 1985; - v[514][12] = 6589; - v[515][12] = 7497; - v[516][12] = 2745; - v[517][12] = 2375; - v[518][12] = 7047; - v[519][12] = 1117; - v[520][12] = 1171; - v[521][12] = 1975; - v[522][12] = 5199; - v[523][12] = 3915; - v[524][12] = 3695; - v[525][12] = 8113; - v[526][12] = 4303; - v[527][12] = 3773; - v[528][12] = 7705; - v[529][12] = 6855; - v[530][12] = 1675; - v[531][12] = 2245; - v[532][12] = 2817; - v[533][12] = 1719; - v[534][12] = 569; - v[535][12] = 1021; - v[536][12] = 2077; - v[537][12] = 5945; - v[538][12] = 1833; - v[539][12] = 2631; - v[540][12] = 4851; - v[541][12] = 6371; - v[542][12] = 833; - v[543][12] = 7987; - v[544][12] = 331; - v[545][12] = 1899; - v[546][12] = 8093; - v[547][12] = 6719; - v[548][12] = 6903; - v[549][12] = 5903; - v[550][12] = 5657; - v[551][12] = 5007; - v[552][12] = 2689; - v[553][12] = 6637; - v[554][12] = 2675; - v[555][12] = 1645; - v[556][12] = 1819; - v[557][12] = 689; - v[558][12] = 6709; - v[559][12] = 7717; - v[560][12] = 6295; - v[561][12] = 7013; - v[562][12] = 7695; - v[563][12] = 3705; - v[564][12] = 7069; - v[565][12] = 2621; - v[566][12] = 3631; - v[567][12] = 6571; - v[568][12] = 6259; - v[569][12] = 7261; - v[570][12] = 3397; - v[571][12] = 7645; - v[572][12] = 1115; - v[573][12] = 4753; - v[574][12] = 2047; - v[575][12] = 7579; - v[576][12] = 2271; - v[577][12] = 5403; - v[578][12] = 4911; - v[579][12] = 7629; - v[580][12] = 4225; - v[581][12] = 1209; - v[582][12] = 6955; - v[583][12] = 6951; - v[584][12] = 1829; - v[585][12] = 5579; - v[586][12] = 5231; - v[587][12] = 1783; - v[588][12] = 4285; - v[589][12] = 7425; - v[590][12] = 599; - v[591][12] = 5785; - v[592][12] = 3275; - v[593][12] = 5643; - v[594][12] = 2263; - v[595][12] = 657; - v[596][12] = 6769; - v[597][12] = 6261; - v[598][12] = 1251; - v[599][12] = 3249; - v[600][12] = 4447; - v[601][12] = 4111; - v[602][12] = 3991; - v[603][12] = 1215; - v[604][12] = 131; - v[605][12] = 4397; - v[606][12] = 3487; - v[607][12] = 7585; - v[608][12] = 5565; - v[609][12] = 7199; - v[610][12] = 3573; - v[611][12] = 7105; - v[612][12] = 7409; - v[613][12] = 1671; - v[614][12] = 949; - v[615][12] = 3889; - v[616][12] = 5971; - v[617][12] = 3333; - v[618][12] = 225; - v[619][12] = 3647; - v[620][12] = 5403; - v[621][12] = 3409; - v[622][12] = 7459; - v[623][12] = 6879; - v[624][12] = 5789; - v[625][12] = 6567; - v[626][12] = 5581; - v[627][12] = 4919; - v[628][12] = 1927; - v[629][12] = 4407; - v[630][12] = 8085; - v[631][12] = 4691; - v[632][12] = 611; - v[633][12] = 3005; - v[634][12] = 591; - v[635][12] = 753; - v[636][12] = 589; - v[637][12] = 171; - v[638][12] = 5729; - v[639][12] = 5891; - v[640][12] = 1033; - v[641][12] = 3049; - v[642][12] = 6567; - v[643][12] = 5257; - v[644][12] = 8003; - v[645][12] = 1757; - v[646][12] = 4489; - v[647][12] = 4923; - v[648][12] = 6379; - v[649][12] = 5171; - v[650][12] = 1757; - v[651][12] = 689; - v[652][12] = 3081; - v[653][12] = 1389; - v[654][12] = 4113; - v[655][12] = 455; - v[656][12] = 2761; - v[657][12] = 847; - v[658][12] = 7575; - v[659][12] = 5829; - v[660][12] = 633; - v[661][12] = 6629; - v[662][12] = 1103; - v[663][12] = 7635; - v[664][12] = 803; - v[665][12] = 6175; - v[666][12] = 6587; - v[667][12] = 2711; - v[668][12] = 3879; - v[669][12] = 67; - v[670][12] = 1179; - v[671][12] = 4761; - v[672][12] = 7281; - v[673][12] = 1557; - v[674][12] = 3379; - v[675][12] = 2459; - v[676][12] = 4273; - v[677][12] = 4127; - v[678][12] = 7147; - v[679][12] = 35; - v[680][12] = 3549; - v[681][12] = 395; - v[682][12] = 3735; - v[683][12] = 5787; - v[684][12] = 4179; - v[685][12] = 5889; - v[686][12] = 5057; - v[687][12] = 7473; - v[688][12] = 4713; - v[689][12] = 2133; - v[690][12] = 2897; - v[691][12] = 1841; - v[692][12] = 2125; - v[693][12] = 1029; - v[694][12] = 1695; - v[695][12] = 6523; - v[696][12] = 1143; - v[697][12] = 5105; - v[698][12] = 7133; - v[699][12] = 3351; - v[700][12] = 2775; - v[701][12] = 3971; - v[702][12] = 4503; - v[703][12] = 7589; - v[704][12] = 5155; - v[705][12] = 4305; - v[706][12] = 1641; - v[707][12] = 4717; - v[708][12] = 2427; - v[709][12] = 5617; - v[710][12] = 1267; - v[711][12] = 399; - v[712][12] = 5831; - v[713][12] = 4305; - v[714][12] = 4241; - v[715][12] = 3395; - v[716][12] = 3045; - v[717][12] = 4899; - v[718][12] = 1713; - v[719][12] = 171; - v[720][12] = 411; - v[721][12] = 7099; - v[722][12] = 5473; - v[723][12] = 5209; - v[724][12] = 1195; - v[725][12] = 1077; - v[726][12] = 1309; - v[727][12] = 2953; - v[728][12] = 7343; - v[729][12] = 4887; - v[730][12] = 3229; - v[731][12] = 6759; - v[732][12] = 6721; - v[733][12] = 6775; - v[734][12] = 675; - v[735][12] = 4039; - v[736][12] = 2493; - v[737][12] = 7511; - v[738][12] = 3269; - v[739][12] = 4199; - v[740][12] = 6625; - v[741][12] = 7943; - v[742][12] = 2013; - v[743][12] = 4145; - v[744][12] = 667; - v[745][12] = 513; - v[746][12] = 2303; - v[747][12] = 4591; - v[748][12] = 7941; - v[749][12] = 2741; - v[750][12] = 987; - v[751][12] = 8061; - v[752][12] = 3161; - v[753][12] = 5951; - v[754][12] = 1431; - v[755][12] = 831; - v[756][12] = 5559; - v[757][12] = 7405; - v[758][12] = 1357; - v[759][12] = 4319; - v[760][12] = 4235; - v[761][12] = 5421; - v[762][12] = 2559; - v[763][12] = 4415; - v[764][12] = 2439; - v[765][12] = 823; - v[766][12] = 1725; - v[767][12] = 6219; - v[768][12] = 4903; - v[769][12] = 6699; - v[770][12] = 5451; - v[771][12] = 349; - v[772][12] = 7703; - v[773][12] = 2927; - v[774][12] = 7809; - v[775][12] = 6179; - v[776][12] = 1417; - v[777][12] = 5987; - v[778][12] = 3017; - v[779][12] = 4983; - v[780][12] = 3479; - v[781][12] = 4525; - v[782][12] = 4643; - v[783][12] = 4911; - v[784][12] = 227; - v[785][12] = 5475; - v[786][12] = 2287; - v[787][12] = 5581; - v[788][12] = 6817; - v[789][12] = 1937; - v[790][12] = 1421; - v[791][12] = 4415; - v[792][12] = 7977; - v[793][12] = 1789; - v[794][12] = 3907; - v[795][12] = 6815; - v[796][12] = 6789; - v[797][12] = 6003; - v[798][12] = 5609; - v[799][12] = 4507; - v[800][12] = 337; - v[801][12] = 7427; - v[802][12] = 7943; - v[803][12] = 3075; - v[804][12] = 6427; - v[805][12] = 1019; - v[806][12] = 7121; - v[807][12] = 4763; - v[808][12] = 81; - v[809][12] = 3587; - v[810][12] = 2929; - v[811][12] = 1795; - v[812][12] = 8067; - v[813][12] = 2415; - v[814][12] = 1265; - v[815][12] = 4025; - v[816][12] = 5599; - v[817][12] = 4771; - v[818][12] = 3025; - v[819][12] = 2313; - v[820][12] = 6129; - v[821][12] = 7611; - v[822][12] = 6881; - v[823][12] = 5253; - v[824][12] = 4413; - v[825][12] = 7869; - v[826][12] = 105; - v[827][12] = 3173; - v[828][12] = 1629; - v[829][12] = 2537; - v[830][12] = 1023; - v[831][12] = 4409; - v[832][12] = 7209; - v[833][12] = 4413; - v[834][12] = 7107; - v[835][12] = 7469; - v[836][12] = 33; - v[837][12] = 1955; - v[838][12] = 2881; - v[839][12] = 5167; - v[840][12] = 6451; - v[841][12] = 4211; - v[842][12] = 179; - v[843][12] = 5573; - v[844][12] = 7879; - v[845][12] = 3387; - v[846][12] = 7759; - v[847][12] = 5455; - v[848][12] = 7157; - v[849][12] = 1891; - v[850][12] = 5683; - v[851][12] = 5689; - v[852][12] = 6535; - v[853][12] = 3109; - v[854][12] = 6555; - v[855][12] = 6873; - v[856][12] = 1249; - v[857][12] = 4251; - v[858][12] = 6437; - v[859][12] = 49; - v[860][12] = 2745; - v[861][12] = 1201; - v[862][12] = 7327; - v[863][12] = 4179; - v[864][12] = 6783; - v[865][12] = 623; - v[866][12] = 2779; - v[867][12] = 5963; - v[868][12] = 2585; - v[869][12] = 6927; - v[870][12] = 5333; - v[871][12] = 4033; - v[872][12] = 285; - v[873][12] = 7467; - v[874][12] = 4443; - v[875][12] = 4917; - v[876][12] = 3; - v[877][12] = 4319; - v[878][12] = 5517; - v[879][12] = 3449; - v[880][12] = 813; - v[881][12] = 5499; - v[882][12] = 2515; - v[883][12] = 5771; - v[884][12] = 3357; - v[885][12] = 2073; - v[886][12] = 4395; - v[887][12] = 4925; - v[888][12] = 2643; - v[889][12] = 7215; - v[890][12] = 5817; - v[891][12] = 1199; - v[892][12] = 1597; - v[893][12] = 1619; - v[894][12] = 7535; - v[895][12] = 4833; - v[896][12] = 609; - v[897][12] = 4797; - v[898][12] = 8171; - v[899][12] = 6847; - v[900][12] = 793; - v[901][12] = 6757; - v[902][12] = 8165; - v[903][12] = 3371; - v[904][12] = 2431; - v[905][12] = 5235; - v[906][12] = 4739; - v[907][12] = 7703; - v[908][12] = 7223; - v[909][12] = 6525; - v[910][12] = 5891; - v[911][12] = 5605; - v[912][12] = 4433; - v[913][12] = 3533; - v[914][12] = 5267; - v[915][12] = 5125; - v[916][12] = 5037; - v[917][12] = 225; - v[918][12] = 6717; - v[919][12] = 1121; - v[920][12] = 5741; - v[921][12] = 2013; - v[922][12] = 4327; - v[923][12] = 4839; - v[924][12] = 569; - v[925][12] = 5227; - v[926][12] = 7677; - v[927][12] = 4315; - v[928][12] = 2391; - v[929][12] = 5551; - v[930][12] = 859; - v[931][12] = 3627; - v[932][12] = 6377; - v[933][12] = 3903; - v[934][12] = 4311; - v[935][12] = 6527; - v[936][12] = 7573; - v[937][12] = 4905; - v[938][12] = 7731; - v[939][12] = 1909; - v[940][12] = 1555; - v[941][12] = 3279; - v[942][12] = 1949; - v[943][12] = 1887; - v[944][12] = 6675; - v[945][12] = 5509; - v[946][12] = 2033; - v[947][12] = 5473; - v[948][12] = 3539; - v[949][12] = 5033; - v[950][12] = 5935; - v[951][12] = 6095; - v[952][12] = 4761; - v[953][12] = 1771; - v[954][12] = 1271; - v[955][12] = 1717; - v[956][12] = 4415; - v[957][12] = 5083; - v[958][12] = 6277; - v[959][12] = 3147; - v[960][12] = 7695; - v[961][12] = 2461; - v[962][12] = 4783; - v[963][12] = 4539; - v[964][12] = 5833; - v[965][12] = 5583; - v[966][12] = 651; - v[967][12] = 1419; - v[968][12] = 2605; - v[969][12] = 5511; - v[970][12] = 3913; - v[971][12] = 5795; - v[972][12] = 2333; - v[973][12] = 2329; - v[974][12] = 4431; - v[975][12] = 3725; - v[976][12] = 6069; - v[977][12] = 2699; - v[978][12] = 7055; - v[979][12] = 6879; - v[980][12] = 1017; - v[981][12] = 3121; - v[982][12] = 2547; - v[983][12] = 4603; - v[984][12] = 2385; - v[985][12] = 6915; - v[986][12] = 6103; - v[987][12] = 5669; - v[988][12] = 7833; - v[989][12] = 2001; - v[990][12] = 4287; - v[991][12] = 6619; - v[992][12] = 955; - v[993][12] = 2761; - v[994][12] = 5711; - v[995][12] = 6291; - v[996][12] = 3415; - v[997][12] = 3909; - v[998][12] = 2841; - v[999][12] = 5627; - v[1000][12] = 4939; - v[1001][12] = 7671; - v[1002][12] = 6059; - v[1003][12] = 6275; - v[1004][12] = 6517; - v[1005][12] = 1931; - v[1006][12] = 4583; - v[1007][12] = 7301; - v[1008][12] = 1267; - v[1009][12] = 7509; - v[1010][12] = 1435; - v[1011][12] = 2169; - v[1012][12] = 6939; - v[1013][12] = 3515; - v[1014][12] = 2985; - v[1015][12] = 2787; - v[1016][12] = 2123; - v[1017][12] = 1969; - v[1018][12] = 3307; - v[1019][12] = 353; - v[1020][12] = 4359; - v[1021][12] = 7059; - v[1022][12] = 5273; - v[1023][12] = 5873; - v[1024][12] = 6657; - v[1025][12] = 6765; - v[1026][12] = 6229; - v[1027][12] = 3179; - v[1028][12] = 1583; - v[1029][12] = 6237; - v[1030][12] = 2155; - v[1031][12] = 371; - v[1032][12] = 273; - v[1033][12] = 7491; - v[1034][12] = 3309; - v[1035][12] = 6805; - v[1036][12] = 3015; - v[1037][12] = 6831; - v[1038][12] = 7819; - v[1039][12] = 713; - v[1040][12] = 4747; - v[1041][12] = 3935; - v[1042][12] = 4109; - v[1043][12] = 1311; - v[1044][12] = 709; - v[1045][12] = 3089; - v[1046][12] = 7059; - v[1047][12] = 4247; - v[1048][12] = 2989; - v[1049][12] = 1509; - v[1050][12] = 4919; - v[1051][12] = 1841; - v[1052][12] = 3045; - v[1053][12] = 3821; - v[1054][12] = 6929; - v[1055][12] = 4655; - v[1056][12] = 1333; - v[1057][12] = 6429; - v[1058][12] = 6649; - v[1059][12] = 2131; - v[1060][12] = 5265; - v[1061][12] = 1051; - v[1062][12] = 261; - v[1063][12] = 8057; - v[1064][12] = 3379; - v[1065][12] = 2179; - v[1066][12] = 1993; - v[1067][12] = 5655; - v[1068][12] = 3063; - v[1069][12] = 6381; - v[1070][12] = 3587; - v[1071][12] = 7417; - v[1072][12] = 1579; - v[1073][12] = 1541; - v[1074][12] = 2107; - v[1075][12] = 5085; - v[1076][12] = 2873; - v[1077][12] = 6141; - v[1078][12] = 955; - v[1079][12] = 3537; - v[1080][12] = 2157; - v[1081][12] = 841; - v[1082][12] = 1999; - v[1083][12] = 1465; - v[1084][12] = 5171; - v[1085][12] = 5651; - v[1086][12] = 1535; - v[1087][12] = 7235; - v[1088][12] = 4349; - v[1089][12] = 1263; - v[1090][12] = 1453; - v[1091][12] = 1005; - v[1092][12] = 6893; - v[1093][12] = 2919; - v[1094][12] = 1947; - v[1095][12] = 1635; - v[1096][12] = 3963; - v[1097][12] = 397; - v[1098][12] = 969; - v[1099][12] = 4569; - v[1100][12] = 655; - v[1101][12] = 6737; - v[1102][12] = 2995; - v[1103][12] = 7235; - v[1104][12] = 7713; - v[1105][12] = 973; - v[1106][12] = 4821; - v[1107][12] = 2377; - v[1108][12] = 1673; - v[1109][12] = 1; - v[1110][12] = 6541; \ No newline at end of file diff --git a/mex/sources/sobol/qmc_sequence.cc b/mex/sources/sobol/qmc_sequence.cc index a3856517fcc7b00ac82143950e9839b8bcd9fdd0..237fb0019cb6d69bb51e1a671695ddd4c2712bde 100644 --- a/mex/sources/sobol/qmc_sequence.cc +++ b/mex/sources/sobol/qmc_sequence.cc @@ -1,7 +1,7 @@ /* ** Computes Quasi Monte-Carlo sequence. ** -** Copyright © 2010-2022 Dynare Team +** Copyright © 2010-2023 Dynare Team ** ** This file is part of Dynare (can be used outside Dynare). ** @@ -73,7 +73,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) if (!(mxIsNumeric(prhs[1]) && mxIsClass(prhs[1], "int64"))) mexErrMsgTxt("qmc_sequence:: Second input (seed) has to be an integer [int64]!"); - int64_T seed = static_cast<int64_T>(mxGetScalar(prhs[1])); +#if MX_HAS_INTERLEAVED_COMPLEX + int64_T seed = *mxGetInt64s(prhs[1]); +#else + int64_T seed = *static_cast<int64_T *>(mxGetData(prhs[1])); +#endif + /* ** Test the third input argument and assign it to type (kind of QMC sequence). */ diff --git a/mex/sources/sobol/sobol.f08 b/mex/sources/sobol/sobol.f08 new file mode 100644 index 0000000000000000000000000000000000000000..e1ada3fd32139d3043fb0816b557568d1edb3d25 --- /dev/null +++ b/mex/sources/sobol/sobol.f08 @@ -0,0 +1,1347 @@ +! Quasi Monte Carlo sequences (à la Sobol) +! +! This is a modified version of the file available at: +! https://people.sc.fsu.edu/~jburkardt/f_src/sobol/sobol.f90 +! The following modifications were made: +! – only the routine i8_sobol and its callees were kept; +! – various Fortran 2018 modernizations were applied. + +! Copyright © 2004-2009 John Burkardt +! Copyright © 2023 Dynare Team +! +! This program is free software: you can redistribute it and/or modify +! it under the terms of the GNU Lesser General Public License as published by +! the Free Software Foundation, either version 3 of the License, or +! (at your option) any later version. +! +! This program 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 Lesser General Public License for more details. +! +! You should have received a copy of the GNU Lesser General Public License +! along with this program. If not, see <https://www.gnu.org/licenses/>. + +function i8_bit_hi1 ( n ) + + !*****************************************************************************80 + ! + !! I8_BIT_HI1 returns the position of the high 1 bit base 2 in an integer. + ! + ! Discussion: + ! + ! This routine uses the integer precision corresponding to a KIND of int64. + ! + ! The input arguments to this function should NOT be constants; they should + ! be variables of type integer(int64)! + ! + ! Example: + ! + ! N Binary Hi 1 + ! ---- -------- ---- + ! 0 0 0 + ! 1 1 1 + ! 2 10 2 + ! 3 11 2 + ! 4 100 3 + ! 5 101 3 + ! 6 110 3 + ! 7 111 3 + ! 8 1000 4 + ! 9 1001 4 + ! 10 1010 4 + ! 11 1011 4 + ! 12 1100 4 + ! 13 1101 4 + ! 14 1110 4 + ! 15 1111 4 + ! 16 10000 5 + ! 17 10001 5 + ! 1023 1111111111 10 + ! 1024 10000000000 11 + ! 1025 10000000001 11 + ! + ! Licensing: + ! + ! This code is distributed under the GNU LGPL license. + ! + ! Modified: + ! + ! 28 May 2004 + ! + ! Author: + ! + ! John Burkardt + ! + ! Parameters: + ! + ! Input, integer(int64) N, the integer to be measured. + ! N should be nonnegative. If N is nonpositive, I8_BIT_HI1 + ! will always be 0. + ! + ! Output, integer(int64) I8_BIT_HI1, the number of bits base 2. + + use iso_fortran_env + implicit none (type, external) + + integer(int64) :: bit + integer(int64) :: i8_bit_hi1 + integer(int64) :: i + integer(int64), intent(in) :: n + + i = n + bit = 0 + + do + + if ( i <= 0 ) then + exit + end if + + bit = bit + 1 + i = i / 2 + + end do + + i8_bit_hi1 = bit +end function i8_bit_hi1 + +function i8_bit_lo0 ( n ) + + !*****************************************************************************80 + ! + !! I8_BIT_LO0 returns the position of the low 0 bit base 2 in an integer. + ! + ! Discussion: + ! + ! This routine uses the integer precision corresponding to a KIND of int64. + ! + ! The input arguments to this function should NOT be constants; they should + ! be variables of type integer(int64)! + ! + ! Example: + ! + ! N Binary Lo 0 + ! ---- -------- ---- + ! 0 0 1 + ! 1 1 2 + ! 2 10 1 + ! 3 11 3 + ! 4 100 1 + ! 5 101 2 + ! 6 110 1 + ! 7 111 4 + ! 8 1000 1 + ! 9 1001 2 + ! 10 1010 1 + ! 11 1011 3 + ! 12 1100 1 + ! 13 1101 2 + ! 14 1110 1 + ! 15 1111 5 + ! 16 10000 1 + ! 17 10001 2 + ! 1023 1111111111 1 + ! 1024 10000000000 1 + ! 1025 10000000001 1 + ! + ! Licensing: + ! + ! This code is distributed under the GNU LGPL license. + ! + ! Modified: + ! + ! 28 May 2004 + ! + ! Author: + ! + ! John Burkardt + ! + ! Parameters: + ! + ! Input, integer(int64) N, the integer to be measured. + ! N should be nonnegative. + ! + ! Output, integer(int64) I8_BIT_LO0, the position of the low 1 bit. + + use iso_fortran_env + implicit none (type, external) + + integer(int64) :: bit + integer(int64) :: i + integer(int64) :: i2 + integer(int64) :: i8_bit_lo0 + integer(int64), intent(in) :: n + + bit = 0 + i = n + + do + + bit = bit + 1 + i2 = i / 2 + + if ( i == 2 * i2 ) then + exit + end if + + i = i2 + + end do + + i8_bit_lo0 = bit +end function i8_bit_lo0 + +subroutine i8_sobol ( dim_num, seed, quasi ) + + !*****************************************************************************80 + ! + !! I8_SOBOL generates a new quasirandom Sobol vector with each call. + ! + ! Discussion: + ! + ! The routine adapts the ideas of Antonov and Saleev. + ! + ! This routine uses the integer and real precisions corresponding + ! respectively to a KIND of int64 and real64. + ! + ! Thanks to Francis Dalaudier for pointing out that the range of allowed + ! values of DIM_NUM should start at 1, not 2! 17 February 2009. + ! + ! Licensing: + ! + ! This code is distributed under the GNU LGPL license. + ! + ! Modified: + ! + ! 17 February 2009 + ! + ! Author: + ! + ! Original FORTRAN77 version by Bennett Fox. + ! FORTRAN90 version by John Burkardt. + ! + ! Reference: + ! + ! IA Antonov, VM Saleev, + ! An Economic Method of Computing LP Tau-Sequences, + ! USSR Computational Mathematics and Mathematical Physics, + ! Volume 19, 1980, pages 252-256. + ! + ! Paul Bratley, Bennett Fox, + ! Algorithm 659: + ! Implementing Sobol's Quasirandom Sequence Generator, + ! ACM Transactions on Mathematical Software, + ! Volume 14, Number 1, March 1988, pages 88-100 + ! + ! Bennett Fox, + ! Algorithm 647: + ! Implementation and Relative Efficiency of Quasirandom + ! Sequence Generators, + ! ACM Transactions on Mathematical Software, + ! Volume 12, Number 4, December 1986, pages 362-376. + ! + ! Stephen Joe, Frances Kuo, + ! Remark on Algorithm 659: + ! Implementing Sobol's Quasirandom Sequence Generator, + ! ACM Transactions on Mathematical Software, + ! Volume 29, Number 1, March 2003, pages 49-57. + ! + ! Ilya Sobol, + ! Uniformly Distributed Sequences with an Additional Uniform Property, + ! USSR Computational Mathematics and Mathematical Physics, + ! Volume 16, 1977, pages 236-242. + ! + ! Ilya Sobol, YL Levitan, + ! The Production of Points Uniformly Distributed in a Multidimensional + ! Cube (in Russian), + ! Preprint IPM Akademii Nauk SSSR, + ! Number 40, Moscow 1976. + ! + ! Parameters: + ! + ! Input, integer(int64) DIM_NUM, the number of spatial dimensions. + ! DIM_NUM must satisfy 1 <= DIM_NUM <= 1111. + ! + ! Input/output, integer(int64) SEED, the "seed" for the sequence. + ! This is essentially the index in the sequence of the quasirandom + ! value to be generated. On output, SEED has been set to the + ! appropriate next value, usually simply SEED+1. + ! If SEED is less than 0 on input, it is treated as though it were 0. + ! An input value of 0 requests the first (0-th) element of the sequence. + ! + ! Output, real(real64) QUASI(DIM_NUM), the next quasirandom vector. + + use iso_fortran_env + implicit none (type, external) + + integer(int64), intent(in) :: dim_num + integer(int64), parameter :: dim_max = 1111 + integer(int64), parameter :: log_max = 62 + + integer(int64) :: atmost + integer(int64), save :: dim_num_save = 0 + integer(int64) :: i + logical includ(log_max) + logical, save :: initialized = .false. + integer(int64) :: j + integer(int64) :: j2 + integer(int64) :: k + integer(int64) :: l + integer(int64), save, dimension(dim_max) :: lastq + integer(int64) :: m + integer(int64), save :: maxcol + integer(int64) :: newv + integer(int64), save, dimension(1:dim_max) :: poly + real(real64), dimension ( dim_num ), intent(out) :: quasi + real(real64), save :: recipd + integer(int64), intent (inout) :: seed + integer(int64), save :: seed_save = - 1 + integer(int64) :: seed_temp + integer(int64), save, dimension(1:dim_max,1:log_max) :: v + + interface + integer(int64) function i8_bit_hi1(n) + import int64 + integer(int64), intent(in) :: n + end function i8_bit_hi1 + + integer(int64) function i8_bit_lo0(n) + import int64 + integer(int64), intent(in) :: n + end function i8_bit_lo0 + end interface + + if ( .not. initialized .or. dim_num /= dim_num_save ) then + + initialized = .true. + + v(1:dim_max,1:log_max) = 0 + ! + ! Initialize (part of) V. + ! + v(2:1111,1) = 1 + v(3:401,2) = (/ & + 1,3,1,3,1,3,3,1,3,1,3,1,3,1,1,3,1,3,1,3, & + 1,3,3,1,1,1,3,1,3,1,3,3,1,3,1,1,1,3,1,3,1,1,1,3,3,1,3,3,1,1, & + 3,3,1,3,3,3,1,3,1,3,1,1,3,3,1,1,1,1,3,1,1,3,1,1,1,3,3,1,3,3, & + 1,3,3,3,1,3,3,3,1,3,3,1,3,3,3,1,3,1,3,1,1,3,3,1,3,3,1,1,1,3, & + 3,1,3,3,1,3,1,1,3,3,3,1,1,1,3,1,1,3,1,1,3,3,1,3,1,3,3,3,3,1, & + 1,1,3,3,1,1,3,1,1,1,1,1,1,3,1,3,1,1,1,3,1,3,1,3,3,3,1,1,3,3, & + 1,3,1,3,1,1,3,1,3,1,3,1,3,1,1,1,3,3,1,3,3,1,3,1,1,1,3,1,3,1, & + 1,3,1,1,3,3,1,1,3,3,3,1,3,3,3,1,3,1,3,1,1,1,3,1,1,1,3,1,1,1, & + 1,1,3,3,3,1,1,1,1,3,3,3,1,3,3,1,1,1,1,3,1,1,3,1,3,3,1,1,3,3, & + 1,1,1,1,3,1,3,3,1,3,3,1,1,1,3,3,3,1,3,3,1,3,3,1,3,1,3,3,3,1, & + 3,1,1,3,1,3,1,1,1,3,3,3,1,1,3,1,3,1,1,1,1,1,1,3,1,1,3,1,3,3, & + 1,1,1,1,3,1,3,1,3,1,1,1,1,3,3,1,1,1,1,1,3,3,3,1,1,3,3,3,3,3, & + 1,3,3,1,3,3,3,3,1,1,1,1,1,1,3,1,1,3,1,1,1,3,1,1,1,3,3,3,1,3, & + 1,1,3,3,3,1,3,3,1,3,1,3,3,1,3,3,3,1,1/) + v(402:800,2) = (/ & + 3,3,1,3,1,3,1,1,1,3,3,3,3,1,3,1,1,3,1, & + 3,1,1,1,3,1,3,1,3,1,3,3,3,3,3,3,3,3,1,3,3,3,3,3,1,3,1,3,3,3, & + 1,3,1,3,1,3,3,1,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,3,3,1,1,3,3,1, & + 1,1,3,3,1,1,3,3,3,3,1,1,3,1,3,3,1,3,3,1,1,1,3,3,3,1,1,3,3,3, & + 3,3,1,1,1,3,1,3,3,1,3,3,3,3,1,1,3,1,1,3,1,3,1,3,1,3,3,1,1,3, & + 3,1,3,3,1,3,3,1,1,3,1,3,3,1,1,3,1,3,1,3,1,1,3,3,1,1,1,3,3,1, & + 3,1,1,3,3,1,1,3,1,3,1,1,1,1,1,3,1,1,1,1,3,1,3,1,1,3,3,1,1,3, & + 1,3,1,3,3,3,1,3,3,3,1,1,3,3,3,1,1,1,1,3,1,3,1,3,1,1,3,3,1,1, & + 1,3,3,1,3,1,3,1,1,1,1,1,1,3,1,3,3,1,3,3,3,1,3,1,1,3,3,1,1,3, & + 3,1,1,1,3,1,3,3,1,1,3,1,1,3,1,3,1,1,1,3,3,3,3,1,1,3,3,1,1,1, & + 1,3,1,1,3,3,3,1,1,3,3,1,3,3,1,1,3,3,3,3,3,3,3,1,3,3,1,3,1,3, & + 1,1,3,3,1,1,1,3,1,3,3,1,3,3,1,3,1,1,3,3,3,1,1,1,3,1,1,1,3,3, & + 3,1,3,3,1,3,1,1,3,3,3,1,3,3,1,1,1,3,1,3,3,3,3,3,3,3,3,1,3,3, & + 1,3,1,1,3,3,3,1,3,3,3,3,3,1,3,3,3,1,1,1/) + v(801:1111,2) = (/ & + 3,3,1,3,3,1,3,1,3,1,3,1,3,3,3,3,3,3, & + 1,1,3,1,3,1,1,1,1,1,3,1,1,1,3,1,3,1,1,3,3,3,1,3,1,3,1,1,3,1, & + 3,3,1,3,1,3,3,1,3,3,1,3,3,3,3,3,3,1,3,1,1,3,3,3,1,1,3,3,3,3, & + 3,3,3,1,3,3,3,3,1,3,1,3,3,3,1,3,1,3,1,1,1,3,3,1,3,1,1,3,3,1, & + 3,1,1,1,1,3,1,3,1,1,3,1,3,1,3,3,3,3,3,3,1,3,3,3,3,1,3,3,1,3, & + 3,3,3,3,1,1,1,1,3,3,3,1,3,3,1,1,3,3,1,1,3,3,1,3,1,1,3,1,3,3, & + 3,3,3,1,3,1,1,3,3,3,3,1,3,1,1,3,3,3,3,3,3,1,1,3,1,3,1,1,3,1, & + 1,1,1,3,3,1,1,3,1,1,1,3,1,3,1,1,3,3,1,3,1,1,3,3,3,3,3,1,3,1, & + 1,1,3,1,1,1,3,1,1,3,1,3,3,3,3,3,1,1,1,3,3,3,3,1,3,3,3,3,1,1, & + 3,3,3,1,3,1,1,3,3,1,3,3,1,1,1,1,1,3,1,1,3,3,1,1,1,3,1,1,3,3, & + 1,3,3,3,3,3,3,3,3,1,1,3,3,1,1,3,1,3,3,3,3,3,1/) + v(4:402,3) = (/ & + 7,5,1,3,3,7,5,5,7,7,1,3,3,7,5,1,1,5,3,7, & + 1,7,5,1,3,7,7,1,1,1,5,7,7,5,1,3,3,7,5,5,5,3,3,3,1,1,5,1,1,5, & + 3,3,3,3,1,3,7,5,7,3,7,1,3,3,5,1,3,5,5,7,7,7,1,1,3,3,1,1,5,1, & + 5,7,5,1,7,5,3,3,1,5,7,1,7,5,1,7,3,1,7,1,7,3,3,5,7,3,3,5,1,3, & + 3,1,3,5,1,3,3,3,7,1,1,7,3,1,3,7,5,5,7,5,5,3,1,3,3,3,1,3,3,7, & + 3,3,1,7,5,1,7,7,5,7,5,1,3,1,7,3,7,3,5,7,3,1,3,3,3,1,5,7,3,3, & + 7,7,7,5,3,1,7,1,3,7,5,3,3,3,7,1,1,3,1,5,7,1,3,5,3,5,3,3,7,5, & + 5,3,3,1,3,7,7,7,1,5,7,1,3,1,1,7,1,3,1,7,1,5,3,5,3,1,1,5,5,3, & + 3,5,7,1,5,3,7,7,3,5,3,3,1,7,3,1,3,5,7,1,3,7,1,5,1,3,1,5,3,1, & + 7,1,5,5,5,3,7,1,1,7,3,1,1,7,5,7,5,7,7,3,7,1,3,7,7,3,5,1,1,7, & + 1,5,5,5,1,5,1,7,5,5,7,1,1,7,1,7,7,1,1,3,3,3,7,7,5,3,7,3,1,3, & + 7,5,3,3,5,7,1,1,5,5,7,7,1,1,1,1,5,5,5,7,5,7,1,1,3,5,1,3,3,7, & + 3,7,5,3,5,3,1,7,1,7,7,1,1,7,7,7,5,5,1,1,7,5,5,7,5,1,1,5,5,5, & + 5,5,5,1,3,1,5,7,3,3,5,7,3,7,1,7,7,1,3/) + v(403:801,3) = (/ & + 5,1,5,5,3,7,3,7,7,5,7,5,7,1,1,5,3,5,1, & + 5,3,7,1,5,7,7,3,5,1,3,5,1,5,3,3,3,7,3,5,1,3,7,7,3,7,5,3,3,1, & + 7,5,1,1,3,7,1,7,1,7,3,7,3,5,7,3,5,3,1,1,1,5,7,7,3,3,1,1,1,5, & + 5,7,3,1,1,3,3,7,3,3,5,1,3,7,3,3,7,3,5,7,5,7,7,3,3,5,1,3,5,3, & + 1,3,5,1,1,3,7,7,1,5,1,3,7,3,7,3,5,1,7,1,1,3,5,3,7,1,5,5,1,1, & + 3,1,3,3,7,1,7,3,1,7,3,1,7,3,5,3,5,7,3,3,3,5,1,7,7,1,3,1,3,7, & + 7,1,3,7,3,1,5,3,1,1,1,5,3,3,7,1,5,3,5,1,3,1,3,1,5,7,7,1,1,5, & + 3,1,5,1,1,7,7,3,5,5,1,7,1,5,1,1,3,1,5,7,5,7,7,1,5,1,1,3,5,1, & + 5,5,3,1,3,1,5,5,3,3,3,3,1,1,3,1,3,5,5,7,5,5,7,5,7,1,3,7,7,3, & + 5,5,7,5,5,3,3,3,1,7,1,5,5,5,3,3,5,1,3,1,3,3,3,7,1,7,7,3,7,1, & + 1,5,7,1,7,1,7,7,1,3,7,5,1,3,5,5,5,1,1,7,1,7,1,7,7,3,1,1,5,1, & + 5,1,5,3,5,5,5,5,5,3,3,7,3,3,5,5,3,7,1,5,7,5,1,5,5,3,5,5,7,5, & + 3,5,5,5,1,5,5,5,5,1,3,5,3,1,7,5,5,7,1,5,3,3,1,5,3,7,1,7,5,1, & + 1,3,1,1,7,1,5,5,3,7,3,7,5,3,1,1,3,1,3,5/) + v(802:1111,3) = (/ & + 5,7,5,3,7,7,7,3,7,3,7,1,3,1,7,7,1,7, & + 3,7,3,7,3,7,3,5,1,1,7,3,1,5,5,7,1,5,5,5,7,1,5,5,1,5,5,3,1,3, & + 1,7,3,1,3,5,7,7,7,1,1,7,3,1,5,5,5,1,1,1,1,1,5,3,5,1,3,5,3,1, & + 1,1,1,3,7,3,7,5,7,1,5,5,7,5,3,3,7,5,3,1,1,3,1,3,1,1,3,7,1,7, & + 1,1,5,1,7,5,3,7,3,5,3,1,1,5,5,1,7,7,3,7,3,7,1,5,1,5,3,7,3,5, & + 7,7,7,3,3,1,1,5,5,3,7,1,1,1,3,5,3,1,1,3,3,7,5,1,1,3,7,1,5,7, & + 3,7,5,5,7,3,5,3,1,5,3,1,1,7,5,1,7,3,7,5,1,7,1,7,7,1,1,7,1,5, & + 5,1,1,7,5,7,1,5,3,5,3,3,7,1,5,1,1,5,5,3,3,7,5,5,1,1,1,3,1,5, & + 7,7,1,7,5,7,3,7,3,1,3,7,3,1,5,5,3,5,1,3,5,5,5,1,1,7,7,1,5,5, & + 1,3,5,1,5,3,5,3,3,7,5,7,3,7,3,1,3,7,7,3,3,1,1,3,3,3,3,3,5,5, & + 3,3,3,1,3,5,7,7,1,5,7,3,7,1,1,3,5,7,5,3,3,3/) + v(6:357,4) = (/ & + 1,7,9,13,11,1,3,7,9,5,13,13,11,3,15,5,3, & + 15,7,9,13,9,1,11,7,5,15,1,15,11,5,11,1,7,9,7,7,1,15,15,15,13, & + 3,3,15,5,9,7,13,3,7,5,11,9,1,9,1,5,7,13,9,9,1,7,3,5,1,11,11, & + 13,7,7,9,9,1,1,3,9,15,1,5,13,1,9,9,9,9,9,13,11,3,5,11,11,13, & + 5,3,15,1,11,11,7,13,15,11,13,9,11,15,15,13,3,15,7,9,11,13,11, & + 9,9,5,13,9,1,13,7,7,7,7,7,5,9,7,13,11,9,11,15,3,13,11,1,11,3, & + 3,9,11,1,7,1,15,15,3,1,9,1,7,13,11,3,13,11,7,3,3,5,13,11,5, & + 11,1,3,9,7,15,7,5,13,7,9,13,15,13,9,7,15,7,9,5,11,11,13,13,9, & + 3,5,13,9,11,15,11,7,1,7,13,3,13,3,13,9,15,7,13,13,3,13,15,15, & + 11,9,13,9,15,1,1,15,11,11,7,1,11,13,9,13,3,5,11,13,9,9,13,1, & + 11,15,13,3,13,7,15,1,15,3,3,11,7,13,7,7,9,7,5,15,9,5,5,7,15, & + 13,15,5,15,5,3,1,11,7,1,5,7,9,3,11,1,15,1,3,15,11,13,5,13,1, & + 7,1,15,7,5,1,1,15,13,11,11,13,5,11,7,9,7,1,5,3,9,5,5,11,5,1, & + 7,1,11,7,9,13,15,13,3,1,11,13,15,1,1,11,9,13,3,13,11,15,13,9, & + 9,9,5,5,5,5,1,15,5,9/) + v(358:710,4) = (/ & + 11,7,15,5,3,13,5,3,11,5,1,11,13,9,11, & + 3,7,13,15,1,7,11,1,13,1,15,1,9,7,3,9,11,1,9,13,13,3,11,7,9,1, & + 7,15,9,1,5,13,5,11,3,9,15,11,13,5,1,7,7,5,13,7,7,9,5,11,11,1, & + 1,15,3,13,9,13,9,9,11,5,5,13,15,3,9,15,3,11,11,15,15,3,11,15, & + 15,3,1,3,1,3,3,1,3,13,1,11,5,15,7,15,9,1,7,1,9,11,15,1,13,9, & + 13,11,7,3,7,3,13,7,9,7,7,3,3,9,9,7,5,11,13,13,7,7,15,9,5,5,3, & + 3,13,3,9,3,1,11,1,3,11,15,11,11,11,9,13,7,9,15,9,11,1,3,3,9, & + 7,15,13,13,7,15,9,13,9,15,13,15,9,13,1,11,7,11,3,13,5,1,7,15, & + 3,13,7,13,13,11,3,5,3,13,11,9,9,3,11,11,7,9,13,11,7,15,13,7, & + 5,3,1,5,15,15,3,11,1,7,3,15,11,5,5,3,5,5,1,15,5,1,5,3,7,5,11, & + 3,13,9,13,15,5,3,5,9,5,3,11,1,13,9,15,3,5,11,9,1,3,15,9,9,9, & + 11,7,5,13,1,15,3,13,9,13,5,1,5,1,13,13,7,7,1,9,5,11,9,11,13, & + 3,15,15,13,15,7,5,7,9,7,9,9,9,11,9,3,11,15,13,13,5,9,15,1,1, & + 9,5,13,3,13,15,3,1,3,11,13,1,15,9,9,3,1,9,1,9,1,13,11,15,7, & + 11,15,13,15,1,9,9,7/) + v(711:1065,4) = (/ & + 3,5,11,7,3,9,5,15,7,5,3,13,7,1,1,9, & + 15,15,15,11,3,5,15,13,7,15,15,11,11,9,5,15,9,7,3,13,1,1,5,1, & + 3,1,7,1,1,5,1,11,11,9,9,5,13,7,7,7,1,1,9,9,11,11,15,7,5,5,3, & + 11,1,3,7,13,7,7,7,3,15,15,11,9,3,9,3,15,13,5,3,3,3,5,9,15,9, & + 9,1,5,9,9,15,5,15,7,9,1,9,9,5,11,5,15,15,11,7,7,7,1,1,11,11, & + 13,15,3,13,5,1,7,1,11,3,13,15,3,5,3,5,7,3,9,9,5,1,7,11,9,3,5, & + 11,13,13,13,9,15,5,7,1,15,11,9,15,15,13,13,13,1,11,9,15,9,5, & + 15,5,7,3,11,3,15,7,13,11,7,3,7,13,5,13,15,5,13,9,1,15,11,5,5, & + 1,11,3,3,7,1,9,7,15,9,9,3,11,15,7,1,3,1,1,1,9,1,5,15,15,7,5, & + 5,7,9,7,15,13,13,11,1,9,11,1,13,1,7,15,15,5,5,1,11,3,9,11,9, & + 9,9,1,9,3,5,15,1,1,9,7,3,3,1,9,9,11,9,9,13,13,3,13,11,13,5,1, & + 5,5,9,9,3,13,13,9,15,9,11,7,11,9,13,9,1,15,9,7,7,1,7,9,9,15, & + 1,11,1,13,13,15,9,13,7,15,3,9,3,1,13,7,5,9,3,1,7,1,1,13,3,3, & + 11,1,7,13,15,15,5,7,13,13,15,11,13,1,13,13,3,9,15,15,11,15,9, & + 15,1,13,15,1,1,5/) + v(1066:1111,4) = (/ & + 11,5,1,11,11,5,3,9,1,3,5,13,9,7,7,1, & + 9,9,15,7,5,5,15,13,9,7,13,3,13,11,13,7,9,13,13,13,15,9,5,5,3, & + 3,3,1,3,15/) + v(8:331,5) = (/ & + 9,3,27,15,29,21,23,19,11,25,7,13,17,1, & + 25,29,3,31,11,5,23,27,19,21,5,1,17,13,7,15,9,31,25,3,5,23,7, & + 3,17,23,3,3,21,25,25,23,11,19,3,11,31,7,9,5,17,23,17,17,25, & + 13,11,31,27,19,17,23,7,5,11,19,19,7,13,21,21,7,9,11,1,5,21, & + 11,13,25,9,7,7,27,15,25,15,21,17,19,19,21,5,11,3,5,29,31,29, & + 5,5,1,31,27,11,13,1,3,7,11,7,3,23,13,31,17,1,27,11,25,1,23, & + 29,17,25,7,25,27,17,13,17,23,5,17,5,13,11,21,5,11,5,9,31,19, & + 17,9,9,27,21,15,15,1,1,29,5,31,11,17,23,19,21,25,15,11,5,5,1, & + 19,19,19,7,13,21,17,17,25,23,19,23,15,13,5,19,25,9,7,3,21,17, & + 25,1,27,25,27,25,9,13,3,17,25,23,9,25,9,13,17,17,3,15,7,7,29, & + 3,19,29,29,19,29,13,15,25,27,1,3,9,9,13,31,29,31,5,15,29,1, & + 19,5,9,19,5,15,3,5,7,15,17,17,23,11,9,23,19,3,17,1,27,9,9,17, & + 13,25,29,23,29,11,31,25,21,29,19,27,31,3,5,3,3,13,21,9,29,3, & + 17,11,11,9,21,19,7,17,31,25,1,27,5,15,27,29,29,29,25,27,25,3, & + 21,17,25,13,15,17,13,23,9,3,11,7,9,9,7,17,7,1/) + v(332:654,5) = (/ & + 27,1,9,5,31,21,25,25,21,11,1,23,19,27, & + 15,3,5,23,9,25,7,29,11,9,13,5,11,1,3,31,27,3,17,27,11,13,15, & + 29,15,1,15,23,25,13,21,15,3,29,29,5,25,17,11,7,15,5,21,7,31, & + 13,11,23,5,7,23,27,21,29,15,7,27,27,19,7,15,27,27,19,19,9,15, & + 1,3,29,29,5,27,31,9,1,7,3,19,19,29,9,3,21,31,29,25,1,3,9,27, & + 5,27,25,21,11,29,31,27,21,29,17,9,17,13,11,25,15,21,11,19,31, & + 3,19,5,3,3,9,13,13,3,29,7,5,9,23,13,21,23,21,31,11,7,7,3,23, & + 1,23,5,9,17,21,1,17,29,7,5,17,13,25,17,9,19,9,5,7,21,19,13,9, & + 7,3,9,3,15,31,29,29,25,13,9,21,9,31,7,15,5,31,7,15,27,25,19, & + 9,9,25,25,23,1,9,7,11,15,19,15,27,17,11,11,31,13,25,25,9,7, & + 13,29,19,5,19,31,25,13,25,15,5,9,29,31,9,29,27,25,27,11,17,5, & + 17,3,23,15,9,9,17,17,31,11,19,25,13,23,15,25,21,31,19,3,11, & + 25,7,15,19,7,5,3,13,13,1,23,5,25,11,25,15,13,21,11,23,29,5, & + 17,27,9,19,15,5,29,23,19,1,27,3,23,21,19,27,11,17,13,27,11, & + 31,23,5,9,21,31,29,11,21,17,15,7,15,7,9,21,27,25/) + v(655:975,5) = (/ & + 29,11,3,21,13,23,19,27,17,29,25,17,9, & + 1,19,23,5,23,1,17,17,13,27,23,7,7,11,13,17,13,11,21,13,23,1, & + 27,13,9,7,1,27,29,5,13,25,21,3,31,15,13,3,19,13,1,27,15,17,1, & + 3,13,13,13,31,29,27,7,7,21,29,15,17,17,21,19,17,3,15,5,27,27, & + 3,31,31,7,21,3,13,11,17,27,25,1,9,7,29,27,21,23,13,25,29,15, & + 17,29,9,15,3,21,15,17,17,31,9,9,23,19,25,3,1,11,27,29,1,31, & + 29,25,29,1,23,29,25,13,3,31,25,5,5,11,3,21,9,23,7,11,23,11,1, & + 1,3,23,25,23,1,23,3,27,9,27,3,23,25,19,29,29,13,27,5,9,29,29, & + 13,17,3,23,19,7,13,3,19,23,5,29,29,13,13,5,19,5,17,9,11,11, & + 29,27,23,19,17,25,13,1,13,3,11,1,17,29,1,13,17,9,17,21,1,11, & + 1,1,25,5,7,29,29,19,19,1,29,13,3,1,31,15,13,3,1,11,19,5,29, & + 13,29,23,3,1,31,13,19,17,5,5,1,29,23,3,19,25,19,27,9,27,13, & + 15,29,23,13,25,25,17,19,17,15,27,3,25,17,27,3,27,31,23,13,31, & + 11,15,7,21,19,27,19,21,29,7,31,13,9,9,7,21,13,11,9,11,29,19, & + 11,19,21,5,29,13,7,19,19,27,23,31,1,27,21,7,3,7,11/) + v(976:1111,5) = (/ & + 23,13,29,11,31,19,1,5,5,11,5,3,27,5, & + 7,11,31,1,27,31,31,23,5,21,27,9,25,3,15,19,1,19,9,5,25,21,15, & + 25,29,15,21,11,19,15,3,7,13,11,25,17,1,5,31,13,29,23,9,5,29, & + 7,17,27,7,17,31,9,31,9,9,7,21,3,3,3,9,11,21,11,31,9,25,5,1, & + 31,13,29,9,29,1,11,19,7,27,13,31,7,31,7,25,23,21,29,11,11,13, & + 11,27,1,23,31,21,23,21,19,31,5,31,25,25,19,17,11,25,7,13,1, & + 29,17,23,15,7,29,17,13,3,17/) + v(14:324,6) = (/ & + 37,33,7,5,11,39,63,59,17,15,23,29,3,21, & + 13,31,25,9,49,33,19,29,11,19,27,15,25,63,55,17,63,49,19,41, & + 59,3,57,33,49,53,57,57,39,21,7,53,9,55,15,59,19,49,31,3,39,5, & + 5,41,9,19,9,57,25,1,15,51,11,19,61,53,29,19,11,9,21,19,43,13, & + 13,41,25,31,9,11,19,5,53,37,7,51,45,7,7,61,23,45,7,59,41,1, & + 29,61,37,27,47,15,31,35,31,17,51,13,25,45,5,5,33,39,5,47,29, & + 35,47,63,45,37,47,59,21,59,33,51,9,27,13,25,43,3,17,21,59,61, & + 27,47,57,11,17,39,1,63,21,59,17,13,31,3,31,7,9,27,37,23,31,9, & + 45,43,31,63,21,39,51,27,7,53,11,1,59,39,23,49,23,7,55,59,3, & + 19,35,13,9,13,15,23,9,7,43,55,3,19,9,27,33,27,49,23,47,19,7, & + 11,55,27,35,5,5,55,35,37,9,33,29,47,25,11,47,53,61,59,3,53, & + 47,5,19,59,5,47,23,45,53,3,49,61,47,39,29,17,57,5,17,31,23, & + 41,39,5,27,7,29,29,33,31,41,31,29,17,29,29,9,9,31,27,53,35,5, & + 61,1,49,13,57,29,5,21,43,25,57,49,37,27,11,61,37,49,5,63,63, & + 3,45,37,63,21,21,19,27,59,21,45,23,13,15,3,43,63,39,19/) + v(325:632,6) = (/ & + 63,31,41,41,15,43,63,53,1,63,31,7,17, & + 11,61,31,51,37,29,59,25,63,59,47,15,27,19,29,45,35,55,39,19, & + 43,21,19,13,17,51,37,5,33,35,49,25,45,1,63,47,9,63,15,25,25, & + 15,41,13,3,19,51,49,37,25,49,13,53,47,23,35,29,33,21,35,23,3, & + 43,31,63,9,1,61,43,3,11,55,11,35,1,63,35,49,19,45,9,57,51,1, & + 47,41,9,11,37,19,55,23,55,55,13,7,47,37,11,43,17,3,25,19,55, & + 59,37,33,43,1,5,21,5,63,49,61,21,51,15,19,43,47,17,9,53,45, & + 11,51,25,11,25,47,47,1,43,29,17,31,15,59,27,63,11,41,51,29,7, & + 27,63,31,43,3,29,39,3,59,59,1,53,63,23,63,47,51,23,61,39,47, & + 21,39,15,3,9,57,61,39,37,21,51,1,23,43,27,25,11,13,21,43,7, & + 11,33,55,1,37,35,27,61,39,5,19,61,61,57,59,21,59,61,57,25,55, & + 27,31,41,33,63,19,57,35,13,63,35,17,11,11,49,41,55,5,45,17, & + 35,5,31,31,37,17,45,51,1,39,49,55,19,41,13,5,51,5,49,1,21,13, & + 17,59,51,11,3,61,1,33,37,33,61,25,27,59,7,49,13,63,3,33,3,15, & + 9,13,35,39,11,59,59,1,57,11,5,57,13,31,13,11,55,45,9,55,55/) + v(633:942,6) = (/ & + 19,25,41,23,45,29,63,59,27,39,21,37,7, & + 61,49,35,39,9,29,7,25,23,57,5,19,15,33,49,37,25,17,45,29,15, & + 25,3,3,49,11,39,15,19,57,39,15,11,3,57,31,55,61,19,5,41,35, & + 59,61,39,41,53,53,63,31,9,59,13,35,55,41,49,5,41,25,27,43,5, & + 5,43,5,5,17,5,15,27,29,17,9,3,55,31,1,45,45,13,57,17,3,61,15, & + 49,15,47,9,37,45,9,51,61,21,33,11,21,63,63,47,57,61,49,9,59, & + 19,29,21,23,55,23,43,41,57,9,39,27,41,35,61,29,57,63,21,31, & + 59,35,49,3,49,47,49,33,21,19,21,35,11,17,37,23,59,13,37,35, & + 55,57,1,29,45,11,1,15,9,33,19,53,43,39,23,7,13,13,1,19,41,55, & + 1,13,15,59,55,15,3,57,37,31,17,1,3,21,29,25,55,9,37,33,53,41, & + 51,19,57,13,63,43,19,7,13,37,33,19,15,63,51,11,49,23,57,47, & + 51,15,53,41,1,15,37,61,11,35,29,33,23,55,11,59,19,61,61,45, & + 13,49,13,63,5,61,5,31,17,61,63,13,27,57,1,21,5,11,39,57,51, & + 53,39,25,41,39,37,23,31,25,33,17,57,29,27,23,47,41,29,19,47, & + 41,25,5,51,43,39,29,7,31,45,51,49,55,17,43,49,45,9,29,3,5,47, & + 9,15,19/) + v(943:1111,6) = (/ & + 51,45,57,63,9,21,59,3,9,13,45,23,15, & + 31,21,15,51,35,9,11,61,23,53,29,51,45,31,29,5,35,29,53,35,17, & + 59,55,27,51,59,27,47,15,29,37,7,49,55,5,19,45,29,19,57,33,53, & + 45,21,9,3,35,29,43,31,39,3,45,1,41,29,5,59,41,33,35,27,19,13, & + 25,27,43,33,35,17,17,23,7,35,15,61,61,53,5,15,23,11,13,43,55, & + 47,25,43,15,57,45,1,49,63,57,15,31,31,7,53,27,15,47,23,7,29, & + 53,47,9,53,3,25,55,45,63,21,17,23,31,27,27,43,63,55,63,45,51, & + 15,27,5,37,43,11,27,5,27,59,21,7,39,27,63,35,47,55,17,17,17, & + 3,19,21,13,49,61,39,15/) + v(20:305,7) = (/ & + 13,33,115,41,79,17,29,119,75,73,105,7, & + 59,65,21,3,113,61,89,45,107,21,71,79,19,71,61,41,57,121,87, & + 119,55,85,121,119,11,23,61,11,35,33,43,107,113,101,29,87,119, & + 97,29,17,89,5,127,89,119,117,103,105,41,83,25,41,55,69,117, & + 49,127,29,1,99,53,83,15,31,73,115,35,21,89,5,1,91,53,35,95, & + 83,19,85,55,51,101,33,41,55,45,95,61,27,37,89,75,57,61,15, & + 117,15,21,27,25,27,123,39,109,93,51,21,91,109,107,45,15,93, & + 127,3,53,81,79,107,79,87,35,109,73,35,83,107,1,51,7,59,33, & + 115,43,111,45,121,105,125,87,101,41,95,75,1,57,117,21,27,67, & + 29,53,117,63,1,77,89,115,49,127,15,79,81,29,65,103,33,73,79, & + 29,21,113,31,33,107,95,111,59,99,117,63,63,99,39,9,35,63,125, & + 99,45,93,33,93,9,105,75,51,115,11,37,17,41,21,43,73,19,93,7, & + 95,81,93,79,81,55,9,51,63,45,89,73,19,115,39,47,81,39,5,5,45, & + 53,65,49,17,105,13,107,5,5,19,73,59,43,83,97,115,27,1,69,103, & + 3,99,103,63,67,25,121,97,77,13,83,103,41,11,27,81,37,33,125, & + 71,41,41,59,41,87,123/) + v(306:589,7) = (/ & + 43,101,63,45,39,21,97,15,97,111,21,49, & + 13,17,79,91,65,105,75,1,45,67,83,107,125,87,15,81,95,105,65, & + 45,59,103,23,103,99,67,99,47,117,71,89,35,53,73,9,115,49,37, & + 1,35,9,45,81,19,127,17,17,105,89,49,101,7,37,33,11,95,95,17, & + 111,105,41,115,5,69,101,27,27,101,103,53,9,21,43,79,91,65, & + 117,87,125,55,45,63,85,83,97,45,83,87,113,93,95,5,17,77,77, & + 127,123,45,81,85,121,119,27,85,41,49,15,107,21,51,119,11,87, & + 101,115,63,63,37,121,109,7,43,69,19,77,49,71,59,35,7,13,55, & + 101,127,103,85,109,29,61,67,21,111,67,23,57,75,71,101,123,41, & + 107,101,107,125,27,47,119,41,19,127,33,31,109,7,91,91,39,125, & + 105,47,125,123,91,9,103,45,23,117,9,125,73,11,37,61,79,21,5, & + 47,117,67,53,85,33,81,121,47,61,51,127,29,65,45,41,95,57,73, & + 33,117,61,111,59,123,65,47,105,23,29,107,37,81,67,29,115,119, & + 75,73,99,103,7,57,45,61,95,49,101,101,35,47,119,39,67,31,103, & + 7,61,127,87,3,35,29,73,95,103,71,75,51,87,57,97,11,105,87,41, & + 73,109,69,35,121,39,111,1,77/) + v(590:875,7) = (/ & + 39,47,53,91,3,17,51,83,39,125,85,111, & + 21,69,85,29,55,11,117,1,47,17,65,63,47,117,17,115,51,25,33, & + 123,123,83,51,113,95,121,51,91,109,43,55,35,55,87,33,37,5,3, & + 45,21,105,127,35,17,35,37,97,97,21,77,123,17,89,53,105,75,25, & + 125,13,47,21,125,23,55,63,61,5,17,93,57,121,69,73,93,121,105, & + 75,91,67,95,75,9,69,97,99,93,11,53,19,73,5,33,79,107,65,69, & + 79,125,25,93,55,61,17,117,69,97,87,111,37,93,59,79,95,53,115, & + 53,85,85,65,59,23,75,21,67,27,99,79,27,3,95,27,69,19,75,47, & + 59,41,85,77,99,55,49,93,93,119,51,125,63,13,15,45,61,19,105, & + 115,17,83,7,7,11,61,37,63,89,95,119,113,67,123,91,33,37,99, & + 43,11,33,65,81,79,81,107,63,63,55,89,91,25,93,101,27,55,75, & + 121,79,43,125,73,27,109,35,21,71,113,89,59,95,41,45,113,119, & + 113,39,59,73,15,13,59,67,121,27,7,105,15,59,59,35,91,89,23, & + 125,97,53,41,91,111,29,31,3,103,61,71,35,7,119,29,45,49,111, & + 41,109,59,125,13,27,19,79,9,75,83,81,33,91,109,33,29,107,111, & + 101,107,109,65,59,43,37/) + v(876:1111,7) = (/ & + 1,9,15,109,37,111,113,119,79,73,65, & + 71,93,17,101,87,97,43,23,75,109,41,49,53,31,97,105,109,119, & + 51,9,53,113,97,73,89,79,49,61,105,13,99,53,71,7,87,21,101,5, & + 71,31,123,121,121,73,79,115,13,39,101,19,37,51,83,97,55,81, & + 91,127,105,89,63,47,49,75,37,77,15,49,107,23,23,35,19,69,17, & + 59,63,73,29,125,61,65,95,101,81,57,69,83,37,11,37,95,1,73,27, & + 29,57,7,65,83,99,69,19,103,43,95,25,19,103,41,125,97,71,105, & + 83,83,61,39,9,45,117,63,31,5,117,67,125,41,117,43,77,97,15, & + 29,5,59,25,63,87,39,39,77,85,37,81,73,89,29,125,109,21,23, & + 119,105,43,93,97,15,125,29,51,69,37,45,31,75,109,119,53,5, & + 101,125,121,35,29,7,63,17,63,13,69,15,105,51,127,105,9,57,95, & + 59,109,35,49,23,33,107,55,33,57,79,73,69,59,107,55,11,63,95, & + 103,23,125,91,31,91,51,65,61,75,69,107,65,101,59,35,15/) + v(38:299,8) = (/ & + 7,23,39,217,141,27,53,181,169,35,15, & + 207,45,247,185,117,41,81,223,151,81,189,61,95,185,23,73,113, & + 239,85,9,201,83,53,183,203,91,149,101,13,111,239,3,205,253, & + 247,121,189,169,179,197,175,217,249,195,95,63,19,7,5,75,217, & + 245,111,189,165,169,141,221,249,159,253,207,249,219,23,49, & + 127,237,5,25,177,37,103,65,167,81,87,119,45,79,143,57,79,187, & + 143,183,75,97,211,149,175,37,135,189,225,241,63,33,43,13,73, & + 213,57,239,183,117,21,29,115,43,205,223,15,3,159,51,101,127, & + 99,239,171,113,171,119,189,245,201,27,185,229,105,153,189,33, & + 35,137,77,97,17,181,55,197,201,155,37,197,137,223,25,179,91, & + 23,235,53,253,49,181,249,53,173,97,247,67,115,103,159,239,69, & + 173,217,95,221,247,97,91,123,223,213,129,181,87,239,85,89, & + 249,141,39,57,249,71,101,159,33,137,189,71,253,205,171,13, & + 249,109,131,199,189,179,31,99,113,41,173,23,189,197,3,135,9, & + 95,195,27,183,1,123,73,53,99,197,59,27,101,55,193,31,61,119, & + 11,7,255,233,53,157,193,97,83,65,81,239,167,69,71,109/) + v(300:559,8) = (/ & + 97,137,71,193,189,115,79,205,37,227, & + 53,33,91,229,245,105,77,229,161,103,93,13,161,229,223,69,15, & + 25,23,233,93,25,217,247,61,75,27,9,223,213,55,197,145,89,199, & + 41,201,5,149,35,119,183,53,11,13,3,179,229,43,55,187,233,47, & + 133,91,47,71,93,105,145,45,255,221,115,175,19,129,5,209,197, & + 57,177,115,187,119,77,211,111,33,113,23,87,137,41,7,83,43, & + 121,145,5,219,27,11,111,207,55,97,63,229,53,33,149,23,187, & + 153,91,193,183,59,211,93,139,59,179,163,209,77,39,111,79,229, & + 85,237,199,137,147,25,73,121,129,83,87,93,205,167,53,107,229, & + 213,95,219,109,175,13,209,97,61,147,19,13,123,73,35,141,81, & + 19,171,255,111,107,233,113,133,89,9,231,95,69,33,1,253,219, & + 253,247,129,11,251,221,153,35,103,239,7,27,235,181,5,207,53, & + 149,155,225,165,137,155,201,97,245,203,47,39,35,105,239,49, & + 15,253,7,237,213,55,87,199,27,175,49,41,229,85,3,149,179,129, & + 185,249,197,15,97,197,139,203,63,33,251,217,199,199,99,249, & + 33,229,177,13,209,147,97,31,125,177,137/) + v(560:819,8) = (/ & + 187,11,91,223,29,169,231,59,31,163,41, & + 57,87,247,25,127,101,207,187,73,61,105,27,91,171,243,33,3,1, & + 21,229,93,71,61,37,183,65,211,53,11,151,165,47,5,129,79,101, & + 147,169,181,19,95,77,139,197,219,97,239,183,143,9,13,209,23, & + 215,53,137,203,19,151,171,133,219,231,3,15,253,225,33,111, & + 183,213,169,119,111,15,201,123,121,225,113,113,225,161,165,1, & + 139,55,3,93,217,193,97,29,69,231,161,93,69,143,137,9,87,183, & + 113,183,73,215,137,89,251,163,41,227,145,57,81,57,11,135,145, & + 161,175,159,25,55,167,157,211,97,247,249,23,129,159,71,197, & + 127,141,219,5,233,131,217,101,131,33,157,173,69,207,239,81, & + 205,11,41,169,65,193,77,201,173,1,221,157,1,15,113,147,137, & + 205,225,73,45,49,149,113,253,99,17,119,105,117,129,243,75, & + 203,53,29,247,35,247,171,31,199,213,29,251,7,251,187,91,11, & + 149,13,205,37,249,137,139,9,7,113,183,205,187,39,3,79,155, & + 227,89,185,51,127,63,83,41,133,183,181,127,19,255,219,59,251, & + 3,187,57,217,115,217,229,181,185,149,83,115,11/) + v(820:1074,8) = (/ & + 123,19,109,165,103,123,219,129,155, & + 207,177,9,49,181,231,33,233,67,155,41,9,95,123,65,117,249,85, & + 169,129,241,173,251,225,147,165,69,81,239,95,23,83,227,249, & + 143,171,193,9,21,57,73,97,57,29,239,151,159,191,47,51,1,223, & + 251,251,151,41,119,127,131,33,209,123,53,241,25,31,183,107, & + 25,115,39,11,213,239,219,109,185,35,133,123,185,27,55,245,61, & + 75,205,213,169,163,63,55,49,83,195,51,31,41,15,203,41,63,127, & + 161,5,143,7,199,251,95,75,101,15,43,237,197,117,167,155,21, & + 83,205,255,49,101,213,237,135,135,21,73,93,115,7,85,223,237, & + 79,89,5,57,239,67,65,201,155,71,85,195,89,181,119,135,147, & + 237,173,41,155,67,113,111,21,183,23,103,207,253,69,219,205, & + 195,43,197,229,139,177,129,69,97,201,163,189,11,99,91,253, & + 239,91,145,19,179,231,121,7,225,237,125,191,119,59,175,237, & + 131,79,43,45,205,199,251,153,207,37,179,113,255,107,217,61,7, & + 181,247,31,13,113,145,107,233,233,43,79,23,169,137,129,183, & + 53,91,55,103,223,87,177,157,79,213,139/) + v(1075:1111,8) = (/ & + 183,231,205,143,129,243,205,93,59, & + 15,89,9,11,47,133,227,75,9,91,19,171,163,79,7,103,5,119,155, & + 75,11,71,95,17,13,243,207,187/) + v(54:299,9) = (/ & + 235,307,495,417,57,151,19,119,375,451, & + 55,449,501,53,185,317,17,21,487,13,347,393,15,391,307,189, & + 381,71,163,99,467,167,433,337,257,179,47,385,23,117,369,425, & + 207,433,301,147,333,85,221,423,49,3,43,229,227,201,383,281, & + 229,207,21,343,251,397,173,507,421,443,399,53,345,77,385,317, & + 155,187,269,501,19,169,235,415,61,247,183,5,257,401,451,95, & + 455,49,489,75,459,377,87,463,155,233,115,429,211,419,143,487, & + 195,209,461,193,157,193,363,181,271,445,381,231,135,327,403, & + 171,197,181,343,113,313,393,311,415,267,247,425,233,289,55, & + 39,247,327,141,5,189,183,27,337,341,327,87,429,357,265,251, & + 437,201,29,339,257,377,17,53,327,47,375,393,369,403,125,429, & + 257,157,217,85,267,117,337,447,219,501,41,41,193,509,131,207, & + 505,421,149,111,177,167,223,291,91,29,305,151,177,337,183, & + 361,435,307,507,77,181,507,315,145,423,71,103,493,271,469, & + 339,237,437,483,31,219,61,131,391,233,219,69,57,459,225,421, & + 7,461,111,451,277,185,193,125,251,199,73,71,7,409,417,149/) + v(300:550,9) = (/ & + 193,53,437,29,467,229,31,35,75,105, & + 503,75,317,401,367,131,365,441,433,93,377,405,465,259,283, & + 443,143,445,3,461,329,309,77,323,155,347,45,381,315,463,207, & + 321,157,109,479,313,345,167,439,307,235,473,79,101,245,19, & + 381,251,35,25,107,187,115,113,321,115,445,61,77,293,405,13, & + 53,17,171,299,41,79,3,485,331,13,257,59,201,497,81,451,199, & + 171,81,253,365,75,451,149,483,81,453,469,485,305,163,401,15, & + 91,3,129,35,239,355,211,387,101,299,67,375,405,357,267,363, & + 79,83,437,457,39,97,473,289,179,57,23,49,79,71,341,287,95, & + 229,271,475,49,241,261,495,353,381,13,291,37,251,105,399,81, & + 89,265,507,205,145,331,129,119,503,249,1,289,463,163,443,63, & + 123,361,261,49,429,137,355,175,507,59,277,391,25,185,381,197, & + 39,5,429,119,247,177,329,465,421,271,467,151,45,429,137,471, & + 11,17,409,347,199,463,177,11,51,361,95,497,163,351,127,395, & + 511,327,353,49,105,151,321,331,329,509,107,109,303,467,287, & + 161,45,385,289,363,331,265,407,37,433,315,343,63,51,185,71, & + 27,267/) + v(551:798,9) = (/ & + 503,239,293,245,281,297,75,461,371, & + 129,189,189,339,287,111,111,379,93,27,185,347,337,247,507, & + 161,231,43,499,73,327,263,331,249,493,37,25,115,3,167,197, & + 127,357,497,103,125,191,165,55,101,95,79,351,341,43,125,135, & + 173,289,373,133,421,241,281,213,177,363,151,227,145,363,239, & + 431,81,397,241,67,291,255,405,421,399,75,399,105,329,41,425, & + 7,283,375,475,427,277,209,411,3,137,195,289,509,121,55,147, & + 275,251,19,129,285,415,487,491,193,219,403,23,97,65,285,75, & + 21,373,261,339,239,495,415,333,107,435,297,213,149,463,199, & + 323,45,19,301,121,499,187,229,63,425,99,281,35,125,349,87, & + 101,59,195,511,355,73,263,243,101,165,141,11,389,219,187,449, & + 447,393,477,305,221,51,355,209,499,479,265,377,145,411,173, & + 11,433,483,135,385,341,89,209,391,33,395,319,451,119,341,227, & + 375,61,331,493,411,293,47,203,375,167,395,155,5,237,361,489, & + 127,21,345,101,371,233,431,109,119,277,125,263,73,135,123,83, & + 123,405,69,75,287,401,23,283,393,41,379,431,11,475,505,19, & + 365,265,271/) + v(799:1045,9) = (/ & + 499,489,443,165,91,83,291,319,199, & + 107,245,389,143,137,89,125,281,381,215,131,299,249,375,455, & + 43,73,281,217,297,229,431,357,81,357,171,451,481,13,387,491, & + 489,439,385,487,177,393,33,71,375,443,129,407,395,127,65,333, & + 309,119,197,435,497,373,71,379,509,387,159,265,477,463,449, & + 47,353,249,335,505,89,141,55,235,187,87,363,93,363,101,67, & + 215,321,331,305,261,411,491,479,65,307,469,415,131,315,487, & + 83,455,19,113,163,503,99,499,251,239,81,167,391,255,317,363, & + 359,395,419,307,251,267,171,461,183,465,165,163,293,477,223, & + 403,389,97,335,357,297,19,469,501,249,85,213,311,265,379,297, & + 283,393,449,463,289,159,289,499,407,129,137,221,43,89,403, & + 271,75,83,445,453,389,149,143,423,499,317,445,157,137,453, & + 163,87,23,391,119,427,323,173,89,259,377,511,249,31,363,229, & + 353,329,493,427,57,205,389,91,83,13,219,439,45,35,371,441,17, & + 267,501,53,25,333,17,201,475,257,417,345,381,377,55,403,77, & + 389,347,363,211,413,419,5,167,219,201,285,425,11,77,269,489, & + 281,403,79/) + v(1046:1111,9) = (/ & + 425,125,81,331,437,271,397,299,475, & + 271,249,413,233,261,495,171,69,27,409,21,421,367,81,483,255, & + 15,219,365,497,181,75,431,99,325,407,229,281,63,83,493,5,113, & + 15,271,37,87,451,299,83,451,311,441,47,455,47,253,13,109,369, & + 347,11,409,275,63,441,15/) + v(102:344,10) = (/ & + 519,307,931,1023,517,771,151,1023, & + 539,725,45,927,707,29,125,371,275,279,817,389,453,989,1015, & + 29,169,743,99,923,981,181,693,309,227,111,219,897,377,425, & + 609,227,19,221,143,581,147,919,127,725,793,289,411,835,921, & + 957,443,349,813,5,105,457,393,539,101,197,697,27,343,515,69, & + 485,383,855,693,133,87,743,747,475,87,469,763,721,345,479, & + 965,527,121,271,353,467,177,245,627,113,357,7,691,725,355, & + 889,635,737,429,545,925,357,873,187,351,677,999,921,477,233, & + 765,495,81,953,479,89,173,473,131,961,411,291,967,65,511,13, & + 805,945,369,827,295,163,835,259,207,331,29,315,999,133,967, & + 41,117,677,471,717,881,755,351,723,259,879,455,721,289,149, & + 199,805,987,851,423,597,129,11,733,549,153,285,451,559,377, & + 109,357,143,693,615,677,701,475,767,85,229,509,547,151,389, & + 711,785,657,319,509,99,1007,775,359,697,677,85,497,105,615, & + 891,71,449,835,609,377,693,665,627,215,911,503,729,131,19, & + 895,199,161,239,633,1013,537,255,23,149,679,1021,595,199,557, & + 659,251,829,727,439,495,647,223/) + v(345:586,10) = (/ & + 949,625,87,481,85,799,917,769,949, & + 739,115,499,945,547,225,1015,469,737,495,353,103,17,665,639, & + 525,75,447,185,43,729,577,863,735,317,99,17,477,893,537,519, & + 1017,375,297,325,999,353,343,729,135,489,859,267,141,831,141, & + 893,249,807,53,613,131,547,977,131,999,175,31,341,739,467, & + 675,241,645,247,391,583,183,973,433,367,131,467,571,309,385, & + 977,111,917,935,473,345,411,313,97,149,959,841,839,669,431, & + 51,41,301,247,1015,377,329,945,269,67,979,581,643,823,557,91, & + 405,117,801,509,347,893,303,227,783,555,867,99,703,111,797, & + 873,541,919,513,343,319,517,135,871,917,285,663,301,15,763, & + 89,323,757,317,807,309,1013,345,499,279,711,915,411,281,193, & + 739,365,315,375,809,469,487,621,857,975,537,939,585,129,625, & + 447,129,1017,133,83,3,415,661,53,115,903,49,79,55,385,261, & + 345,297,199,385,617,25,515,275,849,401,471,377,661,535,505, & + 939,465,225,929,219,955,659,441,117,527,427,515,287,191,33, & + 389,197,825,63,417,949,35,571,9,131,609,439,95,19,569,893, & + 451,397,971,801/) + v(587:824,10) = (/ & + 125,471,187,257,67,949,621,453,411, & + 621,955,309,783,893,597,377,753,145,637,941,593,317,555,375, & + 575,175,403,571,555,109,377,931,499,649,653,329,279,271,647, & + 721,665,429,957,803,767,425,477,995,105,495,575,687,385,227, & + 923,563,723,481,717,111,633,113,369,955,253,321,409,909,367, & + 33,967,453,863,449,539,781,911,113,7,219,725,1015,971,1021, & + 525,785,873,191,893,297,507,215,21,153,645,913,755,371,881, & + 113,903,225,49,587,201,927,429,599,513,97,319,331,833,325, & + 887,139,927,399,163,307,803,169,1019,869,537,907,479,335,697, & + 479,353,769,787,1023,855,493,883,521,735,297,1011,991,879, & + 855,591,415,917,375,453,553,189,841,339,211,601,57,765,745, & + 621,209,875,639,7,595,971,263,1009,201,23,77,621,33,535,963, & + 661,523,263,917,103,623,231,47,301,549,337,675,189,357,1005, & + 789,189,319,721,1005,525,675,539,191,813,917,51,167,415,579, & + 755,605,721,837,529,31,327,799,961,279,409,847,649,241,285, & + 545,407,161,591,73,313,811,17,663,269,261,37,783,127,917,231, & + 577,975,793/) + v(825:1065,10) = (/ & + 921,343,751,139,221,79,817,393,545, & + 11,781,71,1,699,767,917,9,107,341,587,903,965,599,507,843, & + 739,579,397,397,325,775,565,925,75,55,979,931,93,957,857,753, & + 965,795,67,5,87,909,97,995,271,875,671,613,33,351,69,811,669, & + 729,401,647,241,435,447,721,271,745,53,775,99,343,451,427, & + 593,339,845,243,345,17,573,421,517,971,499,435,769,75,203, & + 793,985,343,955,735,523,659,703,303,421,951,405,631,825,735, & + 433,841,485,49,749,107,669,211,497,143,99,57,277,969,107,397, & + 563,551,447,381,187,57,405,731,769,923,955,915,737,595,341, & + 253,823,197,321,315,181,885,497,159,571,981,899,785,947,217, & + 217,135,753,623,565,717,903,581,955,621,361,869,87,943,907, & + 853,353,335,197,771,433,743,195,91,1023,63,301,647,205,485, & + 927,1003,987,359,577,147,141,1017,701,273,89,589,487,859,343, & + 91,847,341,173,287,1003,289,639,983,685,697,35,701,645,911, & + 501,705,873,763,745,657,559,699,315,347,429,197,165,955,859, & + 167,303,833,531,473,635,641,195,589,821,205,3,635,371,891, & + 249,123/) + v(1066:1111,10) = (/ & + 77,623,993,401,525,427,71,655,951, & + 357,851,899,535,493,323,1003,343,515,859,1017,5,423,315,1011, & + 703,41,777,163,95,831,79,975,235,633,723,297,589,317,679,981, & + 195,399,1003,121,501,155/) + v(162:376,11) = (/ & + 7,2011,1001,49,825,415,1441,383,1581, & + 623,1621,1319,1387,619,839,217,75,1955,505,281,1629,1379,53, & + 1111,1399,301,209,49,155,1647,631,129,1569,335,67,1955,1611, & + 2021,1305,121,37,877,835,1457,669,1405,935,1735,665,551,789, & + 1543,1267,1027,1,1911,163,1929,67,1975,1681,1413,191,1711, & + 1307,401,725,1229,1403,1609,2035,917,921,1789,41,2003,187,67, & + 1635,717,1449,277,1903,1179,363,1211,1231,647,1261,1029,1485, & + 1309,1149,317,1335,171,243,271,1055,1601,1129,1653,205,1463, & + 1681,1621,197,951,573,1697,1265,1321,1805,1235,1853,1307,945, & + 1197,1411,833,273,1517,1747,1095,1345,869,57,1383,221,1713, & + 335,1751,1141,839,523,1861,1105,389,1177,1877,805,93,1591, & + 423,1835,99,1781,1515,1909,1011,303,385,1635,357,973,1781, & + 1707,1363,1053,649,1469,623,1429,1241,1151,1055,503,921,3, & + 349,1149,293,45,303,877,1565,1583,1001,663,1535,395,1141, & + 1481,1797,643,1507,465,2027,1695,367,937,719,545,1991,83,819, & + 239,1791,1461,1647,1501,1161,1629,139,1595,1921,1267,1415, & + 509,347,777,1083,363,269,1015/) + v(377:589,11) = (/ & + 1809,1105,1429,1471,2019,381,2025, & + 1223,827,1733,887,1321,803,1951,1297,1995,833,1107,1135,1181, & + 1251,983,1389,1565,273,137,71,735,1005,933,67,1471,551,457, & + 1667,1729,919,285,1629,1815,653,1919,1039,531,393,1411,359, & + 221,699,1485,471,1357,1715,595,1677,153,1903,1281,215,781, & + 543,293,1807,965,1695,443,1985,321,879,1227,1915,839,1945, & + 1993,1165,51,557,723,1491,817,1237,947,1215,1911,1225,1965, & + 1889,1503,1177,73,1767,303,177,1897,1401,321,921,217,1779, & + 327,1889,333,615,1665,1825,1639,237,1205,361,129,1655,983, & + 1089,1171,401,677,643,749,303,1407,1873,1579,1491,1393,1247, & + 789,763,49,5,1607,1891,735,1557,1909,1765,1777,1127,813,695, & + 97,731,1503,1751,333,769,865,693,377,1919,957,1359,1627,1039, & + 1783,1065,1665,1917,1947,991,1997,841,459,221,327,1595,1881, & + 1269,1007,129,1413,475,1105,791,1983,1359,503,691,659,691, & + 343,1375,1919,263,1373,603,1383,297,781,145,285,767,1739, & + 1715,715,317,1333,85,831,1615,81,1667,1467,1457,1453,1825, & + 109,387,1207,2039,213,1351,1329,1173/) + v(590:802,11) = (/ & + 57,1769,951,183,23,451,1155,1551, & + 2037,811,635,1671,1451,863,1499,1673,363,1029,1077,1525,277, & + 1023,655,665,1869,1255,965,277,1601,329,1603,1901,395,65, & + 1307,2029,21,1321,543,1569,1185,1905,1701,413,2041,1697,725, & + 1417,1847,411,211,915,1891,17,1877,1699,687,1089,1973,1809, & + 851,1495,1257,63,1323,1307,609,881,1543,177,617,1505,1747, & + 1537,925,183,77,1723,1877,1703,397,459,521,257,1177,389,1947, & + 1553,1583,1831,261,485,289,1281,1543,1591,1123,573,821,1065, & + 1933,1373,2005,905,207,173,1573,1597,573,1883,1795,1499,1743, & + 553,335,333,1645,791,871,1157,969,557,141,223,1129,1685,423, & + 1069,391,99,95,1847,531,1859,1833,1833,341,237,1997,1799,409, & + 431,1917,363,335,1039,1085,1657,1975,1527,1111,659,389,899, & + 595,1439,1861,1979,1569,1087,1009,165,1895,1481,1583,29,1193, & + 1673,1075,301,1081,1377,1747,1497,1103,1789,887,739,1577,313, & + 1367,1299,1801,1131,1837,73,1865,1065,843,635,55,1655,913, & + 1037,223,1871,1161,461,479,511,1721,1107,389,151,35,375,1099, & + 937,1185,1701,769,639,1633/) + v(803:1018,11) = (/ & + 1609,379,1613,2031,685,289,975,671, & + 1599,1447,871,647,99,139,1427,959,89,117,841,891,1959,223, & + 1697,1145,499,1435,1809,1413,1445,1675,171,1073,1349,1545, & + 2039,1027,1563,859,215,1673,1919,1633,779,411,1845,1477,1489, & + 447,1545,351,1989,495,183,1639,1385,1805,1097,1249,1431,1571, & + 591,697,1509,709,31,1563,165,513,1425,1299,1081,145,1841, & + 1211,941,609,845,1169,1865,1593,347,293,1277,157,211,93,1679, & + 1799,527,41,473,563,187,1525,575,1579,857,703,1211,647,709, & + 981,285,697,163,981,153,1515,47,1553,599,225,1147,381,135, & + 821,1965,609,1033,983,503,1117,327,453,2005,1257,343,1649, & + 1199,599,1877,569,695,1587,1475,187,973,233,511,51,1083,665, & + 1321,531,1875,1939,859,1507,1979,1203,1965,737,921,1565,1943, & + 819,223,365,167,1705,413,1577,745,1573,655,1633,1003,91,1123, & + 477,1741,1663,35,715,37,1513,815,941,1379,263,1831,1735,1111, & + 1449,353,1941,1655,1349,877,285,1723,125,1753,985,723,175, & + 439,791,1051,1261,717,1555,1757,1777,577,1583,1957,873,331, & + 1163,313,1,1963,963,1905,821/) + v(1019:1111,11) = (/ & + 1677,185,709,545,1723,215,1885, & + 1249,583,1803,839,885,485,413,1767,425,129,1035,329,1263, & + 1881,1779,1565,359,367,453,707,1419,831,1889,887,1871,1869, & + 747,223,1547,1799,433,1441,553,2021,1303,1505,1735,1619,1065, & + 1161,2047,347,867,881,1447,329,781,1065,219,589,645,1257, & + 1833,749,1841,1733,1179,1191,1025,1639,1955,1423,1685,1711, & + 493,549,783,1653,397,895,233,759,1505,677,1449,1573,1297, & + 1821,1691,791,289,1187,867,1535,575,183/) + v(338:545,12) = (/ & + 3915,97,3047,937,2897,953,127,1201, & + 3819,193,2053,3061,3759,1553,2007,2493,603,3343,3751,1059, & + 783,1789,1589,283,1093,3919,2747,277,2605,2169,2905,721,4069, & + 233,261,1137,3993,3619,2881,1275,3865,1299,3757,1193,733,993, & + 1153,2945,3163,3179,437,271,3493,3971,1005,2615,2253,1131, & + 585,2775,2171,2383,2937,2447,1745,663,1515,3767,2709,1767, & + 3185,3017,2815,1829,87,3341,793,2627,2169,1875,3745,367,3783, & + 783,827,3253,2639,2955,3539,1579,2109,379,2939,3019,1999, & + 2253,2911,3733,481,1767,1055,4019,4085,105,1829,2097,2379, & + 1567,2713,737,3423,3941,2659,3961,1755,3613,1937,1559,2287, & + 2743,67,2859,325,2601,1149,3259,2403,3947,2011,175,3389,3915, & + 1315,2447,141,359,3609,3933,729,2051,1755,2149,2107,1741, & + 1051,3681,471,1055,845,257,1559,1061,2803,2219,1315,1369, & + 3211,4027,105,11,1077,2857,337,3553,3503,3917,2665,3823,3403, & + 3711,2085,1103,1641,701,4095,2883,1435,653,2363,1597,767,869, & + 1825,1117,1297,501,505,149,873,2673,551,1499,2793,3277,2143, & + 3663,533,3991,575,1877,1009,3929,473,3009,2595,3249,675,3593/) + v(546:752,12) = (/ & + 2453,1567,973,595,1335,1715,589,85, & + 2265,3069,461,1659,2627,1307,1731,1501,1699,3545,3803,2157, & + 453,2813,2047,2999,3841,2361,1079,573,69,1363,1597,3427,2899, & + 2771,1327,1117,1523,3521,2393,2537,1979,3179,683,2453,453, & + 1227,779,671,3483,2135,3139,3381,3945,57,1541,3405,3381,2371, & + 2879,1985,987,3017,3031,3839,1401,3749,2977,681,1175,1519, & + 3355,907,117,771,3741,3337,1743,1227,3335,2755,1909,3603, & + 2397,653,87,2025,2617,3257,287,3051,3809,897,2215,63,2043, & + 1757,3671,297,3131,1305,293,3865,3173,3397,2269,3673,717, & + 3041,3341,3595,3819,2871,3973,1129,513,871,1485,3977,2473, & + 1171,1143,3063,3547,2183,3993,133,2529,2699,233,2355,231, & + 3241,611,1309,3829,1839,1495,301,1169,1613,2673,243,3601, & + 3669,2813,2671,2679,3463,2477,1795,617,2317,1855,1057,1703, & + 1761,2515,801,1205,1311,473,3963,697,1221,251,381,3887,1761, & + 3093,3721,2079,4085,379,3601,3845,433,1781,29,1897,1599,2163, & + 75,3475,3957,1641,3911,2959,2833,1279,1099,403,799,2183,2699, & + 1711,2037,727,289,1785,1575,3633,2367,1261,3953,1735,171, & + 1959/) + v(753:960,12) = (/ & + 2867,859,2951,3211,15,1279,1323,599, & + 1651,3951,1011,315,3513,3351,1725,3793,2399,287,4017,3571, & + 1007,541,3115,429,1585,1285,755,1211,3047,915,3611,2697,2129, & + 3669,81,3939,2437,915,779,3567,3701,2479,3807,1893,3927,2619, & + 2543,3633,2007,3857,3837,487,1769,3759,3105,2727,3155,2479, & + 1341,1657,2767,2541,577,2105,799,17,2871,3637,953,65,69,2897, & + 3841,3559,4067,2335,3409,1087,425,2813,1705,1701,1237,821, & + 1375,3673,2693,3925,1541,1871,2285,847,4035,1101,2029,855, & + 2733,2503,121,2855,1069,3463,3505,1539,607,1349,575,2301, & + 2321,1101,333,291,2171,4085,2173,2541,1195,925,4039,1379,699, & + 1979,275,953,1755,1643,325,101,2263,3329,3673,3413,1977,2727, & + 2313,1419,887,609,2475,591,2613,2081,3805,3435,2409,111,3557, & + 3607,903,231,3059,473,2959,2925,3861,2043,3887,351,2865,369, & + 1377,2639,1261,3625,3279,2201,2949,3049,449,1297,897,1891, & + 411,2773,749,2753,1825,853,2775,3547,3923,3923,987,3723,2189, & + 3877,3577,297,2763,1845,3083,2951,483,2169,3985,245,3655, & + 3441,1023,235,835,3693,3585,327,1003,543,3059,2637/) + v(961:1111,12) = (/ & + 2923,87,3617,1031,1043,903,2913, & + 2177,2641,3279,389,2009,525,4085,3299,987,2409,813,2683,373, & + 2695,3775,2375,1119,2791,223,325,587,1379,2877,2867,3793,655, & + 831,3425,1663,1681,2657,1865,3943,2977,1979,2271,3247,1267, & + 1747,811,159,429,2001,1195,3065,553,1499,3529,1081,2877,3077, & + 845,1793,2409,3995,2559,4081,1195,2955,1117,1409,785,287, & + 1521,1607,85,3055,3123,2533,2329,3477,799,3683,3715,337,3139, & + 3311,431,3511,2299,365,2941,3067,1331,1081,1097,2853,2299, & + 495,1745,749,3819,619,1059,3559,183,3743,723,949,3501,733, & + 2599,3983,3961,911,1899,985,2493,1795,653,157,433,2361,3093, & + 3119,3679,2367,1701,1445,1321,2397,1241,3305,3985,2349,4067, & + 3805,3073,2837,1567,3783,451,2441,1181,487,543,1201,3735, & + 2517,733,1535,2175,3613,3019/) + v(482:680,13) = (/ & + 2319,653,1379,1675,1951,7075,2087, & + 7147,1427,893,171,2019,7235,5697,3615,1961,7517,6849,2893, & + 1883,2863,2173,4543,73,381,3893,6045,1643,7669,1027,1549, & + 3983,1985,6589,7497,2745,2375,7047,1117,1171,1975,5199,3915, & + 3695,8113,4303,3773,7705,6855,1675,2245,2817,1719,569,1021, & + 2077,5945,1833,2631,4851,6371,833,7987,331,1899,8093,6719, & + 6903,5903,5657,5007,2689,6637,2675,1645,1819,689,6709,7717, & + 6295,7013,7695,3705,7069,2621,3631,6571,6259,7261,3397,7645, & + 1115,4753,2047,7579,2271,5403,4911,7629,4225,1209,6955,6951, & + 1829,5579,5231,1783,4285,7425,599,5785,3275,5643,2263,657, & + 6769,6261,1251,3249,4447,4111,3991,1215,131,4397,3487,7585, & + 5565,7199,3573,7105,7409,1671,949,3889,5971,3333,225,3647, & + 5403,3409,7459,6879,5789,6567,5581,4919,1927,4407,8085,4691, & + 611,3005,591,753,589,171,5729,5891,1033,3049,6567,5257,8003, & + 1757,4489,4923,6379,5171,1757,689,3081,1389,4113,455,2761, & + 847,7575,5829,633,6629,1103,7635,803,6175,6587,2711,3879,67, & + 1179,4761,7281,1557,3379,2459,4273,4127,7147,35/) + v(681:877,13) = (/ & + 3549,395,3735,5787,4179,5889,5057, & + 7473,4713,2133,2897,1841,2125,1029,1695,6523,1143,5105,7133, & + 3351,2775,3971,4503,7589,5155,4305,1641,4717,2427,5617,1267, & + 399,5831,4305,4241,3395,3045,4899,1713,171,411,7099,5473, & + 5209,1195,1077,1309,2953,7343,4887,3229,6759,6721,6775,675, & + 4039,2493,7511,3269,4199,6625,7943,2013,4145,667,513,2303, & + 4591,7941,2741,987,8061,3161,5951,1431,831,5559,7405,1357, & + 4319,4235,5421,2559,4415,2439,823,1725,6219,4903,6699,5451, & + 349,7703,2927,7809,6179,1417,5987,3017,4983,3479,4525,4643, & + 4911,227,5475,2287,5581,6817,1937,1421,4415,7977,1789,3907, & + 6815,6789,6003,5609,4507,337,7427,7943,3075,6427,1019,7121, & + 4763,81,3587,2929,1795,8067,2415,1265,4025,5599,4771,3025, & + 2313,6129,7611,6881,5253,4413,7869,105,3173,1629,2537,1023, & + 4409,7209,4413,7107,7469,33,1955,2881,5167,6451,4211,179, & + 5573,7879,3387,7759,5455,7157,1891,5683,5689,6535,3109,6555, & + 6873,1249,4251,6437,49,2745,1201,7327,4179,6783,623,2779, & + 5963,2585,6927,5333,4033,285,7467,4443,4917,3/) + v(878:1070,13) = (/ & + 4319,5517,3449,813,5499,2515,5771, & + 3357,2073,4395,4925,2643,7215,5817,1199,1597,1619,7535,4833, & + 609,4797,8171,6847,793,6757,8165,3371,2431,5235,4739,7703, & + 7223,6525,5891,5605,4433,3533,5267,5125,5037,225,6717,1121, & + 5741,2013,4327,4839,569,5227,7677,4315,2391,5551,859,3627, & + 6377,3903,4311,6527,7573,4905,7731,1909,1555,3279,1949,1887, & + 6675,5509,2033,5473,3539,5033,5935,6095,4761,1771,1271,1717, & + 4415,5083,6277,3147,7695,2461,4783,4539,5833,5583,651,1419, & + 2605,5511,3913,5795,2333,2329,4431,3725,6069,2699,7055,6879, & + 1017,3121,2547,4603,2385,6915,6103,5669,7833,2001,4287,6619, & + 955,2761,5711,6291,3415,3909,2841,5627,4939,7671,6059,6275, & + 6517,1931,4583,7301,1267,7509,1435,2169,6939,3515,2985,2787, & + 2123,1969,3307,353,4359,7059,5273,5873,6657,6765,6229,3179, & + 1583,6237,2155,371,273,7491,3309,6805,3015,6831,7819,713, & + 4747,3935,4109,1311,709,3089,7059,4247,2989,1509,4919,1841, & + 3045,3821,6929,4655,1333,6429,6649,2131,5265,1051,261,8057, & + 3379,2179,1993,5655,3063,6381/) + v(1071:1111,13) = (/ & + 3587,7417,1579,1541,2107,5085,2873, & + 6141,955,3537,2157,841,1999,1465,5171,5651,1535,7235,4349, & + 1263,1453,1005,6893,2919,1947,1635,3963,397,969,4569,655, & + 6737,2995,7235,7713,973,4821,2377,1673,1,6541/) + ! + ! Set POLY. + ! + poly(1:211)= (/ & + 1,3,7,11,13,19,25,37,59,47,61,55,41,67,97,91, & + 109,103,115,131,193,137,145,143,241,157,185,167,229,171,213, & + 191,253,203,211,239,247,285,369,299,301,333,351,355,357,361, & + 391,397,425,451,463,487,501,529,539,545,557,563,601,607,617, & + 623,631,637,647,661,675,677,687,695,701,719,721,731,757,761, & + 787,789,799,803,817,827,847,859,865,875,877,883,895,901,911, & + 949,953,967,971,973,981,985,995,1001,1019,1033,1051,1063, & + 1069,1125,1135,1153,1163,1221,1239,1255,1267,1279,1293,1305, & + 1315,1329,1341,1347,1367,1387,1413,1423,1431,1441,1479,1509, & + 1527,1531,1555,1557,1573,1591,1603,1615,1627,1657,1663,1673, & + 1717,1729,1747,1759,1789,1815,1821,1825,1849,1863,1869,1877, & + 1881,1891,1917,1933,1939,1969,2011,2035,2041,2053,2071,2091, & + 2093,2119,2147,2149,2161,2171,2189,2197,2207,2217,2225,2255, & + 2257,2273,2279,2283,2293,2317,2323,2341,2345,2363,2365,2373, & + 2377,2385,2395,2419,2421,2431,2435,2447,2475,2477,2489,2503, & + 2521,2533,2551,2561,2567,2579,2581,2601,2633,2657,2669/) + poly(212:401)= (/ & + 2681,2687,2693,2705,2717,2727,2731,2739, & + 2741,2773,2783,2793,2799,2801,2811,2819,2825,2833,2867,2879, & + 2881,2891,2905,2911,2917,2927,2941,2951,2955,2963,2965,2991, & + 2999,3005,3017,3035,3037,3047,3053,3083,3085,3097,3103,3159, & + 3169,3179,3187,3205,3209,3223,3227,3229,3251,3263,3271,3277, & + 3283,3285,3299,3305,3319,3331,3343,3357,3367,3373,3393,3399, & + 3413,3417,3427,3439,3441,3475,3487,3497,3515,3517,3529,3543, & + 3547,3553,3559,3573,3589,3613,3617,3623,3627,3635,3641,3655, & + 3659,3669,3679,3697,3707,3709,3713,3731,3743,3747,3771,3791, & + 3805,3827,3833,3851,3865,3889,3895,3933,3947,3949,3957,3971, & + 3985,3991,3995,4007,4013,4021,4045,4051,4069,4073,4179,4201, & + 4219,4221,4249,4305,4331,4359,4383,4387,4411,4431,4439,4449, & + 4459,4485,4531,4569,4575,4621,4663,4669,4711,4723,4735,4793, & + 4801,4811,4879,4893,4897,4921,4927,4941,4977,5017,5027,5033, & + 5127,5169,5175,5199,5213,5223,5237,5287,5293,5331,5391,5405, & + 5453,5523,5573,5591,5597,5611,5641,5703,5717,5721,5797,5821, & + 5909,5913/) + poly(402:591)= (/ & + 5955,5957,6005,6025,6061,6067,6079,6081, & + 6231,6237,6289,6295,6329,6383,6427,6453,6465,6501,6523,6539, & + 6577,6589,6601,6607,6631,6683,6699,6707,6761,6795,6865,6881, & + 6901,6923,6931,6943,6999,7057,7079,7103,7105,7123,7173,7185, & + 7191,7207,7245,7303,7327,7333,7355,7365,7369,7375,7411,7431, & + 7459,7491,7505,7515,7541,7557,7561,7701,7705,7727,7749,7761, & + 7783,7795,7823,7907,7953,7963,7975,8049,8089,8123,8125,8137, & + 8219,8231,8245,8275,8293,8303,8331,8333,8351,8357,8367,8379, & + 8381,8387,8393,8417,8435,8461,8469,8489,8495,8507,8515,8551, & + 8555,8569,8585,8599,8605,8639,8641,8647,8653,8671,8675,8689, & + 8699,8729,8741,8759,8765,8771,8795,8797,8825,8831,8841,8855, & + 8859,8883,8895,8909,8943,8951,8955,8965,8999,9003,9031,9045, & + 9049,9071,9073,9085,9095,9101,9109,9123,9129,9137,9143,9147, & + 9185,9197,9209,9227,9235,9247,9253,9257,9277,9297,9303,9313, & + 9325,9343,9347,9371,9373,9397,9407,9409,9415,9419,9443,9481, & + 9495,9501,9505,9517,9529,9555,9557,9571,9585,9591,9607,9611, & + 9621,9625/) + poly(592:765)= (/ & + 9631,9647,9661,9669,9679,9687,9707,9731, & + 9733,9745,9773,9791,9803,9811,9817,9833,9847,9851,9863,9875, & + 9881,9905,9911,9917,9923,9963,9973,10003,10025,10043,10063, & + 10071,10077,10091,10099,10105,10115,10129,10145,10169,10183, & + 10187,10207,10223,10225,10247,10265,10271,10275,10289,10299, & + 10301,10309,10343,10357,10373,10411,10413,10431,10445,10453, & + 10463,10467,10473,10491,10505,10511,10513,10523,10539,10549, & + 10559,10561,10571,10581,10615,10621,10625,10643,10655,10671, & + 10679,10685,10691,10711,10739,10741,10755,10767,10781,10785, & + 10803,10805,10829,10857,10863,10865,10875,10877,10917,10921, & + 10929,10949,10967,10971,10987,10995,11009,11029,11043,11045, & + 11055,11063,11075,11081,11117,11135,11141,11159,11163,11181, & + 11187,11225,11237,11261,11279,11297,11307,11309,11327,11329, & + 11341,11377,11403,11405,11413,11427,11439,11453,11461,11473, & + 11479,11489,11495,11499,11533,11545,11561,11567,11575,11579, & + 11589,11611,11623,11637,11657,11663,11687,11691,11701,11747, & + 11761,11773,11783,11795,11797,11817,11849,11855,11867,11869, & + 11873,11883,11919/) + poly(766:936)= (/ & + 11921,11927,11933,11947,11955,11961, & + 11999,12027,12029,12037,12041,12049,12055,12095,12097,12107, & + 12109,12121,12127,12133,12137,12181,12197,12207,12209,12239, & + 12253,12263,12269,12277,12287,12295,12309,12313,12335,12361, & + 12367,12391,12409,12415,12433,12449,12469,12479,12481,12499, & + 12505,12517,12527,12549,12559,12597,12615,12621,12639,12643, & + 12657,12667,12707,12713,12727,12741,12745,12763,12769,12779, & + 12781,12787,12799,12809,12815,12829,12839,12857,12875,12883, & + 12889,12901,12929,12947,12953,12959,12969,12983,12987,12995, & + 13015,13019,13031,13063,13077,13103,13137,13149,13173,13207, & + 13211,13227,13241,13249,13255,13269,13283,13285,13303,13307, & + 13321,13339,13351,13377,13389,13407,13417,13431,13435,13447, & + 13459,13465,13477,13501,13513,13531,13543,13561,13581,13599, & + 13605,13617,13623,13637,13647,13661,13677,13683,13695,13725, & + 13729,13753,13773,13781,13785,13795,13801,13807,13825,13835, & + 13855,13861,13871,13883,13897,13905,13915,13939,13941,13969, & + 13979,13981,13997,14027,14035,14037,14051,14063,14085,14095, & + 14107,14113,14125,14137,14145/) + poly(937:1107)= (/ & + 14151,14163,14193,14199,14219,14229, & + 14233,14243,14277,14287,14289,14295,14301,14305,14323,14339, & + 14341,14359,14365,14375,14387,14411,14425,14441,14449,14499, & + 14513,14523,14537,14543,14561,14579,14585,14593,14599,14603, & + 14611,14641,14671,14695,14701,14723,14725,14743,14753,14759, & + 14765,14795,14797,14803,14831,14839,14845,14855,14889,14895, & + 14909,14929,14941,14945,14951,14963,14965,14985,15033,15039, & + 15053,15059,15061,15071,15077,15081,15099,15121,15147,15149, & + 15157,15167,15187,15193,15203,15205,15215,15217,15223,15243, & + 15257,15269,15273,15287,15291,15313,15335,15347,15359,15373, & + 15379,15381,15391,15395,15397,15419,15439,15453,15469,15491, & + 15503,15517,15527,15531,15545,15559,15593,15611,15613,15619, & + 15639,15643,15649,15661,15667,15669,15681,15693,15717,15721, & + 15741,15745,15765,15793,15799,15811,15825,15835,15847,15851, & + 15865,15877,15881,15887,15899,15915,15935,15937,15955,15973, & + 15977,16011,16035,16061,16069,16087,16093,16097,16121,16141, & + 16153,16159,16165,16183,16189,16195,16197,16201,16209,16215, & + 16225,16259,16265,16273,16299/) + poly(1108:1111)= (/ & + 16309,16355,16375,16381/) + + end if + ! + ! Things to do only if the dimension changed. + ! + if ( dim_num /= dim_num_save ) then + ! + ! Check parameters. + ! + if ( dim_num < 1 .or. dim_max < dim_num ) then + write ( *, '(a)' ) ' ' + write ( *, '(a)' ) 'I8_SOBOL - Fatal error!' + write ( *, '(a)' ) ' The spatial dimension DIM_NUM should satisfy:' + write ( *, '(a,i8)' ) ' 2 <= DIM_NUM <= ', dim_max + write ( *, '(a,i8)' ) ' But this input value is DIM_NUM = ', dim_num + stop + end if + + dim_num_save = dim_num + ! + ! Set ATMOST = 2^LOG_MAX - 1. + ! + atmost = 0 + do i = 1, log_max + atmost = 2 * atmost + 1 + end do + ! + ! Find the highest 1 bit in ATMOST (should be LOG_MAX). + ! + maxcol = i8_bit_hi1 ( atmost ) + ! + ! Initialize row 1 of V. + ! + v(1,1:maxcol) = 1 + ! + ! Initialize the remaining rows of V. + ! + do i = 2, dim_num + ! + ! The bit pattern of the integer POLY(I) gives the form + ! of polynomial I. + ! + ! Find the degree of polynomial I from binary encoding. + ! + j = poly(i) + m = 0 + + do + + j = j / 2 + + if ( j <= 0 ) then + exit + end if + + m = m + 1 + + end do + ! + ! Expand this bit pattern to separate components of the logical array INCLUD. + ! + j = poly(i) + do k = m, 1, - 1 + j2 = j / 2 + includ(k) = ( j /= ( 2 * j2 ) ) + j = j2 + end do + ! + ! Calculate the remaining elements of row I as explained + ! in Bratley and Fox, section 2. + ! + do j = m + 1, maxcol + newv = v(i,j-m) + l = 1 + do k = 1, m + l = 2 * l + if ( includ(k) ) then + newv = ieor ( newv, l * v(i,j-k) ) + end if + end do + v(i,j) = newv + end do + end do + ! + ! Multiply columns of V by appropriate power of 2. + ! + l = 1 + do j = maxcol - 1, 1, - 1 + l = 2 * l + v(1:dim_num,j) = v(1:dim_num,j) * l + end do + ! + ! RECIPD is 1/(common denominator of the elements in V) = 1 / ( 2 * L ). + ! + recipd = real (l, real64) + recipd = 0.5_real64 / recipd + + end if + + if ( seed < 0 ) then + seed = 0 + end if + + if ( seed == 0 ) then + + l = 1 + lastq(1:dim_num) = 0 + + else if ( seed == seed_save + 1 ) then + ! + ! Find the position of the right-hand zero in SEED. + ! + l = i8_bit_lo0 ( seed ) + + else if ( seed <= seed_save ) then + + seed_save = 0 + l = 1 + lastq(1:dim_num) = 0 + + do seed_temp = seed_save, seed - 1 + l = i8_bit_lo0 ( seed_temp ) + lastq(1:dim_num) = ieor ( lastq(1:dim_num), v(1:dim_num,l) ) + end do + + l = i8_bit_lo0 ( seed ) + + else if ( seed_save + 1 < seed ) then + + do seed_temp = seed_save+1, seed - 1 + l = i8_bit_lo0 ( seed_temp ) + lastq(1:dim_num) = ieor ( lastq(1:dim_num), v(1:dim_num,l) ) + end do + + l = i8_bit_lo0 ( seed ) + + end if + ! + ! Check that the user is not calling too many times! + ! + if ( maxcol < l ) then + write ( *, '(a)' ) ' ' + write ( *, '(a)' ) 'I8_SOBOL - Fatal error!' + write ( *, '(a)' ) ' Too many calls!' + write ( *, '(a,i12)' ) ' MAXCOL = ', maxcol + write ( *, '(a,i12)' ) ' L = ', l + stop + end if + ! + ! Calculate the new components of QUASI. + ! + quasi(1:dim_num) = real (lastq(1:dim_num), real64) * recipd + lastq(1:dim_num) = ieor ( lastq(1:dim_num), v(1:dim_num,l) ) + + seed_save = seed + seed = seed + 1 + +end subroutine i8_sobol diff --git a/mex/sources/sobol/sobol.hh b/mex/sources/sobol/sobol.hh index ca8fe3df62f1df8b1db107627b251ff0ed7dea43..8dd62ccdeac0c71e314ea7e182b845f5c18f0f24 100644 --- a/mex/sources/sobol/sobol.hh +++ b/mex/sources/sobol/sobol.hh @@ -1,540 +1,44 @@ -/* Quasi Monte Carlo sequences (à la Sobol). -** -** Original files downloaded from http://people.sc.fsu.edu/~burkardt/cpp_src/sobol/ (version 17-Feb-2009 09:46) -** -** Copyright © 2009 John Burkardt -** Copyright © 2010-2017 Dynare Team -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU Lesser General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program 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 Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ +/* Interface to quasi Monte Carlo sequences (à la Sobol) routines. + * + * Copyright © 2010-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/>. + */ -#include <cstdlib> -#include <iostream> -#include <iomanip> -#include <cmath> -#include <ctime> - -#include "initialize_v_array.hh" - -using namespace std; +#include <cstdint> +#include <dynblas.h> // For the FORTRAN_WRAPPER macro constexpr int DIM_MAX = 1111; -template<typename T> -int -bit_hi1(T n) -/* -** This function returns the position of the high 1 bit base 2 in an integer. -** -** Example: -** -** N Binary Hi 1 -** ---- -------- ---- -** 0 0 0 -** 1 1 1 -** 2 10 2 -** 3 11 2 -** 4 100 3 -** 5 101 3 -** 6 110 3 -** 7 111 3 -** 8 1000 4 -** 9 1001 4 -** 10 1010 4 -** 11 1011 4 -** 12 1100 4 -** 13 1101 4 -** 14 1110 4 -** 15 1111 4 -** 16 10000 5 -** 17 10001 5 -** 1023 1111111111 10 -** 1024 10000000000 11 -** 1025 10000000001 11 -** -** -** Original files downloaded from http://people.sc.fsu.edu/~burkardt/cpp_src/sobol/ (version 17-Feb-2009 09:46) -** -** Input, int or long long, the integer to be measured. -** N should be nonnegative. If N is nonpositive, BIT_HI1 will always be 0. -** -** Output: the location of the high order bit. -*/ -{ - int bit = 0; - while (n > 0) - { - bit++; - n = n/2; - } - return bit; -} - -template<typename T> -int -bit_lo0(T n) -/* -** This function returns the position of the low 0 bit base 2 in an integer. -** -** Example: -** -** N Binary Lo 0 -** ---- -------- ---- -** 0 0 1 -** 1 1 2 -** 2 10 1 -** 3 11 3 -** 4 100 1 -** 5 101 2 -** 6 110 1 -** 7 111 4 -** 8 1000 1 -** 9 1001 2 -** 10 1010 1 -** 11 1011 3 -** 12 1100 1 -** 13 1101 2 -** 14 1110 1 -** 15 1111 5 -** 16 10000 1 -** 17 10001 2 -** 1023 1111111111 1 -** 1024 10000000000 1 -** 1025 10000000001 1 -** -** -** Original files downloaded from http://people.sc.fsu.edu/~burkardt/cpp_src/sobol/ (version 17-Feb-2009 09:46) -** -** INPUTS -** -** Input, int N, the integer to be measured. -** N should be nonnegative. -** -** OUTPUTS (int) the position of the low 0 bit. -*/ +// Interface to Fortran code +extern "C" { - int bit = 0; - while (true) - { - bit++; - T n2 = n/2; - if (n == 2*n2) - break; - - n = n2; - } - return bit; -} - -template<typename T> -T -ixor(T i, T j) -/* -** This function calculates the exclusive OR of two integers. -** -** Original files downloaded from http://people.sc.fsu.edu/~burkardt/cpp_src/sobol/ (version 17-Feb-2009 09:46) -** -** INPUTS I, J, two integer to be exclusive OR-ed. -** -** OUTPUTS (integer) the exclusive OR of I and J. -*/ -{ - T k = 0; - T l = 1; - while (i != 0 || j != 0) - { - T i2 = i / 2; - T j2 = j / 2; - if (((i == 2 * i2) && (j != 2 * j2)) - || ((i != 2 * i2) && (j == 2 * j2))) - { - k = k + l; - } - i = i2; - j = j2; - l = 2 * l; - } - return k; +#define i8_sobol FORTRAN_WRAPPER(i8_sobol) + void i8_sobol(const int64_t *dim_num, int64_t *seed, double *quasi); } -template<typename T1, typename T2> -void -next_sobol(int dim_num, T1 *seed, T2 *quasi) -/* -** This function generates a new quasirandom Sobol vector with each call. -** -** Discussion: -** -** The routine adapts the ideas of Antonov and Saleev. -** -** This routine uses LONG LONG INT for integers and DOUBLE for real values or -** INT for integers and FLOAT for real values. -** -** Thanks to Steffan Berridge for supplying (twice) the properly -** formatted V data needed to extend the original routine's dimension -** limit from 40 to 1111, 05 June 2007. -** -** Thanks to Francis Dalaudier for pointing out that the range of allowed -** values of DIM_NUM should start at 1, not 2! 17 February 2009. -** -** Original files downloaded from http://people.sc.fsu.edu/~burkardt/cpp_src/sobol/ (version 17-Feb-2009 09:46) -** -** Reference: -** -** IA Antonov, VM Saleev, -** An Economic Method of Computing LP Tau-Sequences, -** USSR Computational Mathematics and Mathematical Physics, -** Volume 19, 1980, pages 252 - 256. -** -** Paul Bratley, Bennett Fox, -** Algorithm 659: -** Implementing Sobol's Quasirandom Sequence Generator, -** ACM Transactions on Mathematical Software, -** Volume 14, Number 1, pages 88-100, 1988. -** -** Bennett Fox, -** Algorithm 647: -** Implementation and Relative Efficiency of Quasirandom -** Sequence Generators, -** ACM Transactions on Mathematical Software, -** Volume 12, Number 4, pages 362-376, 1986. -** -** Stephen Joe, Frances Kuo -** Remark on Algorithm 659: -** Implementing Sobol's Quasirandom Sequence Generator, -** ACM Transactions on Mathematical Software, -** Volume 29, Number 1, pages 49-57, March 2003. -** -** Ilya Sobol, -** USSR Computational Mathematics and Mathematical Physics, -** Volume 16, pages 236-242, 1977. -** -** Ilya Sobol, YL Levitan, -** The Production of Points Uniformly Distributed in a Multidimensional -** Cube (in Russian), -** Preprint IPM Akad. Nauk SSSR, -** Number 40, Moscow 1976. -** -** Parameters: -** -** Input, int DIM_NUM, the number of spatial dimensions. -** DIM_NUM must satisfy 1 <= DIM_NUM <= 1111. -** -** Input/output, long long int *SEED, the "seed" for the sequence. -** This is essentially the index in the sequence of the quasirandom -** value to be generated. On output, SEED has been set to the -** appropriate next value, usually simply SEED+1. -** If SEED is less than 0 on input, it is treated as though it were 0. -** An input value of 0 requests the first (0-th) element of the sequence. -** -** Output, double QUASI[DIM_NUM], the next quasirandom vector. -*/ +inline void +next_sobol(int dim_num, int64_t *seed, double *quasi) { - static T1 atmost; - static int dim_num_save = 0; - int LOG_MAX = sizeof(T1)*8-2; - bool includ[LOG_MAX]; - static bool initialized = false; - static T1 lastq[DIM_MAX]; - static T1 maxcol; - T1 l = 0; - static T1 poly[DIM_MAX] = - { - 1, 3, 7, 11, 13, 19, 25, 37, 59, 47, - 61, 55, 41, 67, 97, 91, 109, 103, 115, 131, - 193, 137, 145, 143, 241, 157, 185, 167, 229, 171, - 213, 191, 253, 203, 211, 239, 247, 285, 369, 299, - 301, 333, 351, 355, 357, 361, 391, 397, 425, 451, - 463, 487, 501, 529, 539, 545, 557, 563, 601, 607, - 617, 623, 631, 637, 647, 661, 675, 677, 687, 695, - 701, 719, 721, 731, 757, 761, 787, 789, 799, 803, - 817, 827, 847, 859, 865, 875, 877, 883, 895, 901, - 911, 949, 953, 967, 971, 973, 981, 985, 995, 1001, - 1019, 1033, 1051, 1063, 1069, 1125, 1135, 1153, 1163, 1221, - 1239, 1255, 1267, 1279, 1293, 1305, 1315, 1329, 1341, 1347, - 1367, 1387, 1413, 1423, 1431, 1441, 1479, 1509, 1527, 1531, - 1555, 1557, 1573, 1591, 1603, 1615, 1627, 1657, 1663, 1673, - 1717, 1729, 1747, 1759, 1789, 1815, 1821, 1825, 1849, 1863, - 1869, 1877, 1881, 1891, 1917, 1933, 1939, 1969, 2011, 2035, - 2041, 2053, 2071, 2091, 2093, 2119, 2147, 2149, 2161, 2171, - 2189, 2197, 2207, 2217, 2225, 2255, 2257, 2273, 2279, 2283, - 2293, 2317, 2323, 2341, 2345, 2363, 2365, 2373, 2377, 2385, - 2395, 2419, 2421, 2431, 2435, 2447, 2475, 2477, 2489, 2503, - 2521, 2533, 2551, 2561, 2567, 2579, 2581, 2601, 2633, 2657, - 2669, 2681, 2687, 2693, 2705, 2717, 2727, 2731, 2739, 2741, - 2773, 2783, 2793, 2799, 2801, 2811, 2819, 2825, 2833, 2867, - 2879, 2881, 2891, 2905, 2911, 2917, 2927, 2941, 2951, 2955, - 2963, 2965, 2991, 2999, 3005, 3017, 3035, 3037, 3047, 3053, - 3083, 3085, 3097, 3103, 3159, 3169, 3179, 3187, 3205, 3209, - 3223, 3227, 3229, 3251, 3263, 3271, 3277, 3283, 3285, 3299, - 3305, 3319, 3331, 3343, 3357, 3367, 3373, 3393, 3399, 3413, - 3417, 3427, 3439, 3441, 3475, 3487, 3497, 3515, 3517, 3529, - 3543, 3547, 3553, 3559, 3573, 3589, 3613, 3617, 3623, 3627, - 3635, 3641, 3655, 3659, 3669, 3679, 3697, 3707, 3709, 3713, - 3731, 3743, 3747, 3771, 3791, 3805, 3827, 3833, 3851, 3865, - 3889, 3895, 3933, 3947, 3949, 3957, 3971, 3985, 3991, 3995, - 4007, 4013, 4021, 4045, 4051, 4069, 4073, 4179, 4201, 4219, - 4221, 4249, 4305, 4331, 4359, 4383, 4387, 4411, 4431, 4439, - 4449, 4459, 4485, 4531, 4569, 4575, 4621, 4663, 4669, 4711, - 4723, 4735, 4793, 4801, 4811, 4879, 4893, 4897, 4921, 4927, - 4941, 4977, 5017, 5027, 5033, 5127, 5169, 5175, 5199, 5213, - 5223, 5237, 5287, 5293, 5331, 5391, 5405, 5453, 5523, 5573, - 5591, 5597, 5611, 5641, 5703, 5717, 5721, 5797, 5821, 5909, - 5913, 5955, 5957, 6005, 6025, 6061, 6067, 6079, 6081, 6231, - 6237, 6289, 6295, 6329, 6383, 6427, 6453, 6465, 6501, 6523, - 6539, 6577, 6589, 6601, 6607, 6631, 6683, 6699, 6707, 6761, - 6795, 6865, 6881, 6901, 6923, 6931, 6943, 6999, 7057, 7079, - 7103, 7105, 7123, 7173, 7185, 7191, 7207, 7245, 7303, 7327, - 7333, 7355, 7365, 7369, 7375, 7411, 7431, 7459, 7491, 7505, - 7515, 7541, 7557, 7561, 7701, 7705, 7727, 7749, 7761, 7783, - 7795, 7823, 7907, 7953, 7963, 7975, 8049, 8089, 8123, 8125, - 8137, 8219, 8231, 8245, 8275, 8293, 8303, 8331, 8333, 8351, - 8357, 8367, 8379, 8381, 8387, 8393, 8417, 8435, 8461, 8469, - 8489, 8495, 8507, 8515, 8551, 8555, 8569, 8585, 8599, 8605, - 8639, 8641, 8647, 8653, 8671, 8675, 8689, 8699, 8729, 8741, - 8759, 8765, 8771, 8795, 8797, 8825, 8831, 8841, 8855, 8859, - 8883, 8895, 8909, 8943, 8951, 8955, 8965, 8999, 9003, 9031, - 9045, 9049, 9071, 9073, 9085, 9095, 9101, 9109, 9123, 9129, - 9137, 9143, 9147, 9185, 9197, 9209, 9227, 9235, 9247, 9253, - 9257, 9277, 9297, 9303, 9313, 9325, 9343, 9347, 9371, 9373, - 9397, 9407, 9409, 9415, 9419, 9443, 9481, 9495, 9501, 9505, - 9517, 9529, 9555, 9557, 9571, 9585, 9591, 9607, 9611, 9621, - 9625, 9631, 9647, 9661, 9669, 9679, 9687, 9707, 9731, 9733, - 9745, 9773, 9791, 9803, 9811, 9817, 9833, 9847, 9851, 9863, - 9875, 9881, 9905, 9911, 9917, 9923, 9963, 9973, 10003, 10025, - 10043, 10063, 10071, 10077, 10091, 10099, 10105, 10115, 10129, 10145, - 10169, 10183, 10187, 10207, 10223, 10225, 10247, 10265, 10271, 10275, - 10289, 10299, 10301, 10309, 10343, 10357, 10373, 10411, 10413, 10431, - 10445, 10453, 10463, 10467, 10473, 10491, 10505, 10511, 10513, 10523, - 10539, 10549, 10559, 10561, 10571, 10581, 10615, 10621, 10625, 10643, - 10655, 10671, 10679, 10685, 10691, 10711, 10739, 10741, 10755, 10767, - 10781, 10785, 10803, 10805, 10829, 10857, 10863, 10865, 10875, 10877, - 10917, 10921, 10929, 10949, 10967, 10971, 10987, 10995, 11009, 11029, - 11043, 11045, 11055, 11063, 11075, 11081, 11117, 11135, 11141, 11159, - 11163, 11181, 11187, 11225, 11237, 11261, 11279, 11297, 11307, 11309, - 11327, 11329, 11341, 11377, 11403, 11405, 11413, 11427, 11439, 11453, - 11461, 11473, 11479, 11489, 11495, 11499, 11533, 11545, 11561, 11567, - 11575, 11579, 11589, 11611, 11623, 11637, 11657, 11663, 11687, 11691, - 11701, 11747, 11761, 11773, 11783, 11795, 11797, 11817, 11849, 11855, - 11867, 11869, 11873, 11883, 11919, 11921, 11927, 11933, 11947, 11955, - 11961, 11999, 12027, 12029, 12037, 12041, 12049, 12055, 12095, 12097, - 12107, 12109, 12121, 12127, 12133, 12137, 12181, 12197, 12207, 12209, - 12239, 12253, 12263, 12269, 12277, 12287, 12295, 12309, 12313, 12335, - 12361, 12367, 12391, 12409, 12415, 12433, 12449, 12469, 12479, 12481, - 12499, 12505, 12517, 12527, 12549, 12559, 12597, 12615, 12621, 12639, - 12643, 12657, 12667, 12707, 12713, 12727, 12741, 12745, 12763, 12769, - 12779, 12781, 12787, 12799, 12809, 12815, 12829, 12839, 12857, 12875, - 12883, 12889, 12901, 12929, 12947, 12953, 12959, 12969, 12983, 12987, - 12995, 13015, 13019, 13031, 13063, 13077, 13103, 13137, 13149, 13173, - 13207, 13211, 13227, 13241, 13249, 13255, 13269, 13283, 13285, 13303, - 13307, 13321, 13339, 13351, 13377, 13389, 13407, 13417, 13431, 13435, - 13447, 13459, 13465, 13477, 13501, 13513, 13531, 13543, 13561, 13581, - 13599, 13605, 13617, 13623, 13637, 13647, 13661, 13677, 13683, 13695, - 13725, 13729, 13753, 13773, 13781, 13785, 13795, 13801, 13807, 13825, - 13835, 13855, 13861, 13871, 13883, 13897, 13905, 13915, 13939, 13941, - 13969, 13979, 13981, 13997, 14027, 14035, 14037, 14051, 14063, 14085, - 14095, 14107, 14113, 14125, 14137, 14145, 14151, 14163, 14193, 14199, - 14219, 14229, 14233, 14243, 14277, 14287, 14289, 14295, 14301, 14305, - 14323, 14339, 14341, 14359, 14365, 14375, 14387, 14411, 14425, 14441, - 14449, 14499, 14513, 14523, 14537, 14543, 14561, 14579, 14585, 14593, - 14599, 14603, 14611, 14641, 14671, 14695, 14701, 14723, 14725, 14743, - 14753, 14759, 14765, 14795, 14797, 14803, 14831, 14839, 14845, 14855, - 14889, 14895, 14909, 14929, 14941, 14945, 14951, 14963, 14965, 14985, - 15033, 15039, 15053, 15059, 15061, 15071, 15077, 15081, 15099, 15121, - 15147, 15149, 15157, 15167, 15187, 15193, 15203, 15205, 15215, 15217, - 15223, 15243, 15257, 15269, 15273, 15287, 15291, 15313, 15335, 15347, - 15359, 15373, 15379, 15381, 15391, 15395, 15397, 15419, 15439, 15453, - 15469, 15491, 15503, 15517, 15527, 15531, 15545, 15559, 15593, 15611, - 15613, 15619, 15639, 15643, 15649, 15661, 15667, 15669, 15681, 15693, - 15717, 15721, 15741, 15745, 15765, 15793, 15799, 15811, 15825, 15835, - 15847, 15851, 15865, 15877, 15881, 15887, 15899, 15915, 15935, 15937, - 15955, 15973, 15977, 16011, 16035, 16061, 16069, 16087, 16093, 16097, - 16121, 16141, 16153, 16159, 16165, 16183, 16189, 16195, 16197, 16201, - 16209, 16215, 16225, 16259, 16265, 16273, 16299, 16309, 16355, 16375, - 16381 - }; - static T2 recipd; - static T1 seed_save = -1; - static T1 **v; - if (!initialized || dim_num != dim_num_save) - { - v = new T1 *[DIM_MAX]; - for (int i = 0; i < DIM_MAX; i++) - v[i] = new T1[LOG_MAX]; - initialized = true; - initialize_v_array(DIM_MAX, LOG_MAX, v); - /* - ** Check parameters. - */ - if (dim_num < 1 || DIM_MAX < dim_num) - { - cout << "\n"; - cout << "NEXT_SOBOL - Fatal error!\n"; - cout << " The spatial dimension DIM_NUM should satisfy:\n"; - cout << " 1 <= DIM_NUM <= " << DIM_MAX << "\n"; - cout << " But this input value is DIM_NUM = " << dim_num << "\n"; - exit(1); - } - dim_num_save = dim_num; - /* - ** Set ATMOST = 2^LOG_MAX - 1. - */ - atmost = static_cast<T1>(0); - for (int i = 1; i <= LOG_MAX; i++) - atmost = 2 * atmost + 1; - /* - ** Find the highest 1 bit in ATMOST (should be LOG_MAX). - */ - maxcol = bit_hi1(atmost); - /* - ** Initialize row 1 of V. - */ - for (T1 j = 0; j < maxcol; j++) - { - v[0][j] = static_cast<T1>(1); - } - /* - ** Initialize the remaining rows of V. - */ - for (int i = 1; i < dim_num; i++) - { - /* - ** The bit pattern of the integer POLY(I) gives the form - ** of polynomial I. - ** - ** Find the degree of polynomial I from binary encoding. - */ - T1 j = poly[i]; - T1 m = 0; - while (true) - { - j = j / 2; - if (j <= 0) - break; - - m = m + 1; - } - /* - ** We expand this bit pattern to separate components - ** of the logical array INCLUD. - */ - j = poly[i]; - for (T1 k = m-1; 0 <= k; k--) - { - T1 j2 = j / 2; - includ[k] = (j != (2 * j2)); - j = j2; - } - /* - ** Calculate the remaining elements of row I as explained - ** in Bratley and Fox, section 2. - ** - ** Some tricky indexing here. Did I change it correctly? - */ - for (j = m; j < maxcol; j++) - { - T1 newv = v[i][j-m]; - l = 1; - for (T1 k = 0; k < m; k++) - { - l = 2 * l; - if (includ[k]) - newv = newv ^ (l * v[i][j-k-1]); - } - v[i][j] = newv; - } - } - /* - ** Multiply columns of V by appropriate power of 2. - */ - l = 1; - for (T1 j = maxcol - 2; 0 <= j; j--) - { - l = 2 * l; - for (int i = 0; i < dim_num; i++) - v[i][j] = v[i][j] * l; - } - /* - ** RECIPD is 1/(common denominator of the elements in V). - */ - recipd = 1.0E+00 / static_cast<T2>(2 * l); - } - if (*seed < 0) - *seed = 0; - - if (*seed == 0) - { - l = 1; - for (int i = 0; i < dim_num; i++) - lastq[i] = 0; - } - else if (*seed == seed_save + 1) - l = bit_lo0(*seed); - else if (*seed <= seed_save) - { - seed_save = 0; - l = 1; - for (int i = 0; i < dim_num; i++) - lastq[i] = 0; - for (T1 seed_temp = seed_save; seed_temp <= (*seed)-1; seed_temp++) - { - l = bit_lo0(seed_temp); - for (int i = 0; i < dim_num; i++) - lastq[i] = (lastq[i] ^ v[i][l-1]); - } - l = bit_lo0(*seed); - } - else if (seed_save+1 < *seed) - { - for (T1 seed_temp = seed_save+1; seed_temp <= (*seed)-1; seed_temp++) - { - l = bit_lo0(seed_temp); - for (int i = 0; i < dim_num; i++) - lastq[i] = (lastq[i] ^ v[i][l-1]); - } - l = bit_lo0(*seed); - } - /* - ** Check that the user is not calling too many times! - */ - if (maxcol < l) - { - cout << "\n"; - cout << "NEXT_SOBOL - Fatal error!\n"; - cout << " The value of SEED seems to be too large!\n"; - cout << " SEED = " << *seed << "\n"; - cout << " MAXCOL = " << maxcol << "\n"; - cout << " L = " << l << "\n"; - exit(2); - } - /* - ** Calculate the new components of QUASI. - ** The caret indicates the bitwise exclusive OR. - */ - for (int i = 0; i < dim_num; i++) - { - quasi[i] = static_cast<T2>(lastq[i]) * recipd; - lastq[i] = lastq[i]^v[i][l-1]; - } - seed_save = *seed; - *seed = *seed + 1; - return; + int64_t dim_num2 {dim_num}; + i8_sobol(&dim_num2, seed, quasi); } -template<typename T1, typename T2> -T1 -sobol_block(int dimension, int block_size, T1 seed, T2 *block) +inline int64_t +sobol_block(int dimension, int block_size, int64_t seed, double *block) { for (int iter = 0; iter < block_size; iter++) next_sobol(dimension, &seed, &block[iter*dimension]); diff --git a/preprocessor b/preprocessor index df7144525d47489493590b062ee8cde9b9b5170e..1b0e5581378bc98cf73b090c9a849d0e578a895d 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit df7144525d47489493590b062ee8cde9b9b5170e +Subproject commit 1b0e5581378bc98cf73b090c9a849d0e578a895d diff --git a/tests/.gitignore b/tests/.gitignore index 0394d8974dc8aa60da532d14f9227e9b2c05a3c9..d9005b21ce9d14b6e7fc394d683b906cee44f379 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,5 +1,5 @@ # For checking that no file has been unduly ignored, run: -# $ git ls-files -i --exclude-per-directory=.gitignore +# $ git ls-files -i -c --exclude-per-directory=.gitignore # Any file that is displayed should be removed from the ignore list # (possibly by an exclusion rule beginning with an exclamation mark) @@ -32,20 +32,18 @@ wsOct /partial_information/PItest3aHc0PCLsimModPiYrVarobsCNR_PCL* !/AIM/data_ca1.m -!/AIM/fs2000_b1L1L_AIM_steadystate.m -!/AIM/fs2000_b1L1L_steadystate.m !/AIM/fsdat.m !/analytic_derivatives/fsdat_simul.m !/analytic_derivatives/nBrockMirmanSYM.mat +!/block_bytecode/lola_data.mat !/block_bytecode/run_ls2003.m !/bvar_a_la_sims/bvar_sample.m !/conditional_forecasts/2/fsdat_simul.m +!/cyclereduction.m !/dates/fsdat_simul.m !/decision_rules/example1_results_dyn_432.mat !/decision_rules/third_order/FV_2011_policyfunctions.mat !/decision_rules/third_order/comparison_policy_functions_dynare_mathematica.m -!/deterministic_simulations/lola_data.mat -!/ep/ar_steadystate.m !/ep/exact_solution.m !/ep/mean_preserving_spread.m !/ep/rbcii_steadystate.m @@ -55,35 +53,30 @@ wsOct !/estimation/method_of_moments/RBC/RBC_Andreasen_Data_2.mat !/estimation/method_of_moments/AFVRR/AFVRR_data.mat !/estimation/method_of_moments/AFVRR/AFVRR_steady_helper.m -!estimation/no_init_estimation_check_first_obs/fsdat_mat.m -!estimation/no_init_estimation_check_first_obs/fsdat_mat_XFAIL.m -!estimation/no_init_estimation_check_first_obs/fsdat_simul.m +!/estimation/no_init_estimation_check_first_obs/fsdat_mat.m +!/estimation/no_init_estimation_check_first_obs/fsdat_mat_XFAIL.m +!/estimation/no_init_estimation_check_first_obs/fsdat_simul.m +!/estimation/system_prior_restriction/Gali_2015_PC_slope.m +!/estimation/system_prior_restriction/Gali_2015_prior_restrictions.m !/expectations/expectation_ss_old_steadystate.m +!/external_function/+matlab/+namespace/extFunNoDerivsNamespace.m +!/external_function/+matlab/+namespace/extFunWithFirstAndSecondDerivsNamespace.m !/external_function/extFunDeriv.m !/external_function/extFunNoDerivs.m !/external_function/extFunWithFirstAndSecondDerivs.m -!/utils/fataltest.m !/filter_step_ahead/trend_cycle_decomposition_data.m -!/fs2000/fs2000a_steadystate.m +!/first_order/+matlab/+namespace/y_k.m !/fs2000/fsdat_simul.m !/fs2000/fsdat_simul_dseries.m !/fs2000/fsdat_simul_missing_obs.m -!/fs2000_ssfile_aux.m !/gsa/data_ca1.m !/gsa/data_ca1.mat -!/gsa/ls2003_mean.mat -!/gsa/ls2003_mode.mat -!/gsa/ls2003_results.mat -!/gsa/ls2003scr_mean.mat -!/gsa/ls2003scr_mode.mat -!/gsa/ls2003scr_results.mat !/gsa/morris/nk_est_data.m -!/histval_initval_file/histval_initval_file_unit_tests.m !/histval_initval_file/ramst_initval_file_data.m -!/identification/as2007/as2007_steadystate.m +!/histval_initval_file/my_assert.m +!/histval_initval_file_unit_tests.m !/identification/as2007/G_QT.mat -!/identification/kim/kim2_steadystate.m -!/internals/tests.m +!/initval_file/ramst_initval_file_data.m !/kalman/likelihood/compare_kalman_routines.m !/kalman/likelihood/simul_state_space_model.m !/kalman/likelihood/test1.m @@ -91,6 +84,7 @@ wsOct !/kalman/likelihood/test3.m !/kalman_filter_smoother/compare_results_simulation/fsdat_simul_logged.m !/kalman_filter_smoother/fsdat_simul.m +!/kalman_filter_smoother/SOE_data_file.m !/kalman_filter_smoother/test.mat !/kalman_filter_smoother/testsmoother.m !/kalman_steady_state/test1.m @@ -98,6 +92,7 @@ wsOct !/kronecker/test_kron.m !/load_octave_packages.m !/ls2003/data_ca1.m +!/logarithmicreduction.m !/measurement_errors/data_ca1.m !/measurement_errors/fs2000_corr_me_ml_mcmc/fsdat_simul.m !/missing/simulate_data_with_missing_observations.m @@ -117,32 +112,26 @@ wsOct !/ms-sbvar/archive-files/ftd_upperchol7v.m !/ms-sbvar/archive-files/specification_2v.dat !/ms-sbvar/archive-files/specification_2v2c.dat -!/ms-sbvar/data.m -!/objectives/sgu_ex1.mat +!/ms-sbvar/msdata.m +!/nonlinearsolvers.m !/observation_trends_and_prefiltering/generate_trend_stationary_AR1.m !/occbin/filter/dataobsfile.mat !/occbin/filter/NKM_mh_mode_saved.mat !/optimal_policy/Ramsey/find_c.m -!/optimal_policy/Ramsey/oo_ramsey_policy_initval.mat !/optimizers/optimizer_function_wrapper.m !/parallel/data_ca1.m !/parallel/init.m !/particle/benchmark.m !/particle/data_risky_perturb2.m -!/particle/dsge_base2_steadystate.m +!/particle/dsgebase2data.mat !/particle/extreme.m !/particle/risky.m !/pi2004/idata.m !/pi2004/ych.dat -!/practicing/cagan_data.mat -!/practicing/dataHST.mat -!/practicing/data_consRicardoypg.mat -!/practicing/datasaver.m !/pruning/Andreasen_et_al_2018_Dynare44Pruning_v2.mat !/utils/printMakeCheckMatlabErrMsg.m !/utils/printMakeCheckOctaveErrMsg.m !/prior_posterior_function/posterior_function_demo.m -!/ramst_initval_file_data.m !/recursive/data_ca1.m !/reporting/AnnualTable.m !/reporting/CommResidTablePage.m @@ -150,7 +139,8 @@ wsOct !/reporting/CountryTablePage.m !/reporting/ResidTablePage.m !/reporting/runDynareReport.m -!/run_all_unitary_tests.m +!/riccatiupdate.m +!/run_all_unit_tests.m !/run_block_byte_tests_matlab.m !/run_block_byte_tests_octave.m !/run_kronecker_tests.m @@ -158,14 +148,30 @@ wsOct !/run_o_script.m !/run_reporting_test_matlab.m !/run_reporting_test_octave.m -!/run_test.m !/run_test_matlab.m !/run_test_octave.m -!/run_unitary_tests.m !/shock_decomposition/example1_calib_shock_decomp_data.mat !/shock_decomposition/fsdat_simul.m !/smoother2histval/fsdat_simul.m +!/solver-test-functions/brown.m +!/solver-test-functions/broydenbanded.m +!/solver-test-functions/broydentridiagonal.m +!/solver-test-functions/chebyquad.m +!/solver-test-functions/discreteboundaryvalue.m +!/solver-test-functions/discreteintegralequation.m +!/solver-test-functions/helicalvalley.m +!/solver-test-functions/powell1.m +!/solver-test-functions/powell2.m +!/solver-test-functions/rosenbrock.m +!/solver-test-functions/trigonometric.m +!/solver-test-functions/variablydimensioned.m +!/solver-test-functions/watson.m +!/solver-test-functions/wood.m !/steady_state/walsh1_old_ss_steadystate.m +!/steady_state/fs2000_ssfile_aux.m +!/test_aggregate_routine_1_2.m +!/test_aggregate_routine_1_2_3.m +!/utils/fataltest.m /pac/var-6/example1/model/pac-expectations/* /pac/var-5/example1/model/pac-expectations/* diff --git a/tests/Makefile.am b/tests/Makefile.am index 81619c23851fc83941f9e14db68ff98558cc2dbe..9d3704d09c55465f570b94d0226a1a1e37c84294 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ MODFILES = \ - walsh.mod \ + first_order/walsh.mod \ occbin/model_irrcap_twoconstraints/dynrbc.mod \ occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.mod \ occbin/model_borrcon/borrcon.mod \ @@ -97,29 +97,23 @@ MODFILES = \ gsa/ls2003.mod \ gsa/cod_ML_morris/cod_ML_morris.mod \ gsa/morris/nk_est.mod \ - ramst.mod \ - ramst_a.mod \ - ramst_static_tag.mod \ - ramst_static_tag_block.mod \ - ramst_mshocks.mod \ - ramst_model_edit.mod \ on-the-fly/ex1.mod \ on-the-fly/ex2.mod \ on-the-fly/ex3.mod \ on-the-fly/ex4.mod \ on-the-fly/ex5.mod \ on-the-fly/ex6.mod \ - example1.mod \ - example2.mod \ - example1_use_dll.mod \ - example1_with_tags.mod \ - example1_irf_shocks.mod \ - example1_abs_sign.mod \ - example1_mlv.mod \ - example1long.mod \ - example2long.mod \ - example2long_use_dll.mod \ - t_sgu_ex1.mod \ + equation_tags/example1_with_tags.mod \ + equation_tags/ramst_static_tag.mod \ + equation_tags/ramst_static_tag_block.mod \ + stochastic_simulations/example1.mod \ + stochastic_simulations/example1_irf_shocks.mod \ + stochastic_simulations/example1long.mod \ + stochastic_simulations/example2long.mod \ + stochastic_simulations/example2long_use_dll.mod \ + stochastic_simulations/example2_simul_replic.mod \ + stochastic_simulations/histval_sto.mod \ + stochastic_simulations/histval_predetermined.mod \ macro_processor/test_ifndef.mod \ macro_processor/example1_macro.mod \ irfs/example1_unit_std.mod \ @@ -163,18 +157,13 @@ MODFILES = \ histval_initval_file/ramst_datafile.mod \ histval_initval_file/sim_exo_lead_lag.mod \ histval_initval_file/sim_exo_lead_lag_initvalf.mod \ - ramst_normcdf_and_friends_mfile.mod \ - ramst_normcdf_and_friends_use_dll.mod \ - ramst_normcdf_and_friends_bytecode.mod \ - ramst_vec.mod \ - ramst_mshocks_vec.mod \ - example1_varexo_det.mod \ - predetermined_variables.mod \ - fs2000_ssfile.mod \ - comments.mod \ - histval_sto.mod \ - histval_det.mod \ - histval_predetermined.mod \ + stat_functions/ramst_normcdf_and_friends_mfile.mod \ + stat_functions/ramst_normcdf_and_friends_use_dll.mod \ + stat_functions/ramst_normcdf_and_friends_bytecode.mod \ + stat_functions/example1_abs_sign.mod \ + preprocessor_checks/comments.mod \ + preprocessor_checks/example1_mlv.mod \ + preprocessor_checks/ramst_model_edit.mod \ auxiliary_variables/test1.mod \ expectations/expectation.mod \ expectations/expectation_ss.mod \ @@ -189,6 +178,7 @@ MODFILES = \ steady_state/example1_block_trust_region.mod \ steady_state/Gali_2015_chapter_6_4.mod \ steady_state/ramst_solve_algo_0.mod \ + steady_state/fs2000_ssfile.mod \ steady_state_operator/standard.mod \ steady_state_operator/use_dll.mod \ steady_state_operator/block.mod \ @@ -227,9 +217,9 @@ MODFILES = \ fs2000/fs2000_sd.mod \ fs2000/fs2000_dseries_a.mod \ fs2000/fs2000_dseries_b.mod \ - homotopy/homotopy1_test.mod \ - homotopy/homotopy2_test.mod \ - homotopy/homotopy3_test.mod \ + steady_state/homotopy/homotopy1_test.mod \ + steady_state/homotopy/homotopy2_test.mod \ + steady_state/homotopy/homotopy3_test.mod \ bvar_a_la_sims/bvar_standalone.mod \ bvar_a_la_sims/bvar_and_dsge.mod \ AIM/fs2000x10L9_L.mod \ @@ -256,7 +246,6 @@ MODFILES = \ external_function/no_deriv_given.mod \ external_function/no_deriv_given_dll.mod \ external_function/extfun_in_mlv.mod \ - seeds.mod \ minimal_state_space_system/as2007_minimal.mod \ minimal_state_space_system/sw_minimal.mod \ identification/kim/kim2.mod \ @@ -274,12 +263,7 @@ MODFILES = \ identification/correlated_errors/fs2000_corr.mod \ identification/forward_looking/forward_looking_empty_ghx.mod \ identification/forward_looking/forward_looking_varobs_x.mod \ - simul/example1.mod \ - simul/Solow_no_varexo.mod \ - simul/simul_ZLB_purely_forward.mod \ - simul/simul_ZLB_purely_forward_no_solution.mod \ - simul/Irreversible_investment.mod \ - simul/linear_state_space_arma.mod \ + model_diagnostics/example2_block_model_diag.mod \ perfect_foresight/initval_endval_blocks/initval_endval_test.mod \ perfect_foresight/initval_endval_blocks/histval_initval_test.mod \ conditional_forecasts/1/fs2000_cal.mod \ @@ -361,9 +345,22 @@ MODFILES = \ ep/rbc_bytecode.mod \ ep/rbcii_MCP.mod \ stochastic_simulations/example1_noprint.mod \ + stochastic_simulations/example_seeds.mod \ stochastic-backward-models/solow_cd.mod \ stochastic-backward-models/solow_ces.mod \ stochastic-backward-models/solow_cd_with_steadystate.mod \ + deterministic_simulations/ramst.mod \ + deterministic_simulations/ramst_a.mod \ + deterministic_simulations/ramst_mshocks.mod \ + deterministic_simulations/ramst_mshocks_vec.mod \ + deterministic_simulations/predetermined_variables.mod \ + deterministic_simulations/histval_det.mod \ + deterministic_simulations/ramst_vec.mod \ + deterministic_simulations/Solow_no_varexo.mod \ + deterministic_simulations/simul_ZLB_purely_forward.mod \ + deterministic_simulations/simul_ZLB_purely_forward_no_solution.mod \ + deterministic_simulations/Irreversible_investment.mod \ + deterministic_simulations/linear_state_space_arma.mod \ deterministic_simulations/purely_forward/ar1.mod \ deterministic_simulations/purely_forward/nk.mod \ deterministic_simulations/purely_backward/ar1.mod \ @@ -375,8 +372,9 @@ MODFILES = \ deterministic_simulations/rbc_det5.mod \ deterministic_simulations/rbc_det6.mod \ deterministic_simulations/homotopy.mod \ - deterministic_simulations/homotopy_alt_starting_point.mod \ deterministic_simulations/homotopy_histval.mod \ + deterministic_simulations/homotopy_endval_steady_linearization.mod \ + deterministic_simulations/homotopy_marginal_linearization.mod \ deterministic_simulations/rbc_det_exo_lag_2a.mod \ deterministic_simulations/rbc_det_exo_lag_2b.mod \ deterministic_simulations/rbc_det_exo_lag_2c.mod \ @@ -400,6 +398,7 @@ MODFILES = \ deterministic_simulations/pfwee_constant_sim_length.mod \ deterministic_simulations/pfwee_learnt_in.mod \ deterministic_simulations/pfwee_multiple_shocks.mod \ + deterministic_simulations/pfwee_homotopy.mod \ lmmcp/rbc.mod \ lmmcp/sw_lmmcp.mod \ lmmcp/sw_newton.mod \ @@ -407,6 +406,7 @@ MODFILES = \ trend_var/fs2000_log_nonstationary.mod \ decision_rules/third_order/FV2011.mod \ decision_rules/example1.mod \ + decision_rules/example1_use_dll.mod \ decision_rules/ar_qz_test.mod \ shock_decomposition/example1_calib_shock_decomp.mod \ shock_decomposition/fs2000_est.mod \ @@ -416,6 +416,7 @@ MODFILES = \ shock_decomposition/shock_decomp_backward.mod \ stochastic_purely_forward/stochastic_purely_forward.mod \ stochastic_purely_forward/stochastic_purely_forward_with_static.mod \ + forecast/example1_varexo_det.mod \ forecast/Hansen_exo_det_forecast.mod \ forecast/linear_exo_det_forecast.mod \ forecast/ls2003_rolling_window_forecast.mod \ @@ -513,7 +514,9 @@ MODFILES = \ solve_algo_12_14/purely_static_14.mod \ solve_algo_12_14/purely_forward_reference.mod \ solve_algo_12_14/purely_forward_12.mod \ - solve_algo_12_14/purely_forward_14.mod + solve_algo_12_14/purely_forward_14.mod \ + deprecated/ramsey_ex.mod \ + deprecated/ramst.mod ECB_MODFILES = \ var-expectations/1/example1.mod \ @@ -675,8 +678,9 @@ PARTICLEFILES = \ particle/local_state_space_iteration_3_test.mod -XFAIL_MODFILES = ramst_xfail.mod \ - estim_param_in_shock_value_xfail.mod \ +XFAIL_MODFILES = preprocessor_checks/ramst_all_values_required_xfail.mod \ + preprocessor_checks/example1_undeclared_vars_xfail.mod \ + estimation/estim_param_in_shock_value_xfail.mod \ optimal_policy/Ramsey/ramsey_ex_wrong_ss_file_xfail.mod \ estimation/fs2000_mixed_ML_xfail.mod \ estimation/fs2000_stochastic_singularity_xfail.mod \ @@ -690,7 +694,7 @@ XFAIL_MODFILES = ramst_xfail.mod \ particle/first_spec_xfail_0.mod \ particle/first_spec_xfail_1.mod \ kalman_initial_state/fs2000_kalman_initial_xfail.mod \ - example1_extra_exo_xfail.mod \ + preprocessor_checks/example1_extra_exo_xfail.mod \ estimation/tune_mh_jscale/fs2000_1_xfail.mod \ estimation/tune_mh_jscale/fs2000_2_xfail.mod \ estimation/no_init_estimation_check_first_obs/fs2000_init_check_XFAIL.mod \ @@ -717,14 +721,14 @@ occbin/model_irrcap_twoconstraints/dynrbc_0_std_shocks.o.trs: occbin/model_irrca occbin/model_borrcon/borrcon_0_std_shocks.m.trs: occbin/model_borrcon/borrcon.m.trs occbin/model_borrcon/borrcon_0_std_shocks.o.trs: occbin/model_borrcon/borrcon.o.trs -example1_use_dll.m.trs: example1.m.trs -example1_use_dll.o.trs: example1.o.trs +decision_rules/example1_use_dll.m.trs: decision_rules/example1.m.trs +decision_rules/example1_use_dll.o.trs: decision_rules/example1.o.trs -example2long_use_dll.m.trs: example1long.m.trs -example2long_use_dll.o.trs: example1long.o.trs +stochastic_simulations/example2long_use_dll.m.trs: stochastic_simulations/example1long.m.trs +stochastic_simulations/example2long_use_dll.o.trs: stochastic_simulations/example1long.o.trs -example2long.m.trs: example1long.m.trs -example2long.o.trs: example1long.o.trs +stochastic_simulations/example2long.m.trs: stochastic_simulations/example1long.m.trs +stochastic_simulations/example2long.o.trs: stochastic_simulations/example1long.o.trs estimation/MH_recover/fs2000_recover_tarb.m.trs: estimation/MH_recover/fs2000_recover.m.trs estimation/MH_recover/fs2000_recover_tarb.o.trs: estimation/MH_recover/fs2000_recover.o.trs @@ -758,6 +762,9 @@ optimal_policy/Ramsey/ramsey_ex.o.trs: optimal_policy/Ramsey/ramsey_ex_initval.o optimal_policy/nk_ramsey_expectation_a.m.trs: optimal_policy/nk_ramsey_expectation.m.trs optimal_policy/nk_ramsey_expectation_a.o.trs: optimal_policy/nk_ramsey_expectation.o.trs +deprecated/ramsey_ex.m.trs: optimal_policy/Ramsey/ramsey_ex_initval.m.trs +deprecated/ramsey_ex.o.trs: optimal_policy/Ramsey/ramsey_ex_initval.o.trs + second_order/ds2.m.trs: second_order/ds1.m.trs second_order/ds2.o.trs: second_order/ds1.o.trs @@ -869,8 +876,8 @@ deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs: determ deterministic_simulations/multiple_lead_lags/sim_lead_lag.m.trs: deterministic_simulations/multiple_lead_lags/sim_base.m.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.m.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag.o.trs: deterministic_simulations/multiple_lead_lags/sim_base.o.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs -deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: ramst.m.trs -deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.o.trs: ramst.o.trs +deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: deterministic_simulations/ramst.m.trs +deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.o.trs: deterministic_simulations/ramst.o.trs loglinear/example4_loglinear.m.trs: loglinear/example4_exp.m.trs loglinear/example4_loglinear.o.trs: loglinear/example4_exp.o.trs @@ -984,11 +991,11 @@ particle/local_it_k_test_parallel.o.trs: particle/first_spec.o.trs pruning/AS_pruned_state_space_red_shock.m.trs: pruning/AnSchorfheide_pruned_state_space.m.trs pruning/AS_pruned_state_space_red_shock.o.trs: pruning/AnSchorfheide_pruned_state_space.o.trs -ramst_model_edit.m.trs: ramst.m.trs -ramst_model_edit.o.trs: ramst.o.trs +preprocessor_checks/ramst_model_edit.m.trs: deterministic_simulations/ramst.m.trs +preprocessor_checks/ramst_model_edit.o.trs: deterministic_simulations/ramst.o.trs -log_transform/ramst.m.trs: ramst.m.trs -log_transform/ramst.o.trs: ramst.o.trs +log_transform/ramst.m.trs: deterministic_simulations/ramst.m.trs +log_transform/ramst.o.trs: deterministic_simulations/ramst.o.trs model-inversion/nk-1/invert.m.trs: model-inversion/nk-1/simulate.m.trs model-inversion/nk-1/invert.o.trs: model-inversion/nk-1/simulate.o.trs @@ -1025,6 +1032,10 @@ solve_algo_12_14/purely_forward_14.o.trs: solve_algo_12_14/purely_forward_refere estimation/conditional-likelihood/1/fs2000_estimation_conditional.m.trs: estimation/conditional-likelihood/1/fs2000_estimation_exact.m.trs estimation/conditional-likelihood/1/fs2000_estimation_conditional.o.trs: estimation/conditional-likelihood/1/fs2000_estimation_exact.o.trs +deprecated/ramst.m.trs: deterministic_simulations/ramst.m.trs +deprecated/ramst.o.trs: deterministic_simulations/ramst.o.trs + + observation_trends_and_prefiltering/MCMC: m/observation_trends_and_prefiltering/MCMC o/observation_trends_and_prefiltering/MCMC m/observation_trends_and_prefiltering/MCMC: $(patsubst %.mod, %.m.trs, $(filter observation_trends_and_prefiltering/MCMC/%.mod, $(MODFILES))) o/observation_trends_and_prefiltering/MCMC: $(patsubst %.mod, %.o.trs, $(filter observation_trends_and_prefiltering/MCMC/%.mod, $(MODFILES))) @@ -1049,10 +1060,6 @@ arima: m/arima o/arima m/arima: $(patsubst %.mod, %.m.trs, $(filter arima/%.mod, $(MODFILES))) o/arima: $(patsubst %.mod, %.o.trs, $(filter arima/%.mod, $(MODFILES))) -homotopy: m/homotopy o/homotopy -m/homotopy: $(patsubst %.mod, %.m.trs, $(filter homotopy/%.mod, $(MODFILES))) -o/homotopy: $(patsubst %.mod, %.o.trs, $(filter homotopy/%.mod, $(MODFILES))) - expectations: m/expectations o/expectations m/expectations: $(patsubst %.mod, %.m.trs, $(filter expectations/%.mod, $(MODFILES))) o/expectations: $(patsubst %.mod, %.o.trs, $(filter expectations/%.mod, $(MODFILES))) @@ -1121,10 +1128,6 @@ deterministic_simulations: m/deterministic_simulations o/deterministic_simulatio m/deterministic_simulations: $(patsubst %.mod, %.m.trs, $(filter deterministic_simulations/%.mod, $(MODFILES))) o/deterministic_simulations: $(patsubst %.mod, %.o.trs, $(filter deterministic_simulations/%.mod, $(MODFILES))) -simul: m/simul o/simul -m/simul: $(patsubst %.mod, %.m.trs, $(filter simul/%.mod, $(MODFILES))) -o/simul: $(patsubst %.mod, %.o.trs, $(filter simul/%.mod, $(MODFILES))) - ep: m/ep o/ep m/ep: $(patsubst %.mod, %.m.trs, $(filter ep/%.mod, $(MODFILES))) o/ep: $(patsubst %.mod, %.o.trs, $(filter ep/%.mod, $(MODFILES))) @@ -1305,7 +1308,7 @@ EXTRA_DIST = \ run_reporting_test_matlab.m \ run_reporting_test_octave.m \ run_all_unit_tests.m \ - +matlab/+namespace/y_k.m \ + first_order/+matlab/+namespace/y_k.m \ reporting/AnnualTable.m \ reporting/CommResidTablePage.m \ reporting/CountryGraphPage.m \ @@ -1316,9 +1319,9 @@ EXTRA_DIST = \ reporting/dc_a.csv \ reporting/dc_q.csv \ reporting/runDynareReport.m \ - homotopy/common.mod \ + steady_state/homotopy/common.mod \ block_bytecode/ls2003.mod \ - fs2000_ssfile_aux.m \ + steady_state/fs2000_ssfile_aux.m \ utils/printMakeCheckMatlabErrMsg.m \ utils/printMakeCheckOctaveErrMsg.m \ utils/fataltest.m \ @@ -1352,7 +1355,6 @@ EXTRA_DIST = \ measurement_errors/data_ca1.m \ measurement_errors/fs2000_corr_me_ml_mcmc/fsdat_simul.m \ missing/simulate_data_with_missing_observations.m \ - objectives/sgu_ex1.mat \ conditional_forecasts/2/fsdat_simul.m \ ms-sbvar/msdata.m \ ms-sbvar/archive-files/ftd_2s_caseall_upperchol3v.m \ @@ -1483,7 +1485,7 @@ EXTRA_DIST = \ solver-test-functions/variablydimensioned.m \ solver-test-functions/watson.m \ solver-test-functions/wood.m \ - ramst_normcdf_and_friends.inc \ + stat_functions/ramst_normcdf_and_friends.inc \ solve_algo_12_14/backward_model.inc \ solve_algo_12_14/simul_backward_common.inc \ solve_algo_12_14/purely_backward_common.inc \ @@ -1611,7 +1613,6 @@ clean-local: rm -f $(shell find -name H.dat) rm -f arima/data1.m arima/data2.m \ - k_order_perturbation/*.jnl \ k_order_perturbation/*.mat \ kalman_filter_smoother/data_algo.mat \ kalman_filter_smoother/data_Pinf_Pstar.mat @@ -1652,7 +1653,7 @@ clean-local: rm -f estimation/test_matrix.mat - rm -f histval_initval_file/ramst_initval_file_data_col_vec_mat.mat histval_initval_file/ramst_initval_file_data_row_vec_mat.mat histval_initval_file/ramst_initval_file_excel.xls + rm -f histval_initval_file/ramst_initval_file_data_col_vec_mat.mat histval_initval_file/ramst_initval_file_data_row_vec_mat.mat histval_initval_file/ramst_initval_file_excel.xls histval_initval_file/ramst_data.csv rm -f loglinear/results_exp_histval.mat loglinear/results_exp.mat @@ -1671,8 +1672,6 @@ clean-local: rm -f occbin/filter/dataobsfile2.mat - rm -f optimal_policy/Ramsey/oo_ramsey_policy_initval.mat - rm -rf tests/pac/var-12/toto rm -f solve_algo_12_14/simul_backward_ref.mat diff --git a/tests/example1_use_dll.mod b/tests/decision_rules/example1_use_dll.mod similarity index 100% rename from tests/example1_use_dll.mod rename to tests/decision_rules/example1_use_dll.mod diff --git a/tests/deprecated/ramsey_ex.mod b/tests/deprecated/ramsey_ex.mod new file mode 100644 index 0000000000000000000000000000000000000000..9c61deacfd7b20e256a61c4474e4d96a1a50cac0 --- /dev/null +++ b/tests/deprecated/ramsey_ex.mod @@ -0,0 +1,54 @@ +/* Tests the deprecated ramsey_policy command. + * + * The example is taken from Juillard, Michel (2011): User manual for optimal policy package, + * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2 +*/ + +var pai, c, n, r, a; +varexo u; +parameters beta, rho, epsilon, omega, phi, gamma; + +beta=0.99; +gamma=3; +omega=17; +epsilon=8; +phi=1; +rho=0.95; + +model; +a = rho*a(-1)+u; +1/c = beta*r/(c(+1)*pai(+1)); +pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -exp(a)*n*(epsilon-1)/(omega*c); +exp(a)*n = c+(omega/2)*(pai-1)^2; +end; + +initval; +r=1; +end; + +initval; +a = 0; +pai = beta; +c = 0.9665; +n = 0.9673; +end; + +shocks; +var u; stderr 0.008; +end; + +planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma))); +ramsey_policy(planner_discount=0.99,instruments=(r),order=1,nograph); + +benchmark = load('../optimal_policy/Ramsey/ramsey_ex_initval/Output/ramsey_ex_initval_results.mat'); + +if any( [ max(abs(benchmark.oo_.steady_state-oo_.steady_state))>1e-5, ... + max(abs(benchmark.oo_.dr.ys-oo_.dr.ys))>1e-5, ... + max(max(abs(benchmark.oo_.dr.ghx-oo_.dr.ghx)))>1e-5, ... + max(max(abs(benchmark.oo_.dr.ghu-oo_.dr.ghu)))>1e-5, ... + max(max(abs(benchmark.oo_.dr.Gy-oo_.dr.Gy)))>1e-5, ... + abs(benchmark.oo_.planner_objective_value.unconditional-oo_.planner_objective_value.unconditional)>1e-5, ... + abs(benchmark.oo_.planner_objective_value.conditional.zero_initial_multiplier-oo_.planner_objective_value.conditional.zero_initial_multiplier)>1e-5, ... + abs(benchmark.oo_.planner_objective_value.conditional.steady_initial_multiplier-oo_.planner_objective_value.conditional.steady_initial_multiplier)>1e-5] ) + error('ramsey_policy gives results inconsistent with ramsey_model+stoch_simul+evaluate_planner_objective') +end diff --git a/tests/t_periods_a.mod b/tests/deprecated/ramst.mod similarity index 52% rename from tests/t_periods_a.mod rename to tests/deprecated/ramst.mod index 26a064d9ef24580607a624d89d29b4a068fbe07b..cd1d4b404817a7b67136f78c152df3c8ae414f15 100644 --- a/tests/t_periods_a.mod +++ b/tests/deprecated/ramst.mod @@ -1,3 +1,5 @@ +// Tests the deprecated simul command + var c k; varexo x; @@ -17,7 +19,7 @@ end; initval; x = 1; k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1)); -c = aa*k^alph-delt*k +1 ; +c = aa*k^alph-delt*k; end; steady; @@ -30,8 +32,10 @@ periods 1; values 1.2; end; -perfect_foresight_setup(periods=200); -perfect_foresight_solver; +simul(periods=200); + +benchmark = load('../deterministic_simulations/ramst/Output/ramst_results.mat'); -rplot c; -rplot k; +if max(abs(benchmark.oo_.endo_simul-oo_.endo_simul)) > 1e5 + error('The results of simul are inconsistent with perfect_foresight_setup+perfect_foresight_solver'); +end diff --git a/tests/simul/Irreversible_investment.mod b/tests/deterministic_simulations/Irreversible_investment.mod similarity index 100% rename from tests/simul/Irreversible_investment.mod rename to tests/deterministic_simulations/Irreversible_investment.mod diff --git a/tests/simul/Solow_no_varexo.mod b/tests/deterministic_simulations/Solow_no_varexo.mod similarity index 100% rename from tests/simul/Solow_no_varexo.mod rename to tests/deterministic_simulations/Solow_no_varexo.mod diff --git a/tests/histval_det.mod b/tests/deterministic_simulations/histval_det.mod similarity index 100% rename from tests/histval_det.mod rename to tests/deterministic_simulations/histval_det.mod diff --git a/tests/deterministic_simulations/homotopy.mod b/tests/deterministic_simulations/homotopy.mod index 64ccde0d8480a8bb9f5bca6d6c261588bcdd8981..a1043102e83e815452538496cf165af529771fe4 100644 --- a/tests/deterministic_simulations/homotopy.mod +++ b/tests/deterministic_simulations/homotopy.mod @@ -1,4 +1,5 @@ // Example that triggers homotopy in perfect foresight simulation. +// Simulation with a permanent shock. var Consumption, Capital, LoggedProductivity; @@ -34,12 +35,12 @@ set_time(1Q1); initval; LoggedProductivityInnovation = 0; - LoggedProductivity = 10; - Capital = 1; end; +steady; + endval; - LoggedProductivityInnovation = 0; + LoggedProductivityInnovation = 1; end; steady; diff --git a/tests/deterministic_simulations/homotopy_alt_starting_point.mod b/tests/deterministic_simulations/homotopy_alt_starting_point.mod deleted file mode 100644 index 81af0a728d0e979237e70a80b60caa8dd4b71139..0000000000000000000000000000000000000000 --- a/tests/deterministic_simulations/homotopy_alt_starting_point.mod +++ /dev/null @@ -1,50 +0,0 @@ -// Test for the homotopy_alt_starting_point option of perfect_foresight_solver - -var Consumption, Capital, LoggedProductivity; - -varexo LoggedProductivityInnovation; - -parameters beta, alpha, delta, rho; - -beta = .985; -alpha = 1/3; -delta = alpha/10; -rho = .9; - -model; - -[name='Euler equation'] -1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta); - -[name='Physical capital stock law of motion'] -Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption; - -[name='Logged productivity law of motion'] -LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation; - -end; - -steady_state_model; - LoggedProductivity = LoggedProductivityInnovation/(1-rho); - Capital = (exp(LoggedProductivity)*alpha/(1/beta-1+delta))^(1/(1-alpha)); - Consumption = exp(LoggedProductivity)*Capital^alpha-delta*Capital; -end; - -initval; - LoggedProductivityInnovation = 0; -end; - -steady; - -endval; - LoggedProductivityInnovation = 0.4; -end; - -steady; - -perfect_foresight_setup(periods=200); -perfect_foresight_solver(homotopy_alt_starting_point); - -if ~oo_.deterministic_simulation.status - error('Perfect foresight simulation failed') -end diff --git a/tests/deterministic_simulations/homotopy_endval_steady_linearization.mod b/tests/deterministic_simulations/homotopy_endval_steady_linearization.mod new file mode 100644 index 0000000000000000000000000000000000000000..97b8fbae011c6baa30a41663c12c2c8e0383287c --- /dev/null +++ b/tests/deterministic_simulations/homotopy_endval_steady_linearization.mod @@ -0,0 +1,43 @@ +// Example that triggers homotopy in perfect foresight simulation. +// Tests the endval_steady, homotopy_linearization_fallback options, and a few more. + +var Consumption, Capital, LoggedProductivity; + +varexo LoggedProductivityInnovation; + +parameters beta, alpha, delta, rho; + +beta = .985; +alpha = 1/3; +delta = alpha/10; +rho = .9; + +model; + 1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta); + Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption; + LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation; +end; + +initval; + LoggedProductivityInnovation = 0; +end; + +steady; + +endval; + LoggedProductivityInnovation = 1; + Consumption = 0.1; + Capital = 1; +end; + +perfect_foresight_setup(periods=200, endval_steady); + +perfect_foresight_solver(homotopy_initial_step_size = 0.5, + homotopy_max_completion_share = 0.6, + homotopy_min_step_size = 0.0001, + homotopy_linearization_fallback, + steady_solve_algo = 13, steady_tolf=1e-7); + +if ~oo_.deterministic_simulation.status + error('Perfect foresight simulation failed') +end diff --git a/tests/deterministic_simulations/homotopy_histval.mod b/tests/deterministic_simulations/homotopy_histval.mod index 8a1bba3013930b3f9d2ad88c040f37f1f74226d7..551bab78ffa04d70214cea615317a2b50bf5b5a1 100644 --- a/tests/deterministic_simulations/homotopy_histval.mod +++ b/tests/deterministic_simulations/homotopy_histval.mod @@ -1,4 +1,5 @@ // Example that triggers homotopy in perfect foresight simulation. +// Simulation starts out of steady state and returns to it. var Consumption, Capital, LoggedProductivity; @@ -24,11 +25,11 @@ LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation; end; -% steady_state_model; -% LoggedProductivity = LoggedProductivityInnovation/(1-rho); -% Capital = (exp(LoggedProductivity)*alpha/(1/beta-1+delta))^(1/(1-alpha)); -% Consumption = exp(LoggedProductivity)*Capital^alpha-delta*Capital; -% end; +steady_state_model; + LoggedProductivity = LoggedProductivityInnovation/(1-rho); + Capital = (exp(LoggedProductivity)*alpha/(1/beta-1+delta))^(1/(1-alpha)); + Consumption = exp(LoggedProductivity)*Capital^alpha-delta*Capital; +end; set_time(1Q1); @@ -45,12 +46,6 @@ histval; LoggedProductivity(0)=10; end; -// endval; -// LoggedProductivityInnovation = 0; -// end; - -// steady; - perfect_foresight_setup(periods=200); perfect_foresight_solver; diff --git a/tests/deterministic_simulations/homotopy_marginal_linearization.mod b/tests/deterministic_simulations/homotopy_marginal_linearization.mod new file mode 100644 index 0000000000000000000000000000000000000000..080e11b67ceb7da602cff95c1df6ca5036c05a2f --- /dev/null +++ b/tests/deterministic_simulations/homotopy_marginal_linearization.mod @@ -0,0 +1,42 @@ +// Example that triggers homotopy in perfect foresight simulation. +// Tests the homotopy_marginal_linearization_fallback and homotopy_step_size_increase_success_count options + +var Consumption, Capital, LoggedProductivity; + +varexo LoggedProductivityInnovation; + +parameters beta, alpha, delta, rho; + +beta = .985; +alpha = 1/3; +delta = alpha/10; +rho = .9; + +model; + 1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta); + Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption; + LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation; +end; + +initval; + LoggedProductivityInnovation = 0; +end; + +steady; + +endval; + LoggedProductivityInnovation = 1; + Consumption = 0.1; + Capital = 1; +end; + +perfect_foresight_setup(periods=200, endval_steady); + +perfect_foresight_solver(homotopy_max_completion_share = 0.7, + homotopy_step_size_increase_success_count = 3, + homotopy_marginal_linearization_fallback, + steady_solve_algo = 13); + +if ~oo_.deterministic_simulation.status + error('Perfect foresight simulation failed') +end diff --git a/tests/simul/linear_state_space_arma.mod b/tests/deterministic_simulations/linear_state_space_arma.mod similarity index 100% rename from tests/simul/linear_state_space_arma.mod rename to tests/deterministic_simulations/linear_state_space_arma.mod diff --git a/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod b/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod index fe6e9ae2d4fcadb1be1301ed252301963dfed6c3..61f92c4f5d5f8d2fb49f25a9f28f0e2b05093ed6 100644 --- a/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod +++ b/tests/deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.mod @@ -71,7 +71,7 @@ if max(abs(junk(M_.maximum_lag+1:end)-oo_.endo_simul(strmatch('y_backward',M_.en error('Solution of purely backwards model not correct') end -ramst_results=load('../../ramst/Output/ramst_results.mat'); +ramst_results=load('../../deterministic_simulations/ramst/Output/ramst_results.mat'); if max(abs(ramst_results.oo_.endo_simul(strmatch('k',ramst_results.M_.endo_names,'exact'),1:end-M_.maximum_lead)-oo_.endo_simul(strmatch('k',M_.endo_names,'exact'),1:end-M_.maximum_lead)))>1e-10 error('Solution of forward part of the model not correct') end diff --git a/tests/deterministic_simulations/pfwee.mod b/tests/deterministic_simulations/pfwee.mod index 9184101968d893f4b6c12696fc42c196f2a80f58..fb7f4cf0151b444b95a544d4302767ebfc38fa27 100644 --- a/tests/deterministic_simulations/pfwee.mod +++ b/tests/deterministic_simulations/pfwee.mod @@ -27,17 +27,18 @@ steady; check; +// Save initial steady state (it will be modified by pfwee) +orig_steady_state = oo_.steady_state; +orig_exo_steady_state = oo_.exo_steady_state; + perfect_foresight_with_expectation_errors_setup(periods = 7, datafile = 'pfwee.csv'); -// First simulation with default options perfect_foresight_with_expectation_errors_solver; -pfwee1 = oo_.endo_simul; - -// Second simulation with alternative guess values -perfect_foresight_with_expectation_errors_solver(terminal_steady_state_as_guess_value); -pfwee2 = oo_.endo_simul; +pfwee_simul = oo_.endo_simul; // Now compute the solution by hand to verify the results +oo_.steady_state = orig_steady_state; +oo_.exo_steady_state = orig_exo_steady_state; perfect_foresight_setup; @@ -49,7 +50,7 @@ perfect_foresight_solver; oo_.exo_simul(3,1) = 1.3; oo_.exo_steady_state = 1.1; oo_.exo_simul(end, 1) = oo_.exo_steady_state; -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, end) = oo_.steady_state; options_.periods = 6; saved_endo = oo_.endo_simul(:, 1); @@ -64,7 +65,7 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; oo_.exo_simul(4,1) = 1.4; oo_.exo_steady_state = 1.2; oo_.exo_simul(end, 1) = oo_.exo_steady_state; -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, end) = oo_.steady_state; options_.periods = 5; saved_endo = oo_.endo_simul(:, 1:2); @@ -80,7 +81,7 @@ oo_.exo_simul(7,1) = 1.1; oo_.exo_simul(8,1) = 1.1; oo_.exo_steady_state = 1.1; oo_.exo_simul(end, 1) = oo_.exo_steady_state; -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, end) = oo_.steady_state; options_.periods = 2; saved_endo = oo_.endo_simul(:, 1:5); @@ -93,12 +94,6 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; % We should have strict equality with first pfwee simulation, because algorithm % and guess values are exactly the same. -if any(any(pfwee1-oo_.endo_simul ~= 0)) +if any(any(pfwee_simul-oo_.endo_simul ~= 0)) error('Error in perfect_foresight_with_expectation_errors') end - -% For the 2nd simulation, since the guess values are different, there are some -% numerical differences -if max(max(abs(pfwee2-oo_.endo_simul))) > 10*options_.dynatol.f - error('Error in perfect_foresight_with_expectation_errors + terminal_steady_state_as_guess_value') -end diff --git a/tests/deterministic_simulations/pfwee_constant_sim_length.mod b/tests/deterministic_simulations/pfwee_constant_sim_length.mod index 250b4e6733f7f86803f4762635f7b8aef9524605..efe0d2efa2d217ffcba5b94c1da99b708992fc8e 100644 --- a/tests/deterministic_simulations/pfwee_constant_sim_length.mod +++ b/tests/deterministic_simulations/pfwee_constant_sim_length.mod @@ -26,22 +26,21 @@ steady; check; -// First simulation with default options -perfect_foresight_with_expectation_errors_setup(periods = 7, datafile = 'pfwee.csv'); -perfect_foresight_with_expectation_errors_solver(constant_simulation_length); -pfwee1 = oo_.endo_simul; +// Save initial steady state (it will be modified by pfwee) +orig_steady_state = oo_.steady_state; +orig_exo_steady_state = oo_.exo_steady_state; -// Second simulation with alternative guess values perfect_foresight_with_expectation_errors_setup(periods = 7, datafile = 'pfwee.csv'); -perfect_foresight_with_expectation_errors_solver(terminal_steady_state_as_guess_value, constant_simulation_length); -pfwee2 = oo_.endo_simul; + +perfect_foresight_with_expectation_errors_solver(constant_simulation_length); +pfwee_simul = oo_.endo_simul; // Now compute the solution by hand to verify the results +oo_.steady_state = orig_steady_state; +oo_.exo_steady_state = orig_exo_steady_state; perfect_foresight_setup; -initial_steady_state = oo_.steady_state; - // Information arriving in period 1 (temp shock now) oo_.exo_simul(2,1) = 1.2; perfect_foresight_solver; @@ -50,7 +49,7 @@ perfect_foresight_solver; oo_.exo_simul(3,1) = 1.3; oo_.exo_steady_state = 1.1; oo_.exo_simul(9:10, 1) = repmat(oo_.exo_steady_state', 2, 1); -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, 10) = oo_.steady_state; saved_endo = oo_.endo_simul(:, 1); saved_exo = oo_.exo_simul(1, :); @@ -64,7 +63,7 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; oo_.exo_simul(4,1) = 1.4; oo_.exo_steady_state = 1.2; oo_.exo_simul(9:11, 1) = repmat(oo_.exo_steady_state', 3, 1); -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, 11) = oo_.steady_state; saved_endo = oo_.endo_simul(:, 1:2); saved_exo = oo_.exo_simul(1:2, :); @@ -79,8 +78,8 @@ oo_.exo_simul(7,1) = 1.1; oo_.exo_simul(8,1) = 1.1; oo_.exo_steady_state = 1.1; oo_.exo_simul(9:14, 1) = repmat(oo_.exo_steady_state', 6, 1); -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); -oo_.endo_simul(:, 12:13) = repmat(initial_steady_state, 1, 2); +oo_.endo_simul(:, 12:13) = repmat(oo_.steady_state, 1, 2); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, 14) = oo_.steady_state; saved_endo = oo_.endo_simul(:, 1:5); saved_exo = oo_.exo_simul(1:5, :); @@ -92,12 +91,6 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; % We should have strict equality with first pfwee simulation, because algorithm % and guess values are exactly the same. -if any(any(pfwee1-oo_.endo_simul ~= 0)) +if any(any(pfwee_simul-oo_.endo_simul ~= 0)) error('Error in perfect_foresight_with_expectation_errors') end - -% For the 2nd simulation, since the guess values are different, there are some -% numerical differences -if max(max(abs(pfwee2-oo_.endo_simul))) > 40*options_.dynatol.f - error('Error in perfect_foresight_with_expectation_errors + terminal_steady_state_as_guess_value') -end diff --git a/tests/deterministic_simulations/pfwee_homotopy.mod b/tests/deterministic_simulations/pfwee_homotopy.mod new file mode 100644 index 0000000000000000000000000000000000000000..c4175c0906284d1c91ba0966b08ee1d234919527 --- /dev/null +++ b/tests/deterministic_simulations/pfwee_homotopy.mod @@ -0,0 +1,40 @@ +/* Example that triggers homotopy in perfect foresight simulation with + expectation errors. */ + +var Consumption, Capital, LoggedProductivity; + +varexo LoggedProductivityInnovation; + +parameters beta, alpha, delta, rho; + +beta = .985; +alpha = 1/3; +delta = alpha/10; +rho = .9; + +model; + 1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta); + Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption; + LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation; +end; + +initval; + LoggedProductivityInnovation = 0; +end; + +steady; + +endval; + LoggedProductivityInnovation = 0.6; +end; + +endval(learnt_in = 5); + LoggedProductivityInnovation = 1; +end; + +perfect_foresight_with_expectation_errors_setup(periods=200); +perfect_foresight_with_expectation_errors_solver(homotopy_max_completion_share = 0.8, homotopy_linearization_fallback, steady_solve_algo = 13); + +if ~oo_.deterministic_simulation.status + error('Perfect foresight simulation failed') +end diff --git a/tests/deterministic_simulations/pfwee_learnt_in.mod b/tests/deterministic_simulations/pfwee_learnt_in.mod index f12cd13ed779b6325e4679967b09493e1c2f1cab..bef2a04674b3ca8acb1b082614d63f48fd162e60 100644 --- a/tests/deterministic_simulations/pfwee_learnt_in.mod +++ b/tests/deterministic_simulations/pfwee_learnt_in.mod @@ -70,17 +70,18 @@ endval(learnt_in = 6); x *= 0.75; end; +// Save initial steady state (it will be modified by pfwee) +orig_steady_state = oo_.steady_state; +orig_exo_steady_state = oo_.exo_steady_state; + perfect_foresight_with_expectation_errors_setup(periods = 7); -// First simulation with default options perfect_foresight_with_expectation_errors_solver; -pfwee1 = oo_.endo_simul; - -// Second simulation with alternative guess values -perfect_foresight_with_expectation_errors_solver(terminal_steady_state_as_guess_value); -pfwee2 = oo_.endo_simul; +pfwee_simul = oo_.endo_simul; // Now compute the solution by hand to verify the results +oo_.steady_state = orig_steady_state; +oo_.exo_steady_state = orig_exo_steady_state; perfect_foresight_setup; @@ -92,7 +93,7 @@ perfect_foresight_solver; oo_.exo_simul(3,1) = 1.3; oo_.exo_steady_state = 1.1; oo_.exo_simul(end, 1) = oo_.exo_steady_state; -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, end) = oo_.steady_state; options_.periods = 6; saved_endo = oo_.endo_simul(:, 1); @@ -108,7 +109,7 @@ oo_.exo_simul(4,1) = 1.4; oo_.exo_simul(8,1) = 1.5; oo_.exo_steady_state = 1.1+0.1; oo_.exo_simul(end, 1) = oo_.exo_steady_state; -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, end) = oo_.steady_state; options_.periods = 5; saved_endo = oo_.endo_simul(:, 1:2); @@ -124,7 +125,7 @@ oo_.exo_simul(7,1) = 1*0.8; oo_.exo_simul(8,1) = 1.5*0.8; oo_.exo_steady_state = (1.1+0.1)*0.75; oo_.exo_simul(end, 1) = oo_.exo_steady_state; -oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); +oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true); oo_.endo_simul(:, end) = oo_.steady_state; options_.periods = 2; saved_endo = oo_.endo_simul(:, 1:5); @@ -137,12 +138,6 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; % We should have strict equality with first pfwee simulation, because algorithm % and guess values are exactly the same. -if any(any(pfwee1-oo_.endo_simul ~= 0)) +if any(any(pfwee_simul-oo_.endo_simul ~= 0)) error('Error in perfect_foresight_with_expectation_errors') end - -% For the 2nd simulation, since the guess values are different, there are some -% numerical differences -if max(max(abs(pfwee2-oo_.endo_simul))) > 10*options_.dynatol.f - error('Error in perfect_foresight_with_expectation_errors + terminal_steady_state_as_guess_value') -end diff --git a/tests/predetermined_variables.mod b/tests/deterministic_simulations/predetermined_variables.mod similarity index 100% rename from tests/predetermined_variables.mod rename to tests/deterministic_simulations/predetermined_variables.mod diff --git a/tests/ramst.mod b/tests/deterministic_simulations/ramst.mod similarity index 100% rename from tests/ramst.mod rename to tests/deterministic_simulations/ramst.mod diff --git a/tests/ramst_a.mod b/tests/deterministic_simulations/ramst_a.mod similarity index 100% rename from tests/ramst_a.mod rename to tests/deterministic_simulations/ramst_a.mod diff --git a/tests/ramst_mshocks.mod b/tests/deterministic_simulations/ramst_mshocks.mod similarity index 100% rename from tests/ramst_mshocks.mod rename to tests/deterministic_simulations/ramst_mshocks.mod diff --git a/tests/ramst_mshocks_vec.mod b/tests/deterministic_simulations/ramst_mshocks_vec.mod similarity index 100% rename from tests/ramst_mshocks_vec.mod rename to tests/deterministic_simulations/ramst_mshocks_vec.mod diff --git a/tests/ramst_vec.mod b/tests/deterministic_simulations/ramst_vec.mod similarity index 100% rename from tests/ramst_vec.mod rename to tests/deterministic_simulations/ramst_vec.mod diff --git a/tests/simul/simul_ZLB_purely_forward.mod b/tests/deterministic_simulations/simul_ZLB_purely_forward.mod similarity index 100% rename from tests/simul/simul_ZLB_purely_forward.mod rename to tests/deterministic_simulations/simul_ZLB_purely_forward.mod diff --git a/tests/simul/simul_ZLB_purely_forward_no_solution.mod b/tests/deterministic_simulations/simul_ZLB_purely_forward_no_solution.mod similarity index 100% rename from tests/simul/simul_ZLB_purely_forward_no_solution.mod rename to tests/deterministic_simulations/simul_ZLB_purely_forward_no_solution.mod diff --git a/tests/dsge_base2.mod b/tests/dsge_base2.mod deleted file mode 100644 index a4a7c4ad4a884b3bcd818a428798473398d48c83..0000000000000000000000000000000000000000 --- a/tests/dsge_base2.mod +++ /dev/null @@ -1,36 +0,0 @@ -// This file deals with the resolution and estimation of a basic DSGE model with -//employment for comparison with the benchmark in Gauss which solves with -//the same particular filter but global methodology. -// -// January 2010 - -var k A c l i y; -varexo e_a; - -parameters alp bet tet tau delt rho ; -alp = 0.4; -bet = 0.99; -tet = 0.357 ; -tau = 50 ; -delt = 0.02; -rho = 0.95; - -model; -c = ((1 - alp)*tet/(1-tet))*A*(1-l)*((k(-1)/l)^alp); -y = A*(k(-1)^alp)*(l^(1-alp)) ; -i = y-c ; -k = (1-delt)*k(-1) + i ; -log(A) = rho*log(A(-1)) + e_a ; -(((c^(tet))*((1-l)^(1-tet)))^(1-tau))/c - bet*((((c(+1)^(tet))*((1-l(+1))^(1-tet)))^(1-tau))/c(+1))*(1 -delt+alp*(A(1)*(k^alp)*(l(1)^(1-alp)))/k)=0 ; -end; - -shocks; -var e_a; stderr 0.035; -end; - -steady; - -stoch_simul; - -save dsge_base2.mat oo_ M_ options_; -close all, clc; diff --git a/tests/ecb/backward-models/solow_forecast.mod b/tests/ecb/backward-models/solow_forecast.mod index 6832141423c0d9839e6a4588c630f00358a13e08..78d766ec9d03446c7e5ad20f7ae906a0ab3c026f 100644 --- a/tests/ecb/backward-models/solow_forecast.mod +++ b/tests/ecb/backward-models/solow_forecast.mod @@ -51,7 +51,7 @@ histval; PhysicalCapitalStock(0) = 1; end; -simulation__ = simul_backward_nonlinear_model([], 10, options_, M_, oo_); +[simulation__, errorflag] = simul_backward_nonlinear_model([], 10, options_, M_, oo_); initialcondition = dseries(simulation__.data(10,1:M_.endo_nbr), 2017Q1, M_.endo_names); @@ -73,11 +73,11 @@ listofvariables = {'Efficiency', 'Output'}; forecasts = backward_model_forecast(initialcondition, listofvariables, 16, true); /* REMARKS -** +** ** - The third argument is the number of periods for the forecast. Default is 8. ** - The last argument is for computing (or not) the confidence bands. If false (default), only point forecast is produced. ** - forecasts is a structure, each field is a dseries object for the point forecast (ie forecasts without innovations in the future), -** the mean forecast, the median forecast, the standard deviation of the predictive distribution and the lower/upper bounds of the +** the mean forecast, the median forecast, the standard deviation of the predictive distribution and the lower/upper bounds of the ** interval containing 95% of the predictive distribution. */ @@ -89,7 +89,7 @@ plot(forecasts.ub.Output,'-r') hold off /* REMARKS -** -** In this model there is no steady state (only a stable balanced growth paths), this explains the +** +** In this model there is no steady state (only a stable balanced growth paths), this explains the ** shape of the forecast for Output. -*/ \ No newline at end of file +*/ diff --git a/tests/example1_with_tags.mod b/tests/equation_tags/example1_with_tags.mod similarity index 100% rename from tests/example1_with_tags.mod rename to tests/equation_tags/example1_with_tags.mod diff --git a/tests/ramst_static_tag.mod b/tests/equation_tags/ramst_static_tag.mod similarity index 100% rename from tests/ramst_static_tag.mod rename to tests/equation_tags/ramst_static_tag.mod diff --git a/tests/ramst_static_tag_block.mod b/tests/equation_tags/ramst_static_tag_block.mod similarity index 100% rename from tests/ramst_static_tag_block.mod rename to tests/equation_tags/ramst_static_tag_block.mod diff --git a/tests/estim_param_in_shock_value_xfail.mod b/tests/estimation/estim_param_in_shock_value_xfail.mod similarity index 100% rename from tests/estim_param_in_shock_value_xfail.mod rename to tests/estimation/estim_param_in_shock_value_xfail.mod diff --git a/tests/example1.mod b/tests/example1.mod deleted file mode 100644 index 54b0ffa9c26b9e84af21ea4b932acb6a7778fb4c..0000000000000000000000000000000000000000 --- a/tests/example1.mod +++ /dev/null @@ -1,52 +0,0 @@ -// Example 1 from Collard's guide to Dynare -var y, k, a, h, b; -varexo e, u; - -verbatim; -% I want these comments included in -% example1.m 1999q1 1999y -% -var = 1; -end; - -parameters beta, rho, alpha, delta, theta, psi, tau; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -[endogenous='c',name='law of motion of capital'] -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) - *(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) + e; -b = tau*a(-1)+rho*b(-1) + u; -end; - -initval; -y = 1.08068253095672; -c = 0.80359242014163; -h = 0.29175631001732; -k = 11.08360443260358; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -shocks; -var e; stderr 0.009; -var u; stderr 0.009; -var e, u = phi*0.009*0.009; -end; - -stoch_simul; diff --git a/tests/+matlab/+namespace/y_k.m b/tests/first_order/+matlab/+namespace/y_k.m similarity index 100% rename from tests/+matlab/+namespace/y_k.m rename to tests/first_order/+matlab/+namespace/y_k.m diff --git a/tests/walsh.mod b/tests/first_order/walsh.mod similarity index 98% rename from tests/walsh.mod rename to tests/first_order/walsh.mod index fced66cca6603eb9be11e8177c0720562093adeb..0275d71aad67cab5fb5cdc1acc4c8485632fefd2 100644 --- a/tests/walsh.mod +++ b/tests/first_order/walsh.mod @@ -1,3 +1,5 @@ +//test solvers for decision rules as well as accessing matlab namespace from steady state file (see #1639) + @#define Blocks = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15","16", "17", "18", "19", "20", "21", "22", "23", "24", "25","26", "27", "28", "29", "30", "31", "32", "33", "34", "35","36", "37", "38", "39", "40", "41", "42", "43", "44", "45","46", "47", "48", "49", "50", "51", "52", "53", "54", "55","56", "57", "58", "59", "60", "61", "62", "63", "64", "65","66", "67", "68", "69", "70", "71", "72", "73", "74", "75","76", "77", "78", "79", "80", "81", "82", "83", "84", "85","86", "87", "88", "89", "90", "91", "92", "93", "94", "95","96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115","116", "117", "118", "119", "120", "121", "122", "123", "124", "125","126", "127", "128", "129", "130", "131", "132", "133", "134", "135","136", "137", "138", "139", "140", "141", "142", "143", "144", "145","146", "147", "148", "149", "150", "151", "152", "153", "154", "155","156", "157", "158", "159", "160", "161", "162", "163", "164", "165","166", "167", "168", "169", "170", "171", "172", "173", "174", "175","176", "177", "178", "179", "180", "181", "182", "183", "184", "185","186", "187", "188", "189", "190", "191", "192", "193", "194", "195","196", "197", "198", "199", "200"] @#define blocks = Blocks[1:20] diff --git a/tests/example1_varexo_det.mod b/tests/forecast/example1_varexo_det.mod similarity index 100% rename from tests/example1_varexo_det.mod rename to tests/forecast/example1_varexo_det.mod diff --git a/tests/julia/rbc/README.md b/tests/julia/rbc/README.md deleted file mode 100644 index 2c40bdf3a389530d79d6c4a8e2aeacfc3f9b647d..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/README.md +++ /dev/null @@ -1,16 +0,0 @@ -To compile the Dynare mod files ```rbc1.mod``` and/or ```rbc2.mod``` and produce a julia module, just do - -``` -include("test1.jl") -``` -``` -include("test2.jl") -``` -or -``` -include("test3.jl") -``` -in a script or in julia's shell. The first script, evaluates the steady state of the model, using analytical solution or a numerical solver. The two other scripts do nothing except compiling the mod files. The ```test1pfm.jl``` script shows how to solve a perfect foresight model (transition to the steady state or effects of an expected shock). - -Note that Julia's packages ```NLsolve.jl``` and ```PyPlot.jl``` are required. - diff --git a/tests/julia/rbc/clean b/tests/julia/rbc/clean deleted file mode 100755 index 88c95b16b765523c9243decc287fa9531ac93537..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/clean +++ /dev/null @@ -1,8 +0,0 @@ -#/bin/sh -rm -f *~ -rm -f rbc1.jl rbc2.jl -rm -f rbc1Dynamic.jl rbc2Dynamic.jl -rm -f rbc1Static.jl rbc2Static.jl -rm -f rbc1SteadyState2.jl -rm -f rbc1_set_auxiliary_variables.jl rbc2_set_auxiliary_variables.jl -rm -rf rbc1 rbc2 diff --git a/tests/julia/rbc/rbc1.mod b/tests/julia/rbc/rbc1.mod deleted file mode 100644 index fcf6632cfc51531b9285c0c7d51e1ef9106db27c..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/rbc1.mod +++ /dev/null @@ -1,76 +0,0 @@ -var Capital , Output, Labour, Consumption, Efficiency, efficiency ; - -varexo EfficiencyInnovation; - -parameters beta, theta, tau, alpha, Epsilon, delta, rho, effstar, sigma; - -beta = 0.990; -theta = 0.357; -tau = 30.000; -alpha = 0.450; -delta = 0.020; -rho = 0.950; -effstar = 1.500; -sigma = 0.010; -Epsilon = 0.500; - -model; - -#Psi = (Epsilon-1)/Epsilon; - - // Eq. n°1: - efficiency = rho*efficiency(-1) + sigma*EfficiencyInnovation; - - // Eq. n°2: - Efficiency = effstar*exp(efficiency); - - // Eq. n°3: - Output = Efficiency*(alpha*Capital(-1)^Psi+(1-alpha)*Labour^Psi)^(1/Psi); - - // Eq. n°4: - Consumption + Capital - Output - (1-delta)*Capital(-1); - - // Eq. n°5: - ((1-theta)/theta)*(Consumption/(1-Labour)) - (1-alpha)*Efficiency^((1-Psi))*(alpha*(Capital(-1)/Labour)^Psi+1-alpha)^((1-Psi)/Psi); - - // Eq. n°6: - (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - - beta*(Consumption(1)^theta*(1-Labour(1))^(1-theta))^(1-tau)/Consumption(1)*(alpha*Efficiency(1)^Psi*(Output(1)/Capital)^(1-Psi)+1-delta); - -end; - - - -steady_state_model; - - efficiency = 0; - Efficiency = effstar; - - psi = (Epsilon-1)/Epsilon; - - Output_per_unit_of_Capital = ( (1/beta-1+delta) / (alpha*effstar^psi) )^(1/(1-psi)); - - Consumption_per_unit_of_Capital = Output_per_unit_of_Capital-delta; - - Labour_per_unit_of_Capital = ((Output_per_unit_of_Capital/Efficiency)^psi-alpha)^(1/psi)/(1-alpha)^(1/psi); - - gamma_1 = theta*(1-alpha)/(1-theta)*(Output_per_unit_of_Capital/Labour_per_unit_of_Capital)^(1-psi); - gamma_2 = (Output_per_unit_of_Capital-delta)/Labour_per_unit_of_Capital; - - Labour = 1/(1+gamma_2/gamma_1); - - Output_per_unit_of_Labour=Output_per_unit_of_Capital/Labour_per_unit_of_Capital; - - Consumption_per_unit_of_Labour=Consumption_per_unit_of_Capital/Labour_per_unit_of_Capital; - - ShareOfCapital= alpha^(1/(1-psi))*effstar^psi/(1/beta-1+delta)^(psi/(1-psi)); - - Consumption = Consumption_per_unit_of_Labour*Labour; - Capital = Labour/Labour_per_unit_of_Capital; - Output = Output_per_unit_of_Capital*Capital; - -end; - -shocks; -var EfficiencyInnovation = 1; -end; diff --git a/tests/julia/rbc/rbc2.mod b/tests/julia/rbc/rbc2.mod deleted file mode 100644 index a5604cf7fa0d1ef3c8d1adda4b908e6d6a3c9524..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/rbc2.mod +++ /dev/null @@ -1,44 +0,0 @@ -var Capital , Output, Labour, Consumption, Efficiency, efficiency ; - -varexo EfficiencyInnovation; - -parameters beta, theta, tau, alpha, Epsilon, delta, rho, effstar, sigma; - -beta = 0.990; -theta = 0.357; -tau = 30.000; -alpha = 0.450; -delta = 0.020; -rho = 0.950; -effstar = 1.500; -sigma = 0.010; -Epsilon = 0.500; - -model; - -#Psi = (Epsilon-1)/Epsilon; - - // Eq. n°1: - efficiency = rho*efficiency(-1) + sigma*EfficiencyInnovation; - - // Eq. n°2: - Efficiency = effstar*exp(efficiency); - - // Eq. n°3: - Output = Efficiency*(alpha*Capital(-1)^Psi+(1-alpha)*Labour^Psi)^(1/Psi); - - // Eq. n°4: - Consumption + Capital - Output - (1-delta)*Capital(-1); - - // Eq. n°5: - ((1-theta)/theta)*(Consumption/(1-Labour)) - (1-alpha)*Efficiency^((1-Psi))*(alpha*(Capital(-1)/Labour)^Psi+1-alpha)^((1-Psi)/Psi); - - // Eq. n°6: - (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - - beta*(Consumption(1)^theta*(1-Labour(1))^(1-theta))^(1-tau)/Consumption(1)*(alpha*Efficiency(1)^Psi*(Output(1)/Capital)^(1-Psi)+1-delta); - -end; - -shocks; -var EfficiencyInnovation = 1; -end; diff --git a/tests/julia/rbc/test1.jl b/tests/julia/rbc/test1.jl deleted file mode 100644 index 7dae1da06bec3e4cc4ab3d2f0c553c953412a24e..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/test1.jl +++ /dev/null @@ -1,80 +0,0 @@ -# Modification of the path (for packages). Should be done in ~/.juliarc.jl with a fixed path instead. -if isempty(findin([abspath("../../../julia")], LOAD_PATH)) - unshift!(LOAD_PATH, abspath("../../../julia")) -end - -using Dynare -using SteadyState - - -# Compile the rbc.mod file -> produce a module with the model definition. -@dynare "rbc1.mod" - -# First call to the steady state routine (analytical) -@time SteadyState.steady!(model_, oo_) - -# First call to the steady state routine (analytical) -@time SteadyState.steady!(model_, oo_) - -steadyState = deepcopy(oo_.steady_state) - -y_init = copy(steadyState) -y_init[1] = 1.1*steadyState[1] -y_init[2] = 0.9*steadyState[2] - -# First call to the steady state routine (numerical) -println("First call to the numerical steady state routine") -@time SteadyState.steady!(model_, oo_, y_init) - -# Check results -@assert maximum(abs.(oo_.steady_state-steadyState))<1e-6 - -yinit = deepcopy(steadyState) -yinit[1] = 1.1*steadyState[1] -yinit[2] = 0.9*steadyState[2] - -# Second call to the steady state routine (numerical) -println("Second call to the numerical steady state routine") -@time SteadyState.steady!(model_, oo_, yinit) - -params = model_.params - -# change alpha -println("Change α") -model_.params = deepcopy(params) -model_.params[4] = max(min(1.0, params[4]*1.1), 0.0) -@time ys = SteadyState.steady(model_, oo_) # Analytical steady state -@time SteadyState.steady!(model_, oo_, steadyState) -@assert maximum(abs.(oo_.steady_state-ys))<1e-6 - -# change delta -println("Change δ") -model_.params = deepcopy(params) -model_.params[6] = max(min(1.0, params[6]*1.1), 0.0) -@time ys = SteadyState.steady(model_, oo_) # Analytical steady state -@time SteadyState.steady!(model_, oo_, steadyState) -@assert maximum(abs.(oo_.steady_state-ys))<1e-6 - -# change beta -println("Change β") -model_.params = deepcopy(params) -model_.params[1] = max(min(1-1e-6, params[1]*0.99), 0.0) -@time ys = SteadyState.steady(model_, oo_) # Analytical steady state -@time SteadyState.steady!(model_, oo_, steadyState) -@assert maximum(abs.(oo_.steady_state-ys))<1e-6 - -# change tau -println("Change τ") -model_.params = deepcopy(params) -model_.params[3] = params[3]/1.1 -@time ys = SteadyState.steady(model_, oo_) -@time SteadyState.steady!(model_, oo_, steadyState) -@assert maximum(abs.(oo_.steady_state-ys))<1e-6 - -# change Epsilon -println("Change ϵ") -model_.params = deepcopy(params) -model_.params[5] = params[5]*1.1 -@time ys = SteadyState.steady(model_, oo_) -@time SteadyState.steady!(model_, oo_, steadyState) -@assert maximum(abs.(oo_.steady_state-ys))<1e-6 diff --git a/tests/julia/rbc/test1pfm.jl b/tests/julia/rbc/test1pfm.jl deleted file mode 100644 index 66748a20188ba9cfd350d29935d832b9fd4104ea..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/test1pfm.jl +++ /dev/null @@ -1,84 +0,0 @@ -# Modification of the path (for packages). Should be done in ~/.juliarc.jl with a fixed path instead. -if isempty(findin([abspath("../../../julia")], LOAD_PATH)) - unshift!(LOAD_PATH, abspath("../../../julia")) -end - -# Load packages -using Plots -using Dynare -using SteadyState -using PerfectForesightModelSolver - -plotlyjs() # Choose a backend - - -# Compile the rbc.mod file -> produce a module with the model definition. - -@dynare "rbc1.mod" - - -@time SteadyState.steady!(model_, oo_) - -println(oo_.steady_state) - -# Initialize paths for the endogenous variables -endogenousvariables = repmat(oo_.steady_state, 1, options_.pfmsolver.periods+2) -# Destroy part of the initial stock of physical capital. -endogenousvariables[1, 1] = .8*endogenousvariables[1, 1] - -# Set path for the innovations (no shocks). -exogenousvariables = repmat(oo_.exo_steady_state', options_.pfmsolver.periods+2, 1) - -# Simulate the transition to the steady state -@time simulate_perfect_foresight_model!(endogenousvariables, exogenousvariables, oo_.steady_state, model_, options_) - -n = 200 -dates = collect(0:n-1) -#plt[:figure](1) -plot(dates, vec(endogenousvariables[1,1:n]), color="black", linewidth=2.0, linestyle="-") - -# Initialize paths for the endogenous variables -endogenousvariables = repmat(oo_.steady_state, 1, options_.pfmsolver.periods+2) -# Destroy part of the initial stock of physical capital... -endogenousvariables[1, 1] = .8*endogenousvariables[1, 1] -# ... and assume that TFP is initially above its steady state level. -endogenousvariables[6, 1] = .5 - -# Set path for the innovations (no shocks). -exogenousvariables = repmat(oo_.exo_steady_state', options_.pfmsolver.periods+2, 1) - -# Simulate the transition to the steady state (we should have an hump shaped transition) -@time simulate_perfect_foresight_model!(endogenousvariables, exogenousvariables, oo_.steady_state, model_, options_) - -n = 200 -dates = collect(0:n-1) -plot(dates, vec(endogenousvariables[1,1:n]), color="red", linewidth=2.0, linestyle="-") - -# Initialize paths for the endogenous variables -endogenousvariables = repmat(oo_.steady_state, 1, options_.pfmsolver.periods+2) - -# Set path for the innovations (no shocks). -exogenousvariables = repmat(oo_.exo_steady_state', options_.pfmsolver.periods+2, 1) - -# Assume positive expected TFP shock in period 10 -exogenousvariables[10+1, 1] = 2 - -# Simulate the paths for the endogenous variables, given the expected shock -@time simulate_perfect_foresight_model!(endogenousvariables, exogenousvariables, oo_.steady_state, model_, options_) - -# dates = collect(0:n-1) -# n = 200 -# plt[:figure](2) -# subplot(221) -# title("Efficiency") -# plot(dates, vec(endogenousvariables[5,1:n]), color="black", linewidth=2.0, linestyle="-") -# subplot(223) -# title("Output") -# plot(dates, vec(endogenousvariables[2,1:n]), color="black", linewidth=2.0, linestyle="-") -# subplot(222) -# title("Consumption") -# plot(dates, vec(endogenousvariables[4,1:n]), color="black", linewidth=2.0, linestyle="-") -# subplot(224) -# title("Labour") -# plot(dates, vec(endogenousvariables[3,1:n]), color="black", linewidth=2.0, linestyle="-") -# suptitle("Expected positive expected shock") diff --git a/tests/julia/rbc/test2.jl b/tests/julia/rbc/test2.jl deleted file mode 100644 index ea6f15fd65fba7fb4847d2d7dd368da2a076357d..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/test2.jl +++ /dev/null @@ -1,14 +0,0 @@ -# Modification of the path (for packages). Should be done in ~/.juliarc.jl with a fixed path instead. -if isempty(findin([abspath("../../../julia")], LOAD_PATH)) - unshift!(LOAD_PATH, abspath("../../../julia")) -end - -# Load Dynare package(s) -using Dynare -using SteadyState - -# Compile the rbc.mod file -> produce a module with the model definition. -@dynare "rbc1.mod" - -# Compute the steady state -steady_state!(model_, oo_) diff --git a/tests/julia/rbc/test3.jl b/tests/julia/rbc/test3.jl deleted file mode 100644 index 301c96dbbd0d0ba57f31fe9a5c2387c4c933e8f6..0000000000000000000000000000000000000000 --- a/tests/julia/rbc/test3.jl +++ /dev/null @@ -1,21 +0,0 @@ -# Modification of the path (for packages). Should be done in ~/.juliarc.jl with a fixed path instead. -if isempty(findin([abspath("../../../julia")], LOAD_PATH)) - unshift!(LOAD_PATH, abspath("../../../julia")) -end - -# Load Dynare package -importall Dynare - -# Compile the rbc.mod file -> produce a module with the model definition. - - -@dynare "rbc1.mod" "rbc2.mod" - -# The previous command is equivalent to: -# -# @compile "rbc1.mod" -# using rbc1 - -print(rbc1.model_.fname) - -print(rbc2.model_.fname) diff --git a/tests/log_transform/ramst.mod b/tests/log_transform/ramst.mod index 01ce1514d36b1fed89082a8b50a238941d1c4a8c..edc86f1b53a687d1229abb211e0a6e395289e1dd 100644 --- a/tests/log_transform/ramst.mod +++ b/tests/log_transform/ramst.mod @@ -45,7 +45,7 @@ if max(abs(oo_.endo_simul(idx_log_c, :) - log(oo_.endo_simul(idx_c, :)))) > 1e-7 error('Transformation not correctly performed') end -S = load('../ramst/Output/ramst_results.mat'); +S = load('../deterministic_simulations/ramst/Output/ramst_results.mat'); if max(abs(oo_.endo_simul(idx_c, :) - S.oo_.endo_simul(idx_c, :))) > 1e-7 error('Result differs from non-transformed model') end diff --git a/tests/model_diagnostics/example2_block_model_diag.mod b/tests/model_diagnostics/example2_block_model_diag.mod new file mode 100644 index 0000000000000000000000000000000000000000..dcee082e1a018324fae8a101cd24257a43aa139c --- /dev/null +++ b/tests/model_diagnostics/example2_block_model_diag.mod @@ -0,0 +1,63 @@ +//test singular Jacobian check with block decomposition + +/* + * Example 2 from F. Collard (2001): "Stochastic simulations with DYNARE: + * A practical guide" (see "guide.pdf" in the documentation directory). + */ + +/* + * Copyright (C) 2001-2010 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/>. + */ + + +var y, c, k, a, h, b; +varexo e, u; + +parameters beta, rho, alpha, delta, theta, psi, tau; + +alpha = 0.36; +rho = 1; +tau = 0; +beta = 0.99; +delta = 0.025; +psi = 0; +theta = 2.95; + +model(block); +exp(c)*theta*exp(h)^(1+psi)=(1-alpha)*exp(y); +exp(k) = beta*(((exp(b)*exp(c))/(exp(b(+1))*exp(c(+1)))) + *(exp(b(+1))*alpha*exp(y(+1))+(1-delta)*exp(k))); +exp(y) = exp(a)*(exp(k(-1))^alpha)*(exp(h)^(1-alpha)); +exp(k) = exp(b)*(exp(y)-exp(c))+(1-delta)*exp(k(-1)); +a = rho*a(-1)+tau*b(-1) + e; +b = tau*a(-1)+rho*b(-1) + u; +end; + +initval; +y = 0.1; +c = -0.2; +h = -1.2; +k = 2.4; +a = 0; +b = 0; +e = 0; +u = 0; +end; + +steady; +model_diagnostics; \ No newline at end of file diff --git a/tests/objectives/sgu_ex1.mat b/tests/objectives/sgu_ex1.mat deleted file mode 100644 index 5f7a3b3dde42fbe9c399ee925b4df7a630f69b3b..0000000000000000000000000000000000000000 --- a/tests/objectives/sgu_ex1.mat +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:92631dd8caf649e29cb8d2626c2edeb70f74ee4aef6a3407ea2f0c96e062e878 -size 1368 diff --git a/tests/objectives/sgu_ex1.mod b/tests/objectives/sgu_ex1.mod deleted file mode 100644 index 4ee09866a956a6652021f41aee6fde731cf90577..0000000000000000000000000000000000000000 --- a/tests/objectives/sgu_ex1.mod +++ /dev/null @@ -1,33 +0,0 @@ -periods 20000; -var c k a; -varexo e; -parameters alpha beta delta gamma rho; - -beta = 0.95; -delta = 1; -alpha = 0.3; -rho = 0; -gamma = 2; - -model; -exp(c) + exp(k) = (1-delta) * exp(k(-1)) + exp(a) * exp(k(-1))^alpha; -exp(c)^(-gamma) = beta * exp(c(+1))^(-gamma) * (exp(a(+1)) * alpha * exp(k)^(alpha-1) + 1 - delta); -a = rho * a(-1) + e; -end; - -initval; -k=0; -c=0; -a=0; -e=0; -end; - -Sigma_e_ = 1; - -stoch_simul(nomoments,irf=0,nocorr,ar=0); - -global dr_ -dr_obj_ = dr_; - -save sgu_ex1.mat dr_obj_; - diff --git a/tests/optimal_policy/Ramsey/ramsey_ex.mod b/tests/optimal_policy/Ramsey/ramsey_ex.mod index ba00dcacfefd9accc97a783b176c6b0bcd6b5811..eebda5be68914790cb2c6f9e1baeb2f38ba5dac4 100644 --- a/tests/optimal_policy/Ramsey/ramsey_ex.mod +++ b/tests/optimal_policy/Ramsey/ramsey_ex.mod @@ -1,6 +1,6 @@ -/* Mod file tests the correctness of the Ramsey command when used together with a steady state file by - * - checking whether the results coincide with the ones when used with an initval block - * - checking whether between stoch_simul and ramsey_planner are consistent +/* Tests the correctness of the Ramsey command when used together with a steady state file by + * checking whether the results coincide with the ones when used with an initval block + * * The example is taken from Juillard, Michel (2011): User manual for optimal policy package, * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2 */ @@ -39,29 +39,20 @@ var u; stderr 0.008; end; planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma))); -ramsey_policy(planner_discount=0.99,order=1,instruments=(r)); -oo_ramsey_policy_steady_state_file=oo_; -stoch_simul(periods=0, order=1, irf=25, nograph); -if max(abs((oo_ramsey_policy_steady_state_file.steady_state-oo_.steady_state)))>1e-5 ... - || max(abs(oo_ramsey_policy_steady_state_file.dr.ys-oo_.dr.ys))>1e-5 ... - || max(max(abs(oo_ramsey_policy_steady_state_file.dr.ghx-oo_.dr.ghx)))>1e-5 ... - || max(max(abs(oo_ramsey_policy_steady_state_file.dr.ghu-oo_.dr.ghu)))>1e-5 ... - || max(max(abs(oo_ramsey_policy_steady_state_file.dr.Gy-oo_.dr.Gy)))>1e-5 ... - || abs(oo_ramsey_policy_steady_state_file.planner_objective_value.unconditional-oo_.planner_objective_value.unconditional)>1e-5 ... - || abs(oo_ramsey_policy_steady_state_file.planner_objective_value.conditional.zero_initial_multiplier-oo_.planner_objective_value.conditional.zero_initial_multiplier)>1e-5 ... - || abs(oo_ramsey_policy_steady_state_file.planner_objective_value.conditional.steady_initial_multiplier-oo_.planner_objective_value.conditional.steady_initial_multiplier)>1e-5 - error('Running stoch_simul after ramsey_policy leads to inconsistent results') -end - -load oo_ramsey_policy_initval; - -if any( [ max(abs((oo_ramsey_policy_initval.steady_state-oo_.steady_state)))>1e-5, ... - max(abs(oo_ramsey_policy_initval.dr.ys-oo_.dr.ys))>1e-5, ... - max(max(abs(oo_ramsey_policy_initval.dr.ghx-oo_.dr.ghx)))>1e-5, ... - max(max(abs(oo_ramsey_policy_initval.dr.ghu-oo_.dr.ghu)))>1e-5, ... - max(max(abs(oo_ramsey_policy_initval.dr.Gy-oo_.dr.Gy)))>1e-5, ... - abs(oo_ramsey_policy_initval.planner_objective_value.unconditional-oo_.planner_objective_value.unconditional)>1e-5, ... - abs(oo_ramsey_policy_initval.planner_objective_value.conditional.zero_initial_multiplier-oo_.planner_objective_value.conditional.zero_initial_multiplier)>1e-5, ... - abs(oo_ramsey_policy_initval.planner_objective_value.conditional.steady_initial_multiplier-oo_.planner_objective_value.conditional.steady_initial_multiplier)>1e-5] ) +ramsey_model(planner_discount=0.99,instruments=(r)); +steady; +stoch_simul(order=1, nograph); +evaluate_planner_objective; + +benchmark=load('ramsey_ex_initval/Output/ramsey_ex_initval_results.mat'); + +if any( [ max(abs((benchmark.oo_.steady_state-oo_.steady_state)))>1e-5, ... + max(abs(benchmark.oo_.dr.ys-oo_.dr.ys))>1e-5, ... + max(max(abs(benchmark.oo_.dr.ghx-oo_.dr.ghx)))>1e-5, ... + max(max(abs(benchmark.oo_.dr.ghu-oo_.dr.ghu)))>1e-5, ... + max(max(abs(benchmark.oo_.dr.Gy-oo_.dr.Gy)))>1e-5, ... + abs(benchmark.oo_.planner_objective_value.unconditional-oo_.planner_objective_value.unconditional)>1e-5, ... + abs(benchmark.oo_.planner_objective_value.conditional.zero_initial_multiplier-oo_.planner_objective_value.conditional.zero_initial_multiplier)>1e-5, ... + abs(benchmark.oo_.planner_objective_value.conditional.steady_initial_multiplier-oo_.planner_objective_value.conditional.steady_initial_multiplier)>1e-5] ) error('Initval and steady state file yield different results') end diff --git a/tests/optimal_policy/Ramsey/ramsey_ex_initval.mod b/tests/optimal_policy/Ramsey/ramsey_ex_initval.mod index 4743239a362102c311f1b488bc0cf03bd6376a4d..d307df828e6488b5cea1f9e31258c2cd93755cfd 100644 --- a/tests/optimal_policy/Ramsey/ramsey_ex_initval.mod +++ b/tests/optimal_policy/Ramsey/ramsey_ex_initval.mod @@ -1,5 +1,4 @@ -/* Mod file tests the functioning of the Ramsey command when used together with an initval-block - * - Tests whether subsequent calls to ramsey_policy and stoch_simul are possible +/* Tests the functioning of the Ramsey command when used together with an initval-block * The example is taken from Juillard, Michel (2011): User manual for optimal policy package, * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2 */ @@ -38,17 +37,7 @@ var u; stderr 0.008; end; planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma))); -ramsey_policy(planner_discount=0.99,order=1,instruments=(r)); -oo_ramsey_policy_initval=oo_; -save oo_ramsey_policy_initval.mat oo_ramsey_policy_initval; -stoch_simul(periods=0, order=1, irf=25, nograph); -if max(abs((oo_ramsey_policy_initval.steady_state-oo_.steady_state)))>1e-5 ... - || max(abs(oo_ramsey_policy_initval.dr.ys-oo_.dr.ys))>1e-5 ... - || max(max(abs(oo_ramsey_policy_initval.dr.ghx-oo_.dr.ghx)))>1e-5 ... - || max(max(abs(oo_ramsey_policy_initval.dr.ghu-oo_.dr.ghu)))>1e-5 ... - || max(max(abs(oo_ramsey_policy_initval.dr.Gy-oo_.dr.Gy)))>1e-5 ... - || abs(oo_ramsey_policy_initval.planner_objective_value.unconditional-oo_.planner_objective_value.unconditional)>1e-5 ... - || abs(oo_ramsey_policy_initval.planner_objective_value.conditional.zero_initial_multiplier-oo_.planner_objective_value.conditional.zero_initial_multiplier)>1e-5 ... - || abs(oo_ramsey_policy_initval.planner_objective_value.conditional.steady_initial_multiplier-oo_.planner_objective_value.conditional.steady_initial_multiplier)>1e-5 - error('Running stoch_simul after ramsey_policy leads to inconsistent results') -end +ramsey_model(planner_discount=0.99,instruments=(r)); +steady; +stoch_simul(order=1, nograph); +evaluate_planner_objective; diff --git a/tests/optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod b/tests/optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod index 0c522f57f03862ef759f669dc519b52f3fe19e0e..c5954ad166ecb8a9c573f5d83c44c63fe114e911 100644 --- a/tests/optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod +++ b/tests/optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod @@ -1,4 +1,8 @@ -/* Mod file tests the correctness of the Ramsey command when Auxiliary variables for AR2 are used +/* Test the correctness of the Ramsey command when a Lagrange multiplier + * appears with a lead ⩾2, and thus ends up in the definition of an auxiliary variable. + * + * This is related to issues #633, #1119 and #1133 + * * The example is adapted from Juillard, Michel (2011): User manual for optimal policy package, * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2 */ @@ -37,16 +41,7 @@ var u; stderr 0.008; end; planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma))); -ramsey_policy(planner_discount=0.99,order=1,instruments=(r)); -oo_ramsey_policy_initval_AR2=oo_; -stoch_simul(periods=0, order=1, irf=25, nograph); -if max(abs((oo_ramsey_policy_initval_AR2.steady_state-oo_.steady_state)))>1e-5 ... - || max(abs(oo_ramsey_policy_initval_AR2.dr.ys-oo_.dr.ys))>1e-5 ... - || max(max(abs(oo_ramsey_policy_initval_AR2.dr.ghx-oo_.dr.ghx)))>1e-5 ... - || max(max(abs(oo_ramsey_policy_initval_AR2.dr.ghu-oo_.dr.ghu)))>1e-5 ... - || max(max(abs(oo_ramsey_policy_initval_AR2.dr.Gy-oo_.dr.Gy)))>1e-5 ... - || abs(oo_ramsey_policy_initval_AR2.planner_objective_value.unconditional-oo_.planner_objective_value.unconditional)>1e-5 ... - || abs(oo_ramsey_policy_initval_AR2.planner_objective_value.conditional.zero_initial_multiplier-oo_.planner_objective_value.conditional.zero_initial_multiplier)>1e-5 ... - || abs(oo_ramsey_policy_initval_AR2.planner_objective_value.conditional.steady_initial_multiplier-oo_.planner_objective_value.conditional.steady_initial_multiplier)>1e-5 - error('Running stoch_simul after ramsey_policy leads to inconsistent results') -end \ No newline at end of file +ramsey_model(planner_discount=0.99,instruments=(r)); +steady; +stoch_simul(order=1, nograph); +evaluate_planner_objective; diff --git a/tests/parser/t_normcdf.mod b/tests/parser/t_normcdf.mod deleted file mode 100644 index 3c708dcbb5997b60f813f3ac7e506ff53672ba06..0000000000000000000000000000000000000000 --- a/tests/parser/t_normcdf.mod +++ /dev/null @@ -1,51 +0,0 @@ -var y1, y2, y3, x1, x2, x3; - -model; -x1 = 1.96; -x2 = 1; -x3 = 0.5; -y1 = normcdf(x1(-1),0,1); -y2 = normcdf(-x1,-x2,1); -y3 = normcdf(x1/2,0,x3(+1)); -end; - -initval; -y1 = 0; -y2 = 0; -y3 = 0; -x1 = 0; -x2 = 0; -x3 = 1; -end; - -steady; - -if abs(oo_.steady_state(1) - pnorm(1.96,0,1)) > 1e-12; - error('Error 1 in t_normcdf') -end; -if abs(oo_.steady_state(2) - pnorm(-1.96,-1,1)) > 1e-12; - error('Error 2 in t_normcdf') -end; -if abs(oo_.steady_state(3) - pnorm(1.96/2,0,1/2)) > 1e-12; - error('Error 3 in t_normcdf') -end; - -z = [oo_.steady_state(4); oo_.steady_state; oo_.steady_state(6)]; -[junk,JJ] = t_normcdf_dynamic(z,[]); - -if abs(JJ(4,1) + dnorm(1.96,0,1)) > 1e-12; - error('Error 4 in t_normcdf') -end; -if abs(JJ(5,5) - dnorm(-1.96,-1,1)) > 1e-12; - error('Error 5 in t_normcdf') -end; -if abs(JJ(5,6) + dnorm(-1.96,-1,1)) > 1e-12; - error('Error 6 in t_normcdf') -end; -if abs(JJ(6,5) + dnorm(1.96/2,0,1/2)/2) > 1e-12; - error('Error 7 in t_normcdf') -end; -if abs(JJ(6,8) - (1/2)*((1.96/2)/(1/2)^2)*dnorm(1.96/2,0,1/2)) > 1e-12; - error('Error 8 in t_normcdf') -end; - diff --git a/tests/comments.mod b/tests/preprocessor_checks/comments.mod similarity index 100% rename from tests/comments.mod rename to tests/preprocessor_checks/comments.mod diff --git a/tests/example1_extra_exo_xfail.mod b/tests/preprocessor_checks/example1_extra_exo_xfail.mod similarity index 100% rename from tests/example1_extra_exo_xfail.mod rename to tests/preprocessor_checks/example1_extra_exo_xfail.mod diff --git a/tests/example1_mlv.mod b/tests/preprocessor_checks/example1_mlv.mod similarity index 100% rename from tests/example1_mlv.mod rename to tests/preprocessor_checks/example1_mlv.mod diff --git a/tests/example1_undeclared_vars_xfail.mod b/tests/preprocessor_checks/example1_undeclared_vars_xfail.mod similarity index 100% rename from tests/example1_undeclared_vars_xfail.mod rename to tests/preprocessor_checks/example1_undeclared_vars_xfail.mod diff --git a/tests/ramst_xfail.mod b/tests/preprocessor_checks/ramst_all_values_required_xfail.mod similarity index 100% rename from tests/ramst_xfail.mod rename to tests/preprocessor_checks/ramst_all_values_required_xfail.mod diff --git a/tests/ramst_model_edit.mod b/tests/preprocessor_checks/ramst_model_edit.mod similarity index 94% rename from tests/ramst_model_edit.mod rename to tests/preprocessor_checks/ramst_model_edit.mod index a5600d6e6b7778c9dfa101359db01745bf92a569..dd103628a981877f09af1b7fbb3c9196b1c4c69a 100644 --- a/tests/ramst_model_edit.mod +++ b/tests/preprocessor_checks/ramst_model_edit.mod @@ -56,7 +56,7 @@ end; perfect_foresight_setup(periods=200); perfect_foresight_solver; -S = load('ramst/Output/ramst_results.mat'); +S = load('../deterministic_simulations/ramst/Output/ramst_results.mat'); if any(size(oo_.endo_simul) ~= size(S.oo_.endo_simul)) || any(any(abs(oo_.endo_simul - S.oo_.endo_simul) > 1e-10)) error('Model editing failure') end diff --git a/tests/prior_posterior_function/posterior_function_demo.m b/tests/prior_posterior_function/posterior_function_demo.m index 915f4fe70d0eeadccfcc7ef91939b2d5060cc114..2710432e8006eadadea78910eb8091c7ccbfae80 100644 --- a/tests/prior_posterior_function/posterior_function_demo.m +++ b/tests/prior_posterior_function/posterior_function_demo.m @@ -24,7 +24,7 @@ function output_cell =posterior_function_demo(xparam1,M_,options_,oo_,estim_para % output_cell [1 by n cell] 1 by n Matlab cell allowing to store any % desired computation or result (strings, matrices, structures, etc.) -% Copyright © 2015 Dynare Team +% Copyright © 2015-2023 Dynare Team % % This file is part of Dynare. % @@ -49,8 +49,8 @@ output_cell{1,1}=mean(xparam1); % set the parameters draws to the model structure M_ = set_all_parameters(xparam1,estim_params_,M_); % compute the steady state for the parameter draw written to M_ -[ys,params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,0); +[ys,params,info] = evaluate_steady_state(oo_.steady_state,[oo_.exo_steady_state; oo_.exo_det_steady_state],M_,options_,false); %set second part of output cell output_cell{1,2}=ys'; -end \ No newline at end of file +end diff --git a/tests/ramst2.mod b/tests/ramst2.mod deleted file mode 100644 index e74d3aef12d9e5a3532907104a78b52489879c1f..0000000000000000000000000000000000000000 --- a/tests/ramst2.mod +++ /dev/null @@ -1,46 +0,0 @@ -var c k dc s; -varexo x; - -parameters alph gam delt bet aa; -alph=0.5; -gam=0.5; -delt=0.02; -bet=0.05; -aa=0.5; - - -model; -c + k - aa*x*k(-1)^alph - (1-delt)*k(-1); -c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam); -dc = c - c(-1); -s = (dc>=0)-(dc<0); -end; - -initval; -x = 1; -k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1)); -c = aa*k^alph-delt*k; -dc = 0; -s = 1; -end; - -steady; - -check; - -shocks; -var x; -periods 1; -values 1.2; -end; - -perfect_foresight_setup(periods=200); -perfect_foresight_solver; - -dynasave('myfile') c x k; -dynatype('myfile1.txt') c x k; - -rplot c; -rplot k; -rplot dc; -rplot s; diff --git a/tests/example1_abs_sign.mod b/tests/stat_functions/example1_abs_sign.mod similarity index 100% rename from tests/example1_abs_sign.mod rename to tests/stat_functions/example1_abs_sign.mod diff --git a/tests/ramst_normcdf_and_friends.inc b/tests/stat_functions/ramst_normcdf_and_friends.inc similarity index 100% rename from tests/ramst_normcdf_and_friends.inc rename to tests/stat_functions/ramst_normcdf_and_friends.inc diff --git a/tests/ramst_normcdf_and_friends_bytecode.mod b/tests/stat_functions/ramst_normcdf_and_friends_bytecode.mod similarity index 100% rename from tests/ramst_normcdf_and_friends_bytecode.mod rename to tests/stat_functions/ramst_normcdf_and_friends_bytecode.mod diff --git a/tests/ramst_normcdf_and_friends_mfile.mod b/tests/stat_functions/ramst_normcdf_and_friends_mfile.mod similarity index 100% rename from tests/ramst_normcdf_and_friends_mfile.mod rename to tests/stat_functions/ramst_normcdf_and_friends_mfile.mod diff --git a/tests/ramst_normcdf_and_friends_use_dll.mod b/tests/stat_functions/ramst_normcdf_and_friends_use_dll.mod similarity index 100% rename from tests/ramst_normcdf_and_friends_use_dll.mod rename to tests/stat_functions/ramst_normcdf_and_friends_use_dll.mod diff --git a/tests/fs2000_ssfile.mod b/tests/steady_state/fs2000_ssfile.mod similarity index 100% rename from tests/fs2000_ssfile.mod rename to tests/steady_state/fs2000_ssfile.mod diff --git a/tests/fs2000_ssfile_aux.m b/tests/steady_state/fs2000_ssfile_aux.m similarity index 100% rename from tests/fs2000_ssfile_aux.m rename to tests/steady_state/fs2000_ssfile_aux.m diff --git a/tests/homotopy/common.mod b/tests/steady_state/homotopy/common.mod similarity index 100% rename from tests/homotopy/common.mod rename to tests/steady_state/homotopy/common.mod diff --git a/tests/homotopy/homotopy1_test.mod b/tests/steady_state/homotopy/homotopy1_test.mod similarity index 100% rename from tests/homotopy/homotopy1_test.mod rename to tests/steady_state/homotopy/homotopy1_test.mod diff --git a/tests/homotopy/homotopy2_test.mod b/tests/steady_state/homotopy/homotopy2_test.mod similarity index 100% rename from tests/homotopy/homotopy2_test.mod rename to tests/steady_state/homotopy/homotopy2_test.mod diff --git a/tests/homotopy/homotopy3_test.mod b/tests/steady_state/homotopy/homotopy3_test.mod similarity index 100% rename from tests/homotopy/homotopy3_test.mod rename to tests/steady_state/homotopy/homotopy3_test.mod diff --git a/tests/steady_state/walsh1_old_ss_steadystate.m b/tests/steady_state/walsh1_old_ss_steadystate.m index 6543d06186599bce8cea8efaa603bd6371bab0c4..fa6f5d95e74fed054d0e63345b71c8c4be8f9481 100644 --- a/tests/steady_state/walsh1_old_ss_steadystate.m +++ b/tests/steady_state/walsh1_old_ss_steadystate.m @@ -1,5 +1,7 @@ function [ys,params,check] = walsh1_old_ss_steadystate(ys,exo,M_,options_) +delta = NaN; + % read out parameters to access them with their name NumberOfParameters = M_.param_nbr; for ii = 1:NumberOfParameters @@ -11,35 +13,35 @@ check = 0; %% Enter model equations here - - pi = thetass-1; - en = 1/3; - eR = 1/betta; - y_k = (1/alphha)*(1/betta-1+delta); - ek = en*y_k^(-1/(1-alphha)); - ec = ek*(y_k-delta); - em = ec*(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^(-1/b); - ey = ek*y_k; - Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^((b-1)/b)); - Psi = (1-alphha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta; - n = log(en); - k = log(ek); - m = log(em); - c = log(ec); - y = log(ey); - R = log(eR); - z = 0; - u = 0; - + +pi = thetass-1; +en = 1/3; +eR = 1/betta; +y_k = (1/alphha)*(1/betta-1+delta); +ek = en*y_k^(-1/(1-alphha)); +ec = ek*(y_k-delta); +em = ec*(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^(-1/b); +ey = ek*y_k; +Xss = a*ec^(1-b)*(1+(a/(1-a))^(-1/b)*((thetass-betta)/thetass)^((b-1)/b)); +Psi = (1-alphha)*(ey/en)*Xss^((b-phi1)/(1-b))*a*ec^(-b)*(1-en)^eta; +n = log(en); +k = log(ek); +m = log(em); +c = log(ec); +y = log(ey); +R = log(eR); +z = 0; +u = 0; + %% end own model equations params=NaN(NumberOfParameters,1); for iter = 1:NumberOfParameters %update parameters set in the file - eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ]) + eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ]) end NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically for ii = 1:NumberOfEndogenousVariables - varname = M_.endo_names{ii}; - eval(['ys(' int2str(ii) ') = ' varname ';']); + varname = M_.endo_names{ii}; + eval(['ys(' int2str(ii) ') = ' varname ';']); end diff --git a/tests/simul/example1.mod b/tests/stochastic_simulations/example1.mod similarity index 100% rename from tests/simul/example1.mod rename to tests/stochastic_simulations/example1.mod diff --git a/tests/example1_irf_shocks.mod b/tests/stochastic_simulations/example1_irf_shocks.mod similarity index 100% rename from tests/example1_irf_shocks.mod rename to tests/stochastic_simulations/example1_irf_shocks.mod diff --git a/tests/example1long.mod b/tests/stochastic_simulations/example1long.mod similarity index 100% rename from tests/example1long.mod rename to tests/stochastic_simulations/example1long.mod diff --git a/tests/example2.mod b/tests/stochastic_simulations/example2_simul_replic.mod similarity index 100% rename from tests/example2.mod rename to tests/stochastic_simulations/example2_simul_replic.mod diff --git a/tests/example2long.mod b/tests/stochastic_simulations/example2long.mod similarity index 100% rename from tests/example2long.mod rename to tests/stochastic_simulations/example2long.mod diff --git a/tests/example2long_use_dll.mod b/tests/stochastic_simulations/example2long_use_dll.mod similarity index 100% rename from tests/example2long_use_dll.mod rename to tests/stochastic_simulations/example2long_use_dll.mod diff --git a/tests/seeds.mod b/tests/stochastic_simulations/example_seeds.mod similarity index 100% rename from tests/seeds.mod rename to tests/stochastic_simulations/example_seeds.mod diff --git a/tests/histval_predetermined.mod b/tests/stochastic_simulations/histval_predetermined.mod similarity index 98% rename from tests/histval_predetermined.mod rename to tests/stochastic_simulations/histval_predetermined.mod index 51ac05cf8f5c436a7f8119e1d529b59692f216da..4bfdbc3e97cebfb97444d4519673de55ede8d7b0 100644 --- a/tests/histval_predetermined.mod +++ b/tests/stochastic_simulations/histval_predetermined.mod @@ -56,5 +56,4 @@ end; stoch_simul(nograph, periods = 200); -forecast; - +forecast; \ No newline at end of file diff --git a/tests/histval_sto.mod b/tests/stochastic_simulations/histval_sto.mod similarity index 100% rename from tests/histval_sto.mod rename to tests/stochastic_simulations/histval_sto.mod diff --git a/tests/t_sgu_ex1.mod b/tests/t_sgu_ex1.mod deleted file mode 100644 index 87e270666659efa7c0651985a7cca3f020f8c546..0000000000000000000000000000000000000000 --- a/tests/t_sgu_ex1.mod +++ /dev/null @@ -1,37 +0,0 @@ -var c k a; -varexo e; -parameters alpha beta delta gamma rho; - -beta = 0.95; -delta = 1; -alpha = 0.3; -rho = 0; -gamma = 2; - -model; -exp(c) + exp(k) = (1-delta) * exp(k(-1)) + exp(a) * exp(k(-1))^alpha; -exp(c)^(-gamma) = beta * exp(c(+1))^(-gamma) * (exp(a(+1)) * alpha * exp(k)^(alpha-1) + 1 - delta); -a = rho * a(-1) + e; -end; - -initval; -k=0; -c=0; -a=0; -e=0; -end; - -Sigma_e_ = 1; - -stoch_simul(nomoments,nocorr,ar=0,irf=0); - -global dr_ -load objectives/sgu_ex1; - -fataltest(oo_.dr.ghx,dr_obj_.ghx,1); -fataltest(oo_.dr.ghu,dr_obj_.ghu,2); -fataltest(oo_.dr.ghxx,dr_obj_.ghxx,3); -fataltest(oo_.dr.ghxu,dr_obj_.ghxu,4); -fataltest(oo_.dr.ghuu,dr_obj_.ghuu,5); - -disp('TESTS OK'); diff --git a/windows/README.txt b/windows/README.txt index 2c52896e493767cfc1d75c3479f3c56bbdfdce54..fbe36f10b87671bf3a490bd3d91ecb724c54fbd0 100644 --- a/windows/README.txt +++ b/windows/README.txt @@ -21,8 +21,8 @@ Note: Dynare comes with an automated uninstaller, which you can run from the Using Dynare with MATLAB® ───────────────────────── -Dynare works on top of MATLAB®, any version ranging from 8.3 (R2014a) to 9.13 -(R2022b). Only 64-bit versions are supported. +Dynare works on top of MATLAB®, any version ranging from 8.3 (R2014a) to 9.14 +(R2023a). Only 64-bit versions are supported. To use Dynare, you just have to add the ‘matlab’ subdirectory of your Dynare installation to MATLAB® path. You have two options for doing that: @@ -52,10 +52,10 @@ Using Dynare with Octave Dynare also works on top of GNU Octave, a free clone of MATLAB® (see <https://www.octave.org>). -This version of Dynare is compiled for Octave 8.1.0 (MinGW, 64-bit), +This version of Dynare is compiled for Octave 8.2.0 (MinGW, 64-bit), and may not work with other versions of Octave. The recommended version of Octave can be downloaded at: - https://ftpmirror.gnu.org/gnu/octave/windows/octave-8.1.0-w64-installer.exe + https://ftpmirror.gnu.org/gnu/octave/windows/octave-8.2.0-w64-installer.exe Every time you run Octave, you should type the following command (assuming that you have installed Dynare at the standard location, and replacing ‘x.y’ by diff --git a/windows/build.sh b/windows/build.sh index 1719deb07630d23d8a51aa304222a2c5c6a6204c..d2c858f6d1236f9914502c3b67944ab1d151d7dd 100755 --- a/windows/build.sh +++ b/windows/build.sh @@ -54,6 +54,11 @@ BASENAME=dynare-$VERSION LIB64="$ROOT_DIRECTORY"/deps/lib64 LIB64_MSYS2="$ROOT_DIRECTORY"/deps/lib64-msys2 +# Set compilation flags +# For the architectural baseline, we follow MSYS2: +# https://www.msys2.org/news/#2022-10-18-new-minimum-hardware-requirements-cpus-from-20067 +arch_flags="-march=nocona -msahf -mtune=generic" +export CFLAGS="-O3 $arch_flags" # MSYS2 libraries are now built with -fstack-protector-strong, see: # https://www.msys2.org/news/#2022-10-23-mingw-packages-now-built-with-d_fortify_source2-and-fstack-protector-strong # As of 2023-01-03, when linking against HDF5 (and possibly other libraries), @@ -64,7 +69,8 @@ LIB64_MSYS2="$ROOT_DIRECTORY"/deps/lib64-msys2 # and there seems to be no easy way of linking it statically. # Also note that adding this flag is not necessary when building from MSYS2 shell. # Maybe revisit this once our runners are upgraded to Debian “Bookworm” 12. -export CXXFLAGS="-O2 -fstack-protector" +export CXXFLAGS="-O3 $arch_flags -fstack-protector" +export FCFLAGS="-O3 $arch_flags" # Go to source root directory cd .. @@ -129,8 +135,8 @@ build_windows_matlab_mex_64_b () PACKAGE_STRING="dynare $VERSION" make -j"$NTHREADS" all x86_64-w64-mingw32-strip -- **/*.mexw64 - mkdir -p "$ROOT_DIRECTORY"/../mex/matlab/win64-9.4-9.13 - mv -- **/*.mexw64 "$ROOT_DIRECTORY"/../mex/matlab/win64-9.4-9.13 + mkdir -p "$ROOT_DIRECTORY"/../mex/matlab/win64-9.4-9.14 + mv -- **/*.mexw64 "$ROOT_DIRECTORY"/../mex/matlab/win64-9.4-9.14 } # Create Windows DLL binaries for Octave/MinGW (64bit) diff --git a/windows/deps/Makefile b/windows/deps/Makefile index 801599346a0801835815e92dbdad3d140b53c0d5..2d3258389660d5dce0d21e0fd78826fd1294da6a 100644 --- a/windows/deps/Makefile +++ b/windows/deps/Makefile @@ -28,9 +28,9 @@ WGET_OPTIONS := --no-verbose --no-use-server-timestamps --retry-connrefused --re clean-tar clean-slicot-tar clean-x13as-tar \ clean-all clean-lib clean-src clean-tar -all: build octave matlab msys2 +all: build octave matlab msys2 x13as -build: build-slicot build-x13as +build: build-slicot clean-lib: clean-libslicot clean-matlab clean-octave clean-msys2 clean-x13as-bin @@ -170,7 +170,7 @@ msys2: lib64-msys2 mingw64 MSYS2_EXCLUDES := --exclude .MTREE --exclude .BUILDINFO --exclude .PKGINFO -lib64-msys2: tarballs/mingw-w64-x86_64-boost-$(MINGW64_BOOST_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-gsl-$(MINGW64_GSL_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-matio-$(MINGW64_MATIO_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-zlib-$(MINGW64_ZLIB_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-hdf5-$(MINGW64_HDF5_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-libaec-$(MINGW64_LIBAEC_VERSION)-any.pkg.tar.zst +lib64-msys2: tarballs/mingw-w64-x86_64-boost-$(MINGW64_BOOST_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-gsl-$(MINGW64_GSL_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-matio-$(MINGW64_MATIO_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-zlib-$(MINGW64_ZLIB_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-hdf5-$(MINGW64_HDF5_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-libaec-$(MINGW64_LIBAEC_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-openssl-$(MINGW64_OPENSSL_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-curl-$(MINGW64_CURL_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-zstd-$(MINGW64_ZSTD_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-brotli-$(MINGW64_BROTLI_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-libidn2-$(MINGW64_LIBIDN2_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-libpsl-$(MINGW64_LIBPSL_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-libssh2-$(MINGW64_LIBSSH2_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-nghttp2-$(MINGW64_NGHTTP2_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-libiconv-$(MINGW64_LIBICONV_VERSION)-any.pkg.tar.zst tarballs/mingw-w64-x86_64-libunistring-$(MINGW64_LIBUNISTRING_VERSION)-any.pkg.tar.zst rm -rf $@ mkdir $@ for f in $^; do tar xf $$f --directory $@ --strip-components 1 $(MSYS2_EXCLUDES); done @@ -193,30 +193,20 @@ clean-msys2: # X13AS # -tarballs/x13as_asciisrc-v$(X13AS_VERSION).tar.gz: +tarballs/x13as_ascii-v$(X13AS_VERSION).zip: mkdir -p tarballs - wget $(WGET_OPTIONS) -O $@ https://www2.census.gov/software/x-13arima-seats/x13as/unix-linux/program-archives/x13as_asciisrc-v$(X13AS_VERSION).tar.gz + wget $(WGET_OPTIONS) -O $@ https://www2.census.gov/software/x-13arima-seats/x13as/windows/program-archives/$(notdir $@) -sources64/x13as-$(X13AS_VERSION): tarballs/x13as_asciisrc-v$(X13AS_VERSION).tar.gz - rm -rf sources64/x13as-* - mkdir -p $@ - tar xf $< --directory $@ +lib64/x13as/x13as.exe: tarballs/x13as_ascii-v$(X13AS_VERSION).zip + unzip -o -d lib64 $< + mv lib64/x13as/x13as_ascii.exe $@ -lib64/x13as/x13as.exe: sources64/x13as-$(X13AS_VERSION) - make -C $< -f makefile.gf FC=x86_64-w64-mingw32-gfortran LINKER=x86_64-w64-mingw32-gfortran FFLAGS="-O2 -std=legacy" PROGRAM=x13as.exe - x86_64-w64-mingw32-strip $</x13as.exe - mkdir -p $(dir $@) - cp $</x13as.exe $@ - -build-x13as: lib64/x13as/x13as.exe +x13as: lib64/x13as/x13as.exe clean-x13as-tar: - rm -f tarballs/x13assrc_V$(X13AS_VERSION).tar.gz - -clean-x13as-src: - rm -rf sources64/x13as-$(X13AS_VERSION) + rm -f tarballs/x13as_ascii-v$(X13AS_VERSION).zip clean-x13as-bin: rm -rf lib64/x13as -clean-x13as-all: clean-x13as-tar clean-x13as-src clean-x13as-bin +clean-x13as-all: clean-x13as-tar clean-x13as-bin diff --git a/windows/deps/versions.mk b/windows/deps/versions.mk index 6c288b5d6d7c7028064d40ca6f122bc4ad319445..15ea1a36c01455a3511bdbf22d65c6ec0875799d 100644 --- a/windows/deps/versions.mk +++ b/windows/deps/versions.mk @@ -1,7 +1,7 @@ SLICOT_VERSION = 5.0+20101122 X13AS_VERSION = 1-1-b59 -OCTAVE_VERSION = 8.1.0 +OCTAVE_VERSION = 8.2.0 OCTAVE_W64_BUILD = MATLAB64_VERSION = 20200930 @@ -18,7 +18,7 @@ MATLAB64_VERSION = 20200930 ## Build dependencies # pacman -Ss mingw-w64-x86_64-boost -MINGW64_BOOST_VERSION = 1.81.0-6 +MINGW64_BOOST_VERSION = 1.81.0-7 # pacman -Ss mingw-w64-x86_64-gsl MINGW64_GSL_VERSION = 2.7.1-1 @@ -32,46 +32,80 @@ MINGW64_ZLIB_VERSION = 1.2.13-3 # Dependency of matio # pacman -Ss mingw-w64-x86_64-hdf5 -MINGW64_HDF5_VERSION = 1.12.2-2 +MINGW64_HDF5_VERSION = 1.14.1.2-2 # Dependency of HDF5 (provides szip library) # pacman -Ss mingw-w64-x86_64-libaec MINGW64_LIBAEC_VERSION = 1.0.6-2 +# Dependency of HDF5 +# pacman -Ss mingw-w64-x86_64-openssl +MINGW64_OPENSSL_VERSION = 3.1.1-1 + +# Dependency of HDF5 +# pacman -Ss mingw-w64-x86_64-curl +MINGW64_CURL_VERSION = 8.1.2-1 + +# Dependency of curl (and of the MinGW compiler) +# pacman -Ss mingw-w64-x86_64-zstd +MINGW64_ZSTD_VERSION = 1.5.5-1 + +# Dependency of curl +# pacman -Ss mingw-w64-x86_64-brotli +MINGW64_BROTLI_VERSION = 1.0.9-5 + +# Dependency of curl +# pacman -Ss mingw-w64-x86_64-libpsl +MINGW64_LIBPSL_VERSION = 0.21.2-4 + +# Dependency of curl and of libpsl +# pacman -Ss mingw-w64-x86_64-libidn2 +MINGW64_LIBIDN2_VERSION = 2.3.4-1 + +# Dependency of curl +# pacman -Ss mingw-w64-x86_64-libssh2 +MINGW64_LIBSSH2_VERSION = 1.10.0-2 + +# Dependency of curl +# pacman -Ss mingw-w64-x86_64-nghttp2 +MINGW64_NGHTTP2_VERSION = 1.53.0-1 + +# Dependency of libpsl and libunistring (and of the MinGW compiler) +# pacman -Ss mingw-w64-x86_64-libiconv +MINGW64_LIBICONV_VERSION = 1.17-3 + +# Dependency of libpsl and libidn2 +# pacman -Ss mingw-w64-x86_64-libunistring +MINGW64_LIBUNISTRING_VERSION = 1.1-1 + ## MinGW packages for the embedded compiler # pacman -Ss mingw-w64-x86_64-gcc$ -MINGW64_GCC_VERSION = 12.2.0-10 +MINGW64_GCC_VERSION = 13.1.0-6 # pacman -Ss mingw-w64-x86_64-gmp MINGW64_GMP_VERSION = 6.2.1-5 # pacman -Ss mingw-w64-x86_64-binutils -MINGW64_BINUTILS_VERSION = 2.40-2 +MINGW64_BINUTILS_VERSION = 2.40-4 # pacman -Ss mingw-w64-x86_64-headers-git -MINGW64_HEADERS_VERSION = 10.0.0.r234.g283e5b23a-1 +MINGW64_HEADERS_VERSION = 11.0.0.r18.g9df2e604d-1 # pacman -Ss mingw-w64-x86_64-crt-git -MINGW64_CRT_VERSION = 10.0.0.r234.g283e5b23a-1 +MINGW64_CRT_VERSION = 11.0.0.r18.g9df2e604d-1 # pacman -Ss mingw-w64-x86_64-winpthreads-git -MINGW64_WINPTHREADS_VERSION = 10.0.0.r234.g283e5b23a-1 - -# pacman -Ss mingw-w64-x86_64-zstd -MINGW64_ZSTD_VERSION = 1.5.4-1 +MINGW64_WINPTHREADS_VERSION = 11.0.0.r18.g9df2e604d-1 # pacman -Ss mingw-w64-x86_64-isl -MINGW64_ISL_VERSION = 0.25-1 +MINGW64_ISL_VERSION = 0.26-1 # pacman -Ss mingw-w64-x86_64-mpc MINGW64_MPC_VERSION = 1.3.1-1 # pacman -Ss mingw-w64-x86_64-mpfr -MINGW64_MPFR_VERSION = 4.2.0-1 - -# pacman -Ss mingw-w64-x86_64-libiconv -MINGW64_LIBICONV_VERSION = 1.17-3 +MINGW64_MPFR_VERSION = 4.2.0.p9-1 # pacman -Ss mingw-w64-x86_64-windows-default-manifest MINGW64_WINDOWS_DEFAULT_MANIFEST_VERSION = 6.4-4 diff --git a/windows/dynare.nsi b/windows/dynare.nsi index f58d2630c1903eacad41e8d28abb862b5d7c7fa7..a9f8d9b0b1f128c1ae6bc84343670e34aa3f45d3 100644 --- a/windows/dynare.nsi +++ b/windows/dynare.nsi @@ -95,9 +95,9 @@ Section "MEX files for MATLAB 64-bit, version 8.3 to 9.3 (R2014a to R2017b)" File ..\mex\matlab\win64-8.3-9.3\*.mexw64 SectionEnd -Section "MEX files for MATLAB 64-bit, version 9.4 to 9.13 (R2018a to R2022b)" - SetOutPath $INSTDIR\mex\matlab\win64-9.4-9.13 - File ..\mex\matlab\win64-9.4-9.13\*.mexw64 +Section "MEX files for MATLAB 64-bit, version 9.4 to 9.14 (R2018a to R2023a)" + SetOutPath $INSTDIR\mex\matlab\win64-9.4-9.14 + File ..\mex\matlab\win64-9.4-9.14\*.mexw64 SectionEnd Section "MinGW compiler for MATLAB 64-bit" @@ -105,14 +105,14 @@ Section "MinGW compiler for MATLAB 64-bit" File /r deps\mingw64\* SectionEnd -Section "MEX files for Octave 8.1.0 (64-bit)" +Section "MEX files for Octave 8.2.0 (64-bit)" SetOutPath $INSTDIR\mex\octave\win64 File ..\mex\octave\win64\* SectionEnd Section "Documentation and examples" SetOutPath $INSTDIR\doc - File ..\doc\manual\build\latex\dynare-manual.pdf ..\doc\guide.pdf ..\doc\bvar-a-la-sims.pdf ..\doc\dr.pdf ..\preprocessor\doc\macroprocessor\macroprocessor.pdf ..\preprocessor\doc\preprocessor\preprocessor.pdf ..\doc\parallel\parallel.pdf ..\doc\gsa\gsa.pdf ..\doc\dseries-and-reporting\dseriesReporting.pdf + File ..\doc\manual\build\latex\dynare-manual.pdf ..\doc\guide.pdf ..\doc\bvar-a-la-sims.pdf ..\doc\dr.pdf ..\doc\sylvester.pdf ..\doc\tl.pdf ..\preprocessor\doc\macroprocessor\macroprocessor.pdf ..\preprocessor\doc\preprocessor\preprocessor.pdf ..\doc\parallel\parallel.pdf ..\doc\gsa\gsa.pdf ..\doc\dseries-and-reporting\dseriesReporting.pdf SetOutPath $INSTDIR\doc\dynare-manual.html File /r ..\doc\manual\build\html\* diff --git a/windows/install-packages.sh b/windows/install-packages.sh index ae80543f0e5900c8e7f7e55132039f983f93557c..1eab1e6e8ad86ec6633e98743ecccde3ea7b8606 100755 --- a/windows/install-packages.sh +++ b/windows/install-packages.sh @@ -3,7 +3,7 @@ # On a Debian system, install the packages needed for Windows # cross-compilation, and also setup the cross-compiler alternatives. -# Copyright © 2017-2022 Dynare Team +# Copyright © 2017-2023 Dynare Team # # This file is part of Dynare. # @@ -22,15 +22,16 @@ [[ $(id -u) == 0 ]] || { echo "You must be root" >&2; exit 1; } -PACKAGES=(make xz-utils p7zip bzip2 zip zstd patch wget autoconf automake - libtool mingw-w64 gfortran-mingw-w64 parallel flex libfl-dev bison texlive +PACKAGES=(make p7zip zip zstd wget autoconf automake + gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix + gfortran-mingw-w64-x86-64-posix parallel flex libfl-dev bison texlive texlive-publishers texlive-latex-extra texlive-science texlive-fonts-extra lmodern python3-sphinx latexmk nsis) apt install "${PACKAGES[@]}" # Configure MinGW to use the POSIX threading model (needed for C++11 threads in -# Dynare++, see /usr/share/doc/gcc-mingw-w64-base/README.Debian) +# libkorder, see /usr/share/doc/gcc-mingw-w64-base/README.Debian) update-alternatives --set x86_64-w64-mingw32-gfortran /usr/bin/x86_64-w64-mingw32-gfortran-posix update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix