Merge branch 'master' into ecb-master
commit
d8ffd5e83c
|
@ -91,7 +91,7 @@ If you have downloaded the sources from an official source archive or the source
|
|||
|
||||
If you want to use Git, do the following from a terminal:
|
||||
|
||||
git clone --recursive http://github.com/DynareTeam/dynare.git
|
||||
git clone --recursive https://github.com/DynareTeam/dynare.git
|
||||
cd dynare
|
||||
autoreconf -si
|
||||
|
||||
|
|
106
doc/dynare.texi
106
doc/dynare.texi
|
@ -114,8 +114,8 @@ A copy of the license can be found at @uref{http://www.gnu.org/licenses/fdl.txt}
|
|||
@subtitle Reference Manual, version @value{VERSION}
|
||||
@author Stéphane Adjemian
|
||||
@author Houtan Bastani
|
||||
@author Frédéric Karamé
|
||||
@author Michel Juillard
|
||||
@author Frédéric Karamé
|
||||
@author Junior Maih
|
||||
@author Ferhat Mihoubi
|
||||
@author George Perendia
|
||||
|
@ -171,14 +171,14 @@ Installation of Dynare
|
|||
|
||||
* On Windows::
|
||||
* On Debian GNU/Linux and Ubuntu::
|
||||
* On Mac OS X::
|
||||
* On macOS::
|
||||
* For other systems::
|
||||
|
||||
Compiler installation
|
||||
|
||||
* Prerequisites on Windows::
|
||||
* Prerequisites on Debian GNU/Linux and Ubuntu::
|
||||
* Prerequisites on Mac OS X::
|
||||
* Prerequisites on macOS::
|
||||
|
||||
Configuration
|
||||
|
||||
|
@ -356,23 +356,21 @@ as a support tool for forecasting exercises. In the academic world,
|
|||
Dynare is used for research and teaching purposes in postgraduate
|
||||
macroeconomics courses.
|
||||
|
||||
Dynare is a free software, which means that it can be downloaded free
|
||||
of charge, that its source code is freely available, and that it can
|
||||
be used for both non-profit and for-profit purposes. Most of the
|
||||
source files are covered by the GNU General Public Licence (GPL)
|
||||
version 3 or later (there are some exceptions to this, see the file
|
||||
@file{license.txt} in Dynare distribution). It is available for the
|
||||
Windows, Mac and Linux platforms and is fully documented through a
|
||||
user guide and a reference manual. Part of Dynare is programmed in
|
||||
C++, while the rest is written using the
|
||||
@uref{http://www.mathworks.com/products/matlab/, MATLAB} programming
|
||||
language. The latter implies that commercially-available MATLAB
|
||||
software is required in order to run Dynare. However, as an
|
||||
alternative to MATLAB, Dynare is also able to run on top of
|
||||
@uref{http://www.octave.org, GNU Octave} (basically a free clone of
|
||||
MATLAB): this possibility is particularly interesting for students or
|
||||
institutions who cannot afford, or do not want to pay for, MATLAB and
|
||||
are willing to bear the concomitant performance loss.
|
||||
Dynare is a free software, which means that it can be downloaded free of
|
||||
charge, that its source code is freely available, and that it can be used for
|
||||
both non-profit and for-profit purposes. Most of the source files are covered
|
||||
by the GNU General Public Licence (GPL) version 3 or later (there are some
|
||||
exceptions to this, see the file @file{license.txt} in Dynare distribution). It
|
||||
is available for the Windows, macOS, and Linux platforms and is fully
|
||||
documented through a user guide and a reference manual. Part of Dynare is
|
||||
programmed in C++, while the rest is written using the
|
||||
@uref{http://www.mathworks.com/products/matlab/, MATLAB} programming language.
|
||||
The latter implies that commercially-available MATLAB software is required in
|
||||
order to run Dynare. However, as an alternative to MATLAB, Dynare is also able
|
||||
to run on top of @uref{http://www.octave.org, GNU Octave} (basically a free
|
||||
clone of MATLAB): this possibility is particularly interesting for students or
|
||||
institutions who cannot afford, or do not want to pay for, MATLAB and are
|
||||
willing to bear the concomitant performance loss.
|
||||
|
||||
The development of Dynare is mainly done at
|
||||
@uref{http://www.cepremap.fr, Cepremap} by a core team of
|
||||
|
@ -450,7 +448,7 @@ If you want to give a URL, use the address of the Dynare website:
|
|||
|
||||
Packaged versions of Dynare are available for Windows XP/Vista/7/8,
|
||||
@uref{http://www.debian.org,Debian GNU/Linux},
|
||||
@uref{http://www.ubuntu.com/,Ubuntu} and Mac OS X 10.8 or later. Dynare should
|
||||
@uref{http://www.ubuntu.com/,Ubuntu} and macOS 10.8 or later. Dynare should
|
||||
work on other systems, but some compilation steps are necessary in that case.
|
||||
|
||||
In order to run Dynare, you need one of the following:
|
||||
|
@ -458,7 +456,7 @@ In order to run Dynare, you need one of the following:
|
|||
@itemize
|
||||
|
||||
@item
|
||||
MATLAB version 7.5 (R2007b) or above (MATLAB R2009b 64-bit for Mac OS X);
|
||||
MATLAB version 7.5 (R2007b) or above (MATLAB R2009b 64-bit for macOS);
|
||||
|
||||
@item
|
||||
GNU Octave version 3.6 or above.
|
||||
|
@ -481,10 +479,6 @@ If under GNU Octave, the following
|
|||
@uref{http://octave.sourceforge.net/,Octave-Forge} packages: optim,
|
||||
io, statistics, control.
|
||||
|
||||
@item
|
||||
Mac OS X Octave users will also need to install
|
||||
gnuplot if they want graphing capabilities.
|
||||
|
||||
@end itemize
|
||||
|
||||
|
||||
|
@ -501,7 +495,7 @@ about your own files.
|
|||
@menu
|
||||
* On Windows::
|
||||
* On Debian GNU/Linux and Ubuntu::
|
||||
* On Mac OS X::
|
||||
* On macOS::
|
||||
* For other systems::
|
||||
@end menu
|
||||
|
||||
|
@ -532,25 +526,29 @@ Wiki} for detailed instructions.
|
|||
Dynare will be installed under @file{/usr/lib/dynare}. Documentation will be
|
||||
under @file{/usr/share/doc/dynare-doc}.
|
||||
|
||||
@node On Mac OS X
|
||||
@subsection On Mac OS X
|
||||
@node On macOS
|
||||
@subsection On macOS
|
||||
|
||||
Execute the automated installer called
|
||||
@file{dynare-4.@var{x}.@var{y}.pkg} (where
|
||||
4.@var{x}.@var{y} is the version number), and follow the
|
||||
instructions. The default installation directory is
|
||||
@file{/Applications/Dynare/4.@var{x}.@var{y}}.
|
||||
|
||||
Please refer to the
|
||||
To install Dynare for use with Matlab, execute the automated installer called
|
||||
@file{dynare-4.@var{x}.@var{y}.pkg} (where 4.@var{x}.@var{y} is the version
|
||||
number), and follow the instructions. The default installation directory is
|
||||
@file{/Applications/Dynare/4.@var{x}.@var{y}} (please refer to the
|
||||
@uref{http://www.dynare.org/DynareWiki/InstallOnMacOSX,Dynare Wiki} for
|
||||
detailed instructions.
|
||||
detailed instructions).
|
||||
|
||||
After installation, this directory will contain several sub-directories,
|
||||
among which are @file{matlab}, @file{mex} and @file{doc}.
|
||||
|
||||
Note that you can have several versions of Dynare coexisting (for
|
||||
example in @file{/Applications/Dynare}), as long as you correctly
|
||||
adjust your path settings (@pxref{Some words of warning}).
|
||||
Note that several versions of Dynare can coexist (by default in
|
||||
@file{/Applications/Dynare}), as long as you correctly adjust your path
|
||||
settings (@pxref{Some words of warning}).
|
||||
|
||||
To install Dynare for Octave, first install Homebrew following the instructions
|
||||
on their site: @uref{https://brew.sh/}. Then install Octave, issuing the
|
||||
command @code{brew install octave} at the Terminal prompt. You can then install
|
||||
the latest stable version of Dynare by typing @code{brew install dynare} at the
|
||||
Terminal prompt. You can also pass options to the installation command. These
|
||||
options can be viewed by typing @code{brew info dynare} at the Terminal prompt.
|
||||
|
||||
@node For other systems
|
||||
@subsection For other systems
|
||||
|
@ -579,7 +577,7 @@ Octave comes with built-in functionality for compiling mex-files.
|
|||
@menu
|
||||
* Prerequisites on Windows::
|
||||
* Prerequisites on Debian GNU/Linux and Ubuntu::
|
||||
* Prerequisites on Mac OS X::
|
||||
* Prerequisites on macOS::
|
||||
@end menu
|
||||
|
||||
@node Prerequisites on Windows
|
||||
|
@ -607,9 +605,9 @@ it can be installed via @code{apt-get install build-essential}.
|
|||
Users of Octave under Linux should install the package for MEX file compilation
|
||||
(under Debian or Ubuntu, it is called @file{liboctave-dev}).
|
||||
|
||||
@node Prerequisites on Mac OS X
|
||||
@subsection Prerequisites on Mac OS X
|
||||
If you are using MATLAB under Mac OS X, you should install the latest
|
||||
@node Prerequisites on macOS
|
||||
@subsection Prerequisites on macOS
|
||||
If you are using MATLAB under macOS, you should install the latest
|
||||
version of XCode: see
|
||||
@uref{http://www.dynare.org/DynareWiki/InstallOnMacOSX,instructions on
|
||||
the Dynare wiki}.
|
||||
|
@ -649,7 +647,7 @@ Under Debian GNU/Linux or Ubuntu, type:
|
|||
addpath /usr/lib/dynare/matlab
|
||||
@end example
|
||||
|
||||
Under Mac OS X, assuming that you have installed Dynare in the standard
|
||||
Under macOS, assuming that you have installed Dynare in the standard
|
||||
location, and replacing @code{4.@var{x}.@var{y}} with the correct version
|
||||
number, type:
|
||||
|
||||
|
@ -664,7 +662,7 @@ will have to do it again.
|
|||
Via the menu entries:
|
||||
|
||||
Select the ``Set Path'' entry in the ``File'' menu, then click on
|
||||
``Add Folder@dots{}'', and select the @file{matlab} subdirectory of your
|
||||
``Add Folder@dots{}'', and select the @file{matlab} subdirectory of `your
|
||||
Dynare installation. Note that you @emph{should not} use ``Add with
|
||||
Subfolders@dots{}''. Apply the settings by clicking on ``Save''. Note that
|
||||
MATLAB will remember this setting next time you run it.
|
||||
|
@ -688,18 +686,16 @@ addpath c:\dynare\4.@var{x}.@var{y}\matlab
|
|||
Under Debian GNU/Linux or Ubuntu, there is no need to use the
|
||||
@code{addpath} command; the packaging does it for you.
|
||||
|
||||
Under Mac OS X, assuming that you have installed Dynare in the
|
||||
standard location, and replacing ``4.@var{x}.@var{y}'' with the correct
|
||||
version number, type:
|
||||
Under macOS, assuming that you have installed Dynare and Octave via Homebrew, type:
|
||||
|
||||
@example
|
||||
addpath /Applications/Dynare/4.@var{x}.@var{y}/matlab
|
||||
addpath /usr/local/opt/dynare/lib/dynare/matlab
|
||||
@end example
|
||||
|
||||
If you don't want to type this command every time you run Octave, you
|
||||
can put it in a file called @file{.octaverc} in your home directory
|
||||
(under Windows this will generally be @file{c:\Documents and
|
||||
Settings\USERNAME\} while under Mac OS X it is @file{/Users/USERNAME/}).
|
||||
Settings\USERNAME\} while under macOS it is @file{/Users/USERNAME/}).
|
||||
This file is run by Octave at every startup.
|
||||
|
||||
@node Some words of warning
|
||||
|
@ -11138,7 +11134,7 @@ related to the model (and hence not placed in the model file). At the
|
|||
moment, it is only used when using Dynare to run parallel
|
||||
computations.
|
||||
|
||||
On Linux and Mac OS X, the default location of the configuration file
|
||||
On Linux and macOS, the default location of the configuration file
|
||||
is @file{$HOME/.dynare}, while on Windows it is
|
||||
@file{%APPDATA%\dynare.ini} (typically @file{C:\Documents and
|
||||
Settings\@var{USERNAME}\Application Data\dynare.ini} under Windows XP,
|
||||
|
@ -11399,7 +11395,7 @@ If just one integer is passed, the number of processors to use. If a
|
|||
range of integers is passed, the specific processors to use (processor
|
||||
counting is defined to begin at one as opposed to zero). Note that
|
||||
using specific processors is only possible under Windows; under Linux
|
||||
and Mac OS X, if a range is passed the same number of processors will
|
||||
and macOS, if a range is passed the same number of processors will
|
||||
be used but the range will be adjusted to begin at one.
|
||||
|
||||
@item ComputerName = @var{COMPUTER_NAME}
|
||||
|
@ -13821,7 +13817,7 @@ Instantiates a @code{Report} object.
|
|||
The full path to the @LaTeX{} compiler on your system. If this option
|
||||
is not provided, Dynare will try to find the appropriate program to
|
||||
compile @LaTeX{} on your system. Default is system dependent: Windows:
|
||||
the result of @code{findtexmf --file-type=exe pdflatex}, Mac OS X and
|
||||
the result of @code{findtexmf --file-type=exe pdflatex}, macOS and
|
||||
Linux: the result of @code{which pdflatex}
|
||||
|
||||
@item showDate, @code{BOOLEAN}
|
||||
|
@ -14390,7 +14386,7 @@ Print the compiler output to the screen. Useful for debugging your code as the
|
|||
@ref{showOutput}
|
||||
|
||||
@item showReport, @code{BOOLEAN}
|
||||
Open the compiled report (works on Windows and OS X on Matlab). Default:
|
||||
Open the compiled report (works on Windows and macOS on Matlab). Default:
|
||||
@code{true}
|
||||
|
||||
@end table
|
||||
|
|
|
@ -155,18 +155,18 @@ sigma_m =-5.85;
|
|||
Lambdamu=3.4e-3;
|
||||
LambdaA = 2.8e-3;
|
||||
|
||||
LambdaYd= (LambdaA+alppha*Lambdamu)/(1-alppha);
|
||||
|
||||
/*
|
||||
The following parameters are set in the steady state file as they depend on other
|
||||
deep parameters that were estimated in the original study. Setting them in the
|
||||
deep parameters (some were estimated in the original study). Setting them in the
|
||||
steady state file means they are updated for every parameter draw in the MCMC
|
||||
algorithm, while the parameters initialized here are only set once for the initial
|
||||
values of the parameters they depend on:
|
||||
|
||||
gammma1 as it depends on LambdaA, alppha, Lambdamu, betta, and delta
|
||||
Rbar =0 as it depends on PI, LambdaA, alppha, Lambdamu, and betta
|
||||
Lambdax
|
||||
gammma1=mu_z*mu_I/betta-(1-delta);
|
||||
R=1+(PIbar*mu_z/betta-1);
|
||||
Lambdax=exp(LambdaYd);
|
||||
LambdaYd= (LambdaA+alppha*Lambdamu)/(1-alppha);
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ d=1;
|
|||
phi=1;
|
||||
m=0;
|
||||
zeta=1;
|
||||
LambdaYd= (LambdaA+alppha*Lambdamu)/(1-alppha);
|
||||
mu_z=exp(LambdaYd);
|
||||
mu_I=exp(Lambdamu);
|
||||
mu_A=exp(LambdaA);
|
||||
|
|
200
license.txt
200
license.txt
|
@ -1,4 +1,4 @@
|
|||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: Dynare
|
||||
Upstream-Contact: Dynare Team, whose members in 2017 are:
|
||||
Stéphane Adjemian <stephane.adjemian@univ-lemans.fr>
|
||||
|
@ -17,8 +17,8 @@ Copyright: 1996-2017 Dynare Team
|
|||
License: GPL-3+
|
||||
|
||||
Files: matlab/AIM/SP*
|
||||
Copyright: public-domain
|
||||
License: public-domain
|
||||
Copyright: none
|
||||
License: public-domain-aim
|
||||
This code is in the public domain and may be used freely.
|
||||
However the authors would appreciate acknowledgement of the source by
|
||||
citation of any of the following papers:
|
||||
|
@ -85,53 +85,56 @@ Copyright: 2016 Benjamin Born and Johannes Pfeifer
|
|||
2016 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab\gsa\Morris_Measure_Groups.m
|
||||
matlab\gsa\Sampling_Function_2.m
|
||||
Written by Jessica Cariboni and Francesca Campolongo
|
||||
Files: matlab/gsa/Morris_Measure_Groups.m
|
||||
matlab/gsa/Sampling_Function_2.m
|
||||
Copyright: 2005 European Commission
|
||||
2012 Dynare Team
|
||||
License: GPL-3+
|
||||
Comment: Written by Jessica Cariboni and Francesca Campolongo
|
||||
Joint Research Centre, The European Commission,
|
||||
Copyright (C) 2005 European Commission
|
||||
Copyright (C) 2012 Dynare Team
|
||||
|
||||
Files: matlab\gsa\cumplot.m
|
||||
matlab\gsa\filt_mc_.m
|
||||
matlab\gsa\gsa_plotmatrix.m
|
||||
matlab\gsa\gsa_skewness.m
|
||||
matlab\gsa\gsa_speed.m
|
||||
matlab\gsa\log_trans_.m
|
||||
matlab\gsa\map_calibration.m
|
||||
matlab\gsa\map_ident_.m
|
||||
matlab\gsa\mcf_analysis.m
|
||||
matlab\gsa\myboxplot.m
|
||||
matlab\gsa\myprctilecol.m
|
||||
matlab\gsa\prior_draw_gsa.m
|
||||
matlab\gsa\read_data.m
|
||||
matlab\gsa\redform_map.m
|
||||
matlab\gsa\redform_screen.m
|
||||
matlab\gsa\scatter_mcf.m
|
||||
matlab\gsa\smirnov.m
|
||||
matlab\gsa\stab_map_.m
|
||||
matlab\gsa\stab_map_1.m
|
||||
matlab\gsa\stab_map_2.m
|
||||
matlab\gsa\stand_.m
|
||||
matlab\gsa\tcrit.m
|
||||
matlab\gsa\teff.m
|
||||
matlab\gsa\trank.m
|
||||
Copyright (C) 2011-2017 European Commission
|
||||
Copyright (C) 2011-2017 Dynare Team
|
||||
Files: matlab/gsa/cumplot.m
|
||||
matlab/gsa/filt_mc_.m
|
||||
matlab/gsa/gsa_plotmatrix.m
|
||||
matlab/gsa/gsa_skewness.m
|
||||
matlab/gsa/gsa_speed.m
|
||||
matlab/gsa/log_trans_.m
|
||||
matlab/gsa/map_calibration.m
|
||||
matlab/gsa/map_ident_.m
|
||||
matlab/gsa/mcf_analysis.m
|
||||
matlab/gsa/myboxplot.m
|
||||
matlab/gsa/myprctilecol.m
|
||||
matlab/gsa/prior_draw_gsa.m
|
||||
matlab/gsa/read_data.m
|
||||
matlab/gsa/redform_map.m
|
||||
matlab/gsa/redform_screen.m
|
||||
matlab/gsa/scatter_mcf.m
|
||||
matlab/gsa/smirnov.m
|
||||
matlab/gsa/stab_map_.m
|
||||
matlab/gsa/stab_map_1.m
|
||||
matlab/gsa/stab_map_2.m
|
||||
matlab/gsa/stand_.m
|
||||
matlab/gsa/tcrit.m
|
||||
matlab/gsa/teff.m
|
||||
matlab/gsa/trank.m
|
||||
Copyright: 2011-2017 European Commission
|
||||
2011-2017 Dynare Team
|
||||
License: GPL-3+
|
||||
|
||||
Files: matlab/gsa/pick.m
|
||||
Copyright (C) 2001-2017 European Commission
|
||||
This file is part of GLUEWIN
|
||||
The program has been developed by M. Ratto, European Commission, Joint Research Centre,
|
||||
Institute for the Protection and Security of The Citizen, Technological and Economic Risk Management,
|
||||
Applied Statistics, as a deliverable of the IMPACT project
|
||||
(EC Fifth Framework Programme, SCA Project, IST-1999-11313, DG-INFSO).
|
||||
Disclaimer: This software has been developed at the Joint Research Centre of European Commission
|
||||
Copyright: none
|
||||
License: public-domain-jrc
|
||||
This software has been developed at the Joint Research Centre of European Commission
|
||||
by officers in the course of their official duties. This software is not subject to copyright
|
||||
protection and is in the public domain. It is an experimental system. The Joint Research Centre
|
||||
of European Commission assumes no responsibility whatsoever for its use by other parties
|
||||
and makes no guarantees, expressed or implied, about its quality, reliability, or any other
|
||||
characteristic. We would appreciate acknowledgement if the software is used.
|
||||
Comment: This file is part of GLUEWIN.
|
||||
The program has been developed by M. Ratto, European Commission, Joint Research Centre,
|
||||
Institute for the Protection and Security of The Citizen, Technological and Economic Risk Management,
|
||||
Applied Statistics, as a deliverable of the IMPACT project
|
||||
(EC Fifth Framework Programme, SCA Project, IST-1999-11313, DG-INFSO).
|
||||
|
||||
Files: matlab/optimization/simpsa.m matlab/optimization/simpsaget.m matlab/optimization/simpsaset.m
|
||||
Copyright: 2005 Henning Schmidt, FCC, henning@fcc.chalmers.se
|
||||
|
@ -174,83 +177,24 @@ Copyright: 2005 Jos van der Geest <jos@jasen.nl>
|
|||
2013 Christophe Gouel
|
||||
2016 Dynare Team
|
||||
License: BSD-2-clause
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
.
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Files: matlab/lmmcp/lmmcp.m
|
||||
Copyright: 2005 Christian Kanzow and Stefania Petra
|
||||
2013 Christophe Gouel
|
||||
2014 Dynare Team
|
||||
License: permissive
|
||||
License: permissive-lmmcp
|
||||
Unlimited permission is granted to everyone to use, copy, modify or
|
||||
distribute this software.
|
||||
|
||||
Files: matlab/utilities/graphics/distinguishable_colors.m
|
||||
Copyright 2010-2011 by Timothy E. Holy
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
Copyright: 2010-2011 Timothy E. Holy
|
||||
License: BSD-2-clause
|
||||
|
||||
Files: matlab/utilities/graphics/colorspace.m
|
||||
Pascal Getreuer 2005-2010
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
Copyright: 2005-2010 Pascal Getreuer
|
||||
License: BSD-2-clause
|
||||
|
||||
Files: doc/dynare.texi doc/*.tex doc/*.svg doc/*.dia doc/*.pdf doc/*.bib
|
||||
Files: doc/dynare.texi doc/*.tex doc/*.svg doc/*.pdf doc/*.bib
|
||||
Copyright: 1996-2017 Dynare Team
|
||||
License: GFDL-NIV-1.3+
|
||||
|
||||
|
@ -299,7 +243,7 @@ Files: m4/ax_compare_version.m4
|
|||
Copyright: 2008 Tim Toolan <toolan@ele.uri.edu>
|
||||
License: permissive-autoconf
|
||||
|
||||
Files: m4/ax_latex_bibtex_test.m4 m4/ax_latex_class.m4 m4/ax_tex_test.m4
|
||||
Files: m4/ax_latex_class.m4 m4/ax_tex_test.m4
|
||||
Copyright: 2008 Boretti Mathieu <boretti@eig.unige.ch>
|
||||
2009 Dynare Team
|
||||
License: LGPL-2.1+
|
||||
|
@ -328,7 +272,7 @@ Copyright: 1996-2011 Daniel Waggoner and Tao Zha
|
|||
License: GPL-3+
|
||||
|
||||
Files: contrib/ms-sbvar/switch_dw/state_space/sbvar/dw_csminwel.c
|
||||
state_space/sbvar/dw_csminwel.h
|
||||
contrib/ms-sbvar/switch_dw/state_space/sbvar/dw_csminwel.h
|
||||
Copyright: 1996 Christopher Sims
|
||||
2003 Karibzhanov, Waggoner and Zha
|
||||
License: GPL-3+
|
||||
|
@ -409,7 +353,7 @@ License: GPL-3+
|
|||
|
||||
Files: contrib/dmm/randlib/*
|
||||
Copyright: none
|
||||
License: public-domain
|
||||
License: public-domain-dmm
|
||||
We place the Randlib code that we have written in the public domain.
|
||||
.
|
||||
NO WARRANTY
|
||||
|
@ -429,6 +373,29 @@ License: public-domain
|
|||
ITS ANALYSIS BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD
|
||||
PARTIES) THE PROGRAM.
|
||||
|
||||
License: BSD-2-clause
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
.
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
License: GFDL-NIV-1.3+
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||
|
@ -437,21 +404,6 @@ License: GFDL-NIV-1.3+
|
|||
.
|
||||
A copy of the license can be found at <http://www.gnu.org/licenses/fdl.txt>
|
||||
|
||||
License: GPL-2+
|
||||
This program 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 2 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 General Public License for more details.
|
||||
.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
License: GPL-2+ with Autoconf exception
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
# ===========================================================================
|
||||
# http://www.nongnu.org/autoconf-archive/ax_latex_test.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# OBSOLETE MACRO
|
||||
#
|
||||
# Deprecated because of licensing issues. The Lesser GPL imposes licensing
|
||||
# restrictions on the generated configure script unless it is augmented
|
||||
# with an Autoconf Exception clause.
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_LATEX_BIBTEX_TEST(FILEDATA,BIBDATA,VARIABLETOSET,[NOCLEAN])
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This macros creates a bib file called contest.bib with BIBDATA,
|
||||
# executes the latex application with FILEDATA as input, then runs
|
||||
# bibtex on the resulting aux file, and finally sets VARIABLETOSET
|
||||
# to yes or no depending on the result. If NOCLEAN is set, the folder
|
||||
# used for the test is not deleted after testing.
|
||||
#
|
||||
# The macro assumes that the variables PDFLATEX and BIBTEX are set.
|
||||
#
|
||||
# Adapted from the macro AX_LATEX_TEST by Sébastien Villemot.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Boretti Mathieu <boretti@eig.unige.ch>
|
||||
# Copyright (c) 2009 Dynare Team
|
||||
#
|
||||
# This library 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 2.1 of the License, or (at
|
||||
# your option) any later version.
|
||||
#
|
||||
# This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
AC_DEFUN([AX_LATEX_BIBTEX_TEST],[
|
||||
rm -rf conftest.dir/.acltx
|
||||
AS_MKDIR_P([conftest.dir/.acltx])
|
||||
cd conftest.dir/.acltx
|
||||
m4_ifval([$3],[$3="no"; export $3;])
|
||||
cat > conftest.tex << ACLEOF
|
||||
$1
|
||||
ACLEOF
|
||||
cat > conftest.bib << ACLEOF
|
||||
$2
|
||||
ACLEOF
|
||||
$PDFLATEX conftest 2>&1 1>output
|
||||
$BIBTEX conftest 2>&1 1>output2 m4_ifval([$3],[&& $3=yes])
|
||||
cd ..
|
||||
cd ..
|
||||
sed 's/^/| /' conftest.dir/.acltx/conftest.tex >&5
|
||||
echo "$as_me:$LINENO: executing $PDFLATEX conftest" >&5
|
||||
sed 's/^/| /' conftest.dir/.acltx/output >&5
|
||||
echo "$as_me:$LINENO: executing $BIBTEX conftest" >&5
|
||||
sed 's/^/| /' conftest.dir/.acltx/output2 >&5
|
||||
m4_ifval([$4],,[rm -rf conftest.dir/.acltx])
|
||||
])
|
|
@ -65,7 +65,7 @@ if nargin<6
|
|||
DynareOutput.exo_simul = zeros(sample_size,number_of_shocks);
|
||||
DynareOutput.exo_simul(:,positive_var_indx) = DynareOutput.bnlms.shocks;
|
||||
if isfield(DynareModel,'exo_histval') && ~ isempty(DynareModel.exo_histval)
|
||||
DynareOutput.exo_simul = [M_.exo_histval; DynareOutput.exo_simul];
|
||||
DynareOutput.exo_simul = [transpose(DynareModel.exo_histval); DynareOutput.exo_simul];
|
||||
else
|
||||
DynareOutput.exo_simul = [zeros(1,number_of_shocks); DynareOutput.exo_simul];
|
||||
end
|
||||
|
|
|
@ -103,6 +103,9 @@ if ismember('simulate', varargin) % Prior simulations (BK).
|
|||
disp(['mjdgges crash share = ' num2str(results.dll.problem_share)])
|
||||
disp(['Steady state problem share = ' num2str(results.ss.problem_share)])
|
||||
disp(['Complex steady state share = ' num2str(results.ss.complex_share)])
|
||||
if options_.loglinear
|
||||
disp(['Nonpositive steady state share = ' num2str(results.ss.nonpositive_share)])
|
||||
end
|
||||
disp(['Analytical steady state problem share = ' num2str(results.ass.problem_share)])
|
||||
skipline(2)
|
||||
donesomething = true;
|
||||
|
|
|
@ -98,7 +98,9 @@ instr_nbr=endo_nbr-eq_nbr;
|
|||
if instr_nbr==0
|
||||
error('discretionary_policy:: There are no available instruments, because the model has as many equations as variables.')
|
||||
end
|
||||
if size(Instruments,1)~= instr_nbr
|
||||
if size(Instruments,1)< instr_nbr
|
||||
error('discretionary_policy:: There are fewer declared instruments than omitted equations.')
|
||||
elseif size(Instruments,1)> instr_nbr
|
||||
error('discretionary_policy:: There are more declared instruments than omitted equations.')
|
||||
end
|
||||
|
||||
|
|
|
@ -27,6 +27,11 @@ function disp_dr(dr,order,var_list)
|
|||
|
||||
global M_ options_
|
||||
|
||||
if M_.hessian_eq_zero && order~=1
|
||||
order = 1;
|
||||
warning('disp_dr: using order = 1 because Hessian is equal to zero');
|
||||
end
|
||||
|
||||
nx =size(dr.ghx,2);
|
||||
nu =size(dr.ghu,2);
|
||||
if options_.block
|
||||
|
|
|
@ -44,7 +44,7 @@ m(non_stationary_vars) = NaN;
|
|||
i1 = find(abs(diag(oo_.gamma_y{1})) > 1e-12);
|
||||
s2 = diag(oo_.gamma_y{1});
|
||||
sd = sqrt(s2);
|
||||
if options_.order == 2
|
||||
if options_.order == 2 && ~M_.hessian_eq_zero
|
||||
m = m+oo_.gamma_y{options_.ar+3};
|
||||
end
|
||||
|
||||
|
@ -123,7 +123,8 @@ if length(i1) == 0
|
|||
end
|
||||
|
||||
if options_.nocorr == 0 && size(stationary_vars, 1) > 0
|
||||
corr = oo_.gamma_y{1}(i1,i1)./(sd(i1)*sd(i1)');
|
||||
corr=NaN(size(oo_.gamma_y{1}));
|
||||
corr(i1,i1) = oo_.gamma_y{1}(i1,i1)./(sd(i1)*sd(i1)');
|
||||
if options_.contemporaneous_correlation
|
||||
oo_.contemporaneous_correlation = corr;
|
||||
end
|
||||
|
@ -138,12 +139,12 @@ if options_.nocorr == 0 && size(stationary_vars, 1) > 0
|
|||
labels = deblank(M_.endo_names(ivar(i1),:));
|
||||
headers = char('Variables',labels);
|
||||
lh = size(labels,2)+2;
|
||||
dyntable(options_,title,headers,labels,corr,lh,8,4);
|
||||
dyntable(options_,title,headers,labels,corr(i1,i1),lh,8,4);
|
||||
if options_.TeX
|
||||
labels = deblank(M_.endo_names_tex(ivar(i1),:));
|
||||
headers=char('Variables',labels);
|
||||
lh = size(labels,2)+2;
|
||||
dyn_latex_table(M_,options_,title,'th_corr_matrix',headers,labels,corr,lh,8,4);
|
||||
dyn_latex_table(M_,options_,title,'th_corr_matrix',headers,labels,corr(i1,i1),lh,8,4);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -195,6 +195,11 @@ if ismember('onlymacro', varargin)
|
|||
return
|
||||
end
|
||||
|
||||
if ismember('onlyjson', varargin)
|
||||
disp('Preprocesser stopped after preprocessing step because of ''onlyjson'' option.');
|
||||
return;
|
||||
end
|
||||
|
||||
% post-dynare-prerocessor-hook
|
||||
if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') && exist([fname(1:end-4) filesep 'hooks/postprocessing.m'],'file')
|
||||
run([fname(1:end-4) filesep 'hooks/postprocessing'])
|
||||
|
|
|
@ -50,6 +50,7 @@ function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,
|
|||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
hh = [];
|
||||
xparam1 = [];
|
||||
|
||||
if isempty(gsa_flag)
|
||||
gsa_flag = 0;
|
||||
|
@ -311,6 +312,10 @@ if options_.use_calibration_initialization %set calibration as starting values
|
|||
end
|
||||
end
|
||||
|
||||
if ~isempty(bayestopt_) && all(bayestopt_.pshape==0) && any(isnan(xparam1))
|
||||
error('ML estimation requires all estimated parameters to be initialized, either in an estimated_params or estimated_params_init-block ')
|
||||
end
|
||||
|
||||
if ~isempty(estim_params_) && ~(all(strcmp(fieldnames(estim_params_),'full_calibration_detected')) || (isfield(estim_params_,'nvx') && sum(estim_params_.nvx+estim_params_.nvn+estim_params_.ncx+estim_params_.ncn+estim_params_.np)==0))
|
||||
if ~isempty(bayestopt_) && any(bayestopt_.pshape > 0)
|
||||
% Plot prior densities.
|
||||
|
@ -556,7 +561,7 @@ end
|
|||
[oo_.steady_state, params,info] = evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag);
|
||||
|
||||
if info(1)
|
||||
fprintf('\ndynare_estimation_init:: The steady state at the initial parameters cannot be computed.')
|
||||
fprintf('\ndynare_estimation_init:: The steady state at the initial parameters cannot be computed.\n')
|
||||
print_info(info, 0, options_);
|
||||
end
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ elseif (options.bytecode == 0 && options.block == 0)
|
|||
disp(['STEADY: numerical initial values or parameters incompatible with the following' ...
|
||||
' equations'])
|
||||
disp(ii')
|
||||
disp('Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.\n')
|
||||
disp('Check whether your model is truly linear. Put "resid(1);" before "steady;" to see the problematic equations.')
|
||||
elseif isempty(ii) && max(abs(fvec)) > 1e-12
|
||||
ys = ys_init-jacob\fvec;
|
||||
resid = evaluate_static_model(ys,exo_ss,params,M,options);
|
||||
|
|
|
@ -725,7 +725,7 @@ options_.discretionary_tol = 1e-7;
|
|||
% Shock decomposition
|
||||
options_.parameter_set = [];
|
||||
options_.use_shock_groups = '';
|
||||
options_.colormap = '';
|
||||
options_.shock_decomp.colormap = '';
|
||||
options_.shock_decomp.init_state = 0;
|
||||
|
||||
% Shock decomposition realtime
|
||||
|
|
13
matlab/irf.m
13
matlab/irf.m
|
@ -44,11 +44,16 @@ else
|
|||
end
|
||||
y = 0;
|
||||
|
||||
if iorder == 1
|
||||
local_order = iorder;
|
||||
if M_.hessian_eq_zero && local_order~=1
|
||||
local_order = 1;
|
||||
end
|
||||
|
||||
if local_order == 1
|
||||
y1 = repmat(dr.ys,1,long);
|
||||
ex2 = zeros(long,M_.exo_nbr);
|
||||
ex2(1,:) = e1';
|
||||
y2 = simult_(temps,dr,ex2,iorder);
|
||||
y2 = simult_(temps,dr,ex2,local_order);
|
||||
y = y2(:,M_.maximum_lag+1:end)-y1;
|
||||
else
|
||||
% eliminate shocks with 0 variance
|
||||
|
@ -61,8 +66,8 @@ else
|
|||
ex1(:,i_exo_var) = randn(long+drop,nxs)*chol_S;
|
||||
ex2 = ex1;
|
||||
ex2(drop+1,:) = ex2(drop+1,:)+e1';
|
||||
y1 = simult_(temps,dr,ex1,iorder);
|
||||
y2 = simult_(temps,dr,ex2,iorder);
|
||||
y1 = simult_(temps,dr,ex1,local_order);
|
||||
y2 = simult_(temps,dr,ex2,local_order);
|
||||
y = y+(y2(:,M_.maximum_lag+drop+1:end)-y1(:,M_.maximum_lag+drop+1:end));
|
||||
end
|
||||
y=y/replic;
|
||||
|
|
|
@ -41,7 +41,7 @@ function optimal_bandwidth = mh_optimal_bandwidth(data,number_of_draws,bandwidth
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
%% Kernel specifications.
|
||||
% Kernel specifications.
|
||||
if strcmpi(kernel_function,'gaussian')
|
||||
% Kernel definition
|
||||
k = @(x)inv(sqrt(2*pi))*exp(-0.5*x.^2);
|
||||
|
@ -89,15 +89,17 @@ else
|
|||
end
|
||||
|
||||
|
||||
%% Get the Skold and Roberts' correction.
|
||||
% Get the Skold and Roberts' correction.
|
||||
if bandwidth==0 || bandwidth==-1
|
||||
correction = correction_for_repeated_draws(data,number_of_draws);
|
||||
else
|
||||
correction = 0;
|
||||
end
|
||||
%% Compute the standard deviation of the draws.
|
||||
|
||||
% Compute the standard deviation of the draws.
|
||||
sigma = std(data);
|
||||
%% Optimal bandwidth parameter.
|
||||
|
||||
% Optimal bandwidth parameter.
|
||||
if bandwidth == 0 % Rule of thumb bandwidth parameter (Silverman [1986].
|
||||
h = 2*sigma*(sqrt(pi)*mu02/(12*(mu21^2)*number_of_draws))^(1/5);
|
||||
h = h*correction^(1/5);
|
||||
|
@ -132,10 +134,10 @@ elseif bandwidth == -2 % Bump killing... I compute local bandwith parameters
|
|||
error(['I can''t compute the optimal bandwidth with this kernel...' ...
|
||||
'Try the gaussian, triweight or cosinus kernels.']);
|
||||
end
|
||||
T = zeros(n,1);
|
||||
for i=1:n
|
||||
T = zeros(number_of_draws, 1);
|
||||
for i=1:number_of_draws
|
||||
j = i;
|
||||
while j<= n && (data(j,1)-data(i,1))<2*eps
|
||||
while j<=number_of_draws && (data(j,1)-data(i,1))<2*eps
|
||||
j = j+1;
|
||||
end
|
||||
T(i) = (j-i);
|
||||
|
@ -143,13 +145,13 @@ elseif bandwidth == -2 % Bump killing... I compute local bandwith parameters
|
|||
end
|
||||
correction = correction/number_of_draws;
|
||||
Itilda4 = 8*7*6*5/(((2*sigma)^9)*sqrt(pi));
|
||||
g3 = abs(2*correction*k6(0)/(mu21*Itilda4*correction))^(1/9);
|
||||
g3 = abs(2*correction*k6(0)/(mu21*Itilda4*number_of_draws))^(1/9);
|
||||
Ihat3 = 0;
|
||||
for i=1:number_of_draws
|
||||
Ihat3 = Ihat3 + sum(k6((data(i,1)-data)/g3));
|
||||
end
|
||||
Ihat3 = -Ihat3/((n^2)*g3^7);
|
||||
g2 = abs(2*correction*k4(0)/(mu21*Ihat3*n))^(1/7);
|
||||
g2 = abs(2*correction*k4(0)/(mu21*Ihat3*number_of_draws))^(1/7);
|
||||
Ihat2 = 0;
|
||||
for i=1:number_of_draws
|
||||
Ihat2 = Ihat2 + sum(k4((data(i)-data)/g2));
|
||||
|
|
|
@ -31,7 +31,6 @@ function [z, steady_state] = plot_shock_decomposition(M_,oo_,options_,varlist)
|
|||
options_.nodisplay = options_.plot_shock_decomp.nodisplay;
|
||||
options_.graph_format = options_.plot_shock_decomp.graph_format;
|
||||
options_.use_shock_groups = options_.plot_shock_decomp.use_shock_groups;
|
||||
options_.colormap = options_.plot_shock_decomp.colormap;
|
||||
|
||||
% indices of endogenous variables
|
||||
if size(varlist,1) == 0
|
||||
|
|
|
@ -25,6 +25,8 @@ PriorNames = strvcat(PriorNames,'Gaussian');
|
|||
PriorNames = strvcat(PriorNames,'Inverted Gamma');
|
||||
PriorNames = strvcat(PriorNames,'Uniform');
|
||||
PriorNames = strvcat(PriorNames,'Inverted Gamma -- 2');
|
||||
PriorNames = strvcat(PriorNames,'Dirichlet');
|
||||
PriorNames = strvcat(PriorNames,'Weibull');
|
||||
|
||||
n = size(BayesInfo.name,1); % Numbe rof estimated parameters.
|
||||
|
||||
|
@ -71,7 +73,7 @@ for i=1:size(BayesInfo.name,1)
|
|||
if ~isinf(ub(i))
|
||||
UpperBound=min(UpperBound,ub(i));
|
||||
end
|
||||
case { 2 , 4 , 6 }
|
||||
case { 2 , 4 , 6 , 8}
|
||||
LowerBound = BayesInfo.p3(i);
|
||||
if ~isinf(lb(i))
|
||||
LowerBound=max(LowerBound,lb(i));
|
||||
|
|
|
@ -49,6 +49,7 @@ count_complex_steadystate = 0;
|
|||
count_nan_steadystate = 0;
|
||||
count_nan_params = 0;
|
||||
count_complex_params = 0;
|
||||
count_nonpositive_steadystate = 0;
|
||||
count_unknown_problem = 0;
|
||||
NumberOfSimulations = options_.prior_mc;
|
||||
NumberOfParameters = length(bayestopt_.p1);
|
||||
|
@ -135,6 +136,8 @@ while iteration < NumberOfSimulations
|
|||
count_complex_params = count_complex_params + 1 ;
|
||||
case 24
|
||||
count_nan_params = count_nan_params + 1 ;
|
||||
case 26
|
||||
count_nonpositive_steadystate = count_nonpositive_steadystate + 1;
|
||||
otherwise
|
||||
count_unknown_problem = count_unknown_problem + 1 ;
|
||||
end
|
||||
|
@ -162,6 +165,7 @@ results.dll.problem_share = count_dll_problem/loop_indx;
|
|||
results.ss.problem_share = count_no_steadystate/loop_indx;
|
||||
results.ss.complex_share = count_complex_steadystate/loop_indx;
|
||||
results.ass.problem_share = count_steadystate_file_exit/loop_indx;
|
||||
results.ss.nonpositive_share = count_nonpositive_steadystate/loop_indx;
|
||||
results.jacobian.problem_share = count_complex_jacobian/loop_indx;
|
||||
results.garbage_share = ...
|
||||
results.bk.indeterminacy_share + ...
|
||||
|
@ -170,6 +174,8 @@ results.garbage_share = ...
|
|||
results.dll.problem_share + ...
|
||||
results.ss.problem_share + ...
|
||||
results.ass.problem_share + ...
|
||||
results.ss.complex_share + ...
|
||||
results.ss.nonpositive_share + ...
|
||||
results.jacobian.problem_share + ...
|
||||
count_unknown_problem/loop_indx ;
|
||||
results.prior.mean = sampled_prior_expectation;
|
||||
|
|
|
@ -67,6 +67,11 @@ if options_.order >= 3
|
|||
error('Theoretical moments not implemented above 2nd order')
|
||||
end
|
||||
|
||||
local_order = options_.order;
|
||||
if M_.hessian_eq_zero && local_order~=1
|
||||
local_order = 1;
|
||||
end
|
||||
|
||||
endo_nbr = M_.endo_nbr;
|
||||
exo_names_orig_ord = M_.exo_names_orig_ord;
|
||||
if isoctave
|
||||
|
@ -128,7 +133,7 @@ end
|
|||
% Compute stationary variables (before HP filtering),
|
||||
% and compute 2nd order mean correction on stationary variables (in case of
|
||||
% HP filtering, this mean correction is computed *before* filtering)
|
||||
if options_.order == 2 || options_.hp_filter == 0
|
||||
if local_order == 2 || options_.hp_filter == 0
|
||||
[vx, u] = lyapunov_symm(A,B*M_.Sigma_e*B',options_.lyapunov_fixed_point_tol,options_.qz_criterium,options_.lyapunov_complex_threshold,[],options_.debug);
|
||||
if options_.block == 0
|
||||
iky = inv_order_var(ivar);
|
||||
|
@ -143,7 +148,7 @@ if options_.order == 2 || options_.hp_filter == 0
|
|||
end
|
||||
aa = ghx(iky,:);
|
||||
bb = ghu(iky,:);
|
||||
if options_.order == 2 % mean correction for 2nd order
|
||||
if local_order == 2 % mean correction for 2nd order
|
||||
if ~isempty(ikx)
|
||||
Ex = (dr.ghs2(ikx)+dr.ghxx(ikx,:)*vx(:)+dr.ghuu(ikx,:)*M_.Sigma_e(:))/2;
|
||||
Ex = (eye(n0)-AS(ikx,:))\Ex;
|
||||
|
|
|
@ -2237,7 +2237,7 @@ public:
|
|||
inline
|
||||
test_mxMalloc(void *z, int line, string file, string func, int amount)
|
||||
{
|
||||
if (!z && (amount > 0))
|
||||
if (z == NULL && (amount > 0))
|
||||
{
|
||||
ostringstream tmp;
|
||||
tmp << " mxMalloc: out of memory " << amount << " bytes required at line " << line << " in function " << func << " (file " << file;
|
||||
|
|
|
@ -1539,14 +1539,14 @@ Evaluate::solve_simple_one_periods()
|
|||
Per_y_ = it_*y_size;
|
||||
ya = y[Block_Contain[0].Variable + Per_y_];
|
||||
compute_block_time(0, false, false);
|
||||
if (!finite(res1))
|
||||
if (!isfinite(res1))
|
||||
{
|
||||
res1 = NAN;
|
||||
while ((isinf(res1) || isnan(res1)) && (slowc > 1e-9))
|
||||
{
|
||||
it_code = start_code;
|
||||
compute_block_time(0, false, false);
|
||||
if (!finite(res1))
|
||||
if (!isfinite(res1))
|
||||
{
|
||||
slowc /= 1.5;
|
||||
mexPrintf("Reducing the path length in Newton step slowc=%f\n", slowc);
|
||||
|
|
|
@ -663,9 +663,9 @@ dynSparseMatrix::Simple_Init(int Size, map<pair<pair<int, int>, int>, int> &IM,
|
|||
FNZE_C = (NonZeroElem **) mxMalloc(i);
|
||||
test_mxMalloc(FNZE_C, __LINE__, __FILE__, __func__, i);
|
||||
NonZeroElem **temp_NZE_R = (NonZeroElem **) mxMalloc(i);
|
||||
test_mxMalloc(*temp_NZE_R, __LINE__, __FILE__, __func__, i);
|
||||
test_mxMalloc(temp_NZE_R, __LINE__, __FILE__, __func__, i);
|
||||
NonZeroElem **temp_NZE_C = (NonZeroElem **) mxMalloc(i);
|
||||
test_mxMalloc(*temp_NZE_C, __LINE__, __FILE__, __func__, i);
|
||||
test_mxMalloc(temp_NZE_C, __LINE__, __FILE__, __func__, i);
|
||||
i = Size*sizeof(int);
|
||||
NbNZRow = (int *) mxMalloc(i);
|
||||
test_mxMalloc(NbNZRow, __LINE__, __FILE__, __func__, i);
|
||||
|
@ -1900,9 +1900,9 @@ dynSparseMatrix::Init_GE(int periods, int y_kmin, int y_kmax, int Size, map<pair
|
|||
FNZE_C = (NonZeroElem **) mxMalloc(i);
|
||||
test_mxMalloc(FNZE_C, __LINE__, __FILE__, __func__, i);
|
||||
NonZeroElem **temp_NZE_R = (NonZeroElem **) mxMalloc(i);
|
||||
test_mxMalloc(*temp_NZE_R, __LINE__, __FILE__, __func__, i);
|
||||
test_mxMalloc(temp_NZE_R, __LINE__, __FILE__, __func__, i);
|
||||
NonZeroElem **temp_NZE_C = (NonZeroElem **) mxMalloc(i);
|
||||
test_mxMalloc(*temp_NZE_C, __LINE__, __FILE__, __func__, i);
|
||||
test_mxMalloc(temp_NZE_C, __LINE__, __FILE__, __func__, i);
|
||||
i = (periods+y_kmax+1)*Size*sizeof(int);
|
||||
NbNZRow = (int *) mxMalloc(i);
|
||||
test_mxMalloc(NbNZRow, __LINE__, __FILE__, __func__, i);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -36,6 +36,7 @@ public:
|
|||
SteadyStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class CheckStatement : public Statement
|
||||
|
@ -46,6 +47,7 @@ public:
|
|||
CheckStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SimulStatement : public Statement
|
||||
|
@ -56,6 +58,7 @@ public:
|
|||
SimulStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class PerfectForesightSetupStatement : public Statement
|
||||
|
@ -65,6 +68,7 @@ private:
|
|||
public:
|
||||
PerfectForesightSetupStatement(const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class PerfectForesightSolverStatement : public Statement
|
||||
|
@ -75,6 +79,7 @@ public:
|
|||
PerfectForesightSolverStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class PriorPosteriorFunctionStatement : public Statement
|
||||
|
@ -86,6 +91,7 @@ public:
|
|||
PriorPosteriorFunctionStatement(const bool prior_func_arg, const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class ModelInfoStatement : public Statement
|
||||
|
@ -96,6 +102,7 @@ public:
|
|||
ModelInfoStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class StochSimulStatement : public Statement
|
||||
|
@ -108,6 +115,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class VarModelStatement : public Statement
|
||||
|
@ -172,6 +180,7 @@ public:
|
|||
ForecastStatement(const SymbolList &symbol_list_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class RamseyModelStatement : public Statement
|
||||
|
@ -184,6 +193,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class RamseyConstraintsStatement : public Statement
|
||||
|
@ -197,11 +207,13 @@ public:
|
|||
};
|
||||
typedef vector<Constraint> constraints_t;
|
||||
private:
|
||||
const SymbolTable &symbol_table;
|
||||
const constraints_t constraints;
|
||||
public:
|
||||
RamseyConstraintsStatement(const constraints_t &constraints_arg);
|
||||
RamseyConstraintsStatement(const SymbolTable &symbol_table_arg, const constraints_t &constraints_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
// virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table);
|
||||
};
|
||||
|
||||
|
@ -218,6 +230,7 @@ public:
|
|||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
void checkRamseyPolicyList();
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class DiscretionaryPolicyStatement : public Statement
|
||||
|
@ -230,6 +243,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class RplotStatement : public Statement
|
||||
|
@ -239,6 +253,7 @@ private:
|
|||
public:
|
||||
RplotStatement(const SymbolList &symbol_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class UnitRootVarsStatement : public Statement
|
||||
|
@ -246,6 +261,7 @@ class UnitRootVarsStatement : public Statement
|
|||
public:
|
||||
UnitRootVarsStatement(void);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class PeriodsStatement : public Statement
|
||||
|
@ -255,6 +271,7 @@ private:
|
|||
public:
|
||||
PeriodsStatement(int periods_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class DsampleStatement : public Statement
|
||||
|
@ -265,6 +282,7 @@ public:
|
|||
DsampleStatement(int val1_arg);
|
||||
DsampleStatement(int val1_arg, int val2_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class EstimationStatement : public Statement
|
||||
|
@ -277,6 +295,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class DynareSensitivityStatement : public Statement
|
||||
|
@ -287,6 +306,7 @@ public:
|
|||
DynareSensitivityStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class ObservationTrendsStatement : public Statement
|
||||
|
@ -300,6 +320,7 @@ public:
|
|||
ObservationTrendsStatement(const trend_elements_t &trend_elements_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class OsrParamsStatement : public Statement
|
||||
|
@ -311,6 +332,7 @@ public:
|
|||
OsrParamsStatement(const SymbolList &symbol_list_arg, const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class OsrStatement : public Statement
|
||||
|
@ -323,6 +345,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
//! Temporary structure used when parsing estimation_params* statements
|
||||
|
@ -349,6 +372,7 @@ public:
|
|||
OsrParamsBoundsStatement(const vector<OsrParams> &osr_params_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class DynaTypeStatement : public Statement
|
||||
|
@ -360,6 +384,7 @@ public:
|
|||
DynaTypeStatement(const SymbolList &symbol_list_arg,
|
||||
const string &filename_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class DynaSaveStatement : public Statement
|
||||
|
@ -371,6 +396,7 @@ public:
|
|||
DynaSaveStatement(const SymbolList &symbol_list_arg,
|
||||
const string &filename_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class ModelComparisonStatement : public Statement
|
||||
|
@ -384,6 +410,7 @@ public:
|
|||
ModelComparisonStatement(const filename_list_t &filename_list_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
//! Temporary structure used when parsing estimation_params* statements
|
||||
|
@ -423,6 +450,7 @@ public:
|
|||
const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class EstimatedParamsInitStatement : public Statement
|
||||
|
@ -437,6 +465,7 @@ public:
|
|||
const bool use_calibration_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class EstimatedParamsBoundsStatement : public Statement
|
||||
|
@ -448,6 +477,7 @@ public:
|
|||
EstimatedParamsBoundsStatement(const vector<EstimationParams> &estim_params_list_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class OptimWeightsStatement : public Statement
|
||||
|
@ -465,6 +495,7 @@ public:
|
|||
const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
/*! \todo Make model_tree a member instead of a pointer */
|
||||
|
@ -472,6 +503,7 @@ class PlannerObjectiveStatement : public Statement
|
|||
{
|
||||
private:
|
||||
StaticModel *model_tree;
|
||||
bool computing_pass_called;
|
||||
public:
|
||||
//! Constructor
|
||||
/*! \param model_tree_arg the model tree used to store the objective function.
|
||||
|
@ -485,6 +517,7 @@ public:
|
|||
/*! \todo allow for the possibility of disabling temporary terms */
|
||||
virtual void computingPass();
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
//! Return the Planner Objective
|
||||
StaticModel *getPlannerObjective() const;
|
||||
};
|
||||
|
@ -498,6 +531,7 @@ public:
|
|||
BVARDensityStatement(int maxnlags_arg, const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class BVARForecastStatement : public Statement
|
||||
|
@ -509,6 +543,7 @@ public:
|
|||
BVARForecastStatement(int nlags_arg, const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SBVARStatement : public Statement
|
||||
|
@ -519,6 +554,7 @@ public:
|
|||
SBVARStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MSSBVAREstimationStatement : public Statement
|
||||
|
@ -529,6 +565,7 @@ public:
|
|||
MSSBVAREstimationStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MSSBVARSimulationStatement : public Statement
|
||||
|
@ -539,6 +576,7 @@ public:
|
|||
MSSBVARSimulationStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MSSBVARComputeMDDStatement : public Statement
|
||||
|
@ -549,6 +587,7 @@ public:
|
|||
MSSBVARComputeMDDStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MSSBVARComputeProbabilitiesStatement : public Statement
|
||||
|
@ -559,6 +598,7 @@ public:
|
|||
MSSBVARComputeProbabilitiesStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MSSBVARIrfStatement : public Statement
|
||||
|
@ -571,6 +611,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MSSBVARForecastStatement : public Statement
|
||||
|
@ -581,6 +622,7 @@ public:
|
|||
MSSBVARForecastStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MSSBVARVarianceDecompositionStatement : public Statement
|
||||
|
@ -591,6 +633,7 @@ public:
|
|||
MSSBVARVarianceDecompositionStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class IdentificationStatement : public Statement
|
||||
|
@ -601,6 +644,7 @@ public:
|
|||
IdentificationStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class WriteLatexDynamicModelStatement : public Statement
|
||||
|
@ -611,6 +655,7 @@ private:
|
|||
public:
|
||||
WriteLatexDynamicModelStatement(const DynamicModel &dynamic_model_arg, bool write_equation_tags_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class WriteLatexStaticModelStatement : public Statement
|
||||
|
@ -620,6 +665,7 @@ private:
|
|||
public:
|
||||
WriteLatexStaticModelStatement(const StaticModel &static_model_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class WriteLatexOriginalModelStatement : public Statement
|
||||
|
@ -629,6 +675,7 @@ private:
|
|||
public:
|
||||
WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class ShockDecompositionStatement : public Statement
|
||||
|
@ -640,6 +687,7 @@ public:
|
|||
ShockDecompositionStatement(const SymbolList &symbol_list_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class RealtimeShockDecompositionStatement : public Statement
|
||||
|
@ -682,6 +730,7 @@ private:
|
|||
public:
|
||||
ConditionalForecastStatement(const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class PlotConditionalForecastStatement : public Statement
|
||||
|
@ -693,6 +742,7 @@ private:
|
|||
public:
|
||||
PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class CalibSmootherStatement : public Statement
|
||||
|
@ -705,6 +755,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class ExtendedPathStatement : public Statement
|
||||
|
@ -715,6 +766,7 @@ public:
|
|||
ExtendedPathStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SvarIdentificationStatement : public Statement
|
||||
|
@ -746,6 +798,7 @@ public:
|
|||
const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MarkovSwitchingStatement : public Statement
|
||||
|
@ -758,6 +811,7 @@ public:
|
|||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SvarStatement : public Statement
|
||||
|
@ -768,6 +822,7 @@ public:
|
|||
SvarStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SvarGlobalIdentificationCheckStatement : public Statement
|
||||
|
@ -775,6 +830,7 @@ class SvarGlobalIdentificationCheckStatement : public Statement
|
|||
public:
|
||||
SvarGlobalIdentificationCheckStatement();
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SetTimeStatement : public Statement
|
||||
|
@ -784,6 +840,7 @@ private:
|
|||
public:
|
||||
SetTimeStatement(const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class EstimationDataStatement : public Statement
|
||||
|
@ -794,6 +851,7 @@ public:
|
|||
EstimationDataStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SubsamplesStatement : public Statement
|
||||
|
@ -813,6 +871,7 @@ public:
|
|||
const SymbolTable &symbol_table_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SubsamplesEqualStatement : public Statement
|
||||
|
@ -830,6 +889,7 @@ public:
|
|||
const string &from_name2_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class JointPriorStatement : public Statement
|
||||
|
@ -845,6 +905,7 @@ public:
|
|||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
void writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class BasicPriorStatement : public Statement
|
||||
|
@ -877,6 +938,8 @@ protected:
|
|||
void writeCShape(ostream &output) const;
|
||||
void writeCVarianceOption(ostream &output) const;
|
||||
void writeCDomain(ostream &output) const;
|
||||
void writeJsonShape(ostream &output) const;
|
||||
void writeJsonPriorOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class PriorStatement : public BasicPriorStatement
|
||||
|
@ -889,6 +952,7 @@ public:
|
|||
const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class StdPriorStatement : public BasicPriorStatement
|
||||
|
@ -904,6 +968,7 @@ public:
|
|||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class CorrPriorStatement : public BasicPriorStatement
|
||||
|
@ -922,6 +987,7 @@ public:
|
|||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class PriorEqualStatement : public Statement
|
||||
|
@ -949,6 +1015,7 @@ public:
|
|||
void get_base_name(const SymbolType symb_type, string &lhs_field) const;
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class BasicOptionsStatement : public Statement
|
||||
|
@ -972,6 +1039,7 @@ protected:
|
|||
void writeOptionsIndex(ostream &output, const string &lhs_field) const;
|
||||
void writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const;
|
||||
void writeCOutputHelper(ostream &output, const string &field) const;
|
||||
void writeJsonOptionsOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class OptionsStatement : public BasicOptionsStatement
|
||||
|
@ -980,6 +1048,7 @@ public:
|
|||
OptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class StdOptionsStatement : public BasicOptionsStatement
|
||||
|
@ -993,6 +1062,7 @@ public:
|
|||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class CorrOptionsStatement : public BasicOptionsStatement
|
||||
|
@ -1008,6 +1078,7 @@ public:
|
|||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class OptionsEqualStatement : public Statement
|
||||
|
@ -1035,6 +1106,7 @@ public:
|
|||
void get_base_name(const SymbolType symb_type, string &lhs_field) const;
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class ModelDiagnosticsStatement : public Statement
|
||||
|
@ -1042,6 +1114,7 @@ class ModelDiagnosticsStatement : public Statement
|
|||
public:
|
||||
ModelDiagnosticsStatement();
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class Smoother2histvalStatement : public Statement
|
||||
|
@ -1051,6 +1124,7 @@ private:
|
|||
public:
|
||||
Smoother2histvalStatement(const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5544,3 +5544,470 @@ DynamicModel::writeCCOutput(ostream &output, const string &basename, bool block_
|
|||
output << "NNZDerivatives.push_back(-1);" << endl
|
||||
<< "NNZDerivatives.push_back(-1);" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
writeJsonModelEquations(output, false);
|
||||
output << ", ";
|
||||
writeJsonXrefs(output);
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeJsonXrefs(ostream &output) const
|
||||
{
|
||||
output << "\"xrefs\": {"
|
||||
<< "\"parameters\": [";
|
||||
for (map<pair<int, int>, set<int> >::const_iterator it = xref_param.begin();
|
||||
it != xref_param.end(); it++)
|
||||
{
|
||||
if (it != xref_param.begin())
|
||||
output << ", ";
|
||||
output << "{\"parameter\": \"" << symbol_table.getName(it->first.first) << "\""
|
||||
<< ", \"equations\": [";
|
||||
for (set<int>::const_iterator it1 = it->second.begin();
|
||||
it1 != it->second.end(); it1++)
|
||||
{
|
||||
if (it1 != it->second.begin())
|
||||
output << ", ";
|
||||
output << *it1 + 1;
|
||||
}
|
||||
output << "]}";
|
||||
}
|
||||
output << "]"
|
||||
<< ", \"endogenous\": [";
|
||||
for (map<pair<int, int>, set<int> >::const_iterator it = xref_endo.begin();
|
||||
it != xref_endo.end(); it++)
|
||||
{
|
||||
if (it != xref_endo.begin())
|
||||
output << ", ";
|
||||
output << "{\"endogenous\": \"" << symbol_table.getName(it->first.first) << "\""
|
||||
<< ", \"shift\": " << it->first.second
|
||||
<< ", \"equations\": [";
|
||||
for (set<int>::const_iterator it1 = it->second.begin();
|
||||
it1 != it->second.end(); it1++)
|
||||
{
|
||||
if (it1 != it->second.begin())
|
||||
output << ", ";
|
||||
output << *it1 + 1;
|
||||
}
|
||||
output << "]}";
|
||||
}
|
||||
output << "]"
|
||||
<< ", \"exogenous\": [";
|
||||
for (map<pair<int, int>, set<int> >::const_iterator it = xref_exo.begin();
|
||||
it != xref_exo.end(); it++)
|
||||
{
|
||||
if (it != xref_exo.begin())
|
||||
output << ", ";
|
||||
output << "{\"exogenous\": \"" << symbol_table.getName(it->first.first) << "\""
|
||||
<< ", \"shift\": " << it->first.second
|
||||
<< ", \"equations\": [";
|
||||
for (set<int>::const_iterator it1 = it->second.begin();
|
||||
it1 != it->second.end(); it1++)
|
||||
{
|
||||
if (it1 != it->second.begin())
|
||||
output << ", ";
|
||||
output << *it1 + 1;
|
||||
}
|
||||
output << "]}";
|
||||
}
|
||||
output << "]"
|
||||
<< ", \"exogenous_deterministic\": [";
|
||||
for (map<pair<int, int>, set<int> >::const_iterator it = xref_exo_det.begin();
|
||||
it != xref_exo_det.end(); it++)
|
||||
{
|
||||
if (it != xref_exo_det.begin())
|
||||
output << ", ";
|
||||
output << "{\"exogenous_det\": \"" << symbol_table.getName(it->first.first) << "\""
|
||||
<< ", \"shift\": " << it->first.second
|
||||
<< ", \"equations\": [";
|
||||
for (set<int>::const_iterator it1 = it->second.begin();
|
||||
it1 != it->second.end(); it1++)
|
||||
{
|
||||
if (it1 != it->second.begin())
|
||||
output << ", ";
|
||||
output << *it1 + 1;
|
||||
}
|
||||
output << "]}";
|
||||
}
|
||||
output << "]}" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) const
|
||||
{
|
||||
ostringstream model_local_vars_output; // Used for storing model local vars
|
||||
ostringstream model_output; // Used for storing model temp vars and equations
|
||||
ostringstream jacobian_output; // Used for storing jacobian equations
|
||||
ostringstream hessian_output; // Used for storing Hessian equations
|
||||
ostringstream third_derivatives_output; // Used for storing third order derivatives equations
|
||||
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
temporary_terms_t temp_term_empty;
|
||||
temporary_terms_t temp_term_union = temporary_terms_res;
|
||||
temporary_terms_t temp_term_union_m_1;
|
||||
|
||||
string concat = "";
|
||||
int hessianColsNbr = dynJacobianColsNbr * dynJacobianColsNbr;
|
||||
|
||||
writeJsonModelLocalVariables(model_local_vars_output, tef_terms);
|
||||
|
||||
writeJsonTemporaryTerms(temporary_terms_res, temp_term_union_m_1, model_output, tef_terms, concat);
|
||||
model_output << ", ";
|
||||
writeJsonModelEquations(model_output, true);
|
||||
|
||||
// Writing Jacobian
|
||||
temp_term_union_m_1 = temp_term_union;
|
||||
temp_term_union.insert(temporary_terms_g1.begin(), temporary_terms_g1.end());
|
||||
concat = "jacobian";
|
||||
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, jacobian_output, tef_terms, concat);
|
||||
jacobian_output << ", \"jacobian\": {"
|
||||
<< " \"nrows\": " << equations.size()
|
||||
<< ", \"ncols\": " << dynJacobianColsNbr
|
||||
<< ", \"entries\": [";
|
||||
for (first_derivatives_t::const_iterator it = first_derivatives.begin();
|
||||
it != first_derivatives.end(); it++)
|
||||
{
|
||||
if (it != first_derivatives.begin())
|
||||
jacobian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var = it->first.second;
|
||||
int col = getDynJacobianCol(var);
|
||||
expr_t d1 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"lag\": " << getLagByDerivID(var);
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"col\": " << col + 1
|
||||
<< ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
jacobian_output << "]}";
|
||||
|
||||
// Writing Hessian
|
||||
temp_term_union_m_1 = temp_term_union;
|
||||
temp_term_union.insert(temporary_terms_g2.begin(), temporary_terms_g2.end());
|
||||
concat = "hessian";
|
||||
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, hessian_output, tef_terms, concat);
|
||||
hessian_output << ", \"hessian\": {"
|
||||
<< " \"nrows\": " << equations.size()
|
||||
<< ", \"ncols\": " << hessianColsNbr
|
||||
<< ", \"entries\": [";
|
||||
for (second_derivatives_t::const_iterator it = second_derivatives.begin();
|
||||
it != second_derivatives.end(); it++)
|
||||
{
|
||||
if (it != second_derivatives.begin())
|
||||
hessian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var1 = it->first.second.first;
|
||||
int var2 = it->first.second.second;
|
||||
expr_t d2 = it->second;
|
||||
int id1 = getDynJacobianCol(var1);
|
||||
int id2 = getDynJacobianCol(var2);
|
||||
int col_nb = id1 * dynJacobianColsNbr + id2;
|
||||
int col_nb_sym = id2 * dynJacobianColsNbr + id1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"lag1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"lag2\": " << getLagByDerivID(var2);
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
|
||||
hessian_output << ", \"col\": [" << col_nb + 1;
|
||||
if (id1 != id2)
|
||||
hessian_output << ", " << col_nb_sym + 1;
|
||||
hessian_output << "]"
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms);
|
||||
hessian_output << "\"}" << endl;
|
||||
}
|
||||
hessian_output << "]}";
|
||||
|
||||
// Writing third derivatives
|
||||
temp_term_union_m_1 = temp_term_union;
|
||||
temp_term_union.insert(temporary_terms_g3.begin(), temporary_terms_g3.end());
|
||||
concat = "third_derivatives";
|
||||
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, third_derivatives_output, tef_terms, concat);
|
||||
third_derivatives_output << ", \"third_derivative\": {"
|
||||
<< " \"nrows\": " << equations.size()
|
||||
<< ", \"ncols\": " << hessianColsNbr * dynJacobianColsNbr
|
||||
<< ", \"entries\": [";
|
||||
for (third_derivatives_t::const_iterator it = third_derivatives.begin();
|
||||
it != third_derivatives.end(); it++)
|
||||
{
|
||||
if (it != third_derivatives.begin())
|
||||
third_derivatives_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var1 = it->first.second.first;
|
||||
int var2 = it->first.second.second.first;
|
||||
int var3 = it->first.second.second.second;
|
||||
expr_t d3 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivatives_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"lag1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"lag2\": " << getLagByDerivID(var2)
|
||||
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\""
|
||||
<< ", \"lag3\": " << getLagByDerivID(var3);
|
||||
else
|
||||
third_derivatives_output << "{\"row\": " << eq + 1;
|
||||
|
||||
int id1 = getDynJacobianCol(var1);
|
||||
int id2 = getDynJacobianCol(var2);
|
||||
int id3 = getDynJacobianCol(var3);
|
||||
set<int> cols;
|
||||
cols.insert(id1 * hessianColsNbr + id2 * dynJacobianColsNbr + id3);
|
||||
cols.insert(id1 * hessianColsNbr + id3 * dynJacobianColsNbr + id2);
|
||||
cols.insert(id2 * hessianColsNbr + id1 * dynJacobianColsNbr + id3);
|
||||
cols.insert(id2 * hessianColsNbr + id3 * dynJacobianColsNbr + id1);
|
||||
cols.insert(id3 * hessianColsNbr + id1 * dynJacobianColsNbr + id2);
|
||||
cols.insert(id3 * hessianColsNbr + id2 * dynJacobianColsNbr + id1);
|
||||
|
||||
third_derivatives_output << ", \"col\": [";
|
||||
for (set<int>::iterator it2 = cols.begin(); it2 != cols.end(); it2++)
|
||||
{
|
||||
if (it2 != cols.begin())
|
||||
third_derivatives_output << ", ";
|
||||
third_derivatives_output << *it2 + 1;
|
||||
}
|
||||
third_derivatives_output << "]"
|
||||
<< ", \"val\": \"";
|
||||
d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms);
|
||||
third_derivatives_output << "\"}" << endl;
|
||||
}
|
||||
third_derivatives_output << "]}";
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"dynamic_model_derivative_details\": {";
|
||||
else
|
||||
output << "\"dynamic_model_derivatives\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
<< ", " << hessian_output.str()
|
||||
<< ", " << third_derivatives_output.str()
|
||||
<< "}";
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) const
|
||||
{
|
||||
if (!residuals_params_derivatives.size()
|
||||
&& !residuals_params_second_derivatives.size()
|
||||
&& !jacobian_params_derivatives.size()
|
||||
&& !jacobian_params_second_derivatives.size()
|
||||
&& !hessian_params_derivatives.size())
|
||||
return;
|
||||
|
||||
ostringstream model_local_vars_output; // Used for storing model local vars
|
||||
ostringstream model_output; // Used for storing model temp vars and equations
|
||||
ostringstream jacobian_output; // Used for storing jacobian equations
|
||||
ostringstream hessian_output; // Used for storing Hessian equations
|
||||
ostringstream hessian1_output; // Used for storing Hessian equations
|
||||
ostringstream third_derivs_output; // Used for storing third order derivatives equations
|
||||
ostringstream third_derivs1_output; // Used for storing third order derivatives equations
|
||||
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
writeJsonModelLocalVariables(model_local_vars_output, tef_terms);
|
||||
|
||||
temporary_terms_t temp_terms_empty;
|
||||
string concat = "all";
|
||||
writeJsonTemporaryTerms(params_derivs_temporary_terms, temp_terms_empty, model_output, tef_terms, concat);
|
||||
jacobian_output << "\"deriv_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nparamcols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (first_derivatives_t::const_iterator it = residuals_params_derivatives.begin();
|
||||
it != residuals_params_derivatives.end(); it++)
|
||||
{
|
||||
if (it != residuals_params_derivatives.begin())
|
||||
jacobian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int param = it->first.second;
|
||||
expr_t d1 = it->second;
|
||||
|
||||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"param_col\": " << param_col + 1
|
||||
<< ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, params_derivs_temporary_terms, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
jacobian_output << "]}";
|
||||
hessian_output << "\"deriv_jacobian_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nvarcols\": " << dynJacobianColsNbr
|
||||
<< ", \"nparamcols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (second_derivatives_t::const_iterator it = jacobian_params_derivatives.begin();
|
||||
it != jacobian_params_derivatives.end(); it++)
|
||||
{
|
||||
if (it != jacobian_params_derivatives.begin())
|
||||
hessian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var = it->first.second.first;
|
||||
int param = it->first.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int var_col = getDynJacobianCol(var) + 1;
|
||||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"lag\": " << getLagByDerivID(var)
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
hessian_output << ", \"var_col\": " << var_col + 1
|
||||
<< ", \"param_col\": " << param_col + 1
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian_output, params_derivs_temporary_terms, tef_terms);
|
||||
hessian_output << "\"}" << endl;
|
||||
}
|
||||
hessian_output << "]}";
|
||||
|
||||
hessian1_output << "\"second_deriv_residuals_wrt_params\": {"
|
||||
<< " \"nrows\": " << equations.size()
|
||||
<< ", \"nparam1cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"nparam2cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (second_derivatives_t::const_iterator it = residuals_params_second_derivatives.begin();
|
||||
it != residuals_params_second_derivatives.end(); ++it)
|
||||
{
|
||||
if (it != residuals_params_second_derivatives.begin())
|
||||
hessian1_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int param1 = it->first.second.first;
|
||||
int param2 = it->first.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1;
|
||||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
else
|
||||
hessian1_output << "{\"row\": " << eq + 1;
|
||||
hessian1_output << ", \"param1_col\": " << param1_col + 1
|
||||
<< ", \"param2_col\": " << param2_col + 1
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian1_output, params_derivs_temporary_terms, tef_terms);
|
||||
hessian1_output << "\"}" << endl;
|
||||
}
|
||||
hessian1_output << "]}";
|
||||
third_derivs_output << "\"second_deriv_jacobian_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nvarcols\": " << dynJacobianColsNbr
|
||||
<< ", \"nparam1cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"nparam2cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (third_derivatives_t::const_iterator it = jacobian_params_second_derivatives.begin();
|
||||
it != jacobian_params_second_derivatives.end(); ++it)
|
||||
{
|
||||
if (it != jacobian_params_second_derivatives.begin())
|
||||
third_derivs_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var = it->first.second.first;
|
||||
int param1 = it->first.second.second.first;
|
||||
int param2 = it->first.second.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int var_col = getDynJacobianCol(var) + 1;
|
||||
int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1;
|
||||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(var) << "\""
|
||||
<< ", \"lag\": " << getLagByDerivID(var)
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
else
|
||||
third_derivs_output << "{\"row\": " << eq + 1;
|
||||
third_derivs_output << ", \"var_col\": " << var_col + 1
|
||||
<< ", \"param1_col\": " << param1_col + 1
|
||||
<< ", \"param2_col\": " << param2_col + 1
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs_output << "\"}" << endl;
|
||||
}
|
||||
third_derivs_output << "]}" << endl;
|
||||
|
||||
third_derivs1_output << "\"derivative_hessian_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nvar1cols\": " << dynJacobianColsNbr
|
||||
<< ", \"nvar2cols\": " << dynJacobianColsNbr
|
||||
<< ", \"nparamcols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (third_derivatives_t::const_iterator it = hessian_params_derivatives.begin();
|
||||
it != hessian_params_derivatives.end(); ++it)
|
||||
{
|
||||
if (it != hessian_params_derivatives.begin())
|
||||
third_derivs1_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var1 = it->first.second.first;
|
||||
int var2 = it->first.second.second.first;
|
||||
int param = it->first.second.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int var1_col = getDynJacobianCol(var1) + 1;
|
||||
int var2_col = getDynJacobianCol(var2) + 1;
|
||||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"lag1\": " << getLagByDerivID(var1)
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"lag2\": " << getLagByDerivID(var2)
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
else
|
||||
third_derivs1_output << "{\"row\": " << eq + 1;
|
||||
third_derivs1_output << ", \"var1_col\": " << var1_col + 1
|
||||
<< ", \"var2_col\": " << var2_col + 1
|
||||
<< ", \"param_col\": " << param_col + 1
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs1_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs1_output << "\"}" << endl;
|
||||
}
|
||||
third_derivs1_output << "]}" << endl;
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"dynamic_model_params_derivative_details\": {";
|
||||
else
|
||||
output << "\"dynamic_model_params_derivatives\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
<< ", " << hessian_output.str()
|
||||
<< ", " << hessian1_output.str()
|
||||
<< ", " << third_derivs_output.str()
|
||||
<< ", " << third_derivs1_output.str()
|
||||
<< "}";
|
||||
}
|
||||
|
|
|
@ -241,6 +241,18 @@ public:
|
|||
//! Writes model initialization and lead/lag incidence matrix to output
|
||||
void writeOutput(ostream &output, const string &basename, bool block, bool byte_code, bool use_dll, int order, bool estimation_present, bool compute_xrefs, bool julia) const;
|
||||
|
||||
//! Write JSON Output
|
||||
void writeJsonOutput(ostream &output) const;
|
||||
|
||||
//! Write JSON Output representation of dynamic model after computing pass
|
||||
void writeJsonComputingPassOutput(ostream &output, bool writeDetails) const;
|
||||
|
||||
//! Write JSON prams derivatives file
|
||||
void writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) const;
|
||||
|
||||
//! Write cross reference output if the xref maps have been filed
|
||||
void writeJsonXrefs(ostream &output) const;
|
||||
|
||||
//! Return true if the hessian is equal to zero
|
||||
inline bool checkHessianZero() const;
|
||||
|
||||
|
|
|
@ -3518,7 +3518,7 @@ o_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("use_shock_groups","de
|
|||
o_psd_use_shock_groups : USE_SHOCK_GROUPS { driver.option_str("plot_shock_decomp.use_shock_groups","default"); }
|
||||
| USE_SHOCK_GROUPS EQUAL symbol { driver.option_str("plot_shock_decomp.use_shock_groups", $3); }
|
||||
;
|
||||
o_colormap : COLORMAP EQUAL symbol { driver.option_num("colormap",$3); };
|
||||
o_colormap : COLORMAP EQUAL symbol { driver.option_num("plot_shock_decomp.colormap",$3); };
|
||||
o_psd_colormap : COLORMAP EQUAL symbol { driver.option_num("plot_shock_decomp.colormap",$3); };
|
||||
|
||||
range : symbol ':' symbol
|
||||
|
|
|
@ -45,6 +45,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
, bool cygwin, bool msvc, bool mingw
|
||||
#endif
|
||||
, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail
|
||||
);
|
||||
|
||||
void main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file,
|
||||
|
@ -61,6 +62,7 @@ usage()
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
<< " [cygwin] [msvc] [mingw]"
|
||||
#endif
|
||||
<< "[json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonprintderivdetail]"
|
||||
<< endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -113,6 +115,10 @@ main(int argc, char **argv)
|
|||
map<string, string> defines;
|
||||
vector<string> path;
|
||||
FileOutputType output_mode = none;
|
||||
JsonOutputPointType json = nojson;
|
||||
JsonFileOutputType json_output_mode = file;
|
||||
bool onlyjson = false;
|
||||
bool jsonprintderivdetail = false;
|
||||
LanguageOutputType language = matlab;
|
||||
|
||||
// Parse options
|
||||
|
@ -291,6 +297,33 @@ main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argv[arg], "jsonstdout"))
|
||||
json_output_mode = standardout;
|
||||
else if (!strcmp(argv[arg], "onlyjson"))
|
||||
onlyjson = true;
|
||||
else if (!strcmp(argv[arg], "jsonprintderivdetail"))
|
||||
jsonprintderivdetail = true;
|
||||
else if (strlen(argv[arg]) >= 4 && !strncmp(argv[arg], "json", 4))
|
||||
{
|
||||
if (strlen(argv[arg]) <= 5 || argv[arg][4] != '=')
|
||||
{
|
||||
cerr << "Incorrect syntax for json option" << endl;
|
||||
usage();
|
||||
}
|
||||
if (strlen(argv[arg]) == 10 && !strncmp(argv[arg] + 5, "parse", 5))
|
||||
json = parsing;
|
||||
else if (strlen(argv[arg]) == 10 && !strncmp(argv[arg] + 5, "check", 5))
|
||||
json = checkpass;
|
||||
else if (strlen(argv[arg]) == 14 && !strncmp(argv[arg] + 5, "transform", 9))
|
||||
json = transformpass;
|
||||
else if (strlen(argv[arg]) == 12 && !strncmp(argv[arg] + 5, "compute", 7))
|
||||
json = computingpass;
|
||||
else
|
||||
{
|
||||
cerr << "Incorrect syntax for json option" << endl;
|
||||
usage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Unknown option: " << argv[arg] << endl;
|
||||
|
@ -337,6 +370,7 @@ main(int argc, char **argv)
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
, cygwin, msvc, mingw
|
||||
#endif
|
||||
, json, json_output_mode, onlyjson, jsonprintderivdetail
|
||||
);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -34,24 +34,33 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
|
|||
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
, bool cygwin, bool msvc, bool mingw
|
||||
#endif
|
||||
, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail
|
||||
)
|
||||
{
|
||||
ParsingDriver p(warnings, nostrict);
|
||||
|
||||
// Do parsing and construct internal representation of mod file
|
||||
ModFile *mod_file = p.parse(in, debug);
|
||||
if (json == parsing)
|
||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
|
||||
|
||||
// Run checking pass
|
||||
mod_file->checkPass(nostrict);
|
||||
if (json == checkpass)
|
||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
|
||||
|
||||
// Perform transformations on the model (creation of auxiliary vars and equations)
|
||||
mod_file->transformPass(nostrict, compute_xrefs);
|
||||
mod_file->transformPass(nostrict, compute_xrefs || json == transformpass);
|
||||
if (json == transformpass)
|
||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
|
||||
|
||||
// Evaluate parameters initialization, initval, endval and pounds
|
||||
mod_file->evalAllExpressions(warn_uninit);
|
||||
|
||||
// Do computations
|
||||
mod_file->computingPass(no_tmp_terms, output_mode, params_derivs_order);
|
||||
if (json == computingpass)
|
||||
mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, jsonprintderivdetail);
|
||||
|
||||
// Write outputs
|
||||
if (output_mode != none)
|
||||
|
|
|
@ -73,6 +73,13 @@ ExprNode::precedence(ExprNodeOutputType output_type, const temporary_terms_t &te
|
|||
return 100;
|
||||
}
|
||||
|
||||
int
|
||||
ExprNode::precedenceJson(const temporary_terms_t &temporary_terms) const
|
||||
{
|
||||
// For a constant, a variable, or a unary op, the precedence is maximal
|
||||
return 100;
|
||||
}
|
||||
|
||||
int
|
||||
ExprNode::cost(int cost, bool is_matlab) const
|
||||
{
|
||||
|
@ -185,6 +192,14 @@ ExprNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output
|
|||
// Nothing to do
|
||||
}
|
||||
|
||||
void
|
||||
ExprNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
void
|
||||
ExprNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
|
@ -327,6 +342,14 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
|||
output << datatree.num_constants.get(id);
|
||||
}
|
||||
|
||||
void
|
||||
NumConstNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
output << datatree.num_constants.get(id);
|
||||
}
|
||||
|
||||
bool
|
||||
NumConstNode::containsExternalFunction() const
|
||||
{
|
||||
|
@ -643,6 +666,23 @@ VariableNode::containsExternalFunction() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<VariableNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
output << "T" << idx;
|
||||
return;
|
||||
}
|
||||
|
||||
output << datatree.symbol_table.getName(symb_id);
|
||||
if (lag != 0)
|
||||
output << "(" << lag << ")";
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -1918,6 +1958,147 @@ UnaryOpNode::containsExternalFunction() const
|
|||
return arg->containsExternalFunction();
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
output << "T" << idx;
|
||||
return;
|
||||
}
|
||||
|
||||
// Always put parenthesis around uminus nodes
|
||||
if (op_code == oUminus)
|
||||
output << "(";
|
||||
|
||||
switch (op_code)
|
||||
{
|
||||
case oUminus:
|
||||
output << "-";
|
||||
break;
|
||||
case oExp:
|
||||
output << "exp";
|
||||
break;
|
||||
case oLog:
|
||||
output << "log";
|
||||
break;
|
||||
case oLog10:
|
||||
output << "log10";
|
||||
break;
|
||||
case oCos:
|
||||
output << "cos";
|
||||
break;
|
||||
case oSin:
|
||||
output << "sin";
|
||||
break;
|
||||
case oTan:
|
||||
output << "tan";
|
||||
break;
|
||||
case oAcos:
|
||||
output << "acos";
|
||||
break;
|
||||
case oAsin:
|
||||
output << "asin";
|
||||
break;
|
||||
case oAtan:
|
||||
output << "atan";
|
||||
break;
|
||||
case oCosh:
|
||||
output << "cosh";
|
||||
break;
|
||||
case oSinh:
|
||||
output << "sinh";
|
||||
break;
|
||||
case oTanh:
|
||||
output << "tanh";
|
||||
break;
|
||||
case oAcosh:
|
||||
output << "acosh";
|
||||
break;
|
||||
case oAsinh:
|
||||
output << "asinh";
|
||||
break;
|
||||
case oAtanh:
|
||||
output << "atanh";
|
||||
break;
|
||||
case oSqrt:
|
||||
output << "sqrt";
|
||||
break;
|
||||
case oAbs:
|
||||
output << "abs";
|
||||
break;
|
||||
case oSign:
|
||||
output << "sign";
|
||||
break;
|
||||
case oDiff:
|
||||
output << "diff";
|
||||
break;
|
||||
case oSteadyState:
|
||||
output << "(";
|
||||
arg->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << ")";
|
||||
return;
|
||||
case oSteadyStateParamDeriv:
|
||||
{
|
||||
VariableNode *varg = dynamic_cast<VariableNode *>(arg);
|
||||
assert(varg != NULL);
|
||||
assert(datatree.symbol_table.getType(varg->symb_id) == eEndogenous);
|
||||
assert(datatree.symbol_table.getType(param1_symb_id) == eParameter);
|
||||
int tsid_endo = datatree.symbol_table.getTypeSpecificID(varg->symb_id);
|
||||
int tsid_param = datatree.symbol_table.getTypeSpecificID(param1_symb_id);
|
||||
output << "ss_param_deriv(" << tsid_endo+1 << "," << tsid_param+1 << ")";
|
||||
}
|
||||
return;
|
||||
case oSteadyStateParam2ndDeriv:
|
||||
{
|
||||
VariableNode *varg = dynamic_cast<VariableNode *>(arg);
|
||||
assert(varg != NULL);
|
||||
assert(datatree.symbol_table.getType(varg->symb_id) == eEndogenous);
|
||||
assert(datatree.symbol_table.getType(param1_symb_id) == eParameter);
|
||||
assert(datatree.symbol_table.getType(param2_symb_id) == eParameter);
|
||||
int tsid_endo = datatree.symbol_table.getTypeSpecificID(varg->symb_id);
|
||||
int tsid_param1 = datatree.symbol_table.getTypeSpecificID(param1_symb_id);
|
||||
int tsid_param2 = datatree.symbol_table.getTypeSpecificID(param2_symb_id);
|
||||
output << "ss_param_2nd_deriv(" << tsid_endo+1 << "," << tsid_param1+1
|
||||
<< "," << tsid_param2+1 << ")";
|
||||
}
|
||||
return;
|
||||
case oExpectation:
|
||||
output << "EXPECTATION(" << expectation_information_set << ")";
|
||||
break;
|
||||
case oErf:
|
||||
output << "erf";
|
||||
break;
|
||||
}
|
||||
|
||||
bool close_parenthesis = false;
|
||||
|
||||
/* Enclose argument with parentheses if:
|
||||
- current opcode is not uminus, or
|
||||
- current opcode is uminus and argument has lowest precedence
|
||||
*/
|
||||
if (op_code != oUminus
|
||||
|| (op_code == oUminus
|
||||
&& arg->precedenceJson(temporary_terms) < precedenceJson(temporary_terms)))
|
||||
{
|
||||
output << "(";
|
||||
close_parenthesis = true;
|
||||
}
|
||||
|
||||
// Write argument
|
||||
arg->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
|
||||
if (close_parenthesis)
|
||||
output << ")";
|
||||
|
||||
// Close parenthesis for uminus
|
||||
if (op_code == oUminus)
|
||||
output << ")";
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -2115,6 +2296,14 @@ UnaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType out
|
|||
arg->writeExternalFunctionOutput(output, output_type, temporary_terms, tef_terms);
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
arg->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
|
@ -2923,6 +3112,44 @@ BinaryOpNode::precedence(ExprNodeOutputType output_type, const temporary_terms_t
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
BinaryOpNode::precedenceJson(const temporary_terms_t &temporary_terms) const
|
||||
{
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
|
||||
// A temporary term behaves as a variable
|
||||
if (it != temporary_terms.end())
|
||||
return 100;
|
||||
|
||||
switch (op_code)
|
||||
{
|
||||
case oEqual:
|
||||
return 0;
|
||||
case oEqualEqual:
|
||||
case oDifferent:
|
||||
return 1;
|
||||
case oLessEqual:
|
||||
case oGreaterEqual:
|
||||
case oLess:
|
||||
case oGreater:
|
||||
return 2;
|
||||
case oPlus:
|
||||
case oMinus:
|
||||
return 3;
|
||||
case oTimes:
|
||||
case oDivide:
|
||||
return 4;
|
||||
case oPower:
|
||||
case oPowerDeriv:
|
||||
return 5;
|
||||
case oMin:
|
||||
case oMax:
|
||||
case oAdl:
|
||||
return 100;
|
||||
}
|
||||
// Suppress GCC warning
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
BinaryOpNode::cost(const map<NodeTreeReference, temporary_terms_t> &temp_terms_map, bool is_matlab) const
|
||||
{
|
||||
|
@ -3194,6 +3421,127 @@ BinaryOpNode::containsExternalFunction() const
|
|||
|| arg2->containsExternalFunction();
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
output << "T" << idx;
|
||||
return;
|
||||
}
|
||||
|
||||
if (op_code == oMax || op_code == oMin)
|
||||
{
|
||||
switch (op_code)
|
||||
{
|
||||
case oMax:
|
||||
output << "max(";
|
||||
break;
|
||||
case oMin:
|
||||
output << "min(";
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << ",";
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
int prec = precedenceJson(temporary_terms);
|
||||
|
||||
bool close_parenthesis = false;
|
||||
|
||||
// If left argument has a lower precedence, or if current and left argument are both power operators,
|
||||
// add parenthesis around left argument
|
||||
BinaryOpNode *barg1 = dynamic_cast<BinaryOpNode *>(arg1);
|
||||
if (arg1->precedenceJson(temporary_terms) < prec
|
||||
|| (op_code == oPower && barg1 != NULL && barg1->op_code == oPower))
|
||||
{
|
||||
output << "(";
|
||||
close_parenthesis = true;
|
||||
}
|
||||
|
||||
// Write left argument
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
|
||||
if (close_parenthesis)
|
||||
output << ")";
|
||||
|
||||
// Write current operator symbol
|
||||
switch (op_code)
|
||||
{
|
||||
case oPlus:
|
||||
output << "+";
|
||||
break;
|
||||
case oMinus:
|
||||
output << "-";
|
||||
break;
|
||||
case oTimes:
|
||||
output << "*";
|
||||
break;
|
||||
case oDivide:
|
||||
output << "/";
|
||||
break;
|
||||
case oPower:
|
||||
output << "^";
|
||||
break;
|
||||
case oLess:
|
||||
output << "<";
|
||||
break;
|
||||
case oGreater:
|
||||
output << ">";
|
||||
break;
|
||||
case oLessEqual:
|
||||
output << "<=";
|
||||
break;
|
||||
case oGreaterEqual:
|
||||
output << ">=";
|
||||
break;
|
||||
case oEqualEqual:
|
||||
output << "==";
|
||||
break;
|
||||
case oDifferent:
|
||||
output << "!=";
|
||||
break;
|
||||
case oEqual:
|
||||
output << "=";
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
close_parenthesis = false;
|
||||
|
||||
/* Add parenthesis around right argument if:
|
||||
- its precedence is lower than those of the current node
|
||||
- it is a power operator and current operator is also a power operator
|
||||
- it is a minus operator with same precedence than current operator
|
||||
- it is a divide operator with same precedence than current operator */
|
||||
BinaryOpNode *barg2 = dynamic_cast<BinaryOpNode *>(arg2);
|
||||
int arg2_prec = arg2->precedenceJson(temporary_terms);
|
||||
if (arg2_prec < prec
|
||||
|| (op_code == oPower && barg2 != NULL && barg2->op_code == oPower)
|
||||
|| (op_code == oMinus && arg2_prec == prec)
|
||||
|| (op_code == oDivide && arg2_prec == prec))
|
||||
{
|
||||
output << "(";
|
||||
close_parenthesis = true;
|
||||
}
|
||||
|
||||
// Write right argument
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
|
||||
if (close_parenthesis)
|
||||
output << ")";
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -3383,6 +3731,15 @@ BinaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType ou
|
|||
arg2->writeExternalFunctionOutput(output, output_type, temporary_terms, tef_terms);
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
arg1->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg2->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
}
|
||||
|
||||
void
|
||||
BinaryOpNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
|
@ -4382,6 +4739,37 @@ TrinaryOpNode::containsExternalFunction() const
|
|||
|| arg3->containsExternalFunction();
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
output << "T" << idx;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (op_code)
|
||||
{
|
||||
case oNormcdf:
|
||||
output << "normcdf(";
|
||||
break;
|
||||
case oNormpdf:
|
||||
output << "normpdf(";
|
||||
break;
|
||||
}
|
||||
|
||||
arg1->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << ",";
|
||||
arg2->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << ",";
|
||||
arg3->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << ")";
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -4458,6 +4846,16 @@ TrinaryOpNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType o
|
|||
arg3->writeExternalFunctionOutput(output, output_type, temporary_terms, tef_terms);
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
arg1->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg2->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
arg3->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
|
@ -5126,6 +5524,21 @@ AbstractExternalFunctionNode::writeExternalFunctionArguments(ostream &output, Ex
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
AbstractExternalFunctionNode::writeJsonExternalFunctionArguments(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
for (vector<expr_t>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
{
|
||||
if (it != arguments.begin())
|
||||
output << ",";
|
||||
|
||||
(*it)->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -5289,6 +5702,23 @@ ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsign
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExternalFunctionNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<ExternalFunctionNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
output << "T" << idx;
|
||||
return;
|
||||
}
|
||||
|
||||
output << datatree.symbol_table.getName(symb_id) << "(";
|
||||
writeJsonExternalFunctionArguments(output, temporary_terms, tef_terms);
|
||||
output << ")";
|
||||
}
|
||||
|
||||
void
|
||||
ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -5398,6 +5828,42 @@ ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutpu
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
|
||||
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
||||
for (vector<expr_t>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
(*it)->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
|
||||
if (!alreadyWrittenAsTefTerm(symb_id, tef_terms))
|
||||
{
|
||||
tef_terms[make_pair(symb_id, arguments)] = (int) tef_terms.size();
|
||||
int indx = getIndxInTefTerms(symb_id, tef_terms);
|
||||
int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
|
||||
assert(second_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
||||
stringstream ef;
|
||||
ef << "{\"external_function\": {"
|
||||
<< "\"external_function_term\": \"TEF_" << indx << "\"";
|
||||
|
||||
if (symb_id == first_deriv_symb_id)
|
||||
ef << ", \"external_function_term_d\": \"TEFD_" << indx << "\"";
|
||||
|
||||
if (symb_id == second_deriv_symb_id)
|
||||
ef << ", \"external_function_term_dd\": \"TEFDD_" << indx << "\"";
|
||||
|
||||
ef << ", \"value\": \"" << datatree.symbol_table.getName(symb_id) << "(";
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms);
|
||||
ef << ")\"}}";
|
||||
efout.push_back(ef.str());
|
||||
}
|
||||
}
|
||||
|
||||
expr_t
|
||||
ExternalFunctionNode::toStatic(DataTree &static_datatree) const
|
||||
{
|
||||
|
@ -5479,6 +5945,34 @@ FirstDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
|||
return theDeriv;
|
||||
}
|
||||
|
||||
void
|
||||
FirstDerivExternalFunctionNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<FirstDerivExternalFunctionNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
output << "T" << idx;
|
||||
return;
|
||||
}
|
||||
|
||||
const int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
|
||||
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
||||
const int tmpIndx = inputIndex - 1;
|
||||
|
||||
if (first_deriv_symb_id == symb_id)
|
||||
output << "TEFD_" << getIndxInTefTerms(symb_id, tef_terms)
|
||||
<< "[" << tmpIndx << "]";
|
||||
else if (first_deriv_symb_id == eExtFunNotSet)
|
||||
output << "TEFD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex;
|
||||
else
|
||||
output << "TEFD_def_" << getIndxInTefTerms(first_deriv_symb_id, tef_terms)
|
||||
<< "[" << tmpIndx << "]";
|
||||
}
|
||||
|
||||
void
|
||||
FirstDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -5666,6 +6160,47 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
FirstDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
|
||||
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
||||
/* For a node with derivs provided by the user function, call the method
|
||||
on the non-derived node */
|
||||
if (first_deriv_symb_id == symb_id)
|
||||
{
|
||||
expr_t parent = datatree.AddExternalFunction(symb_id, arguments);
|
||||
parent->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
return;
|
||||
}
|
||||
|
||||
if (alreadyWrittenAsTefTerm(first_deriv_symb_id, tef_terms))
|
||||
return;
|
||||
|
||||
stringstream ef;
|
||||
if (first_deriv_symb_id == eExtFunNotSet)
|
||||
ef << "{\"first_deriv_external_function\": {"
|
||||
<< "\"external_function_term\": \"TEFD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex << "\""
|
||||
<< ", \"analytic_derivative\": false"
|
||||
<< ", \"wrt\": " << inputIndex
|
||||
<< ", \"value\": \"" << datatree.symbol_table.getName(symb_id) << "(";
|
||||
else
|
||||
{
|
||||
tef_terms[make_pair(first_deriv_symb_id, arguments)] = (int) tef_terms.size();
|
||||
ef << "{\"first_deriv_external_function\": {"
|
||||
<< "\"external_function_term\": \"TEFD_def_" << getIndxInTefTerms(first_deriv_symb_id, tef_terms) << "\""
|
||||
<< ", \"analytic_derivative\": true"
|
||||
<< ", \"value\": \"" << datatree.symbol_table.getName(first_deriv_symb_id) << "(";
|
||||
}
|
||||
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms);
|
||||
ef << ")\"}}";
|
||||
efout.push_back(ef.str());
|
||||
}
|
||||
|
||||
void
|
||||
FirstDerivExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
|
@ -5791,6 +6326,35 @@ SecondDerivExternalFunctionNode::composeDerivatives(const vector<expr_t> &dargs)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void
|
||||
SecondDerivExternalFunctionNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
// If current node is a temporary term
|
||||
temporary_terms_t::const_iterator it = temporary_terms.find(const_cast<SecondDerivExternalFunctionNode *>(this));
|
||||
if (it != temporary_terms.end())
|
||||
{
|
||||
output << "T" << idx;
|
||||
return;
|
||||
}
|
||||
|
||||
const int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
|
||||
assert(second_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
||||
const int tmpIndex1 = inputIndex1 - 1;
|
||||
const int tmpIndex2 = inputIndex2 - 1;
|
||||
|
||||
if (second_deriv_symb_id == symb_id)
|
||||
output << "TEFDD_" << getIndxInTefTerms(symb_id, tef_terms)
|
||||
<< "[" << tmpIndex1 << "," << tmpIndex2 << "]";
|
||||
else if (second_deriv_symb_id == eExtFunNotSet)
|
||||
output << "TEFDD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex1 << "_" << inputIndex2;
|
||||
else
|
||||
output << "TEFDD_def_" << getIndxInTefTerms(second_deriv_symb_id, tef_terms)
|
||||
<< "[" << tmpIndex1 << "," << tmpIndex2 << "]";
|
||||
}
|
||||
|
||||
void
|
||||
SecondDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
|
@ -5955,6 +6519,48 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
SecondDerivExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
|
||||
assert(second_deriv_symb_id != eExtFunSetButNoNameProvided);
|
||||
|
||||
/* For a node with derivs provided by the user function, call the method
|
||||
on the non-derived node */
|
||||
if (second_deriv_symb_id == symb_id)
|
||||
{
|
||||
expr_t parent = datatree.AddExternalFunction(symb_id, arguments);
|
||||
parent->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms);
|
||||
return;
|
||||
}
|
||||
|
||||
if (alreadyWrittenAsTefTerm(second_deriv_symb_id, tef_terms))
|
||||
return;
|
||||
|
||||
stringstream ef;
|
||||
if (second_deriv_symb_id == eExtFunNotSet)
|
||||
ef << "{\"second_deriv_external_function\": {"
|
||||
<< "\"external_function_term\": \"TEFDD_fdd_" << getIndxInTefTerms(symb_id, tef_terms) << "_" << inputIndex1 << "_" << inputIndex2 << "\""
|
||||
<< ", \"analytic_derivative\": false"
|
||||
<< ", \"wrt1\": " << inputIndex1
|
||||
<< ", \"wrt2\": " << inputIndex2
|
||||
<< ", \"value\": \"" << datatree.symbol_table.getName(symb_id) << "(";
|
||||
else
|
||||
{
|
||||
tef_terms[make_pair(second_deriv_symb_id, arguments)] = (int) tef_terms.size();
|
||||
ef << "{\"second_deriv_external_function\": {"
|
||||
<< "\"external_function_term\": \"TEFDD_def_" << getIndxInTefTerms(second_deriv_symb_id, tef_terms) << "\""
|
||||
<< ", \"analytic_derivative\": true"
|
||||
<< ", \"value\": \"" << datatree.symbol_table.getName(second_deriv_symb_id) << "(";
|
||||
}
|
||||
|
||||
writeJsonExternalFunctionArguments(ef, temporary_terms, tef_terms);
|
||||
ef << ")\"}}" << endl;
|
||||
efout.push_back(ef.str());
|
||||
}
|
||||
|
||||
expr_t
|
||||
SecondDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const
|
||||
{
|
||||
|
@ -6312,3 +6918,16 @@ VarExpectationNode::substituteStaticAuxiliaryVariable() const
|
|||
{
|
||||
return const_cast<VarExpectationNode *>(this);
|
||||
}
|
||||
|
||||
void
|
||||
VarExpectationNode::writeJsonOutput(ostream &output,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
output << "var_expectation("
|
||||
<< "forecast_horizon = " << forecast_horizon
|
||||
<< ", name = " << datatree.symbol_table.getName(symb_id)
|
||||
<< ", model_name = " << model_name
|
||||
<< ", yindex = " << yidx
|
||||
<< ")";
|
||||
}
|
||||
|
|
|
@ -224,11 +224,22 @@ enum ExprNodeOutputType
|
|||
//! Writes output of node, using a Txxx notation for nodes in temporary_terms
|
||||
void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||
|
||||
//! Writes output of node in JSON syntax
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
|
||||
virtual int precedenceJson(const temporary_terms_t &temporary_terms) const;
|
||||
|
||||
//! Writes the output for an external function, ensuring that the external function is called as few times as possible using temporary terms
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
|
||||
//! Write the JSON output of an external function in a string vector
|
||||
//! Allows the insertion of commas if necessary
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -497,6 +508,7 @@ public:
|
|||
};
|
||||
virtual void prepareForDerivation();
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
|
||||
|
@ -550,6 +562,7 @@ public:
|
|||
VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg);
|
||||
virtual void prepareForDerivation();
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
|
||||
virtual void computeTemporaryTerms(map<expr_t, int > &reference_count,
|
||||
|
@ -633,10 +646,14 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -719,15 +736,20 @@ public:
|
|||
BinaryOpNode(DataTree &datatree_arg, const expr_t arg1_arg,
|
||||
BinaryOpcode op_code_arg, const expr_t arg2_arg, int powerDerivOrder);
|
||||
virtual void prepareForDerivation();
|
||||
virtual int precedenceJson(const temporary_terms_t &temporary_terms) const;
|
||||
virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const;
|
||||
virtual void computeTemporaryTerms(map<expr_t, pair<int, NodeTreeReference> > &reference_count,
|
||||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -833,10 +855,14 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -907,6 +933,7 @@ protected:
|
|||
int getIndxInTefTerms(int the_symb_id, deriv_node_temp_terms_t &tef_terms) const throw (UnknownFunctionNameAndArgs);
|
||||
//! Helper function to write output arguments of any given external function
|
||||
void writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
void writeJsonExternalFunctionArguments(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
public:
|
||||
AbstractExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg,
|
||||
const vector<expr_t> &arguments_arg);
|
||||
|
@ -915,10 +942,14 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const = 0;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual bool containsExternalFunction() const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const = 0;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -985,9 +1016,13 @@ public:
|
|||
map<NodeTreeReference, temporary_terms_t> &temp_terms_map,
|
||||
bool is_matlab, NodeTreeReference tr) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1025,6 +1060,7 @@ public:
|
|||
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
||||
int equation) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1032,6 +1068,9 @@ public:
|
|||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1064,6 +1103,7 @@ public:
|
|||
vector< vector<temporary_terms_t> > &v_temporary_terms,
|
||||
int equation) const;
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1071,6 +1111,9 @@ public:
|
|||
virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void writeJsonExternalFunctionOutput(vector<string> &efout,
|
||||
const temporary_terms_t &temporary_terms,
|
||||
deriv_node_temp_terms_t &tef_terms) const;
|
||||
virtual void compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number,
|
||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
|
||||
|
@ -1141,6 +1184,7 @@ public:
|
|||
virtual bool isVarModelReferenced(const string &model_info_name) const;
|
||||
virtual void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const;
|
||||
virtual expr_t substituteStaticAuxiliaryVariable() const;
|
||||
virtual void writeJsonOutput(ostream &output, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,4 +38,19 @@ enum LanguageOutputType
|
|||
julia, // outputs files for Julia
|
||||
python, // outputs files for Python (not yet implemented) (not yet implemented)
|
||||
};
|
||||
|
||||
enum JsonFileOutputType
|
||||
{
|
||||
file, // output JSON files to file
|
||||
standardout, // output JSON files to stdout
|
||||
};
|
||||
|
||||
enum JsonOutputPointType
|
||||
{
|
||||
nojson, // don't output JSON
|
||||
parsing, // output JSON after the parsing step
|
||||
checkpass, // output JSON after the check pass
|
||||
transformpass, // output JSON after the transform pass
|
||||
computingpass // output JSON after the computing pass
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -1288,3 +1288,229 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
|
|||
jlOutputFile.close();
|
||||
cout << "done" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
ModFile::writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail)
|
||||
{
|
||||
if (json == nojson)
|
||||
return;
|
||||
|
||||
if (json == parsing || json == checkpass)
|
||||
symbol_table.freeze();
|
||||
|
||||
writeJsonOutputParsingCheck(basename, json_output_mode);
|
||||
|
||||
if (json == parsing || json == checkpass)
|
||||
symbol_table.unfreeze();
|
||||
|
||||
if (json == computingpass)
|
||||
writeJsonComputingPassOutput(basename, json_output_mode, jsonprintderivdetail);
|
||||
|
||||
switch (json)
|
||||
{
|
||||
case parsing:
|
||||
cout << "JSON written after Parsing step." << endl;
|
||||
break;
|
||||
case checkpass:
|
||||
cout << "JSON written after Check step." << endl;
|
||||
break;
|
||||
case transformpass:
|
||||
cout << "JSON written after Transform step." << endl;
|
||||
break;
|
||||
case computingpass:
|
||||
cout << "JSON written after Computing step." << endl;
|
||||
break;
|
||||
case nojson:
|
||||
cerr << "ModFile::writeJsonOutput: should not arrive here." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (onlyjson)
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType json_output_mode) const
|
||||
{
|
||||
ostringstream output;
|
||||
output << "{" << endl;
|
||||
|
||||
symbol_table.writeJsonOutput(output);
|
||||
output << ", ";
|
||||
dynamic_model.writeJsonOutput(output);
|
||||
|
||||
if (!statements.empty())
|
||||
{
|
||||
output << ", \"statements\": [";
|
||||
for (vector<Statement *>::const_iterator it = statements.begin();
|
||||
it != statements.end(); it++)
|
||||
{
|
||||
if (it != statements.begin())
|
||||
output << ", " << endl;
|
||||
(*it)->writeJsonOutput(output);
|
||||
}
|
||||
output << "]" << endl;
|
||||
}
|
||||
output << "}" << endl;
|
||||
|
||||
if (json_output_mode == standardout)
|
||||
cout << output.str();
|
||||
else
|
||||
{
|
||||
ofstream jsonOutputFile;
|
||||
|
||||
if (basename.size())
|
||||
{
|
||||
string fname(basename);
|
||||
fname += ".json";
|
||||
jsonOutputFile.open(fname.c_str(), ios::out | ios::binary);
|
||||
if (!jsonOutputFile.is_open())
|
||||
{
|
||||
cerr << "ERROR: Can't open file " << fname << " for writing" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: Missing file name" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
jsonOutputFile << output.str();
|
||||
jsonOutputFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonprintderivdetail) const
|
||||
{
|
||||
ostringstream static_output, static_detail_output;
|
||||
static_output << "{";
|
||||
static_model.writeJsonComputingPassOutput(static_output, false);
|
||||
static_output << "}" << endl;
|
||||
|
||||
ostringstream dynamic_output, dynamic_detail_output;
|
||||
dynamic_output << "{";
|
||||
dynamic_model.writeJsonComputingPassOutput(dynamic_output, false);
|
||||
dynamic_output << "}" << endl;
|
||||
|
||||
ostringstream tmp_out, static_paramsd_output, static_paramsd_detail_output;
|
||||
tmp_out << "";
|
||||
static_paramsd_output << "";
|
||||
static_paramsd_detail_output << "";
|
||||
static_model.writeJsonParamsDerivativesFile(tmp_out, false);
|
||||
if (!tmp_out.str().empty())
|
||||
static_paramsd_output << "{" << tmp_out.str() << "}" << endl;
|
||||
|
||||
ostringstream tmp1_out, dynamic_paramsd_output, dynamic_paramsd_detail_output;
|
||||
tmp1_out << "";
|
||||
dynamic_paramsd_output << "";
|
||||
dynamic_paramsd_detail_output << "";
|
||||
dynamic_model.writeJsonParamsDerivativesFile(tmp1_out, false);
|
||||
if (!tmp1_out.str().empty())
|
||||
dynamic_paramsd_output << "{" << tmp1_out.str() << "}" << endl;
|
||||
|
||||
if (jsonprintderivdetail)
|
||||
{
|
||||
static_detail_output << "{";
|
||||
static_model.writeJsonComputingPassOutput(static_detail_output, true);
|
||||
static_detail_output << "}";
|
||||
|
||||
dynamic_detail_output << "{";
|
||||
dynamic_model.writeJsonComputingPassOutput(dynamic_detail_output, true);
|
||||
dynamic_detail_output << "}";
|
||||
|
||||
ostringstream tmpd_out, tmpd1_out;
|
||||
tmpd_out << "";
|
||||
tmpd1_out << "";
|
||||
static_model.writeJsonParamsDerivativesFile(tmpd_out, true);
|
||||
if (!tmpd_out.str().empty())
|
||||
static_paramsd_detail_output << "{" << tmpd_out.str() << "}" << endl;
|
||||
|
||||
dynamic_model.writeJsonParamsDerivativesFile(tmpd1_out, true);
|
||||
if (!tmpd1_out.str().empty())
|
||||
dynamic_paramsd_detail_output << "{" << tmpd1_out.str() << "}" << endl;
|
||||
}
|
||||
|
||||
if (json_output_mode == standardout)
|
||||
{
|
||||
cout << static_output.str() << endl
|
||||
<< dynamic_output.str() << endl;
|
||||
|
||||
if (!static_paramsd_output.str().empty())
|
||||
cout << static_paramsd_output.str() << endl;
|
||||
|
||||
if (!dynamic_paramsd_output.str().empty())
|
||||
cout << dynamic_paramsd_output.str() << endl;
|
||||
|
||||
if (jsonprintderivdetail)
|
||||
{
|
||||
cout << static_detail_output.str() << endl
|
||||
<< dynamic_detail_output.str() << endl;
|
||||
|
||||
if (!static_paramsd_detail_output.str().empty())
|
||||
cout << static_paramsd_detail_output.str() << endl;
|
||||
|
||||
if (!dynamic_paramsd_detail_output.str().empty())
|
||||
cout << dynamic_paramsd_detail_output.str() << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (basename.empty())
|
||||
{
|
||||
cerr << "ERROR: Missing file name" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
string fname_static, fname_dynamic;
|
||||
fname_static = basename + "_static.json";
|
||||
fname_dynamic = basename + "_dynamic.json";
|
||||
|
||||
writeJsonFileHelper(fname_static, static_output);
|
||||
writeJsonFileHelper(fname_dynamic, dynamic_output);
|
||||
|
||||
if (jsonprintderivdetail)
|
||||
{
|
||||
string fname_static_details, fname_dynamic_details;
|
||||
fname_static_details = basename + "_static_details.json";
|
||||
fname_dynamic_details = basename + "_dynamic_details.json";
|
||||
|
||||
writeJsonFileHelper(fname_static_details, static_detail_output);
|
||||
writeJsonFileHelper(fname_dynamic_details, dynamic_detail_output);
|
||||
}
|
||||
|
||||
if (!static_paramsd_output.str().empty())
|
||||
{
|
||||
string fname_static_params, fname_static_params_details;
|
||||
fname_static_params = basename + "_static_params_derivs.json";
|
||||
fname_static_params_details = basename + "_static_params_derivs_details.json";
|
||||
writeJsonFileHelper(fname_static_params, static_paramsd_output);
|
||||
writeJsonFileHelper(fname_static_params_details, static_paramsd_detail_output);
|
||||
}
|
||||
|
||||
if (!dynamic_paramsd_output.str().empty())
|
||||
{
|
||||
string fname_dynamic_params, fname_dynamic_params_details;
|
||||
fname_dynamic_params = basename + "_params_derivs.json";
|
||||
fname_dynamic_params_details = basename + "_params_derivs_details.json";
|
||||
writeJsonFileHelper(fname_dynamic_params, dynamic_paramsd_output);
|
||||
writeJsonFileHelper(fname_dynamic_params_details, dynamic_paramsd_detail_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModFile::writeJsonFileHelper(string &fname, ostringstream &output) const
|
||||
{
|
||||
ofstream jsonOutput;
|
||||
jsonOutput.open(fname.c_str(), ios::out | ios::binary);
|
||||
if (!jsonOutput.is_open())
|
||||
{
|
||||
cerr << "ERROR: Can't open file " << fname << " for writing" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
jsonOutput << output.str();
|
||||
jsonOutput.close();
|
||||
|
||||
}
|
||||
|
|
|
@ -117,7 +117,10 @@ private:
|
|||
ModFileStructure mod_file_struct;
|
||||
//! Warnings Encountered
|
||||
WarningConsolidation &warnings;
|
||||
|
||||
//! Functions used in writing of JSON outut. See writeJsonOutput
|
||||
void writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType json_output_mode) const;
|
||||
void writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonprintderivdetail) const;
|
||||
void writeJsonFileHelper(string &fname, ostringstream &output) const;
|
||||
public:
|
||||
//! Add a statement
|
||||
void addStatement(Statement *st);
|
||||
|
@ -167,6 +170,11 @@ public:
|
|||
void writeModelCC(const string &basename) const;
|
||||
|
||||
void computeChecksum();
|
||||
//! Write JSON representation of ModFile object
|
||||
//! Initially created to enable Julia to work with .mod files
|
||||
//! Potentially outputs ModFile after the various parts of processing (parsing, checkPass, transformPass, computingPass)
|
||||
//! Allows user of other host language platforms (python, fortran, etc) to provide support for dynare .mod files
|
||||
void writeJsonOutput(const string &basename, JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonprintderivdetail = false);
|
||||
};
|
||||
|
||||
#endif // ! MOD_FILE_HH
|
||||
|
|
|
@ -232,7 +232,7 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian
|
|||
void
|
||||
ModelTree::computeNormalizedEquations(multimap<int, int> &endo2eqs) const
|
||||
{
|
||||
for (int i = 0; i < equations.size(); i++)
|
||||
for (size_t i = 0; i < equations.size(); i++)
|
||||
{
|
||||
VariableNode *lhs = dynamic_cast<VariableNode *>(equations[i]->get_arg1());
|
||||
if (lhs == NULL)
|
||||
|
@ -247,7 +247,7 @@ ModelTree::computeNormalizedEquations(multimap<int, int> &endo2eqs) const
|
|||
if (endo.find(make_pair(symbol_table.getTypeSpecificID(symb_id), 0)) != endo.end())
|
||||
continue;
|
||||
|
||||
endo2eqs.insert(make_pair(symbol_table.getTypeSpecificID(symb_id), i));
|
||||
endo2eqs.insert(make_pair(symbol_table.getTypeSpecificID(symb_id), (int) i));
|
||||
cout << "Endogenous " << symbol_table.getName(symb_id) << " normalized in equation " << (i+1) << endl;
|
||||
}
|
||||
}
|
||||
|
@ -1195,6 +1195,60 @@ ModelTree::writeTemporaryTerms(const temporary_terms_t &tt, const temporary_term
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::writeJsonTemporaryTerms(const temporary_terms_t &tt, const temporary_terms_t &ttm1, ostream &output,
|
||||
deriv_node_temp_terms_t &tef_terms, string &concat) const
|
||||
{
|
||||
// Local var used to keep track of temp nodes already written
|
||||
bool wrote_term = false;
|
||||
temporary_terms_t tt2 = ttm1;
|
||||
|
||||
output << "\"external_functions_temporary_terms_" << concat << "\": [";
|
||||
for (temporary_terms_t::const_iterator it = tt.begin();
|
||||
it != tt.end(); it++)
|
||||
if (ttm1.find(*it) == ttm1.end())
|
||||
{
|
||||
if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL)
|
||||
{
|
||||
if (wrote_term)
|
||||
output << ", ";
|
||||
vector<string> efout;
|
||||
(*it)->writeJsonExternalFunctionOutput(efout, tt2, tef_terms);
|
||||
for (vector<string>::const_iterator it1 = efout.begin(); it1 != efout.end(); it1++)
|
||||
{
|
||||
if (it1 != efout.begin())
|
||||
output << ", ";
|
||||
output << *it1;
|
||||
}
|
||||
wrote_term = true;
|
||||
}
|
||||
tt2.insert(*it);
|
||||
}
|
||||
|
||||
tt2 = ttm1;
|
||||
wrote_term = false;
|
||||
output << "]"
|
||||
<< ", \"temporary_terms_" << concat << "\": [";
|
||||
for (temporary_terms_t::const_iterator it = tt.begin();
|
||||
it != tt.end(); it++)
|
||||
if (ttm1.find(*it) == ttm1.end())
|
||||
{
|
||||
if (wrote_term)
|
||||
output << ", ";
|
||||
output << "{\"temporary_term\": \"";
|
||||
(*it)->writeJsonOutput(output, tt, tef_terms);
|
||||
output << "\""
|
||||
<< ", \"value\": \"";
|
||||
(*it)->writeJsonOutput(output, tt2, tef_terms);
|
||||
output << "\"}" << endl;
|
||||
wrote_term = true;
|
||||
|
||||
// Insert current node into tt2
|
||||
tt2.insert(*it);
|
||||
}
|
||||
output << "]";
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::fixNestedParenthesis(ostringstream &output, map<string, string> &tmp_paren_vars, bool &message_printed) const
|
||||
{
|
||||
|
@ -1384,6 +1438,54 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t &tef_terms) const
|
||||
{
|
||||
/* Collect all model local variables appearing in equations, and print only
|
||||
them. Printing unused model local variables can lead to a crash (see
|
||||
ticket #101). */
|
||||
set<int> used_local_vars;
|
||||
|
||||
// Use an empty set for the temporary terms
|
||||
const temporary_terms_t tt;
|
||||
|
||||
for (size_t i = 0; i < equations.size(); i++)
|
||||
equations[i]->collectVariables(eModelLocalVariable, used_local_vars);
|
||||
|
||||
output << "\"external_functions_model_local_variables\": [";
|
||||
for (set<int>::const_iterator it = used_local_vars.begin();
|
||||
it != used_local_vars.end(); ++it)
|
||||
{
|
||||
vector<string> efout;
|
||||
expr_t value = local_variables_table.find(*it)->second;
|
||||
value->writeJsonExternalFunctionOutput(efout, tt, tef_terms);
|
||||
for (vector<string>::const_iterator it1 = efout.begin(); it1 != efout.end(); it1++)
|
||||
{
|
||||
if (it1 != efout.begin())
|
||||
output << ", ";
|
||||
output << *it1;
|
||||
}
|
||||
}
|
||||
output << "]"
|
||||
<< ", \"model_local_variables\": [";
|
||||
for (set<int>::const_iterator it = used_local_vars.begin();
|
||||
it != used_local_vars.end(); ++it)
|
||||
{
|
||||
if (it != used_local_vars.begin())
|
||||
output << ", ";
|
||||
int id = *it;
|
||||
expr_t value = local_variables_table.find(id)->second;
|
||||
|
||||
/* We append underscores to avoid name clashes with "g1" or "oo_" (see
|
||||
also VariableNode::writeOutput) */
|
||||
output << "{\"variable\": \"" << symbol_table.getName(id) << "__\""
|
||||
<< ", \"value\": \"";
|
||||
value->writeJsonOutput(output, tt, tef_terms);
|
||||
output << "\"}" << endl;
|
||||
}
|
||||
output << "]";
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::writeModelEquations(ostream &output, ExprNodeOutputType output_type) const
|
||||
{
|
||||
|
@ -1588,7 +1690,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
|
|||
|
||||
content_output << iteqt->second.first;
|
||||
|
||||
if (!empty(iteqt->second.second))
|
||||
if (iteqt->second.second.empty())
|
||||
content_output << "= `" << iteqt->second.second << "'";
|
||||
|
||||
wrote_eq_tag = true;
|
||||
|
@ -1667,7 +1769,7 @@ ModelTree::addNonstationaryVariables(vector<int> nonstationary_vars, bool log_de
|
|||
void
|
||||
ModelTree::initializeVariablesAndEquations()
|
||||
{
|
||||
for (int j = 0; j < equations.size(); j++)
|
||||
for (size_t j = 0; j < equations.size(); j++)
|
||||
{
|
||||
equation_reordered.push_back(j);
|
||||
variable_reordered.push_back(j);
|
||||
|
@ -1845,3 +1947,80 @@ ModelTree::isNonstationary(int symb_id) const
|
|||
return (nonstationary_symbols_map.find(symb_id)
|
||||
!= nonstationary_symbols_map.end());
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
vector<pair<string, string> > eqtags;
|
||||
temporary_terms_t tt_empty;
|
||||
if (residuals)
|
||||
output << endl << "\"residuals\":[" << endl;
|
||||
else
|
||||
output << endl << "\"model\":[" << endl;
|
||||
for (int eq = 0; eq < (int) equations.size(); eq++)
|
||||
{
|
||||
if (eq > 0)
|
||||
output << ", ";
|
||||
|
||||
BinaryOpNode *eq_node = equations[eq];
|
||||
expr_t lhs = eq_node->get_arg1();
|
||||
expr_t rhs = eq_node->get_arg2();
|
||||
|
||||
if (residuals)
|
||||
{
|
||||
output << "{\"residual\": {"
|
||||
<< "\"lhs\": \"";
|
||||
lhs->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << "\"";
|
||||
|
||||
output << ", \"rhs\": \"";
|
||||
rhs->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << "\"";
|
||||
try
|
||||
{
|
||||
// Test if the right hand side of the equation is empty.
|
||||
if (rhs->eval(eval_context_t()) != 0)
|
||||
{
|
||||
output << ", \"rhs\": \"";
|
||||
rhs->writeJsonOutput(output, temporary_terms, tef_terms);
|
||||
output << "\"";
|
||||
}
|
||||
}
|
||||
catch (ExprNode::EvalException &e)
|
||||
{
|
||||
}
|
||||
output << "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
output << "{\"lhs\": \"";
|
||||
lhs->writeJsonOutput(output, tt_empty, tef_terms);
|
||||
output << "\", \"rhs\": \"";
|
||||
rhs->writeJsonOutput(output, tt_empty, tef_terms);
|
||||
output << "\""
|
||||
<< ", \"line\": " << equations_lineno[eq];
|
||||
|
||||
for (vector<pair<int, pair<string, string> > >::const_iterator it = equation_tags.begin();
|
||||
it != equation_tags.end(); it++)
|
||||
if (it->first == eq)
|
||||
eqtags.push_back(it->second);
|
||||
|
||||
if (!eqtags.empty())
|
||||
{
|
||||
output << ", \"tags\": {";
|
||||
int i = 0;
|
||||
for (vector<pair<string, string> >::const_iterator it = eqtags.begin(); it != eqtags.end(); it++, i++)
|
||||
{
|
||||
if (i != 0)
|
||||
output << ", ";
|
||||
output << "\"" << it->first << "\": \"" << it->second << "\"";
|
||||
}
|
||||
output << "}";
|
||||
eqtags.clear();
|
||||
}
|
||||
}
|
||||
output << "}" << endl;
|
||||
}
|
||||
output << endl << "]" << endl;
|
||||
}
|
||||
|
|
|
@ -177,6 +177,7 @@ protected:
|
|||
void computeParamsDerivativesTemporaryTerms();
|
||||
//! Writes temporary terms
|
||||
void writeTemporaryTerms(const temporary_terms_t &tt, const temporary_terms_t &ttm1, ostream &output, ExprNodeOutputType output_type, deriv_node_temp_terms_t &tef_terms) const;
|
||||
void writeJsonTemporaryTerms(const temporary_terms_t &tt, const temporary_terms_t &ttm1, ostream &output, deriv_node_temp_terms_t &tef_terms, string &concat) const;
|
||||
//! Compiles temporary terms
|
||||
void compileTemporaryTerms(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, map_idx_t map_idx, bool dynamic, bool steady_dynamic) const;
|
||||
//! Adds informations for simulation in a binary file
|
||||
|
@ -190,6 +191,11 @@ protected:
|
|||
void writeModelLocalVariables(ostream &output, ExprNodeOutputType output_type, deriv_node_temp_terms_t &tef_terms) const;
|
||||
//! Writes model equations
|
||||
void writeModelEquations(ostream &output, ExprNodeOutputType output_type) const;
|
||||
//! Writes JSON model equations
|
||||
//! if residuals = true, we are writing the dynamic/static model.
|
||||
//! Otherwise, just the model equations (with line numbers, no tmp terms)
|
||||
void writeJsonModelEquations(ostream &output, bool residuals) const;
|
||||
void writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t &tef_terms) const;
|
||||
//! Compiles model equations
|
||||
void compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const;
|
||||
|
||||
|
|
|
@ -63,6 +63,15 @@ InitParamStatement::writeJuliaOutput(ostream &output, const string &basename)
|
|||
// output << symbol_table.getName(symb_id) << " = model_.params[ " << id << " ]" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
InitParamStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
output << "{\"statementName\": \"param_init\", \"name\": \"" << symbol_table.getName(symb_id) << "\", " << "\"value\": \"";
|
||||
param_value->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
|
||||
void
|
||||
InitParamStatement::writeCOutput(ostream &output, const string &basename)
|
||||
{
|
||||
|
@ -165,6 +174,21 @@ InitOrEndValStatement::writeInitValues(ostream &output) const
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
InitOrEndValStatement::writeJsonInitValues(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
for (init_values_t::const_iterator it = init_values.begin();
|
||||
it != init_values.end(); it++)
|
||||
{
|
||||
if (it != init_values.begin())
|
||||
output << ", ";
|
||||
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\", " << "\"value\": \"";
|
||||
it->second->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
InitValStatement::InitValStatement(const init_values_t &init_values_arg,
|
||||
const SymbolTable &symbol_table_arg,
|
||||
const bool &all_values_required_arg) :
|
||||
|
@ -210,6 +234,14 @@ InitValStatement::writeOutput(ostream &output, const string &basename, bool mini
|
|||
writeInitValues(output);
|
||||
}
|
||||
|
||||
void
|
||||
InitValStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"init_val\", \"vals\": [";
|
||||
writeJsonInitValues(output);
|
||||
output << "]}";
|
||||
}
|
||||
|
||||
void
|
||||
InitValStatement::writeOutputPostInit(ostream &output) const
|
||||
{
|
||||
|
@ -267,6 +299,14 @@ EndValStatement::writeOutput(ostream &output, const string &basename, bool minim
|
|||
writeInitValues(output);
|
||||
}
|
||||
|
||||
void
|
||||
EndValStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"end_val\", \"vals\": [";
|
||||
writeJsonInitValues(output);
|
||||
output << "]}";
|
||||
}
|
||||
|
||||
HistValStatement::HistValStatement(const hist_values_t &hist_values_arg,
|
||||
const SymbolTable &symbol_table_arg,
|
||||
const bool &all_values_required_arg) :
|
||||
|
@ -373,6 +413,25 @@ HistValStatement::writeOutput(ostream &output, const string &basename, bool mini
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
HistValStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
output << "{\"statementName\": \"hist_val\", \"vals\": [";
|
||||
for (hist_values_t::const_iterator it = hist_values.begin();
|
||||
it != hist_values.end(); it++)
|
||||
{
|
||||
if (it != hist_values.begin())
|
||||
output << ", ";
|
||||
output << "{ \"name\": \"" << symbol_table.getName(it->first.first) << "\""
|
||||
<< ", \"lag\": " << it->first.second
|
||||
<< ", \"value\": \"";
|
||||
it->second->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
output << "]}";
|
||||
}
|
||||
|
||||
InitvalFileStatement::InitvalFileStatement(const string &filename_arg) :
|
||||
filename(filename_arg)
|
||||
{
|
||||
|
@ -388,6 +447,14 @@ InitvalFileStatement::writeOutput(ostream &output, const string &basename, bool
|
|||
<< "initvalf('" << filename << "');" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
InitvalFileStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"init_val_file\""
|
||||
<< ", \"filename\": \"" << filename << "\""
|
||||
<< "}";
|
||||
}
|
||||
|
||||
HistvalFileStatement::HistvalFileStatement(const string &filename_arg) :
|
||||
filename(filename_arg)
|
||||
{
|
||||
|
@ -399,6 +466,14 @@ HistvalFileStatement::writeOutput(ostream &output, const string &basename, bool
|
|||
output << "histvalf('" << filename << "');" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
HistvalFileStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"hist_val_file\""
|
||||
<< ", \"filename\": \"" << filename << "\""
|
||||
<< "}";
|
||||
}
|
||||
|
||||
HomotopyStatement::HomotopyStatement(const homotopy_values_t &homotopy_values_arg,
|
||||
const SymbolTable &symbol_table_arg) :
|
||||
homotopy_values(homotopy_values_arg),
|
||||
|
@ -435,6 +510,31 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename, bool min
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
HomotopyStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
output << "{\"statementName\": \"homotopy\", "
|
||||
<< "\"values\": [";
|
||||
for (homotopy_values_t::const_iterator it = homotopy_values.begin();
|
||||
it != homotopy_values.end(); it++)
|
||||
{
|
||||
if (it != homotopy_values.begin())
|
||||
output << ", ";
|
||||
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\""
|
||||
<< ", \"initial_value\": \"";
|
||||
if (it->second.first != NULL)
|
||||
it->second.first->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
else
|
||||
output << "NaN";
|
||||
output << "\", \"final_value\": \"";
|
||||
it->second.second->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
output << "]"
|
||||
<< "}";
|
||||
}
|
||||
|
||||
SaveParamsAndSteadyStateStatement::SaveParamsAndSteadyStateStatement(const string &filename_arg) :
|
||||
filename(filename_arg)
|
||||
{
|
||||
|
@ -446,6 +546,14 @@ SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba
|
|||
output << "save_params_and_steady_state('" << filename << "');" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
SaveParamsAndSteadyStateStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"save_params_and_steady_state\""
|
||||
<< ", \"filename\": \"" << filename << "\""
|
||||
<< "}";
|
||||
}
|
||||
|
||||
LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename,
|
||||
const SymbolTable &symbol_table_arg,
|
||||
WarningConsolidation &warnings) :
|
||||
|
@ -511,6 +619,24 @@ LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
LoadParamsAndSteadyStateStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
output << "{\"statementName\": \"load_params_and_steady_state\""
|
||||
<< "\"values\": [";
|
||||
for (map<int, string>::const_iterator it = content.begin();
|
||||
it != content.end(); it++)
|
||||
{
|
||||
if (it != content.begin())
|
||||
output << ", ";
|
||||
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\""
|
||||
<< ", \"value\": \"" << it->second << "\"}";
|
||||
}
|
||||
output << "]"
|
||||
<< "}";
|
||||
}
|
||||
|
||||
void
|
||||
LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t &eval_context) const
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2016 Dynare Team
|
||||
* Copyright (C) 2003-2017 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -43,6 +43,7 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJuliaOutput(ostream &output, const string &basename);
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
//! Fill eval context with parameter value
|
||||
void fillEvalContext(eval_context_t &eval_context) const;
|
||||
};
|
||||
|
@ -69,6 +70,7 @@ public:
|
|||
void fillEvalContext(eval_context_t &eval_context) const;
|
||||
protected:
|
||||
void writeInitValues(ostream &output) const;
|
||||
void writeJsonInitValues(ostream &output) const;
|
||||
};
|
||||
|
||||
class InitValStatement : public InitOrEndValStatement
|
||||
|
@ -79,6 +81,7 @@ public:
|
|||
const bool &all_values_required_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
//! Writes initializations for oo_.exo_simul and oo_.exo_det_simul
|
||||
void writeOutputPostInit(ostream &output) const;
|
||||
};
|
||||
|
@ -92,6 +95,7 @@ public:
|
|||
//! Workaround for trac ticket #35
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class HistValStatement : public Statement
|
||||
|
@ -114,6 +118,7 @@ public:
|
|||
//! Workaround for trac ticket #157
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class InitvalFileStatement : public Statement
|
||||
|
@ -123,6 +128,7 @@ private:
|
|||
public:
|
||||
InitvalFileStatement(const string &filename_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class HistvalFileStatement : public Statement
|
||||
|
@ -132,6 +138,7 @@ private:
|
|||
public:
|
||||
HistvalFileStatement(const string &filename_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class HomotopyStatement : public Statement
|
||||
|
@ -147,6 +154,7 @@ public:
|
|||
HomotopyStatement(const homotopy_values_t &homotopy_values_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class SaveParamsAndSteadyStateStatement : public Statement
|
||||
|
@ -156,6 +164,7 @@ private:
|
|||
public:
|
||||
SaveParamsAndSteadyStateStatement(const string &filename_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class LoadParamsAndSteadyStateStatement : public Statement
|
||||
|
@ -172,6 +181,7 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
//! Fill eval context with parameters/variables values
|
||||
void fillEvalContext(eval_context_t &eval_context) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3189,7 +3189,7 @@ ParsingDriver::prior_posterior_function(bool prior_func)
|
|||
void
|
||||
ParsingDriver::add_ramsey_constraints_statement()
|
||||
{
|
||||
mod_file->addStatement(new RamseyConstraintsStatement(ramsey_constraints));
|
||||
mod_file->addStatement(new RamseyConstraintsStatement(mod_file->symbol_table, ramsey_constraints));
|
||||
ramsey_constraints.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,34 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
|
|||
output << "M_.exo_det_length = " << exo_det_length << ";\n";
|
||||
}
|
||||
|
||||
void
|
||||
AbstractShocksStatement::writeJsonDetShocks(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
output << "\"deterministic_shocks\": [";
|
||||
for (det_shocks_t::const_iterator it = det_shocks.begin();
|
||||
it != det_shocks.end(); it++)
|
||||
{
|
||||
if (it != det_shocks.begin())
|
||||
output << ", ";
|
||||
output << "{\"var\": \"" << symbol_table.getName(it->first) << "\", "
|
||||
<< "\"values\": [";
|
||||
for (vector<DetShockElement>::const_iterator it1 = it->second.begin();
|
||||
it1 != it->second.end(); it1++)
|
||||
{
|
||||
if (it1 != it->second.begin())
|
||||
output << ", ";
|
||||
output << "{\"period1\": " << it1->period1 << ", "
|
||||
<< "\"period2\": " << it1->period2 << ", "
|
||||
<< "\"value\": \"";
|
||||
it1->value->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
output << "]}";
|
||||
}
|
||||
output << "]";
|
||||
}
|
||||
|
||||
ShocksStatement::ShocksStatement(bool overwrite_arg,
|
||||
const det_shocks_t &det_shocks_arg,
|
||||
const var_and_std_shocks_t &var_shocks_arg,
|
||||
|
@ -123,6 +151,72 @@ ShocksStatement::writeOutput(ostream &output, const string &basename, bool minim
|
|||
output << "M_.sigma_e_is_diagonal = 1;" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
ShocksStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
output << "{\"statementName\": \"shocks\""
|
||||
<< ", \"overwrite\": ";
|
||||
if (overwrite)
|
||||
output << "true";
|
||||
else
|
||||
output << "false";
|
||||
if (!det_shocks.empty())
|
||||
{
|
||||
output << ", ";
|
||||
writeJsonDetShocks(output);
|
||||
}
|
||||
output<< ", \"variance\": [";
|
||||
for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); it != var_shocks.end(); it++)
|
||||
{
|
||||
if (it != var_shocks.begin())
|
||||
output << ", ";
|
||||
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\", "
|
||||
<< "\"variance\": \"";
|
||||
it->second->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
output << "]"
|
||||
<< ", \"stderr\": [";
|
||||
for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); it != std_shocks.end(); it++)
|
||||
{
|
||||
if (it != std_shocks.begin())
|
||||
output << ", ";
|
||||
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\", "
|
||||
<< "\"stderr\": \"";
|
||||
it->second->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
output << "]"
|
||||
<< ", \"covariance\": [";
|
||||
for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); it != covar_shocks.end(); it++)
|
||||
{
|
||||
if (it != covar_shocks.begin())
|
||||
output << ", ";
|
||||
output << "{"
|
||||
<< "\"name\": \"" << symbol_table.getName(it->first.first) << "\", "
|
||||
<< "\"name2\": \"" << symbol_table.getName(it->first.second) << "\", "
|
||||
<< "\"covariance\": \"";
|
||||
it->second->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
output << "]"
|
||||
<< ", \"correlation\": [";
|
||||
for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin(); it != corr_shocks.end(); it++)
|
||||
{
|
||||
if (it != corr_shocks.begin())
|
||||
output << ", ";
|
||||
output << "{"
|
||||
<< "\"name\": \"" << symbol_table.getName(it->first.first) << "\", "
|
||||
<< "\"name2\": \"" << symbol_table.getName(it->first.second) << "\", "
|
||||
<< "\"correlation\": \"";
|
||||
it->second->writeJsonOutput(output, temporary_terms_t(), tef_terms);
|
||||
output << "\"}";
|
||||
}
|
||||
output << "]"
|
||||
<< "}";
|
||||
}
|
||||
|
||||
void
|
||||
ShocksStatement::writeVarOrStdShock(ostream &output, var_and_std_shocks_t::const_iterator &it,
|
||||
bool stddev) const
|
||||
|
@ -430,6 +524,26 @@ MomentCalibration::writeOutput(ostream &output, const string &basename, bool min
|
|||
output << "};" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
MomentCalibration::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"moment_calibration\""
|
||||
<< ", \"moment_calibration_criteria\": [";
|
||||
for (constraints_t::const_iterator it = constraints.begin(); it != constraints.end(); it++)
|
||||
{
|
||||
if (it != constraints.begin())
|
||||
output << ", ";
|
||||
output << "{\"endogenous1\": \"" << symbol_table.getName(it->endo1) << "\""
|
||||
<< ", \"endogenous2\": \"" << symbol_table.getName(it->endo2) << "\""
|
||||
<< ", \"lags\": \"" << it->lags << "\""
|
||||
<< ", \"lower_bound\": \"" << it->lower_bound << "\""
|
||||
<< ", \"upper_bound\": \"" << it->upper_bound << "\""
|
||||
<< "}";
|
||||
}
|
||||
output << "]"
|
||||
<< "}";
|
||||
}
|
||||
|
||||
IrfCalibration::IrfCalibration(const constraints_t &constraints_arg,
|
||||
const SymbolTable &symbol_table_arg,
|
||||
const OptionsList &options_list_arg)
|
||||
|
@ -455,6 +569,32 @@ IrfCalibration::writeOutput(ostream &output, const string &basename, bool minima
|
|||
output << "};" << endl;
|
||||
}
|
||||
|
||||
void
|
||||
IrfCalibration::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"irf_calibration\"";
|
||||
if (options_list.getNumberOfOptions())
|
||||
{
|
||||
output << ", ";
|
||||
options_list.writeJsonOutput(output);
|
||||
}
|
||||
|
||||
output << ", \"irf_restrictions\": [";
|
||||
for (constraints_t::const_iterator it = constraints.begin(); it != constraints.end(); it++)
|
||||
{
|
||||
if (it != constraints.begin())
|
||||
output << ", ";
|
||||
output << "{\"endogenous\": \"" << symbol_table.getName(it->endo) << "\""
|
||||
<< ", \"exogenous\": \"" << symbol_table.getName(it->exo) << "\""
|
||||
<< ", \"periods\": \"" << it->periods << "\""
|
||||
<< ", \"lower_bound\": \"" << it->lower_bound << "\""
|
||||
<< ", \"upper_bound\": \"" << it->upper_bound << "\""
|
||||
<< "}";
|
||||
}
|
||||
output << "]"
|
||||
<< "}";
|
||||
}
|
||||
|
||||
ShockGroupsStatement::ShockGroupsStatement(const group_t &shock_groups_arg, const string &name_arg)
|
||||
: shock_groups(shock_groups_arg), name(name_arg)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ protected:
|
|||
const det_shocks_t det_shocks;
|
||||
const SymbolTable &symbol_table;
|
||||
void writeDetShocks(ostream &output) const;
|
||||
void writeJsonDetShocks(ostream &output) const;
|
||||
|
||||
AbstractShocksStatement(bool mshocks_arg, bool overwrite_arg,
|
||||
const det_shocks_t &det_shocks_arg,
|
||||
|
@ -77,8 +78,9 @@ public:
|
|||
const covar_and_corr_shocks_t &covar_shocks_arg,
|
||||
const covar_and_corr_shocks_t &corr_shocks_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class MShocksStatement : public AbstractShocksStatement
|
||||
|
@ -120,6 +122,7 @@ public:
|
|||
MomentCalibration(const constraints_t &constraints_arg,
|
||||
const SymbolTable &symbol_table_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class IrfCalibration : public Statement
|
||||
|
@ -141,6 +144,7 @@ public:
|
|||
const SymbolTable &symbol_table_arg,
|
||||
const OptionsList &options_list_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class ShockGroupsStatement : public Statement
|
||||
|
|
|
@ -82,6 +82,11 @@ Statement::writeJuliaOutput(ostream &output, const string &basename)
|
|||
{
|
||||
}
|
||||
|
||||
void
|
||||
Statement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Statement::computingPass()
|
||||
{
|
||||
|
@ -105,6 +110,14 @@ NativeStatement::writeOutput(ostream &output, const string &basename, bool minim
|
|||
output << ns << endl;
|
||||
}
|
||||
|
||||
void
|
||||
NativeStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"native\""
|
||||
<< ", \"string\": \"" << native_statement << "\""
|
||||
<< "}";
|
||||
}
|
||||
|
||||
VerbatimStatement::VerbatimStatement(const string &verbatim_statement_arg) :
|
||||
verbatim_statement(verbatim_statement_arg)
|
||||
{
|
||||
|
@ -116,6 +129,14 @@ VerbatimStatement::writeOutput(ostream &output, const string &basename, bool min
|
|||
output << verbatim_statement << endl;
|
||||
}
|
||||
|
||||
void
|
||||
VerbatimStatement::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "{\"statementName\": \"verbatim\""
|
||||
<< ", \"string\": \"" << verbatim_statement << "\""
|
||||
<< "}";
|
||||
}
|
||||
|
||||
void
|
||||
OptionsList::writeOutput(ostream &output) const
|
||||
{
|
||||
|
@ -209,6 +230,100 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
OptionsList::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
if (getNumberOfOptions() == 0)
|
||||
return;
|
||||
|
||||
output << "\"options\": {";
|
||||
for (num_options_t::const_iterator it = num_options.begin();
|
||||
it != num_options.end();)
|
||||
{
|
||||
output << "\""<< it->first << "\": " << it->second;
|
||||
it++;
|
||||
if (it != num_options.end()
|
||||
|| !(paired_num_options.empty()
|
||||
&& string_options.empty()
|
||||
&& date_options.empty()
|
||||
&& symbol_list_options.empty()
|
||||
&& vector_int_options.empty()))
|
||||
output << ", ";
|
||||
}
|
||||
|
||||
for (paired_num_options_t::const_iterator it = paired_num_options.begin();
|
||||
it != paired_num_options.end();)
|
||||
{
|
||||
output << "\""<< it->first << "\": [" << it->second.first << " " << it->second.second << "]";
|
||||
it++;
|
||||
if (it != paired_num_options.end()
|
||||
|| !(string_options.empty()
|
||||
&& date_options.empty()
|
||||
&& symbol_list_options.empty()
|
||||
&& vector_int_options.empty()))
|
||||
output << ", ";
|
||||
}
|
||||
|
||||
for (string_options_t::const_iterator it = string_options.begin();
|
||||
it != string_options.end();)
|
||||
{
|
||||
output << "\""<< it->first << "\": \"" << it->second << "\"";
|
||||
it++;
|
||||
if (it != string_options.end()
|
||||
|| !(date_options.empty()
|
||||
&& symbol_list_options.empty()
|
||||
&& vector_int_options.empty()))
|
||||
output << ", ";
|
||||
}
|
||||
|
||||
for (date_options_t::const_iterator it = date_options.begin();
|
||||
it != date_options.end();)
|
||||
{
|
||||
output << "\""<< it->first << "\": \"" << it->second << "\"";
|
||||
it++;
|
||||
if (it != date_options.end()
|
||||
|| !(symbol_list_options.empty()
|
||||
&& vector_int_options.empty()))
|
||||
output << ", ";
|
||||
}
|
||||
|
||||
for (symbol_list_options_t::const_iterator it = symbol_list_options.begin();
|
||||
it != symbol_list_options.end(); it++)
|
||||
{
|
||||
output << "\""<< it->first << "\":";
|
||||
it->second.writeJsonOutput(output);
|
||||
it++;
|
||||
if (it != symbol_list_options.end()
|
||||
|| !vector_int_options.empty())
|
||||
output << ", ";
|
||||
}
|
||||
|
||||
for (vec_int_options_t::const_iterator it = vector_int_options.begin();
|
||||
it != vector_int_options.end();)
|
||||
{
|
||||
output << "\""<< it->first << "\": [";
|
||||
if (it->second.size() > 1)
|
||||
{
|
||||
for (vector<int>::const_iterator viit = it->second.begin();
|
||||
viit != it->second.end();)
|
||||
{
|
||||
output << *viit;
|
||||
viit++;
|
||||
if (viit != it->second.end())
|
||||
output << ", ";
|
||||
}
|
||||
}
|
||||
else
|
||||
output << it->second.front() << endl;
|
||||
output << "]";
|
||||
it++;
|
||||
if (it != vector_int_options.end())
|
||||
output << ", ";
|
||||
}
|
||||
|
||||
output << "}";
|
||||
}
|
||||
|
||||
void
|
||||
OptionsList::clear()
|
||||
{
|
||||
|
@ -219,3 +334,14 @@ OptionsList::clear()
|
|||
symbol_list_options.clear();
|
||||
vector_int_options.clear();
|
||||
}
|
||||
|
||||
int
|
||||
OptionsList::getNumberOfOptions() const
|
||||
{
|
||||
return num_options.size()
|
||||
+ paired_num_options.size()
|
||||
+ string_options.size()
|
||||
+ date_options.size()
|
||||
+ symbol_list_options.size()
|
||||
+ vector_int_options.size();
|
||||
}
|
||||
|
|
|
@ -141,6 +141,7 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const = 0;
|
||||
virtual void writeCOutput(ostream &output, const string &basename);
|
||||
virtual void writeJuliaOutput(ostream &output, const string &basename);
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class NativeStatement : public Statement
|
||||
|
@ -150,6 +151,7 @@ private:
|
|||
public:
|
||||
NativeStatement(const string &native_statement_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class VerbatimStatement : public Statement
|
||||
|
@ -159,6 +161,7 @@ private:
|
|||
public:
|
||||
VerbatimStatement(const string &verbatim_statement_arg);
|
||||
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
|
||||
virtual void writeJsonOutput(ostream &output) const;
|
||||
};
|
||||
|
||||
class OptionsList
|
||||
|
@ -176,8 +179,10 @@ public:
|
|||
date_options_t date_options;
|
||||
symbol_list_options_t symbol_list_options;
|
||||
vec_int_options_t vector_int_options;
|
||||
int getNumberOfOptions() const;
|
||||
void writeOutput(ostream &output) const;
|
||||
void writeOutput(ostream &output, const string &option_group) const;
|
||||
void writeJsonOutput(ostream &output) const;
|
||||
void clear();
|
||||
};
|
||||
|
||||
|
|
|
@ -2412,3 +2412,384 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons
|
|||
|
||||
paramsDerivsFile.close();
|
||||
}
|
||||
|
||||
void
|
||||
StaticModel::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
writeJsonModelEquations(output, false);
|
||||
}
|
||||
|
||||
void
|
||||
StaticModel::writeJsonComputingPassOutput(ostream &output, bool writeDetails) const
|
||||
{
|
||||
ostringstream model_local_vars_output; // Used for storing model local vars
|
||||
ostringstream model_output; // Used for storing model
|
||||
ostringstream jacobian_output; // Used for storing jacobian equations
|
||||
ostringstream hessian_output; // Used for storing Hessian equations
|
||||
ostringstream third_derivatives_output; // Used for storing third order derivatives equations
|
||||
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
temporary_terms_t temp_term_empty;
|
||||
temporary_terms_t temp_term_union = temporary_terms_res;
|
||||
temporary_terms_t temp_term_union_m_1;
|
||||
|
||||
string concat = "";
|
||||
|
||||
writeJsonModelLocalVariables(model_local_vars_output, tef_terms);
|
||||
|
||||
writeJsonTemporaryTerms(temporary_terms_res, temp_term_union_m_1, model_output, tef_terms, concat);
|
||||
model_output << ", ";
|
||||
writeJsonModelEquations(model_output, true);
|
||||
|
||||
int nrows = equations.size();
|
||||
int JacobianColsNbr = symbol_table.endo_nbr();
|
||||
int hessianColsNbr = JacobianColsNbr*JacobianColsNbr;
|
||||
|
||||
// Write Jacobian w.r. to endogenous only
|
||||
temp_term_union_m_1 = temp_term_union;
|
||||
temp_term_union.insert(temporary_terms_g1.begin(), temporary_terms_g1.end());
|
||||
concat = "jacobian";
|
||||
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, jacobian_output, tef_terms, concat);
|
||||
jacobian_output << ", \"jacobian\": {"
|
||||
<< " \"nrows\": " << nrows
|
||||
<< ", \"ncols\": " << JacobianColsNbr
|
||||
<< ", \"entries\": [";
|
||||
for (first_derivatives_t::const_iterator it = first_derivatives.begin();
|
||||
it != first_derivatives.end(); it++)
|
||||
{
|
||||
if (it != first_derivatives.begin())
|
||||
jacobian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var = it->first.second;
|
||||
int symb_id = getSymbIDByDerivID(var);
|
||||
int col = symbol_table.getTypeSpecificID(symb_id);
|
||||
expr_t d1 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(symb_id) << "\"";
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"col\": " << col + 1
|
||||
<< ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, temp_term_union, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
jacobian_output << "]}";
|
||||
|
||||
int g2ncols = symbol_table.endo_nbr() * symbol_table.endo_nbr();
|
||||
// Write Hessian w.r. to endogenous only (only if 2nd order derivatives have been computed)
|
||||
temp_term_union_m_1 = temp_term_union;
|
||||
temp_term_union.insert(temporary_terms_g2.begin(), temporary_terms_g2.end());
|
||||
concat = "hessian";
|
||||
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, hessian_output, tef_terms, concat);
|
||||
hessian_output << ", \"hessian\": {"
|
||||
<< " \"nrows\": " << equations.size()
|
||||
<< ", \"ncols\": " << g2ncols
|
||||
<< ", \"entries\": [";
|
||||
for (second_derivatives_t::const_iterator it = second_derivatives.begin();
|
||||
it != second_derivatives.end(); it++)
|
||||
{
|
||||
if (it != second_derivatives.begin())
|
||||
hessian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int symb_id1 = getSymbIDByDerivID(it->first.second.first);
|
||||
int symb_id2 = getSymbIDByDerivID(it->first.second.second);
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int tsid1 = symbol_table.getTypeSpecificID(symb_id1);
|
||||
int tsid2 = symbol_table.getTypeSpecificID(symb_id2);
|
||||
|
||||
int col = tsid1*symbol_table.endo_nbr()+tsid2;
|
||||
int col_sym = tsid2*symbol_table.endo_nbr()+tsid1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(symb_id1) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(symb_id2) << "\"";
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
|
||||
hessian_output << ", \"col\": [" << col + 1;
|
||||
if (symb_id1 != symb_id2)
|
||||
hessian_output << ", " << col_sym + 1;
|
||||
hessian_output << "]"
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian_output, temp_term_union, tef_terms);
|
||||
hessian_output << "\"}" << endl;
|
||||
}
|
||||
hessian_output << "]}";
|
||||
|
||||
// Writing third derivatives
|
||||
temp_term_union_m_1 = temp_term_union;
|
||||
temp_term_union.insert(temporary_terms_g3.begin(), temporary_terms_g3.end());
|
||||
concat = "third_derivatives";
|
||||
writeJsonTemporaryTerms(temp_term_union, temp_term_union_m_1, third_derivatives_output, tef_terms, concat);
|
||||
third_derivatives_output << ", \"third_derivative\": {"
|
||||
<< " \"nrows\": " << equations.size()
|
||||
<< ", \"ncols\": " << hessianColsNbr * JacobianColsNbr
|
||||
<< ", \"entries\": [";
|
||||
for (third_derivatives_t::const_iterator it = third_derivatives.begin();
|
||||
it != third_derivatives.end(); it++)
|
||||
{
|
||||
if (it != third_derivatives.begin())
|
||||
third_derivatives_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var1 = it->first.second.first;
|
||||
int var2 = it->first.second.second.first;
|
||||
int var3 = it->first.second.second.second;
|
||||
expr_t d3 = it->second;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivatives_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"var3\": \"" << symbol_table.getName(getSymbIDByDerivID(var3)) << "\"";
|
||||
else
|
||||
third_derivatives_output << "{\"row\": " << eq + 1;
|
||||
|
||||
int id1 = getSymbIDByDerivID(var1);
|
||||
int id2 = getSymbIDByDerivID(var2);
|
||||
int id3 = getSymbIDByDerivID(var3);
|
||||
set<int> cols;
|
||||
cols.insert(id1 * hessianColsNbr + id2 * JacobianColsNbr + id3);
|
||||
cols.insert(id1 * hessianColsNbr + id3 * JacobianColsNbr + id2);
|
||||
cols.insert(id2 * hessianColsNbr + id1 * JacobianColsNbr + id3);
|
||||
cols.insert(id2 * hessianColsNbr + id3 * JacobianColsNbr + id1);
|
||||
cols.insert(id3 * hessianColsNbr + id1 * JacobianColsNbr + id2);
|
||||
cols.insert(id3 * hessianColsNbr + id2 * JacobianColsNbr + id1);
|
||||
|
||||
third_derivatives_output << ", \"col\": [";
|
||||
for (set<int>::iterator it2 = cols.begin(); it2 != cols.end(); it2++)
|
||||
{
|
||||
if (it2 != cols.begin())
|
||||
third_derivatives_output << ", ";
|
||||
third_derivatives_output << *it2 + 1;
|
||||
}
|
||||
third_derivatives_output << "]"
|
||||
<< ", \"val\": \"";
|
||||
d3->writeJsonOutput(third_derivatives_output, temp_term_union, tef_terms);
|
||||
third_derivatives_output << "\"}" << endl;
|
||||
}
|
||||
third_derivatives_output << "]}";
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"static_model_derivative_details\": {";
|
||||
else
|
||||
output << "\"static_model_derivatives\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
<< ", " << hessian_output.str()
|
||||
<< ", " << third_derivatives_output.str()
|
||||
<< "}";
|
||||
}
|
||||
|
||||
void
|
||||
StaticModel::writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) const
|
||||
{
|
||||
if (!residuals_params_derivatives.size()
|
||||
&& !residuals_params_second_derivatives.size()
|
||||
&& !jacobian_params_derivatives.size()
|
||||
&& !jacobian_params_second_derivatives.size()
|
||||
&& !hessian_params_derivatives.size())
|
||||
return;
|
||||
|
||||
ostringstream model_local_vars_output; // Used for storing model local vars
|
||||
ostringstream model_output; // Used for storing model temp vars and equations
|
||||
ostringstream jacobian_output; // Used for storing jacobian equations
|
||||
ostringstream hessian_output; // Used for storing Hessian equations
|
||||
ostringstream hessian1_output; // Used for storing Hessian equations
|
||||
ostringstream third_derivs_output; // Used for storing third order derivatives equations
|
||||
ostringstream third_derivs1_output; // Used for storing third order derivatives equations
|
||||
|
||||
deriv_node_temp_terms_t tef_terms;
|
||||
writeJsonModelLocalVariables(model_local_vars_output, tef_terms);
|
||||
|
||||
temporary_terms_t temp_terms_empty;
|
||||
string concat = "all";
|
||||
writeJsonTemporaryTerms(params_derivs_temporary_terms, temp_terms_empty, model_output, tef_terms, concat);
|
||||
jacobian_output << "\"deriv_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nparamcols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (first_derivatives_t::const_iterator it = residuals_params_derivatives.begin();
|
||||
it != residuals_params_derivatives.end(); it++)
|
||||
{
|
||||
if (it != residuals_params_derivatives.begin())
|
||||
jacobian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int param = it->first.second;
|
||||
expr_t d1 = it->second;
|
||||
|
||||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
jacobian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
else
|
||||
jacobian_output << "{\"row\": " << eq + 1;
|
||||
jacobian_output << ", \"param_col\": " << param_col
|
||||
<< ", \"val\": \"";
|
||||
d1->writeJsonOutput(jacobian_output, params_derivs_temporary_terms, tef_terms);
|
||||
jacobian_output << "\"}" << endl;
|
||||
}
|
||||
jacobian_output << "]}";
|
||||
hessian_output << "\"deriv_jacobian_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nvarcols\": " << symbol_table.endo_nbr()
|
||||
<< ", \"nparamcols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (second_derivatives_t::const_iterator it = jacobian_params_derivatives.begin();
|
||||
it != jacobian_params_derivatives.end(); it++)
|
||||
{
|
||||
if (it != jacobian_params_derivatives.begin())
|
||||
hessian_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var = it->first.second.first;
|
||||
int param = it->first.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int var_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(var)) + 1;
|
||||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(getSymbIDByDerivID(var)) << "\""
|
||||
<< ", \"param\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
else
|
||||
hessian_output << "{\"row\": " << eq + 1;
|
||||
hessian_output << ", \"var_col\": " << var_col
|
||||
<< ", \"param_col\": " << param_col
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian_output, params_derivs_temporary_terms, tef_terms);
|
||||
hessian_output << "\"}" << endl;
|
||||
}
|
||||
hessian_output << "]}";
|
||||
|
||||
hessian1_output << "\"second_deriv_residuals_wrt_params\": {"
|
||||
<< " \"nrows\": " << equations.size()
|
||||
<< ", \"nparam1cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"nparam2cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (second_derivatives_t::const_iterator it = residuals_params_second_derivatives.begin();
|
||||
it != residuals_params_second_derivatives.end(); ++it)
|
||||
{
|
||||
if (it != residuals_params_second_derivatives.begin())
|
||||
hessian1_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int param1 = it->first.second.first;
|
||||
int param2 = it->first.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1;
|
||||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
hessian1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
else
|
||||
hessian1_output << "{\"row\": " << eq + 1;
|
||||
hessian1_output << ", \"param1_col\": " << param1_col
|
||||
<< ", \"param2_col\": " << param2_col
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(hessian1_output, params_derivs_temporary_terms, tef_terms);
|
||||
hessian1_output << "\"}" << endl;
|
||||
}
|
||||
hessian1_output << "]}";
|
||||
third_derivs_output << "\"second_deriv_jacobian_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nvarcols\": " << symbol_table.endo_nbr()
|
||||
<< ", \"nparam1cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"nparam2cols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (third_derivatives_t::const_iterator it = jacobian_params_second_derivatives.begin();
|
||||
it != jacobian_params_second_derivatives.end(); ++it)
|
||||
{
|
||||
if (it != jacobian_params_second_derivatives.begin())
|
||||
third_derivs_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var = it->first.second.first;
|
||||
int param1 = it->first.second.second.first;
|
||||
int param2 = it->first.second.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int var_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(var)) + 1;
|
||||
int param1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param1)) + 1;
|
||||
int param2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param2)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var\": \"" << symbol_table.getName(var) << "\""
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param1)) << "\""
|
||||
<< ", \"param2\": \"" << symbol_table.getName(getSymbIDByDerivID(param2)) << "\"";
|
||||
else
|
||||
third_derivs_output << "{\"row\": " << eq + 1;
|
||||
third_derivs_output << ", \"var_col\": " << var_col
|
||||
<< ", \"param1_col\": " << param1_col
|
||||
<< ", \"param2_col\": " << param2_col
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs_output << "\"}" << endl;
|
||||
}
|
||||
third_derivs_output << "]}" << endl;
|
||||
|
||||
third_derivs1_output << "\"derivative_hessian_wrt_params\": {"
|
||||
<< " \"neqs\": " << equations.size()
|
||||
<< ", \"nvar1cols\": " << symbol_table.endo_nbr()
|
||||
<< ", \"nvar2cols\": " << symbol_table.endo_nbr()
|
||||
<< ", \"nparamcols\": " << symbol_table.param_nbr()
|
||||
<< ", \"entries\": [";
|
||||
for (third_derivatives_t::const_iterator it = hessian_params_derivatives.begin();
|
||||
it != hessian_params_derivatives.end(); ++it)
|
||||
{
|
||||
if (it != hessian_params_derivatives.begin())
|
||||
third_derivs1_output << ", ";
|
||||
|
||||
int eq = it->first.first;
|
||||
int var1 = it->first.second.first;
|
||||
int var2 = it->first.second.second.first;
|
||||
int param = it->first.second.second.second;
|
||||
expr_t d2 = it->second;
|
||||
|
||||
int var1_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(var1)) + 1;
|
||||
int var2_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(var2)) + 1;
|
||||
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
|
||||
|
||||
if (writeDetails)
|
||||
third_derivs1_output << "{\"eq\": " << eq + 1
|
||||
<< ", \"var1\": \"" << symbol_table.getName(getSymbIDByDerivID(var1)) << "\""
|
||||
<< ", \"var2\": \"" << symbol_table.getName(getSymbIDByDerivID(var2)) << "\""
|
||||
<< ", \"param1\": \"" << symbol_table.getName(getSymbIDByDerivID(param)) << "\"";
|
||||
else
|
||||
third_derivs1_output << "{\"row\": " << eq + 1;
|
||||
third_derivs1_output << ", \"var1_col\": " << var1_col
|
||||
<< ", \"var2_col\": " << var2_col
|
||||
<< ", \"param_col\": " << param_col
|
||||
<< ", \"val\": \"";
|
||||
d2->writeJsonOutput(third_derivs1_output, params_derivs_temporary_terms, tef_terms);
|
||||
third_derivs1_output << "\"}" << endl;
|
||||
}
|
||||
third_derivs1_output << "]}" << endl;
|
||||
|
||||
if (writeDetails)
|
||||
output << "\"static_model_params_derivative_details\": {";
|
||||
else
|
||||
output << "\"static_model_params_derivatives\": {";
|
||||
output << model_local_vars_output.str()
|
||||
<< ", " << model_output.str()
|
||||
<< ", " << jacobian_output.str()
|
||||
<< ", " << hessian_output.str()
|
||||
<< ", " << hessian1_output.str()
|
||||
<< ", " << third_derivs_output.str()
|
||||
<< ", " << third_derivs1_output.str()
|
||||
<< "}";
|
||||
}
|
||||
|
|
|
@ -170,6 +170,15 @@ public:
|
|||
//! Writes static model file
|
||||
void writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, bool julia) const;
|
||||
|
||||
//! Write JSON Output (used by PlannerObjectiveStatement)
|
||||
void writeJsonOutput(ostream &output) const;
|
||||
|
||||
//! Write JSON representation of static model
|
||||
void writeJsonComputingPassOutput(ostream &output, bool writeDetails) const;
|
||||
|
||||
//! Writes file containing static parameters derivatives
|
||||
void writeJsonParamsDerivativesFile(ostream &output, bool writeDetails) const;
|
||||
|
||||
//! Writes file containing static parameters derivatives
|
||||
void writeParamsDerivativesFile(const string &basename, bool julia) const;
|
||||
|
||||
|
|
|
@ -59,6 +59,20 @@ SymbolList::getSymbols() const
|
|||
return symbols;
|
||||
}
|
||||
|
||||
void
|
||||
SymbolList::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "\"symbol_list\": [";
|
||||
for (vector<string>::const_iterator it = symbols.begin();
|
||||
it != symbols.end(); ++it)
|
||||
{
|
||||
if (it != symbols.begin())
|
||||
output << ",";
|
||||
output << "\"" << *it << "\"";
|
||||
}
|
||||
output << "]";
|
||||
}
|
||||
|
||||
void
|
||||
SymbolList::clear()
|
||||
{
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
void writeOutput(const string &varname, ostream &output) const;
|
||||
//! Output content in Matlab format without preceding varname of writeOutput
|
||||
void write(ostream &output) const;
|
||||
//! Write JSON output
|
||||
void writeJsonOutput(ostream &output) const;
|
||||
//! Clears all content
|
||||
void clear();
|
||||
//! Get a copy of the string vector
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
#include "SymbolTable.hh"
|
||||
|
||||
|
@ -138,6 +139,17 @@ SymbolTable::freeze() throw (FrozenException)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
SymbolTable::unfreeze()
|
||||
{
|
||||
frozen = false;
|
||||
endo_ids.clear();
|
||||
exo_ids.clear();
|
||||
exo_det_ids.clear();
|
||||
param_ids.clear();
|
||||
type_specific_ids.clear();
|
||||
}
|
||||
|
||||
void
|
||||
SymbolTable::changeType(int id, SymbolType newtype) throw (UnknownSymbolIDException, FrozenException)
|
||||
{
|
||||
|
@ -1067,3 +1079,36 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
|
|||
output << " ]" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SymbolTable::writeJsonOutput(ostream &output) const
|
||||
{
|
||||
output << "\"endogenous\": ";
|
||||
writeJsonVarVector(output, endo_ids);
|
||||
|
||||
output << ", \"exogenous\":";
|
||||
writeJsonVarVector(output, exo_ids);
|
||||
|
||||
output << ", \"exogenous_deterministic\": ";
|
||||
writeJsonVarVector(output, exo_det_ids);
|
||||
|
||||
output << ", \"parameters\": ";
|
||||
writeJsonVarVector(output, param_ids);
|
||||
}
|
||||
|
||||
void
|
||||
SymbolTable::writeJsonVarVector(ostream &output, const vector<int> &varvec) const
|
||||
{
|
||||
output << "[";
|
||||
for (size_t i = 0; i < varvec.size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
output << ", ";
|
||||
output << "{"
|
||||
<< "\"name\":\"" << getName(varvec[i]) << "\", "
|
||||
<< "\"texName\":\"" << boost::replace_all_copy(getTeXName(varvec[i]), "\\", "\\\\") << "\", "
|
||||
<< "\"longName\":\"" << boost::replace_all_copy(getLongName(varvec[i]), "\\", "\\\\") << "\"}"
|
||||
<< endl;
|
||||
}
|
||||
output << "]" << endl;
|
||||
}
|
||||
|
|
|
@ -224,7 +224,8 @@ private:
|
|||
int addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag, expr_t arg) throw (FrozenException);
|
||||
//! Factorized code for adding aux lead variables
|
||||
int addLeadAuxiliaryVarInternal(bool endo, int index, expr_t arg) throw (FrozenException);
|
||||
|
||||
//! Factorized code for Json writing
|
||||
void writeJsonVarVector(ostream &output, const vector<int> &varvec) const;
|
||||
public:
|
||||
//! Add a symbol
|
||||
/*! Returns the symbol ID */
|
||||
|
@ -317,6 +318,9 @@ public:
|
|||
int getID(SymbolType type, int tsid) const throw (UnknownTypeSpecificIDException, NotYetFrozenException);
|
||||
//! Freeze symbol table
|
||||
void freeze() throw (FrozenException);
|
||||
//! unreeze symbol table
|
||||
//! Used after having written JSON files
|
||||
void unfreeze();
|
||||
//! Change the type of a symbol
|
||||
void changeType(int id, SymbolType newtype) throw (UnknownSymbolIDException, FrozenException);
|
||||
//! Get type specific ID (by symbol ID)
|
||||
|
@ -337,6 +341,8 @@ public:
|
|||
inline int orig_endo_nbr() const throw (NotYetFrozenException);
|
||||
//! Write output of this class
|
||||
void writeOutput(ostream &output) const throw (NotYetFrozenException);
|
||||
//! Write JSON Output
|
||||
void writeJsonOutput(ostream &output) const;
|
||||
//! Write Julia output of this class
|
||||
void writeJuliaOutput(ostream &output) const throw (NotYetFrozenException);
|
||||
//! Write C output of this class
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
*.prn
|
||||
*_simul
|
||||
*-macroexp.mod
|
||||
*.json
|
||||
|
||||
wsOct
|
||||
/run_test_octave_output.txt
|
||||
|
|
|
@ -28,6 +28,7 @@ MODFILES = \
|
|||
estimation/fs2000_MCMC_jumping_covariance.mod \
|
||||
ms-sbvar/test_ms_variances_repeated_runs.mod \
|
||||
fs2000/fs2000.mod \
|
||||
ls2003/ls2003_hessian_zero.mod \
|
||||
ep/rbc.mod \
|
||||
exogenous-observed-variables/preprocessor.mod \
|
||||
estimation/fs2000_with_weibull_prior.mod \
|
||||
|
@ -725,6 +726,7 @@ EXTRA_DIST = \
|
|||
read_trs_files.sh \
|
||||
run_test_matlab.m \
|
||||
run_test_octave.m \
|
||||
load_octave_packages.m \
|
||||
$(MODFILES) \
|
||||
$(XFAIL_MODFILES) \
|
||||
$(MFILES) \
|
||||
|
@ -915,7 +917,11 @@ clean-local:
|
|||
$(patsubst %.trs, %.log, $(M_TRS_FILES)) \
|
||||
$(patsubst %.trs, %.log, $(M_XFAIL_TRS_FILES)) \
|
||||
$(patsubst %.trs, %.log, $(O_TRS_FILES)) \
|
||||
$(patsubst %.trs, %.log, $(O_XFAIL_TRS_FILES))
|
||||
$(patsubst %.trs, %.log, $(O_XFAIL_TRS_FILES)) \
|
||||
$(patsubst %.trs, %.json, $(M_TRS_FILES)) \
|
||||
$(patsubst %.trs, %.json, $(M_XFAIL_TRS_FILES)) \
|
||||
$(patsubst %.trs, %.json, $(O_TRS_FILES)) \
|
||||
$(patsubst %.trs, %.json, $(O_XFAIL_TRS_FILES))
|
||||
|
||||
rm -f $(patsubst %.mod, %.m, $(MODFILES)) \
|
||||
$(patsubst %.mod, %_static.*, $(MODFILES)) \
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
//test whether Dynare correctly reverts to linear approximation if 0 Hessian is detected
|
||||
|
||||
var y y_s R pie dq pie_s de A y_obs pie_obs R_obs;
|
||||
varexo e_R e_q e_ys e_pies e_A;
|
||||
|
||||
parameters psi1 psi2 psi3 rho_R tau alpha rr k rho_q rho_A rho_ys rho_pies;
|
||||
|
||||
psi1 = 1.54;
|
||||
psi2 = 0.25;
|
||||
psi3 = 0.25;
|
||||
rho_R = 0.5;
|
||||
alpha = 0.3;
|
||||
rr = 2.51;
|
||||
k = 0.5;
|
||||
tau = 0.5;
|
||||
rho_q = 0.4;
|
||||
rho_A = 0.2;
|
||||
rho_ys = 0.9;
|
||||
rho_pies = 0.7;
|
||||
|
||||
|
||||
model;
|
||||
y = y(+1) - (tau +alpha*(2-alpha)*(1-tau))*(R-pie(+1))-alpha*(tau +alpha*(2-alpha)*(1-tau))*dq(+1) + alpha*(2-alpha)*((1-tau)/tau)*(y_s-y_s(+1))-A(+1);
|
||||
pie = exp(-rr/400)*pie(+1)+alpha*exp(-rr/400)*dq(+1)-alpha*dq+(k/(tau+alpha*(2-alpha)*(1-tau)))*y+alpha*(2-alpha)*(1-tau)/(tau*(tau+alpha*(2-alpha)*(1-tau)))*y_s;
|
||||
pie = de+(1-alpha)*dq+pie_s;
|
||||
R = rho_R*R(-1)+(1-rho_R)*(psi1*pie+psi2*(y+alpha*(2-alpha)*((1-tau)/tau)*y_s)+psi3*de)+e_R;
|
||||
dq = rho_q*dq(-1)+e_q;
|
||||
y_s = rho_ys*y_s(-1)+e_ys;
|
||||
pie_s = rho_pies*pie_s(-1)+e_pies;
|
||||
A = rho_A*A(-1)+e_A;
|
||||
y_obs = y-y(-1)+A;
|
||||
pie_obs = 4*pie;
|
||||
R_obs = 4*R;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e_R = 1.25^2;
|
||||
var e_q = 2.5^2;
|
||||
var e_A = 1.89;
|
||||
var e_ys = 1.89;
|
||||
var e_pies = 1.89;
|
||||
end;
|
||||
|
||||
stoch_simul(order=2);
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
top_test_dir = getenv('TOP_TEST_DIR');
|
||||
addpath(top_test_dir);
|
||||
addpath('.'); % workaround for bug in Octave 4.2.0-rc2: https://savannah.gnu.org/bugs/?49334
|
||||
addpath([top_test_dir filesep '..' filesep 'matlab']);
|
||||
|
||||
## Test Dynare Version
|
||||
|
|
Loading…
Reference in New Issue