diff --git a/Makefile.am b/Makefile.am index ce8c90a7dc25cf245be1236e67b714146c8797ff..404e051a34851560d9ac11139237c74cc0306481 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,6 @@ ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = \ matlab \ - dynare++ \ contrib \ NEWS.md \ license.txt \ diff --git a/doc/Makefile.am b/doc/Makefile.am index f16874bbbb282f7cd98d3d60256c5660651831c6..925ed8cf0bcc904f315ab6149a2766f3e9014649 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = parallel internals gsa dseries-and-reporting if ENABLE_DOC SUBDIRS += manual -pdf-local: guide.pdf bvar-a-la-sims.pdf dr.pdf +pdf-local: guide.pdf bvar-a-la-sims.pdf dr.pdf sylvester.pdf tl.pdf endif EXTRA_DIST = guide.tex guide.bbl bibmad.sty bvar-a-la-sims.tex dr.tex dr.bib dynare.plots @@ -21,6 +21,14 @@ dr.pdf: dr.tex $(PDFLATEX) dr $(PDFLATEX) dr +sylvester.pdf: sylvester.tex + $(PDFLATEX) sylvester + $(PDFLATEX) sylvester + +tl.pdf: tl.tex + $(PDFLATEX) tl + $(PDFLATEX) tl + clean-local: # Do not delete guide.bbl which is not autogenerated rm -f *~ *.pdf *.log *.aux *.out *.blg dr.bbl diff --git a/doc/dr.tex b/doc/dr.tex index 65559c68fbee733efe00aabdf4af179664735e5e..71abf27f38dc77e20f5247f77f241a803f7ecbb0 100644 --- a/doc/dr.tex +++ b/doc/dr.tex @@ -650,7 +650,7 @@ equation is: In the general case, this equation is a specialized Sylvester equation, which can be solved using the algorithm proposed by \citet{kamenik:2004}\footnote{This paper is distributed with Dynare, in the - \texttt{sylvester.pdf} file under the Dynare++ documentation directory.}. + \texttt{sylvester.pdf} file under the documentation directory.}. \bibliographystyle{elsarticle-harv} \bibliography{dr} diff --git a/dynare++/doc/sylvester.tex b/doc/sylvester.tex similarity index 100% rename from dynare++/doc/sylvester.tex rename to doc/sylvester.tex diff --git a/dynare++/doc/tl.tex b/doc/tl.tex similarity index 100% rename from dynare++/doc/tl.tex rename to doc/tl.tex diff --git a/dynare++/Makefile.am b/dynare++/Makefile.am deleted file mode 100644 index 806c55dbeb43158fadd1c82efbbfc9c4913b050d..0000000000000000000000000000000000000000 --- a/dynare++/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -SUBDIRS = utils/cc sylv parser/cc tl doc integ kord src tests - -EXTRA_DIST = dynare_simul - -install-exec-local: - $(MKDIR_P) $(DESTDIR)$(pkglibdir)/dynare++ - cp -r dynare_simul/* $(DESTDIR)$(pkglibdir)/dynare++ - -uninstall-local: - rm -rf $(DESTDIR)$(pkglibdir)/dynare++ - diff --git a/dynare++/doc/Makefile.am b/dynare++/doc/Makefile.am deleted file mode 100644 index 9d787d9b04db654e149f38f72da5645958001a86..0000000000000000000000000000000000000000 --- a/dynare++/doc/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -EXTRA_DIST = \ - dynare++-ramsey.tex \ - dynare++-tutorial.tex \ - sylvester.tex \ - tl.tex \ - changelog-old.html \ - changelog-sylv-old.html - -if ENABLE_DOC -pdf-local: dynare++-ramsey.pdf dynare++-tutorial.pdf sylvester.pdf tl.pdf -endif - -%.pdf: %.tex - $(PDFLATEX) $< - $(PDFLATEX) $< - $(PDFLATEX) $< - -CLEANFILES = *.pdf *.log *.aux *.out *.toc - - diff --git a/dynare++/doc/changelog-old.html b/dynare++/doc/changelog-old.html deleted file mode 100644 index d7a4c4923353046c03e199f6e2f86870de417790..0000000000000000000000000000000000000000 --- a/dynare++/doc/changelog-old.html +++ /dev/null @@ -1,280 +0,0 @@ -<HTML> -<TITLE> -Dynare++ Change Log -</TITLE> -<!-- $Header$ --> -<BODY> -<TABLE CELLSPACING=2 ALIGN="CENTER" BORDER=1> -<TR> -<TD BGCOLOR="#d0d0d0" WIDTH="85"> <b>Revision</b> </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="85"> <b>Version</b></TD> -<TD BGCOLOR="#d0d0d0" WIDTH="80"> <b>Date</b> </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="600"> <b>Description of changes</b></TD> -</TR> - -<TR> -<TD> -<TD>1.3.7 -<TD>2008/01/15 -<TD> - -<TR><TD><TD><TD> <TD> Corrected a serious bug in centralizing a -decision rule. This bug implies that all results based on simulations -of the decision rule were wrong. However results based on stochastic -fix points were correct. Thanks to Wouter J. den Haan and Joris de Wind! - -<TR><TD><TD><TD> <TD> Added options --centralize and --no-centralize. - -<TR><TD><TD><TD> <TD> Corrected an error of a wrong -variance-covariance matrix in real-time simulations (thanks to Pawel -Zabzcyk). - -<TR><TD><TD><TD> <TD> Corrected a bug of integer overflow in refined -faa Di Bruno formula if one of refinements is empty. This bug appeared -when solving models without forward looking variables. - -<TR><TD><TD><TD> <TD> Corrected a bug in the Sylvester equation -formerly working only for models with forward looking variables. - -<TR><TD><TD><TD> <TD> Corrected a bug in global check printout. - -<TR><TD><TD><TD> <TD> Added generating a dump file. - -<TR><TD><TD><TD> <TD> Fixed a bug of forgetting repeated assignments -(for example in parameter settings and initval). - -<TR><TD><TD><TD> <TD> Added a diff operator to the parser. - -<TR> -<TD>1539 -<TD>1.3.6 -<TD>2008/01/03 -<TD> - -<TR><TD><TD><TD> <TD> Corrected a bug of segmentation faults for long -names and path names. - -<TR><TD><TD><TD> <TD> Changed a way how random numbers are -generated. Dynare++ uses a separate instance of Mersenne twister for -each simulation, this corrects a flaw of additional randomness caused -by operating system scheduler. This also corrects a strange behaviour -of random generator on Windows, where each simulation was getting the -same sequence of random numbers. - -<TR><TD><TD><TD> <TD> Added calculation of conditional distributions -controlled by --condper and --condsim. - -<TR><TD><TD><TD> <TD> Dropped creating unfoled version of decision -rule at the end. This might consume a lot of memory. However, -simulations might be slower for some models. - -<TR> -<TD>1368 -<TD>1.3.5 -<TD>2007/07/11 -<TD> - -<TR><TD><TD><TD> <TD> Corrected a bug of useless storing all derivative -indices in a parser. This consumed a lot of memory for large models. - -<TR><TD><TD><TD> <TD> Added an option <tt>--ss-tol</tt> controlling a -tolerance used for convergence of a non-linear solver. - -<TR><TD><TD><TD> <TD> Corrected buggy interaction of optimal policy -and forward looking variables with more than one period. - -<TR><TD><TD><TD> <TD> Variance matrices can be positive -semidefinite. This corrects a bug of throwing an error if estimating -approximation errors on ellipse of the state space with a -deterministic variable. - -<TR><TD><TD><TD> <TD> Implemented simulations with statistics -calculated in real-time. Options <tt>--rtsim</tt> and <tt>--rtper</tt>. - -<TR> -<TD>1282 -<TD>1.3.4 -<TD>2007/05/15 -<TD> - -<TR><TD><TD><TD> <TD>Corrected a bug of wrong representation of NaN in generated M-files. - -<TR><TD><TD><TD> <TD>Corrected a bug of occassionaly wrong evaluation of higher order derivatives of integer powers. - -<TR><TD><TD><TD> <TD>Implemented automatic handling of terms involving multiple leads. - -<TR><TD><TD><TD> <TD>Corrected a bug in the numerical integration, i.e. checking of the precision of the solution. - -<TR> -<TD>1090 -<TD>1.3.3 -<TD>2006/11/20 -<TD> - -<TR><TD><TD><TD> <TD>Corrected a bug of non-registering an auxiliary variable in initval assignments. - -<TR> -<TD>988 -<TD>1.3.2 -<TD>2006/10/11 -<TD> - -<TR><TD><TD><TD> <TD>Corrected a few not-serious bugs: segfault on -some exception, error in parsing large files, error in parsing -matrices with comments, a bug in dynare_simul.m - -<TR><TD><TD><TD> <TD>Added posibility to specify a list of shocks for -which IRFs are calculated - -<TR><TD><TD><TD> <TD>Added --order command line switch - -<TR><TD><TD><TD> <TD>Added writing two MATLAB files for steady state -calcs - -<TR><TD><TD><TD> <TD>Implemented optimal policy using keyword -planner_objective and planner_discount - -<TR><TD><TD><TD> <TD>Implemented an R interface to Dynare++ algorithms -(Tamas Papp) - -<TR><TD><TD><TD> <TD>Highlevel code reengineered to allow for -different model inputs - -<TR> -<TD>799 -<TD>1.3.1 -<TD>2006/06/13 -<TD> - -<TR><TD><TD><TD> <TD>Corrected few bugs: in error functions, in linear algebra module. - -<TR><TD><TD><TD> <TD>Updated dynare_simul. - -<TR><TD><TD><TD> <TD>Updated the tutorial. - -<TR><TD><TD><TD> <TD>Corrected an error in summing up tensors where -setting up the decision rule derivatives. Thanks to Michel -Juillard. The previous version was making deterministic effects of -future volatility smaller than they should be. - -<TR> -<TD>766 -<TD>1.3.0 -<TD>2006/05/22 -<TD> - -<TR><TD><TD><TD> <TD>The non-linear solver replaced with a new one. - -<TR><TD><TD><TD> <TD>The parser and derivator replaced with a new -code. Now it is possible to put expressions in parameters and initval -sections. - -<TR> -<TD>752 -<TD>1.2.2 -<TD>2006/05/22 -<TD> - -<TR><TD><TD><TD> <TD>Added an option triggering/suppressing IRF calcs.. - -<TR><TD><TD><TD> <TD>Newton algortihm is now used for fix-point calculations. - -<TR><TD><TD><TD> <TD> Vertical narrowing of tensors in Faa Di Bruno -formula to avoid multiplication with zeros.. - -<TR> -<TD>436 -<TD>1.2.1 -<TD>2005/08/17 -<TD> - -<TR><TD><TD><TD> <TD>Faa Di Bruno for sparse matrices optimized. The -implementation now accommodates vertical refinement of function stack -in order to fit a corresponding slice to available memory. In -addition, zero slices are identified. For some problems, this implies -significant speedup. - -<TR><TD><TD><TD> <TD>Analytic derivator speedup. - -<TR><TD><TD><TD> <TD>Corrected a bug in the threading code. The bug -stayed concealed in Linux 2.4.* kernels, and exhibited in Linux 2.6.*, -which has a different scheduling. This correction also allows using -detached threads on Windows. - -<TR> -<TD>410 -<TD>1.2 -<TD>2005/07/29 -<TD> - -<TR><TD><TD><TD> <TD>Added Dynare++ tutorial. - -<TR><TD><TD><TD> <TD>Changed and enriched contents of MAT-4 output -file. - -<TR><TD><TD><TD> <TD>Corrected a bug of wrong variable indexation -resulting in an exception. The error occurred if a variable appeared -at time t-1 or t+1 and not at t. - -<TR><TD><TD><TD> <TD>Added MATLAB interface, which allows simulation -of a decision rule in MATLAB. - -<TR><TD><TD><TD> <TD>Got rid of Matrix Template Library. - -<TR><TD><TD><TD> <TD>Added checking of model residuals by the -numerical integration. Three methods: checking along simulation path, -checking along shocks, and on ellipse of states. - -<TR><TD><TD><TD> <TD>Corrected a bug in calculation of higher moments -of Normal dist. - -<TR><TD><TD><TD> <TD>Corrected a bug of wrong drawing from Normal dist -with non-zero covariances. - -<TR><TD><TD><TD> -<TD>Added numerical integration module. Product and Smolyak -quadratures over Gauss-Hermite and Gauss-Legendre, and quasi Monte -Carlo. - -<TR> -<TD>152 -<TD>1.1 -<TD>2005/04/22 -<TD> - -<TR><TD><TD><TD> -<TD>Added a calculation of approximation at a stochastic steady state -(still experimental). - -<TR><TD><TD><TD> -<TD>Corrected a bug in Cholesky decomposition of variance-covariance -matrix with off-diagonal elements. - -<TR> -<TD>89 -<TD>1.01 -<TD>2005/02/23 -<TD> - -<TR><TD><TD><TD> -<TD>Added version printout. - -<TR><TD><TD><TD> -<TD>Corrected the bug of multithreading support for P4 HT processors running on Win32. - -<TR><TD><TD><TD> -<TD>Enhanced Kronecker product code resulting in approx. 20% speedup. - -<TR><TD><TD><TD> -<TD>Implemented vertical stack container refinement, and another -method for sparse folded Faa Di Bruno (both not used yet). - -<TR> -<TD>5 -<TD>1.0 -<TD>2005/02/23 -<TD>The first released version. - -</TABLE> -</BODY> -</HTML> diff --git a/dynare++/doc/changelog-sylv-old.html b/dynare++/doc/changelog-sylv-old.html deleted file mode 100644 index 39571f73a6ccef8c87af1d1c474d391372a240b2..0000000000000000000000000000000000000000 --- a/dynare++/doc/changelog-sylv-old.html +++ /dev/null @@ -1,140 +0,0 @@ -<HTML> -<!-- $Header: /var/lib/cvs/dynare_cpp/sylv/change_log.html,v 1.1.1.1 2004/06/04 13:00:05 kamenik Exp $ --> -<!-- Tag $Name: $ --> -<TITLE> -Sylvester Solver Change Log -</TITLE> -<BODY> -<TABLE CELLSPACING=2 ALIGN="CENTER" BORDER=1> -<TR> -<TD BGCOLOR="#d0d0d0" WIDTH="85"> Tag </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="80"> Date </TD> -<TD BGCOLOR="#d0d0d0" WIDTH="600"> Description/Changes</TD> -</TR> -<TR> -<TD></TD> -<TD>2003/09/10</TD> -<TD>Initial version solving triangular system put to repository</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented solution of general case.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented a memory pool (Paris).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented MEX interface to the routine (Paris).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented QuasiTriangularZero (Paris) (not fully used yet).</TD> -</TR> -<TR> -<TD>rel-1</TD> -<TD>2003/10-02</TD> -<TD>Version sent to Michel.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Inheritance streamlined, QuasiTriangular inherits from GeneralMatrix.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented block diagonalization algorithm.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Solution routines rewritten so that the output rewrites input, -considerable memory improvement.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>MEX interface now links with LAPACK library from MATLAB.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Added a hack to MEX library loading in order to avoid MATLAB crash in Wins.</TD> -</TR> -<TR> -<TD>rel-2</TD> -<TD>2003/10/15</TD> -<TD>Version sent to Michel.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>KronUtils now rewrite input by output using less memory.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Added iterative solution algorithm (doubling).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Introduced abstraction for set of parameters (SylvParams).</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Algorithm enabled to solve problems with singular C.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented a class chooser chossing between QuasiTriangularZero, -and QuasiTriangular (padded with zero) depending on size of the -problem. Full use of QuasiTriangularZero.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Reimplemented QuasiTriangular::solve, offdiagonal elements are -eleiminated by gauss with partial pivoting, not by transformation of -complex eigenvalues. More stable for ill conditioned eigenvalues.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Reimplemented calculation of eliminating vectors, much more -numerically stable now.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>Implemented algorithm for ordering of eigenvalues (not used now, -no numerical improvements).</TD> -</TR> -<TR> -<TD>rel-3</TD> -<TD>2003/12/4</TD> -<TD>Version sent to Michel.</TD> -</TR> -<TR> -<TD></TD> -<TD></TD> -<TD>GeneralMatrix separated for use outside, in sylv module we use -its subclass SylvMatrix. Implemented ConstGeneralMatrix (useful outside). -</TD> -</TR> -<TR> -<TD>rel-4</TD> -<TD>2004/6/4</TD> -<TD>Version, which was moved to pythie.cepremap.cnrs.fr repository.</TD> -</TR> -</TABLE> -</BODY> -</HTML> diff --git a/dynare++/doc/dynare++-ramsey.tex b/dynare++/doc/dynare++-ramsey.tex deleted file mode 100644 index 00b73ce8f44770e1112058f08f647fbc66fb9b11..0000000000000000000000000000000000000000 --- a/dynare++/doc/dynare++-ramsey.tex +++ /dev/null @@ -1,157 +0,0 @@ -\documentclass[10pt]{article} -\usepackage{array,natbib,times} -\usepackage{amsmath, amsthm, amssymb} - -%\usepackage[pdftex,colorlinks]{hyperref} - -\begin{document} - -\title{Implementation of Ramsey Optimal Policy in Dynare++, Timeless Perspective} - -\author{Ondra Kamen\'\i k} - -\date{June 2006} -\maketitle - -\textbf{Abstract:} This document provides a derivation of Ramsey -optimal policy from timeless perspective and describes its -implementation in Dynare++. - -\section{Derivation of the First Order Conditions} - -Let us start with an economy populated by agents who take a number of -variables exogenously, or given. These may include taxes or interest -rates for example. These variables can be understood as decision (or control) -variables of the timeless Ramsey policy (or social planner). The agent's -information set at time $t$ includes mass-point distributions of these -variables for all times after $t$. If $i_t$ denotes an interest rate -for example, then the information set $I_t$ includes -$i_{t|t},i_{t+1|t},\ldots,i_{t+k|t},\ldots$ as numbers. In addition -the information set includes all realizations of past exogenous -innovations $u_\tau$ for $\tau=t,t-1,\ldots$ and distibutions -$u_\tau\sim N(0,\Sigma)$ for $\tau=t+1,\ldots$. These information sets will be denoted $I_t$. - -An information set including only the information on past realizations -of $u_\tau$ and future distributions of $u_\tau\sim N(0\sigma)$ will -be denoted $J_t$. We will use the following notation for expectations -through these sets: -\begin{eqnarray*} -E^I_t[X] &=& E(X|I_t)\\ -E^J_t[X] &=& E(X|J_t) -\end{eqnarray*} - -The agents optimize taking the decision variables of the social -planner at $t$ and future as given. This means that all expectations -they form are conditioned on the set $I_t$. Let $y_t$ denote a vector -of all endogenous variables including the planer's decision -variables. Let the number of endogenous variables be $n$. The economy -can be described by $m$ equations including the first order conditions -and transition equations: -\begin{equation}\label{constr} -E_t^I\left[f(y_{t-1},y_t,y_{t+1},u_t)\right] = 0. -\end{equation} -This lefts $n-m$ -the planner's control variables. The solution of this problem is a -decision rule of the form: -\begin{equation}\label{agent_dr} -y_t=g(y_{t-1},u_t,c_{t|t},c_{t+1|t},\ldots,c_{t+k|t},\ldots), -\end{equation} -where $c$ is a vector of planner's control variables. - -Each period the social planner chooses the vector $c_t$ to maximize -his objective such that \eqref{agent_dr} holds for all times following -$t$. This would lead to $n-m$ first order conditions with respect to -$c_t$. These first order conditions would contain unknown derivatives -of endogenous variables with respect to $c$, which would have to be -retrieved from the implicit constraints \eqref{constr} since the -explicit form \eqref{agent_dr} is not known. - -The other way to proceed is to assume that the planner is so dumb that -he is not sure what are his control variables. So he optimizes with -respect to all $y_t$ given the constraints \eqref{constr}. If the -planner's objective is $b(y_{t-1},y_t,y_{t+1},u_t)$ with a discount rate -$\beta$, then the optimization problem looks as follows: -\begin{align} -\max_{\left\{y_\tau\right\}^\infty_t}&E_t^J -\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\notag\\ -&\rm{s.t.}\label{planner_optim}\\ -&\hskip1cm E^I_\tau\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]=0\quad\rm{for\ } -\tau=\ldots,t-1,t,t+1,\ldots\notag -\end{align} -Note two things: First, each constraint \eqref{constr} in -\eqref{planner_optim} is conditioned on $I_\tau$ not $I_t$. This is -very important, since the behaviour of agents at period $\tau=t+k$ is -governed by the constraint using expectations conditioned on $t+k$, -not $t$. The social planner knows that at $t+k$ the agents will use -all information available at $t+k$. Second, the constraints for the -planner's decision made at $t$ include also constraints for agent's -behaviour prior to $t$. This is because the agent's decision rules are -given in the implicit form \eqref{constr} and not in the explicit form -\eqref{agent_dr}. - -Using Lagrange multipliers, this can be rewritten as -\begin{align} -\max_{y_t}E_t^J&\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right.\notag\\ -&\left.+\sum_{\tau=-\infty}^{\infty}\beta^{\tau-t}\lambda^T_\tau E_\tau^I\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\right], -\label{planner_optim_l} -\end{align} -where $\lambda_t$ is a vector of Lagrange multipliers corresponding to -constraints \eqref{constr}. Note that the multipliers are multiplied -by powers of $\beta$ in order to make them stationary. Taking a -derivative wrt $y_t$ and putting it to zero yields the first order -conditions of the planner's problem: -\begin{align} -E^J_t\left[\vphantom{\frac{\int^(_)}{\int^(\_)}}\right.&\frac{\partial}{\partial y_t}b(y_{t-1},y_t,y_{t+1},u_t)+ -\beta L^{+1}\frac{\partial}{\partial y_{t-1}}b(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta^{-1}\lambda_{t-1}^TE^I_{t-1}\left[L^{-1}\frac{\partial}{\partial y_{t+1}}f(y_{t-1},y_t,y_{t+1},u_t)\right]\notag\\ -&+\lambda_t^TE^I_t\left[\frac{\partial}{\partial y_{t}}f(y_{t-1},y_t,y_{t+1},u_t)\right]\notag\\ -&+\beta\lambda_{t+1}^TE^I_{t+1}\left[L^{+1}\frac{\partial}{\partial y_{t-1}}f(y_{t-1},y_t,y_{t+1},u_t)\right] -\left.\vphantom{\frac{\int^(_)}{\int^(\_)}}\right] - = 0,\label{planner_optim_foc} -\end{align} -where $L^{+1}$ and $L^{-1}$ are one period lead and lag operators respectively. - -Now we have to make a few assertions concerning expectations -conditioned on the different information sets to simplify -\eqref{planner_optim_foc}. Recall the formula for integration through -information on which another expectation is conditioned, this is: -$$E\left[E\left[u|v\right]\right] = E[u],$$ -where the outer expectation integrates through $v$. Since $J_t\subset -I_t$, by easy application of the above formula we obtain -\begin{eqnarray} -E^J_t\left[E^I_t\left[X\right]\right] &=& E^J_t\left[X\right]\quad\rm{and}\notag\\ -E^J_t\left[E^I_{t-1}\left[X\right]\right] &=& E^J_t\left[X\right]\label{e_iden}\\ -E^J_t\left[E^I_{t+1}\left[X\right]\right] &=& E^J_{t+1}\left[X\right]\notag -\end{eqnarray} -Now, the last term of \eqref{planner_optim_foc} needs a special -attention. It is equal to -$E^J_t\left[\beta\lambda^T_{t+1}E^I_{t+1}[X]\right]$. If we assume -that the problem \eqref{planner_optim} has a solution, then there is a -deterministic function from $J_{t+1}$ to $\lambda_{t+1}$ and so -$\lambda_{t+1}\in J_{t+1}\subset I_{t+1}$. And the last term is equal -to $E^J_{t}\left[E^I_{t+1}[\beta\lambda^T_{t+1}X]\right]$, which is -$E^J_{t+1}\left[\beta\lambda^T_{t+1}X\right]$. This term can be -equivalently written as -$E^J_{t}\left[\beta\lambda^T_{t+1}E^J_{t+1}[X]\right]$. The reason why -we write the term in this way will be clear later. All in all, we have -\begin{align} -E^J_t\left[\vphantom{\frac{\int^(_)}{\int^(\_)}}\right.&\frac{\partial}{\partial y_t}b(y_{t-1},y_t,y_{t+1},u_t)+ -\beta L^{+1}\frac{\partial}{\partial y_{t-1}}b(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta^{-1}\lambda_{t-1}^TL^{-1}\frac{\partial}{\partial y_{t+1}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\lambda_t^T\frac{\partial}{\partial y_{t}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta\lambda_{t+1}^TE^J_{t+1}\left[L^{+1}\frac{\partial}{\partial y_{t-1}}f(y_{t-1},y_t,y_{t+1},u_t)\right] -\left.\vphantom{\frac{\int^(_)}{\int^(\_)}}\right] - = 0.\label{planner_optim_foc2} -\end{align} -Note that we have not proved that \eqref{planner_optim_foc} and -\eqref{planner_optim_foc2} are equivalent. We proved only that if -\eqref{planner_optim_foc} has a solution, then -\eqref{planner_optim_foc2} is equivalent (and has the same solution). - -%%- \section{Implementation} -%%- -%%- The user inputs $b(y_{t-1},y_t,y_{t+1},u_t)$, $\beta$, and agent's -%%- first order conditions \eqref{constr}. The algorithm has to produce -%%- \eqref{planner_optim_foc2}. -%%- -\end{document} diff --git a/dynare++/doc/dynare++-tutorial.tex b/dynare++/doc/dynare++-tutorial.tex deleted file mode 100644 index d94475a2a1da844d8e999fabdbe14604712846ae..0000000000000000000000000000000000000000 --- a/dynare++/doc/dynare++-tutorial.tex +++ /dev/null @@ -1,1512 +0,0 @@ -\documentclass[10pt]{article} -\usepackage{array,natbib} -\usepackage{amsmath, amsthm, amssymb} - -\usepackage[pdftex,colorlinks]{hyperref} - -\begin{document} - -\title{DSGE Models with Dynare++. A Tutorial.} - -\author{Ondra Kamen\'\i k} - -\date{First version: February 2011 \\ This version: September 2020} -\maketitle - -\tableofcontents - -\section{Setup} - -The Dynare++ setup procedure is pretty straightforward as Dynare++ is included in the Dynare installation -packages which can be downloaded from \url{https://www.dynare.org}. Take the following steps: -\begin{enumerate} -\item Add the {\tt dynare++} subdirectory of the root Dynare installation directory to the your -operating system path. This ensures that your OS will find the {\tt dynare++} executable. -\item If you have MATLAB and want to run custom simulations (see \ref{custom}), - then you need to add to your MATLAB path the {\tt dynare++} subdirectory of - the root Dynare installation directory, and also directory containing the - \texttt{dynare\_simul\_} MEX file (note the trailing underscore). The easiest - way to add the latter is to run Dynare once in your MATLAB session (even - without giving it any MOD file). -\end{enumerate} - -\section{Sample Session} - -As an example, let us take a simple DSGE model with time to build, whose dynamic -equilibrium is described by the following first order conditions: - -\begin{align*} -&c_t\theta h_t^{1+\psi} = (1-\alpha)y_t\cr -&\beta E_t\left[\frac{\exp(b_t)c_t}{\exp(b_{t+1})c_{t+1}} -\left(\exp(b_{t+1})\alpha\frac{y_{t+1}}{k_{t+1}}+1-\delta\right)\right]=1\cr -&y_t=\exp(a_t)k_t^\alpha h_t^{1-\alpha}\cr -&k_{t}=\exp(b_{t-1})(y_{t-1}-c_{t-1})+(1-\delta)k_{t-1}\cr -&a_t=\rho a_{t-1}+\tau b_{t-1}+\epsilon_t\cr -&b_t=\tau a_{t-1}+\rho b_{t-1}+\nu_t -\end{align*} - -\label{timing} -The convention is that the timing of a variable reflects when this variable -is decided. Dynare++ therefore uses a ``stock at the end of the -period'' notation for predetermined state variables (see the Dynare manual for details). - -The timing of this model is that the exogenous shocks $\epsilon_t$, -and $\nu_t$ are observed by agents in the beginning of period $t$ and -before the end of period $t$ all endogenous variables with index $t$ -are decided. The expectation operator $E_t$ works over the information -accumulated just before the end of the period $t$ (this includes -$\epsilon_t$, $\nu_t$ and all endogenous variables with index $t$). - -The exogenous shocks $\epsilon_t$ and $\nu_t$ are supposed to be -serially uncorrelated with zero means and time-invariant -variance-covariance matrix. In Dynare++, these variables are called -exogenous; all other variables are endogenous. Now we are prepared to -start writing a model file for Dynare++, which is an ordinary text -file and could be created with any text editor. - -The model file starts with a preamble declaring endogenous and -exogenous variables, parameters, and setting values of the -parameters. Note that one can put expression on right hand sides. The -preamble follows: - -{\small -\begin{verbatim} -var Y, C, K, A, H, B; -varexo EPS, NU; - -parameters beta, rho, alpha, delta, theta, psi, tau; -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 1/(1.03^0.25); -delta = 0.025; -psi = 0; -theta = 2.95; -\end{verbatim} -} - -The section setting values of the parameters is terminated by a -beginning of the {\tt model} section, which states all the dynamic -equations. A timing convention of a Dynare++ model is the same as the -timing of our example model, so we may proceed with writing the model -equations. The time indexes of $c_{t-1}$, $c_t$, and $c_{t+1}$ are -written as {\tt C(-1)}, {\tt C}, and {\tt C(1)} resp. The {\tt model} -section looks as follows: - -{\small -\begin{verbatim} -model; -C*theta*H^(1+psi) = (1-alpha)*Y; -beta*exp(B)*C/exp(B(1))/C(1)* - (exp(B(1))*alpha*Y(1)/K(1)+1-delta) = 1; -Y = exp(A)*K^alpha*H^(1-alpha); -K = exp(B(-1))*(Y(-1)-C(-1)) + (1-delta)*K(-1); -A = rho*A(-1) + tau*B(-1) + EPS; -B = tau*A(-1) + rho*B(-1) + NU; -end; -\end{verbatim} -} - -At this point, almost all information that Dynare++ needs has been -provided. Only three things remain to be specified: initial values of -endogenous variables for non-linear solver, variance-covariance matrix -of the exogenous shocks and order of the Taylor approximation. Since -the model is very simple, there is a closed form solution for the -deterministic steady state. We use it as initial values for the -non-linear solver. Note that the expressions on the right hand-sides in -{\tt initval} section can reference values previously calculated. The -remaining portion of the model file looks as follows: - -{\small -\begin{verbatim} -initval; -A = 0; -B = 0; -H = ((1-alpha)/(theta*(1-(delta*alpha) - /(1/beta-1+delta))))^(1/(1+psi)); -Y = (alpha/(1/beta-1+delta))^(alpha/(1-alpha))*H; -K = alpha/(1/beta-1+delta)*Y; -C = Y - delta*K; -end; - -vcov = [ - 0.0002 0.00005; - 0.00005 0.0001 -]; - -order = 7; -\end{verbatim} -} - -Note that the order of rows/columns of the variance-covariance matrix -corresponds to the ordering of exogenous variables in the {\tt varexo} -declaration. Since the {\tt EPS} was declared first, its variance is -$0.0002$, and the variance of {\tt NU} is $0.0001$. - -Let the model file be saved as {\tt example1.mod}. Now we are prepared -to solve the model. At the operating system command -prompt\footnote{Under Windows it is a {\tt cmd} program, under Unix it -is any shell} we issue a command: - -{\small -\begin{verbatim} -dynare++ example1.mod -\end{verbatim} -} - -When the program is finished, it produces two output files: a journal -file {\tt example1.jnl} and a MATLAB MAT-4 {\tt example1.mat}. The -journal file contains information about time, memory and processor -resources needed for all steps of solution. The output file is more -interesting. It contains various simulation results. It can be loaded -into MATLAB or Octave and examined. - -Let us first examine the contents of the MAT file: -{\small -\begin{verbatim} ->> load example1.mat ->> who - -Your variables are: - -dyn_g_1 dyn_i_Y dyn_npred -dyn_g_2 dyn_irfm_EPS_mean dyn_nstat -dyn_g_3 dyn_irfm_EPS_var dyn_shocks -dyn_g_4 dyn_irfm_NU_mean dyn_ss -dyn_g_5 dyn_irfm_NU_var dyn_state_vars -dyn_i_A dyn_irfp_EPS_mean dyn_steady_states -dyn_i_B dyn_irfp_EPS_var dyn_vars -dyn_i_C dyn_irfp_NU_mean dyn_vcov -dyn_i_EPS dyn_irfp_NU_var dyn_vcov_exo -dyn_i_H dyn_mean -dyn_i_K dyn_nboth -dyn_i_NU dyn_nforw -\end{verbatim} -} - -All the variables coming from one MAT file have a common prefix. In -this case it is {\tt dyn}, which is Dynare++ default. The prefix can -be changed, so that the multiple results could be loaded into one MATLAB -session. - -In the default setup, Dynare++ solves the Taylor approximation to the -decision rule and calculates unconditional mean and covariance of the -endogenous variables, and generates impulse response functions. The -mean and covariance are stored in {\tt dyn\_mean} and {\tt -dyn\_vcov}. The ordering of the endogenous variables is given by {\tt -dyn\_vars}. - -In our example, the ordering is - -{\small -\begin{verbatim} ->> dyn_vars -dyn_vars = -H -A -Y -C -K -B -\end{verbatim} -} - -and unconditional mean and covariance are - -{\small -\begin{verbatim} ->> dyn_mean -dyn_mean = - 0.2924 - 0.0019 - 1.0930 - 0.8095 - 11.2549 - 0.0011 ->> dyn_vcov -dyn_vcov = - 0.0003 0.0006 0.0016 0.0004 0.0060 0.0004 - 0.0006 0.0024 0.0059 0.0026 0.0504 0.0012 - 0.0016 0.0059 0.0155 0.0069 0.1438 0.0037 - 0.0004 0.0026 0.0069 0.0040 0.0896 0.0016 - 0.0060 0.0504 0.1438 0.0896 2.1209 0.0405 - 0.0004 0.0012 0.0037 0.0016 0.0405 0.0014 -\end{verbatim} -} - -The ordering of the variables is also given by indexes starting with -{\tt dyn\_i\_}. Thus the mean of capital can be retrieved as - -{\small -\begin{verbatim} ->> dyn_mean(dyn_i_K) -ans = - 11.2549 -\end{verbatim} -} - -\noindent and covariance of labor and capital by - -{\small -\begin{verbatim} ->> dyn_vcov(dyn_i_K,dyn_i_H) -ans = - 0.0060 -\end{verbatim} -} - -The impulse response functions are stored in matrices as follows -\begin{center} -\begin{tabular}{|l|l|} -\hline -matrix& response to\\ -\hline -{\tt dyn\_irfp\_EPS\_mean}& positive impulse to {\tt EPS}\\ -{\tt dyn\_irfm\_EPS\_mean}& negative impulse to {\tt EPS}\\ -{\tt dyn\_irfp\_NU\_mean}& positive impulse to {\tt NU}\\ -{\tt dyn\_irfm\_NU\_mean}& negative impulse to {\tt NU}\\ -\hline -\end{tabular} -\end{center} -All shocks sizes are one standard error. Rows of the matrices -correspond to endogenous variables, columns correspond to -periods. Thus capital response to a positive shock to {\tt EPS} can be -plotted as - -{\small -\begin{verbatim} -plot(dyn_irfp_EPS_mean(dyn_i_K,:)); -\end{verbatim} -} - -The data is in units of the respective variables, so in order to plot -the capital response in percentage changes from the decision rule's -fix point (which is a vector {\tt dyn\_ss}), one has to issue the -commands: - -{\small -\begin{verbatim} -Kss=dyn_ss(dyn_i_K); -plot(100*dyn_irfp_EPS_mean(dyn_i_K,:)/Kss); -\end{verbatim} -} - -The plotted impulse response shows that the model is pretty persistent -and that the Dynare++ default for a number of simulated periods is not -sufficient. In addition, the model persistence puts in doubt also a -number of simulations. The Dynare++ defaults can be changed when -calling Dynare++, in operating system's command prompt, we issue a -command: - -{\small -\begin{verbatim} -dynare++ --per 300 --sim 150 example1.mod -\end{verbatim} -} - -\noindent This sets the number of simulations to $150$ and the number -of periods to $300$ for each simulation giving $45000$ total simulated -periods. - -\section{Sample Optimal Policy Session} -\label{optim_tut} - -Suppose that one wants to solve the following optimal policy problem -with timeless perspective.\footnote{See \ref{ramsey} on how to solve -Ramsey optimality problem within this framework} The following -optimization problem is how to choose capital taxes financing public -good to maximize agent's utility from consumption good and public -good. The problem takes the form: -\begin{align*} -\max_{\{\tau_t\}_{t_0}^\infty} -E_{t_0}\sum_{t=t_0}^\infty &\beta^{t-t_0}\left(u(c_t)+av(g_t)\right)\\ -\hbox{subject\ to}&\\ -u'(c_t) &= -\beta E_t\left[u'(c_{t+1})\left(1-\delta+f'(k_{t+1})(1-\alpha\tau_{t+1})\right)\right]\\ -K_t &= (1-\delta)K_{t-1} + (f(K_{t-1}) - c_{t-1} - g_{t-1})\\ -g_t &= \tau_t\alpha f(K_t),\\ -\hbox{where\ } t & = \ldots,t_0-1,t_0,t_0+1,\ldots -\end{align*} -$u(c_t)$ is utility from consuming the consumption good, $v(g_t)$ is -utility from consuming the public good, $f(K_t)$ is a production -function $f(K_t) = Z_tK_t^\alpha$. $Z_t$ is a technology shock modeled -as AR(1) process. The three constraints come from the first order -conditions of a representative agent. We suppose that it pursues a -different objective, namely lifetime utility involving only -consumption $c_t$. The representative agents chooses between -consumption and investment. It rents the capital to firms and supplies -constant amount of labour. All output is paid back to consumer in form -of wage and capital rent. Only the latter is taxed. We suppose that -the optimal choice has been taking place from infinite past and will -be taking place for ever. Further we suppose the same about the -constraints. - -Let us choose the following functional forms: -\begin{eqnarray*} -u(c_t) &=& \frac{c_t^{1-\eta}}{1-\eta}\\ -v(g_t) &=& \frac{g_t^{1-\phi}}{1-\phi}\\ -f(K_t) &=& K_t^\alpha -\end{eqnarray*} - -Then the problem can be coded into Dynare++ as follows. We start with -a preamble which states all the variables, shocks and parameters: -{\small -\begin{verbatim} -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; -\end{verbatim} -} - -Then we specify the planner's objective and the discount factor in the -objective. The objective is an expression (possibly including also -variable leads and lags), and the discount factor must be one single -declared parameter: -{\small -\begin{verbatim} -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; -\end{verbatim} -} - -The model section will contain only the constraints of the social -planner. These are capital accumulation, identity for the public -product, AR(1) process for $Z_t$ and the first order condition of the -representative agent (with different objective). -{\small -\begin{verbatim} -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -C^(-eta) = beta*C(+1)^(-eta)*(1-delta + - exp(Z(+1))*alpha*K(+1)^(alpha-1)*(1-alpha*TAU(+1))); -end; -\end{verbatim} -} - -Now we have to provide a good guess for non-linear solver calculating -the deterministic steady state. The model's steady state has a closed -form solution if the taxes are known. So we provide a guess for -taxation {\tt TAU} and then use the closed form solution for capital, -public good and consumption:\footnote{Initial guess for Lagrange -multipliers and some auxiliary variables is calculated automatically. See -\ref{opt_init} for more details.} -{\small -\begin{verbatim} -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/(alpha*(1-alpha*TAU)))^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -\end{verbatim} -} - -Finally, we have to provide the order of approximation, and the -variance-covariance matrix of the shocks (in our case we have only one -shock): -{\small -\begin{verbatim} -order = 4; - -vcov = [ - 0.01 -]; -\end{verbatim} -} - -After this model file has been run, we can load the resulting MAT-file -into the MATLAB and examine its contents: -{\small -\begin{verbatim} ->> load kp1980_2.mat ->> who - -Your variables are: - -dyn_g_1 dyn_i_MULT1 dyn_nforw -dyn_g_2 dyn_i_MULT2 dyn_npred -dyn_g_3 dyn_i_MULT3 dyn_nstat -dyn_g_4 dyn_i_TAU dyn_shocks -dyn_i_AUX_3_0_1 dyn_i_Z dyn_ss -dyn_i_AUX_4_0_1 dyn_irfm_EPS_mean dyn_state_vars -dyn_i_C dyn_irfm_EPS_var dyn_steady_states -dyn_i_EPS dyn_irfp_EPS_mean dyn_vars -dyn_i_G dyn_irfp_EPS_var dyn_vcov -dyn_i_K dyn_mean dyn_vcov_exo -dyn_i_MULT0 dyn_nboth -\end{verbatim} -} - -The data dumped into the MAT-file have the same structure as in the -previous example of this tutorial. The only difference is that -Dynare++ added a few more variables. Indeed: -{\small -\begin{verbatim} ->> dyn_vars -dyn_vars = -MULT1 -G -MULT3 -C -K -Z -TAU -AUX_3_0_1 -AUX_4_0_1 -MULT0 -MULT2 -\end{verbatim} -} -Besides the five variables declared in the model ({\tt C}, {\tt G}, -{\tt K}, {\tt TAU}, and {\tt Z}), Dy\-na\-re++ added 6 more, four as Lagrange -multipliers of the four constraints, two as auxiliary variables for -shifting in time. See \ref{aux_var} for more details. - -The structure and the logic of the MAT-file is the same as these new 6 -variables were declared in the model file and the file is examined in -the same way. - -For instance, let us examine the Lagrange multiplier of the optimal -policy associated with the consumption first order condition. Recall -that the consumers' objective is different from the policy -objective. Therefore, the constraint will be binding and the -multiplier will be non-zero. Indeed, its deterministic steady state, -fix point and mean are as follows: -{\small -\begin{verbatim} ->> dyn_steady_states(dyn_i_MULT3,1) -ans = - -1.3400 ->> dyn_ss(dyn_i_MULT3) -ans = - -1.3035 ->> dyn_mean(dyn_i_MULT3) -ans = - -1.3422 -\end{verbatim} -} - -\section{What Dynare++ Calculates} -\label{dynpp_calc} - -Dynare++ solves first order conditions of a DSGE model in the recursive form: -\begin{equation}\label{focs} -E_t[f(y^{**}_{t+1},y_t,y^*_{t-1},u_t)]=0, -\end{equation} -where $y$ is a vector of endogenous variables, and $u$ a vector of -exogenous variables. Some of elements of $y$ can occur at time $t+1$, -these are $y^{**}$. Elements of $y$ occurring at time $t-1$ are denoted -$y^*$. The exogenous shocks are supposed to be serially independent -and normally distributed $u_t\sim N(0,\Sigma)$. - -The solution of this dynamic system is a decision rule -\[ -y_t=g(y^*_{t-1},u_t) -\] -Dynare++ calculates a Taylor approximation of this decision rule of a -given order. The approximation takes into account deterministic -effects of future volatility, so a point about which the Taylor -approximation is done will be different from the fix point $y$ of the rule -yielding $y=g(y^*,0)$. - -The fix point of a rule corresponding to a model with $\Sigma=0$ is -called {\it deterministic steady state} denoted as $\bar y$. In -contrast to deterministic steady state, there is no consensus in -literature how to call a fix point of the rule corresponding to a -model with non-zero $\Sigma$. I am tempted to call it {\it stochastic - steady state}, however, it might be confused with unconditional mean -or with steady distribution. So I will use a term {\it fix point} to -avoid a confusion. - -By default, Dynare++ solves the Taylor approximation about the -deterministic steady state. Alternatively, Dynare++ can split the -uncertainty to a few steps and take smaller steps when calculating the -fix points. This is controlled by an option {\tt --steps}. For the -brief description of the second method, see \ref{multistep_alg}. - -\subsection{Decision Rule Form} -\label{dr_form} - -In case of default solution algorithm (approximation about the -deterministic steady state $\bar y$), Dynare++ calculates the higher -order derivatives of the equilibrium rule to get a decision rule of -the following form. In Einstein notation, it is: -\[ -y_t-\bar y = \sum_{i=0}^k\frac{1}{i!}\left[g_{(y^*u)^i}\right] -_{\alpha_1\ldots\alpha_i} -\prod_{j=1}^i\left[\begin{array}{c} y^*_{t-1}-\bar y^*\\ u_t \end{array}\right] -^{\alpha_j} -\] - -Note that the ergodic mean will be different from the deterministic -steady state $\bar y$ and thus deviations $y^*_{t-1}-\bar y^*$ will -not be zero in average. This implies that in average we will commit -larger round off errors than if we used the decision rule expressed in -deviations from a point closer to the ergodic mean. Therefore, by -default, Dynare++ recalculates this rule and expresses it in -deviations from the stochastic fix point $y$. -\[ -y_t-y = \sum_{i=1}^k\frac{1}{i!}\left[\tilde g_{(y^*u)^i}\right] -_{\alpha_1\ldots\alpha_i} -\prod_{j=1}^i\left[\begin{array}{c} y^*_{t-1}-y^*\\ u_t \end{array}\right] -^{\alpha_j} -\] -Note that since the rule is centralized around its fix point, the -first term (for $i=0$) drops out. - -Also note, that this rule mathematically equivalent to the rule -expressed in deviations from the deterministic steady state, and still -it is an approximation about the deterministic steady state. The fact -that it is expressed in deviations from a different point should not -be confused with the algorithm in \ref{multistep_alg}. - -This centralization can be avoided by invoking {\tt --no-centralize} -command line option. - -\subsection{Taking Steps in Volatility Dimension} -\label{multistep_alg} - -For models, where volatility of the exogenous shocks plays a big -role, the approximation about deterministic steady state can be poor, -since the equilibrium dynamics can be very different from the dynamics -in the vicinity of the perfect foresight (deterministic steady state). - -Therefore, Dynare++ has on option {\tt --steps} triggering a multistep -algorithm. The algorithm splits the volatility to a given number of -steps. Dynare++ attempts to calculate approximations about fix points -corresponding to these levels of volatility. The problem is that if we -want to calculate higher order approximations about fix points -corresponding to volatilities different from zero (as in the case of -deterministic steady state), then the derivatives of lower orders -depend on derivatives of higher orders with respect to forward looking -variables. The multistep algorithm in each step approximates the -missing higher order derivatives with extrapolations based on the -previous step. - -In this way, the approximation of the stochastic fix point and the -derivatives about this fix point are obtained. It is difficult to a -priori decide whether this algorithm yields a better decision -rule. Nothing is guaranteed, and the resulted decision rule should be -checked with a numerical integration. See \ref{checks}. - -\subsection{Simulating the Decision Rule} - -After some form of a decision rule is calculated, it is simulated to -obtain draws from ergodic (unconditional) distribution of endogenous -variables. The mean and the covariance are reported. There are two -ways how to calculate the mean and the covariance. The first one is to -store all simulated samples and calculate the sample mean and -covariance. The second one is to calculate mean and the covariance in -the real-time not storing the simulated sample. The latter case is -described below (see \ref{rt_simul}). - -The stored simulated samples are then used for impulse response -function calculations. For each shock, the realized shocks in these -simulated samples (control simulations) are taken and an impulse is -added and the new realization of shocks is simulated. Then the control -simulation is subtracted from the simulation with the impulse. This is -done for all control simulations and the results are averaged. As the -result, we get an expectation of difference between paths with impulse -and without impulse. In addition, the sample variances are -reported. They might be useful for confidence interval calculations. - -For each shock, Dynare++ calculates IRF for two impulses, positive and -negative. Size of an impulse is one standard error of a respective -shock.\footnote{Note that if the exogenous shocks are correlated, Dynare++ will - ignore the correlation when computing the IRFs, and simulate the impulse on - each shock independently of the others. Note that Dynare behaves differently - in this case, and computes IRFs after performing an orthogonalization of the - shocks (via a Cholesky decomposition of the variance-covariance matrix).} - -The rest of this subsection is divided to three parts giving account -on real-time simulations, conditional simulations, and on the way how -random numbers are generated resp. - -\subsubsection{Simulations With Real-Time Statistics} -\label{rt_simul} - -When one needs to simulate large samples to get a good estimate of -unconditional mean, simulating the decision rule with statistics -calculated in real-time comes handy. The main reason is that the -storing of all simulated samples may not fit into the available -memory. - -The real-time statistics proceed as follows: We model the ergodic -distribution as having normal distribution $y\sim N(\mu,\Sigma)$. Further, -the parameters $\mu$ and $\Sigma$ are modelled as: -\begin{eqnarray*} - \Sigma &\sim& {\rm InvWishart}_\nu(\Lambda)\\ - \mu|\Sigma &\sim& N(\bar\mu,\Sigma/\kappa) \\ -\end{eqnarray*} -This model of $p(\mu,\Sigma)$ has an advantage of conjugacy, i.e. a -prior distribution has the same form as posterior. This property is -used in the calculation of real-time estimates of $\mu$ and $\Sigma$, -since it suffices to maintain only the parameters of $p(\mu,\Sigma)$ -conditional observed draws so far. The parameters are: $\nu$, -$\Lambda$, $\kappa$, and $\bar\mu$. - -The mean of $\mu,\Sigma|Y$, where $Y$ are all the draws (simulated -periods) is reported. - -\subsubsection{Conditional Distributions} -\label{cond_dist} - -Starting with version 1.3.6, Dynare++ calculates variable -distributions $y_t$ conditional on $y_0=\bar y$, where $\bar y$ is the -deterministic steady state. If triggered, Dynare++ simulates a given -number of samples with a given number of periods all starting at -the deterministic steady state. Then for each time $t$, mean -$E[y_t|y_0=\bar y]$ and variances $E[(y_t-E[y_t|y_0=\bar -y])(y_t-E[y_t|y_0=\bar y])^T|y_0=\bar y]$ are reported. - -\subsubsection{Random Numbers} -\label{random_numbers} - -For generating of the pseudo random numbers, Dynare++ uses Mersenne -twister by Makoto Matsumoto and Takuji Nishimura. Because of the -parallel nature of Dynare++ simulations, each simulated sample gets -its own instance of the twister. Each such instance is seeded before -the simulations are started. This is to prevent additional randomness -implied by the operating system's thread scheduler to interfere with -the pseudo random numbers. - -For seeding the individual instances of the Mersenne twister assigned -to each simulated sample the system (C library) random generator is -used. These random generators do not have usually very good -properties, but we use them only to seed the Mersenne twister -instances. The user can set the initial seed of the system random -generator and in this way deterministically choose the seeds of all -instances of the Mersenne twister. - -In this way, it is guaranteed that two runs of Dynare++ -with the same seed will yield the same results regardless the -operating system's scheduler. The only difference may be caused by a -different round-off errors committed when the same set of samples are -summed in the different order (due to the operating system's scheduler). - -\subsection{Numerical Approximation Checks} -\label{checks} - -Optionally, Dynare++ can run three kinds of checks for Taylor -approximation errors. All three methods numerically calculate -the residual of the DSGE equations -\[ -E[f(g^{**}(g^*(y^*,u),u'),g(y^*,u),y^*,u)|y^*,u] -\] -which must be ideally zero for all $y^*$ and $u$. This integral is -evaluated by either product or Smolyak rule applied to one dimensional -Gauss--Hermite quadrature. The user does not need to care about the -decision. An algorithm yielding higher quadrature level and less -number of evaluations less than a user given maximum is selected. - -The three methods differ only by a set of $y^*$ and $u$ where the -residuals are evaluated. These are: -\begin{itemize} -\item The first method calculates the residuals along the shocks for -fixed $y^*$ equal to the fix point. We let all elements of $u$ be -fixed at $0$ but one element, which varies from $-\mu\sigma$ to -$\mu\sigma$, where $\sigma$ is a standard error of the element and -$\mu$ is the user given multiplier. In this way we can see how the -approximation error grows if the fix point is disturbed by a shock of -varying size. -\item The second method calculates the residuals along a simulation -path. A random simulation is run, and at each point the residuals are -reported. -\item The third method calculates the errors on an ellipse of the -state variables $y^*$. The shocks $u$ are always zero. The ellipse is -defined as -\[\{Ax|\; \Vert x\Vert_2=\mu\},\] -where $\mu$ is a user given multiplier, and $AA^T=V$ for $V$ being a -covariance of endogenous variables based on the first order -approximation. The method calculates the residuals at low discrepancy -sequence of points on the ellipse. Both the residuals and the points -are reported. -\end{itemize} - -\section{Optimal Policy with Dynare++} -\label{optim} - -Starting with version 1.3.2, Dynare++ is able to automatically -generate and then solve the first order conditions for a given -objective and (possibly) forward looking constraints. Since the -constraints can be forward looking, the use of this feature will -mainly be in optimal policy or control. - -The only extra thing which needs to be added to the model file is a -specification of the policy's objective. This is done by two keywords, -placed not before parameter settings. If the objective is to maximize -$$E_{t_0}\sum_{t=t_0}^\infty\beta^{t-t_0}\left[\frac{c_t^{1-\eta}}{1-\eta}+ -a\frac{g_t^{1-\phi}}{1-\phi}\right],$$ -then the keywords will be: -{\small -\begin{verbatim} -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; -\end{verbatim} -} - -Dynare++ parses the file and if the two keywords are present, it -automatically derives the first order conditions for the problem. The -first order conditions are put to the form \eqref{focs} and solved. In -this case, the equations in the {\tt model} section are understood as -the constraints (they might come as the first order conditions from -optimizations of other agents) and their number must be less than the -number of endogenous variables. - -This section further describes how the optimal policy first order -conditions look like, then discusses some issues with the initial -guess for deterministic steady state, and finally describes how to -simulate Ramsey policy within this framework. - -\subsection{First Order Conditions} - -Mathematically, the optimization problem looks as follows: -\begin{align} -\max_{\left\{y_\tau\right\}^\infty_t}&E_t -\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\notag\\ -&\rm{s.t.}\label{planner_optim}\\ -&\hskip1cm E^I_\tau\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]=0\quad\rm{for\ } -\tau=\ldots,t-1,t,t+1,\ldots\notag -\end{align} -where $E^I$ is an expectation operator over an information set including, -besides all the past, all future realizations of policy's control -variables and distributions of future shocks $u_t\sim -N(0,\Sigma)$. The expectation operator $E$ integrates over an -information including only distributions of $u_t$ (besides the past). - -Note that the constraints $f$ take place at all times, and they are -conditioned at the running $\tau$ since the policy knows that the -agents at time $\tau$ will use all the information available at -$\tau$. - -The maximization problem can be rewritten using Lagrange multipliers as: -\begin{align} -\max_{y_t}E_t&\left[\sum_{\tau=t}^\infty\beta^{\tau-t}b(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right.\notag\\ -&\left.+\sum_{\tau=-\infty}^{\infty}\beta^{\tau-t}\lambda^T_\tau E_\tau^I\left[f(y_{\tau-1},y_\tau,y_{\tau+1},u_\tau)\right]\right], -\label{planner_optim_l} -\end{align} -where $\lambda_t$ is a column vector of Lagrange multipliers. - -After some manipulations with compounded expectations over different -information sets, one gets the following first order conditions: -\begin{align} -E_t\left[\vphantom{\frac{\int^(_)}{\int^(\_)}}\right.&\frac{\partial}{\partial y_t}b(y_{t-1},y_t,y_{t+1},u_t)+ -\beta L^{+1}\frac{\partial}{\partial y_{t-1}}b(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta^{-1}\lambda_{t-1}^TL^{-1}\frac{\partial}{\partial y_{t+1}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\lambda_t^T\frac{\partial}{\partial y_{t}}f(y_{t-1},y_t,y_{t+1},u_t)\notag\\ -&+\beta\lambda_{t+1}^TE_{t+1}\left[L^{+1}\frac{\partial}{\partial y_{t-1}}f(y_{t-1},y_t,y_{t+1},u_t)\right] -\left.\vphantom{\frac{\int^(_)}{\int^(\_)}}\right] - = 0,\label{planner_optim_foc2} -\end{align} -where $L^{+1}$ is one period lead operator, and $L^{-1}$ is one period lag operator. - -Dynare++ takes input corresponding to \eqref{planner_optim}, -introduces the Lagrange multipliers according to -\eqref{planner_optim_l}, and using its symbolic derivator it compiles -\eqref{planner_optim_foc2}. The system \eqref{planner_optim_foc2} with -the constraints from \eqref{planner_optim_l} is then solved in the -same way as the normal input \eqref{focs}. - -\subsection{Initial Guess for Deterministic Steady State} -\label{opt_init} - -Solving deterministic steady state of non-linear dynamic systems is -not trivial and the first order conditions for optimal policy add -significant complexity. The {\tt initval} section allows to input the -initial guess of the non-linear solver. It requires that all user -declared endogenous variables be initialized. However, in most cases, -we have no idea what are good initial guesses for the Lagrange -multipliers. - -For this reason, Dynare++ calculates an initial guess of Lagrange -multipliers using user provided initial guesses of all other -endogenous variables. It uses the linearity of the Lagrange -multipliers in the \eqref{planner_optim_foc2}. In its static form, -\eqref{planner_optim_foc2} looks as follows: -\begin{align} -&\frac{\partial}{\partial y_t}b(y,y,y,0)+ -\beta\frac{\partial}{\partial y_{t-1}}b(y,y,y,0)\notag\\ -&+\lambda^T\left[\beta^{-1}\frac{\partial}{\partial y_{t+1}}f(y,y,y,0) - +\frac{\partial}{\partial y_{t}}f(y,y,y,0) - +\beta\frac{\partial}{\partial y_{t-1}}f(y,y,y,0)\right] - = 0\label{planner_optim_static} -\end{align} - -The user is required to provide an initial guess of all declared -variables (all $y$). Then \eqref{planner_optim_static} becomes an -overdetermined linear system in $\lambda$, which is solved by means of -the least squares. The closer the initial guess of $y$ is to the exact -solution, the closer are the Lagrange multipliers $\lambda$. - -The calculated Lagrange multipliers by the least squares are not used, -if they are set in the {\tt initval} section. In other words, if a -multiplier has been given a value in the {\tt initval} section, then -the value is used, otherwise the calculated value is taken. - -For even more difficult problems, Dynare++ generates two MATLAB files -calculating a residual of the static system and its derivative. These -can be used in MATLAB's {\tt fsolve} or other algorithm to get an -exact solution of the deterministic steady state. See -\ref{output_matlab_scripts} for more details. - -Finally, Dynare++ might generate a few auxiliary variables. These are -simple transformations of other variables. They are initialized -automatically and the user usually does not need to care about it. - -\subsection{Optimal Ramsey Policy} -\label{ramsey} - -Dynare++ solves the optimal policy problem with timeless -perspective. This means that it assumes that the constraints in -\eqref{planner_optim} are valid from the infinite past to infinite -future. Dynare++ calculation of ergodic distribution then assumes that -the policy has been taking place from infinite past. - -If some constraints in \eqref{planner_optim} are forward looking, this -will result in some backward looking Lagrange multipliers. Such -multipliers imply possibly time inconsistent policy in the states of -the ``original'' economy, since these backward looking multipliers add -new states to the ``optimized'' economy. In this respect, the timeless -perspective means that there is no fixed initial distribution of such -multipliers, instead, their ergodic distribution is taken. - -In contrast, Ramsey optimal policy is started at $t=0$. This means -that the first order conditions at $t=0$ are different than the first -order conditions at $t\geq 1$, which are -\eqref{planner_optim_foc2}. However, it is not difficult to assert -that the first order conditions at $t=0$ are in the form of -\eqref{planner_optim_foc2} if all the backward looking Lagrange -multipliers are set to zeros at period $-1$, i.e. $\lambda_{-1}=0$. - -All in all, the solution of \eqref{planner_optim_foc2} calculated by -Dynare++ can be used as a Ramsey optimal policy solution provided that -all the backward looking Lagrange multipliers were set to zeros prior -to the first simulation period. This can be done by setting the -initial state of a simulation path in {\tt dynare\_simul.m}. If this -is applied on the example from \ref{optim_tut}, then we may do the -following in the command prompt: -{\small -\begin{verbatim} ->> load kp1980_2.mat ->> shocks = zeros(1,100); ->> ystart = dyn_ss; ->> ystart(dyn_i_MULT3) = 0; ->> r=dynare_simul('kp1980_2.mat',shocks,ystart); -\end{verbatim} -} -This will simulate the economy if the policy was introduced in the -beginning and no shocks happened. - -More information on custom simulations can be obtained by typing: -{\small -\begin{verbatim} -help dynare_simul -\end{verbatim} -} - - -\section{Running Dynare++} - -This section deals with Dynare++ input. The first subsection -\ref{dynpp_opts} provides a list of command line options, next -subsection \ref{dynpp_mod} deals with a format of Dynare++ model file, -and the last subsection discusses incompatibilities between Dynare -and Dynare++. - -\subsection{Command Line Options} -\label{dynpp_opts} - -The calling syntax of the Dynare++ is - -{\small -\begin{verbatim} -dynare++ [--help] [--version] [options] <model file> -\end{verbatim} -} - -\noindent where the model file must be given as the last token and -must include its extension. The model file may include path, in this -case, the path is taken relative to the current directory. Note that -the current directory can be different from the location of {\tt -dynare++} binary. - -The options are as follows: - -\def\desc#1{\rlap{#1}\kern4cm} - -\begin{description} -\item[\desc{\tt --help}] This prints a help message and exits. - -\item[\desc{\tt --version}] This prints a version information and -exits. - -\item[\desc{\tt --per \it num}] This sets a number of simulated -periods to {\it num} in addition to the burn-in periods. This number -is used when calculating unconditional mean and covariance and for -IRFs. Default is 100. - -\item[\desc{\tt --burn \it num}] This sets a number of initial periods -which should be ignored from the statistics. The burn-in periods are -used to eliminate the influence of the starting point when -calculating ergodic distributions or/and impulse response -functions. The number of simulated period given by {\tt --per \it - num} option does not include the number of burn-in -periods. Default is 0. - -\item[\desc{\tt --sim \it num}] This sets a number of stochastic -simulations. This number is used when calculating unconditional mean -and covariance and for IRFs. The total sample size for unconditional -mean and covariance is the number of periods times the number of -successful simulations. Note that if a simulation results in {\tt NaN} -or {\tt +-Inf}, then it is thrown away and is not considered for the -mean nor the variance. The same is valid for IRF. Default is 80. - -\item[\desc{\tt --rtsim \it num}] This sets a number of stochastic -simulations whose statistics are calculated in the real-time. This -number excludes the burn-in periods set by {\tt --burn \it num} -option. See \ref{rt_simul} for more details. Default is 0, no -simulations. - -\item[\desc{\tt --rtper \it num}] This sets a number of simulated -periods per one simulation with real-time statistics to {\it num}. See -\ref{rt_simul} for more details. Default is 0, no simulations. - -\item[\desc{\tt --condsim \it num}] This sets a number of stochastic -conditional simulations. See \ref{cond_dist} for more details. Default -is 0, no simulations. - -\item[\desc{\tt --condper \it num}] This sets a number of simulated -periods per one conditional simulation. See \ref{cond_dist} for more -details. Default is 0, no simulations. - -\item[\desc{\tt --steps \it num}] If the number {\it num} is greater -than 0, this option invokes a multi-step algorithm (see section -\ref{dynpp_calc}), which in the given number of steps calculates fix -points and approximations of the decision rule for increasing -uncertainty. Default is 0, which invokes a standard algorithm for -approximation about deterministic steady state. For more details, -see \ref{multistep_alg}. - -\item[\desc{\tt --centralize}] This option causes that the resulting -decision rule is centralized about (in other words: expressed in the -deviations from) the stochastic fix point. The centralized decision -rule is mathematically equivalent but has an advantage of yielding -less numerical errors in average than not centralized decision -rule. By default, the rule is centralized. For more details, see -\ref{dr_form}. - -\item[\desc{\tt --no-centralize}] This option causes that the -resulting decision rule is not centralized about (in other words: -expressed in the deviations from) the stochastic fix point. By -default, the rule is centralized. For more details, see -\ref{dr_form}. - -This option has no effect if the number of steps given by {\tt ---steps} is greater than 0. In this case, the rule is always -centralized. - -\item[\desc{\tt --prefix \it string}] This sets a common prefix of -variables in the output MAT file. Default is {\tt dyn}. - -\item[\desc{\tt --seed \it num}] This sets an initial seed for the -random generator providing seed to generators for each sample. See -\ref{random_numbers} for more details. Default is 934098. - -\item[\desc{\tt --order \it num}] This sets the order of approximation -and overrides the {\tt order} statement in the model file. There is no -default. - -\item[\desc{\tt --threads \it num}] This sets a number of parallel -threads. Complex evaluations of Faa Di Bruno formulas, simulations and -numerical integration can be parallelized, Dynare++ exploits this -advantage. You have to have a hardware support for this, otherwise -there is no gain from the parallelization. The default value is the number of -logical processors present on the machine, divided by 2. - -\item[\desc{\tt --ss-tol \it float}] This sets the tolerance of the -non-linear solver of deterministic steady state to {\it float}. It is -in $\Vert\cdot\Vert_\infty$ norm, i.e. the algorithm is considered as -converged when a maximum absolute residual is less than the -tolerance. Default is $10^{-13}$. - -\item[\desc{\tt --check \it pPeEsS}] This selects types of residual -checking to be performed. See section \ref{checks} for details. The -string consisting of the letters ``pPeEsS'' governs the selection. The -upper-case letters switch a check on, the lower-case letters -off. ``P'' stands for checking along a simulation path, ``E'' stands -for checking on ellipse, and finally ``S'' stands for checking along -the shocks. It is possible to choose more than one type of check. The -default behavior is that no checking is performed. - -\item[\desc{\tt --check-evals \it num}] This sets a maximum number of -evaluations per one re\-sidual. The actual value depends on the selected -algorithm for the integral evaluation. The algorithm can be either -product or Smolyak quadrature and is chosen so that the actual number -of evaluations would be minimal with maximal level of -quadrature. Default is 1000. - -\item[\desc{\tt --check-num \it num}] This sets a number of checked -points in a residual check. One input value $num$ is used for all -three types of checks in the following way: -\begin{itemize} -\item For checks along the simulation, the number of simulated periods -is $10\cdot num$ -\item For checks on ellipse, the number of points on ellipse is $10\cdot num$ -\item For checks along the shocks, the number of checked points -corresponding to shocks from $0$ to $\mu\sigma$ (see \ref{checks}) is -$num$. -\end{itemize} -Default is 10. - -\item[\desc{\tt --check-scale \it float}] This sets the scaling factor -$\mu$ for checking on ellipse to $0.5\cdot float$ and scaling factor -$\mu$ for checking along shocks to $float$. See section -\ref{checks}. Default is 2.0. - -\item[\desc{\tt --no-irfs}] This suppresses IRF calculations. Default -is to calculate IRFs for all shocks. - -\item[\desc{\tt --irfs}] This triggers IRF calculations. If there are -no shock names following the {\tt --irfs} option, then IRFs for all -shocks are calculated, otherwise see below. Default is to calculate -IRFs for all shocks. - -\item[\desc{\tt --irfs \it shocklist}] This triggers IRF calculations -only for the listed shocks. The {\it shocklist} is a space separated -list of exogenous variables for which the IRFs will be -calculated. Default is to calculate IRFs for all shocks. -\end{description} - -The following are a few examples: -{\small -\begin{verbatim} -dynare++ --sim 300 --per 50 blah.mod -dynare++ --check PE --check-num 15 --check-evals 500 blah.dyn -dynare++ --steps 5 --check S --check-scale 3 blahblah.mod -\end{verbatim} -} -The first one sets the number of periods for IRF to 50, and sets a sample -size for unconditional mean and covariance calculations to 6000. The -second one checks the decision rule along a simulation path having 150 -periods and on ellipse at 150 points performing at most 500 evaluations -per one residual. The third one solves the model in five steps and -checks the rule along all the shocks from $-3\sigma$ to $3\sigma$ in -$2*10+1$ steps (10 for negative, 10 for positive and 1 for at zero). - -\subsection{Dynare++ Model File} -\label{dynpp_mod} - -In its strictest form, Dynare++ solves the following mathematical problem: -\begin{equation}\label{basic_form} -E_t[f(y^{**}_{t+1},y_t,y^*_{t-1},u_t)]=0 -\end{equation} -This problem is input either directly, or it is an output of Dynare++ -routines calculating first order conditions of the optimal policy -problem. In either case, Dynare++ performs necessary and -mathematically correct substitutions to put the user specified problem -to the \eqref{basic_form} form, which goes to Dynare++ solver. The -following discusses a few timing issues: -\begin{itemize} -\item Endogenous variables can occur, starting from version 1.3.4, at -times after $t+1$. If so, an equation containing such occurrence is -broken to non-linear parts, and new equations and new auxiliary -variables are automatically generated only for the non-linear terms -containing the occurrence. Note that shifting such terms to time $t+1$ -may add occurrences of some other variables (involved in the terms) at -times before $t-1$ implying addition of auxiliary variables to bring -those variables to $t-1$. -\item Variables declared as shocks may occur also at arbitrary -times. If before $t$, additional endogenous variables are used to -bring them to time $t$. If after $t$, then similar method is used as -for endogenous variables occurring after $t+1$. -\item There is no constraint on variables occurring at both times -$t+1$ (or later) and $t-1$ (or earlier). Virtually, all variables can -occur at arbitrary times. -\item Endogenous variables can occur at times before $t-1$. If so, -additional endogenous variables are added for all lags between the -variable and $t-1$. -\item Dynare++ applies the operator $E_t$ to all occurrences at time -$t+1$. The realization of $u_t$ is included in the information set of -$E_t$. See an explanation of Dynare++ timing on page \pageref{timing}. -\end{itemize} - -The model equations are formulated in the same way as in -Dynare. The time indexes different from $t$ are put to round -parenthesis in this way: {\tt C(-1)}, {\tt C}, {\tt C(+1)}. - -The mathematical expressions can use the following functions and operators: -\begin{itemize} -\item binary {\tt + - * / \verb|^|} -\item unary plus and minus minus as in {\tt a = -3;} and {\tt a = +3;} resp. -\item unary mathematical functions: {\tt log exp sin cos tan -sqrt}, whe\-re the logarithm has a natural base -\item symbolic differentiation operator {\tt diff(expr,symbol)}, where -{\tt expr} is a mathematical expression and {\tt symbol} is a unary -symbol (a variable or a parameter); for example {\tt - diff(A*K(-1)\verb|^|alpha*L\verb|^|(1-alpha),K(-1))} is internally expanded as -{\tt A*alpha*K(-1)\verb|^|(alpha-1)*L\verb|^|(1-alpha)} -\item unary error function and complementary error function: {\tt erf} -and {\tt erfc} defined as -\begin{eqnarray*} -erf(x) &= \frac{2}{\sqrt{\pi}}\int_0^x e^{-t^2}{\rm d}t\\ -erfc(x)&= \frac{2}{\sqrt{\pi}}\int_x^\infty e^{-t^2}{\rm d}t -\end{eqnarray*} -\end{itemize} - -The model file can contain user comments. Their usage can be -understood from the following piece of the model file: - -{\small -\begin{verbatim} -P*C^(-gamma) = // line continues until semicolon - beta*C(+1)^(-gamma)*(P(+1)+Y(+1)); // asset price -// choose dividend process: (un)comment what you want -Y/Y_SS = (Y(-1)/Y_SS)^rho*exp(EPS); -/* -Y-Y_SS = rho*(Y(-1)-Y_SS)+EPS; -*/ -\end{verbatim} -} - -\subsection{Incompatibilities with Dynare} - -This section provides a list of incompatibilities between a model file -for Dy\-na\-re++ and for Dynare. These must be considered when a model -file for Dynare is being migrated to Dynare++. The list is the -following: -\begin{itemize} -\item There is no {\tt periods} keyword. -\item The parameters cannot be lagged or leaded; Dynare -allows it, though the semantics is the same (parameter is a -constant). -\item There are no commands like {\tt steady}, {\tt check}, {\tt -simul}, {\tt stoch\_simul}, etc. -\item There are no sections like {\tt estimated\_params}, {\tt -var\_obs}, etc. -\item The variance-covariance matrix of endogenous shocks is given by -{\tt vcov} matrix in Dynare++. An example follows. Starting from -version 1.3.5, it is possible for vcov to be positive semi-definite -matrix. -{\small -\begin{verbatim} -vcov = [ -0.05 0 0 0; -0 0.025 0 0; -0 0 0.05 0; -0 0 0 0.025 -]; -\end{verbatim} -} - -\end{itemize} - -\section{Dynare++ Output} - -There are three output files; a data file in MAT-4 format containing -the output data (\ref{matfile}), a journal text file containing an -information about the Dynare++ run (\ref{journalfile}), and a dump -file (\ref{dumpfile}). Further, Dynare++ generates two MATLAB script -files, which calculate a residual and the first derivative of the -residual of the static system (\ref{output_matlab_scripts}). These are -useful when calculating the deterministic steady state outside -Dynare++. - -Note that all output files are created in the current directory of -the Dynare++ process. This can be different from the directory where -the Dynare++ binary is located and different from the directory where -the model file is located. - -Before all, we need to understand what variables are automatically -generated in Dynare++. - -\subsection{Auxiliary Variables} -\label{aux_var} - -Besides the endogenous variables declared in {\tt var} section, -Dynare++ might automatically add the following endogenous variables: - -\halign{\vrule width0pt height14pt{\tt #}\hfil & \kern 3mm% -\vtop{\rightskip=0pt plus 5mm\noindent\hsize=9.5cm #}\cr -MULT{\it n}& A Lagrange multiplier of the optimal policy problem -associated with a constraint number {\it n} starting from zero.\cr -AUX\_{\it n1}\_{\it n2}\_{\it n3}& An auxiliary variable associated -with the last term in equation \eqref{planner_optim_foc2}. Since the -term is under $E_{t+k}$, we need the auxiliary variable be put back -in time. {\it n1} is a variable number starting from 0 in the declared -order with respect to which the term was differentiated, {\it n2} is a -number of constraint starting from 0, and finally {\it n3} is $k$ -(time shift of the term).\cr -{\it endovar}\_p{\it K}& An auxiliary variable for bringing an -endogenous variable {\it endovar} back in time by $K$ periods. The -semantics of this variables is {\tt {\it endovar}\_p{\it K} = {\it -endovar}(+{\it K})}.\cr -{\it endovar}\_m{\it K}& An auxiliary variable for bringing an -endogenous variable {\it endovar} forward in time by $K$ periods. The -semantics of this variables is {\tt {\it endovar}\_m{\it K} = {\it -endovar}(-{\it K})}.\cr -{\it exovar}\_e& An auxiliary endogenous variable made equal to the -exogenous variable to allow for a semantical occurrence of the -exogenous variable at time other than $t$. The semantics of this -variables is {\tt {\it exovar}\_e = {\it exovar}}.\cr -AUXLD\_{\it n1}\_{\it n2}\_{\it n3}& An auxiliary variable for -bringing a non-linear term containing an occurrence of a variable -after $t+1$ to time $t+1$. {\it n1} is an equation number starting -from 0, {\it n2} is the non-linear sub-term number in the equation -starting from 0. {\it n3} is a time shift. For example, if the first -equation is the following: -\begin{verbatim} -X - Y*W(+1) + W(+2)*Z(+4) = 0; -\end{verbatim} -then it will be expanded as: -\begin{verbatim} -X - Y*W(+1) + AUXLD_0_2_3(+1) = 0; -AUXLD_0_2_1 = W(-1)*Z(+1); -AUXLD_0_2_2 = AUXLD_0_2_1(+1); -AUXLD_0_2_3 = AUXLD_0_2_2(+1); -\end{verbatim} -\cr -} - -\subsection{MAT File} -\label{matfile} - -The contents of the data file is depicted below. We -assume that the prefix is {\tt dyn}. - -\halign{\vrule width0pt height14pt{\tt #}\hfil & \kern 3mm% -\vtop{\rightskip=0pt plus 5mm\noindent\hsize=7.5cm #}\cr -dyn\_nstat& Scalar. A number of static variables -(those occurring only at time $t$).\cr -dyn\_npred & Scalar. A number of variables occurring -at time $t-1$ and not at $t+1$.\cr -dyn\_nboth & Scalar. A number of variables occurring -at $t+1$ and $t-1$.\cr -dyn\_nforw & Scalar. A number of variables occurring -at $t+1$ and not at $t-1$.\cr -dyn\_vars & Column vector of endogenous variable -names in Dy\-na\-re++ internal ordering.\cr -dyn\_i\_{\it endovar} & Scalar. Index of a variable -named {\it endovar} in the {\tt dyn\_vars}.\cr -dyn\_shocks & Column vector of exogenous variable -names.\cr -dyn\_i\_{\it exovar} & Scalar. Index of a shock -named {\it exovar} in the {\tt dyn\_shocks}.\cr -dyn\_state\_vars & Column vector of state variables, -these are stacked variables counted by {\tt dyn\_\-npred}, {\tt -dyn\_\-nboth} and shocks.\cr -dyn\_vcov\_exo & Matrix $nexo\times nexo$. The -variance-covariance matrix of exogenous shocks as input in the model -file. The ordering is given by {\tt dyn\_shocks}.\cr -dyn\_mean & Column vector $nendo\times 1$. The -unconditional mean of endogenous variables. The ordering is given by -{\tt dyn\_vars}.\cr -dyn\_vcov & Matrix $nendo\times nendo$. The -unconditional covariance of endogenous variables. The ordering is given -by {\tt dyn\_vars}.\cr -dyn\_rt\_mean & Column vector $nendo\times 1$. The unconditional mean -of endogenous variables estimated in real-time. See -\ref{rt_simul}. The ordering is given by {\tt dyn\_vars}.\cr -dyn\_rt\_vcov & Matrix $nendo\times nendo$. The unconditional -covariance of endogenous variables estimated in real-time. See \ref{rt_simul}. The -ordering is given by {\tt dyn\_vars}.\cr -dyn\_cond\_mean & Matrix $nendo\times nper$. The rows correspond to -endogenous variables in the ordering of {\tt dyn\_vars}, the columns -to periods. If $t$ is a period (starting with 1), then $t$-th column -is $E[y_t|y_0=\bar y]$. See \ref{cond_dist}.\cr -dyn\_cond\_variance & Matrix $nendo\times nper$. The rows correspond -to endogenous variables in the ordering of {\tt dyn\_vars}, the -columns to periods. If $t$ is a period (starting with 1), then $t$-th -column are the variances of $y_t|y_0=\bar y$. See \ref{cond_dist}.\cr -dyn\_ss & Column vector $nendo\times 1$. The fix -point of the resulting approximation of the decision rule.\cr -dyn\_g\_{\it order} & Matrix $nendo\times ?$. A -derivative of the decision rule of the {\it order} multiplied by -$1/order!$. The rows correspond to endogenous variables in the -ordering of {\tt dyn\_vars}. The columns correspond to a -multidimensional index going through {\tt dyn\_state\_vars}. The data -is folded (all symmetrical derivatives are stored only once).\cr -dyn\_steady\_states & Matrix $nendo\times -nsteps+1$. A list of fix points at which the multi-step algorithm -calculated approximations. The rows correspond to endogenous variables -and are ordered by {\tt dyn\_vars}, the columns correspond to the -steps. The first column is always the deterministic steady state.\cr -dyn\_irfp\_{\it exovar}\_mean & Matrix -$nendo\times nper$. Positive impulse response to a shock named {\it -exovar}. The row ordering is given by {\tt dyn\_vars}. The columns -correspond to periods.\cr -dyn\_irfp\_{\it exovar}\_var & Matrix -$nendo\times nper$. The variances of positive impulse response -functions.\cr -dyn\_irfm\_{\it exovar}\_mean & Same as {\tt -dyn\_irfp\_}{\it exovar}{\tt \_mean} but for negative impulse.\cr -dyn\_irfp\_{\it exovar}\_var & Same as {\tt -dyn\_irfp\_}{\it exovar}{\tt \_var} but for negative impulse.\cr -dyn\_simul\_points & A simulation path along which the check was -done. Rows correspond to endogenous variables, columns to -periods. Appears only if {\tt --check P}.\cr -dyn\_simul\_errors & Errors along {\tt -dyn\_simul\_points}. The rows correspond to equations as stated in the -model file, the columns to the periods. Appears only if {\tt --check -P}\cr -dyn\_ellipse\_points & A set of points on the ellipse at which the -approximation was checked. Rows correspond to state endogenous -variables (the upper part of {\tt dyn\_state\_vars}, this means -without shocks), and columns correspond to periods. Appears only if -{\tt --check E}.\cr -dyn\_ellipse\_errors & Errors on the ellipse points {\tt -dyn\_ellipse\_points}. The rows correspond to the equations as stated -in the model file, columns to periods. Appears only if {\tt --check -E}.\cr -dyn\_shock\_{\it exovar}\_errors& Errors along a shock named {\it -exovar}. The rows correspond to the equations as stated in the model -file. There are $2m+1$ columns, the middle column is the error at zero -shock. The columns to the left correspond to negative values, columns -to the right to positive. Appears only if {\tt --check S}.\cr -} - -\subsection{Journal File} -\label{journalfile} - -The journal file provides information on resources usage during the -run and gives some informative messages. The journal file is a text -file, it is organized in single line records. The format of records is -documented in a header of the journal file. - -The journal file should be consulted in the following circumstances: -\begin{itemize} -\item Something goes wrong. For example, if a model is not -Blanchard--Kahn stable, then the eigenvalues are dumped to the journal -file. - -If the unconditional covariance matrix {\tt dyn\_vcov} is NaN, then -from the journal file you will know that all the simulations had to be -thrown away due to occurrence of NaN or Inf. This is caused by -non-stationarity of the resulting decision rule. - -If Dynare++ crashes, the journal file can be helpful for guessing a -point where it crashed. - -\item You are impatient. You might be looking at the journal file -during the run in order to have a better estimate about the time when -the calculations are finished. In Unix, I use a command {\tt tail -f -blah.jnl}.\footnote{This helps to develop one of the three -programmer's virtues: {\it impatience}. The other two are {\it -laziness} and {\it hubris}; according to Larry Wall.} - -\item Heavy swapping. If the physical memory is not -sufficient, an operating system starts swapping memory pages with a -disk. If this is the case, the journal file can be consulted for -information on memory consumption and swapping activity. - -\item Not sure what Dynare++ is doing. If so, read the journal file, -which contains a detailed record on what was calculated, simulated -etc. -\end{itemize} - -\subsection{Dump File} -\label{dumpfile} - -The dump file is always created with the suffix {\tt .dump}. It is a -text file which takes a form of a model file. It sets the parameter -values which were used, it has the initval section setting the values -which were finally used, and mainly it has a model section of all -equations with all substitutions and formed the first order conditions -of the planner. - -The dump file serves for debugging purposes, since it contains the -mathematical problem which is being solved by dynare++. - -\subsection{MATLAB Scripts for Steady State Calculations} -\label{output_matlab_scripts} - -This section describes two MATLAB scripts, which are useful when -calculating the deterministic steady state outside Dynare++. The -scripts are created by Dynare++ as soon as an input file is parsed, -that is before any calculations. - -The first MATLAB script having a name {\tt {\it modname}\_f.m} for -given parameters values and given all endogenous variables $y$ -calculates a residual of the static system. Supposing the model is in -the form of \eqref{focs}, the script calculates a vector: -\[ -f(y,y,y,0) -\] - -The second script having a name {\tt {\it modname}\_ff.m} calculates a matrix: -\[ -\frac{\partial}{\partial y}f(y,y,y,0) -\] - -Both scripts take two arguments. The first is a vector of parameter -values ordered in the same ordering as declared in the model file. The -second is a vector of all endogenous variables at which the evaluation -is performed. These endogenous variables also include auxiliary -variables automatically added by Dynare++ and Lagrange multipliers if -an optimal policy problem is solved. If no endogenous variable has not -been added by Dynare++, then the ordering is the same as the ordering -in declaration in the model file. If some endogenous variables have -been added, then the ordering can be read from comments close to the -top of either two files. - -For example, if we want to calculate the deterministic steady state of -the {\tt kp1980.dyn} model, we need to do the following: -\begin{enumerate} -\item Run Dynare++ with {\tt kp1980.dyn}, no matter if the calculation -has not been finished, important output are the two MATLAB scripts -created just in the beginning. -\item Consult file {\tt kp1980\_f.m}\ to get the ordering of parameters -and all endogenous variables. -\item Create a vector {\tt p} with the parameter values in the ordering -\item Create a vector {\tt init\_y} with the initial guess for the -MATLAB solver {\tt fsolve} -\item Create a simple MATLAB function called {\tt kp1980\_fsolve.m}\ -returning the residual and Jacobian: -{\small -\begin{verbatim} -function [r, J] = kp1980_fsolve(p, y) - r = kp1980_f(p, y); - J = kp1980_ff(p, y); -\end{verbatim} -} -\item In the MATLAB prompt, run the following: -{\small -\begin{verbatim} -opt=optimset('Jacobian','on','Display','iter'); -y=fsolve(@(y) kp1980_fsolve(p,y), init_y, opt); -\end{verbatim} -} -\end{enumerate} - - -\subsection{Custom Simulations} -\label{custom} - -When Dynare++ run is finished it dumps the derivatives of the -calculated decision rule to the MAT file. The derivatives can be used -for a construction of the decision rule and custom simulations can be -run. This is done by {\tt dynare\_simul.m} M-file in MATLAB. It reads -the derivatives and simulates the decision rule with provided -realization of shocks. - -All the necessary documentation can be viewed by the command: -{\small -\begin{verbatim} -help dynare_simul -\end{verbatim} -} - -\end{document} diff --git a/dynare++/dynare_simul/dynare_simul.m b/dynare++/dynare_simul/dynare_simul.m deleted file mode 100644 index 293d3a73207991edbd9f88927ab3d6fd2d7119f8..0000000000000000000000000000000000000000 --- a/dynare++/dynare_simul/dynare_simul.m +++ /dev/null @@ -1,176 +0,0 @@ -% -% SYNOPSIS -% -% r = dynare_simul(name, shocks) -% r = dynare_simul(name, prefix, shocks) -% r = dynare_simul(name, shocks, start) -% r = dynare_simul(name, prefix, shocks, start) -% -% name name of MAT-file produced by dynare++ -% prefix prefix of variables in the MAT-file -% shocks matrix of shocks -% start zero period value -% -% Note that this file requires the dynare_simul_ DLL to be in the path. -% This DLL is distributed with Dynare, under the mex/matlab or mex/octave -% subdirectory. -% -% SEMANTICS -% -% The command reads a decision rule from the MAT-file having the given -% prefix. Then it starts simulating the decision rule with zero time value -% equal to the given start. It uses the given shocks for the simulation. If -% the start is not given, the state about which the decision rule is -% centralized is taken (called fix point, or stochastic steady state, take -% your pick). -% -% prefix Use the prefix with which you called dynare++, the default -% prefix in dynare++ is 'dyn'. -% shocks Number of rows must be a number of exogenous shocks, -% number of columns gives the number of simulated -% periods. NaNs and Infs in the matrix are substitued by -% draws from the normal distribution using the covariance -% matrix given in the model file. -% start Vector of endogenous variables in the ordering given by -% <prefix>_vars. -% -% Seed for random generator is derived from calling rand(1,1). Therefore, -% seeding can be controlled with rand('state') and rand('state',some_seed). -% -% EXAMPLES -% -% All examples suppose that the prefix is 'dyn' and that your_model.mat -% has been loaded into Matlab. -% -% 1. response to permanent negative shock to the third exo var EPS3 for -% 100 periods -% -% shocks = zeros(4,100); % 4 exogenous variables in the model -% shocks(dyn_i_EPS3,:) = -0.1; % the permanent shock to EPS3 -% r = dynare_simul('your_model.mat',shocks); -% -% 2. one stochastic simulation for 100 periods -% -% shocks = zeros(4,100)./0; % put NaNs everywhere -% r = dynare_simul('your_model.mat',shocks); -% -% 3. one stochastic simulation starting at 75% undercapitalized economy -% -% shocks = zeros(4,100)./0; % put NaNs everywhere -% ystart = dyn_ss; % get copy of DR fix point -% ystart(dyn_i_K) = 0.75*dyn_ss(dyn_i_K); % scale down the capital -% r = dynare_simul('your_model.mat',shocks,ystart); -% -% -% SEE ALSO -% -% "DSGE Models with Dynare++. A Tutorial.", Ondra Kamenik, 2005 - -% Copyright © 2005-2011, Ondra Kamenik -% Copyright © 2020, Dynare Team - - -function r = dynare_simul(varargin) - -if ~exist('dynare_simul_','file') - error('Can''t find dynare_simul_ DLL in the path. The simplest way to add it is to run Dynare once in this session.') -end - -% get the file name and load data -fname = varargin{1}; -load(fname); - -% set prefix, shocks, ystart -if ischar(varargin{2}) - prefix = varargin{2}; - if length(varargin) == 3 - shocks = varargin{3}; - ystart = NaN; - elseif length(varargin) == 4 - shocks = varargin{3}; - ystart = varargin{4}; - else - error('Wrong number of parameters.'); - end -else - prefix = 'dyn'; - if length(varargin) == 2 - shocks = varargin{2}; - ystart = NaN; - elseif length(varargin) == 3 - shocks = varargin{2}; - ystart = varargin{3}; - else - error('Wrong number of parameters.'); - end -end - -% load all needed variables but prefix_g_* -if exist([prefix '_nstat'],'var') - nstat = eval([prefix '_nstat']); -else - error(['Could not find variable ' prefix '_nstat in workspace']); -end -if exist([prefix '_npred'],'var') - npred = eval([prefix '_npred']); -else - error(['Could not find variable ' prefix '_npred in workspace']); -end -if exist([prefix '_nboth'],'var') - nboth = eval([prefix '_nboth']); -else - error(['Could not find variable ' prefix '_nboth in workspace']); -end -if exist([prefix '_nforw'],'var') - nforw = eval([prefix '_nforw']); -else - error(['Could not find variable ' prefix '_nforw in workspace']); -end -if exist([prefix '_ss'],'var') - ss = eval([prefix '_ss']); -else - error(['Could not find variable ' prefix '_ss in workspace']); -end -if exist([prefix '_vcov_exo'],'var') - vcov_exo = eval([prefix '_vcov_exo']); -else - error(['Could not find variable ' prefix '_vcov_exo in workspace']); -end -nexog = size(vcov_exo,1); - -if isnan(ystart) - ystart = ss; -end - -% newer version of dynare++ doesn't return prefix_g_0, we make it here if -% it does not exist in workspace -g_zero = [prefix '_g_0']; -if ~exist(g_zero,'var') - dr.g_0=zeros(nstat+npred+nboth+nforw,1); -else - dr.g_0=eval(g_zero); -end - -% make derstr a string of comma seperated existing prefix_g_* -order = 1; -cont = 1; -while cont == 1 - g_ord = [prefix '_g_' num2str(order)]; - if exist(g_ord,'var') - dr.(['g_' num2str(order)])=eval(g_ord); - order = order + 1; - else - cont = 0; - end -end - -% set seed -seed = ceil(10000*rand(1,1)); - -% call dynare_simul_ -[err,r]=dynare_simul_(order-1,nstat,npred,nboth,nforw,... - nexog,ystart,shocks,vcov_exo,seed,ss,dr); - -if err - error('Simulation failed') -end \ No newline at end of file diff --git a/dynare++/integ/Makefile.am b/dynare++/integ/Makefile.am deleted file mode 100644 index 24104f1e7664f30ecb971eb22e2ae0a2011a2065..0000000000000000000000000000000000000000 --- a/dynare++/integ/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = cc src testing diff --git a/dynare++/integ/cc/Makefile.am b/dynare++/integ/cc/Makefile.am deleted file mode 100644 index 4e98a764017ca23283a3201d6b00ea228f30bf7c..0000000000000000000000000000000000000000 --- a/dynare++/integ/cc/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -noinst_LIBRARIES = libinteg.a - -libinteg_a_SOURCES = \ - quadrature.cc \ - quadrature.hh \ - quasi_mcarlo.cc \ - quasi_mcarlo.hh \ - product.cc \ - product.hh \ - smolyak.cc \ - smolyak.hh \ - vector_function.cc \ - vector_function.hh \ - precalc_quadrature.hh -libinteg_a_CPPFLAGS = -I../../sylv/cc -I../../utils/cc -I../../tl/cc -I$(top_srcdir)/mex/sources diff --git a/dynare++/integ/src/Makefile.am b/dynare++/integ/src/Makefile.am deleted file mode 100644 index 6eec5e1b4c7757c13550129215a76b31e5be735f..0000000000000000000000000000000000000000 --- a/dynare++/integ/src/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -noinst_PROGRAMS = quadrature-points - -quadrature_points_SOURCES = quadrature-points.cc -quadrature_points_CPPFLAGS = -I../.. -I../../sylv/cc -I../../integ/cc -I../../tl/cc -I../../utils/cc -quadrature_points_LDADD = ../cc/libinteg.a ../../tl/cc/libtl.a ../../parser/cc/libparser.a ../../sylv/cc/libsylv.a ../../utils/cc/libutils.a $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) diff --git a/dynare++/integ/src/quadrature-points.cc b/dynare++/integ/src/quadrature-points.cc deleted file mode 100644 index b4ed5206b578f9f40e4ffa2adc38b3b851461c8b..0000000000000000000000000000000000000000 --- a/dynare++/integ/src/quadrature-points.cc +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright © 2008-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "parser/cc/matrix_parser.hh" -#include "utils/cc/exception.hh" -#include "sylv/cc/GeneralMatrix.hh" -#include "sylv/cc/Vector.hh" -#include "sylv/cc/SymSchurDecomp.hh" -#include "sylv/cc/SylvException.hh" -#include "integ/cc/quadrature.hh" -#include "integ/cc/smolyak.hh" -#include "integ/cc/product.hh" - -#include <getopt.h> - -#include <cmath> -#include <cstdlib> -#include <iostream> -#include <fstream> -#include <sstream> -#include <memory> -#include <string> - -struct QuadParams -{ - std::string outname; - std::string vcovname; - int max_level{3}; - double discard_weight{0.0}; - QuadParams(int argc, char **argv); - void check_consistency() const; -private: - enum class opt { max_level, discard_weight, vcov }; -}; - -QuadParams::QuadParams(int argc, char **argv) -{ - if (argc == 1) - { - // Print the help and exit - std::cerr << "Usage: " << argv[0] << " [--max-level INTEGER] [--discard-weight FLOAT] [--vcov FILENAME] OUTPUT_FILENAME" << std::endl; - std::exit(EXIT_FAILURE); - } - - outname = argv[argc-1]; - argc--; - - struct option const opts[] = { - {"max-level", required_argument, nullptr, static_cast<int>(opt::max_level)}, - {"discard-weight", required_argument, nullptr, static_cast<int>(opt::discard_weight)}, - {"vcov", required_argument, nullptr, static_cast<int>(opt::vcov)}, - {nullptr, 0, nullptr, 0} - }; - - int ret; - int index; - while (-1 != (ret = getopt_long(argc, argv, "", opts, &index))) - { - if (ret == '?') - { - std::cerr << "Unknown option, ignored\n"; - continue; - } - - switch (static_cast<opt>(ret)) - { - case opt::max_level: - try - { - max_level = std::stoi(optarg); - } - catch (const std::invalid_argument &e) - { - std::cerr << "Couldn't parse integer " << optarg << ", ignored" << std::endl; - } - break; - case opt::discard_weight: - try - { - discard_weight = std::stod(optarg); - } - catch (const std::invalid_argument &e) - { - std::cerr << "Couldn't parse float " << optarg << ", ignored" << std::endl; - } - break; - case opt::vcov: - vcovname = optarg; - break; - } - } - - check_consistency(); -} - -void -QuadParams::check_consistency() const -{ - if (outname.empty()) - { - std::cerr << "Error: output name not set" << std::endl; - std::exit(EXIT_FAILURE); - } - - if (vcovname.empty()) - { - std::cerr << "Error: vcov file name not set" << std::endl; - std::exit(EXIT_FAILURE); - } -} - -int -main(int argc, char **argv) -{ - QuadParams params(argc, argv); - - // Open output file for writing - std::ofstream fout{params.outname, std::ios::out | std::ios::trunc}; - if (fout.fail()) - { - std::cerr << "Could not open " << params.outname << " for writing" << std::endl; - std::exit(EXIT_FAILURE); - } - - try - { - std::ifstream f{params.vcovname}; - std::ostringstream buffer; - buffer << f.rdbuf(); - std::string contents{buffer.str()}; - - // Parse the vcov matrix - ogp::MatrixParser mp; - mp.parse(contents); - if (mp.nrows() != mp.ncols()) - throw ogu::Exception(__FILE__, __LINE__, - "VCOV matrix not square"); - // And put to the GeneralMatrix - GeneralMatrix vcov(mp.nrows(), mp.ncols()); - vcov.zeros(); - for (ogp::MPIterator it = mp.begin(); it != mp.end(); ++it) - vcov.get(it.row(), it.col()) = *it; - - // Calculate the factor A of vcov, so that A·Aᵀ=VCOV - GeneralMatrix A(vcov.nrows(), vcov.nrows()); - SymSchurDecomp ssd(vcov); - ssd.getFactor(A); - - // Construct Gauss-Hermite quadrature - GaussHermite ghq; - // Construct Smolyak quadrature - int level = params.max_level; - SmolyakQuadrature sq(vcov.nrows(), level, ghq); - - std::cout << "Dimension: " << vcov.nrows() << std::endl - << "Maximum level: " << level << std::endl - << "Total number of nodes: " << sq.numEvals(level) << std::endl; - - // Put the points to the vector - std::vector<std::unique_ptr<Vector>> points; - for (smolpit qit = sq.start(level); qit != sq.end(level); ++qit) - points.push_back(std::make_unique<Vector>(const_cast<const Vector &>(qit.point()))); - // Sort and uniq - std::sort(points.begin(), points.end(), [](auto &a, auto &b) { return a.get() < b.get(); }); - auto new_end = std::unique(points.begin(), points.end()); - points.erase(new_end, points.end()); - - std::cout << "Duplicit nodes removed: " << static_cast<unsigned long>(sq.numEvals(level)-points.size()) - << std::endl; - - // Calculate weights and mass - double mass = 0.0; - std::vector<double> weights; - for (auto &point : points) - { - weights.push_back(std::exp(-point->dot(*point))); - mass += weights.back(); - } - - // Calculate discarded mass - double discard_mass = 0.0; - for (double weight : weights) - if (weight/mass < params.discard_weight) - discard_mass += weight; - - std::cout << "Total mass discarded: " << std::fixed << discard_mass/mass << std::endl; - - // Dump the results - int npoints = 0; - double upscale_weight = 1/(mass-discard_mass); - Vector x(vcov.nrows()); - fout << std::setprecision(16); - for (int i = 0; i < static_cast<int>(weights.size()); i++) - if (weights[i]/mass >= params.discard_weight) - { - // Print the upscaled weight - fout << std::setw(20) << upscale_weight*weights[i]; - // Multiply point with the factor A and √2 - A.multVec(0.0, x, std::sqrt(2.), *(points[i])); - // Print the coordinates - for (int j = 0; j < x.length(); j++) - fout << ' ' << std::setw(20) << x[j]; - fout << std::endl; - npoints++; - } - - std::cout << "Final number of points: " << npoints << std::endl; - - fout.close(); - } - catch (const SylvException &e) - { - e.printMessage(); - return EXIT_FAILURE; - } - catch (const ogu::Exception &e) - { - e.print(); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/dynare++/kord/Makefile.am b/dynare++/kord/Makefile.am deleted file mode 100644 index 2779a754428be950e57b45727a90ff555694e291..0000000000000000000000000000000000000000 --- a/dynare++/kord/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -noinst_LIBRARIES = libkord.a - -libkord_a_SOURCES = \ - approximation.cc \ - approximation.hh \ - decision_rule.cc \ - decision_rule.hh \ - dynamic_model.cc \ - dynamic_model.hh \ - faa_di_bruno.cc \ - faa_di_bruno.hh \ - first_order.cc \ - first_order.hh \ - global_check.cc \ - global_check.hh \ - kord_exception.hh \ - korder.cc \ - korder.hh \ - korder_stoch.cc \ - korder_stoch.hh \ - journal.cc \ - journal.hh \ - normal_conjugate.cc \ - normal_conjugate.hh \ - seed_generator.cc \ - seed_generator.hh - -libkord_a_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -I../utils/cc -I$(top_srcdir)/mex/sources $(CPPFLAGS_MATIO) -DDYNVERSION=\"$(PACKAGE_VERSION)\" - -check_PROGRAMS = tests - -tests_SOURCES = tests.cc -tests_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -I../utils/cc -I$(top_srcdir)/mex/sources -tests_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) -tests_LDADD = libkord.a ../tl/cc/libtl.a ../sylv/cc/libsylv.a ../utils/cc/libutils.a $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) $(LIBADD_MATIO) - -check-local: - ./tests - -CLEANFILES = out.txt diff --git a/dynare++/parser/cc/Makefile.am b/dynare++/parser/cc/Makefile.am deleted file mode 100644 index 6294c1cf35a39353f37dc17b0b6d15b28c15f517..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -noinst_LIBRARIES = libparser.a - -GENERATED_FILES = assign_tab.cc formula_tab.cc matrix_tab.cc assign_tab.hh formula_tab.hh matrix_tab.hh assign_ll.cc formula_ll.cc matrix_ll.cc - -libparser_a_SOURCES = \ - location.hh \ - atom_assignings.cc \ - atom_assignings.hh \ - atom_substitutions.cc \ - atom_substitutions.hh \ - dynamic_atoms.cc \ - dynamic_atoms.hh \ - fine_atoms.cc \ - fine_atoms.hh \ - formula_parser.cc \ - formula_parser.hh \ - matrix_parser.cc \ - matrix_parser.hh \ - parser_exception.cc \ - parser_exception.hh \ - static_atoms.cc \ - static_atoms.hh \ - static_fine_atoms.cc \ - static_fine_atoms.hh \ - tree.cc \ - tree.hh \ - $(GENERATED_FILES) - -libparser_a_CPPFLAGS = -I../.. $(BOOST_CPPFLAGS) - -BUILT_SOURCES = $(GENERATED_FILES) - -EXTRA_DIST = assign.yy formula.yy matrix.yy assign.ll formula.ll matrix.ll - -%_tab.cc %_tab.hh: %.yy - $(YACC) -W -o$*_tab.cc $< - -%_tab.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast - -%_ll.cc: %.ll - $(LEX) -i -o$@ $< - -%_ll.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast diff --git a/dynare++/parser/cc/assign.ll b/dynare++/parser/cc/assign.ll deleted file mode 100644 index 64d756ffef3727743ec66733c7a251741b919b7e..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/assign.ll +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ -%{ -#include "location.hh" -#include "assign_tab.hh" - -#define YY_USER_ACTION SET_LLOC(asgn_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="asgn_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* spaces */ -[ \t\r\n] {return BLANK;} - - /* names */ -[A-Za-z_][A-Za-z0-9_]* { - asgn_lval.string = asgn_text; - return NAME; -} - -; {return SEMICOLON;} -= {return EQUAL_SIGN;} -. { - asgn_lval.character = asgn_text[0]; - return CHARACTER; -} - -%% - -int -asgn_wrap() -{ - return 1; -} - -void -asgn__destroy_buffer(void* p) -{ - asgn__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/parser/cc/assign.yy b/dynare++/parser/cc/assign.yy deleted file mode 100644 index 167063c609804d358bfa28783644e56b194f4027..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/assign.yy +++ /dev/null @@ -1,76 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -%code requires -{ -#include "location.hh" -#define ASGN_LTYPE ogp::location_type -} - -%code -{ -#include "atom_assignings.hh" -#include <string> - -void asgn_error(std::string); -int asgn_lex(); -extern ogp::AtomAssignings* aparser; -} - -%union -{ - int integer; - char *string; - char character; -} - -%token EQUAL_SIGN SEMICOLON CHARACTER BLANK -%token <string> NAME; - -%define api.prefix {asgn_} - -%locations -%defines -%define parse.error verbose - -%% - -root : assignments | %empty; - -assignments : assignments BLANK | assignments assignment | assignment | BLANK; - -assignment : NAME EQUAL_SIGN material SEMICOLON { - aparser->add_assignment(@1.off, $1, @1.ll, @3.off-@1.off, @3.ll + @4.ll);} - | NAME space EQUAL_SIGN material SEMICOLON { - aparser->add_assignment(@1.off, $1, @1.ll, @4.off-@1.off, @4.ll + @5.ll);} - ; - -material : material CHARACTER | material NAME | material BLANK | NAME | CHARACTER | BLANK; - -space : space BLANK | BLANK; - -%% - -void -asgn_error(std::string mes) -{ - aparser->error(std::move(mes)); -} diff --git a/dynare++/parser/cc/atom_assignings.cc b/dynare++/parser/cc/atom_assignings.cc deleted file mode 100644 index dc4b995501f4e6710a60ca052a3a96738ac4bfc7..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_assignings.cc +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "atom_assignings.hh" -#include "location.hh" -#include "parser_exception.hh" - -#include "utils/cc/exception.hh" - -#include <limits> -#include <iostream> -#include <sstream> -#include <iomanip> - -using namespace ogp; - -AtomAssignings::AtomAssignings(const AtomAssignings &aa, ogp::StaticAtoms &a) - : atoms(a), expr(aa.expr, atoms), left_names(aa.left_names), - lname2expr(aa.lname2expr), order(aa.order) -{ -} - -/** A global symbol for passing info to the AtomAssignings from - * asgn_parse(). */ -AtomAssignings *aparser; - -/** The declaration of functions defined in asgn_ll.cc and asgn_tab.cc - * generated from assign.lex assign.y */ -void *asgn__scan_string(const char *); -void asgn__destroy_buffer(void *); -void asgn_parse(); -extern location_type asgn_lloc; - -void -AtomAssignings::parse(const string &stream) -{ - asgn_lloc.off = 0; - asgn_lloc.ll = 0; - void *p = asgn__scan_string(stream.c_str()); - aparser = this; - asgn_parse(); - asgn__destroy_buffer(p); -} - -void -AtomAssignings::error(string mes) -{ - throw ParserException(std::move(mes), asgn_lloc.off); -} - -void -AtomAssignings::add_assignment_to_double(string name, double val) -{ - // if left hand side is a registered atom, insert it to tree - int t; - try - { - if (atoms.check(name)) - t = expr.add_nulary(name); - else - t = -1; - } - catch (const ParserException &e) - { - t = -1; - } - // register left hand side in order - order.push_back(t); - - // add the double to the tree - std::ostringstream buf; - buf << std::setprecision(std::numeric_limits<double>::max_digits10) - << val; - try - { - expr.parse(buf.str()); - } - catch (const ParserException &e) - { - // should never happen - throw ParserException("Error parsing double "+buf.str()+": "+e.message(), 0); - } - - // register name of the left hand side and put to lname2expr - left_names.insert(name); - lname2expr.emplace(std::move(name), order.size()-1); -} - -void -AtomAssignings::add_assignment(int asgn_off, const string &str, int name_len, - int right_off, int right_len) -{ - // the order of doing things here is important: since the - // FormulaParser requires that all references from the i-th tree - // refere to trees with index lass than i, so to capture also a - // nulary term for the left hand side, it must be inserted to the - // expression tree before the expression is parsed. - - // find the name in the atoms - string name = str.substr(0, name_len); - - // if left hand side is a registered atom, insert it to tree - int t; - try - { - t = atoms.check(name); - if (t == -1) - t = expr.add_nulary(name); - } - catch (const ParserException &e) - { - atoms.register_name(name); - t = expr.add_nulary(name); - } - // register left hand side in order - order.push_back(t); - - // parse expression on the right - try - { - expr.parse(str.substr(right_off, right_len)); - } - catch (const ParserException &e) - { - throw ParserException(e, asgn_off+right_off); - } - - // register name of the left hand side and put to lname2expr - left_names.insert(name); - if (lname2expr.find(name) != lname2expr.end()) - { - // Prevent the occurrence of #415 - std::cerr << "Changing the value of " << name << " through a second assignment (e.g. in initval) is not supported. Aborting." << std::endl; - exit(EXIT_FAILURE); - } - lname2expr[name] = order.size()-1; -} - -void -AtomAssignings::apply_subst(const AtomSubstitutions::Toldnamemap &mm) -{ - // go through all old variables and see what are their derived new - // variables - for (const auto &it : mm) - { - const string &oldname = it.first; - const AtomSubstitutions::Tshiftnameset &sset = it.second; - if (!sset.empty()) - { - int told = atoms.index(oldname); - if (told < 0 && !atoms.get_name_storage().query(oldname)) - atoms.register_name(oldname); - if (told == -1) - told = expr.add_nulary(oldname); - // at least one substitution here, so make an expression - expr.add_formula(told); - // say that this expression is not assigned to any atom - order.push_back(-1); - // now go through all new names derived from the old name and - // reference to the newly added formula - for (const auto &itt : sset) - { - const string &newname = itt.first; - left_names.insert(newname); - lname2expr.emplace(newname, expr.nformulas()-1); - } - } - } -} - -void -AtomAssignings::print() const -{ - std::cout << "Atom Assignings\nExpressions:\n"; - expr.print(); - std::cout << "Left names:\n"; - for (auto it : lname2expr) - std::cout << it.first << " ⇒ " << expr.formula(it.second) << " (t=" << order[it.second] << ")\n"; -} - -void -AtomAsgnEvaluator::setValues(EvalTree &et) const -{ - // set values of constants - aa.atoms.setValues(et); - - // set values of variables to NaN or to user set values - double nan = std::numeric_limits<double>::quiet_NaN(); - for (int i = 0; i < aa.atoms.nvar(); i++) - { - const string &ss = aa.atoms.name(i); - int t = aa.atoms.index(ss); - if (t >= 0) - { - auto it = user_values.find(t); - if (it == user_values.end()) - et.set_nulary(t, nan); - else - et.set_nulary(t, it->second); - } - } -} - -void -AtomAsgnEvaluator::set_user_value(const string &name, double val) -{ - int t = aa.atoms.index(name); - if (t >= 0) - { - auto it = user_values.find(t); - if (it == user_values.end()) - user_values.emplace(t, val); - else - it->second = val; - } -} - -void -AtomAsgnEvaluator::load(int i, double res) -{ - // set the value - operator[](i) = res; - // if i-th expression is atom, set its value to this EvalTree - int t = aa.order[i]; - if (t >= 0) - etree.set_nulary(t, res); -} - -double -AtomAsgnEvaluator::get_value(const string &name) const -{ - auto it = aa.lname2expr.find(name); - if (it == aa.lname2expr.end()) - return std::numeric_limits<double>::quiet_NaN(); - else - return operator[](it->second); -} diff --git a/dynare++/parser/cc/atom_assignings.hh b/dynare++/parser/cc/atom_assignings.hh deleted file mode 100644 index e5a12413544167e298e4ad59546dfd4fd9345692..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_assignings.hh +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_ATOM_ASSIGNINGS_H -#define OGP_ATOM_ASSIGNINGS_H - -#include "static_atoms.hh" -#include "formula_parser.hh" -#include "atom_substitutions.hh" - -#include <vector> -#include <map> - -namespace ogp -{ - class AtomAsgnEvaluator; - - /** This class represents atom assignments used in parameters - * settings and initval initialization. It maintains atoms of the - * all expressions on the right hand side, the parsed formulas of - * the right hand sides, and the information about the left hand - * sides. See documentation to the order member below. */ - class AtomAssignings - { - friend class AtomAsgnEvaluator; - protected: - using Tvarintmap = std::map<string, int>; - /** All atoms which should be sufficient for formulas at the - * right hand sides. The atoms should be filled with names - * (preregistered). This is a responsibility of the caller. */ - StaticAtoms &atoms; - /** The formulas of right hand sides. */ - FormulaParser expr; - /** Name storage of the names from left hand sides. */ - NameStorage left_names; - /** Information on left hand sides. This maps a name to the - * index of its assigned expression in expr. More than one - * name may reference to the same expression. */ - Tvarintmap lname2expr; - /** Information on left hand sides. If order[i] >= 0, then it - * says that i-th expression in expr is assigned to atom with - * order[i] tree index. */ - std::vector<int> order; - public: - /** Construct the object using the provided static atoms. */ - AtomAssignings(StaticAtoms &a) : atoms(a), expr(atoms) - { - } - /** Make a copy with provided reference to (posibly different) - * static atoms. */ - AtomAssignings(const AtomAssignings &aa, StaticAtoms &a); - virtual ~AtomAssignings() = default; - /** Parse the assignments from the given string. */ - void parse(const string &stream); - /** Process a syntax error from bison. */ - void error(string mes); - /** Add an assignment of the given name to the given - * double. Can be called by a user, anytime. */ - void add_assignment_to_double(string name, double val); - /** Add an assignment. Called from assign.y. */ - void add_assignment(int asgn_off, const string &str, int name_len, - int right_off, int right_len); - /** This applies old2new map (possibly from atom - * substitutions) to this object. It registers new variables - * in the atoms, and adds the expressions to expr, and left - * names to lname2expr. The information about dynamical part - * of substitutions is ignored, since we are now in the static - * world. */ - void apply_subst(const AtomSubstitutions::Toldnamemap &mm); - /** Debug print. */ - void print() const; - }; - - /** This class basically evaluates the atom assignments - * AtomAssignings, so it inherits from ogp::FormulaEvaluator. It - * is also a storage for the results of the evaluation stored as a - * vector, so the class inherits from std::vector<double> and - * ogp::FormulaEvalLoader. As the expressions for atoms are - * evaluated, the results are values for atoms which will be - * used in subsequent evaluations. For this reason, the class - * inherits also from AtomValues. */ - class AtomAsgnEvaluator : public FormulaEvalLoader, - public AtomValues, - protected FormulaEvaluator, - public std::vector<double> - { - protected: - using Tusrvalmap = std::map<int, double>; - Tusrvalmap user_values; - const AtomAssignings &aa; - public: - AtomAsgnEvaluator(const AtomAssignings &a) - : FormulaEvaluator(a.expr), - std::vector<double>(a.expr.nformulas()), aa(a) - { - } - ~AtomAsgnEvaluator() override = default; - /** This sets all initial values to NaNs, all constants and - * all values set by user by call set_value. This is called by - * FormulaEvaluator::eval() method, which is called by eval() - * method passing this argument as AtomValues. So the - * ogp::EvalTree will be always this->etree. */ - void setValues(EvalTree &et) const override; - /** User setting of the values. For example in initval, - * parameters are known and should be set to their values. In - * constrast endogenous variables are set initially to NaNs by - * AtomValues::setValues. */ - void set_user_value(const string &name, double val); - /** This sets the result of i-th expression in aa to res, and - * also checks whether the i-th expression is an atom. If so, - * it sets the value of the atom in ogp::EvalTree - * this->etree. */ - void load(int i, double res) override; - /** After the user values have been set, the assignments can - * be evaluated. For this purpose we have eval() method. The - * result is that this object as std::vector<double> will - * contain the values. It is ordered given by formulas in - * expr. */ - void - eval() - { - FormulaEvaluator::eval(*this, *this); - } - /** This returns a value for a given name. If the name is not - * found among atoms, or there is no assignment for the atom, - * NaN is returned. */ - double get_value(const string &name) const; - }; -}; - -#endif diff --git a/dynare++/parser/cc/atom_substitutions.cc b/dynare++/parser/cc/atom_substitutions.cc deleted file mode 100644 index 83d4f42ce637dd8f44e60953d3340088017617a5..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_substitutions.cc +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "atom_substitutions.hh" -#include "utils/cc/exception.hh" - -using namespace ogp; - -AtomSubstitutions::AtomSubstitutions(const AtomSubstitutions &as, const FineAtoms &oa, - FineAtoms &na) - : new2old(as.new2old), old2new(as.old2new), old_atoms(oa), new_atoms(na) -{ -} - -void -AtomSubstitutions::add_substitution(string newname, string oldname, int tshift) -{ - // insert to new2old map - new2old.emplace(newname, Tshiftname(oldname, tshift)); - // insert to old2new map - auto it = old2new.find(oldname); - if (it != old2new.end()) - it->second.emplace(std::move(newname), -tshift); - else - { - Tshiftnameset snset; - snset.emplace(std::move(newname), -tshift); - old2new.emplace(std::move(oldname), snset); - } - - // put to info - info.num_substs++; -} - -void -AtomSubstitutions::substitutions_finished(VarOrdering::ord_type ot) -{ - // create an external ordering of new_atoms from old_atoms - const vector<string> &oa_ext = old_atoms.get_allvar(); - vector<string> na_ext; - for (const auto &oname : oa_ext) - { - // add the old name itself - na_ext.push_back(oname); - // add all new names derived from the old name - auto it = old2new.find(oname); - if (it != old2new.end()) - for (const auto &itt : it->second) - na_ext.push_back(itt.first); - } - - // call parsing finished for the new_atoms - new_atoms.parsing_finished(ot, na_ext); -} - -string -AtomSubstitutions::get_new4old(const string &oldname, int tshift) const -{ - auto it = old2new.find(oldname); - if (it != old2new.end()) - { - const Tshiftnameset &sset = it->second; - for (const auto &itt : sset) - if (itt.second == -tshift) - return itt.first; - } - return ""; -} - -void -AtomSubstitutions::print() const -{ - std::cout << "Atom Substitutions:\nOld ⇒ New:\n"; - for (const auto &it : old2new) - for (const auto &itt : it.second) - std::cout << " " << it.first << " ⇒ [" << itt.first << ", " << itt.second << "]\n"; - - std::cout << "Old ⇐ New:\n"; - for (const auto &it : new2old) - std::cout << " [" << it.second.first << ", " << it.second.second << "] ⇐ " << it.first << '\n'; -} - -void -SAtoms::substituteAllLagsAndLeads(FormulaParser &fp, AtomSubstitutions &as) -{ - string name; - - int mlead, mlag; - endovarspan(mlead, mlag); - - // substitute all endo lagged more than 1 - while (!(name = findEndoWithLeadInInterval(mlag, -2)).empty()) - makeAuxVariables(name, -1, -2, mlag, fp, as); - // substitute all endo leaded more than 1 - while (!(name = findEndoWithLeadInInterval(2, mlead)).empty()) - makeAuxVariables(name, 1, 2, mlead, fp, as); - - exovarspan(mlead, mlag); - - // substitute all lagged exo - while (!(name = findExoWithLeadInInterval(mlag, -1)).empty()) - makeAuxVariables(name, -1, -1, mlag, fp, as); - // substitute all leaded exo - while (!(name = findExoWithLeadInInterval(1, mlead)).empty()) - makeAuxVariables(name, 1, 1, mlead, fp, as); - - // notify that substitution have been finished - as.substitutions_finished(order_type); -} - -void -SAtoms::substituteAllLagsAndExo1Leads(FormulaParser &fp, AtomSubstitutions &as) -{ - string name; - - int mlead, mlag; - endovarspan(mlead, mlag); - - // substitute all endo lagged more than 1 - while (!(name = findEndoWithLeadInInterval(mlag, -2)).empty()) - makeAuxVariables(name, -1, -2, mlag, fp, as); - - exovarspan(mlead, mlag); - - // substitute all lagged exo - while (!(name = findExoWithLeadInInterval(mlag, -1)).empty()) - makeAuxVariables(name, -1, -1, mlag, fp, as); - // substitute all leaded exo by 1 - while (!(name = findExoWithLeadInInterval(1, 1)).empty()) - makeAuxVariables(name, 1, 1, 1, fp, as); - - // notify that substitution have been finished - as.substitutions_finished(order_type); -} - -string -SAtoms::findNameWithLeadInInterval(const vector<string> &names, - int ll1, int ll2) const -{ - for (auto name : names) - { - auto it = vars.find(name); - if (it != vars.end()) - { - const DynamicAtoms::Tlagmap &lmap = it->second; - for (auto itt : lmap) - if (itt.first >= ll1 && itt.first <= ll2) - return name; - } - } - - // nothing found - return ""; -} - -void -SAtoms::attemptAuxName(const string &str, int ll, string &out) const -{ - char c = (ll >= 0) ? ((ll == 0) ? 'e' : 'p') : 'm'; - string absll = std::to_string(std::abs(ll)); - int iter = 1; - do - { - out = str + '_'; - for (int i = 0; i < iter; i++) - out += c; - if (ll != 0) - out += absll; - iter++; - } - while (varnames.query(out)); -} - -void -SAtoms::makeAuxVariables(const string &name, int step, int start, int limit_lead, - FormulaParser &fp, AtomSubstitutions &as) -{ - if (!(step == 1 || step == -1)) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong value of step in SAtoms::makeAuxVariables"); - if (step*start > step*limit_lead) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong value of start in SAtoms::makeAuxVariables"); - - // make sure that we do not go further than necessary, this is - // that the limit lead is not behind maxlead or minlag - int mlead, mlag; - varspan(name, mlead, mlag); - if (step == -1) - limit_lead = std::max(limit_lead, mlag); - else - limit_lead = std::min(limit_lead, mlead); - - // Comment to comments: name="a"; start=-3; step=-1; - - // recover tree index of a previous atom, i.e. set tprev to a tree - // index of atom "a(-2)" - int tprev = index(name, start-step); - if (tprev == -1) - tprev = fp.add_nulary(name + '(' + std::to_string(start-step) + ')'); - - int ll = start; - do - { - // either create atom "a_m2(0)" with tree index taux and add - // equation "a_m2(0)=a(-2)" - // or - // check if "a_m2(0)" has not been already created (with - // different step), in this case do not add equation "a_m2(0) - // = a(-2)" - string newname, newname_str; - int taux; - if ((newname = as.get_new4old(name, ll-step)).empty()) - { - attemptAuxName(name, ll-step, newname_str); - newname = newname_str; - register_uniq_endo(newname); - taux = fp.add_nulary(newname + "(0)"); - // add to substitutions - as.add_substitution(newname, name, ll-step); - - // add equation "a_m2(0) = a(-2)", this is taux = tprev - fp.add_formula(fp.add_binary(code_t::MINUS, taux, tprev)); - } - else - { - // example: exogenous EPS and occurrence at both EPS(-1) - // EPS(+1) - // first call makeAuxVariables("EPS",1,1,...) will make endo EPS_p0 = EPS - // second call makeAuxVariables("EPS",-1,-1,...) will use this EPS_p0 - // to substitute for EPS(-1) - taux = index(newname, 0); - if (taux < 0) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find tree index of previously substituted variable"); - } - - // create atom "a_m2(-1)" or turn "a(-3)" if any to "a_m2(-1)"; tree index t - int t = index(name, ll); - if (t == -1) - { - // no "a(-3)", make t <-> a_m2(-1) - t = fp.add_nulary(newname + '(' + std::to_string(step) + ')'); - } - else - { - // turn a(-3) to a_m2(-1) - unassign_variable(name, ll, t); - assign_variable(newname, step, t); - } - - // next iteration starts with tprev <-> "a_m2(-1)" (this will be made equal to "a_m3(0)") - tprev = t; - - ll += step; - } - while (step*ll <= step*limit_lead); -} diff --git a/dynare++/parser/cc/atom_substitutions.hh b/dynare++/parser/cc/atom_substitutions.hh deleted file mode 100644 index 3fbf3e80a40a3951b41cadf7f3542b6e0c3f9c6c..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/atom_substitutions.hh +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_ATOM_SUBSTITUTIONS_H -#define OGP_ATOM_SUBSTITUTIONS_H - -#include "fine_atoms.hh" - -#include <string> - -namespace ogp -{ - - using std::string; - using std::map; - using std::pair; - - /** This class tracts an information about the performed - * substitutions. In fact, there is only one number to keep track - * about, this is a number of substitutions. */ - struct SubstInfo - { - int num_substs{0}; - SubstInfo() = default; - }; - - /** This class tracks all atom substitutions during the job and - * then builds structures when all substitutions are finished. */ - class AtomSubstitutions - { - public: - using Tshiftname = pair<string, int>; - using Tshiftmap = map<string, Tshiftname>; - using Tshiftnameset = set<Tshiftname>; - using Toldnamemap = map<string, Tshiftnameset>; - protected: - /** This maps a new name to a shifted old name. This is, one - * entry looks as "a_m3 ==> a(-3)", saying that a variable - * "a_m3" corresponds to a variable "a" lagged by 3. */ - Tshiftmap new2old; - /** This is inverse to new2old, which is not unique. For old - * name, say "a", it says what new names are derived with what - * shifts from the "a". For example, it can map "a" to a two - * element set {["a_m3", +3], ["a_p2", -2]}. This says that - * leading "a_m3" by 3 one gets old "a" and lagging "a_p2" by - * 2 one gets also old "a". */ - Toldnamemap old2new; - /** This is a reference to old atoms with multiple leads and - * lags. They are supposed to be used with parsing finished - * being had called, so that the external ordering is - * available. */ - const FineAtoms &old_atoms; - /** This is a reference to new atoms. All name pointers point - * to storage of these atoms. */ - FineAtoms &new_atoms; - /** Substitutions information. */ - SubstInfo info; - public: - /** Create the object with reference to the old and new - * atoms. In the beginning, old atoms are supposed to be with - * parsing_finished() called, and new atoms a simple copy of - * old atoms. The new atoms will be an instance of SAtoms. All - * substitution job is done by a substitution method of the - * new atoms. */ - AtomSubstitutions(const FineAtoms &oa, FineAtoms &na) - : old_atoms(oa), new_atoms(na) - { - } - /** Construct a copy of the object using a different instances - * of old atoms and new atoms, which are supposed to be - * semantically same as the atoms from as. */ - AtomSubstitutions(const AtomSubstitutions &as, const FineAtoms &oa, FineAtoms &na); - virtual ~AtomSubstitutions() = default; - /** This is called during the substitution job from the - * substitution method of the new atoms. This says that the - * new name, say "a_m3" is a substitution of old name "a" - * shifted by -3. */ - void add_substitution(string newname, string oldname, int tshift); - /** This is called when all substitutions are finished. This - * forms the new external ordering of the new atoms and calls - * parsing_finished() for the new atoms with the given ordering type. */ - void substitutions_finished(VarOrdering::ord_type ot); - /** Returns a new name for old name and given tshift. For "a" - * and tshift=-3, it returns "a_m3". If there is no such - * substitution, it returns an empty string. */ - string get_new4old(const string &oldname, int tshift) const; - /** Return new2old. */ - const Tshiftmap & - get_new2old() const - { - return new2old; - } - /** Return old2new. */ - const Toldnamemap & - get_old2new() const - { - return old2new; - } - /** Return substitution info. */ - const SubstInfo & - get_info() const - { - return info; - } - /** Return old atoms. */ - const FineAtoms & - get_old_atoms() const - { - return old_atoms; - } - /** Return new atoms. */ - const FineAtoms & - get_new_atoms() const - { - return new_atoms; - } - /** Debug print. */ - void print() const; - }; - - class SAtoms : public FineAtoms - { - public: - SAtoms() - : FineAtoms() - { - } - SAtoms(const SAtoms &sa) = default; - /** This substitutes all lags and leads for all exogenous and - * all lags and leads greater than 1 for all endogenous - * variables. This is useful for perfect foresight problems - * where we can do that. */ - void substituteAllLagsAndLeads(FormulaParser &fp, AtomSubstitutions &as); - /** This substitutes all lags of all endo and exo and one step - * leads of all exo variables. This is useful for stochastic - * models where we cannot solve leads more than 1. */ - void substituteAllLagsAndExo1Leads(FormulaParser &fp, AtomSubstitutions &as); - protected: - /** This finds an endogenous variable name which occurs between - * ll1 and ll2 included. */ - string - findEndoWithLeadInInterval(int ll1, int ll2) const - { - return findNameWithLeadInInterval(get_endovars(), ll1, ll2); - } - /** This finds an exogenous variable name which occurs between - * ll1 and ll2 included. */ - string - findExoWithLeadInInterval(int ll1, int ll2) const - { - return findNameWithLeadInInterval(get_exovars(), ll1, ll2); - } - - /** This attempts to find a non registered name of the form - * <str>_m<abs(ll)> or <str>_p<abs(ll)>. A letter 'p' is - * chosen if ll is positive, 'm' if negative. If a name of - * such form is already registered, one more character (either - * 'p' or 'm') is added and the test is performed again. The - * resulting name is returned in a string out. */ - void attemptAuxName(const string &str, int ll, string &out) const; - - /** This makes auxiliary variables to eliminate all leads/lags - * greater/less than or equal to start up to the limit_lead - * for a variable with the given name. If the limit_lead is - * greater/less than the maxlead/minlag of the variable, than - * maxlead/minlag is used. This process is recorded in - * AtomSubstitutions. The new auxiliary variables and their - * atoms are created in this object. The auxiliary equations - * are created in the given FormulaParser. The value of step - * is allowed to be either -1 (lags) or +1 (leads). */ - void makeAuxVariables(const string &name, int step, int start, int limit_lead, - FormulaParser &fp, AtomSubstitutions &as); - private: - /** This is a worker routine for findEndoWithLeadInInterval - * and findExoWithLeadInInterval. */ - string findNameWithLeadInInterval(const vector<string> &names, - int ll1, int ll2) const; - - }; - -}; - -#endif diff --git a/dynare++/parser/cc/dynamic_atoms.cc b/dynare++/parser/cc/dynamic_atoms.cc deleted file mode 100644 index 580ec70d00bf5ce12e4d53b2f2740f9c99674942..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/dynamic_atoms.cc +++ /dev/null @@ -1,617 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "utils/cc/exception.hh" -#include "dynamic_atoms.hh" - -using namespace ogp; - -void -NameStorage::insert(string name) -{ - if (!query(name)) - { - name_store.push_back(name); - name_set.insert(std::move(name)); - } -} - -void -NameStorage::print() const -{ - for (auto i : name_store) - std::cout << i << '\n'; -} - -void -Constants::import_constants(const Constants &c, OperationTree &otree, Tintintmap &tmap) -{ - for (auto it : c.cmap) - { - int told = it.first; - int tnew = otree.add_nulary(); - tmap.emplace(told, tnew); - add_constant(tnew, it.second); - } -} - -void -Constants::setValues(EvalTree &et) const -{ - for (const auto &it : cmap) - et.set_nulary(it.first, it.second); -} - -void -Constants::add_constant(int t, double val) -{ - cmap.emplace(t, val); - cinvmap.emplace(val, t); -} - -bool -Constants::is_constant(int t) const -{ - if (t < OperationTree::num_constants) - return true; - auto it = cmap.find(t); - return (it != cmap.end()); -} - -double -Constants::get_constant_value(int t) const -{ - auto it = cmap.find(t); - if (it != cmap.end()) - return it->second; - else - throw ogu::Exception(__FILE__, __LINE__, - "Tree index is not constant in Constants::get_constant_value"); -} - -int -Constants::check(const string &str) const -{ - double d = std::stod(str); - auto it = cinvmap.find(d); - if (it != cinvmap.end()) - return it->second; - else - return -1; -} - -void -Constants::print() const -{ - for (const auto &it : cmap) - std::cout << "$" << it.first << ": " << it.second << "\n"; -} - -int -DynamicAtoms::check(const string &name) const -{ - if (is_string_constant(name)) - return Constants::check(name); - - return check_variable(name); -} - -int -DynamicAtoms::check_variable(const string &name) const -{ - string str; - int ll; - parse_variable(name, str, ll); - auto it = vars.find(str); - - if (it != vars.end()) - { - const Tlagmap &lmap = it->second; - auto itt = lmap.find(ll); - if (itt != lmap.end()) - return itt->second; - } - return -1; -} - -void -DynamicAtoms::assign(const string &name, int t) -{ - if (is_string_constant(name)) - assign_constant(name, t); - else - assign_variable(name, t); -} - -void -DynamicAtoms::assign_constant(const string &name, int t) -{ - double val = std::stod(name); - add_constant(t, val); -} - -// parse the name and then call assing_variable(varname, ll, t) - -void -DynamicAtoms::assign_variable(const string &name, int t) -{ - int ll; - string str; - parse_variable(name, str, ll); - // here str is just name without lead/lag - varnames.insert(str); - - assign_variable(str, ll, t); -} - -void -DynamicAtoms::assign_variable(const string &varname, int ll, int t) -{ - if (indices.end() != indices.find(t)) - throw ogu::Exception(__FILE__, __LINE__, - "Attempt to assign already allocated tree index"); - - auto it = vars.find(varname); - if (it != vars.end()) - { - Tlagmap &lmap = it->second; - if (lmap.end() != lmap.find(ll)) - throw ogu::Exception(__FILE__, __LINE__, - "Attempt to assign already allocated variable"); - lmap.emplace(ll, t); - } - else - { - Tlagmap lmap; - lmap.emplace(ll, t); - vars.emplace(varname, lmap); - } - indices.emplace(t, varname); - - nv++; - minlag = std::min(ll, minlag); - maxlead = std::max(ll, maxlead); -} - -void -DynamicAtoms::unassign_variable(const string &varname, int ll, int t) -{ - auto it = vars.find(varname); - if (it != vars.end()) - { - Tlagmap &lmap = it->second; - auto itt = lmap.find(ll); - if (itt != lmap.end()) - { - if (itt->second == t) - { - // erase it from the lagmap; if it becomes empty, - // erase the lagmap from varmap - lmap.erase(itt); - if (lmap.size() == 0) - vars.erase(it); - // erase it from the indices - auto ittt = indices.find(t); - if (ittt != indices.end()) - indices.erase(ittt); - - nv--; - if (ll == minlag || ll == maxlead) - update_minmaxll(); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "Tree index inconsistent in DynamicAtoms::unassign_variable"); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "Lead/lag of the variable not found in DynamicAtoms::unassign_variable"); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "Variable not found in DynamicAtoms::unassign_variable"); -} - -void -DynamicAtoms::update_minmaxll() -{ - minlag = std::numeric_limits<int>::max(); - maxlead = std::numeric_limits<int>::min(); - for (const auto &it : vars) - { - const Tlagmap &lmap = it.second; - for (auto itt : lmap) - { - int ll = itt.first; - minlag = std::min(ll, minlag); - maxlead = std::max(ll, maxlead); - } - } -} - -vector<int> -DynamicAtoms::variables() const -{ - vector<int> res; - for (const auto &var : vars) - { - const Tlagmap &lmap = var.second; - for (auto itt : lmap) - res.push_back(itt.second); - } - return res; -} - -void -DynamicAtoms::varspan(int t, int &mlead, int &mlag) const -{ - auto it = indices.find(t); - if (indices.end() == it) - { - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - return; - } - varspan(it->second, mlead, mlag); -} - -void -DynamicAtoms::varspan(const string &name, int &mlead, int &mlag) const -{ - auto it = vars.find(name); - if (vars.end() == it) - { - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - return; - } - const Tlagmap &lmap = it->second; - auto beg = lmap.begin(); - auto end = lmap.rbegin(); - mlag = beg->first; - mlead = end->first; -} - -void -DynamicAtoms::varspan(const vector<string> &names, int &mlead, int &mlag) const -{ - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - for (const auto &name : names) - { - int lag, lead; - varspan(name, lead, lag); - mlead = std::max(lead, mlead); - mlag = std::min(lag, mlag); - } -} - -bool -DynamicAtoms::is_named_atom(int t) const -{ - return indices.end() != indices.find(t); -} - -int -DynamicAtoms::index(const string &name, int ll) const -{ - auto it = vars.find(name); - if (vars.end() != it) - { - const Tlagmap &lmap = it->second; - auto itt = lmap.find(ll); - if (lmap.end() != itt) - return itt->second; - } - return -1; -} - -bool -DynamicAtoms::is_referenced(const string &name) const -{ - return vars.find(name) != vars.end(); -} - -const DynamicAtoms::Tlagmap & -DynamicAtoms::lagmap(const string &name) const -{ - auto it = vars.find(name); - if (vars.end() == it) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find the name " - + name + " in DynamicAtoms::lagmap"); - return it->second; -} - -const string & -DynamicAtoms::name(int t) const -{ - auto it = indices.find(t); - if (indices.end() == it) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find tree index in DynamicAtoms::name"); - return it->second; -} - -int -DynamicAtoms::lead(int t) const -{ - const string &nam = name(t); - const Tlagmap &lmap = lagmap(nam); - auto it = lmap.begin(); - while (it != lmap.end() && it->second != t) - ++it; - if (lmap.end() == it) - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find the three index in DynamicAtoms::lead"); - return it->first; -} - -void -DynamicAtoms::print() const -{ - std::cout << "names:\n"; - varnames.print(); - std::cout << "constants:\n"; - Constants::print(); - std::cout << "variables:\n"; - for (const auto &var : vars) - { - const Tlagmap &lmap = var.second; - for (auto itt : lmap) - std::cout << "$" << itt.second << ": " << var.first << "(" << itt.first << ")\n"; - } - std::cout << "indices:\n"; - for (auto indice : indices) - std::cout << "t=" << indice.first << " ⇒ " << indice.second << "\n"; -} - -/** Note that the str has been parsed by the lexicographic - * analyzer. It can be either a variable or a double. So it is easy to - * recognize it by the first character. */ -bool -DynamicAtoms::is_string_constant(const string &str) -{ - return str[0] == '.' || str[0] == '-' || (str[0] >= '0' && str[0] <= '9'); -} - -VarOrdering::VarOrdering(const VarOrdering &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : n_stat(vo.n_stat), n_pred(vo.n_pred), n_both(vo.n_both), n_forw(vo.n_forw), - der_atoms(vo.der_atoms), positions(vo.positions), - outer2y(vo.outer2y), y2outer(vo.y2outer), varnames(vnames), atoms(a) -{ -} - -bool -VarOrdering::check(int t) const -{ - return positions.find(t) != positions.end(); -} - -int -VarOrdering::get_pos_of(int t) const -{ - auto it = positions.find(t); - if (it != positions.end()) - return it->second; - else - throw ogu::Exception(__FILE__, __LINE__, - "Couldn't find the tree index in VarOrdering::get_pos_of"); -} - -void -VarOrdering::do_general(ord_type ordering) -{ - // auxiliary vectors for setting der_atoms and map - vector<int> pred_minus; - vector<int> both_minus; - vector<int> stat; - vector<int> pred_pad; - vector<int> both_pad; - vector<int> forw_pad; - vector<int> both_plus; - vector<int> forw_plus; - - // auxiliary vectors for setting y2outer and outer2y - vector<int> y2o_stat; - vector<int> y2o_pred; - vector<int> y2o_both; - vector<int> y2o_forw; - - for (unsigned int i = 0; i < varnames.size(); i++) - { - const string &ss = varnames[i]; - int lead; - int lag; - atoms.varspan(ss, lead, lag); - if (lag == 0 && lead == 0) - { - stat.push_back(atoms.index(ss, 0)); - y2o_stat.push_back(i); - } - else if (lag == -1 && lead < 1) - { - pred_minus.push_back(atoms.index(ss, -1)); - pred_pad.push_back(atoms.index(ss, 0)); - y2o_pred.push_back(i); - } - else if (lag > -1 && lead == 1) - { - forw_pad.push_back(atoms.index(ss, 0)); - forw_plus.push_back(atoms.index(ss, 1)); - y2o_forw.push_back(i); - } - else if (lag == -1 && lead == 1) - { - both_minus.push_back(atoms.index(ss, -1)); - both_pad.push_back(atoms.index(ss, 0)); - both_plus.push_back(atoms.index(ss, 1)); - y2o_both.push_back(i); - } - else - throw ogu::Exception(__FILE__, __LINE__, - "A wrong lag/lead of a variable in VarOrdering::do_pbspbfbf"); - } - - // here we fill ords according to ordering - vector<int> *ords[8]; - if (ordering == pbspbfbf) - { - ords[0] = &pred_minus; - ords[1] = &both_minus; - ords[2] = &stat; - ords[3] = &pred_pad; - ords[4] = &both_pad; - ords[5] = &forw_pad; - ords[6] = &both_plus; - ords[7] = &forw_plus; - } - else if (ordering == bfspbfpb) - { - ords[0] = &both_plus; - ords[1] = &forw_plus; - ords[2] = &stat; - ords[3] = &pred_pad; - ords[4] = &both_pad; - ords[5] = &forw_pad; - ords[6] = &pred_minus; - ords[7] = &both_minus; - } - else // BEWARE: when implementing a new ordering, check also the code below setting y2outer - throw ogu::Exception(__FILE__, __LINE__, - "Ordering not implemented in VarOrdering::do_general"); - - // make der_atoms and positions - int off = 0; - for (auto &ord : ords) - for (unsigned int j = 0; j < ord->size(); j++, off++) - if ((*ord)[j] != -1) - { - der_atoms.push_back((*ord)[j]); - positions.emplace((*ord)[j], off); - } - - // set integer constants - n_stat = stat.size(); - n_pred = pred_pad.size(); - n_both = both_pad.size(); - n_forw = forw_pad.size(); - - // make y2outer mapping - y2outer.insert(y2outer.end(), y2o_stat.begin(), y2o_stat.end()); - y2outer.insert(y2outer.end(), y2o_pred.begin(), y2o_pred.end()); - y2outer.insert(y2outer.end(), y2o_both.begin(), y2o_both.end()); - y2outer.insert(y2outer.end(), y2o_forw.begin(), y2o_forw.end()); - // make outer2y mapping - outer2y.resize(y2outer.size(), -1); - for (unsigned int i = 0; i < y2outer.size(); i++) - outer2y[y2outer[i]] = i; -} - -void -VarOrdering::do_increasing_time() -{ - // get maxlead and minlag of the variables - int mlag, mlead; - atoms.varspan(varnames, mlead, mlag); - // setup the matrix of tree indices, if there is no occurrence, - // the index is set to -1 - vector<int> ll_init(varnames.size(), -1); - vector<vector<int>> tree_ind(mlead-mlag+1, ll_init); - for (unsigned int iv = 0; iv < varnames.size(); iv++) - { - try - { - const DynamicAtoms::Tlagmap &lmap = atoms.lagmap(varnames[iv]); - for (auto it : lmap) - { - int ll = it.first; - int t = it.second; - tree_ind[ll-mlag][iv] = t; - } - } - catch (const ogu::Exception &e) - { - // ignore the error of not found variable in the tree - } - } - - // setup der_atoms and positions - for (int ll = mlag; ll <= mlead; ll++) - for (unsigned int iv = 0; iv < varnames.size(); iv++) - { - int t = tree_ind[ll-mlag][iv]; - if (t != -1) - { - der_atoms.push_back(t); - int pos = (ll-mlag)*varnames.size() + iv; - positions.emplace(t, pos); - } - } - - // set outer2y and y2outer to identities - for (unsigned int iv = 0; iv < varnames.size(); iv++) - { - outer2y.push_back(iv); - y2outer.push_back(iv); - } - - // set n_stat, n_pred, n_both, and n_forw - for (auto varname : varnames) - { - int mmlag, mmlead; - atoms.varspan(varname, mmlead, mmlag); - if (mmlead == 0 && mmlag == 0) - n_stat++; - else if (mmlead <= 0 && mmlag < 0) - n_pred++; - else if (mmlead > 0 && mmlag >= 0) - n_forw++; - else if (mmlead > 0 && mmlag < 0) - n_both++; - else if (mmlead < mmlag) - // variable does not occur in the tree, cound as static - n_stat++; - else - throw ogu::Exception(__FILE__, __LINE__, - "A wrong lag/lead of a variable in VarOrdering::do_increasing_time"); - } -} - -void -VarOrdering::print() const -{ - std::cout << "nstat=" << n_stat << ", npred=" << n_pred << ", nboth=" << n_both - << ", nforw=" << n_forw << "\n" - << "der_atoms:\n"; - for (int der_atom : der_atoms) - std::cout << " " << der_atom; - std::cout << "\nmap:\n"; - for (auto position : positions) - std::cout << " [" << position.first << "→" << position.second << "]"; - std::cout << "\ny2outer:\n"; - for (int i : y2outer) - std::cout << " " << i; - std::cout << "\nouter2y:\n"; - for (int i : outer2y) - std::cout << " " << i; - std::cout << "\n"; -} diff --git a/dynare++/parser/cc/dynamic_atoms.hh b/dynare++/parser/cc/dynamic_atoms.hh deleted file mode 100644 index f0f1bfaefe4d7ca714c71126bc9059f5dffdeb39..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/dynamic_atoms.hh +++ /dev/null @@ -1,470 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_DYNAMIC_ATOMS_H -#define OGP_DYNAMIC_ATOMS_H - -#include "formula_parser.hh" - -#include <vector> -#include <map> -#include <set> -#include <string> -#include <limits> -#include <memory> - -namespace ogp -{ - using std::vector; - using std::map; - using std::set; - using std::string; - - /** Class storing names. We will keep names of variables in - * various places, and all these pointers will point to one - * storage, which will be responsible for allocation and - * deallocation. The main function of the class is to allocate - * space for names, and return a pointer of the stored name if - * required. */ - class NameStorage - { - protected: - /** Vector of names allocated, this is the storage. */ - vector<string> name_store; - /** Map useful to quickly decide if the name is already - * allocated or not. */ - set<string> name_set; - public: - /** Query for the name. If the name has been stored, it - * true, otherwise false. */ - bool - query(const string &name) const - { - return name_set.find(name) != name_set.end(); - } - /** Insert the name if it has not been inserted yet. */ - void insert(string name); - int - num() const - { - return static_cast<int>(name_store.size()); - } - const string & - get_name(int i) const - { - return name_store[i]; - } - /** Debug print. */ - void print() const; - }; - - class Constants : public AtomValues - { - public: - /** Type for a map mapping tree indices to double values. */ - using Tconstantmap = map<int, double>; - using Tintintmap = map<int, int>; - protected: - /** Map mapping a tree index of a constant to its double value. */ - Tconstantmap cmap; - public: - Constants() = default; - /** Copy constructor. */ - Constants(const Constants &c) - : cmap(c.cmap), cinvmap(c.cinvmap) - { - } - /** Copy constructor registering the constants in the given - * tree. The mapping from old tree indices to new ones is - * traced in tmap. */ - Constants(const Constants &c, OperationTree &otree, Tintintmap &tmap) - { - import_constants(c, otree, tmap); - } - /** Import constants registering their tree indices in the - * given tree. The mapping form old tree indices to new ones - * is traced in tmap. */ - void import_constants(const Constants &c, OperationTree &otree, Tintintmap &tmap); - /** Implements AtomValues interface. This sets the values to - * the evaluation tree EvalTree. */ - void setValues(EvalTree &et) const override; - /** This adds a constant with the given tree index. The - * constant must be checked previously and asserted that it - * does not exist. */ - void add_constant(int t, double val); - /** Returns true if the tree index is either an hardwired - * constant (initial number OperationTree:num_constants in - * OperationTree) or the tree index is a registered constant - * by add_constant method. */ - bool is_constant(int t) const; - double get_constant_value(int t) const; - /** Return -1 if the given string representation of a constant - * is not among the constants (double represenations). If it - * is, its tree index is returned. */ - int check(const string &str) const; - /** Debug print. */ - void print() const; - const Tconstantmap & - get_constantmap() const - { - return cmap; - } - private: - /** Inverse map to Tconstantmap. */ - using Tconstantinvmap = map<double, int>; - /** This is an inverse map to cmap. This is only used for fast - * queries for the existing double constants in check - * method and add_constant. */ - Tconstantinvmap cinvmap; - }; - - /** This class is a parent to Atoms classes which distinguish between - * constants (numerical literals), and variables with lags and - * leads. This abstraction does not distinguish between a parameter - * and a variable without lag or lead. In this sense, everything is a - * variable.*/ - class DynamicAtoms : public Atoms, public Constants - { - public: - /** Definition of a type mapping lags to the indices of the variables. */ - using Tlagmap = map<int, int>; - protected: - /** Definition of a type mapping names of the atoms to Tlagmap. */ - using Tvarmap = map<string, Tlagmap>; - /** Definition of a type mapping indices of variables to the variable names. */ - using Tindexmap = map<int, string>; - /** This is just a storage for variable names, since all other - * instances of a variable name just point to the memory - * allocated by this object. */ - NameStorage varnames; - /** This is the map for variables. Each variable name is - * mapped to the Tlagmap, which maps lags/leads to the nulary - * term indices in the tree. */ - Tvarmap vars; - /** This is almost inverse map to the vars. It maps variable - * indices to the names. A returned name can be in turn used - * as a key in vars. */ - Tindexmap indices; - - /** Number of variables. */ - int nv{0}; - /** Minimum lag, if there is at least one lag, than this is a negative number. */ - int minlag{std::numeric_limits<int>::max()}; - /** Maximum lead, if there is at least one lead, than this is a positive number. */ - int maxlead{std::numeric_limits<int>::min()}; - public: - /** Construct empty DynamicAtoms. */ - DynamicAtoms() = default; - /** Check the nulary term identified by its string - * representation. The nulary term can be either a constant or - * a variable. If constant, -1 is returned so that it could be - * assigned regardless if the same constant has already - * appeared or not. If variable, then -1 is returned only if - * the variable has not been assigned an index, otherwise the - * assigned index is returned. */ - int check(const string &name) const override; - /** Assign the nulary term identified by its string - * representation. This method should be called when check() - * returns -1. */ - void assign(const string &name, int t) override; - /** Return a number of all variables. */ - int - nvar() const override - { - return nv; - } - /** Return the vector of variable indices. */ - vector<int> variables() const override; - /** Return max lead and min lag for a variable given by the - * index. If a variable cannot be found, the method retursn - * the smallest integer as maxlead and the largest integer as - * minlag. */ - void varspan(int t, int &mlead, int &mlag) const; - /** Return max lead and min lag for a variable given by the - * name (without lead, lag). The same is valid if the variable - * name cannot be found. */ - void varspan(const string &name, int &mlead, int &mlag) const; - /** Return max lead and min lag for a vector of variables given by the names. */ - void varspan(const vector<string> &names, int &mlead, int &mlag) const; - /** Return true for all tree indices corresponding to a - * variable in the sense of this class. (This is parameters, - * exo and endo). Since the semantics of 'variable' will be - * changed in subclasses, we use name 'named atom'. These are - * all atoms but constants. */ - bool is_named_atom(int t) const; - /** Return index of the variable described by the variable - * name and lag/lead. If it doesn't exist, return -1. */ - int index(const string &name, int ll) const; - /** Return true if a variable is referenced, i.e. it has lag - * map. */ - bool is_referenced(const string &name) const; - /** Return the lag map for the variable name. */ - const Tlagmap &lagmap(const string &name) const; - /** Return the variable name for the tree index. It throws an - * exception if the tree index t is not a named atom. */ - const string &name(int t) const; - /** Return the lead/lag for the tree index. It throws an - * exception if the tree index t is not a named atom. */ - int lead(int t) const; - /** Return maximum lead. */ - int - get_maxlead() const - { - return maxlead; - } - /** Return minimum lag. */ - int - get_minlag() const - { - return minlag; - } - /** Return the name storage to allow querying to other - * classes. */ - const NameStorage & - get_name_storage() const - { - return varnames; - } - /** Assign the variable with a given lead. The varname must be - * from the varnames storage. The method checks if the - * variable iwht the given lead/lag is not assigned. If so, an - * exception is thrown. */ - void assign_variable(const string &varname, int ll, int t); - /** Unassign the variable with a given lead and given tree - * index. The tree index is only provided as a check. An - * exception is thrown if the name, ll, and the tree index t - * are not consistent. The method also updates nv, indices, - * maxlead and minlag. The varname must be from the varnames - * storage. */ - void unassign_variable(const string &varname, int ll, int t); - /** Debug print. */ - void print() const override; - protected: - /** Do the check for the variable. A subclass may need to - * reimplement this so that it could raise an error if the - * variable is not among a given list. */ - virtual int check_variable(const string &name) const; - /** Assign the constant. */ - void assign_constant(const string &name, int t); - /** Assign the variable. */ - void assign_variable(const string &name, int t); - /** The method just updates minlag or/and maxlead. Note that - * when assigning variables, the update is done when inserting - * to the maps, however, if removing a variable, we need to - * call this method. */ - void update_minmaxll(); - /** The method parses the string to recover a variable name - * and lag/lead ll. The variable name doesn't contain a lead/lag. */ - virtual void parse_variable(const string &in, string &out, int &ll) const = 0; - public: - /** Return true if the str represents a double.*/ - static bool is_string_constant(const string &str); - }; - - /** This class is a parent of all orderings of the dynamic atoms - * of variables which can appear before t, at t, or after t. It - * encapsulates the ordering, and the information about the number - * of static (appearing only at time t) predetermined (appearing - * before t and possibly at t), both (appearing before t and after - * t and possibly at t) and forward looking (appearing after t and - * possibly at t). - * - * The constructor takes a list of variable names. The class also - * provides mapping from the ordering of the variables in the list - * (outer) to the new ordering (at time t) and back. - * - * The user of the subclass must call do_ordering() after - * initialization. - * - * The class contains a few preimplemented methods for - * ordering. The class is used in this way: Make a subclass, and - * implement pure virtual do_ordering() by just plugging a - * preimplemented method, or plugging your own implementation. The - * method do_ordering() is called by the user after the constructor. - */ - class VarOrdering - { - protected: - /** Number of static variables. */ - int n_stat; - /** Number of predetermined variables. */ - int n_pred; - /** Number of both variables. */ - int n_both; - /** Number of forward looking variables. */ - int n_forw; - /** This is a set of tree indices corresponding to the - * variables at all times as they occur in the formulas. In - * fact, since this is used only for derivatives, the ordering - * of this vector is only important for ordering of the - * derivatives, in other contexts the ordering is not - * important, so it is rather a set of indices.*/ - vector<int> der_atoms; - /** This maps tree index of the variable to the position in - * the row of the ordering. One should be careful with making - * space in the positions for variables not appearing at time - * t. For instance in the pred(t-1), both(t-1), stat(t), - * pred(t), both(t), forw(t), both(t+1), forw(t+1) ordering, - * the variables x(t-1), y(t-1), x(t+1), z(t-1), z(t), and - * z(t+1) having tree indices 6,5,4,3,2,1 will be ordered as - * follows: y(t-1), x(t-1), z(t-1), [y(t)], [x(t)], z(t), - * x(t+1), where a bracketed expresion means non-existent by - * occupying a space. The map thus will look as follows: - * {5→0, 6→1, 3→2, 2→5, 3→6}. Note that nothing is mapped - * to positions 3 and 4. */ - map<int, int> positions; - /** This maps an ordering of the list of variables in - * constructor to the new ordering (at time t). The length is - * the number of variables. */ - vector<int> outer2y; - /** This maps a new ordering to the ordering of the list of - * variables in constructor (at time t). The length is the - * number of variables. */ - vector<int> y2outer; - /** This is just a reference for variable names to keep it - * from constructor to do_ordering() implementations. */ - const vector<string> &varnames; - /** This is just a reference to atoms to keep it from - * constructor to do_ordering() implementations. */ - const DynamicAtoms &atoms; - public: - /** This is an enum type for an ordering type implemented by - * do_general. */ - enum ord_type { pbspbfbf, bfspbfpb }; - /** Construct the ordering of the variables given by the names - * with their dynamic occurrences defined by the atoms. It - * calls the virtual method do_ordering which can be - * reimplemented. */ - VarOrdering(const vector<string> &vnames, const DynamicAtoms &a) - : n_stat(0), n_pred(0), n_both(0), n_forw(0), varnames(vnames), atoms(a) - { - } - VarOrdering(const VarOrdering &vo, const vector<string> &vnames, - const DynamicAtoms &a); - VarOrdering(const VarOrdering &vo) = delete; - virtual std::unique_ptr<VarOrdering> clone(const vector<string> &vnames, - const DynamicAtoms &a) const = 0; - /** Destructor does nothing here. */ - virtual ~VarOrdering() = default; - /** This is the method setting the ordering and the map. A - * subclass must reimplement it, possibly using a - * preimplemented ordering. This method must be called by the - * user after the class has been created. */ - virtual void do_ordering() = 0; - /** Return number of static. */ - int - nstat() const - { - return n_stat; - } - /** Return number of predetermined. */ - int - npred() const - { - return n_pred; - } - /** Return number of both. */ - int - nboth() const - { - return n_both; - } - /** Return number of forward looking. */ - int - nforw() const - { - return n_forw; - } - /** Return the set of tree indices for derivatives. */ - const vector<int> & - get_der_atoms() const - { - return der_atoms; - } - /** Return the y2outer. */ - const vector<int> & - get_y2outer() const - { - return y2outer; - } - /** Return the outer2y. */ - const vector<int> & - get_outer2y() const - { - return outer2y; - } - /** Query the atom given by the tree index. True is returned - * if the atom is one of the variables in the object. */ - bool check(int t) const; - /** Return the position of the atom (nulary term) given by a - * tree index. It is a lookup to the map. If the atom cannot - * be found, the exception is raised. */ - int get_pos_of(int t) const; - /** This returns a length of ordered row of atoms. In all - * cases so far, it does not depend on the ordering and it is - * as follows. */ - int - length() const - { - return n_stat+2*n_pred+3*n_both+2*n_forw; - } - /** Debug print. */ - void print() const; - protected: - /** This is a general ordering method which orders the - * variables by the given ordering ord_type. See documentation - * for respective do_ methods. */ - void do_general(ord_type ordering); - /** This is a preimplemented ordering for do_ordering() - * method. It assumes that the variables appear only at time - * t-1, t, t+1. It orders the atoms as pred(t-1), both(t-1), - * stat(t), pred(t), both(t), forw(t), both(t+1), - * forw(t+1). It builds the der_atoms, the map of positions, - * as well as y2outer and outer2y. */ - void - do_pbspbfbf() - { - do_general(pbspbfbf); - } - /** This is a preimplemented ordering for do_ordering() - * method. It assumes that the variables appear only at time - * t-1, t, t+1. It orders the atoms as both(t+1), forw(t+1), - * stat(t), pred(t), both(t), forw(t), pred(t-1), - * both(t-1). It builds the der_atoms, the map of positions, - * as well as y2outer and outer2y. */ - void - do_bfspbfpb() - { - do_general(bfspbfpb); - } - /** This is a preimplemented ordering for do_ordering() - * method. It makes no assumptions about occurences of - * variables at different times. It orders the atoms with - * increasing time keeping the given ordering within one - * time. This implies that y2outer and outer2y will be - * identities. The der_atoms will be just a sequence of atoms - * from the least to the most time preserving the order of atoms - * within one time. */ - void do_increasing_time(); - }; - -}; - -#endif diff --git a/dynare++/parser/cc/fine_atoms.cc b/dynare++/parser/cc/fine_atoms.cc deleted file mode 100644 index 8143e074e25b910b45c1530860b53d3cb303a807..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/fine_atoms.cc +++ /dev/null @@ -1,536 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "utils/cc/exception.hh" - -#include "parser_exception.hh" -#include "fine_atoms.hh" - -using namespace ogp; - -AllvarOuterOrdering::AllvarOuterOrdering(const vector<string> &allvar_outer, - const FineAtoms &a) - : atoms(a), allvar(), - endo2all(a.get_endovars().size(), -1), - exo2all(a.get_exovars().size(), -1) -{ - // fill in the allvar from allvar_outer - for (const auto &s : allvar_outer) - { - if (atoms.varnames.query(s)) - allvar.push_back(s); - else - throw ogu::Exception(__FILE__, __LINE__, - "Variable " + s + " is not a declared symbol in AllvarOuterOrdering constructor"); - } - - // fill in endo2all and exo2all - for (unsigned int i = 0; i < allvar.size(); i++) - { - auto it = atoms.endo_outer_map.find(allvar[i]); - if (it != atoms.endo_outer_map.end()) - endo2all[it->second] = i; - else - { - it = atoms.exo_outer_map.find(allvar[i]); - if (it != atoms.exo_outer_map.end()) - exo2all[it->second] = i; - else - throw ogu::Exception(__FILE__, __LINE__, - "Name " + allvar[i] + " is neither endogenous nor exogenous variable in AllvarOuterOrdering constructor"); - } - } - - // check whether everything has been filled - unsigned int iendo = 0; - while (iendo < endo2all.size() && endo2all[iendo] != -1) - iendo++; - unsigned int iexo = 0; - while (iexo < exo2all.size() && exo2all[iexo] != -1) - iexo++; - if (iendo < endo2all.size()) - throw ogu::Exception(__FILE__, __LINE__, - "Endogenous variable " + atoms.get_endovars()[iendo] - +" not found in outer all ordering in AllvarOuterOrdering constructor"); - if (iexo < exo2all.size()) - throw ogu::Exception(__FILE__, __LINE__, - "Exogenous variable " + atoms.get_exovars()[iexo] - +" not found in outer all ordering in AllvarOuterOrdering constructor"); -} - -AllvarOuterOrdering::AllvarOuterOrdering(const AllvarOuterOrdering &avo, - const FineAtoms &a) - : atoms(a), allvar(avo.allvar), - endo2all(avo.endo2all), - exo2all(avo.exo2all) -{ -} - -FineAtoms::FineAtoms(const FineAtoms &fa) - : DynamicAtoms(fa), params(), endovars(), exovars(), - der_atoms(fa.der_atoms), - endo_atoms_map(fa.endo_atoms_map), - exo_atoms_map(fa.exo_atoms_map) -{ - // fill in params - for (const auto ¶m : fa.params) - { - if (!varnames.query(param)) - throw ogu::Exception(__FILE__, __LINE__, - "Parameter " + param + " does not exist in FineAtoms copy cosntructor"); - params.push_back(param); - param_outer_map.emplace(param, params.size()-1); - } - // fill in endovars - for (const auto &endovar : fa.endovars) - { - if (!varnames.query(endovar)) - throw ogu::Exception(__FILE__, __LINE__, - "Endo variable " + endovar + " does not exist in FineAtoms copy constructor"); - endovars.push_back(endovar); - endo_outer_map.emplace(endovar, endovars.size()-1); - } - // fill in exovars - for (const auto &exovar : fa.exovars) - { - if (!varnames.query(exovar)) - throw ogu::Exception(__FILE__, __LINE__, - "Exo variable " + exovar + " does not exist in FineAtoms copy cosntructor"); - exovars.push_back(exovar); - exo_outer_map.emplace(exovar, exovars.size()-1); - } - - if (fa.endo_order) - endo_order = fa.endo_order->clone(endovars, *this); - - if (fa.exo_order) - exo_order = fa.exo_order->clone(exovars, *this); - - if (fa.allvar_order) - allvar_order = std::make_unique<AllvarOuterOrdering>(*(fa.allvar_order), *this); -} - -int -FineAtoms::check_variable(const string &name) const -{ - string str; - int ll; - parse_variable(name, str, ll); - if (varnames.query(str)) - return DynamicAtoms::check_variable(name); - else - { - throw ParserException("Variable <"+str+"> not declared.", 0); - return -1; - } -} - -int -FineAtoms::num_exo_periods() const -{ - int mlead, mlag; - exovarspan(mlead, mlag); - return mlead-mlag+1; -} - -void -FineAtoms::parsing_finished(VarOrdering::ord_type ot) -{ - make_internal_orderings(ot); - - // by default, concatenate outer endo and outer exo and make it as - // allvar outer: - vector<string> allvar_tmp; - allvar_tmp.insert(allvar_tmp.end(), endovars.begin(), endovars.end()); - allvar_tmp.insert(allvar_tmp.end(), exovars.begin(), exovars.end()); - - allvar_order = std::make_unique<AllvarOuterOrdering>(allvar_tmp, *this); -} - -void -FineAtoms::parsing_finished(VarOrdering::ord_type ot, - const vector<string> &allvar) -{ - make_internal_orderings(ot); - allvar_order = std::make_unique<AllvarOuterOrdering>(allvar, *this); -} - -const vector<string> & -FineAtoms::get_allvar() const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_allvars called before parsing_finished"); - - return allvar_order->get_allvar(); -} - -const vector<int> & -FineAtoms::outer_endo2all() const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer_endo2all called before parsing_finished"); - - return allvar_order->get_endo2all(); -} - -const vector<int> & -FineAtoms::outer_exo2all() const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer_exo2all called before parsing_finished"); - - return allvar_order->get_exo2all(); -} - -vector<int> -FineAtoms::variables() const -{ - if (endo_order) - return der_atoms; - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::variables called before parsing_finished"); - return {}; - } -} - -int -FineAtoms::nstat() const -{ - if (endo_order) - return endo_order->nstat(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::nstat called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::npred() const -{ - if (endo_order) - return endo_order->npred(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::npred called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::nboth() const -{ - if (endo_order) - return endo_order->nboth(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::nboth called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::nforw() const -{ - if (endo_order) - return endo_order->nforw(); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::nforw called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::get_pos_of_endo(int t) const -{ - if (endo_order) - return endo_order->get_pos_of(t); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_pos_of_endo called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::get_pos_of_exo(int t) const -{ - if (exo_order) - return exo_order->get_pos_of(t); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_pos_of_exo called before parsing_finished"); - return -1; - } -} - -int -FineAtoms::get_pos_of_all(int t) const -{ - if (endo_order && exo_order) - { - if (endo_order->check(t)) - return endo_order->get_pos_of(t); - else if (exo_order->check(t)) - return endo_order->length() + exo_order->get_pos_of(t); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Atom is not endo nor exo in FineAtoms::get_pos_of_all"); - return -1; - } - } - else - { - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_pos_of_exo called before parsing_finished"); - return -1; - } -} - -const vector<int> & -FineAtoms::y2outer_endo() const -{ - if (!endo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::y2outer_endo called before parsing_finished"); - return endo_order->get_y2outer(); -} - -const vector<int> & -FineAtoms::outer2y_endo() const -{ - if (!endo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer2y_endo called before parsing_finished"); - return endo_order->get_outer2y(); -} - -const vector<int> & -FineAtoms::y2outer_exo() const -{ - if (!exo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::y2outer_endo called before parsing_finished"); - return exo_order->get_y2outer(); -} - -const vector<int> & -FineAtoms::outer2y_exo() const -{ - if (!exo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::outer2y_exo called before parsing_finished"); - return exo_order->get_outer2y(); -} - -const vector<int> & -FineAtoms::get_endo_atoms_map() const -{ - if (!endo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_endo_atoms_map called before parsing_finished"); - return endo_atoms_map; -} - -const vector<int> & -FineAtoms::get_exo_atoms_map() const -{ - if (!exo_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::get_exo_atoms_map called before parsing_finished"); - return exo_atoms_map; -} - -int -FineAtoms::name2outer_param(const string &name) const -{ - auto it = param_outer_map.find(name); - if (it == param_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not a parameter in FineAtoms::name2outer_param"); - return it->second; -} - -int -FineAtoms::name2outer_endo(const string &name) const -{ - auto it = endo_outer_map.find(name); - if (it == endo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an endogenous variable in FineAtoms::name2outer_endo"); - return it->second; -} - -int -FineAtoms::name2outer_exo(const string &name) const -{ - auto it = exo_outer_map.find(name); - if (it == exo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an exogenous variable in FineAtoms::name2outer_exo"); - return it->second; -} - -int -FineAtoms::name2outer_allvar(const string &name) const -{ - if (!allvar_order) - throw ogu::Exception(__FILE__, __LINE__, - "FineAtoms::name2outer_allvar called beore parsing_finished"); - - auto it = endo_outer_map.find(name); - if (it != endo_outer_map.end()) - return allvar_order->get_endo2all()[it->second]; - else - { - it = exo_outer_map.find(name); - if (it != exo_outer_map.end()) - return allvar_order->get_exo2all()[it->second]; - } - - throw ogu::Exception(__FILE__, __LINE__, - "Name " + name + " is neither endo nor exo variable in FineAtoms::name2outer_allvar"); - return -1; -} - -void -FineAtoms::register_uniq_endo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Endogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - endovars.push_back(name); - endo_outer_map.emplace(std::move(name), endovars.size()-1); -} - -void -FineAtoms::register_uniq_exo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Exogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - exovars.push_back(name); - exo_outer_map.emplace(std::move(name), exovars.size()-1); -} - -void -FineAtoms::register_uniq_param(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Parameter <"+name+"> is not unique.", 0); - varnames.insert(name); - params.push_back(name); - param_outer_map.emplace(std::move(name), params.size()-1); -} - -void -FineAtoms::make_internal_orderings(VarOrdering::ord_type ot) -{ - bool endo_ordering_done = false; - bool exo_ordering_done = false; - - order_type = ot; - - int mlead, mlag; - endovarspan(mlead, mlag); - if (mlag >= -1 && mlead <= 1) - { - // make endo ordering - if (ot == VarOrdering::pbspbfbf) - endo_order = std::make_unique<EndoVarOrdering1>(endovars, *this); - else - endo_order = std::make_unique<EndoVarOrdering2>(endovars, *this); - endo_order->do_ordering(); - endo_ordering_done = true; - } - - exovarspan(mlead, mlag); - if (mlag == 0 && mlead == 0) - { - // make exo ordering - exo_order = std::make_unique<ExoVarOrdering>(exovars, *this); - exo_order->do_ordering(); - exo_ordering_done = true; - } - - if (endo_ordering_done && exo_ordering_done) - { - // concatenate der atoms from endo_order and exo_order - der_atoms.clear(); - der_atoms.insert(der_atoms.end(), - endo_order->get_der_atoms().begin(), - endo_order->get_der_atoms().end()); - der_atoms.insert(der_atoms.end(), - exo_order->get_der_atoms().begin(), - exo_order->get_der_atoms().end()); - - // create endo_atoms_map; der_atoms is a concatenation, so it is easy - int endo_atoms = endo_order->get_der_atoms().size(); - endo_atoms_map.clear(); - for (int i = 0; i < endo_atoms; i++) - endo_atoms_map.push_back(i); - // create exo_atoms_map - int exo_atoms = exo_order->get_der_atoms().size(); - exo_atoms_map.clear(); - for (int i = 0; i < exo_atoms; i++) - exo_atoms_map.push_back(endo_atoms + i); - } -} - -void -FineAtoms::print() const -{ - DynamicAtoms::print(); - if (endo_order) - { - std::cout << "Endo ordering:\n"; - endo_order->print(); - } - else - std::cout << "Endo ordering not created.\n"; - - if (exo_order) - { - std::cout << "Exo ordering:\n"; - exo_order->print(); - } - else - std::cout << "Exo ordering not created.\n"; - - std::cout << "endo atoms map:\n"; - for (unsigned int i = 0; i < endo_atoms_map.size(); i++) - std::cout << i << " → " << endo_atoms_map[i] << "\n"; - std::cout << "exo atoms map:\n"; - for (unsigned int i = 0; i < exo_atoms_map.size(); i++) - std::cout << i << " → " << exo_atoms_map[i] << "\n"; -} diff --git a/dynare++/parser/cc/fine_atoms.hh b/dynare++/parser/cc/fine_atoms.hh deleted file mode 100644 index c463c7c7c3b2a6b34d7365d63263967480604104..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/fine_atoms.hh +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_FINE_ATOMS_H -#define OGP_FINE_ATOMS_H - -#include "dynamic_atoms.hh" - -#include <vector> -#include <string> -#include <memory> - -namespace ogp -{ - using std::vector; - using std::string; - - /** This is just ordering used for endogenous variables. It - * assumes that we have only time t-1, t, and t+1, orders them as - * pred(t-1), both(t-1), stat(t), pred(t), both(t), forw(t), - * both(t+1), forw(t+1). */ - class EndoVarOrdering1 : public VarOrdering - { - public: - EndoVarOrdering1(const vector<string> &vnames, const DynamicAtoms &a) - : VarOrdering(vnames, a) - { - } - EndoVarOrdering1(const EndoVarOrdering1 &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : VarOrdering(vo, vnames, a) - { - } - std::unique_ptr<VarOrdering> - clone(const vector<string> &vnames, const DynamicAtoms &a) const override - { - return std::make_unique<EndoVarOrdering1>(*this, vnames, a); - } - void - do_ordering() override - { - do_pbspbfbf(); - } - }; - - /** This is just another ordering used for endogenous - * variables. It assumes that we have only time t-1, t, and t+1, - * orders them as both(t+1), forw(t+1), pred(t-1), both(t-1), - * stat(t), pred(t), both(t), forw(t). */ - class EndoVarOrdering2 : public VarOrdering - { - public: - EndoVarOrdering2(const vector<string> &vnames, const DynamicAtoms &a) - : VarOrdering(vnames, a) - { - } - EndoVarOrdering2(const EndoVarOrdering2 &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : VarOrdering(vo, vnames, a) - { - } - std::unique_ptr<VarOrdering> - clone(const vector<string> &vnames, const DynamicAtoms &a) const override - { - return std::make_unique<EndoVarOrdering2>(*this, vnames, a); - } - void - do_ordering() override - { - do_bfspbfpb(); - } - }; - - /** This is just ordering used for exogenous variables. It makes - * no assumptions about their timing. It orders them from the - * least time to the latest time. */ - class ExoVarOrdering : public VarOrdering - { - public: - ExoVarOrdering(const vector<string> &vnames, const DynamicAtoms &a) - : VarOrdering(vnames, a) - { - } - ExoVarOrdering(const ExoVarOrdering &vo, const vector<string> &vnames, - const DynamicAtoms &a) - : VarOrdering(vo, vnames, a) - { - } - std::unique_ptr<VarOrdering> - clone(const vector<string> &vnames, const DynamicAtoms &a) const override - { - return std::make_unique<ExoVarOrdering>(*this, vnames, a); - } - void - do_ordering() override - { - do_increasing_time(); - } - }; - - class FineAtoms; - - /** This class provides an outer ordering of all variables (endo - * and exo). It maps the ordering to the particular outer - * orderings of endo and exo. It works tightly with the FineAtoms - * class. */ - class AllvarOuterOrdering - { - protected: - /** Type for a map mapping a variable name to an integer. */ - using Tvarintmap = map<string, int>; - /** Reference to atoms. */ - const FineAtoms &atoms; - /** The vector of all endo and exo variables in outer - * ordering. The pointers point to storage in atoms. */ - vector<string> allvar; - /** The mapping from outer endogenous to outer all. For - * example endo2all[0] is the order of the first outer - * endogenous variable in the allvar ordering. */ - vector<int> endo2all; - /** The mapping from outer exogenous to outer all. For example - * exo2all[0] is the order of the first outer exogenous - * variables in the allvar ordering. */ - vector<int> exo2all; - public: - /** Construct the allvar outer ordering from the provided - * sequence of endo and exo names. The names can have an - * arbitrary storage, the storage is transformed to the atoms - * storage. An exception is thrown if either the list is not - * exhaustive, or some string is not a variable. */ - AllvarOuterOrdering(const vector<string> &allvar_outer, const FineAtoms &a); - /** Copy constructor using the storage of provided atoms. */ - AllvarOuterOrdering(const AllvarOuterOrdering &allvar_outer, const FineAtoms &a); - /** Return endo2all mapping. */ - const vector<int> & - get_endo2all() const - { - return endo2all; - } - /** Return exo2all mapping. */ - const vector<int> & - get_exo2all() const - { - return exo2all; - } - /** Return the allvar ordering. */ - const vector<string> & - get_allvar() const - { - return allvar; - } - }; - - /** This class refines the DynamicAtoms by distinguishing among - * parameters (no lag and leads) and endogenous and exogenous - * variables (with lags and leads). For parameters, endogenous and - * exogenous, it defines outer orderings and internal - * orderings. The internal orderings are created by - * parsing_finished() method when it is sure that no new variables - * would be registered. The outer orderings are given by the order - * of calls of registering methods. - * - * In addition, the class also defines outer ordering of - * endogenous and exogenous variables. This is input as a - * parameter to parsing_finished(). By default, this whole outer - * ordering is just a concatenation of outer ordering of - * endogenous and exogenous variables. - * - * The internal ordering of all endo and exo variables is just a - * concatenation of endo and exo variables in their internal - * orderings. This is the ordering with respect to which all - * derivatives are taken. */ - class FineAtoms : public DynamicAtoms - { - friend class AllvarOuterOrdering; - protected: - using Tvarintmap = map<string, int>; - private: - /** The vector of parameters names. The order gives the order - * the data is communicated with outside world. */ - vector<string> params; - /** A map mapping a name of a parameter to an index in the outer - * ordering. */ - Tvarintmap param_outer_map; - /** The vector of endogenous variables. This defines the order - * like parameters. */ - vector<string> endovars; - /** A map mapping a name of an endogenous variable to an index - * in the outer ordering. */ - Tvarintmap endo_outer_map; - /** The vector of exogenous variables. Also defines the order - * like parameters and endovars. */ - vector<string> exovars; - /** A map mapping a name of an exogenous variable to an index - * in the outer ordering. */ - Tvarintmap exo_outer_map; - - protected: - /** This is the internal ordering of all atoms corresponding - * to endogenous variables. It is constructed by - * parsing_finished() method, which should be called after all - * parsing jobs have been finished. */ - std::unique_ptr<VarOrdering> endo_order; - /** This is the internal ordering of all atoms corresponding - * to exogenous variables. It has the same handling as - * endo_order. */ - std::unique_ptr<VarOrdering> exo_order; - /** This is the all variables outer ordering. It is - * constructed by parsing finished. */ - std::unique_ptr<AllvarOuterOrdering> allvar_order; - /** This vector defines a set of atoms as tree indices used - * for differentiation. The order of the atoms in this vector - * defines ordering of the derivative tensors. The ordering is - * a concatenation of atoms from endo_order and then - * exo_order. This vector is setup by parsing_finished() and - * is returned by variables(). */ - vector<int> der_atoms; - /** This is a mapping from endogenous atoms to all atoms in - * der_atoms member. The mapping maps index in endogenous atom - * ordering to index (not value) in der_atoms. It is useful if - * one wants to evaluate derivatives wrt only endogenous - * variables. It is set by parsing_finished(). By definition, - * it is monotone. */ - vector<int> endo_atoms_map; - /** This is a mapping from exogenous atoms to all atoms in - * der_atoms member. It is the same as endo_atoms_map for - * atoms of exogenous variables. */ - vector<int> exo_atoms_map; - public: - FineAtoms() = default; - FineAtoms(const FineAtoms &fa); - /** Deletes endo_order and exo_order. */ - ~FineAtoms() override = default; - /** Overrides DynamicAtoms::check_variable so that the error - * would be raised if the variable name is not declared. A - * variable is declared by inserting it to - * DynamicAtoms::varnames. This is a responsibility of a - * subclass. */ - int check_variable(const string &name) const override; - /** This calculates min lag and max lead of endogenous variables. */ - void - endovarspan(int &mlead, int &mlag) const - { - varspan(endovars, mlead, mlag); - } - /** This calculates mim lag and max lead of exogenous variables. */ - void - exovarspan(int &mlead, int &mlag) const - { - varspan(exovars, mlead, mlag); - } - /** This calculates the number of periods in which at least - * one exogenous variable occurs. */ - int num_exo_periods() const; - /** Return an (external) ordering of parameters. */ - const vector<string> & - get_params() const - { - return params; - } - /** Return an external ordering of endogenous variables. */ - const vector<string> & - get_endovars() const - { - return endovars; - } - /** Return an external ordering of exogenous variables. */ - const vector<string> & - get_exovars() const - { - return exovars; - } - /** This constructs internal orderings and makes the indices - * returned by variables method available. Further it - * constructs outer ordering of all variables by a simple - * concatenation of outer endogenous and outer exogenous. In - * addition, it makes nstat, npred, nboth, nforw available. */ - void parsing_finished(VarOrdering::ord_type ot); - /** This does the same thing as - * parsing_finished(VarOrdering::ord_type) plus it allows for - * inputing a different outer ordering of all variables. The - * ordering is input as a list of strings, their storage can - * be arbitrary. */ - void parsing_finished(VarOrdering::ord_type ot, const vector<string> &avo); - /** Return the external ordering of all variables (endo and - * exo). This is either the second argument to - * parsing_finished or the default external ordering. This - * must be called only after parsing_finished. */ - const vector<string> &get_allvar() const; - /** Return the map from outer ordering of endo variables to - * the allvar ordering. This must be called only after - * parsing_finished. */ - const vector<int> &outer_endo2all() const; - /** Return the map from outer ordering of exo variables to - * the allvar ordering. This must be called only after - * parsing_finished. */ - const vector<int> &outer_exo2all() const; - /** Return the atoms with respect to which we are going to - * differentiate. This must be called after - * parsing_finished. */ - vector<int> variables() const override; - /** Return the number of static. */ - int nstat() const; - /** Return the number of predetermined. */ - int npred() const; - /** Return the number of both. */ - int nboth() const; - /** Return the number of forward looking. */ - int nforw() const; - /** Return the index of an endogenous atom given by tree index in - * the endo ordering. This must be also called only after - * parsing_finished(). */ - int get_pos_of_endo(int t) const; - /** Return the index of an exogenous atom given by tree index in - * the exo ordering. This must be also called only after - * parsing_finished(). */ - int get_pos_of_exo(int t) const; - /** Return the index of either endogenous or exogenous atom - * given by tree index in the concatenated ordering of - * endogenous and exogenous atoms. This must be also called - * only after parsing_finished(). */ - int get_pos_of_all(int t) const; - /** Return the mapping from endogenous at time t to outer - * ordering of endogenous. */ - const vector<int> &y2outer_endo() const; - /** Return the mapping from the outer ordering of endogenous to endogenous - * at time t. */ - const vector<int> &outer2y_endo() const; - /** Return the mapping from exogenous at time t to outer - * ordering of exogenous. */ - const vector<int> &y2outer_exo() const; - /** Return the mapping from the outer ordering of exogenous to exogenous - * at time t. */ - const vector<int> &outer2y_exo() const; - /** Return the endo_atoms_map. */ - const vector<int> &get_endo_atoms_map() const; - /** Return the exo_atoms_map. */ - const vector<int> &get_exo_atoms_map() const; - /** Return an index in the outer ordering of a given - * parameter. An exception is thrown if the name is not a - * parameter. */ - int name2outer_param(const string &name) const; - /** Return an index in the outer ordering of a given - * endogenous variable. An exception is thrown if the name is not a - * and endogenous variable. */ - int name2outer_endo(const string &name) const; - /** Return an index in the outer ordering of a given - * exogenous variable. An exception is thrown if the name is not a - * and exogenous variable. */ - int name2outer_exo(const string &name) const; - /** Return an index in the outer ordering of all variables - * (endo and exo) for a given name. An exception is thrown if - * the name is not a variable. This must be called only after - * parsing_finished(). */ - int name2outer_allvar(const string &name) const; - /** Return the number of endogenous variables at time t-1, these are state - * variables. */ - int - nys() const - { - return npred()+nboth(); - } - /** Return the number of endogenous variables at time t+1. */ - int - nyss() const - { - return nboth()+nforw(); - } - /** Return the number of endogenous variables. */ - int - ny() const - { - return endovars.size(); - } - /** Return the number of exogenous variables. */ - int - nexo() const - { - return static_cast<int>(exovars.size()); - } - /** Return the number of parameters. */ - int - np() const - { - return static_cast<int>(params.size()); - } - /** Register unique endogenous variable name. The order of - * calls defines the endo outer ordering. The method is - * virtual, since a superclass may want to do some additional - * action. */ - virtual void register_uniq_endo(string name); - /** Register unique exogenous variable name. The order of - * calls defines the exo outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_exo(string name); - /** Register unique parameter name. The order of calls defines - * the param outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_param(string name); - /** Debug print. */ - void print() const override; - private: - /** This performs the common part of parsing_finished(), which - * is a construction of internal orderings. */ - void make_internal_orderings(VarOrdering::ord_type ot); - protected: - /** This remembers the ordering type of the last call make_internal_ordering. */ - VarOrdering::ord_type order_type; - }; -}; - -#endif diff --git a/dynare++/parser/cc/formula.ll b/dynare++/parser/cc/formula.ll deleted file mode 100644 index 4b5b2aeb2c5bdb9dab3025b4a2341a8b936e25d8..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula.ll +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ -%{ -#include "location.hh" -#include "formula_tab.hh" - -#define YY_USER_ACTION SET_LLOC(fmla_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="fmla_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* initial spaces or tabs are ignored */ - -[ \t\r\n] -[+] {return YPLUS;} -[-] {return YMINUS;} -[*] {return YTIMES;} -[/] {return YDIVIDE;} -[\^] {return YPOWER;} -exp {return YEXP;} -log {return YLOG;} -sin {return YSIN;} -cos {return YCOS;} -tan {return YTAN;} -sqrt {return YSQRT;} -erf {return YERF;} -erfc {return YERFC;} -diff {return YDIFF;} - - /* names: parameters, variables (lagged/leaded) */ -[A-Za-z_][A-Za-z0-9_]*([\(\{][+-]?[0-9]+[\)\}])? { - fmla_lval.string=fmla_text; - return NAME; -} - - /* floating point numbers */ -(([0-9]*\.?[0-9]+)|([0-9]+\.))([edED][-+]?[0-9]+)? { - fmla_lval.string=fmla_text; - return DNUMBER; -} - -= {return EQUAL_SIGN;} - -. {return fmla_text[0];} - -%% - -int -fmla_wrap() -{ - return 1; -} - -void -fmla__destroy_buffer(void* p) -{ - fmla__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/parser/cc/formula.yy b/dynare++/parser/cc/formula.yy deleted file mode 100644 index 4fc7f934d9c288cd16205c883aed18d289e92927..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula.yy +++ /dev/null @@ -1,101 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -%code requires -{ -#include "location.hh" -#define FMLA_LTYPE ogp::location_type -} - -%code -{ -#include "formula_parser.hh" -#include <string> - -void fmla_error(std::string); -int fmla_lex(); -extern ogp::FormulaParser* fparser; -} - -%union -{ - char* string; - double dvalue; - int integer; -} - -%token EQUAL_SIGN -%left YPLUS YMINUS -%left YTIMES YDIVIDE -%precedence YUMINUS YUPLUS -%right YPOWER -%token YEXP YLOG YSIN YCOS YTAN YSQRT YERF YERFC YDIFF -%token <string> DNUMBER NAME -%type <integer> expression - -%define api.prefix {fmla_} - -%locations -%defines -%define parse.error verbose - -%% - root : equation_list - | expression - {fparser->add_formula($1);} - ; - - equation_list : equation_list equation | equation ; - - equation : expression EQUAL_SIGN expression ';' - {fparser->add_formula(fparser->add_binary(ogp::code_t::MINUS,$1,$3));} - | expression ';' - {fparser->add_formula($1);} - ; - - expression : '(' expression ')' { $$ = $2;} - | expression YPLUS expression {$$=fparser->add_binary(ogp::code_t::PLUS,$1,$3);} - | expression YMINUS expression {$$=fparser->add_binary(ogp::code_t::MINUS,$1,$3);} - | expression YTIMES expression {$$=fparser->add_binary(ogp::code_t::TIMES,$1,$3);} - | expression YDIVIDE expression {$$=fparser->add_binary(ogp::code_t::DIVIDE,$1,$3);} - | expression YPOWER expression {$$=fparser->add_binary(ogp::code_t::POWER,$1,$3);} - | YMINUS expression %prec YUMINUS {$$=fparser->add_unary(ogp::code_t::UMINUS,$2);} - | YPLUS expression %prec YUPLUS {$$ = $2;} - | YSIN '(' expression ')' {$$=fparser->add_unary(ogp::code_t::SIN,$3);} - | YCOS '(' expression ')' {$$=fparser->add_unary(ogp::code_t::COS,$3);} - | YTAN '(' expression ')' {$$=fparser->add_unary(ogp::code_t::TAN,$3);} - | YEXP '(' expression ')' {$$=fparser->add_unary(ogp::code_t::EXP,$3);} - | YLOG '(' expression ')' {$$=fparser->add_unary(ogp::code_t::LOG,$3);} - | YSQRT '(' expression ')' {$$=fparser->add_unary(ogp::code_t::SQRT,$3);} - | YERF '(' expression ')' {$$=fparser->add_unary(ogp::code_t::ERF,$3);} - | YERFC '(' expression ')' {$$=fparser->add_unary(ogp::code_t::ERFC,$3);} - | YDIFF '(' expression ',' NAME ')' {$$=fparser->add_derivative($3, fparser->add_nulary($5));} - | NAME {$$=fparser->add_nulary($1);} - | DNUMBER {$$=fparser->add_nulary($1);} - ; - -%% - -void -fmla_error(std::string s) -{ - fparser->error(std::move(s)); -} diff --git a/dynare++/parser/cc/formula_parser.cc b/dynare++/parser/cc/formula_parser.cc deleted file mode 100644 index e23ca3a0d2e4941612f1ec75bacdcf1ac2bad02f..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula_parser.cc +++ /dev/null @@ -1,536 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "utils/cc/pascal_triangle.hh" -#include "utils/cc/exception.hh" - -#include "parser_exception.hh" -#include "location.hh" -#include "formula_parser.hh" -#include "formula_tab.hh" - -#include <cmath> -#include <algorithm> - -using namespace ogp; - -extern location_type fmla_lloc; - -FormulaParser::FormulaParser(const FormulaParser &fp, Atoms &a) - : otree(fp.otree), atoms(a), formulas(fp.formulas), ders() -{ - // create derivatives - for (const auto &der : fp.ders) - ders.push_back(std::make_unique<FormulaDerivatives>(*der)); -} - -void -FormulaParser::differentiate(int max_order) -{ - ders.clear(); - vector<int> vars; - vars = atoms.variables(); - for (int formula : formulas) - ders.push_back(std::make_unique<FormulaDerivatives>(otree, vars, formula, max_order)); -} - -const FormulaDerivatives & -FormulaParser::derivatives(int i) const -{ - if (i < static_cast<int>(ders.size())) - return *(ders[i]); - else - throw ogu::Exception(__FILE__, __LINE__, - "Wrong formula index in FormulaParser::derivatives"); - return *(ders[0]); // just because of compiler -} - -void -FormulaParser::add_formula(int t) -{ - formulas.push_back(t); -} - -int -FormulaParser::add_binary(code_t code, int t1, int t2) -{ - return otree.add_binary(code, t1, t2); -} - -int -FormulaParser::add_unary(code_t code, int t) -{ - return otree.add_unary(code, t); -} - -int -FormulaParser::add_nulary(const string &str) -{ - int t = -1; - try - { - t = atoms.check(str); - } - catch (const ParserException &e) - { - throw ParserException(e, fmla_lloc.off); - } - if (t == -1) - { - t = otree.add_nulary(); - atoms.assign(str, t); - } - return t; -} - -void -FormulaParser::add_subst_formulas(const map<int, int> &subst, const FormulaParser &fp) -{ - for (int i = 0; i < fp.nformulas(); i++) - { - int f = add_substitution(fp.formula(i), subst, fp); - add_formula(f); - } -} - -void -FormulaParser::substitute_formulas(const map<int, int> &smap) -{ - for (int i = 0; i < nformulas(); i++) - { - // make substitution and replace the formula for it - int f = add_substitution(formulas[i], smap); - formulas[i] = f; - // update the derivatives if any - if (i < static_cast<int>(ders.size()) && ders[i]) - { - int order = ders[i]->get_order(); - ders[i] = std::make_unique<FormulaDerivatives>(otree, atoms.variables(), formulas[i], order); - } - } -} - -/** Global symbols for passing info to parser. */ -FormulaParser *fparser; - -/** The declarations of functions defined in formula_ll.cc and - * formula_tab.cc generated from formula.lex and formula.y */ -void *fmla__scan_string(const char *); -void fmla__destroy_buffer(void *); -int fmla_parse(); -extern location_type fmla_lloc; - -/** This makes own copy of provided data, sets the buffer for the - * parser with fmla_scan_buffer, and launches fmla_parse(). Note that - * the pointer returned from fmla_scan_buffer must be freed at the - * end. */ -void -FormulaParser::parse(const string &stream) -{ - fmla_lloc.off = 0; - fmla_lloc.ll = 0; - void *p = fmla__scan_string(stream.c_str()); - fparser = this; - fmla_parse(); - fmla__destroy_buffer(p); -} - -void -FormulaParser::error(string mes) const -{ - throw ParserException(std::move(mes), fmla_lloc.off); -} - -int -FormulaParser::last_formula() const -{ - int res = -1; - for (int formula : formulas) - res = std::max(res, formula); - return std::max(res, otree.get_last_nulary()); -} - -int -FormulaParser::pop_last_formula() -{ - if (formulas.size() == 0) - return -1; - int t = formulas.back(); - if (formulas.size() == ders.size()) - ders.pop_back(); - formulas.pop_back(); - return t; -} - -void -FormulaParser::print() const -{ - atoms.print(); - for (int formula : formulas) - { - std::cout << "formula " << formula << ":\n"; - otree.print_operation(formula); - } - for (unsigned int i = 0; i < ders.size(); i++) - { - std::cout << "derivatives for the formula " << formulas[i] << ":\n"; - ders[i]->print(otree); - } -} - -/** This constructor makes a vector of indices for formulas - * corresponding to derivatives of the given formula. The formula is - * supposed to belong to the provided tree, the created derivatives - * are added to the tree. - * - * The algorithm is as follows. todo: update description of the - * algorithm - */ -FormulaDerivatives::FormulaDerivatives(OperationTree &otree, - const vector<int> &vars, int f, int max_order) - : nvar(vars.size()), order(max_order) -{ - FoldMultiIndex fmi_zero(nvar); - tder.push_back(f); - indices.push_back(fmi_zero); - unsigned int last_order_beg = 0; - unsigned int last_order_end = tder.size(); - - for (int k = 1; k <= order; k++) - { - // interval <last_order_beg,last_order_end) is guaranteed - // here to contain at least one item - for (unsigned int run = last_order_beg; run < last_order_end; run++) - { - // shift one order from the run - FoldMultiIndex fmi(indices[run], 1); - // set starting variable from the run, note that if k=1, - // the shift order ctor of fmi will set it to zero - int ivar_start = fmi[k-1]; - for (int ivar = ivar_start; ivar < nvar; ivar++, fmi.increment()) - { - int der = otree.add_derivative(tder[run], vars[ivar]); - if (der != OperationTree::zero) - { - tder.push_back(der); - indices.push_back(fmi); - } - } - } - - // set new last_order_beg and last_order_end - last_order_beg = last_order_end; - last_order_end = tder.size(); - // if there was no new derivative, break out from the loop - if (last_order_beg >= last_order_end) - break; - } - - // build ind2der map - for (unsigned int i = 0; i < indices.size(); i++) - ind2der.emplace(indices[i], i); - -} - -FormulaDerivatives::FormulaDerivatives(const FormulaDerivatives &fd) = default; - -int -FormulaDerivatives::derivative(const FoldMultiIndex &mi) const -{ - if (mi.order() > order) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong order of multi-index in FormulaDerivatives::derivative"); - if (mi.nv() != nvar) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong multi-index variables in FormulaDerivatives::derivative"); - - auto it = ind2der.find(mi); - if (it == ind2der.end()) - return OperationTree::zero; - else - return tder[it->second]; -} - -void -FormulaDerivatives::print(const OperationTree &otree) const -{ - for (const auto &it : ind2der) - { - std::cout << "derivative "; - it.first.print(); - std::cout << " is formula " << tder[it.second] << '\n'; - otree.print_operation(tder[it.second]); - } -} - -void -FormulaCustomEvaluator::eval(const AtomValues &av, FormulaEvalLoader &loader) -{ - etree.reset_all(); - av.setValues(etree); - for (unsigned int i = 0; i < terms.size(); i++) - { - double res = etree.eval(terms[i]); - loader.load(static_cast<int>(i), res); - } -} - -FoldMultiIndex::FoldMultiIndex(int nv) - : nvar(nv), ord(0), data(std::make_unique<int[]>(ord)) -{ -} - -FoldMultiIndex::FoldMultiIndex(int nv, int ordd, int ii) - : nvar(nv), ord(ordd), data(std::make_unique<int[]>(ord)) -{ - for (int i = 0; i < ord; i++) - data[i] = ii; -} - -/** Note that a monotone sequence mapped by monotone mapping yields a - * monotone sequence. */ -FoldMultiIndex::FoldMultiIndex(int nv, const FoldMultiIndex &mi, const vector<int> &mp) - : nvar(nv), ord(mi.ord), data(std::make_unique<int[]>(ord)) -{ - for (int i = 0; i < ord; i++) - { - if (i < ord-1 && mp[i+1] < mp[i]) - throw ogu::Exception(__FILE__, __LINE__, - "Mapping not monotone in FoldMultiIndex constructor"); - if (mp[mi[i]] >= nv || mp[mi[i]] < 0) - throw ogu::Exception(__FILE__, __LINE__, - "Mapping out of bounds in FoldMultiIndex constructor"); - data[i] = mp[mi[i]]; - } -} - -FoldMultiIndex::FoldMultiIndex(const FoldMultiIndex &fmi, int new_orders) - : nvar(fmi.nvar), - ord(fmi.ord+new_orders), - data(std::make_unique<int[]>(ord)) -{ - std::copy_n(fmi.data.get(), fmi.ord, data.get()); - int new_item = (fmi.ord > 0) ? fmi.data[fmi.ord-1] : 0; - for (int i = fmi.ord; i < ord; i++) - data[i] = new_item; -} - -FoldMultiIndex::FoldMultiIndex(const FoldMultiIndex &fmi) - : nvar(fmi.nvar), - ord(fmi.ord), - data(std::make_unique<int[]>(ord)) -{ - std::copy_n(fmi.data.get(), ord, data.get()); -} - -const FoldMultiIndex & -FoldMultiIndex::operator=(const FoldMultiIndex &fmi) -{ - if (ord != fmi.ord) - data = std::make_unique<int[]>(fmi.ord); - - ord = fmi.ord; - nvar = fmi.nvar; - std::copy_n(fmi.data.get(), ord, data.get()); - - return *this; -} - -bool -FoldMultiIndex::operator<(const FoldMultiIndex &fmi) const -{ - if (nvar != fmi.nvar) - ogu::Exception(__FILE__, __LINE__, - "Different nvar in FoldMultiIndex::operator<"); - - if (ord < fmi.ord) - return true; - if (ord > fmi.ord) - return false; - - int i = 0; - while (i < ord && data[i] == fmi.data[i]) - i++; - if (i == ord) - return false; - else - return data[i] < fmi.data[i]; -} - -bool -FoldMultiIndex::operator==(const FoldMultiIndex &fmi) const -{ - bool res = true; - res = res && (nvar == fmi.nvar) && (ord == fmi.ord); - if (res) - for (int i = 0; i < ord; i++) - if (data[i] != fmi.data[i]) - return false; - return res; -} - -void -FoldMultiIndex::increment() -{ - if (ord == 0) - return; - - int k = ord-1; - data[k]++; - while (k > 0 && data[k] == nvar) - { - data[k] = 0; - data[--k]++; - } - for (int kk = 1; kk < ord; kk++) - if (data[kk-1] > data[kk]) - data[kk] = data[kk-1]; -} - -// For description of an algorithm for calculation of folded offset, -// see Tensor Library Documentation, Ondra Kamenik, 2005, description -// of FTensor::getOffsetRecurse(). -int -FoldMultiIndex::offset() const -{ - // make copy for the recursions - auto tmp = std::make_unique<int[]>(ord); - std::copy_n(data.get(), ord, tmp.get()); - // call the recursive algorithm - int res = offset_recurse(tmp.get(), ord, nvar); - return res; -} - -void -FoldMultiIndex::print() const -{ - std::cout << "["; - for (int i = 0; i < ord; i++) - std::cout << data[i] << ' '; - std::cout << "]"; -} - -int -FoldMultiIndex::offset_recurse(int *data, int len, int nv) -{ - if (len == 0) - return 0; - // calculate length of initial constant indices - int prefix = 1; - while (prefix < len && data[0] == data[prefix]) - prefix++; - - int m = data[0]; - int s1 = PascalTriangle::noverk(nv+len-1, len) - PascalTriangle::noverk(nv-m+len-1, len); - - // cancel m from the rest of the sequence - for (int i = prefix; i < len; i++) - data[i] -= m; - - // calculate offset of the remaining sequence - int s2 = offset_recurse(data+prefix, len-prefix, nv-m); - // return the sum - return s1+s2; -} - -bool -ltfmi::operator()(const FoldMultiIndex &i1, const FoldMultiIndex &i2) const -{ - return i1 < i2; -} - -FormulaDerEvaluator::FormulaDerEvaluator(const FormulaParser &fp) - : etree(fp.otree, -1) -{ - for (const auto &der : fp.ders) - ders.push_back(der.get()); - - der_atoms = fp.atoms.variables(); -} - -void -FormulaDerEvaluator::eval(const AtomValues &av, FormulaDerEvalLoader &loader, int order) -{ - if (ders.size() == 0) - return; - int maxorder = ders[0]->order; - - if (order > maxorder) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong order in FormulaDerEvaluator::eval"); - - etree.reset_all(); - av.setValues(etree); - - auto vars = std::make_unique<int[]>(order); - - for (unsigned int i = 0; i < ders.size(); i++) - { - for (const auto &it : ders[i]->ind2der) - { - const FoldMultiIndex &mi = it.first; - if (mi.order() == order) - { - // set vars from multiindex mi and variables - for (int k = 0; k < order; k++) - vars[k] = der_atoms[mi[k]]; - // evaluate - double res = etree.eval(ders[i]->tder[it.second]); - // load - loader.load(i, order, vars.get(), res); - } - } - } -} - -void -FormulaDerEvaluator::eval(const vector<int> &mp, const AtomValues &av, - FormulaDerEvalLoader &loader, int order) -{ - etree.reset_all(); - av.setValues(etree); - - int nvar_glob = der_atoms.size(); - int nvar = mp.size(); - auto vars = std::make_unique<int[]>(order); - - for (unsigned int i = 0; i < ders.size(); i++) - { - FoldMultiIndex mi(nvar, order); - do - { - // find index of the derivative in the tensor - FoldMultiIndex mi_glob(nvar_glob, mi, mp); - int der = ders[i]->derivative(mi_glob); - if (der != OperationTree::zero) - { - // set vars from the global multiindex - for (int k = 0; k < order; k++) - vars[k] = der_atoms[mi_glob[k]]; - // evaluate derivative - double res = etree.eval(der); - // load - loader.load(i, order, vars.get(), res); - } - mi.increment(); - } - while (!mi.past_the_end()); - } -} diff --git a/dynare++/parser/cc/formula_parser.hh b/dynare++/parser/cc/formula_parser.hh deleted file mode 100644 index 09a9e37d64672c30f360e7ddd501ef0e49090e3a..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/formula_parser.hh +++ /dev/null @@ -1,497 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_FORMULA_PARSER_H -#define OGP_FORMULA_PARSER_H - -#include <utility> -#include <memory> -#include <vector> - -#include "tree.hh" - -namespace ogp -{ - using std::vector; - - /** Pure virtual class defining a minimal interface for - * representation of nulary terms within FormulaParser. */ - class Atoms - { - public: - Atoms() = default; - virtual ~Atoms() = default; - /** This returns previously assigned internal index to the - * given atom, or returns -1 if the atom has not been assigned - * yet. The method can raise an exception, if the Atoms - * implementation is strict and the name is not among - * prescribed possible values. */ - virtual int check(const std::string &name) const = 0; - /** This method assigns an internal index to the nulary term - * described by the name. The internal index is allocated by - * OperationTree class. */ - virtual void assign(const std::string &name, int t) = 0; - /** Returns a number of variables which will be used for - * differentiations. */ - virtual int nvar() const = 0; - /** Returns a vector of variable's internal indices which will - * be used for differentiations. */ - virtual vector<int> variables() const = 0; - /** Debug print. */ - virtual void print() const = 0; - }; - - /** Pure virtual class defining interface for all classes able to - * set nulary terms to evaluation tree EvalTree. The - * implementations of this class will have to be connected with - * Atoms to have knowledge about the atoms and their indices in - * the tree, and will call EvalTree::set_nulary. */ - class AtomValues - { - public: - virtual ~AtomValues() = default; - virtual void setValues(EvalTree &et) const = 0; - }; - - class FormulaDerEvaluator; - class FoldMultiIndex; - /** For ordering FoldMultiIndex in the std::map. */ - struct ltfmi - { - bool operator()(const FoldMultiIndex &i1, const FoldMultiIndex &i2) const; - }; - - /** This class stores derivatives (tree indices) of one formula - * for all orders upto a given one. It stores the derivatives as a - * sequence (vector) of these tree indices and sequence of the - * multidimensional indices of variables wrt which the derivatives - * were taken. In order to speed up querying for a derivative - * given the variables, we have a map mapping the multidimensional - * index to the order of the derivative in the sequence. - * - * The only reason we do not have only this map is that the - * iterators of the map do not survive the insertions to the map, - * and implementation of the constructor has to be very difficult. - */ - class FormulaDerivatives - { - friend class FormulaDerEvaluator; - protected: - /** Vector of derivatives. This is a list of derivatives (tree - * indices), the ordering is given by the algorithm used to - * create it. Currently, it starts with zero-th derivative, - * the formula itself and carries with first order, second, - * etc. */ - vector<int> tder; - /** Vector of multiindices corresponding to the vector of - * derivatives. */ - vector<FoldMultiIndex> indices; - /** For retrieving derivatives via a multiindex, we have a map - * mapping a multiindex to a derivative in the tder - * ordering. This means that indices[ind2der[index]] == index. */ - using Tfmiintmap = map<FoldMultiIndex, int, ltfmi>; - Tfmiintmap ind2der; - /** The number of variables. */ - int nvar; - /** The maximum order of derivatives. */ - int order; - public: - /** The constructor allocates and fills the sequence of the - * indices of derivatives for a formula. - * @param otree the OperationTree for which all work is done - * and to which the derivatives are added. - * @param vars the vector of nulary terms in the tree; the - * derivatives are taken with respect to these variables in - * the ordering given by the vector. - * @param f the index of the formula being differentiated. The - * zero derivative is set to f. - * @param max_order the maximum order of differentiation. - */ - FormulaDerivatives(OperationTree &otree, const vector<int> &vars, int f, int max_order); - /** Copy constructor. */ - FormulaDerivatives(const FormulaDerivatives &fd); - virtual ~FormulaDerivatives() = default; - /** Random access to the derivatives via multiindex. */ - int derivative(const FoldMultiIndex &mi) const; - /** Return the order. */ - int - get_order() const - { - return order; - } - /** Debug print. */ - void print(const OperationTree &otree) const; - }; - - class FormulaEvaluator; - - /** This class is able to parse a number of formulas and - * differentiate them. The life cycle of the object is as follows: - * After it is created, a few calls to parse will add formulas - * (zero derivatives) to the object. Then a method differentiate() - * can be called and a vector of pointers to derivatives for each - * formula is created. After this, no one should call other - * parse() or differentiate(). A const reference of the object can - * be used in constructors of FormulaEvaluator and - * FormulaDerEvaluator in order to evaluate formulas (zero - * derivatives) and higher derivatives resp. */ - class FormulaParser - { - friend class FormulaCustomEvaluator; - friend class FormulaDerEvaluator; - protected: - /** The OperationTree of all formulas, including derivatives. */ - OperationTree otree; - /** Reference to Atoms. The Atoms are filled with nulary terms - * during execution of parse(). */ - Atoms &atoms; - /** Vector of formulas (zero derivatives) in the order as they - * have been parsed. */ - vector<int> formulas; - /** The vector to derivatives, each vector corresponds to a - * formula in the vector formulas. */ - vector<std::unique_ptr<FormulaDerivatives>> ders; - public: - /** Construct an empty formula parser. */ - FormulaParser(Atoms &a) - : atoms(a) - { - } - FormulaParser(const FormulaParser &fp) = delete; - /** Copy constructor using a different instance of Atoms. */ - FormulaParser(const FormulaParser &fp, Atoms &a); - virtual ~FormulaParser() = default; - - /** Requires an addition of the formula; called from the - * parser. */ - void add_formula(int t); - /** Requires an addition of the binary operation; called from - * the parser. */ - int add_binary(code_t code, int t1, int t2); - /** Requires an addition of the unary operation; called from - * the parser. */ - int add_unary(code_t code, int t); - /** Requires an addition of the nulary operation given by the - * string. The Atoms are consulted for uniquness and are given - * an internal index generated by the OperationTree. This is - * the channel through which the Atoms are filled. */ - int add_nulary(const std::string &str); - - /** Adds a derivative to the tree. This just calls - * OperationTree::add_derivative. */ - int - add_derivative(int t, int v) - { - return otree.add_derivative(t, v); - } - /** Adds a substitution. This just calls - * OperationTree::add_substitution. */ - int - add_substitution(int t, const map<int, int> &subst) - { - return otree.add_substitution(t, subst); - } - /** Add the substitution given by the map where left sides of - * substitutions come from another parser. The right sides are - * from this object. The given t is from the given parser fp. */ - int - add_substitution(int t, const map<int, int> &subst, - const FormulaParser &fp) - { - return otree.add_substitution(t, subst, fp.otree); - } - /** This adds formulas from the given parser with (possibly) - * different atoms applying substitutions from the given map - * mapping atoms from fp to atoms of the object. */ - void add_subst_formulas(const map<int, int> &subst, const FormulaParser &fp); - /** Substitute formulas. For each i from 1 through all - * formulas, it adds a substitution of the i-th formula and - * make it to be i-th formula.*/ - void substitute_formulas(const std::map<int, int> &subst); - /** This method turns the given term to nulary operation. It - * should be used with caution, since this method does not - * anything do with atoms, but usually some action is also - * needed (at leat to assign the tree index t to some - * atom). */ - void - nularify(int t) - { - otree.nularify(t); - } - /** Returns a set of nulary terms of the given term. Just - * calls OperationTree::nulary_of_term. */ - const unordered_set<int> & - nulary_of_term(int t) const - { - return otree.nulary_of_term(t); - } - - /** Parse a given string containing one or more formulas. The - * formulas are parsed and added to the OperationTree and to - * the formulas vector. */ - void parse(const std::string &stream); - /** Processes a syntax error from bison. */ - void error(std::string mes) const; - /** Differentiate all the formulas up to the given order. The - * variables with respect to which the derivatives are taken - * are obtained by Atoms::variables(). If the derivates exist, - * they are destroyed and created again (with possibly - * different order). */ - void differentiate(int max_order); - /** Return i-th formula derivatives. */ - const FormulaDerivatives &derivatives(int i) const; - - /** This returns a maximum index of zero derivative formulas - * including all nulary terms. This is a mimumum length of the - * tree for which it is safe to evaluate zero derivatives of - * the formulas. */ - int last_formula() const; - /** This returns a tree index of the i-th formula in the - * vector. */ - int - formula(int i) const - { - return formulas[i]; - } - - /** This returns a tree index of the last formula and pops its - * item from the formulas vector. The number of formulas is - * then less by one. Returns -1 if there is no formula. If - * there are derivatives of the last formula, they are - * destroyed and the vector ders is popped from the back. */ - int pop_last_formula(); - - /** This returns a number of formulas. */ - int - nformulas() const - { - return static_cast<int>(formulas.size()); - } - - /** This returns a reference to atoms. */ - const Atoms & - getAtoms() const - { - return atoms; - } - Atoms & - getAtoms() - { - return atoms; - } - /** This returns the tree. */ - const OperationTree & - getTree() const - { - return otree; - } - OperationTree & - getTree() - { - return otree; - } - - /** Debug print. */ - void print() const; - }; - - /** This is a pure virtual class defining an interface for all - * classes which will load the results of formula (zero - * derivative) evaluations. A primitive implementation of this - * class can be a vector of doubles. */ - class FormulaEvalLoader - { - public: - virtual ~FormulaEvalLoader() = default; - /** Set the value res for the given formula. The formula is - * identified by an index corresponding to the ordering in - * which the formulas have been parsed (starting from - * zero). */ - virtual void load(int i, double res) = 0; - }; - - /** This class evaluates a selected subset of terms of the - * tree. In the protected constructor, one can constraint the - * initialization of the evaluation tree to a given number of - * terms in the beginning. Using this constructor, one has to make - * sure, that the terms in the beginning do not refer to terms - * behind the initial part. */ - class FormulaCustomEvaluator - { - protected: - /** The evaluation tree. */ - EvalTree etree; - /** The custom tree indices to be evaluated. */ - vector<int> terms; - public: - /** Construct from FormulaParser and given list of terms. */ - FormulaCustomEvaluator(const FormulaParser &fp, vector<int> ts) - : etree(fp.otree), terms(std::move(ts)) - { - } - /** Construct from OperationTree and given list of terms. */ - FormulaCustomEvaluator(const OperationTree &ot, vector<int> ts) - : etree(ot), terms(std::move(ts)) - { - } - /** Evaluate the terms using the given AtomValues and load the - * results using the given loader. The loader is called for - * each term in the order of the terms. */ - void eval(const AtomValues &av, FormulaEvalLoader &loader); - protected: - FormulaCustomEvaluator(const FormulaParser &fp) - : etree(fp.otree, fp.last_formula()), terms(fp.formulas) - { - } - }; - - /** This class evaluates zero derivatives of the FormulaParser. */ - class FormulaEvaluator : public FormulaCustomEvaluator - { - public: - /** Construct from FormulaParser. */ - FormulaEvaluator(const FormulaParser &fp) - : FormulaCustomEvaluator(fp) - { - } - }; - - /** This is a pure virtual class defining an interface for all - * classes which will load the results of formula derivative - * evaluations. */ - class FormulaDerEvalLoader - { - public: - virtual ~FormulaDerEvalLoader() = default; - /** This loads the result of the derivative of the given - * order. The semantics of i is the same as in - * FormulaEvalLoader::load. The indices of variables with - * respect to which the derivative was taken are stored in - * memory pointed by vars. These are the tree indices of the - * variables. */ - virtual void load(int i, int order, const int *vars, double res) = 0; - }; - - /** This class is a utility class representing the tensor - * multindex. It can basically increment itself, and calculate - * its offset in the folded tensor. */ - class FoldMultiIndex - { - /** Number of variables. */ - int nvar; - /** Dimension. */ - int ord; - /** The multiindex. */ - std::unique_ptr<int[]> data; - public: - /** Initializes to the zero derivative. Order is 0, data is - * empty. */ - FoldMultiIndex(int nv); - /** Initializes the multiindex to zeros or given i. */ - FoldMultiIndex(int nv, int order, int i = 0); - /** Makes a new multiindex of the same order applying a given - * mapping to the indices. The mapping is supposed to be monotone. */ - FoldMultiIndex(int nv, const FoldMultiIndex &mi, const vector<int> &mp); - /** Shifting constructor. This adds a given number of orders - * to the end, copying the last item to the newly added items, - * keeping the index ordered. If the index was empty (zero-th - * dimension), then zeros are added. */ - FoldMultiIndex(const FoldMultiIndex &fmi, int new_orders); - /** Copy constructor. */ - FoldMultiIndex(const FoldMultiIndex &fmi); - /** Desctructor. */ - virtual ~FoldMultiIndex() = default; - /** Assignment operator. */ - const FoldMultiIndex &operator=(const FoldMultiIndex &fmi); - /** Operator < implementing lexicographic ordering within one - * order, increasing order across orders. */ - bool operator<(const FoldMultiIndex &fmi) const; - bool operator==(const FoldMultiIndex &fmi) const; - /** Increment the multiindex. */ - void increment(); - /** Return offset of the multiindex in the folded tensor. */ - int offset() const; - const int & - operator[](int i) const - { - return data[i]; - } - /** Return order of the multiindex, i.e. dimension of the - * tensor. */ - int - order() const - { - return ord; - } - /** Return the number of variables. */ - int - nv() const - { - return nvar; - } - /** Return the data. */ - const int * - ind() const - { - return data.get(); - } - /** Return true if the end of the tensor is reached. The - * result of a subsequent increment should be considered - * unpredictable. */ - bool - past_the_end() const - { - return (ord == 0) || (data[0] == nvar); - } - /** Prints the multiindex in the brackets. */ - void print() const; - private: - static int offset_recurse(int *data, int len, int nv); - }; - - /** This class evaluates derivatives of the FormulaParser. */ - class FormulaDerEvaluator - { - /** Its own instance of EvalTree. */ - EvalTree etree; - /** The indices of derivatives for each formula. This is a - * const copy FormulaParser::ders. We do not allocate nor - * deallocate anything here. */ - vector<const FormulaDerivatives *> ders; - /** A copy of tree indices corresponding to atoms to with - * respect the derivatives were taken. */ - vector<int> der_atoms; - public: - /** Construct the object from FormulaParser. */ - FormulaDerEvaluator(const FormulaParser &fp); - /** Evaluate the derivatives from the FormulaParser wrt to all - * atoms in variables vector at the given AtomValues. The - * given loader is used for output. */ - void eval(const AtomValues &av, FormulaDerEvalLoader &loader, int order); - /** Evaluate the derivatives from the FormulaParser wrt to a - * selection of atoms of the atoms in der_atoms vector at the - * given AtomValues. The selection is given by a monotone - * mapping to the indices (not values) of the der_atoms. */ - void eval(const vector<int> &mp, const AtomValues &av, FormulaDerEvalLoader &loader, - int order); - }; -}; - -#endif diff --git a/dynare++/parser/cc/location.hh b/dynare++/parser/cc/location.hh deleted file mode 100644 index 43a2839cef8332dae1e6877daa0481c967df9d0f..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/location.hh +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2006, Ondra Kamenik - -// $Id: location.h 762 2006-05-22 13:00:07Z kamenik $ - -// Purpose: This file defines macros for lex and bison so that the -// very primitive location tracking would be enabled. The location of -// a token is given by offset of its first character. The offset is -// relative to the number which is (and must be) initialized before -// parsing. This file is to be included to the top of bison and lex -// sources. - -// How to use: in preamble of bison and flex, you must include this -// file and declare extern YYLTYPE prefix##lloc. In addition, in flex, -// you must define int prefix##ll =0; and use macro SET_LLOC(prefix) -// in EVERY action consuming material (this can be done with #define -// YY_USER_ACTION) and in bison you must use option %locations. - -#ifndef OG_LOCATION_H -#define OG_LOCATION_H - -namespace ogp -{ - struct location_type - { - int off{0}; // offset of the token - int ll{0}; // length ot the token - location_type() = default; - }; -}; - -// set current off to the first off and add all lengths -#define YYLLOC_DEFAULT(Current, Rhs, N) \ - { \ - (Current).off = (Rhs)[1].off; \ - (Current).ll = 0; \ - for (int i = 1; i <= N; i++) \ - (Current).ll += (Rhs)[i].ll; \ - } - -#define SET_LLOC(prefix) (prefix ## lloc.off += prefix ## lloc.ll, prefix ## lloc.ll = prefix ## leng) - -#endif diff --git a/dynare++/parser/cc/matrix.ll b/dynare++/parser/cc/matrix.ll deleted file mode 100644 index ca710f25899afb72faea8cdd78d2d21ad8e95acd..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix.ll +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -%{ -#include <string> - -#include "location.hh" -#include "matrix_tab.hh" - -extern void matrix_error(std::string); - -#define YY_USER_ACTION SET_LLOC(matrix_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="matrix_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* ignore spaces and commas */ -[ \t,] - /* new row */ -\r\n {return NEW_ROW;} -\n {return NEW_ROW;} -;[ \t]*\n {return NEW_ROW;} -;[ \t]*\r\n {return NEW_ROW;} -; {return NEW_ROW;} - -[+-]?(([0-9]*\.?[0-9]+)|([0-9]+\.))([edED][-+]?[0-9]+)? { - matrix_lval.val = strtod(matrix_text, NULL); - return DNUMBER; -} - -. { - using namespace std::string_literals; - matrix_error("Unrecognized character "s + matrix_text); -} - -%% - -int -matrix_wrap() -{ - return 1; -} - -void -matrix__destroy_buffer(void* p) -{ - matrix__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/parser/cc/matrix.yy b/dynare++/parser/cc/matrix.yy deleted file mode 100644 index b80f3aef7126e2df43a13293b14b116b7a4918ff..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix.yy +++ /dev/null @@ -1,89 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -%code requires -{ -#include "location.hh" -#define MATRIX_LTYPE ogp::location_type -} - -%code -{ -#include "matrix_parser.hh" - -void matrix_error(std::string); -int matrix_lex(); -extern ogp::MatrixParser* mparser; -} - -%union -{ - double val; - int integer; -} - -%token NEW_ROW -%token <val> DNUMBER - -%define api.prefix {matrix_}; - -%locations -%defines -%define parse.error verbose - -%% - -matrix : first_row other_rows - | first_row other_rows empty_rows - | first_row empty_rows other_rows empty_rows - | first_row empty_rows other_rows - | empty_rows first_row other_rows - | empty_rows first_row other_rows empty_rows - | empty_rows first_row empty_rows other_rows empty_rows - | empty_rows first_row empty_rows - | first_row empty_rows - | empty_rows first_row - | first_row - | empty_rows - ; - -empty_rows : empty_rows NEW_ROW | NEW_ROW; - -lod : DNUMBER {mparser->add_item($1);} - | lod DNUMBER {mparser->add_item($2);} - ; - -first_row : lod; - -other_rows : other_rows one_row | other_rows empty_rows one_row |one_row ; - -one_row : NEW_ROW {mparser->start_row();} lod; - - -%% - -void -matrix_error(std::string s) -{ - mparser->error(std::move(s)); -} - - diff --git a/dynare++/parser/cc/matrix_parser.cc b/dynare++/parser/cc/matrix_parser.cc deleted file mode 100644 index 91d90a01f5193c7382106789f778fba9beadce78..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix_parser.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "parser_exception.hh" -#include "matrix_parser.hh" -#include "location.hh" -#include "matrix_tab.hh" - -#include <algorithm> - -using namespace ogp; - -/** A global symbol for passing info to the MatrixParser from - * matrix_parse(). */ -MatrixParser *mparser; - -/** The declaration of functions defined in matrix_ll.cc and - * matrix_tab.cc generated from matrix.lex and matrix.y. */ -void *matrix__scan_string(const char *); -void matrix__destroy_buffer(void *); -int matrix_parse(); -extern ogp::location_type matrix_lloc; - -void -MatrixParser::parse(const string &stream) -{ - // reinitialize the object - data.clear(); - row_lengths.clear(); - nc = 0; - // allocate temporary buffer and parse - matrix_lloc.off = 0; - matrix_lloc.ll = 0; - void *p = matrix__scan_string(stream.c_str()); - mparser = this; - matrix_parse(); - matrix__destroy_buffer(p); -} - -void -MatrixParser::add_item(double v) -{ - data.push_back(v); - if (row_lengths.size() == 0) - row_lengths.push_back(0); - (row_lengths.back())++; - nc = std::max(nc, row_lengths.back()); -} - -void -MatrixParser::start_row() -{ - row_lengths.push_back(0); -} - -void -MatrixParser::error(string mes) const -{ - throw ParserException(std::move(mes), matrix_lloc.off); -} - -int -MatrixParser::find_first_non_empty_row(int start) const -{ - int r = start; - while (r < static_cast<int>(row_lengths.size()) && row_lengths[r] == 0) - r++; - return r; -} - -MPIterator -MatrixParser::begin() const -{ - MPIterator it(*this); - return it; -} - -MPIterator -MatrixParser::end() const -{ - MPIterator it(*this, "end"); - return it; -} - -MPIterator::MPIterator(const MatrixParser &mp) - : p(&mp), i(0), r(mp.find_first_non_empty_row()) -{ -} - -MPIterator::MPIterator(const MatrixParser &mp, const char *dummy) - : p(&mp), i(mp.data.size()), r(mp.row_lengths.size()) -{ -} - -MPIterator & -MPIterator::operator++() -{ - i++; - c++; - if (p->row_lengths[r] <= c) - { - c = 0; - r = p->find_first_non_empty_row(r+1); - } - return *this; -} diff --git a/dynare++/parser/cc/matrix_parser.hh b/dynare++/parser/cc/matrix_parser.hh deleted file mode 100644 index 3a7c9c2962b11cdf24fab1996c7a5b366e7d8d16..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/matrix_parser.hh +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_MATRIX_PARSER -#define OGP_MATRIX_PARSER - -#include <vector> -#include <string> - -namespace ogp -{ - using std::vector; - - /** This class reads the given string and parses it as a - * matrix. The matrix is read row by row. The row delimiter is - * either a newline character or semicolon (first newline - * character after the semicolon is ignored), the column delimiter - * is either blank character or comma. A different number of items - * in the row is not reconciliated, we do not construct a matrix - * here. The class provides only an iterator to go through all - * read items, the iterator provides information on row number and - * column number of the item. */ - class MPIterator; - class MatrixParser - { - friend class MPIterator; - protected: - /** Raw data as they were read. */ - vector<double> data; - /** Number of items in each row. */ - vector<int> row_lengths; - /** Maximum number of row lengths. */ - int nc{0}; - public: - MatrixParser() = default; - MatrixParser(const MatrixParser &mp) = default; - virtual ~MatrixParser() = default; - /** Return a number of read rows. */ - int - nrows() const - { - return static_cast<int>(row_lengths.size()); - } - /** Return a maximum number of items in the rows. */ - int - ncols() const - { - return nc; - } - /** Parses a given data. This initializes the object data. */ - void parse(const std::string &stream); - /** Adds newly read item. This should be called from bison - * parser. */ - void add_item(double v); - /** Starts a new row. This should be called from bison - * parser. */ - void start_row(); - /** Process a parse error from the parser. */ - void error(std::string mes) const; - /** Return begin iterator. */ - MPIterator begin() const; - /** Return end iterator. */ - MPIterator end() const; - protected: - /** Returns an index of the first non-empty row starting at - * start. If the start row is non-empty, returns the start. If - * there is no other non-empty row, returns - * row_lengths.size(). */ - int find_first_non_empty_row(int start = 0) const; - }; - - /** This is an iterator intended to iterate through a matrix parsed - * by MatrixParser. The iterator provides only read-only access. */ - class MPIterator - { - friend class MatrixParser; - protected: - /** Reference to the matrix parser. */ - const MatrixParser *p{nullptr}; - /** The index of the pointed item in the matrix parser. */ - unsigned int i{0}; - /** The column number of the pointed item starting from zero. */ - int c{0}; - /** The row number of the pointed item starting from zero. */ - int r{0}; - - public: - MPIterator() = default; - /** Constructs an iterator pointing to the beginning of the - * parsed matrix. */ - MPIterator(const MatrixParser &mp); - /** Constructs an iterator pointing to the past-the-end of the - * parsed matrix. */ - MPIterator(const MatrixParser &mp, const char *dummy); - /** Return read-only reference to the pointed item. */ - const double & - operator*() const - { - return p->data[i]; - } - /** Return a row index of the pointed item. */ - int - row() const - { - return r; - } - /** Return a column index of the pointed item. */ - int - col() const - { - return c; - } - /** Assignment operator. */ - MPIterator &operator=(const MPIterator &it) = default; - /** Return true if the iterators are the same, this is if they - * have the same underlying object and the same item index. */ - bool - operator==(const MPIterator &it) const - { - return it.p == p && it.i == i; - } - /** Negative of the operator==. */ - bool - operator!=(const MPIterator &it) const - { - return !(it == *this); - } - /** Increment operator. */ - MPIterator &operator++(); - }; -}; - -#endif diff --git a/dynare++/parser/cc/parser_exception.cc b/dynare++/parser/cc/parser_exception.cc deleted file mode 100644 index 8659c33363a81276b839de4d7f27be893b5ca930..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/parser_exception.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "parser_exception.hh" - -using namespace ogp; - -ParserException::ParserException(string m, int offset) - : mes(std::move(m)), off(offset), - aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ -} - -ParserException::ParserException(string m, const char *dum, int i1) - : mes(std::move(m)), off(0), - aux_i1(i1), aux_i2(-1), aux_i3(-1) -{ -} - -ParserException::ParserException(string m, const char *dum, int i1, int i2) - : mes(std::move(m)), off(0), - aux_i1(i1), aux_i2(i2), aux_i3(-1) -{ -} - -ParserException::ParserException(string m, const char *dum, int i1, int i2, int i3) - : mes(std::move(m)), off(0), - aux_i1(i1), aux_i2(i2), aux_i3(i3) -{ -} - -ParserException::ParserException(const ParserException &m, int plus_offset) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - off += plus_offset; -} - -ParserException::ParserException(const ParserException &m, const char *dum, int i) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - aux_i3 = m.aux_i2; - aux_i2 = m.aux_i1; - aux_i1 = i; -} - -ParserException::ParserException(const ParserException &m, const char *dum, int i1, int i2) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - aux_i3 = m.aux_i1; - aux_i2 = i2; - aux_i1 = i1; -} - -ParserException::ParserException(const ParserException &m, const char *dum, int i1, int i2, int i3) - : aux_i1(-1), aux_i2(-1), aux_i3(-1) -{ - copy(m); - aux_i3 = i3; - aux_i2 = i2; - aux_i1 = i1; -} - -void -ParserException::copy(const ParserException &e) -{ - mes = e.mes; - off = e.off; - aux_i1 = e.aux_i1; - aux_i2 = e.aux_i2; - aux_i3 = e.aux_i3; -} diff --git a/dynare++/parser/cc/parser_exception.hh b/dynare++/parser/cc/parser_exception.hh deleted file mode 100644 index d8b69fe1f945f1931689aaa83027504f3aa93061..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/parser_exception.hh +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OG_FORMULA_PARSER_H -#define OG_FORMULA_PARSER_H - -#include <string> - -namespace ogp -{ - using std::string; - - /** This is an easy exception, which, besides the message, stores - * also an offset of the parse error. Since we might need to track - * the argument number and for example the filed in the argument - * which caused the error, we add three integers, which have no - * semantics here. They should be documented in the function which - * throws an exception and sets them. Their default value is -1, - * which means they have not been set. */ - class ParserException - { - protected: - string mes; - int off; - int aux_i1; - int aux_i2; - int aux_i3; - public: - ParserException(string m, int offset); - ParserException(string m, const char *dum, int i1); - ParserException(string m, const char *dum, int i1, int i2); - ParserException(string m, const char *dum, int i1, int i2, int i3); - ParserException(const ParserException &e, int plus_offset); - /** Makes a copy and pushes given integer to aux_i1 shuffling - * others and forgetting the last. */ - ParserException(const ParserException &e, const char *dum, int i); - /** Makes a copy and pushes given two integers to aux_i1 and aux_i2 shuffling - * others and forgetting the last two. */ - ParserException(const ParserException &e, const char *dum, int i1, int i2); - /** Makes a copy and pushes given three integers to aux_i1, aux_i2, aus_i3 shuffling - * others and forgetting the last three. */ - ParserException(const ParserException &e, const char *dum, int i1, int i2, int i3); - ParserException(const ParserException &e) = default; - virtual ~ParserException() = default; - const string & - message() const - { - return mes; - } - int - offset() const - { - return off; - } - const int & - i1() const - { - return aux_i1; - } - int & - i1() - { - return aux_i1; - } - const int & - i2() const - { - return aux_i2; - } - int & - i2() - { - return aux_i2; - } - const int & - i3() const - { - return aux_i3; - } - int & - i3() - { - return aux_i3; - } - protected: - void copy(const ParserException &e); - }; -}; - -#endif diff --git a/dynare++/parser/cc/static_atoms.cc b/dynare++/parser/cc/static_atoms.cc deleted file mode 100644 index cc64d98979d6e8529d401029554955d758567b21..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_atoms.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "static_atoms.hh" -#include "utils/cc/exception.hh" - -using namespace ogp; - -void -StaticAtoms::import_atoms(const DynamicAtoms &da, OperationTree &otree, Tintintmap &tmap) -{ - Constants::import_constants(da, otree, tmap); - - for (int i = 0; i < da.get_name_storage().num(); i++) - { - const string &name = da.get_name_storage().get_name(i); - register_name(name); - int tnew = otree.add_nulary(); - assign(name, tnew); - if (da.is_referenced(name)) - { - const DynamicAtoms::Tlagmap &lmap = da.lagmap(name); - for (const auto &it : lmap) - { - int told = it.second; - tmap.emplace(told, tnew); - } - } - } -} - -int -StaticAtoms::check(const string &name) const -{ - if (DynamicAtoms::is_string_constant(name)) - return Constants::check(name); - else - return check_variable(name); -} - -int -StaticAtoms::index(const string &name) const -{ - auto it = vars.find(name); - if (it == vars.end()) - return -1; - else - return it->second; -} - -void -StaticAtoms::assign(const string &name, int t) -{ - if (DynamicAtoms::is_string_constant(name)) - { - double val = std::stod(name); - add_constant(t, val); - } - else - { - varnames.insert(name); - vars.emplace(name, t); - indices.emplace(t, name); - } -} - -vector<int> -StaticAtoms::variables() const -{ - vector<int> res; - for (const auto &var : vars) - res.push_back(var.second); - return res; -} - -void -StaticAtoms::register_name(string name) -{ - varnames.insert(name); - varorder.push_back(std::move(name)); -} - -void -StaticAtoms::print() const -{ - std::cout << "constants:\n"; - Constants::print(); - std::cout << "variable names:\n"; - varnames.print(); - std::cout << "map to tree indices:\n"; - for (auto var : vars) - std::cout << var.first << "\t→\t" << var.second << "\n"; -} diff --git a/dynare++/parser/cc/static_atoms.hh b/dynare++/parser/cc/static_atoms.hh deleted file mode 100644 index bb2d954fe6001e0e075bff71f69db9c68846cdf2..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_atoms.hh +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_STATIC_ATOMS -#define OGP_STATIC_ATOMS - -#include "dynamic_atoms.hh" - -namespace ogp -{ - class StaticAtoms : public Atoms, public Constants - { - protected: - using Tvarmap = map<string, int>; - using Tinvmap = map<int, string>; - /** Storage for names. */ - NameStorage varnames; - /** Outer order of variables. */ - vector<string> varorder; - /** This is the map mapping a variable name to the tree - * index. */ - Tvarmap vars; - /** This is the inverse mapping. It maps a tree index to the - * variable name. */ - Tinvmap indices; - public: - StaticAtoms() = default; - /** Conversion from DynamicAtoms. This takes all atoms from - * the DynamicAtoms and adds its static version. The new tree - * indices are allocated in the passed OperationTree. Whole - * the process is traced in the map mapping old tree indices - * to new tree indices. */ - StaticAtoms(const DynamicAtoms &da, OperationTree &otree, Tintintmap &tmap) - : Atoms(), Constants(), varnames(), varorder(), vars() - { - import_atoms(da, otree, tmap); - } - /* Destructor. */ - ~StaticAtoms() override = default; - /** This imports atoms from dynamic atoms inserting the new - * tree indices to the given tree (including constants). The - * mapping from old atoms to new atoms is traced in tmap. */ - void import_atoms(const DynamicAtoms &da, OperationTree &otree, - Tintintmap &tmap); - /** If the name is constant, it returns its tree index if the - * constant is registered in Constants, it returns -1 - * otherwise. If the name is not constant, it returns result - * from check_variable, which is implemented by a subclass. */ - int check(const string &name) const override; - /** This assigns a given tree index to the variable name. The - * name should have been checked before the call. */ - void assign(const string &name, int t) override; - int - nvar() const override - { - return varnames.num(); - } - /** This returns a vector of all variables. */ - vector<int> variables() const override; - /** This returns a tree index of the given variable. */ - int index(const string &name) const; - /** This returns a name in a outer ordering. (There is no other ordering.) */ - const string & - name(int i) const - { - return varorder[i]; - } - /** Debug print. */ - void print() const override; - /** This registers a variable. A subclass can reimplement - * this, for example, to ensure uniqueness of the - * name. However, this method should be always called in - * overriding methods to do the registering job. */ - virtual void register_name(string name); - /** Return the name storage to allow querying to other - * classes. */ - const NameStorage & - get_name_storage() const - { - return varnames; - } - protected: - /** This checks the variable. The implementing subclass might - * want to throw an exception if the variable has not been - * registered. */ - virtual int check_variable(const string &name) const = 0; - }; -}; - -#endif diff --git a/dynare++/parser/cc/static_fine_atoms.cc b/dynare++/parser/cc/static_fine_atoms.cc deleted file mode 100644 index 4d7406c14e624e0a19079de23aed1763d5fe5f3d..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_fine_atoms.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "utils/cc/exception.hh" - -#include "static_fine_atoms.hh" -#include "parser_exception.hh" - -using namespace ogp; - -void -StaticFineAtoms::import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap) -{ - StaticAtoms::import_atoms(fa, otree, tmap); - - // we just need to put parameters, endovars, and exovars to - // respective vectors, the names are already in the storage - - // parameters - auto &fa_params = fa.get_params(); - for (const auto &fa_param : fa_params) - register_param(fa_param); - - // endogenous - auto &fa_endovars = fa.get_endovars(); - for (const auto &fa_endovar : fa_endovars) - register_endo(fa_endovar); - - // exogenous - auto &fa_exovars = fa.get_exovars(); - for (const auto &fa_exovar : fa_exovars) - register_exo(fa_exovar); - - parsing_finished(); -} - -void -StaticFineAtoms::import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap, - const char *dummy) -{ - StaticAtoms::import_atoms(fa, otree, tmap); - - // we just need to put parameters, endovars, and exovars to - // respective vectors, the names are already in the storage - - // parameters - auto &fa_params = fa.get_params(); - for (const auto &fa_param : fa_params) - register_param(fa_param); - - // endogenous - auto &fa_endovars = fa.get_endovars(); - for (unsigned int i = 0; i < fa_endovars.size(); i++) - register_endo(fa_endovars[fa.y2outer_endo()[i]]); - - // exogenous - auto &fa_exovars = fa.get_exovars(); - for (unsigned int i = 0; i < fa_exovars.size(); i++) - register_exo(fa_exovars[fa.y2outer_exo()[i]]); - - parsing_finished(); -} - -int -StaticFineAtoms::check_variable(const string &name) const -{ - if (!varnames.query(name)) - throw ParserException("Variable <"+name+"> not declared.", 0); - return index(name); -} - -void -StaticFineAtoms::parsing_finished() -{ - // build der_atoms, and endo_atoms_map and exo_atoms_map - der_atoms.clear(); - endo_atoms_map.clear(); - exo_atoms_map.clear(); - - // go through all endo and exo insert tree indices, ignore names - // whose tree index is -1 (those which are not referenced) - for (auto &endovar : endovars) - { - int t = index(endovar); - if (t != -1) - { - endo_atoms_map.push_back(der_atoms.size()); - der_atoms.push_back(t); - } - } - for (auto &exovar : exovars) - { - int t = index(exovar); - if (t != -1) - { - exo_atoms_map.push_back(der_atoms.size()); - der_atoms.push_back(t); - } - } -} - -int -StaticFineAtoms::name2outer_param(const string &name) const -{ - auto it = param_outer_map.find(name); - if (it == param_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not a parameter in StaticFineAtoms::name2outer_param"); - return it->second; -} - -int -StaticFineAtoms::name2outer_endo(const string &name) const -{ - auto it = endo_outer_map.find(name); - if (it == endo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an endogenous variable in StaticFineAtoms::name2outer_endo"); - return it->second; -} - -int -StaticFineAtoms::name2outer_exo(const string &name) const -{ - auto it = exo_outer_map.find(name); - if (it == exo_outer_map.end()) - throw ogu::Exception(__FILE__, __LINE__, - "Name is not an exogenous variable in StaticFineAtoms::name2outer_exo"); - return it->second; -} - -void -StaticFineAtoms::register_uniq_endo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Endogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - register_endo(std::move(name)); -} - -void -StaticFineAtoms::register_uniq_exo(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Exogenous variable <"+name+"> is not unique.", 0); - varnames.insert(name); - register_exo(std::move(name)); -} - -void -StaticFineAtoms::register_uniq_param(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("Parameter <"+name+"> is not unique.", 0); - varnames.insert(name); - register_param(std::move(name)); -} - -void -StaticFineAtoms::print() const -{ - StaticAtoms::print(); - std::cout << "endo atoms map:\n"; - for (unsigned int i = 0; i < endo_atoms_map.size(); i++) - std::cout << i << " → " << endo_atoms_map[i] << "\n"; - std::cout << "exo atoms map:\n"; - for (unsigned int i = 0; i < exo_atoms_map.size(); i++) - std::cout << i << " → " << exo_atoms_map[i] << "\n"; - std::cout << "der atoms:\n"; - for (unsigned int i = 0; i < der_atoms.size(); i++) - std::cout << i << "\t" << der_atoms[i] << "\n"; -} - -void -StaticFineAtoms::register_endo(string name) -{ - if (!varnames.query(name)) - throw ogp::ParserException("Endogenous variable <"+name+"> not found in storage.", 0); - endovars.push_back(name); - endo_outer_map.emplace(std::move(name), endovars.size()-1); -} - -void -StaticFineAtoms::register_exo(string name) -{ - if (!varnames.query(name)) - throw ogp::ParserException("Exogenous variable <"+name+"> not found in storage.", 0); - exovars.push_back(name); - exo_outer_map.emplace(std::move(name), exovars.size()-1); -} - -void -StaticFineAtoms::register_param(string name) -{ - if (!varnames.query(name)) - throw ogp::ParserException("Parameter <"+name+"> not found in storage.", 0); - params.push_back(name); - param_outer_map.emplace(std::move(name), params.size()-1); -} diff --git a/dynare++/parser/cc/static_fine_atoms.hh b/dynare++/parser/cc/static_fine_atoms.hh deleted file mode 100644 index 482d5e33d21460612f5228a600892f3fc1c72187..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/static_fine_atoms.hh +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_STATIC_FINE_ATOMS_H -#define OGP_STATIC_FINE_ATOMS_H - -#include "static_atoms.hh" -#include "fine_atoms.hh" - -namespace ogp -{ - /** This class represents static atoms distinguishing between - * parameters, endogenous and exogenous variables. The class - * maintains also ordering of all three categories (referenced as - * outer or inner, since there is only one ordering). It can be - * constructed either from scratch, or from fine dynamic atoms. In - * the latter case, one can decide if the ordering of this static - * atoms should be internal or external ordering of the original - * dynamic fine atoms. */ - class StaticFineAtoms : public StaticAtoms - { - public: - using Tintintmap = map<int, int>; - protected: - using Tvarintmap = map<string, int>; - private: - /** The vector of parameter names, gives the parameter - * ordering. */ - vector<string> params; - /** A map mappping a parameter name to an index in the ordering. */ - Tvarintmap param_outer_map; - /** The vector of endogenous variables. This defines the order - * like parameters. */ - vector<string> endovars; - /** A map mapping a name of an endogenous variable to an index - * in the ordering. */ - Tvarintmap endo_outer_map; - /** The vector of exogenous variables. Also defines the order - * like parameters and endovars. */ - vector<string> exovars; - /** A map mapping a name of an exogenous variable to an index - * in the outer ordering. */ - Tvarintmap exo_outer_map; - /** This vector defines a set of atoms as tree indices used - * for differentiation. The order of the atoms in is the - * concatenation of the outer ordering of endogenous and - * exogenous. This vector is setup by parsing_finished() and - * is returned by variables(). */ - vector<int> der_atoms; - /** This is a mapping from endogenous atoms to all atoms in - * der_atoms member. The mapping maps index in endogenous atom - * ordering to index (not value) in der_atoms. It is useful if - * one wants to evaluate derivatives wrt only endogenous - * variables. It is set by parsing_finished(). By definition, - * it is monotone. */ - vector<int> endo_atoms_map; - /** This is a mapping from exogenous atoms to all atoms in - * der_atoms member. It is the same as endo_atoms_map for - * atoms of exogenous variables. */ - vector<int> exo_atoms_map; - public: - StaticFineAtoms() = default; - /** Conversion from dynamic FineAtoms taking its outer - * ordering as ordering of parameters, endogenous and - * exogenous. A biproduct is an integer to integer map mapping - * tree indices of the dynamic atoms to tree indices of the - * static atoms. */ - StaticFineAtoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap) - { - StaticFineAtoms::import_atoms(fa, otree, tmap); - } - /** Conversion from dynamic FineAtoms taking its internal - * ordering as ordering of parameters, endogenous and - * exogenous. A biproduct is an integer to integer map mapping - * tree indices of the dynamic atoms to tree indices of the - * static atoms. */ - StaticFineAtoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap, - const char *dummy) - { - StaticFineAtoms::import_atoms(fa, otree, tmap, dummy); - } - ~StaticFineAtoms() override = default; - /** This adds atoms from dynamic atoms inserting new tree - * indices to the given tree and tracing the mapping from old - * atoms to new atoms in tmap. The ordering of the static - * atoms is the same as outer ordering of dynamic atoms. */ - void import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap); - /** This adds atoms from dynamic atoms inserting new tree - * indices to the given tree and tracing the mapping from old - * atoms to new atoms in tmap. The ordering of the static - * atoms is the same as internal ordering of dynamic atoms. */ - void import_atoms(const FineAtoms &fa, OperationTree &otree, Tintintmap &tmap, - const char *dummy); - /** Overrides StaticAtoms::check_variable so that the error - * would be raised if the variable name is not declared. A - * variable is declared by inserting it to - * StaticAtoms::varnames, which is done with registering - * methods. This a responsibility of a subclass. */ - int check_variable(const string &name) const override; - /** Return an (external) ordering of parameters. */ - const vector<string> & - get_params() const - { - return params; - } - /** Return an external ordering of endogenous variables. */ - const vector<string> & - get_endovars() const - { - return endovars; - } - /** Return an external ordering of exogenous variables. */ - const vector<string> & - get_exovars() const - { - return exovars; - } - /** This constructs der_atoms, and the endo_endoms_map and - * exo_atoms_map, which can be created only after the parsing - * is finished. */ - void parsing_finished(); - /** Return the atoms with respect to which we are going to - * differentiate. */ - vector<int> - variables() const override - { - return der_atoms; - } - /** Return the endo_atoms_map. */ - const vector<int> & - get_endo_atoms_map() const - { - return endo_atoms_map; - } - /** Return the exo_atoms_map. */ - const vector<int> & - get_exo_atoms_map() const - { - return endo_atoms_map; - } - /** Return an index in the outer ordering of a given - * parameter. An exception is thrown if the name is not a - * parameter. */ - int name2outer_param(const string &name) const; - /** Return an index in the outer ordering of a given - * endogenous variable. An exception is thrown if the name is not a - * and endogenous variable. */ - int name2outer_endo(const string &name) const; - /** Return an index in the outer ordering of a given - * exogenous variable. An exception is thrown if the name is not a - * and exogenous variable. */ - int name2outer_exo(const string &name) const; - /** Return the number of endogenous variables. */ - int - ny() const - { - return endovars.size(); - } - /** Return the number of exogenous variables. */ - int - nexo() const - { - return static_cast<int>(exovars.size()); - } - /** Return the number of parameters. */ - int - np() const - { - return static_cast<int>(params.size()); - } - /** Register unique endogenous variable name. The order of - * calls defines the endo outer ordering. The method is - * virtual, since a superclass may want to do some additional - * action. */ - virtual void register_uniq_endo(string name); - /** Register unique exogenous variable name. The order of - * calls defines the exo outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_exo(string name); - /** Register unique parameter name. The order of calls defines - * the param outer ordering. The method is - * virtual, since a superclass may want to do somem additional - * action. */ - virtual void register_uniq_param(string name); - /** Debug print. */ - void print() const override; - private: - /** Add endogenous variable name, which is already in the name - * storage. */ - void register_endo(string name); - /** Add exogenous variable name, which is already in the name - * storage. */ - void register_exo(string name); - /** Add parameter name, which is already in the name - * storage. */ - void register_param(string name); - }; -}; - -#endif diff --git a/dynare++/parser/cc/tree.cc b/dynare++/parser/cc/tree.cc deleted file mode 100644 index 7d05a13e3d9074a11a0f09871fc015cb852787dc..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/tree.cc +++ /dev/null @@ -1,1011 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "utils/cc/exception.hh" - -#include "tree.hh" - -#include <cmath> -#include <limits> -#include <sstream> -#include <iomanip> - -using namespace ogp; - -/** Here we initialize OperationTree to contain only zero, one, nan - * and two_over_pi terms. */ -OperationTree::OperationTree() -{ - last_nulary = -1; - // allocate space for the constants - for (int i = 0; i < num_constants; i++) - add_nulary(); -} - -int -OperationTree::add_nulary() -{ - int op = terms.size(); - terms.push_back({}); - _Tintset s; - s.insert(op); - nul_incidence.push_back(s); - derivatives.push_back({}); - last_nulary = op; - return op; -} - -int -OperationTree::add_unary(code_t code, int op) -{ - if (op == zero - && (code == code_t::UMINUS - || code == code_t::SIN - || code == code_t::TAN - || code == code_t::SQRT - || code == code_t::ERF)) - return zero; - if ((op == zero && code == code_t::LOG) || op == nan) - return nan; - if (op == zero && (code == code_t::EXP - || code == code_t::COS - || code == code_t::ERFC)) - return one; - - Operation unary(code, op); - auto i = opmap.find(unary); - if (i == opmap.end()) - { - int newop = terms.size(); - // add to the terms - terms.push_back(unary); - // copy incidence of the operand - nul_incidence.push_back(nul_incidence[op]); - // insert it to opmap - opmap.emplace(unary, newop); - // add empty map of derivatives - _Tderivmap empty; - derivatives.push_back(empty); - return newop; - } - return i->second; -} - -int -OperationTree::add_binary(code_t code, int op1, int op2) -{ - // quick exits for special values - if (op1 == nan || op2 == nan) - return nan; - // for plus - if (code == code_t::PLUS) - { - if (op1 == zero && op2 == zero) - return zero; - else if (op1 == zero) - return op2; - else if (op2 == zero) - return op1; - } - // for minus - if (code == code_t::MINUS) - { - if (op1 == zero && op2 == zero) - return zero; - else if (op1 == zero) - return add_unary(code_t::UMINUS, op2); - else if (op2 == zero) - return op1; - } - // for times - if (code == code_t::TIMES) - { - if (op1 == zero || op2 == zero) - return zero; - else if (op1 == one) - return op2; - else if (op2 == one) - return op1; - } - // for divide - if (code == code_t::DIVIDE) - { - if (op1 == op2) - return one; - else if (op1 == zero) - return zero; - else if (op2 == zero) - return nan; - } - // for power - if (code == code_t::POWER) - { - if (op1 == zero && op2 == zero) - return nan; - else if (op1 == zero) - return zero; - else if (op2 == zero) - return one; - else if (op1 == one) - return one; - else if (op2 == one) - return op1; - } - - // order operands of commutative operations - if (code == code_t::TIMES || code == code_t::PLUS) - if (op1 > op2) - { - int tmp = op1; - op1 = op2; - op2 = tmp; - } - - // construct operation and check/add it - Operation binary(code, op1, op2); - auto i = opmap.find(binary); - if (i == opmap.end()) - { - int newop = terms.size(); - terms.push_back(binary); - // sum both sets of incidenting nulary operations - nul_incidence.push_back(nul_incidence[op1]); - nul_incidence.back().insert(nul_incidence[op2].begin(), nul_incidence[op2].end()); - // add to opmap - opmap.emplace(binary, newop); - // add empty map of derivatives - _Tderivmap empty; - derivatives.push_back(empty); - return newop; - } - return i->second; -} - -int -OperationTree::add_derivative(int t, int v) -{ - if (t < 0 || t >= static_cast<int>(terms.size())) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong value for tree index in OperationTree::add_derivative"); - - // quick returns for nulary terms or empty incidence - if (terms[t].nary() == 0 && t != v) - return zero; - - if (terms[t].nary() == 0 && t == v) - return one; - - if (nul_incidence[t].end() == nul_incidence[t].find(v)) - return zero; - - // quick return if the derivative has been registered - auto i = derivatives[t].find(v); - if (i != derivatives[t].end()) - return i->second; - - int res = -1; - switch (terms[t].getCode()) - { - case code_t::UMINUS: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_unary(code_t::UMINUS, tmp); - break; - } - case code_t::LOG: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::DIVIDE, tmp, terms[t].getOp1()); - break; - } - case code_t::EXP: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::TIMES, t, tmp); - break; - } - case code_t::SIN: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::TIMES, add_unary(code_t::COS, terms[t].getOp1()), tmp); - break; - } - case code_t::COS: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_unary(code_t::UMINUS, add_binary(code_t::TIMES, add_unary(code_t::SIN, terms[t].getOp1()), tmp)); - break; - } - case code_t::TAN: - { - int tmp = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_unary(code_t::COS, terms[t].getOp1()); - res = add_binary(code_t::DIVIDE, tmp, add_binary(code_t::TIMES, tmp2, tmp2)); - break; - } - case code_t::SQRT: - { - int tmp = add_derivative(terms[t].getOp1(), v); - res = add_binary(code_t::DIVIDE, tmp, - add_binary(code_t::PLUS, t, t)); - break; - } - case code_t::ERF: - { - int tmp = add_binary(code_t::TIMES, terms[t].getOp1(), terms[t].getOp1()); - tmp = add_unary(code_t::UMINUS, tmp); - tmp = add_unary(code_t::EXP, tmp); - int der = add_derivative(terms[t].getOp1(), v); - tmp = add_binary(code_t::TIMES, tmp, der); - res = add_binary(code_t::TIMES, two_over_pi, tmp); - break; - } - case code_t::ERFC: - { - int tmp = add_binary(code_t::TIMES, terms[t].getOp1(), terms[t].getOp1()); - tmp = add_unary(code_t::UMINUS, tmp); - tmp = add_unary(code_t::EXP, tmp); - int der = add_derivative(terms[t].getOp1(), v); - tmp = add_binary(code_t::TIMES, tmp, der); - tmp = add_binary(code_t::TIMES, two_over_pi, tmp); - res = add_unary(code_t::UMINUS, tmp); - break; - } - case code_t::PLUS: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - res = add_binary(code_t::PLUS, tmp1, tmp2); - break; - } - case code_t::MINUS: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - res = add_binary(code_t::MINUS, tmp1, tmp2); - break; - } - case code_t::TIMES: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - int res1 = add_binary(code_t::TIMES, terms[t].getOp1(), tmp2); - int res2 = add_binary(code_t::TIMES, tmp1, terms[t].getOp2()); - res = add_binary(code_t::PLUS, res1, res2); - break; - } - case code_t::DIVIDE: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - if (tmp2 == zero) - res = add_binary(code_t::DIVIDE, tmp1, terms[t].getOp2()); - else - { - int nom = add_binary(code_t::MINUS, - add_binary(code_t::TIMES, tmp1, terms[t].getOp2()), - add_binary(code_t::TIMES, tmp2, terms[t].getOp1())); - int den = add_binary(code_t::TIMES, terms[t].getOp2(), terms[t].getOp2()); - res = add_binary(code_t::DIVIDE, nom, den); - } - break; - } - case code_t::POWER: - { - int tmp1 = add_derivative(terms[t].getOp1(), v); - int tmp2 = add_derivative(terms[t].getOp2(), v); - int s1 = add_binary(code_t::TIMES, tmp2, - add_binary(code_t::TIMES, t, - add_unary(code_t::LOG, terms[t].getOp1()))); - int s2 = add_binary(code_t::TIMES, tmp1, - add_binary(code_t::TIMES, terms[t].getOp2(), - add_binary(code_t::POWER, terms[t].getOp1(), - add_binary(code_t::MINUS, terms[t].getOp2(), one)))); - res = add_binary(code_t::PLUS, s1, s2); - break; - } - case code_t::NONE: - break; - } - - if (res == -1) - throw ogu::Exception(__FILE__, __LINE__, - "Unknown operation code."); - - register_derivative(t, v, res); - - return res; -} - -int -OperationTree::add_substitution(int t, const map<int, int> &subst) -{ - return add_substitution(t, subst, *this); -} - -int -OperationTree::add_substitution(int t, const map<int, int> &subst, - const OperationTree &otree) -{ - // return substitution of t if it is in the map - auto it = subst.find(t); - if (subst.end() != it) - return it->second; - - int nary = otree.terms[t].nary(); - if (nary == 2) - { - // return the binary operation of the substituted terms - int t1 = add_substitution(otree.terms[t].getOp1(), subst, otree); - int t2 = add_substitution(otree.terms[t].getOp2(), subst, otree); - return add_binary(otree.terms[t].getCode(), t1, t2); - } - else if (nary == 1) - { - // return the unary operation of the substituted term - int t1 = add_substitution(otree.terms[t].getOp1(), subst, otree); - return add_unary(otree.terms[t].getCode(), t1); - } - else - { - // if t is not the first num_constants, and otree is not this - // tree, then raise and exception. Otherwise return t, since - // it is either a special term (having the same semantics in - // both trees), or the trees are the same, hence t has the - // same semantics - if (t < num_constants || this == &otree) - return t; - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Incomplete substitution map in OperationTree::add_substitution"); - return -1; - } - } -} - -void -OperationTree::nularify(int t) -{ - // remove the original operation from opmap - auto it = opmap.find(terms[t]); - if (it != opmap.end()) - opmap.erase(it); - // turn the operation to nulary - Operation nulary_op; - terms[t] = nulary_op; - // update last nulary - if (last_nulary < t) - last_nulary = t; - // update nul_incidence information for all terms including t - update_nul_incidence_after_nularify(t); -} - -void -OperationTree::register_derivative(int t, int v, int tder) -{ - // todo: might check that the insert inserts a new pair - derivatives[t].emplace(v, tder); -} - -unordered_set<int> -OperationTree::select_terms(int t, const opselector &sel) const -{ - unordered_set<int> subterms; - select_terms(t, sel, subterms); - return subterms; -} - -void -OperationTree::select_terms(int t, const opselector &sel, unordered_set<int> &subterms) const -{ - const Operation &op = terms[t]; - - if (sel(t)) - subterms.insert(t); - else - if (op.nary() == 2) - { - select_terms(op.getOp1(), sel, subterms); - select_terms(op.getOp2(), sel, subterms); - } - else if (op.nary() == 1) - select_terms(op.getOp1(), sel, subterms); -} - -unordered_set<int> -OperationTree::select_terms_inv(int t, const opselector &sel) const -{ - unordered_set<int> subterms; - select_terms_inv(t, sel, subterms); - return subterms; -} - -bool -OperationTree::select_terms_inv(int t, const opselector &sel, unordered_set<int> &subterms) const -{ - const Operation &op = terms[t]; - - if (op.nary() == 2) - { - bool a1 = select_terms_inv(op.getOp1(), sel, subterms); - bool a2 = select_terms_inv(op.getOp2(), sel, subterms); - if (a1 && a2 && sel(t)) - { - subterms.insert(t); - return true; - } - } - else if (op.nary() == 1) - { - bool a1 = select_terms_inv(op.getOp1(), sel, subterms); - if (a1 && sel(t)) - { - subterms.insert(t); - return true; - } - } - else - { - if (sel(t)) - { - subterms.insert(t); - return true; - } - } - - return false; -} - -void -OperationTree::forget_derivative_maps() -{ - for (auto &derivative : derivatives) - derivative.clear(); -} - -void -OperationTree::print_operation_tree(int t, std::ostream &os, OperationFormatter &f) const -{ - f.format(terms[t], t, os); -} - -void -OperationTree::print_operation(int t) const -{ - DefaultOperationFormatter dof(*this); - print_operation_tree(t, std::cout, dof); -} - -void -OperationTree::update_nul_incidence_after_nularify(int t) -{ - unordered_set<int> updated; - for (int tnode = num_constants; tnode < static_cast<int>(terms.size()); tnode++) - { - const Operation &op = terms[tnode]; - if (op.nary() == 2) - { - int op1 = op.getOp1(); - int op2 = op.getOp2(); - if (op1 >= tnode || op2 >= tnode) - throw ogu::Exception(__FILE__, __LINE__, - "Tree disorder asserted"); - bool updated1 = (updated.end() != updated.find(op1)); - bool updated2 = (updated.end() != updated.find(op2)); - if (updated1 || updated2) - { - nul_incidence[tnode] = nul_incidence[op1]; - nul_incidence[tnode].insert(nul_incidence[op2].begin(), nul_incidence[op2].end()); - updated.insert(tnode); - } - } - else if (op.nary() == 1) - { - int op1 = op.getOp1(); - if (op1 >= tnode) - throw ogu::Exception(__FILE__, __LINE__, - "Tree disorder asserted"); - bool updated1 = (updated.end() != updated.find(op1)); - if (updated1) - { - nul_incidence[tnode] = nul_incidence[op1]; - updated.insert(tnode); - } - } - else if (op.nary() == 0) - { - if (tnode == t) - { - nul_incidence[tnode].clear(); - nul_incidence[tnode].insert(tnode); - updated.insert(tnode); - } - } - } -} - -EvalTree::EvalTree(const OperationTree &ot, int last) - : otree(ot), - values(std::make_unique<double[]>((last == -1) ? ot.terms.size() : last+1)), - flags(std::make_unique<bool[]>((last == -1) ? ot.terms.size() : last+1)), - last_operation((last == -1) ? ot.terms.size()-1 : last) -{ - if (last_operation < OperationTree::num_constants-1 - || last_operation > static_cast<int>(ot.terms.size())-1) - throw ogu::Exception(__FILE__, __LINE__, - "Wrong last in EvalTree constructor."); - - values[0] = 0.0; - flags[0] = true; - values[1] = 1.0; - flags[1] = true; - values[2] = std::numeric_limits<double>::quiet_NaN(); - flags[2] = true; - values[3] = 2.0/std::sqrt(M_PI); - flags[3] = true; - // this sets from num_constants on - reset_all(); -} - -void -EvalTree::reset_all() -{ - for (int i = OperationTree::num_constants; i <= last_operation; i++) - flags[i] = false; -} - -void -EvalTree::set_nulary(int t, double val) -{ - if (t < 0 || t > last_operation) - throw ogu::Exception(__FILE__, __LINE__, - "The tree index out of bounds in EvalTree::set_nulary"); - if (t < OperationTree::num_constants || otree.terms[t].nary() != 0) - throw ogu::Exception(__FILE__, __LINE__, - "The term is not nulary assignable in EvalTree::set_nulary"); - - values[t] = val; - flags[t] = true; -} - -double -EvalTree::eval(int t) -{ - if (t < 0 || t > last_operation) - throw ogu::Exception(__FILE__, __LINE__, - "The tree index out of bounds in EvalTree::eval"); - if (otree.terms[t].nary() == 0 && flags[t] == false) - throw ogu::Exception(__FILE__, __LINE__, - "Nulary term has not been assigned a value in EvalTree::eval"); - - if (!flags[t]) - { - const Operation &op = otree.terms[t]; - if (op.nary() == 1) - { - double r1 = eval(op.getOp1()); - double res; - if (op.getCode() == code_t::UMINUS) - res = -r1; - else if (op.getCode() == code_t::LOG) - res = log(r1); - else if (op.getCode() == code_t::EXP) - res = exp(r1); - else if (op.getCode() == code_t::SIN) - res = sin(r1); - else if (op.getCode() == code_t::COS) - res = cos(r1); - else if (op.getCode() == code_t::TAN) - res = tan(r1); - else if (op.getCode() == code_t::SQRT) - res = sqrt(r1); - else if (op.getCode() == code_t::ERF) - res = erf(r1); - else if (op.getCode() == code_t::ERFC) - res = erfc(r1); - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Unknown unary operation code in EvalTree::eval"); - res = 0.0; - } - values[t] = res; - flags[t] = true; - } - else if (op.nary() == 2) - { - double res; - if (op.getCode() == code_t::PLUS) - { - double r1 = eval(op.getOp1()); - double r2 = eval(op.getOp2()); - res = r1 + r2; - } - else if (op.getCode() == code_t::MINUS) - { - double r1 = eval(op.getOp1()); - double r2 = eval(op.getOp2()); - res = r1 - r2; - } - else if (op.getCode() == code_t::TIMES) - { - // pickup less complex formula first - unsigned int nul1 = otree.nulary_of_term(op.getOp1()).size(); - unsigned int nul2 = otree.nulary_of_term(op.getOp2()).size(); - if (nul1 < nul2) - { - double r1 = eval(op.getOp1()); - if (r1 == 0.0) - res = 0.0; - else - { - double r2 = eval(op.getOp2()); - res = r1 * r2; - } - } - else - { - double r2 = eval(op.getOp2()); - if (r2 == 0) - res = 0.0; - else - { - double r1 = eval(op.getOp1()); - res = r1*r2; - } - } - } - else if (op.getCode() == code_t::DIVIDE) - { - double r1 = eval(op.getOp1()); - if (r1 == 0) - res = 0.0; - else - { - double r2 = eval(op.getOp2()); - res = r1 / r2; - } - } - else if (op.getCode() == code_t::POWER) - { - // suppose that more complex is the first op in average - double r2 = eval(op.getOp2()); - if (r2 == 0.0) - res = 1.0; - else - { - double r1 = eval(op.getOp1()); - res = pow(r1, r2); - } - } - else - { - throw ogu::Exception(__FILE__, __LINE__, - "Unknown binary operation code in EvalTree::eval"); - res = 0.0; - } - values[t] = res; - flags[t] = true; - } - return values[t]; - } - - return values[t]; -} - -void -EvalTree::print() const -{ - std::cout << "last_op=" << last_operation << '\n' - << " 0 1 2 3 4 5 6 7 8 9\n" - << "────────────────────────────────────────────────────────────────\n"; - for (int i = 0; i <= (last_operation+1)/10; i++) - { - std::cout << std::setw(3) << i << "│"; - int j = 0; - while (j < 10 && 10*i+j < last_operation+1) - { - int k = 10*i+j; - if (flags[k]) - std::cout << " " << std::setw(5) << std::setprecision(1) << values[k]; - else - std::cout << " ─────"; - j++; - } - std::cout << "\n"; - } -} - -void -DefaultOperationFormatter::format(const Operation &op, int t, std::ostream &os) -{ - // add to the stop_set - if (stop_set.end() == stop_set.find(t)) - stop_set.insert(t); - else - return; - - // call recursively non-nulary terms of the operation - if (op.nary() == 2) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - int t2 = op.getOp2(); - const Operation &op2 = otree.terms[t2]; - if (op1.nary() > 0) - format(op1, t1, os); - if (op2.nary() > 0) - format(op2, t2, os); - } - if (op.nary() == 1) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - if (op1.nary() > 0) - format(op1, t1, os); - } - - // print 'term =' - format_term(t, os); - os << " = "; - if (op.nary() == 0) - format_nulary(t, os); - else if (op.nary() == 1) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::UMINUS: - opname = "-"; - break; - case code_t::LOG: - opname = "log"; - break; - case code_t::EXP: - opname = "exp"; - break; - case code_t::SIN: - opname = "sin"; - break; - case code_t::COS: - opname = "cos"; - break; - case code_t::TAN: - opname = "tan"; - break; - case code_t::SQRT: - opname = "sqrt"; - break; - case code_t::ERF: - opname = "erf"; - break; - case code_t::ERFC: - opname = "erfc"; - break; - default: - break; - } - os << opname << '('; - if (op1.nary() == 0) - format_nulary(t1, os); - else - format_term(t1, os); - os << ")"; - } - else - { - int t1 = op.getOp1(); - const Operation &op1 = otree.terms[t1]; - int t2 = op.getOp2(); - const Operation &op2 = otree.terms[t2]; - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::PLUS: - opname = "+"; - break; - case code_t::MINUS: - opname = "-"; - break; - case code_t::TIMES: - opname = "*"; - break; - case code_t::DIVIDE: - opname = "/"; - break; - case code_t::POWER: - opname = "^"; - break; - default: - break; - } - if (op1.nary() == 0) - format_nulary(t1, os); - else - format_term(t1, os); - os << ' ' << opname << ' '; - if (op2.nary() == 0) - format_nulary(t2, os); - else - format_term(t2, os); - } - - print_delim(os); -} - -void -DefaultOperationFormatter::format_term(int t, std::ostream &os) const -{ - os << '$' << t; -} - -void -DefaultOperationFormatter::format_nulary(int t, std::ostream &os) const -{ - if (t == OperationTree::zero) - os << '0'; - else if (t == OperationTree::one) - os << '1'; - else if (t == OperationTree::nan) - os << "NaN"; - else - os << '$' << t; -} - -void -DefaultOperationFormatter::print_delim(std::ostream &os) const -{ - os << ";\n"; -} - -std::string -OperationStringConvertor::convert(const Operation &op, int t) const -{ - if (op.nary() == 0) - { - if (t < OperationTree::num_constants) - if (t == OperationTree::zero) - return "0"; - else if (t == OperationTree::one) - return "1"; - else if (t == OperationTree::nan) - return "NaN"; - else if (t == OperationTree::two_over_pi) - { - std::ostringstream buf; - buf << std::setprecision(std::numeric_limits<double>::max_digits10) - << 2.0/std::sqrt(M_PI); - return buf.str(); - } - else - return "error!error"; - else - return nulsc.convert(t); - } - else if (op.nary() == 1) - { - int t1 = op.getOp1(); - const Operation &op1 = otree.operation(t1); - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::UMINUS: - opname = "-"; - break; - case code_t::LOG: - opname = "log"; - break; - case code_t::EXP: - opname = "exp"; - break; - case code_t::SIN: - opname = "sin"; - break; - case code_t::COS: - opname = "cos"; - break; - case code_t::TAN: - opname = "tan"; - break; - case code_t::SQRT: - opname = "sqrt"; - break; - case code_t::ERF: - opname = "erf"; - break; - case code_t::ERFC: - opname = "erfc"; - break; - default: - break; - } - std::string s1 = convert(op1, t1); - return opname + "(" + s1 + ")"; - } - else - { - int t1 = op.getOp1(); - const Operation &op1 = otree.operation(t1); - int t2 = op.getOp2(); - const Operation &op2 = otree.operation(t2); - std::string opname = "unknown"; - switch (op.getCode()) - { - case code_t::PLUS: - opname = "+"; - break; - case code_t::MINUS: - opname = "-"; - break; - case code_t::TIMES: - opname = "*"; - break; - case code_t::DIVIDE: - opname = "/"; - break; - case code_t::POWER: - opname = "^"; - break; - default: - break; - } - // decide about parenthesis - bool op1_par = true; - bool op2_par = true; - if (op.getCode() == code_t::PLUS) - { - op1_par = false; - op2_par = false; - } - else if (op.getCode() == code_t::MINUS) - { - op1_par = false; - if (op2.getCode() != code_t::MINUS && op2.getCode() != code_t::PLUS) - op2_par = false; - } - else - { - if (op1.nary() < 2) - op1_par = false; - if (op2.nary() < 2) - op2_par = false; - } - - std::string res; - if (op1_par) - res += "("; - res += convert(op1, t1); - if (op1_par) - res += ")"; - res += " "; - res += opname; - res += " "; - if (op2_par) - res += "("; - res += convert(op2, t2); - if (op2_par) - res += ")"; - - return res; - } -} diff --git a/dynare++/parser/cc/tree.hh b/dynare++/parser/cc/tree.hh deleted file mode 100644 index 88474b369ef51feb9ea29faeed86becc8f4ae064..0000000000000000000000000000000000000000 --- a/dynare++/parser/cc/tree.hh +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGP_TREE_H -#define OGP_TREE_H - -#include <vector> -#include <set> -#include <map> -#include <unordered_map> -#include <unordered_set> -#include <ostream> -#include <memory> - -namespace ogp -{ - using std::unordered_set; - using std::unordered_map; - using std::vector; - using std::set; - using std::map; - - /** Enumerator representing nulary, unary and binary operation - * codes. For nulary, 'none' is used. When one is adding a new - * codes, he should update the code of #OperationTree::add_unary, - * #OperationTree::add_binary, and of course - * #OperationTree::add_derivative. */ - enum class code_t { NONE, UMINUS, LOG, EXP, SIN, COS, TAN, SQRT, ERF, - ERFC, PLUS, MINUS, TIMES, DIVIDE, POWER }; - - /** Class representing a nulary, unary, or binary operation. */ - class Operation - { - protected: - /** Code of the operation. */ - code_t code{code_t::NONE}; - /** First operand. If none, then it is -1. */ - int op1{-1}; - /** Second operand. If none, then it is -1. */ - int op2{-1}; - - public: - /** Constructs a binary operation. */ - Operation(code_t cd, int oper1, int oper2) - : code(cd), op1(oper1), op2(oper2) - { - } - /** Constructs a unary operation. */ - Operation(code_t cd, int oper1) - : code(cd), op1(oper1) - { - } - /** Constructs a nulary operation. */ - Operation() = default; - /** A copy constructor. */ - Operation(const Operation &op) = default; - - /** Operator =. */ - Operation &operator=(const Operation &op) = default; - /** Operator ==. */ - bool - operator==(const Operation &op) const - { - return code == op.code && op1 == op.op1 && op2 == op.op2; - } - /** Operator < implementing lexicographic ordering. */ - bool - operator<(const Operation &op) const - { - return (code < op.code - || (code == op.code - && (op1 < op.op1 || (op1 == op.op1 && op2 < op.op2)))); - } - /** Returns a number of operands. */ - int - nary() const - { - return (op2 == -1) ? ((op1 == -1) ? 0 : 1) : 2; - } - /** Returns a hash value of the operation. */ - size_t - hashval() const - { - return (op2+1 + op1+1)^(15 + static_cast<int>(code))^30; - } - - code_t - getCode() const - { - return code; - } - int - getOp1() const - { - return op1; - } - int - getOp2() const - { - return op2; - } - }; - - /** This struct is a predicate for ordering of the operations in - * OperationTree class. now obsolete */ - struct ltoper - { - bool - operator()(const Operation &oper1, const Operation &oper2) const - { - return oper1 < oper2; - } - }; - - /** Hash function object for Operation. */ - struct ophash - { - size_t - operator()(const Operation &op) const - { - return op.hashval(); - } - }; - - /** This struct is a function object selecting some - * operations. The operation is given by a tree index. */ - struct opselector - { - virtual bool operator()(int t) const = 0; - virtual ~opselector() = default; - }; - - /** Forward declaration of OperationFormatter. */ - class OperationFormatter; - class DefaultOperationFormatter; - - /** Forward declaration of EvalTree to make it friend of OperationTree. */ - class EvalTree; - - /** Class representing a set of trees for terms. Each term is - * given a unique non-negative integer. The terms are basically - * operations whose (integer) operands point to another terms in - * the tree. The terms are stored in the vector. Equivalent unary - * and binary terms are stored only once. This class guarantees - * the uniqueness. The uniqueness of nulary terms is guaranteed by - * the caller, since at this level of Operation abstraction, one - * cannot discriminate between different nulary operations - * (constants, variables). The uniqueness is enforced by the - * unordered_map whose keys are operations and values are integers - * (indices of the terms). - - * This class can also make derivatives of a given term with - * respect to a given nulary term. I order to be able to quickly - * recognize zero derivativates, we maintain a list of nulary - * terms contained in the term. A possible zero derivative is then quickly - * recognized by looking at the list. The list is implemented as a - * unordered_set of integers. - * - * In addition, many term can be differentiated multiple times wrt - * one variable since they can be referenced multiple times. To - * avoid this, for each term we maintain a map mapping variables - * to the derivatives of the term. As the caller will - * differentiate wrt more and more variables, these maps will - * become richer and richer. - */ - class OperationTree - { - friend class EvalTree; - friend class DefaultOperationFormatter; - protected: - /** This is the vector of the terms. An index to this vector - * uniquelly determines the term. */ - vector<Operation> terms; - - /** This defines a type for a map mapping the unary and binary - * operations to their indices. */ - using _Topmap = unordered_map<Operation, int, ophash>; - - /** This is the map mapping the unary and binary operations to - * the indices of the terms.*/ - _Topmap opmap; - - /** This is a type for a set of integers. */ - using _Tintset = unordered_set<int>; - /** This is a vector of integer sets corresponding to the - * nulary terms contained in the term. */ - vector<_Tintset> nul_incidence; - - /** This is a type of the map from variables (nulary terms) to - * the terms. */ - using _Tderivmap = unordered_map<int, int>; - /** This is a vector of derivative mappings. For each term, it - * maps variables to the derivatives of the term with respect - * to the variables. */ - vector<_Tderivmap> derivatives; - - /** The tree index of the last nulary term. */ - int last_nulary; - public: - /** Enumeration for special terms. We need zero, one, nan and - * 2/pi. These will be always first four terms having indices - * zero, one and two, three. If adding anything to this - * enumeration, make sure ‘num_constants’ remains the last one.*/ - enum { zero, one, nan, two_over_pi, num_constants }; - - /** The unique constructor which initializes the object to - * contain only zero, one and nan and two_over_pi.*/ - OperationTree(); - - /** Copy constructor. */ - OperationTree(const OperationTree &ot) = default; - - /** Add a nulary operation. The caller is responsible for not - * inserting two semantically equivalent nulary operations. - * @return newly allocated index - */ - int add_nulary(); - - /** Add a unary operation. The uniqness is checked, if it - * already exists, then it is not added. - * @param code the code of the unary operation - * @param op the index of the operand - * @return the index of the operation - */ - int add_unary(code_t code, int op); - - /** Add a binary operation. The uniqueness is checked, if it - * already exists, then it is not added. - * @param code the code of the binary operation - * @param op1 the index of the first operand - * @param op2 the index of the second operand - * @return the index of the operation - */ - int add_binary(code_t code, int op1, int op2); - - /** Add the derivative of the given term with respect to the - * given nulary operation. - * @param t the index of the operation being differentiated - * @param v the index of the nulary operation - * @return the index of the derivative - */ - int add_derivative(int t, int v); - - /** Add the substitution given by the map. This adds a new - * term which is equal to the given term with applied - * substitutions given by the map replacing each term on the - * left by a term on the right. We do not check that the terms - * on the left are not subterms of the terms on the right. If - * so, the substituted terms are not subject of further - * substitution. */ - int add_substitution(int t, const map<int, int> &subst); - - /** Add the substitution given by the map where left sides of - * substitutions come from another tree. The right sides are - * from this tree. The given t is from the given otree. */ - int add_substitution(int t, const map<int, int> &subst, - const OperationTree &otree); - - /** This method turns the given term to a nulary - * operation. This is an only method, which changes already - * existing term (all other methods add something new). User - * should use this with caution and must make sure that - * something similar has happened for atoms. In addition, it - * does not do anything with derivatives, so it should not be - * used after some derivatives were created, and derivatives - * already created and saved in derivatives mappings should be - * forgotten with forget_derivative_maps. */ - void nularify(int t); - - /** Return the set of nulary terms of the given term. */ - const unordered_set<int> & - nulary_of_term(int t) const - { - return nul_incidence[t]; - } - - /** Select subterms of the given term according a given - * operation selector and return the set of terms that - * correspond to the compounded operations. The given term is - * a compound function of the returned subterms and the - * function consists only from operations which yield false in - * the selector. */ - unordered_set<int> select_terms(int t, const opselector &sel) const; - - /** Select subterms of the given term according a given - * operation selector and return the set of terms that - * correspond to the compounded operations. The given term is - * a compound function of the returned subterms and the - * subterms are maximal subterms consisting from operations - * yielding true in the selector. */ - unordered_set<int> select_terms_inv(int t, const opselector &sel) const; - - /** This forgets all the derivative mappings. It is used after - * a term has been nularified, and then the derivative - * mappings carry wrong information. Note that the derivatives - * mappings serve only as a tool for quick returns in - * add_derivative. Resseting the mappings is harmless, all the - * information is rebuilt in add_derivative without any - * additional nodes (trees). */ - void forget_derivative_maps(); - - /** This returns an operation of a given term. */ - const Operation & - operation(int t) const - { - return terms[t]; - } - - /** This outputs the operation to the given file descriptor - * using the given OperationFormatter. */ - void print_operation_tree(int t, std::ostream &os, OperationFormatter &f) const; - - /** Debug print of a given operation: */ - void print_operation(int t) const; - - /** Return the last tree index of a nulary term. */ - int - get_last_nulary() const - { - return last_nulary; - } - - /** Get the number of all operations. */ - int - get_num_op() const - { - return static_cast<int>(terms.size()); - } - private: - /** This registers a calculated derivative of the term in the - * #derivatives vector. - * @param t the index of the term for which we register the derivative - * @param v the index of the nulary term (variable) to which - * respect the derivative was taken - * @param tder the index of the resulting derivative - */ - void register_derivative(int t, int v, int tder); - /** This does the same job as select_terms with the only - * difference, that it adds the terms to the given set and - * hence can be used recursivelly. */ - void select_terms(int t, const opselector &sel, unordered_set<int> &subterms) const; - /** This does the same job as select_terms_inv with the only - * difference, that it adds the terms to the given set and - * hence can be used recursivelly and returns true if the term - * was selected. */ - bool select_terms_inv(int t, const opselector &sel, unordered_set<int> &subterms) const; - /** This updates nul_incidence information after the term t - * was turned to a nulary term in all terms. It goes through - * the tree from simplest terms to teh more complex ones and - * changes the nul_incidence information where necesary. It - * maintains a set where the changes have been made.*/ - void update_nul_incidence_after_nularify(int t); - }; - - /** EvalTree class allows for an evaluation of the given tree for - * a given values of nulary terms. For each term in the - * OperationTree the class maintains a resulting value and a flag - * if the value has been calculated or set. The life cycle of the - * class is the following: After it is initialized, the user must - * set values for necessary nulary terms. Then the object can be - * requested to evaluate particular terms. During this process, - * the number of evaluated terms is increasing. Then the user can - * request overall reset of evaluation flags, set the nulary terms - * to new values and evaluate a number of terms. - * - * Note that currently the user cannot request a reset of - * evaluation flags only for those terms depending on a given - * nulary term. This might be added in future and handeled by a - * subclasses of OperationTree and EvalTree, since we need a - * support for this in OperationTree. - */ - class EvalTree - { - protected: - /** Reference to the OperationTree over which all evaluations - * are done. */ - const OperationTree &otree; - /** The array of values. */ - const std::unique_ptr<double[]> values; - /** The array of evaluation flags. */ - const std::unique_ptr<bool[]> flags; - /** The index of last operation in the EvalTree. Length of - * values and flags will be then last_operation+1. */ - int last_operation; - public: - /** Initializes the evaluation tree for the given operation - * tree. If last is greater than -1, that the evaluation tree - * will contain only formulas up to the given last index - * (included). */ - EvalTree(const OperationTree &otree, int last = -1); - EvalTree(const EvalTree &) = delete; - virtual ~EvalTree() = default; - /** Set evaluation flag to all terms (besides the first - * special terms) to false. */ - void reset_all(); - /** Set value for a given nulary term. */ - void set_nulary(int t, double val); - /** Evaluate the given term with nulary terms set so far. */ - double eval(int t); - /** Debug print. */ - void print() const; - /* Return the operation tree. */ - const OperationTree & - getOperationTree() const - { - return otree; - } - }; - - /** This is an interface describing how a given operation is - * formatted for output. */ - class OperationFormatter - { - public: - /** Empty virtual destructor. */ - virtual ~OperationFormatter() = default; - /** Print the formatted operation op with a given tree index t - * to a given descriptor. (See class OperationTree to know - * what is a tree index.) This prints all the tree. This - * always writes equation, left hand side is a string - * represenation (a variable, temporary, whatever) of the - * term, the right hand side is a string representation of the - * operation (which will refer to other string representation - * of subterms). */ - virtual void format(const Operation &op, int t, std::ostream &os) = 0; - }; - - /** The default formatter formats the formulas with a usual syntax - * (for example Matlab). A formatting of atoms and terms might be - * reimplemented by a subclass. In addition, during its life, the - * object maintains a set of tree indices which have been output - * and they are not output any more. */ - class DefaultOperationFormatter : public OperationFormatter - { - protected: - const OperationTree &otree; - set<int> stop_set; - public: - DefaultOperationFormatter(const OperationTree &ot) - : otree(ot) - { - } - /** Format the operation with the default syntax. */ - void format(const Operation &op, int t, std::ostream &os) override; - /** This prints a string represenation of the given term, for - * example 'tmp10' for term 10. In this implementation it - * prints $10. */ - virtual void format_term(int t, std::ostream &os) const; - /** Print a string representation of the nulary term. */ - virtual void format_nulary(int t, std::ostream &os) const; - /** Print a delimiter between two statements. By default it is - * "\n". */ - virtual void print_delim(std::ostream &os) const; - }; - - class NularyStringConvertor - { - public: - virtual ~NularyStringConvertor() = default; - /** Return the string representation of the atom with the tree - * index t. */ - virtual std::string convert(int t) const = 0; - }; - - /** This class converts the given term to its mathematical string representation. */ - class OperationStringConvertor - { - protected: - const NularyStringConvertor &nulsc; - const OperationTree &otree; - public: - OperationStringConvertor(const NularyStringConvertor &nsc, const OperationTree &ot) - : nulsc(nsc), otree(ot) - { - } - /** Empty virtual destructor. */ - virtual ~OperationStringConvertor() = default; - /** Convert the operation to the string mathematical - * representation. This does not write any equation, just - * returns a string representation of the formula. */ - std::string convert(const Operation &op, int t) const; - }; -}; - -#endif diff --git a/dynare++/src/Makefile.am b/dynare++/src/Makefile.am deleted file mode 100644 index 85abffa34b6ab401da47605d90e70a7a37efd177..0000000000000000000000000000000000000000 --- a/dynare++/src/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -bin_PROGRAMS = dynare++ - -GENERATED_FILES = dynglob_ll.cc dynglob_tab.cc dynglob_tab.hh - -dynare___SOURCES = \ - main.cc \ - dynare3.cc \ - dynare_atoms.hh \ - dynare_model.hh \ - forw_subst_builder.hh \ - planner_builder.cc \ - dynare3.hh \ - dynare_exception.hh \ - dynare_params.cc \ - planner_builder.hh \ - dynare_atoms.cc \ - dynare_model.cc \ - dynare_params.hh \ - forw_subst_builder.cc \ - nlsolve.cc \ - nlsolve.hh \ - $(GENERATED_FILES) - -dynare___CPPFLAGS = -I../sylv/cc -I../tl/cc -I../kord -I../integ/cc -I../utils/cc -I.. -I$(top_srcdir)/mex/sources $(BOOST_CPPFLAGS) $(CPPFLAGS_MATIO) -dynare___LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) $(BOOST_LDFLAGS) -dynare___LDADD = ../kord/libkord.a ../integ/cc/libinteg.a ../tl/cc/libtl.a ../parser/cc/libparser.a ../utils/cc/libutils.a ../sylv/cc/libsylv.a $(LIBADD_MATIO) $(noinst_LIBRARIES) $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) - -BUILT_SOURCES = $(GENERATED_FILES) -EXTRA_DIST = dynglob.ll dynglob.yy - -dynglob_tab.cc dynglob_tab.hh: dynglob.yy - $(YACC) -W -odynglob_tab.cc dynglob.yy - -dynare__-dynglob_tab.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast - -dynglob_ll.cc: dynglob.ll - $(LEX) -i -odynglob_ll.cc dynglob.ll - -dynare__-dynglob_ll.$(OBJEXT): CXXFLAGS += -Wno-old-style-cast diff --git a/dynare++/src/dynare3.cc b/dynare++/src/dynare3.cc deleted file mode 100644 index 746cf21ff6136eef1d3dfd110d698ba41589fb79..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare3.cc +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include <sstream> -#include <fstream> - -#include "dynare3.hh" -#include "dynare_exception.hh" -#include "planner_builder.hh" -#include "forw_subst_builder.hh" - -#include "utils/cc/exception.hh" -#include "parser/cc/parser_exception.hh" -#include "parser/cc/atom_substitutions.hh" -#include "../tl/cc/tl_exception.hh" -#include "../kord/kord_exception.hh" - -/**************************************************************************************/ -/* DynareNameList class */ -/**************************************************************************************/ -std::vector<int> -DynareNameList::selectIndices(const std::vector<std::string> &ns) const -{ - std::vector<int> res; - for (const auto &n : ns) - { - int j = 0; - while (j < getNum() && n != getName(j)) - j++; - if (j == getNum()) - throw DynareException(__FILE__, __LINE__, - "Couldn't find name for " + n - +" in DynareNameList::selectIndices"); - res.push_back(j); - } - return res; -} - -/**************************************************************************************/ -/* Dynare class */ -/**************************************************************************************/ - -Dynare::Dynare(const std::string &modname, int ord, double sstol, Journal &jr) - : journal(jr), md(1), ss_tol(sstol) -{ - std::ifstream f{modname}; - if (f.fail()) - throw DynareException(__FILE__, __LINE__, "Could not open model file "+modname); - - std::ostringstream buffer; - buffer << f.rdbuf(); - std::string contents{buffer.str()}; - - try - { - model = std::make_unique<ogdyn::DynareParser>(contents, ord); - } - catch (const ogp::ParserException &pe) - { - // Compute line and column, given the offset in the file - int line = 1; - int col = 0; - size_t i = 0; - while (i < contents.length() && i < static_cast<size_t>(pe.offset())) - { - if (contents[i] == '\n') - { - line++; - col = 0; - } - i++; - col++; - } - throw DynareException(pe.message(), modname, line, col); - } - ysteady = std::make_unique<Vector>(model->getAtoms().ny()); - dnl = std::make_unique<DynareNameList>(*this); - denl = std::make_unique<DynareExogNameList>(*this); - dsnl = std::make_unique<DynareStateNameList>(*this, *dnl, *denl); - fe = std::make_unique<ogp::FormulaEvaluator>(model->getParser()); - fde = std::make_unique<ogp::FormulaDerEvaluator>(model->getParser()); - writeModelInfo(journal); -} - -Dynare::Dynare(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const std::string &equations, int ord, - double sstol, Journal &jr) - : journal(jr), md(1), ss_tol(sstol) -{ - try - { - model = std::make_unique<ogdyn::DynareSPModel>(endo, exo, par, equations, ord); - } - catch (const ogp::ParserException &pe) - { - throw DynareException(pe.message(), pe.offset()); - } - ysteady = std::make_unique<Vector>(model->getAtoms().ny()); - dnl = std::make_unique<DynareNameList>(*this); - denl = std::make_unique<DynareExogNameList>(*this); - dsnl = std::make_unique<DynareStateNameList>(*this, *dnl, *denl); - fe = std::make_unique<ogp::FormulaEvaluator>(model->getParser()); - fde = std::make_unique<ogp::FormulaDerEvaluator>(model->getParser()); - writeModelInfo(journal); -} - -Dynare::Dynare(const Dynare &dynare) - : journal(dynare.journal), md(dynare.md), ss_tol(dynare.ss_tol) -{ - model = dynare.model->clone(); - ysteady = std::make_unique<Vector>(*(dynare.ysteady)); - dnl = std::make_unique<DynareNameList>(*this); - denl = std::make_unique<DynareExogNameList>(*this); - dsnl = std::make_unique<DynareStateNameList>(*this, *dnl, *denl); - fe = std::make_unique<ogp::FormulaEvaluator>(model->getParser()); - fde = std::make_unique<ogp::FormulaDerEvaluator>(model->getParser()); -} - -void -Dynare::writeMat(mat_t *fd, const std::string &prefix) const -{ - getAllEndoNames().writeMat(fd, prefix + "_vars"); - getAllEndoNames().writeMatIndices(fd, prefix); - getStateNames().writeMat(fd, prefix + "_state_vars"); - getExogNames().writeMat(fd, prefix + "_shocks"); - getExogNames().writeMatIndices(fd, prefix); - model->getVcov().writeMat(fd, prefix + "_vcov_exo"); - TwoDMatrix aux(1, 1); - aux.get(0, 0) = nstat(); - aux.writeMat(fd, prefix + "_nstat"); - aux.get(0, 0) = npred(); - aux.writeMat(fd, prefix + "_npred"); - aux.get(0, 0) = nboth(); - aux.writeMat(fd, prefix + "_nboth"); - aux.get(0, 0) = nforw(); - aux.writeMat(fd, prefix + "_nforw"); -} - -void -Dynare::writeDump(const std::string &basename) const -{ - std::string fname(basename + ".dump"); - std::ofstream out(fname); - model->dump_model(out); - out.close(); -} - -void -Dynare::solveDeterministicSteady(Vector &steady) -{ - JournalRecordPair pa(journal); - pa << "Non-linear solver for deterministic steady state" << endrec; - steady = const_cast<const Vector &>(model->getInit()); - DynareVectorFunction dvf(*this); - DynareJacobian dj(*this); - ogu::NLSolver nls(dvf, dj, 500, ss_tol, journal); - int iter; - if (!nls.solve(steady, iter)) - throw DynareException(__FILE__, __LINE__, - "Could not obtain convergence in non-linear solver"); -} - -// Evaluate system at given yₜ=yₜ₊₁=yₜ₋₁, and given shocks xₜ -void -Dynare::evaluateSystem(Vector &out, const ConstVector &yy, const Vector &xx) -{ - ConstVector yym(yy, nstat(), nys()); - ConstVector yyp(yy, nstat()+npred(), nyss()); - evaluateSystem(out, yym, yy, yyp, xx); -} - -/* Evaluate system at given y*ₜ₋₁, yₜ, y**ₜ₊₁ and at exogenous xₜ, all three - vectors yym, yy, and yyp have the respective lengths of y*ₜ₋₁, yₜ, y**ₜ₊₁ */ -void -Dynare::evaluateSystem(Vector &out, const ConstVector &yym, const ConstVector &yy, - const ConstVector &yyp, const Vector &xx) -{ - ogdyn::DynareAtomValues dav(model->getAtoms(), model->getParams(), yym, yy, yyp, xx); - DynareEvalLoader del(model->getAtoms(), out); - fe->eval(dav, del); -} - -void -Dynare::calcDerivatives(const Vector &yy, const Vector &xx) -{ - ConstVector yym(yy, nstat(), nys()); - ConstVector yyp(yy, nstat()+npred(), nyss()); - ogdyn::DynareAtomValues dav(model->getAtoms(), model->getParams(), yym, yy, yyp, xx); - DynareDerEvalLoader ddel(model->getAtoms(), md, model->getOrder()); - for (int iord = 1; iord <= model->getOrder(); iord++) - fde->eval(dav, ddel, iord); -} - -void -Dynare::calcDerivativesAtSteady() -{ - Vector xx(nexog()); - xx.zeros(); - calcDerivatives(*ysteady, xx); -} - -void -Dynare::writeModelInfo(Journal &jr) const -{ - // write info on variables - { - JournalRecordPair rp(journal); - rp << "Information on variables" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of endogenous: " << ny() << endrec; - JournalRecord rec2(journal); - rec2 << "Number of exogenous: " << nexog() << endrec; - JournalRecord rec3(journal); - rec3 << "Number of static: " << nstat() << endrec; - JournalRecord rec4(journal); - rec4 << "Number of predetermined: " << npred()+nboth() << endrec; - JournalRecord rec5(journal); - rec5 << "Number of forward looking: " << nforw()+nboth() << endrec; - JournalRecord rec6(journal); - rec6 << "Number of both: " << nboth() << endrec; - } - - // write info on planner variables - const ogdyn::PlannerInfo *pinfo = model->get_planner_info(); - if (pinfo) - { - JournalRecordPair rp(journal); - rp << "Information on planner variables" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of Lagrange multipliers: " << pinfo->num_lagrange_mults << endrec; - JournalRecord rec2(journal); - rec2 << "Number of auxiliary variables: " << pinfo->num_aux_variables << endrec; - JournalRecord rec3(journal); - rec3 << "Number of new terms in the tree: " << pinfo->num_new_terms << endrec; - } - - // write info on forward substitutions - const ogdyn::ForwSubstInfo *finfo = model->get_forw_subst_info(); - if (finfo) - { - JournalRecordPair rp(journal); - rp << "Information on forward substitutions" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of affected equations: " << finfo->num_affected_equations << endrec; - JournalRecord rec2(journal); - rec2 << "Number of substituted terms: " << finfo->num_subst_terms << endrec; - JournalRecord rec3(journal); - rec3 << "Number of auxiliary variables: " << finfo->num_aux_variables << endrec; - JournalRecord rec4(journal); - rec4 << "Number of new terms in the tree: " << finfo->num_new_terms << endrec; - } - - // write info on substitutions - const ogp::SubstInfo *sinfo = model->get_subst_info(); - if (sinfo) - { - JournalRecordPair rp(journal); - rp << "Information on substitutions" << endrec; - JournalRecord rec1(journal); - rec1 << "Number of substitutions: " << sinfo->num_substs << endrec; - } -} - -DynareNameList::DynareNameList(const Dynare &dynare) -{ - for (int i = 0; i < dynare.ny(); i++) - { - int j = dynare.model->getAtoms().y2outer_endo()[i]; - const std::string &name = dynare.model->getAtoms().get_endovars()[j]; - names.push_back(name); - } -} - -DynareStateNameList::DynareStateNameList(const Dynare &dynare, const DynareNameList &dnl, - const DynareExogNameList &denl) -{ - for (int i = 0; i < dynare.nys(); i++) - names.push_back(dnl.getName(i+dynare.nstat())); - for (int i = 0; i < dynare.nexog(); i++) - names.push_back(denl.getName(i)); -} - -DynareExogNameList::DynareExogNameList(const Dynare &dynare) -{ - for (int i = 0; i < dynare.nexog(); i++) - { - int j = dynare.model->getAtoms().y2outer_exo()[i]; - const std::string &name = dynare.model->getAtoms().get_exovars()[j]; - names.push_back(name); - } -} - -DynareEvalLoader::DynareEvalLoader(const ogp::FineAtoms &a, Vector &out) - : Vector(out) -{ - if (a.ny() != out.length()) - throw DynareException(__FILE__, __LINE__, "Wrong length of out vector in DynareEvalLoader constructor"); -} - -/* This clears the container of model derivatives and initializes it inserting - empty sparse tensors up to the given order. */ -DynareDerEvalLoader::DynareDerEvalLoader(const ogp::FineAtoms &a, - TensorContainer<FSSparseTensor> &mod_ders, - int order) - : atoms(a), md(mod_ders) -{ - md.clear(); - for (int iord = 1; iord <= order; iord++) - { - auto t = std::make_unique<FSSparseTensor>(iord, atoms.ny()+atoms.nys()+atoms.nyss()+atoms.nexo(), atoms.ny()); - md.insert(std::move(t)); - } -} - -void -DynareDerEvalLoader::load(int i, int iord, const int *vars, double res) -{ - FSSparseTensor &t = md.get(Symmetry{iord}); - IntSequence s(iord, 0); - for (int j = 0; j < iord; j++) - s[j] = atoms.get_pos_of_all(vars[j]); - t.insert(s, i, res); -} - -DynareJacobian::DynareJacobian(Dynare &dyn) - : Jacobian(dyn.ny()), d(dyn) -{ - zeros(); -} - -void -DynareJacobian::eval(const Vector &yy) -{ - ogdyn::DynareSteadyAtomValues - dav(d.getModel().getAtoms(), d.getModel().getParams(), yy); - zeros(); - d.fde->eval(dav, *this, 1); -} - -void -DynareJacobian::load(int i, int iord, const int *vars, double res) -{ - if (iord != 1) - throw DynareException(__FILE__, __LINE__, - "Derivative order different from order=1 in DynareJacobian::load"); - - int t = vars[0]; - int j = d.getModel().getAtoms().get_pos_of_all(t); - if (j < d.nyss()) - get(i, j+d.nstat()+d.npred()) += res; - else if (j < d.nyss()+d.ny()) - get(i, j-d.nyss()) += res; - else if (j < d.nyss()+d.ny()+d.nys()) - get(i, j-d.nyss()-d.ny()+d.nstat()) += res; -} - -void -DynareVectorFunction::eval(const ConstVector &in, Vector &out) -{ - check_for_eval(in, out); - Vector xx(d.nexog()); - xx.zeros(); - d.evaluateSystem(out, in, xx); -} diff --git a/dynare++/src/dynare3.hh b/dynare++/src/dynare3.hh deleted file mode 100644 index d0c2098725a93d4fe6389ad759d943874136ecfe..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare3.hh +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright © 2005 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef DYNARE3_H -#define DYNARE3_H - -#include "../tl/cc/t_container.hh" -#include "../tl/cc/sparse_tensor.hh" -#include "../kord/decision_rule.hh" -#include "../kord/dynamic_model.hh" - -#include "dynare_model.hh" -#include "nlsolve.hh" - -#include <vector> -#include <memory> - -#include <matio.h> - -class Dynare; - -class DynareNameList : public NameList -{ - std::vector<std::string> names; -public: - DynareNameList(const Dynare &dynare); - int - getNum() const override - { - return static_cast<int>(names.size()); - } - const std::string & - getName(int i) const override - { - return names[i]; - } - /* This for each string of the input vector calculates its index in the - names. And returns the resulting vector of indices. If the name cannot be - found, then an exception is raised. */ - std::vector<int> selectIndices(const std::vector<std::string> &ns) const; -}; - -class DynareExogNameList : public NameList -{ - std::vector<std::string> names; -public: - DynareExogNameList(const Dynare &dynare); - int - getNum() const override - { - return static_cast<int>(names.size()); - } - const std::string & - getName(int i) const override - { - return names[i]; - } -}; - -class DynareStateNameList : public NameList -{ - std::vector<std::string> names; -public: - DynareStateNameList(const Dynare &dynare, const DynareNameList &dnl, - const DynareExogNameList &denl); - int - getNum() const override - { - return static_cast<int>(names.size()); - } - const std::string & - getName(int i) const override - { - return names[i]; - } -}; - -// The following only implements DynamicModel with help of ogdyn::DynareModel - -class DynareJacobian; -class Dynare : public DynamicModel -{ - friend class DynareNameList; - friend class DynareExogNameList; - friend class DynareStateNameList; - friend class DynareJacobian; - Journal &journal; - std::unique_ptr<ogdyn::DynareModel> model; - std::unique_ptr<Vector> ysteady; - TensorContainer<FSSparseTensor> md; - std::unique_ptr<DynareNameList> dnl; - std::unique_ptr<DynareExogNameList> denl; - std::unique_ptr<DynareStateNameList> dsnl; - std::unique_ptr<ogp::FormulaEvaluator> fe; - std::unique_ptr<ogp::FormulaDerEvaluator> fde; - const double ss_tol; -public: - /* Parses the given model file and uses the given order to - override order from the model file (if it is ≠ −1). */ - Dynare(const std::string &modname, int ord, double sstol, Journal &jr); - /** Parses the given equations with explicitly given names. */ - Dynare(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const std::string &equations, int ord, - double sstol, Journal &jr); - /* Makes a deep copy of the object. */ - Dynare(const Dynare &dyn); - Dynare(Dynare &&) = default; - std::unique_ptr<DynamicModel> - clone() const override - { - return std::make_unique<Dynare>(*this); - } - - ~Dynare() override = default; - int - nstat() const override - { - return model->getAtoms().nstat(); - } - int - nboth() const override - { - return model->getAtoms().nboth(); - } - int - npred() const override - { - return model->getAtoms().npred(); - } - int - nforw() const override - { - return model->getAtoms().nforw(); - } - int - nexog() const override - { - return model->getAtoms().nexo(); - } - int - nys() const - { - return model->getAtoms().nys(); - } - int - nyss() const - { - return model->getAtoms().nyss(); - } - int - ny() const - { - return model->getAtoms().ny(); - } - int - order() const override - { - return model->getOrder(); - } - - const NameList & - getAllEndoNames() const override - { - return *dnl; - } - const NameList & - getStateNames() const override - { - return *dsnl; - } - const NameList & - getExogNames() const override - { - return *denl; - } - - TwoDMatrix & - getVcov() - { - return model->getVcov(); - } - const TwoDMatrix & - getVcov() const override - { - return model->getVcov(); - } - Vector & - getParams() - { - return model->getParams(); - } - const Vector & - getParams() const - { - return model->getParams(); - } - void - setInitOuter(const Vector &x) - { - model->setInitOuter(x); - } - - const TensorContainer<FSSparseTensor> & - getModelDerivatives() const override - { - return md; - } - const Vector & - getSteady() const override - { - return *ysteady; - } - Vector & - getSteady() override - { - return *ysteady; - } - const ogdyn::DynareModel & - getModel() const - { - return *model; - } - - // here is true public interface - void solveDeterministicSteady(Vector &steady); - void - solveDeterministicSteady() override - { - solveDeterministicSteady(*ysteady); - } - void evaluateSystem(Vector &out, const ConstVector &yy, const Vector &xx) override; - void evaluateSystem(Vector &out, const ConstVector &yym, const ConstVector &yy, - const ConstVector &yyp, const Vector &xx) override; - void calcDerivatives(const Vector &yy, const Vector &xx); - void calcDerivativesAtSteady() override; - - void writeMat(mat_t *fd, const std::string &prefix) const; - void writeDump(const std::string &basename) const; -private: - void writeModelInfo(Journal &jr) const; -}; - -class DynareEvalLoader : public ogp::FormulaEvalLoader, public Vector -{ -public: - DynareEvalLoader(const ogp::FineAtoms &a, Vector &out); - void - load(int i, double res) override - { - operator[](i) = res; - } -}; - -class DynareDerEvalLoader : public ogp::FormulaDerEvalLoader -{ -protected: - const ogp::FineAtoms &atoms; - TensorContainer<FSSparseTensor> &md; -public: - DynareDerEvalLoader(const ogp::FineAtoms &a, TensorContainer<FSSparseTensor> &mod_ders, - int order); - void load(int i, int iord, const int *vars, double res) override; -}; - -class DynareJacobian : public ogu::Jacobian, public ogp::FormulaDerEvalLoader -{ -protected: - Dynare &d; -public: - DynareJacobian(Dynare &dyn); - ~DynareJacobian() override = default; - void load(int i, int iord, const int *vars, double res) override; - void eval(const Vector &in) override; -}; - -class DynareVectorFunction : public ogu::VectorFunction -{ -protected: - Dynare &d; -public: - DynareVectorFunction(Dynare &dyn) - : d(dyn) - { - } - ~DynareVectorFunction() override = default; - int - inDim() const override - { - return d.ny(); - } - int - outDim() const override - { - return d.ny(); - } - void eval(const ConstVector &in, Vector &out) override; -}; - -#endif diff --git a/dynare++/src/dynare_atoms.cc b/dynare++/src/dynare_atoms.cc deleted file mode 100644 index 567dcb28f4d0d80250948edfe559e73c8b0bb513..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_atoms.cc +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "parser/cc/parser_exception.hh" -#include "utils/cc/exception.hh" - -#include "dynare_atoms.hh" - -#include <string> -#include <cmath> -#include <limits> -#include <sstream> -#include <iomanip> - -using namespace ogdyn; -using std::string; - -void -DynareStaticAtoms::register_name(string name) -{ - if (varnames.query(name)) - throw ogp::ParserException("The name "+name+" is not unique.", 0); - StaticAtoms::register_name(std::move(name)); -} - -int -DynareStaticAtoms::check_variable(const string &name) const -{ - if (!varnames.query(name)) - throw ogp::ParserException("Unknown name <"+name+">", 0); - auto it = vars.find(name); - if (it == vars.end()) - return -1; - else - return it->second; -} - -void -DynareDynamicAtoms::parse_variable(const string &in, std::string &out, int &ll) const -{ - ll = 0; - auto left = in.find_first_of("({"); - if (left != string::npos) - { - out = in.substr(0, left); - left++; - auto right = in.find_first_of(")}", left); - if (string::npos == right) - throw ogp::ParserException("Syntax error when parsing Dynare atom <"+in+">.", 0); - ll = std::stoi(in.substr(left, right-left)); - } - else - out = in; -} - -void -DynareDynamicAtoms::register_uniq_endo(string name) -{ - FineAtoms::register_uniq_endo(name); - atom_type.emplace(std::move(name), atype::endovar); -} - -void -DynareDynamicAtoms::register_uniq_exo(string name) -{ - FineAtoms::register_uniq_exo(name); - atom_type.emplace(std::move(name), atype::exovar); -} - -void -DynareDynamicAtoms::register_uniq_param(string name) -{ - FineAtoms::register_uniq_param(name); - atom_type.emplace(std::move(name), atype::param); -} - -bool -DynareDynamicAtoms::is_type(const string &name, atype tp) const -{ - auto it = atom_type.find(name); - if (it != atom_type.end() && it->second == tp) - return true; - else - return false; -} - -void -DynareDynamicAtoms::print() const -{ - SAtoms::print(); - std::cout << "Name types:\n"; - for (auto it : atom_type) - std::cout << "name=" << it.first << " type=" - << (it.second == atype::endovar ? "endovar" : it.second == atype::exovar ? "exovar" : "param") - << '\n'; -} - -std::string -DynareDynamicAtoms::convert(int t) const -{ - if (t < ogp::OperationTree::num_constants) - { - throw ogu::Exception(__FILE__, __LINE__, - "Tree index is a built-in constant in DynareDynamicAtoms::convert"); - return {}; - } - if (is_constant(t)) - { - double v = get_constant_value(t); - std::ostringstream buf; - buf << std::setprecision(std::numeric_limits<double>::max_digits10) - << v; - return buf.str(); - } - - const string &s = name(t); - if (is_type(s, atype::endovar)) - { - int ll = lead(t); - if (ll) - return s + '(' + std::to_string(ll) + ')'; - } - - return s; -} - -void -DynareAtomValues::setValues(ogp::EvalTree &et) const -{ - // set constants - atoms.setValues(et); - - // set parameteres - for (unsigned int i = 0; i < atoms.get_params().size(); i++) - if (atoms.is_referenced(atoms.get_params()[i])) - { - const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_params()[i]); - for (auto it : lmap) - { - int t = it.second; - et.set_nulary(t, paramvals[i]); - } - } - - // set endogenous - for (unsigned int outer_i = 0; outer_i < atoms.get_endovars().size(); outer_i++) - if (atoms.is_referenced(atoms.get_endovars()[outer_i])) - { - const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_endovars()[outer_i]); - for (auto it : lmap) - { - int ll = it.first; - int t = it.second; - int i = atoms.outer2y_endo()[outer_i]; - if (ll == -1) - et.set_nulary(t, yym[i-atoms.nstat()]); - else if (ll == 0) - et.set_nulary(t, yy[i]); - else - et.set_nulary(t, yyp[i-atoms.nstat()-atoms.npred()]); - } - } - - // set exogenous - for (unsigned int outer_i = 0; outer_i < atoms.get_exovars().size(); outer_i++) - if (atoms.is_referenced(atoms.get_exovars()[outer_i])) - { - const ogp::DynamicAtoms::Tlagmap &lmap = atoms.lagmap(atoms.get_exovars()[outer_i]); - for (auto it : lmap) - { - int ll = it.first; - if (ll == 0) // this is always true because of checks - { - int t = it.second; - int i = atoms.outer2y_exo()[outer_i]; - et.set_nulary(t, xx[i]); - } - } - } -} - -void -DynareStaticSteadyAtomValues::setValues(ogp::EvalTree &et) const -{ - // set constants - atoms_static.setValues(et); - - // set parameters - for (auto name : atoms_static.get_params()) - { - int t = atoms_static.index(name); - if (t != -1) - { - int idyn = atoms.name2outer_param(name); - et.set_nulary(t, paramvals[idyn]); - } - } - - // set endogenous - for (auto name : atoms_static.get_endovars()) - { - int t = atoms_static.index(name); - if (t != -1) - { - int idyn = atoms.outer2y_endo()[atoms.name2outer_endo(name)]; - et.set_nulary(t, yy[idyn]); - } - } - - // set exogenous - for (auto name : atoms_static.get_exovars()) - { - int t = atoms_static.index(name); - if (t != -1) - et.set_nulary(t, 0.0); - } -} - -DynareSteadySubstitutions::DynareSteadySubstitutions(const ogp::FineAtoms &a, - const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy) - : atoms(a), y(yy) -{ - // fill the vector of left and right hand sides - for (auto it : subst) - { - left_hand_sides.push_back(it.first); - right_hand_sides.push_back(it.second); - } - - // evaluate right hand sides - DynareSteadyAtomValues dsav(atoms, pvals, y); - ogp::FormulaCustomEvaluator fe(tree, right_hand_sides); - fe.eval(dsav, *this); -} - -void -DynareSteadySubstitutions::load(int i, double res) -{ - const string &name = left_hand_sides[i]; - int iouter = atoms.name2outer_endo(name); - int iy = atoms.outer2y_endo()[iouter]; - if (!std::isfinite(y[iy])) - y[iy] = res; -} - -DynareStaticSteadySubstitutions:: -DynareStaticSteadySubstitutions(const ogp::FineAtoms &a, const ogp::StaticFineAtoms &sa, - const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy) - : atoms(a), atoms_static(sa), y(yy) -{ - // fill the vector of left and right hand sides - for (const auto &it : subst) - { - left_hand_sides.push_back(it.first); - right_hand_sides.push_back(it.second); - } - - // evaluate right hand sides - DynareStaticSteadyAtomValues dsav(atoms, atoms_static, pvals, y); - ogp::FormulaCustomEvaluator fe(tree, right_hand_sides); - fe.eval(dsav, *this); -} - -void -DynareStaticSteadySubstitutions::load(int i, double res) -{ - const string &name = left_hand_sides[i]; - int iouter = atoms.name2outer_endo(name); - int iy = atoms.outer2y_endo()[iouter]; - if (!std::isfinite(y[iy])) - y[iy] = res; -} diff --git a/dynare++/src/dynare_atoms.hh b/dynare++/src/dynare_atoms.hh deleted file mode 100644 index 60d8244910c9e52946b46d0585acee4a3dee1494..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_atoms.hh +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGDYN_DYNARE_ATOMS_H -#define OGDYN_DYNARE_ATOMS_H - -#include "sylv/cc/Vector.hh" - -#include "parser/cc/static_atoms.hh" -#include "parser/cc/static_fine_atoms.hh" -#include "parser/cc/atom_substitutions.hh" -#include "parser/cc/tree.hh" - -#include <map> -#include <vector> - -namespace ogdyn -{ - using std::map; - using std::vector; - using std::string; - - /* A definition of a type mapping a string to an integer. Used as a - substitution map, saying what names are substituted for what expressions - represented by tree indices. */ - using Tsubstmap = map<string, int>; - - class DynareStaticAtoms : public ogp::StaticAtoms - { - public: - DynareStaticAtoms() - : StaticAtoms() - { - } - DynareStaticAtoms(const DynareStaticAtoms &a) = default; - ~DynareStaticAtoms() override = default; - /* This registers a unique varname identifier. It throws an exception if - the variable name is duplicate. It checks the uniqueness and then it - calls StaticAtoms::register_name. */ - void register_name(string name) override; - protected: - /* This returns a tree index of the given variable, and if the variable has - not been registered, it throws an exception. */ - int check_variable(const string &name) const override; - }; - - class DynareDynamicAtoms : public ogp::SAtoms, public ogp::NularyStringConvertor - { - public: - enum class atype { endovar, exovar, param }; - protected: - using Tatypemap = map<string, atype>; - /* The map assigining a type to each name. */ - Tatypemap atom_type; - public: - DynareDynamicAtoms() - : ogp::SAtoms() - { - } - /* This parses a variable of the forms: varname(+3), varname(3), varname, - varname(-3), varname(0), varname(+0), varname(-0). */ - void parse_variable(const string &in, std::string &out, int &ll) const override; - /* Registers unique name of endogenous variable. */ - void register_uniq_endo(string name) override; - /* Registers unique name of exogenous variable. */ - void register_uniq_exo(string name) override; - /* Registers unique name of parameter. */ - void register_uniq_param(string name) override; - /* Return true if the name is a given type. */ - bool is_type(const string &name, atype tp) const; - /* Debug print. */ - void print() const override; - /* Implement NularyStringConvertor::convert. */ - std::string convert(int t) const override; - }; - - /* This class represents the atom values for dynare, where exogenous - variables can occur only at time t, and endogenous at times t−1, t, and - t+1. */ - class DynareAtomValues : public ogp::AtomValues - { - protected: - /* Reference to the atoms (we suppose that they are only at t−1,t,t+1. */ - const ogp::FineAtoms &atoms; - /* De facto reference to the values of parameters. */ - const ConstVector paramvals; - /* De facto reference to the values of endogenous at time t−1. Only - predetermined and both part. */ - const ConstVector yym; - /* De facto reference to the values of endogenous at time t. Ordering given - by the atoms. */ - const ConstVector yy; - /* De facto reference to the values of endogenous at time t+1. Only both - and forward looking part. */ - const ConstVector yyp; - /* De facto reference to the values of exogenous at time t. */ - const ConstVector xx; - public: - DynareAtomValues(const ogp::FineAtoms &a, const Vector &pvals, const Vector &ym, - const Vector &y, const Vector &yp, const Vector &x) - : atoms(a), paramvals(pvals), yym(ym), yy(y), yyp(yp), xx(x) - { - } - DynareAtomValues(const ogp::FineAtoms &a, const Vector &pvals, const ConstVector &ym, - const ConstVector &y, const ConstVector &yp, const Vector &x) - : atoms(a), paramvals(pvals), yym(ym), yy(y), yyp(yp), xx(x) - { - } - void setValues(ogp::EvalTree &et) const override; - }; - - /* This class represents the atom values at the steady state. It makes only - appropriate subvector yym and yyp of the y vector, makes a vector of zero - exogenous variables and uses DynareAtomValues with more general - interface. */ - class DynareSteadyAtomValues : public ogp::AtomValues - { - protected: - /* Subvector of yy. */ - const ConstVector yym; - /* Subvector of yy. */ - const ConstVector yyp; - /* Vector of zeros for exogenous variables. */ - Vector xx; - /* Atom values using this yym, yyp and xx. */ - DynareAtomValues av; - public: - DynareSteadyAtomValues(const ogp::FineAtoms &a, const Vector &pvals, const Vector &y) - : yym(y, a.nstat(), a.nys()), - yyp(y, a.nstat()+a.npred(), a.nyss()), - xx(a.nexo()), - av(a, pvals, yym, y, yyp, xx) - { - xx.zeros(); - } - void - setValues(ogp::EvalTree &et) const override - { - av.setValues(et); - } - }; - - class DynareStaticSteadyAtomValues : public ogp::AtomValues - { - protected: - /* Reference to static atoms over which the tree, where the values go, is - defined. */ - const ogp::StaticFineAtoms &atoms_static; - /* Reference to dynamic atoms for which the class gets input data. */ - const ogp::FineAtoms &atoms; - /* De facto reference to input data, this is a vector of endogenous - variables in internal ordering of the dynamic atoms. */ - ConstVector yy; - /* De facto reference to input parameters corresponding to ordering defined - by the dynamic atoms. */ - ConstVector paramvals; - public: - /* Construct the object. */ - DynareStaticSteadyAtomValues(const ogp::FineAtoms &a, const ogp::StaticFineAtoms &sa, - const Vector &pvals, const Vector &yyy) - : atoms_static(sa), - atoms(a), - yy(yyy), - paramvals(pvals) - { - } - /* Set the values to the tree defined over the static atoms. */ - void setValues(ogp::EvalTree &et) const override; - }; - - /* This class takes a vector of endogenous variables and a substitution map. - It supposes that variables at the right hand sides of the substitutions - are set in the endogenous vector. It evaluates the substitutions and if - the variables corresponding to left hand sides are not set in the - endogenous vector it sets them to calculated values. If a variable is - already set, it does not override its value. It has no methods, everything - is done in the constructor. */ - class DynareSteadySubstitutions : public ogp::FormulaEvalLoader - { - protected: - const ogp::FineAtoms &atoms; - public: - DynareSteadySubstitutions(const ogp::FineAtoms &a, const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy); - void load(int i, double res) override; - protected: - Vector &y; - vector<string> left_hand_sides; - vector<int> right_hand_sides; - }; - - /* This class is a static version of DynareSteadySustitutions. It works for - static atoms and static tree and substitution map over the static tree. It - also needs dynamic version of the atoms, since it defines ordering of the - vectors pvals, and yy. */ - class DynareStaticSteadySubstitutions : public ogp::FormulaEvalLoader - { - protected: - const ogp::FineAtoms &atoms; - const ogp::StaticFineAtoms &atoms_static; - public: - DynareStaticSteadySubstitutions(const ogp::FineAtoms &a, - const ogp::StaticFineAtoms &sa, - const ogp::OperationTree &tree, - const Tsubstmap &subst, - const Vector &pvals, Vector &yy); - void load(int i, double res) override; - protected: - Vector &y; - vector<string> left_hand_sides; - vector<int> right_hand_sides; - }; - -}; - -#endif diff --git a/dynare++/src/dynare_model.cc b/dynare++/src/dynare_model.cc deleted file mode 100644 index ce9e48dcb61485cb30e0e76de5b92918f4795eaa..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_model.cc +++ /dev/null @@ -1,968 +0,0 @@ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "parser/cc/parser_exception.hh" -#include "parser/cc/location.hh" -#include "utils/cc/exception.hh" -#include "dynare_model.hh" -#include "dynare_exception.hh" -#include "planner_builder.hh" -#include "forw_subst_builder.hh" - -#include <string> -#include <cmath> -#include <limits> -#include <ostream> -#include <memory> -#include <algorithm> -#include <iomanip> - -using namespace ogdyn; - -ParsedMatrix::ParsedMatrix(const ogp::MatrixParser &mp) - : TwoDMatrix(mp.nrows(), mp.ncols()) -{ - zeros(); - for (ogp::MPIterator it = mp.begin(); it != mp.end(); ++it) - get(it.row(), it.col()) = *it; -} - -DynareModel::DynareModel() - : atoms(), eqs(atoms) -{ -} - -DynareModel::DynareModel(const DynareModel &dm) - : atoms(dm.atoms), eqs(dm.eqs, atoms), order(dm.order), - t_plobjective(dm.t_plobjective), - t_pldiscount(dm.t_pldiscount) -{ - if (dm.param_vals) - param_vals = std::make_unique<Vector>(const_cast<const Vector &>(*dm.param_vals)); - if (dm.init_vals) - init_vals = std::make_unique<Vector>(const_cast<const Vector &>(*dm.init_vals)); - if (dm.vcov_mat) - vcov_mat = std::make_unique<TwoDMatrix>(const_cast<const TwoDMatrix &>(*dm.vcov_mat)); - if (dm.old_atoms) - old_atoms = std::make_unique<DynareDynamicAtoms>(static_cast<const DynareDynamicAtoms &>(*dm.old_atoms)); - if (dm.atom_substs) - atom_substs = std::make_unique<ogp::AtomSubstitutions>(*dm.atom_substs, *old_atoms, atoms); - if (dm.pbuilder) - pbuilder = std::make_unique<PlannerBuilder>(*dm.pbuilder, *this); - if (dm.fbuilder) - fbuilder = std::make_unique<ForwSubstBuilder>(*dm.fbuilder, *this); -} - -const PlannerInfo * -DynareModel::get_planner_info() const -{ - if (pbuilder) - return &(pbuilder->get_info()); - return nullptr; -} - -const ForwSubstInfo * -DynareModel::get_forw_subst_info() const -{ - if (fbuilder) - return &(fbuilder->get_info()); - return nullptr; -} - -const ogp::SubstInfo * -DynareModel::get_subst_info() const -{ - if (atom_substs) - return &(atom_substs->get_info()); - return nullptr; -} - -void -DynareModel::setInitOuter(const Vector &x) -{ - if (x.length() != atoms.ny()) - throw DynareException(__FILE__, __LINE__, - "Wrong length of vector in DynareModel::setInitOuter"); - for (int i = 0; i < atoms.ny(); i++) - (*init_vals)[i] = x[atoms.y2outer_endo()[i]]; -} - -void -DynareModel::print() const -{ - std::cout << "all atoms:\n"; - atoms.print(); - std::cout << "formulas:\n"; - DebugOperationFormatter dof(*this); - for (int i = 0; i < eqs.nformulas(); i++) - { - int tf = eqs.formula(i); - std::cout << "formula " << tf << "%d:\n"; - eqs.getTree().print_operation_tree(tf, std::cout, dof); - } -} - -void -DynareModel::dump_model(std::ostream &os) const -{ - // endogenous variable declaration - os << "var"; - for (auto i : atoms.get_endovars()) - os << " " << i; - os << ";\n\n"; - - // exogenous variables - os << "varexo"; - for (auto i : atoms.get_exovars()) - os << " " << i; - os << ";\n\n"; - - // parameters - os << "parameters"; - for (auto i : atoms.get_params()) - os << " " << i; - os << ";\n\n"; - - // parameter values - os.precision(16); - for (int i = 0; i < static_cast<int>(atoms.get_params().size()); i++) - os << atoms.get_params()[i] << "=" << getParams()[i] << ";\n"; - os << "\n\n"; - - // model section - ogp::OperationStringConvertor osc(atoms, getParser().getTree()); - os << "model;\n"; - for (int i = 0; i < getParser().nformulas(); i++) - { - os << "// Equation " << i << "\n0 = "; - int t = getParser().formula(i); - os << osc.convert(getParser().getTree().operation(t), t); - os << ";\n"; - } - os << "end;\n"; - - // initval as steady state - os << "initval;\n"; - for (int i = 0; i < static_cast<int>(atoms.get_endovars().size()); i++) - os << atoms.get_endovars()[atoms.y2outer_endo()[i]] << "=" << getInit()[i] << ";\n"; - os << "end;\n"; -} - -void -DynareModel::add_name(std::string name, int flag) -{ - if (flag == 1) - // endogenous - atoms.register_uniq_endo(name); - else if (flag == 2) - // exogenous - atoms.register_uniq_exo(name); - else if (flag == 3) - // parameter - atoms.register_uniq_param(name); - else - throw DynareException(__FILE__, __LINE__, "Unrecognized flag value."); -} - -void -DynareModel::check_model() const -{ - if (order == -1) - throw DynareException(__FILE__, __LINE__, - "Order of approximation not set in DynareModel::check_model"); - - if (atoms.ny() != eqs.nformulas()) - throw DynareException(__FILE__, __LINE__, "Model has " + std::to_string(eqs.nformulas()) - + " equations for " + std::to_string(atoms.ny()) + " endogenous variables"); - - /* check whether all nulary terms of all formulas in eqs are either constant - or assigned to a name */ - for (int i = 0; i < eqs.nformulas(); i++) - { - int ft = eqs.formula(i); - const unordered_set<int> &nuls = eqs.nulary_of_term(ft); - for (int nul : nuls) - if (!atoms.is_constant(nul) && !atoms.is_named_atom(nul)) - throw DynareException(__FILE__, __LINE__, - "Dangling nulary term found, internal error."); - } - - int mlag, mlead; - atoms.exovarspan(mlead, mlag); - if (atoms.nexo() > 0 && (mlead != 0 || mlag != 0)) - throw DynareException(__FILE__, __LINE__, - "The model contains occurrences of lagged/leaded exogenous variables"); - - atoms.endovarspan(mlead, mlag); - if (mlead > 1 || mlag < -1) - throw DynareException(__FILE__, __LINE__, - "The model contains occurrences of too lagged/leaded endogenous variables"); - - // check the dimension of vcov matrix - if (getAtoms().nexo() != getVcov().nrows()) - throw DynareException(__FILE__, __LINE__, - "Dimension of VCOV matrix does not correspond to the shocks"); -} - -int -DynareModel::variable_shift(int t, int tshift) -{ - const string &name = atoms.name(t); - if (atoms.is_type(name, DynareDynamicAtoms::atype::param) - || atoms.is_constant(t)) - throw DynareException(__FILE__, __LINE__, - "The tree index is not a variable in DynareModel::variable_shift"); - int ll = atoms.lead(t) + tshift; - int res = atoms.index(name, ll); - if (res == -1) - res = eqs.add_nulary(name + '(' + std::to_string(ll) + ')'); - return res; -} - -void -DynareModel::variable_shift_map(const unordered_set<int> &a_set, int tshift, - map<int, int> &s_map) -{ - s_map.clear(); - for (int t : a_set) - // make shift map only for non-constants and non-parameters - if (!atoms.is_constant(t)) - { - const string &name = atoms.name(t); - if (atoms.is_type(name, DynareDynamicAtoms::atype::endovar) - || atoms.is_type(name, DynareDynamicAtoms::atype::exovar)) - { - int tt = variable_shift(t, tshift); - s_map.emplace(t, tt); - } - } -} - -void -DynareModel::termspan(int t, int &mlead, int &mlag) const -{ - mlead = std::numeric_limits<int>::min(); - mlag = std::numeric_limits<int>::max(); - const unordered_set<int> &nul_terms = eqs.nulary_of_term(t); - for (int nul_term : nul_terms) - { - if (!atoms.is_constant(nul_term) - && (atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::atype::endovar) - || atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::atype::exovar))) - { - int ll = atoms.lead(nul_term); - mlag = std::min(ll, mlag); - mlead = std::max(ll, mlead); - } - } -} - -bool -DynareModel::is_constant_term(int t) const -{ - const unordered_set<int> &nul_terms = eqs.nulary_of_term(t); - for (int nul_term : nul_terms) - if (!atoms.is_constant(nul_term) - && !atoms.is_type(atoms.name(nul_term), DynareDynamicAtoms::atype::param)) - return false; - return true; -} - -unordered_set<int> -DynareModel::get_nonlinear_subterms(int t) const -{ - NLSelector nls(*this); - return eqs.getTree().select_terms(t, nls); -} - -void -DynareModel::substitute_atom_for_term(const string &name, int ll, int t) -{ - /* if the term t is itself a named atom (parameter, exo, endo), then we have - to unassign it first */ - if (atoms.is_named_atom(t)) - atoms.unassign_variable(atoms.name(t), atoms.lead(t), t); - /* assign allocated tree index for the term now to name(ll) */ - atoms.assign_variable(name, ll, t); - // make operation t nulary in operation tree - eqs.nularify(t); -} - -void -DynareModel::final_job() -{ - if (t_plobjective != -1 && t_pldiscount != -1) - { - /* at this moment include all equations and all variables; in future we - will exclude purely exogenous processes; TODO */ - PlannerBuilder::Tvarset vset; - for (int i = 0; i < atoms.ny(); i++) - vset.insert(atoms.get_endovars()[i]); - PlannerBuilder::Teqset eset; - for (int i = 0; i < eqs.nformulas(); i++) - eset.push_back(i); - - // construct the planner builder, this adds a lot of stuff to the model - pbuilder = std::make_unique<PlannerBuilder>(*this, vset, eset); - } - - // construct ForwSubstBuilder - fbuilder = std::make_unique<ForwSubstBuilder>(*this); - - // call parsing_finished (this will define an outer ordering of all variables) - atoms.parsing_finished(ogp::VarOrdering::bfspbfpb); - // make a copy of atoms and name it old_atoms - old_atoms = std::make_unique<DynareDynamicAtoms>(atoms); - // construct empty substitutions from old_atoms to atoms - atom_substs = std::make_unique<ogp::AtomSubstitutions>(*old_atoms, atoms); - /* do the actual substitution, it will also call parsing_finished for atoms - which creates internal orderings */ - atoms.substituteAllLagsAndExo1Leads(eqs, *atom_substs); -} - -extern ogp::location_type dynglob_lloc; - -DynareParser::DynareParser(const string &stream, int ord) - : DynareModel(), - pa_atoms(), paramset(pa_atoms), - ia_atoms(), initval(ia_atoms), vcov(), - model_beg(0), model_end(-1), - paramset_beg(0), paramset_end(-1), - initval_beg(0), initval_end(-1), - vcov_beg(0), vcov_end(-1), - order_beg(0), order_end(-1), - plobjective_beg(0), plobjective_end(-1), - pldiscount_beg(0), pldiscount_end(-1) -{ - // global parse - try - { - parse_glob(stream); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, dynglob_lloc.off); - } - // setting parameters parse - try - { - if (paramset_end > paramset_beg) - paramset.parse(stream.substr(paramset_beg, paramset_end-paramset_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, paramset_beg); - } - // model parse - try - { - if (model_end > model_beg) - eqs.parse(stream.substr(model_beg, model_end-model_beg)); - else - throw ogp::ParserException("Model section not found.", 0); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, model_beg); - } - // initval setting parse - try - { - if (initval_end > initval_beg) - initval.parse(stream.substr(initval_beg, initval_end-initval_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, initval_beg); - } - // vcov parse - try - { - if (vcov_end > vcov_beg) - vcov.parse(stream.substr(vcov_beg, vcov_end-vcov_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, vcov_beg); - } - // planner objective parse - try - { - if (plobjective_end > plobjective_beg) - { - eqs.parse(stream.substr(plobjective_beg, plobjective_end-plobjective_beg)); - t_plobjective = eqs.pop_last_formula(); - } - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, plobjective_beg); - } - // planner discount parse - try - { - if (pldiscount_end > pldiscount_beg) - t_pldiscount = parse_pldiscount(stream.substr(pldiscount_beg, pldiscount_end - pldiscount_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, pldiscount_beg); - } - // order parse - try - { - if (order_end > order_beg) - order = parse_order(stream.substr(order_beg, order_end - order_beg)); - } - catch (const ogp::ParserException &e) - { - throw ogp::ParserException(e, order_beg); - } - - // check the overridden order - if (ord != -1) - order = ord; - - // end parsing job, add planner's FOCs, make substitutions - DynareModel::final_job(); - - // calculate parameters - calc_params(); - // calculate initial values - calc_init(); - - if (vcov_end > vcov_beg) - vcov_mat = std::make_unique<ParsedMatrix>(vcov); - else - { - // vcov has not been asserted, set it to unit matrix - vcov_mat = std::make_unique<TwoDMatrix>(atoms.nexo(), atoms.nexo()); - vcov_mat->unit(); - } - - // check the model - check_model(); - - // differentiate - if (order >= 1) - eqs.differentiate(order); -} - -DynareParser::DynareParser(const DynareParser &dp) - : DynareModel(dp), - pa_atoms(dp.pa_atoms), paramset(dp.paramset, pa_atoms), - ia_atoms(dp.ia_atoms), initval(dp.initval, ia_atoms), vcov(dp.vcov), - model_beg(dp.model_beg), model_end(dp.model_end), - paramset_beg(dp.paramset_beg), paramset_end(dp.paramset_end), - initval_beg(dp.initval_beg), initval_end(dp.initval_end), - vcov_beg(dp.vcov_beg), vcov_end(dp.vcov_end), - order_beg(dp.order_beg), order_end(dp.order_end), - plobjective_beg(dp.plobjective_beg), plobjective_end(dp.plobjective_end), - pldiscount_beg(dp.pldiscount_beg), pldiscount_end(dp.pldiscount_end) -{ -} - -void -DynareParser::add_name(string name, int flag) -{ - DynareModel::add_name(name, flag); - // register with static atoms used for atom assignements - if (flag == 1) - // endogenous - ia_atoms.register_name(std::move(name)); - else if (flag == 2) - // exogenous - ia_atoms.register_name(std::move(name)); - else if (flag == 3) - { - // parameter - pa_atoms.register_name(name); - ia_atoms.register_name(std::move(name)); - } - else - throw DynareException(__FILE__, __LINE__, "Unrecognized flag value."); -} - -void -DynareParser::error(string mes) -{ - // throwing zero offset since this exception will be caugth at constructor - throw ogp::ParserException(std::move(mes), 0); -} - -void -DynareParser::print() const -{ - DynareModel::print(); - std::cout << "parameter atoms:\n"; - paramset.print(); - std::cout << "initval atoms:\n"; - initval.print(); - std::cout << "model position: " << model_beg << ' ' << model_end << '\n' - << "paramset position: " << paramset_beg << ' ' << paramset_end << '\n' - << "initval position: " << initval_beg << ' ' << initval_end << '\n'; -} - -/* A global symbol for passing info to the DynareParser from parser. */ -DynareParser *dynare_parser; - -/* The declarations of functions defined in dynglob_ll.cc and dynglob_tab.cc - generated from dynglob.lex and dynglob.y */ -void *dynglob__scan_string(const char *); -void dynglob__destroy_buffer(void *); -void dynglob_parse(); -extern ogp::location_type dynglob_lloc; - -void -DynareParser::parse_glob(const string &stream) -{ - void *p = dynglob__scan_string(stream.c_str()); - dynare_parser = this; - dynglob_parse(); - dynglob__destroy_buffer(p); -} - -int -DynareParser::parse_order(const string &str) -{ - return std::stoi(str); -} - -int -DynareParser::parse_pldiscount(const string &str) -{ - if (!atoms.is_type(str, DynareDynamicAtoms::atype::param)) - throw ogp::ParserException("Name " + str + " is not a parameter", 0); - - int t = atoms.index(str, 0); - if (t == -1) - t = eqs.add_nulary(str); - - return t; -} - -void -DynareParser::calc_params() -{ - param_vals = std::make_unique<Vector>(atoms.np()); - ogp::AtomAsgnEvaluator aae(paramset); - aae.eval(); - for (int i = 0; i < atoms.np(); i++) - (*param_vals)[i] = aae.get_value(atoms.get_params()[i]); - - for (unsigned int i = 0; i < atoms.get_params().size(); i++) - if (!std::isfinite((*param_vals)[i])) - std::cout << "dynare++: warning: value for parameter " << atoms.get_params()[i] << " is not finite\n"; -} - -void -DynareParser::calc_init() -{ - // update initval atoms assignings according to substitutions - if (atom_substs) - initval.apply_subst(atom_substs->get_old2new()); - - // calculate the vector of initial values - init_vals = std::make_unique<Vector>(atoms.ny()); - ogp::AtomAsgnEvaluator aae(initval); - // set parameters - for (int ip = 0; ip < atoms.np(); ip++) - aae.set_user_value(atoms.get_params()[ip], (*param_vals)[ip]); - // set exogenous to zeros - for (int ie = 0; ie < atoms.nexo(); ie++) - aae.set_user_value(atoms.get_exovars()[ie], 0.0); - // evaluate - aae.eval(); - // set results to internally ordered vector init_vals - for (int outer = 0; outer < atoms.ny(); outer++) - { - int i = atoms.outer2y_endo()[outer]; - (*init_vals)[i] = aae.get_value(atoms.get_endovars()[outer]); - } - - /* if the planner's FOCs have been added, then add estimate of Lagrange - multipliers to the vector */ - if (pbuilder) - MultInitSS mis(*pbuilder, *param_vals, *init_vals); - - /* if forward substitution builder has been created, we have to its - substitutions and evaluate them */ - if (fbuilder) - ogdyn::DynareSteadySubstitutions dss(atoms, eqs.getTree(), - fbuilder->get_aux_map(), *param_vals, *init_vals); - - for (unsigned int i = 0; i < atoms.get_endovars().size(); i++) - if (!std::isfinite((*init_vals)[i])) - std::cout << "dynare++: warning: initval for <" << atoms.get_endovars()[atoms.y2outer_endo()[i]] << "> is not finite\n"; -} - -// this returns false for linear functions -bool -NLSelector::operator()(int t) const -{ - const ogp::Operation &op = model.getParser().getTree().operation(t); - const DynareDynamicAtoms &atoms = model.getAtoms(); - // if the term is constant, return false - if (model.is_constant_term(t)) - return false; - int nary = op.nary(); - if (nary == 0) - { - if (atoms.is_type(atoms.name(t), DynareDynamicAtoms::atype::endovar) - || atoms.is_type(atoms.name(t), DynareDynamicAtoms::atype::exovar)) - return true; - else - return false; - } - else if (nary == 1) - { - if (op.getCode() == ogp::code_t::UMINUS) - return false; - else - return true; - } - else - { - if (op.getCode() == ogp::code_t::TIMES) - // if at least one operand is constant, than the TIMES is linear - if (model.is_constant_term(op.getOp1()) - || model.is_constant_term(op.getOp2())) - return false; - else - return true; - // both PLUS and MINUS are linear - if (op.getCode() == ogp::code_t::PLUS - || op.getCode() == ogp::code_t::MINUS) - return false; - // POWER is linear if exponent or base is 0 or one - if (op.getCode() == ogp::code_t::POWER - && (op.getOp1() == ogp::OperationTree::zero - || op.getOp1() == ogp::OperationTree::one - || op.getOp2() == ogp::OperationTree::zero - || op.getOp2() == ogp::OperationTree::one)) - return false; - else - return true; - /* DIVIDE is linear if the denominator is constant, or if the nominator - is zero */ - if (op.getCode() == ogp::code_t::DIVIDE - && (op.getOp1() == ogp::OperationTree::zero - || model.is_constant_term(op.getOp2()))) - return false; - else - return true; - } - - throw DynareException(__FILE__, __LINE__, - "Wrong operation in operation tree"); - return false; -} - -DynareSPModel::DynareSPModel(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const string &equations, - int ord) - : DynareModel() -{ - // set the order - order = ord; - - // add names - for (const auto &it : endo) - add_name(it, 1); - for (const auto &it : exo) - add_name(it, 2); - for (const auto &it : par) - add_name(it, 3); - - // parse the equations - eqs.parse(equations); - - // parsing finished - atoms.parsing_finished(ogp::VarOrdering::bfspbfpb); - - // create what has to be created from DynareModel - param_vals = std::make_unique<Vector>(atoms.np()); - init_vals = std::make_unique<Vector>(atoms.ny()); - vcov_mat = std::make_unique<TwoDMatrix>(atoms.nexo(), atoms.nexo()); - - // check the model - check_model(); - - // differentiate - if (order >= 1) - eqs.differentiate(order); -} - -void -ModelSSWriter::write_der0(std::ostream &os) -{ - write_der0_preamble(os); - write_atom_assignment(os); - - stop_set.clear(); - for (int fi = 0; fi < model.eqs.nformulas(); fi++) - otree.print_operation_tree(model.eqs.formula(fi), os, *this); - - write_der0_assignment(os); -} - -void -ModelSSWriter::write_der1(std::ostream &os) -{ - write_der1_preamble(os); - write_atom_assignment(os); - - stop_set.clear(); - - const vector<int> &variables = model.getAtoms().variables(); - const vector<int> &eam = model.getAtoms().get_endo_atoms_map(); - for (int i = 0; i < model.getParser().nformulas(); i++) - { - const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i); - for (int j : eam) - { - int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, j)); - if (t > 0) - otree.print_operation_tree(t, os, *this); - } - } - - write_der1_assignment(os); -} - -MatlabSSWriter::MatlabSSWriter(const DynareModel &dm, std::string id_arg) - : ModelSSWriter(dm), id(std::move(id_arg)) -{ -} - -void -MatlabSSWriter::write_der0_preamble(std::ostream &os) const -{ - os << "% Usage:\n" - << "% out = " << id << "_f(params, y)\n" - << "% where\n" - << "% out is a (" << model.getAtoms().ny() << ",1) column vector of the residuals\n" - << "% of the static system\n"; - write_common1_preamble(os); - os << "function out = " << id << "_f(params, y)\n"; - write_common2_preamble(os); -} - -void -MatlabSSWriter::write_der1_preamble(std::ostream &os) const -{ - os << "% Usage:\n" - << "% out = " << id << "_ff(params, y)\n" - << "% where\n" - << "% out is a (" << model.getAtoms().ny() << "," << model.getAtoms().ny() << ") matrix of the first order\n" - << "% derivatives of the static system residuals\n" - << "% columns correspond to endo variables in\n" - << "% the ordering as declared\n"; - write_common1_preamble(os); - os << "function out = " << id << "_ff(params, y)\n"; - write_common2_preamble(os); -} - -void -MatlabSSWriter::write_common1_preamble(std::ostream &os) const -{ - os << "% params is a (" << model.getAtoms().np() << ",1) vector of parameter values\n" - << "% in the ordering as declared\n" - << "% y is a (" << model.getAtoms().ny() << ",1) vector of endogenous variables\n" - << "% in the ordering as declared\n" - << "%\n" - << "% Created by Dynare++ v. " << VERSION << "\n"; - // write ordering of parameters - os << "\n% params ordering\n% =====================\n"; - for (auto parname : model.getAtoms().get_params()) - os << "% " << parname << "\n"; - - // write endogenous variables - os << "%\n% y ordering\n% =====================\n"; - for (auto endoname : model.getAtoms().get_endovars()) - os << "% " << endoname << "\n"; - os << "\n"; -} - -void -MatlabSSWriter::write_common2_preamble(std::ostream &os) const -{ - os << "if size(y) ~= [" << model.getAtoms().ny() << ",1]\n" - << "\terror('Wrong size of y, must be [" << model.getAtoms().ny() << ",1]');\nend\n" - << "if size(params) ~= [" << model.getAtoms().np() << ",1]\n" - << "\terror('Wrong size of params, must be [" << model.getAtoms().np() << ",1]');\nend\n\n"; -} - -void -MatlabSSWriter::write_atom_assignment(std::ostream &os) const -{ - // write OperationTree::num_constants - os << "% hardwired constants\n"; - ogp::EvalTree etree(model.getParser().getTree(), ogp::OperationTree::num_constants-1); - for (int i = 0; i < ogp::OperationTree::num_constants; i++) - { - format_nulary(i, os); - double g = etree.eval(i); - if (std::isnan(g)) - os << " = NaN;\n"; - else - os << " = " << std::defaultfloat << std::setprecision(8) << etree.eval(i) << ";\n"; - } - // write numerical constants - os << "% numerical constants\n"; - const ogp::Constants::Tconstantmap &cmap = model.getAtoms().get_constantmap(); - for (auto it : cmap) - { - format_nulary(it.first, os); - os << " = " << std::defaultfloat << std::setprecision(8) << it.second << ";\n"; - } - // write parameters - os << "% parameter values\n"; - for (unsigned int ip = 0; ip < model.getAtoms().get_params().size(); ip++) - { - const string &parname = model.getAtoms().get_params()[ip]; - int t = model.getAtoms().index(parname, 0); - if (t == -1) - os << "% " << parname << " not used in the model\n"; - else - { - format_nulary(t, os); - os << " = params(" << ip+1 << "); % " << parname << "\n"; - } - } - // write exogenous variables - os << "% exogenous variables to zeros\n"; - for (unsigned int ie = 0; ie < model.getAtoms().get_exovars().size(); ie++) - { - const string &exoname = model.getAtoms().get_exovars()[ie]; - try - { - const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(exoname); - for (auto it : lmap) - { - format_nulary(it.second, os); - os << " = 0.0; % " << exoname << "\n"; - } - } - catch (const ogu::Exception &e) - { - // ignore the error of not found variable in the tree - } - } - // write endogenous variables - os << "% endogenous variables to y\n"; - for (unsigned int ie = 0; ie < model.getAtoms().get_endovars().size(); ie++) - { - const string &endoname = model.getAtoms().get_endovars()[ie]; - const ogp::DynamicAtoms::Tlagmap &lmap = model.getAtoms().lagmap(endoname); - for (auto it : lmap) - { - format_nulary(it.second, os); - os << " = y(" << ie+1 << "); % " << endoname << "\n"; - } - } - os << "\n"; -} - -void -MatlabSSWriter::write_der0_assignment(std::ostream &os) const -{ - - // initialize out variable - os << "% setting the output variable\n" - << "out = zeros(" << model.getParser().nformulas() << ", 1);\n"; - - // fill out with the terms - for (int i = 0; i < model.getParser().nformulas(); i++) - { - os << "out(" << i+1 << ") = "; - format_term(model.getParser().formula(i), os); - os << ";\n"; - } -} - -void -MatlabSSWriter::write_der1_assignment(std::ostream &os) const -{ - // initialize out variable - os << "% setting the output variable\n"; - os << "out = zeros(" << model.getParser().nformulas() << ", " << model.getAtoms().ny() << ");\n"; - - // fill out with the terms - const vector<int> &variables = model.getAtoms().variables(); - const vector<int> &eam = model.getAtoms().get_endo_atoms_map(); - for (int i = 0; i < model.getParser().nformulas(); i++) - { - const ogp::FormulaDerivatives &fder = model.getParser().derivatives(i); - for (int j : eam) - { - int tvar = variables[j]; - const string &name = model.getAtoms().name(tvar); - int yi = model.getAtoms().name2outer_endo(name); - int t = fder.derivative(ogp::FoldMultiIndex(variables.size(), 1, j)); - if (t != ogp::OperationTree::zero) - { - os << "out(" << i+1 << "," << yi+1 << ") = out("<< i+1 << "," << yi+1 << ") + "; - format_term(t, os); - os << "; % " << name << "(" << model.getAtoms().lead(tvar) << ")\n"; - } - } - } -} - -void -MatlabSSWriter::format_term(int t, std::ostream &os) const -{ - os << 't' << t; -} - -void -MatlabSSWriter::format_nulary(int t, std::ostream &os) const -{ - os << 'a' << t; -} - -void -DebugOperationFormatter::format_nulary(int t, std::ostream &os) const -{ - const DynareDynamicAtoms &a = model.getAtoms(); - - if (t == ogp::OperationTree::zero) - os << '0'; - else if (t == ogp::OperationTree::one) - os << '1'; - else if (t == ogp::OperationTree::nan) - os << "NaN"; - else if (t == ogp::OperationTree::two_over_pi) - os << "2/sqrt(PI)"; - else if (a.is_constant(t)) - os << a.get_constant_value(t); - else - { - int ll = a.lead(t); - const std::string &name = a.name(t); - if (ll == 0) - os << name; - else - os << name << '(' << ll << ')'; - } -} diff --git a/dynare++/src/dynare_model.hh b/dynare++/src/dynare_model.hh deleted file mode 100644 index a4498d9dea8dd735280bc5589fe0ba4a46ea633d..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_model.hh +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright © 2005-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef OGDYN_DYNARE_MODEL -#define OGDYN_DYNARE_MODEL - -#include "parser/cc/matrix_parser.hh" -#include "parser/cc/atom_assignings.hh" - -#include "dynare_atoms.hh" -#include "twod_matrix.hh" -#include "planner_builder.hh" -#include "forw_subst_builder.hh" - -#include "Vector.hh" -#include "GeneralMatrix.hh" - -#include <map> -#include <unordered_set> -#include <ostream> -#include <memory> -#include <iostream> - -namespace ogdyn -{ - using std::unordered_set; - using std::map; - - /* This represents an interval in a string by the pair of positions - (including the first, excluding the second). A position is given by the - line and the column within the line (both starting from 1). */ - struct PosInterval - { - int fl; - int fc; - int ll; - int lc; - PosInterval() = default; - PosInterval(int ifl, int ifc, int ill, int ilc) - : fl(ifl), fc(ifc), ll(ill), lc(ilc) - { - } - PosInterval &operator=(const PosInterval &pi) = default; - /* Debug print. */ - void - print() const - { - std::cout << "fl=" << fl << " fc=" << fc << " ll=" << ll << " lc=" << lc << '\n'; - } - }; - - /* This class is basically a GeneralMatrix but is created from parsed matrix - data. */ - class ParsedMatrix : public TwoDMatrix - { - public: - /* Construct the object from the parsed data of ogp::MatrixParser. */ - ParsedMatrix(const ogp::MatrixParser &mp); - }; - - class PlannerBuilder; - class PlannerInfo; - class ForwSubstBuilder; - class ForwSubstInfo; - class MultInitSS; - class ModelSSWriter; - - /* A subclass is responsible for creating param_vals, init_vals, and - vcov_mat. */ - class DynareModel - { - friend class PlannerBuilder; - friend class ForwSubstBuilder; - friend class MultInitSS; - friend class ModelSSWriter; - protected: - /* All atoms for whole model. */ - DynareDynamicAtoms atoms; - /* Parsed model equations. */ - ogp::FormulaParser eqs; - /* Order of approximation. */ - int order{-1}; - /* A vector of parameters values created by a subclass. It is stored with - natural ordering (outer) of the parameters given by atoms. */ - std::unique_ptr<Vector> param_vals; - /* A vector of initial values created by a subclass. It is stored with - internal ordering given by atoms. */ - std::unique_ptr<Vector> init_vals; - /* A matrix for vcov. It is created by a subclass. */ - std::unique_ptr<TwoDMatrix> vcov_mat; - /* Tree index of the planner objective. If there was no planner objective - keyword, the value is set to −1. */ - int t_plobjective{-1}; - /* Tree index of the planner discount. If there was no planner discount - keyword, the value is set to −1. */ - int t_pldiscount{-1}; - /* Pointer to PlannerBuilder, which is created only if the planner's FOC - are added to the model. */ - std::unique_ptr<PlannerBuilder> pbuilder; - /* Pointer to an object which builds auxiliary variables and equations to - rewrite a model containing multiple leads to an equivalent model having - only +1 leads. */ - std::unique_ptr<ForwSubstBuilder> fbuilder; - /* Pointer to AtomSubstitutions which are created when the atoms are being - substituted because of multiple lags etc. It uses also an old copy of - atoms, which is created. */ - std::unique_ptr<ogp::AtomSubstitutions> atom_substs; - /* Pointer to a copy of original atoms before substitutions took place. */ - std::unique_ptr<ogp::SAtoms> old_atoms; - public: - /* Initializes the object to an empty state. */ - DynareModel(); - /* Construct a new deep copy. */ - DynareModel(const DynareModel &dm); - virtual ~DynareModel() = default; - virtual std::unique_ptr<DynareModel> clone() const = 0; - const DynareDynamicAtoms & - getAtoms() const - { - return atoms; - } - const ogp::FormulaParser & - getParser() const - { - return eqs; - } - int - getOrder() const - { - return order; - } - /* Return the vector of parameter values. */ - const Vector & - getParams() const - { - return *param_vals; - } - Vector & - getParams() - { - return *param_vals; - } - /* Return the vector of initial values of endo variables. */ - const Vector & - getInit() const - { - return *init_vals; - } - Vector & - getInit() - { - return *init_vals; - } - /* Return the vcov matrix. */ - const TwoDMatrix & - getVcov() const - { - return *vcov_mat; - } - TwoDMatrix & - getVcov() - { - return *vcov_mat; - } - /* Return planner info. */ - const PlannerInfo *get_planner_info() const; - /* Return forward substitutions info. */ - const ForwSubstInfo *get_forw_subst_info() const; - /* Return substitutions info. */ - const ogp::SubstInfo *get_subst_info() const; - /* This sets initial values given in outer ordering. */ - void setInitOuter(const Vector &x); - /* This returns true if the given term is a function of hardwired - constants, numerical constants and parameters. */ - bool is_constant_term(int t) const; - /* Debug print. */ - void print() const; - /* Dump the model to the output stream. This includes variable - declarations, parameter values, model code, initval, vcov and order. */ - void dump_model(std::ostream &os) const; - protected: - /* Adds a name of endogenous, exogenous or a parameter. The sort is - governed by the flag. See dynglob.yy for values of the flag. This is - used by a subclass when declaring the names. */ - void add_name(std::string name, int flag); - /* This checks the model consistency. Thus includes: number of endo - variables and number of equations, min and max lag of endogenous - variables and occurrrences of exogenous variables. It throws an - exception, if there is a problem. */ - void check_model() const; - /* This shifts the given variable identified by the tree index in time. So - if the given tree index represents a(+3) and the tshift is −4, the - method returns tree index of the a(-1). If a(-1) doesn't exist, it is - added to the tree. If it exists, its tree index is returned. If the tree - index doesn't correspond to an endogenous nor exogenous variable, an - exception is thrown. */ - int variable_shift(int t, int tshift); - /* For the given set of atoms identified by tree indices and given time - shift, this method returns a map mapping each variable in the given set - to its time shifted variable. The map is passed through the reference - and is cleared in the beginning. */ - void variable_shift_map(const unordered_set<int> &a_set, int tshift, - map<int, int> &s_map); - /* This returns maximum lead and minimum lag of an endogenous or exogenous - variable in the given term. If there are no endo or exo variables, than - it returns the least integer as max lead and the greatest integer as min - lag. */ - void termspan(int t, int &mlead, int &mlag) const; - /* This function returns a set of non-linear subterms of the given term, - these are terms whose linear combination constitutes the given term. */ - unordered_set<int> get_nonlinear_subterms(int t) const; - /* This method assigns already used tree index of some term to the not-yet - used atom name with the given lead/lag. In this way, all occurrences of - term t are substituted with the atom name(ll). The method handles also - rewriting operation tree including derivatives of the term t. */ - void substitute_atom_for_term(const string &name, int ll, int t); - /* This performs a final job after the model is parsed. It creates the - PlannerBuilder object if the planner's FOC are needed, then it creates - ForwSubstBuilder handling multiple leads and finally it creates the - substitution object saving old atoms and performs the substitutions. */ - void final_job(); - }; - - /* This class constructs DynareModel from dynare++ model file. It parses - variable declarations, model equations, parameter assignments, initval - assignments, vcov matrix and order of approximation. */ - class DynareParser : public DynareModel - { - protected: - /* Static atoms for parameter assignments. */ - DynareStaticAtoms pa_atoms; - /* Assignments for the parameters. */ - ogp::AtomAssignings paramset; - /* Static atoms for initval assignments. */ - DynareStaticAtoms ia_atoms; - /* Assignments for the initval. */ - ogp::AtomAssignings initval; - /* Matrix parser for vcov. */ - ogp::MatrixParser vcov; - public: - /* This, in fact, creates DynareModel from the given string of the given - length corresponding to the Dynare++ model file. If the given ord is not - −1, then it overrides setting in the model file. */ - DynareParser(const string &str, int ord); - DynareParser(const DynareParser &dp); - std::unique_ptr<DynareModel> - clone() const override - { - return std::make_unique<DynareParser>(*this); - } - /* Adds a name of endogenous, exogenous or a parameter. This addss the name - to the parent class DynareModel and also registers the name to either - paramset, or initval. */ - void add_name(string name, int flag); - /* Sets position of the model section. Called from dynglob.yy. */ - void - set_model_pos(int off1, int off2) - { - model_beg = off1; - model_end = off2; - } - /* Sets position of the section setting parameters. Called from - dynglob.yy. */ - void - set_paramset_pos(int off1, int off2) - { - paramset_beg = off1; - paramset_end = off2; - } - /* Sets position of the initval section. Called from dynglob.yy. */ - void - set_initval_pos(int off1, int off2) - { - initval_beg = off1; - initval_end = off2; - } - /* Sets position of the vcov section. Called from dynglob.yy. */ - void - set_vcov_pos(int off1, int off2) - { - vcov_beg = off1; - vcov_end = off2; - } - /* Parser the given string as integer and set to as the order. */ - void - set_order_pos(int off1, int off2) - { - order_beg = off1; - order_end = off2; - } - /* Sets position of the planner_objective section. Called from - dynglob.yy. */ - void - set_pl_objective_pos(int off1, int off2) - { - plobjective_beg = off1; - plobjective_end = off2; - } - /* Sets position of the planner_discount section. Called from - dynglob.yy. */ - void - set_pl_discount_pos(int off1, int off2) - { - pldiscount_beg = off1; - pldiscount_end = off2; - } - /* Processes a syntax error from bison. */ - void error(string mes); - /* Debug print. */ - void print() const; - protected: - void parse_glob(const string &stream); - int parse_order(const string &stream); - int parse_pldiscount(const string &stream); - /* Evaluate paramset assignings and set param_vals. */ - void calc_params(); - /* Evaluate initval assignings and set init_vals. */ - void calc_init(); - /* Do the final job. This includes building the planner problem (if any) - and substituting for multiple lags, and one period leads of exogenous - variables, and calculating initial guess of lagrange multipliers in the - social planner problem. Precondtion: everything parsed and calculated - parameters, postcondition: calculated initvals vector and - parsing_finished for expanded vectors. */ - void final_job(); - private: - int model_beg, model_end; - int paramset_beg, paramset_end; - int initval_beg, initval_end; - int vcov_beg, vcov_end; - int order_beg, order_end; - int plobjective_beg, plobjective_end; - int pldiscount_beg, pldiscount_end; - }; - - /* Semiparsed model. The equations are given by a string, everything other by - C++ objects. The initial values are set manually after the creation of - this object. This implies that no automatic substitutions cannot be done - here, which in turn implies that we cannot do here a social planner nor - substitutions of multiple lags. */ - class DynareSPModel : public DynareModel - { - public: - DynareSPModel(const std::vector<std::string> &endo, - const std::vector<std::string> &exo, - const std::vector<std::string> &par, - const string &equations, int ord); - DynareSPModel(const DynareSPModel &dm) = default; - ~DynareSPModel() override = default; - std::unique_ptr<DynareModel> - clone() const override - { - return std::make_unique<DynareSPModel>(*this); - } - }; - - /* This class implements a selector of operations which correspond to - non-linear functions. This inherits from ogp::opselector and is used to - calculate non-linear subterms in DynareModel::get_nonlinear_subterms(). */ - class NLSelector : public ogp::opselector - { - private: - const DynareModel &model; - public: - NLSelector(const DynareModel &m) : model(m) - { - } - bool operator()(int t) const override; - }; - - /* This class writes a mathematical code evaluating the system of equations - and the first derivatives at zero shocks and at the given (static) state. - Static means that lags and leads are ignored. */ - class ModelSSWriter : public ogp::DefaultOperationFormatter - { - protected: - const DynareModel &model; - public: - ModelSSWriter(const DynareModel &m) - : DefaultOperationFormatter(m.eqs.getTree()), - model(m) - { - } - /* This writes the evaluation of the system. It calls pure virtual methods - for writing a preamble, then assignment of atoms, and then assignment - for resulting object. These are language dependent and are implemented - in the subclass. */ - void write_der0(std::ostream &os); - /* This writes the evaluation of the first order derivative of the system. - It calls pure virtual methods for writing a preamble, assignment, and - assignemnt of the resulting objects. */ - void write_der1(std::ostream &os); - protected: - virtual void write_der0_preamble(std::ostream &os) const = 0; - virtual void write_der1_preamble(std::ostream &os) const = 0; - virtual void write_atom_assignment(std::ostream &os) const = 0; - virtual void write_der0_assignment(std::ostream &os) const = 0; - virtual void write_der1_assignment(std::ostream &os) const = 0; - }; - - class MatlabSSWriter : public ModelSSWriter - { - protected: - /* Identifier used in function names. */ - std::string id; - public: - MatlabSSWriter(const DynareModel &dm, std::string id_arg); - protected: - // from ModelSSWriter - void write_der0_preamble(std::ostream &os) const override; - void write_der1_preamble(std::ostream &os) const override; - /* This writes atom assignments. We have four kinds of atoms set here: - endogenous vars coming from one parameter, parameter values given by the - second parameter, constants, and the OperationTree::num_constants - hardwired constants in ogp::OperationTree. */ - void write_atom_assignment(std::ostream &os) const override; - void write_der0_assignment(std::ostream &os) const override; - void write_der1_assignment(std::ostream &os) const override; - /* This prints t10 for t=10. */ - void format_term(int t, std::ostream &os) const override; - /* This prints a10 for t=10. The atoms a10 are supposed to be set by - write_atom_assignments(). */ - void format_nulary(int t, std::ostream &os) const override; - private: - void write_common1_preamble(std::ostream &os) const; - void write_common2_preamble(std::ostream &os) const; - }; - - /* This class implements OperationFormatter for debugging purposes. It - renders atoms in a more friendly way than the - ogp::DefaulOperationFormatter. */ - class DebugOperationFormatter : public ogp::DefaultOperationFormatter - { - protected: - const DynareModel &model; - public: - DebugOperationFormatter(const DynareModel &m) - : DefaultOperationFormatter(m.getParser().getTree()), - model(m) - { - } - void format_nulary(int t, std::ostream &os) const override; - }; -}; - -#endif diff --git a/dynare++/src/dynare_params.cc b/dynare++/src/dynare_params.cc deleted file mode 100644 index 3679ecf381404ec6e513389790c44ca50726971d..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_params.cc +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "dynare_params.hh" - -#include "sthread.hh" - -#include <getopt.h> -#include <string> -#include <iostream> - -DynareParams::DynareParams(int argc, char **argv) - : num_per(100), num_burn(0), num_sim(80), - num_rtper(0), num_rtsim(0), - num_condper(0), num_condsim(0), - num_threads(sthread::default_threads_number()), num_steps(0), - prefix("dyn"), seed(934098), order(-1), ss_tol(1.e-13), - check_along_path(false), check_along_shocks(false), - check_on_ellipse(false), check_evals(1000), check_num(10), check_scale(2.0), - do_irfs_all(true), do_centralize(true), qz_criterium(1.0+1e-6), - help(false), version(false) -{ - using namespace std::string_literals; - if (argc == 1 || argv[1] == "--help"s) - { - help = true; - return; - } - if (argc == 1 || argv[1] == "--version"s) - { - version = true; - return; - } - - modname = argv[argc-1]; - argc--; - - struct option const opts[] = - { - {"periods", required_argument, nullptr, static_cast<int>(opt::per)}, - {"per", required_argument, nullptr, static_cast<int>(opt::per)}, - {"burn", required_argument, nullptr, static_cast<int>(opt::burn)}, - {"simulations", required_argument, nullptr, static_cast<int>(opt::sim)}, - {"sim", required_argument, nullptr, static_cast<int>(opt::sim)}, - {"rtperiods", required_argument, nullptr, static_cast<int>(opt::rtper)}, - {"rtper", required_argument, nullptr, static_cast<int>(opt::rtper)}, - {"rtsimulations", required_argument, nullptr, static_cast<int>(opt::rtsim)}, - {"rtsim", required_argument, nullptr, static_cast<int>(opt::rtsim)}, - {"condperiods", required_argument, nullptr, static_cast<int>(opt::condper)}, - {"condper", required_argument, nullptr, static_cast<int>(opt::condper)}, - {"condsimulations", required_argument, nullptr, static_cast<int>(opt::condsim)}, - {"condsim", required_argument, nullptr, static_cast<int>(opt::condsim)}, - {"prefix", required_argument, nullptr, static_cast<int>(opt::prefix)}, - {"threads", required_argument, nullptr, static_cast<int>(opt::threads)}, - {"steps", required_argument, nullptr, static_cast<int>(opt::steps)}, - {"seed", required_argument, nullptr, static_cast<int>(opt::seed)}, - {"order", required_argument, nullptr, static_cast<int>(opt::order)}, - {"ss-tol", required_argument, nullptr, static_cast<int>(opt::ss_tol)}, - {"check", required_argument, nullptr, static_cast<int>(opt::check)}, - {"check-scale", required_argument, nullptr, static_cast<int>(opt::check_scale)}, - {"check-evals", required_argument, nullptr, static_cast<int>(opt::check_evals)}, - {"check-num", required_argument, nullptr, static_cast<int>(opt::check_num)}, - {"qz-criterium", required_argument, nullptr, static_cast<int>(opt::qz_criterium)}, - {"no-irfs", no_argument, nullptr, static_cast<int>(opt::noirfs)}, - {"irfs", no_argument, nullptr, static_cast<int>(opt::irfs)}, - {"centralize", no_argument, nullptr, static_cast<int>(opt::centralize)}, - {"no-centralize", no_argument, nullptr, static_cast<int>(opt::no_centralize)}, - {"help", no_argument, nullptr, static_cast<int>(opt::help)}, - {"version", no_argument, nullptr, static_cast<int>(opt::version)}, - {nullptr, 0, nullptr, 0} - }; - - int ret; - int index; - while (-1 != (ret = getopt_long(argc, argv, "", opts, &index))) - { - if (ret == '?') - { - std::cerr << "Unknown option, ignored\n"; - continue; - } - - try - { - switch (static_cast<opt>(ret)) - { - case opt::per: - num_per = std::stoi(optarg); - break; - case opt::burn: - num_burn = std::stoi(optarg); - break; - case opt::sim: - num_sim = std::stoi(optarg); - break; - case opt::rtper: - num_rtper = std::stoi(optarg); - break; - case opt::rtsim: - num_rtsim = std::stoi(optarg); - break; - case opt::condper: - num_condper = std::stoi(optarg); - break; - case opt::condsim: - num_condsim = std::stoi(optarg); - break; - case opt::prefix: - prefix = optarg; - break; - case opt::threads: - num_threads = std::stoi(optarg); - break; - case opt::steps: - num_steps = std::stoi(optarg); - break; - case opt::seed: - seed = std::stoi(optarg); - break; - case opt::order: - order = std::stoi(optarg); - break; - case opt::ss_tol: - ss_tol = std::stod(optarg); - break; - case opt::check: - processCheckFlags(optarg); - break; - case opt::check_scale: - check_scale = std::stod(optarg); - break; - case opt::check_evals: - check_evals = std::stoi(optarg); - break; - case opt::check_num: - check_num = std::stoi(optarg); - break; - case opt::noirfs: - irf_list.clear(); - do_irfs_all = false; - break; - case opt::irfs: - processIRFList(argc, argv); - if (irf_list.empty()) - do_irfs_all = true; - else - do_irfs_all = false; - break; - case opt::centralize: - do_centralize = true; - break; - case opt::no_centralize: - do_centralize = false; - break; - case opt::qz_criterium: - qz_criterium = std::stod(optarg); - break; - case opt::help: - help = true; - break; - case opt::version: - version = true; - break; - } - } - catch (std::invalid_argument &) - { - std::cerr << "Couldn't parse option " << optarg << ", ignored\n"; - } - catch (std::out_of_range &) - { - std::cerr << "Out-of-range value " << optarg << ", ignored\n"; - } - } - - // make basename (get rid of the directory and the extension) - basename = modname; - auto pos = basename.find_last_of(R"(/\)"); - if (pos != std::string::npos) - basename = basename.substr(pos+1); - pos = basename.find_last_of('.'); - if (pos != std::string::npos) - basename.erase(pos); -} - -void -DynareParams::printHelp() const -{ - std::cout << "usage: dynare++ [--help] [--version] [options] <model file>\n" - "\n" - " --help print this message and return\n" - " --version print version and return\n" - "\n" - "options:\n" - " --per <num> number of periods simulated after burnt [100]\n" - " --burn <num> number of periods burnt [0]\n" - " --sim <num> number of simulations [80]\n" - " --rtper <num> number of RT periods simulated after burnt [0]\n" - " --rtsim <num> number of RT simulations [0]\n" - " --condper <num> number of periods in cond. simulations [0]\n" - " --condsim <num> number of conditional simulations [0]\n" - " --steps <num> steps towards stoch. SS [0=deter.]\n" - " --centralize centralize the rule [do centralize]\n" - " --no-centralize do not centralize the rule [do centralize]\n" - " --prefix <string> prefix of variables in Mat-4 file [\"dyn\"]\n" - " --seed <num> random number generator seed [934098]\n" - " --order <num> order of approximation [no default]\n" - " --threads <num> number of max parallel threads [1/2 * nb. of logical CPUs]\n" - " --ss-tol <num> steady state calcs tolerance [1.e-13]\n" - " --check pesPES check model residuals [no checks]\n" - " lower/upper case switches off/on\n" - " pP checking along simulation path\n" - " eE checking on ellipse\n" - " sS checking along shocks\n" - " --check-evals <num> max number of evals per residual [1000]\n" - " --check-num <num> number of checked points [10]\n" - " --check-scale <num> scaling of checked points [2.0]\n" - " --no-irfs shuts down IRF simulations [do IRFs]\n" - " --irfs performs IRF simulations [do IRFs]\n" - " --qz-criterium <num> threshold for stable eigenvalues [1.000001]\n" - "\n\n"; -} - -void -DynareParams::processCheckFlags(const std::string &flags) -{ - for (char c : flags) - switch (c) - { - case 'p': - check_along_path = false; - break; - case 'P': - check_along_path = true; - break; - case 'e': - check_on_ellipse = false; - break; - case 'E': - check_on_ellipse = true; - break; - case 's': - check_along_shocks = false; - break; - case 'S': - check_along_shocks = true; - break; - default: - std::cerr << "Unknown check type selection character <" << c << ">, ignored.\n"; - } -} - -void -DynareParams::processIRFList(int argc, char **argv) -{ - irf_list.clear(); - while (optind < argc && *(argv[optind]) != '-') - { - irf_list.push_back(argv[optind]); - optind++; - } -} diff --git a/dynare++/src/dynare_params.hh b/dynare++/src/dynare_params.hh deleted file mode 100644 index 91363356ec5c5eb7eda786b230f813ae3074c8b0..0000000000000000000000000000000000000000 --- a/dynare++/src/dynare_params.hh +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2004 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -/* - along shocks: m mult max_evals - ellipse: m mult max_evals (10·m) (0.5·mult) - simul: m max_evals (10·m) - - --check-scale 2.0 --check-evals 1000 --check-num 10 --check PES -*/ - -#include <vector> -#include <string> - -struct DynareParams -{ - std::string modname; - std::string basename; - int num_per; - int num_burn; - int num_sim; - int num_rtper; - int num_rtsim; - int num_condper; - int num_condsim; - int num_threads; - int num_steps; - std::string prefix; - int seed; - int order; - /* Tolerance used for steady state calcs. */ - double ss_tol; - bool check_along_path; - bool check_along_shocks; - bool check_on_ellipse; - int check_evals; - int check_num; - double check_scale; - /* Flag for doing IRFs even if the irf_list is empty. */ - bool do_irfs_all; - /* List of shocks for which IRF will be calculated. */ - std::vector<std::string> irf_list; - bool do_centralize; - double qz_criterium; - bool help; - bool version; - DynareParams(int argc, char **argv); - void printHelp() const; - int - getCheckShockPoints() const - { - return check_num; - } - double - getCheckShockScale() const - { - return check_scale; - } - int - getCheckEllipsePoints() const - { - return 10*check_num; - } - double - getCheckEllipseScale() const - { - return 0.5*check_scale; - } - int - getCheckPathPoints() const - { - return 10*check_num; - } -private: - enum class opt { per, burn, sim, rtper, rtsim, condper, condsim, - prefix, threads, - steps, seed, order, ss_tol, check, - check_evals, check_scale, check_num, noirfs, irfs, - help, version, centralize, no_centralize, qz_criterium }; - void processCheckFlags(const std::string &flags); - /* This gathers strings from argv[optind] and on not starting with '-' to the - irf_list. It stops one item before the end, since this is the model - file. */ - void processIRFList(int argc, char **argv); -}; diff --git a/dynare++/src/dynglob.ll b/dynare++/src/dynglob.ll deleted file mode 100644 index cbb0341b9f56ebb82c2e1b3b051961908551e0ea..0000000000000000000000000000000000000000 --- a/dynare++/src/dynglob.ll +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- C++ -*- */ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ -%{ -#include "parser/cc/location.hh" -#include "dynglob_tab.hh" - -#define YY_USER_ACTION SET_LLOC(dynglob_); -%} - -%option nounput -%option noyy_top_state -%option stack -%option yylineno -%option prefix="dynglob_" -%option never-interactive -%x CMT - -%% - - /* comments */ -<*>"/*" {yy_push_state(CMT);} -<CMT>[^*\n]* -<CMT>"*"+[^*/\n]* -<CMT>"*"+"/" {yy_pop_state();} -<CMT>[\n] -"//".*\n - - /* initial spaces or tabs are ignored */ - -[ \t\r\n\0] -var {return VAR;} -varexo {return VAREXO;} -parameters {return PARAMETERS;} -model {return MODEL;} -end {return END;} -initval {return INITVAL;} -order {return ORDER;} -vcov {return VCOV;} -planner_objective {return PLANNEROBJECTIVE;} -planner_discount {return PLANNERDISCOUNT;} - - /* names */ -[A-Za-z_][A-Za-z0-9_]* { - dynglob_lval.string = dynglob_text; - return NAME; -} - -; {return SEMICOLON;} -, {return COMMA;} -= {return EQUAL_SIGN;} -\[ {return LEFT_BRACKET;} -\] {return RIGHT_BRACKET;} -. { - dynglob_lval.character = dynglob_text[0]; - return CHARACTER; -} - -%% - -int -dynglob_wrap() -{ - return 1; -} - -void -dynglob__destroy_buffer(void* p) -{ - dynglob__delete_buffer(static_cast<YY_BUFFER_STATE>(p)); -} diff --git a/dynare++/src/dynglob.yy b/dynare++/src/dynglob.yy deleted file mode 100644 index dac74dc8c980af795ec3d7805109b545300a6acb..0000000000000000000000000000000000000000 --- a/dynare++/src/dynglob.yy +++ /dev/null @@ -1,135 +0,0 @@ -// -*- C++ -*- -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -%code requires -{ -#include "parser/cc/location.hh" -#define DYNGLOB_LTYPE ogp::location_type -} - -%code -{ -#include <string> - -#include "dynare_model.hh" - -void dynglob_error(std::string); -int dynglob_lex(); -extern ogdyn::DynareParser* dynare_parser; -int symblist_flag; -} - -%union -{ - int integer; - char *string; - char character; -} - -%token END INITVAL MODEL PARAMETERS VAR VAREXO SEMICOLON COMMA EQUAL_SIGN CHARACTER -%token VCOV LEFT_BRACKET RIGHT_BRACKET ORDER PLANNEROBJECTIVE PLANNERDISCOUNT -%token <string> NAME; - -%define api.prefix {dynglob_} - -%locations -%defines -%define parse.error verbose - -%% - -dynare_file : preamble paramset model rest { - dynare_parser->set_paramset_pos(@2.off, @3.off);} - | preamble model rest { - dynare_parser->set_paramset_pos(0, 0);} - | preamble paramset planner model rest { - dynare_parser->set_paramset_pos(@2.off, @3.off);} - ; - -preamble : preamble preamble_statement | preamble_statement; - -preamble_statement : var | varexo | parameters; - -var : VAR {symblist_flag=1;} symblist SEMICOLON; - -varexo : VAREXO {symblist_flag=2;} symblist SEMICOLON; - -parameters : PARAMETERS {symblist_flag=3;} symblist SEMICOLON; - - -symblist : symblist NAME {dynare_parser->add_name($2,symblist_flag);} - | symblist COMMA NAME {dynare_parser->add_name($3,symblist_flag);} - | NAME {dynare_parser->add_name($1,symblist_flag);} - ; - -paramset : recnameset; - -recnameset : recnameset onenameset | onenameset; - -onenameset : NAME EQUAL_SIGN material SEMICOLON; - -material : material CHARACTER | material NAME | NAME | CHARACTER; - -model : MODEL SEMICOLON equations END SEMICOLON { - dynare_parser->set_model_pos(@3.off, @4.off); -}; - -equations : equations equation | equation; - -equation : material EQUAL_SIGN material SEMICOLON | material SEMICOLON; - -rest : rest_statement | rest rest_statement; - -rest_statement : initval | vcov | order | planner; - -initval : INITVAL SEMICOLON recnameset END SEMICOLON { - dynare_parser->set_initval_pos(@3.off, @4.off); -}; - -vcov : VCOV EQUAL_SIGN LEFT_BRACKET m_material RIGHT_BRACKET SEMICOLON { - dynare_parser->set_vcov_pos(@4.off, @5.off); -}; - -m_material : m_material CHARACTER | m_material NAME | m_material SEMICOLON | m_material COMMA | CHARACTER | NAME | SEMICOLON | COMMA; - -order : ORDER EQUAL_SIGN material SEMICOLON { - dynare_parser->set_order_pos(@3.off, @4.off); -}; - -planner : planner_objective planner_discount - | planner_discount planner_objective -; - -planner_objective : PLANNEROBJECTIVE material SEMICOLON { - dynare_parser->set_pl_objective_pos(@2.off, @3.off); -}; - -planner_discount : PLANNERDISCOUNT NAME SEMICOLON { - dynare_parser->set_pl_discount_pos(@2.off, @3.off); -}; - -%% - -void -dynglob_error(std::string mes) -{ - dynare_parser->error(mes); -} diff --git a/dynare++/src/forw_subst_builder.cc b/dynare++/src/forw_subst_builder.cc deleted file mode 100644 index 08ebd8a1e921c155141747e347882ce17de27dff..0000000000000000000000000000000000000000 --- a/dynare++/src/forw_subst_builder.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "forw_subst_builder.hh" - -#include "dynare_model.hh" - -using namespace ogdyn; - -ForwSubstBuilder::ForwSubstBuilder(DynareModel &m) - : model(m) -{ - info.num_new_terms -= model.getParser().getTree().get_num_op(); - - // go through all equations - int neq = model.eqs.nformulas(); - for (int i = 0; i < neq; i++) - { - int ft = model.eqs.formula(i); - int mlead, mlag; - model.termspan(ft, mlead, mlag); - // if equation is too forward looking - if (mlead > 1) - { - info.num_affected_equations++; - // break it to non-linear terms - unordered_set<int> nlt = model.get_nonlinear_subterms(ft); - int j = 0; // indexes subterms - // and make substitutions for all these non-linear subterms - for (const auto &it : nlt) - substitute_for_term(it, i, j++); - } - } - // unassign all variables with lead greater than 1 - unassign_gt_1_leads(); - - /* Forget the derivatives in the tree because some variables could have been - unassigned */ - model.eqs.getTree().forget_derivative_maps(); - - info.num_new_terms += model.getParser().getTree().get_num_op(); -} - -void -ForwSubstBuilder::substitute_for_term(int t, int i, int j) -{ - int mlead, mlag; - model.termspan(t, mlead, mlag); - if (mlead > 1) - { - info.num_subst_terms++; - // Example for comments: let t = f(x(+4)) - // first make lagsubst be substitution setting f(x(+4)) to f(x(+1)) - // this is lag = -3 (1-mlead) - map<int, int> lagsubst; - unordered_set<int> nult = model.eqs.nulary_of_term(t); // make copy of nult! - model.variable_shift_map(nult, 1-mlead, lagsubst); - int lagt = model.eqs.add_substitution(t, lagsubst); - - // now maxlead of lagt is +1 - // add AUXLD_*_*_1 = f(x(+1)) to the model - std::string name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + "_1"; - model.atoms.register_uniq_endo(name); - info.num_aux_variables++; - int auxt = model.eqs.add_nulary(name); - model.eqs.add_formula(model.eqs.add_binary(ogp::code_t::MINUS, auxt, lagt)); - aux_map.emplace(name, lagt); - // now add variables and equations - // AUXLD_*_*_2 = AUXLD_*_*_1(+1) through - // AUXLD_*_*_{mlead-1} = AUXLD_*_*_{mlead-2}(+1) - for (int ll = 1; ll <= mlead-2; ll++) - { - // create AUXLD_*_*_{ll}(+1) - name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + '_' + std::to_string(ll) + "(+1)"; - int lastauxt_lead = model.eqs.add_nulary(name); - // create AUXLD_*_*{ll+1} - name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + '_' + std::to_string(ll+1); - model.atoms.register_uniq_endo(name); - info.num_aux_variables++; - auxt = model.eqs.add_nulary(name); - // add AUXLD_*_*_{ll+1} = AUXLD_*_*_{ll}(+1) - model.eqs.add_formula(model.eqs.add_binary(ogp::code_t::MINUS, auxt, lastauxt_lead)); - /* add substitution to the map; TODO: this works well because in the - context where aux_map is used the timing doesn't matter, however, - it is misleading, needs to be changed */ - aux_map.emplace(name, lagt); - } - - // now we have to substitute AUXLD_*_*{mlead-1}(+1) for t - name = "AUXLD_" + std::to_string(i) + '_' + std::to_string(j) + '_' + std::to_string(mlead-1); - model.substitute_atom_for_term(name, +1, t); - } -} - -void -ForwSubstBuilder::unassign_gt_1_leads(const string &name) -{ - int mlead, mlag; - model.atoms.varspan(name, mlead, mlag); - for (int ll = 2; ll <= mlead; ll++) - { - int t = model.atoms.index(name, ll); - if (t != -1) - model.atoms.unassign_variable(name, ll, t); - } -} - -void -ForwSubstBuilder::unassign_gt_1_leads() -{ - auto &endovars = model.atoms.get_endovars(); - for (const auto &endovar : endovars) - unassign_gt_1_leads(endovar); - auto &exovars = model.atoms.get_exovars(); - for (const auto &exovar : exovars) - unassign_gt_1_leads(exovar); -} - -ForwSubstBuilder::ForwSubstBuilder(const ForwSubstBuilder &b, DynareModel &m) - : model(m) -{ - for (auto it : b.aux_map) - aux_map.insert(it); -} diff --git a/dynare++/src/forw_subst_builder.hh b/dynare++/src/forw_subst_builder.hh deleted file mode 100644 index 7bf12f1e7673ba301f9fe4461150b00b308e8142..0000000000000000000000000000000000000000 --- a/dynare++/src/forw_subst_builder.hh +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef FORW_SUBST_BUILDER_H -#define FORW_SUBST_BUILDER_H - -#include <map> - -#include "dynare_atoms.hh" - -namespace ogdyn -{ - /* This struct encapsulates information about the process of forward - substitutions. */ - struct ForwSubstInfo - { - int num_affected_equations{0}; - int num_subst_terms{0}; - int num_aux_variables{0}; - int num_new_terms{0}; - }; - - class DynareModel; - - class ForwSubstBuilder - { - using Ttermauxmap = map<int, string>; - protected: - /* Reference to the model, to which we will add equations and change some - equations. */ - DynareModel &model; - /* A map mapping new auxiliary variables to the terms in the tree in the - DynareModel. */ - Tsubstmap aux_map; - /* Information about the substitutions. */ - ForwSubstInfo info; - public: - /* Do all the jobs needed. This scans all equations in the model, and for - equations containing forward looking variables greater than 1 lead, it - makes corresponding substitutions. Basically, it breaks each equation to - its non-linear components and creates substitutions for these - components, not for whole equation. This is because the expectation - operator can go through the linear part of the function. This will save - us many occurrences of other variables involved in the equation. */ - ForwSubstBuilder(DynareModel &m); - ForwSubstBuilder(const ForwSubstBuilder &b) = delete; - /* Copy constructor with a new instance of the model. */ - ForwSubstBuilder(const ForwSubstBuilder &b, DynareModel &m); - /* Return the auxiliary variable mapping. */ - const Tsubstmap & - get_aux_map() const - { - return aux_map; - } - /* Return the information. */ - const ForwSubstInfo & - get_info() const - { - return info; - } - private: - /* This method takes a nonlinear term t, and if it has leads of greater - than 1, then it substitutes the term for the new variable (or string of - variables). Note that the substitution is done by - DynamicAtoms::assign_variable. This means that the substitution is made - for all other ocurrences of t in the model. So there is no need of - tracking already substituted terms. The other two parameters are just - for identification of the new auxiliary variables. When called from the - constructor, i is an equation number, j is an order of the non-linear - term in the equation. */ - void substitute_for_term(int t, int i, int j); - /* This is called just at the end of the job. It unassigns all nulary terms - with a lead greater than 1. */ - void unassign_gt_1_leads(); - /* This unassigns all leads greater than 1 of the given name. */ - void unassign_gt_1_leads(const string &name); - }; -}; - -#endif diff --git a/dynare++/src/main.cc b/dynare++/src/main.cc deleted file mode 100644 index 3d46230ffa78652715358748e8d9d2cc9f2251b1..0000000000000000000000000000000000000000 --- a/dynare++/src/main.cc +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright © 2004-2011 Ondra Kamenik - * Copyright © 2019-2022 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "dynare3.hh" -#include "dynare_exception.hh" -#include "dynare_params.hh" - -#include "utils/cc/exception.hh" -#include "parser/cc/parser_exception.hh" -#include "../sylv/cc/SylvException.hh" -#include "../kord/seed_generator.hh" -#include "../kord/global_check.hh" -#include "../kord/approximation.hh" - -#include <fstream> -#include <iostream> -#include <cstdlib> - -int -main(int argc, char **argv) -{ - DynareParams params(argc, argv); - if (params.help) - { - params.printHelp(); - return EXIT_SUCCESS; - } - if (params.version) - { - std::cout << "Dynare++ v. " << VERSION << '\n' - << '\n' - << "Copyright © 2004-2011 Ondra Kamenik\n" - << "Copyright © 2019-2020 Dynare Team\n" - << "Dynare++ comes with ABSOLUTELY NO WARRANTY and is distributed under the GNU GPL,\n" - << "version 3 or later (see https://www.gnu.org/licenses/gpl.html)\n"; - return EXIT_SUCCESS; - } - sthread::detach_thread_group::max_parallel_threads = params.num_threads; - - try - { - // make journal - Journal journal(params.basename + ".jnl"); - - // make dynare object - Dynare dynare(params.modname, params.order, params.ss_tol, journal); - // make list of shocks for which we will do IRFs - std::vector<int> irf_list_ind; - if (params.do_irfs_all) - for (int i = 0; i < dynare.nexog(); i++) - irf_list_ind.push_back(i); - else - irf_list_ind = static_cast<const DynareNameList &>(dynare.getExogNames()).selectIndices(params.irf_list); - - // write matlab files - std::string mfile1(params.basename + "_f.m"); - std::ofstream mfd{mfile1, std::ios::out | std::ios::trunc}; - if (mfd.fail()) - { - std::cerr << "Couldn't open " << mfile1 << " for writing.\n"; - std::exit(EXIT_FAILURE); - } - ogdyn::MatlabSSWriter writer0(dynare.getModel(), params.basename); - writer0.write_der0(mfd); - mfd.close(); - - std::string mfile2(params.basename + "_ff.m"); - mfd.open(mfile2, std::ios::out | std::ios::trunc); - if (mfd.fail()) - { - std::cerr << "Couldn't open " << mfile2 << " for writing.\n"; - std::exit(EXIT_FAILURE); - } - ogdyn::MatlabSSWriter writer1(dynare.getModel(), params.basename); - writer1.write_der1(mfd); - mfd.close(); - - // open mat file - std::string matfile(params.basename + ".mat"); - mat_t *matfd = Mat_Create(matfile.c_str(), nullptr); - if (!matfd) - { - std::cerr << "Couldn't open " << matfile << " for writing.\n"; - std::exit(EXIT_FAILURE); - } - - // write info about the model (dimensions and variables) - dynare.writeMat(matfd, params.prefix); - // write the dump file corresponding to the input - dynare.writeDump(params.basename); - - seed_generator::set_meta_seed(static_cast<std::mt19937::result_type>(params.seed)); - - TLStatic::init(dynare.order(), - dynare.nstat()+2*dynare.npred()+3*dynare.nboth() - +2*dynare.nforw()+dynare.nexog()); - - Approximation app(dynare, journal, params.num_steps, params.do_centralize, params.qz_criterium); - try - { - app.walkStochSteady(); - } - catch (const KordException &e) - { - // tell about the exception and continue - std::cout << "Caught (not yet fatal) Kord exception: "; - e.print(); - JournalRecord rec(journal); - rec << "Solution routine not finished (" << e.get_message() - << "), see what happens" << endrec; - } - - std::string ss_matrix_name(params.prefix + "_steady_states"); - ConstTwoDMatrix(app.getSS()).writeMat(matfd, ss_matrix_name); - - // check the approximation - if (params.check_along_path || params.check_along_shocks - || params.check_on_ellipse) - { - GlobalChecker gcheck(app, sthread::detach_thread_group::max_parallel_threads, journal); - if (params.check_along_shocks) - gcheck.checkAlongShocksAndSave(matfd, params.prefix, - params.getCheckShockPoints(), - params.getCheckShockScale(), - params.check_evals); - if (params.check_on_ellipse) - gcheck.checkOnEllipseAndSave(matfd, params.prefix, - params.getCheckEllipsePoints(), - params.getCheckEllipseScale(), - params.check_evals); - if (params.check_along_path) - gcheck.checkAlongSimulationAndSave(matfd, params.prefix, - params.getCheckPathPoints(), - params.check_evals); - } - - // write the folded decision rule to the Mat-4 file - app.getFoldDecisionRule().writeMat(matfd, params.prefix); - - // simulate conditional - if (params.num_condper > 0 && params.num_condsim > 0) - { - SimResultsDynamicStats rescond(dynare.numeq(), params.num_condper, 0); - Vector det_ss{app.getSS().getCol(0)}; - rescond.simulate(params.num_condsim, app.getFoldDecisionRule(), det_ss, dynare.getVcov(), journal); - rescond.writeMat(matfd, params.prefix); - } - - // simulate unconditional - //const DecisionRule& dr = app.getUnfoldDecisionRule(); - const DecisionRule &dr = app.getFoldDecisionRule(); - if (params.num_per > 0 && params.num_sim > 0) - { - SimResultsStats res(dynare.numeq(), params.num_per, params.num_burn); - res.simulate(params.num_sim, dr, dynare.getSteady(), dynare.getVcov(), journal); - res.writeMat(matfd, params.prefix); - - // impulse response functions - if (!irf_list_ind.empty()) - { - IRFResults irf(dynare, dr, res, irf_list_ind, journal); - irf.writeMat(matfd, params.prefix); - } - } - - // simulate with real-time statistics - if (params.num_rtper > 0 && params.num_rtsim > 0) - { - RTSimResultsStats rtres(dynare.numeq(), params.num_rtper, params.num_burn); - rtres.simulate(params.num_rtsim, dr, dynare.getSteady(), dynare.getVcov(), journal); - rtres.writeMat(matfd, params.prefix); - } - - Mat_Close(matfd); - } - catch (const KordException &e) - { - std::cout << "Caught Kord exception: "; - e.print(); - return e.code(); - } - catch (const TLException &e) - { - std::cout << "Caught TL exception: "; - e.print(); - return 255; - } - catch (SylvException &e) - { - std::cout << "Caught Sylv exception: "; - e.printMessage(); - return 255; - } - catch (const DynareException &e) - { - std::cout << "Caught Dynare exception: " << e.message() << '\n'; - return 255; - } - catch (const ogu::Exception &e) - { - std::cout << "Caught ogu::Exception: "; - e.print(); - return 255; - } - catch (const ogp::ParserException &e) - { - std::cout << "Caught parser exception: " << e.message() << '\n'; - return 255; - } - - return EXIT_SUCCESS; -} diff --git a/dynare++/src/planner_builder.cc b/dynare++/src/planner_builder.cc deleted file mode 100644 index 41bb6f91da2ae31a8c6d9da1c3316181415820a7..0000000000000000000000000000000000000000 --- a/dynare++/src/planner_builder.cc +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright © 2006 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "planner_builder.hh" -#include "dynare_exception.hh" -#include "dynare_model.hh" - -#include <cmath> -#include <utility> - -using namespace ogdyn; - -const IntegerMatrix & -IntegerMatrix::operator=(const IntegerMatrix &im) -{ - if (nr != im.nr || nc != im.nc) - throw DynareException(__FILE__, __LINE__, - "Matrices have different dimensions in IntegerMatrix::operator="); - std::copy_n(im.data.get(), nr*nc, data.get()); - return *this; -} - -const IntegerArray3 & -IntegerArray3::operator=(const IntegerArray3 &ia3) -{ - if (n1 != ia3.n1 || n2 != ia3.n2 || n3 != ia3.n3) - throw DynareException(__FILE__, __LINE__, - "Arrays have different dimensions in IntegerArray3::operator="); - std::copy_n(ia3.data.get(), n1*n2*n3, data.get()); - return *this; -} - -PlannerBuilder::PlannerBuilder(DynareModel &m, const Tvarset &yyset, - Teqset ffset) - : yset(), fset(std::move(ffset)), model(m), - tb(model.t_plobjective), tbeta(model.t_pldiscount), - maxlead(model.atoms.get_maxlead()), - minlag(model.atoms.get_minlag()), - diff_b(yyset.size(), 1-minlag), - diff_f(yyset.size(), fset.size(), 1+maxlead-minlag), - static_atoms(), - static_tree(), - diff_b_static(yyset.size(), 1-minlag), - diff_f_static(yyset.size(), fset.size(), 1+maxlead-minlag) -{ - info.num_new_terms -= model.getParser().getTree().get_num_op(); - - fill_yset(m.atoms.get_name_storage(), yyset); - - add_derivatives_of_b(); - add_derivatives_of_f(); - shift_derivatives_of_b(); - shift_derivatives_of_f(); - beta_multiply_b(); - beta_multiply_f(); - make_static_version(); - lagrange_mult_f(); - form_equations(); - - info.num_new_terms += model.getParser().getTree().get_num_op(); -} - -PlannerBuilder::PlannerBuilder(const PlannerBuilder &pb, ogdyn::DynareModel &m) - : yset(), fset(pb.fset), model(m), - tb(pb.tb), tbeta(pb.tbeta), - maxlead(pb.maxlead), minlag(pb.minlag), - diff_b(pb.diff_b), diff_f(pb.diff_f), - static_atoms(pb.static_atoms), - static_tree(pb.static_tree), - diff_b_static(pb.diff_b_static), - diff_f_static(pb.diff_f_static), - aux_map(), static_aux_map() -{ - fill_yset(m.atoms.get_name_storage(), pb.yset); - fill_aux_map(m.atoms.get_name_storage(), pb.aux_map, pb.static_aux_map); -} - -void -PlannerBuilder::add_derivatives_of_b() -{ - int yi = 0; - for (auto yname = yset.begin(); yname != yset.end(); ++yname, yi++) - for (int ll = minlag; ll <= 0; ll++) - { - int yt = model.atoms.index(*yname, ll); - if (yt != -1) - diff_b(yi, ll-minlag) = model.eqs.add_derivative(tb, yt); - else - diff_b(yi, ll-minlag) = ogp::OperationTree::zero; - } -} - -void -PlannerBuilder::add_derivatives_of_f() -{ - int yi = 0; - for (auto yname = yset.begin(); yname != yset.end(); ++yname, yi++) - for (unsigned int fi = 0; fi < fset.size(); fi++) - for (int ll = minlag; ll <= maxlead; ll++) - { - int yt = model.atoms.index(*yname, ll); - if (yt != -1) - diff_f(yi, fi, ll-minlag) - = model.eqs.add_derivative(model.eqs.formula(fset[fi]), yt); - else - diff_f(yi, fi, ll-minlag) = ogp::OperationTree::zero; - } -} - -void -PlannerBuilder::shift_derivatives_of_b() -{ - map<int, int> subst; - for (int yi = 0; yi < diff_b.nrows(); yi++) - for (int ll = minlag; ll < 0; ll++) - if (diff_b(yi, ll-minlag) != ogp::OperationTree::zero) - { - model.variable_shift_map(model.eqs.nulary_of_term(diff_b(yi, ll-minlag)), - -ll, subst); - diff_b(yi, ll-minlag) = model.eqs.add_substitution(diff_b(yi, ll-minlag), subst); - } -} - -void -PlannerBuilder::shift_derivatives_of_f() -{ - map<int, int> subst; - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - { - // first do it leads which are put under expectation before t: no problem - for (int ll = 0; ll <= maxlead; ll++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - { - model.variable_shift_map(model.eqs.nulary_of_term(diff_f(yi, fi, ll-minlag)), - -ll, subst); - diff_f(yi, fi, ll-minlag) - = model.eqs.add_substitution(diff_f(yi, fi, ll-minlag), subst); - } - /* now do it for lags, these are put as leads under expectations after - time t, so we have to introduce auxiliary variables at time t, and - make leads of them here */ - for (int ll = minlag; ll < 0; ll++) - { - int ft = diff_f(yi, fi, ll-minlag); - if (ft != ogp::OperationTree::zero) - { - /* if the ft term has a lead, than we need to introduce an - auxiliary variable zₜ, define it as 𝔼ₜ[ft] and put z_{t-ll} - to the equation. Otherwise, we just put leaded ft to the - equation directly. */ - int ft_maxlead, ft_minlag; - model.termspan(ft, ft_maxlead, ft_minlag); - if (ft_maxlead > 0) - { - // make an auxiliary variable - std::string name; - name = "AUX_" + std::to_string(yi) + '_' + std::to_string(fset[fi]) + '_' + std::to_string(-ll); - model.atoms.register_uniq_endo(name); - info.num_aux_variables++; - int taux = model.eqs.add_nulary(name); - name = "AUX_" + std::to_string(yi) + '_' + std::to_string(fset[fi]) + '_' + std::to_string(-ll) + '(' + std::to_string(-ll) + ')'; - int taux_leaded = model.eqs.add_nulary(name); - // put aux_leaded to the equation - diff_f(yi, fi, ll-minlag) = taux_leaded; - // save auxiliary variable and the term - aux_map.emplace(model.atoms.name(taux), ft); - } - else - { - /* no auxiliary variable is needed and the term ft can be - leaded in place */ - model.variable_shift_map(model.eqs.nulary_of_term(ft), -ll, subst); - diff_f(yi, fi, ll-minlag) = model.eqs.add_substitution(ft, subst); - } - } - } - } -} - -void -PlannerBuilder::beta_multiply_b() -{ - int beta_pow = ogp::OperationTree::one; - for (int ll = 0; ll >= minlag; ll--, - beta_pow = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, tbeta)) - for (int yi = 0; yi < diff_b.nrows(); yi++) - if (diff_b(yi, ll-minlag) != ogp::OperationTree::zero) - diff_b(yi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, diff_b(yi, ll-minlag)); -} - -void -PlannerBuilder::beta_multiply_f() -{ - int beta_pow = ogp::OperationTree::one; - for (int ll = 0; ll <= maxlead; ll++, - beta_pow = model.eqs.add_binary(ogp::code_t::DIVIDE, beta_pow, tbeta)) - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - diff_f(yi, fi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, diff_f(yi, fi, ll-minlag)); - - beta_pow = ogp::OperationTree::one; - for (int ll = 0; ll >= minlag; ll--, - beta_pow = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, tbeta)) - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - diff_f(yi, fi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, beta_pow, diff_f(yi, fi, ll-minlag)); -} - -void -PlannerBuilder::make_static_version() -{ - // map holding substitutions from dynamic to static - ogp::StaticFineAtoms::Tintintmap tmap; - - // fill static atoms with outer ordering - static_atoms.import_atoms(model.atoms, static_tree, tmap); - - // go through diff_b and fill diff_b_static - for (int ll = minlag; ll <= 0; ll++) - for (int yi = 0; yi < diff_b.nrows(); yi++) - diff_b_static(yi, ll-minlag) - = static_tree.add_substitution(diff_b(yi, ll-minlag), - tmap, model.eqs.getTree()); - - // go through diff_f and fill diff_f_static - for (int ll = minlag; ll <= maxlead; ll++) - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - diff_f_static(yi, fi, ll-minlag) - = static_tree.add_substitution(diff_f(yi, fi, ll-minlag), - tmap, model.eqs.getTree()); - - // go through aux_map and fill static_aux_map - for (const auto &it : aux_map) - { - int tstatic = static_tree.add_substitution(it.second, tmap, model.eqs.getTree()); - static_aux_map.emplace(it.first, tstatic); - } -} - -void -PlannerBuilder::lagrange_mult_f() -{ - // register multipliers - std::string mult_name; - for (int fi = 0; fi < diff_f.dim2(); fi++) - { - mult_name = "MULT" + std::to_string(fset[fi]); - model.atoms.register_uniq_endo(mult_name); - info.num_lagrange_mults++; - } - // multiply with the multipliers - for (int yi = 0; yi < diff_f.dim1(); yi++) - for (int fi = 0; fi < diff_f.dim2(); fi++) - for (int ll = minlag; ll <= maxlead; ll++) - if (diff_f(yi, fi, ll-minlag) != ogp::OperationTree::zero) - { - mult_name = "MULT" + std::to_string(fset[fi]) + '(' + std::to_string(-ll) + ')'; - int tm = model.eqs.add_nulary(mult_name); - diff_f(yi, fi, ll-minlag) - = model.eqs.add_binary(ogp::code_t::TIMES, tm, diff_f(yi, fi, ll-minlag)); - } -} - -void -PlannerBuilder::form_equations() -{ - // add planner’s FOCs - for (int yi = 0; yi < diff_f.dim1(); yi++) - { - int eq = ogp::OperationTree::zero; - for (int ll = minlag; ll <= 0; ll++) - eq = model.eqs.add_binary(ogp::code_t::PLUS, eq, diff_b(yi, ll-minlag)); - for (int fi = 0; fi < diff_f.dim2(); fi++) - for (int ll = minlag; ll <= maxlead; ll++) - eq = model.eqs.add_binary(ogp::code_t::PLUS, eq, diff_f(yi, fi, ll-minlag)); - model.eqs.add_formula(eq); - } - - // add equations for auxiliary variables - for (const auto &it : aux_map) - { - int t = model.atoms.index(it.first, 0); - model.eqs.add_formula(model.eqs.add_binary(ogp::code_t::MINUS, t, it.second)); - } -} - -void -PlannerBuilder::fill_yset(const ogp::NameStorage &ns, - const PlannerBuilder::Tvarset &yyset) -{ - for (auto it : yyset) - yset.insert(it); -} - -void -PlannerBuilder::fill_aux_map(const ogp::NameStorage &ns, const Tsubstmap &aaux_map, - const Tsubstmap &astatic_aux_map) -{ - // fill aux_map - for (auto it : aaux_map) - aux_map.insert(it); - - // fill static_aux_map - for (auto it : astatic_aux_map) - static_aux_map.insert(it); -} - -MultInitSS::MultInitSS(const PlannerBuilder &pb, const Vector &pvals, Vector &yy) - : builder(pb), b(builder.diff_b_static.nrows()), - F(builder.diff_f_static.dim1(), builder.diff_f_static.dim2()) -{ - b.zeros(); - F.zeros(); - - // first evaluate substitutions (auxiliary variables) from the builder - ogdyn::DynareStaticSteadySubstitutions dss(builder.model.atoms, builder.static_atoms, - builder.static_tree, - builder.static_aux_map, pvals, yy); - - /* gather all the terms from builder.diff_b_static and builder.diff_f_static - to the vector, the ordering is important, since the index of this vector - will have to be decoded to the position in b and F. */ - vector<int> terms; - for (int yi = 0; yi < builder.diff_b_static.nrows(); yi++) - for (int l = 0; l < builder.diff_b_static.ncols(); l++) - terms.push_back(builder.diff_b_static(yi, l)); - for (int yi = 0; yi < builder.diff_f_static.dim1(); yi++) - for (int fi = 0; fi < builder.diff_f_static.dim2(); fi++) - for (int l = 0; l < builder.diff_f_static.dim3(); l++) - terms.push_back(builder.diff_f_static(yi, fi, l)); - - /* evaluate the terms, it will call a series of load(i,res), which sum the - results through lags/leads to b and F */ - DynareStaticSteadyAtomValues dssav(builder.model.atoms, builder.static_atoms, pvals, yy); - ogp::FormulaCustomEvaluator fe(builder.static_tree, terms); - fe.eval(dssav, *this); - - // solve overdetermined system b+F*lambda=0 using SVD decomposition - SVDDecomp decomp(F); - Vector lambda(builder.diff_f_static.dim2()); - decomp.solve(b, lambda); - lambda.mult(-1); - - // take values of lambda and put it to yy - for (int fi = 0; fi < builder.diff_f_static.dim2(); fi++) - { - std::string mult_name = "MULT" + std::to_string(builder.fset[fi]); - int iouter = builder.model.atoms.name2outer_endo(mult_name); - int iy = builder.model.atoms.outer2y_endo()[iouter]; - if (!std::isfinite(yy[iy])) - yy[iy] = lambda[fi]; - - /* go through all substitutions of the multiplier and set them as well */ - if (builder.model.atom_substs) - { - const ogp::AtomSubstitutions::Toldnamemap &old2new - = builder.model.atom_substs->get_old2new(); - auto it = old2new.find(mult_name); - if (it != old2new.end()) - { - const ogp::AtomSubstitutions::Tshiftnameset &sset = it->second; - for (const auto &itt : sset) - { - const std::string &newname = itt.first; - int iouter = builder.model.atoms.name2outer_endo(newname); - int iy = builder.model.atoms.outer2y_endo()[iouter]; - if (!std::isfinite(yy[iy])) - yy[iy] = lambda[fi]; - } - } - } - } -} - -void -MultInitSS::load(int i, double res) -{ - /* we can afford it, since the evaluator sets res to exact zero if the term - is zero */ - if (res == 0) - return; - // decode i and add to either b or F - if (i < builder.diff_b_static.nrows()*builder.diff_b_static.ncols()) - // add to b - b[i / builder.diff_b_static.ncols()] += res; - else - { - // add to F - i -= builder.diff_b_static.nrows()*builder.diff_b_static.ncols(); - int yifi = i / builder.diff_f_static.dim3(); - int yi = yifi / builder.diff_f_static.dim2(); - int fi = yifi % builder.diff_f_static.dim2(); - F.get(yi, fi) += res; - } -} diff --git a/dynare++/src/planner_builder.hh b/dynare++/src/planner_builder.hh deleted file mode 100644 index 206df7da767dd53cd1274ad40a3a536db48c6be4..0000000000000000000000000000000000000000 --- a/dynare++/src/planner_builder.hh +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright © 2006-2011 Ondra Kamenik - * Copyright © 2019 Dynare Team - * - * This file is part of Dynare. - * - * Dynare is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Dynare is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Dynare. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef PLANNER_BUILDER_H -#define PLANNER_BUILDER_H - -#include <unordered_set> -#include <map> -#include <vector> -#include <memory> -#include <algorithm> - -#include "parser/cc/static_fine_atoms.hh" -#include "dynare_atoms.hh" -#include "GeneralMatrix.hh" - -namespace ogdyn -{ - using std::unordered_set; - using std::map; - using std::vector; - - /** This is a two dimensional array of integers. Nothing - * difficult. */ - class IntegerMatrix - { - protected: - /** Number of rows. */ - int nr; - /** Number of columns. */ - int nc; - /** The pointer to the data. */ - std::unique_ptr<int[]> data; - public: - /** Construct uninitialized array. */ - IntegerMatrix(int nrr, int ncc) - : nr(nrr), nc(ncc), data(std::make_unique<int[]>(nr*nc)) - { - } - /** Copy constructor. */ - IntegerMatrix(const IntegerMatrix &im) - : nr(im.nr), nc(im.nc), data(std::make_unique<int[]>(nr*nc)) - { - std::copy_n(im.data.get(), nr*nc, data.get()); - } - /** Assignment operator. It can only assing array with the - * same dimensions. */ - const IntegerMatrix &operator=(const IntegerMatrix &im); - int & - operator()(int i, int j) - { - return data[i+j*nr]; - } - const int & - operator()(int i, int j) const - { - return data[i+j*nr]; - } - int - nrows() const - { - return nr; - } - int - ncols() const - { - return nc; - } - }; - - /** The three dimensional array of integers. Nothing difficult. */ - class IntegerArray3 - { - protected: - /** First dimension. */ - int n1; - /** Second dimension. */ - int n2; - /** Third dimension. */ - int n3; - /** The data. */ - std::unique_ptr<int[]> data; - public: - /** Constrcut unitialized array. */ - IntegerArray3(int nn1, int nn2, int nn3) - : n1(nn1), n2(nn2), n3(nn3), data(std::make_unique<int[]>(n1*n2*n3)) - { - } - /** Copy constructor. */ - IntegerArray3(const IntegerArray3 &ia3) - : n1(ia3.n1), n2(ia3.n2), n3(ia3.n3), data(std::make_unique<int[]>(n1*n2*n3)) - { - std::copy_n(ia3.data.get(), n1*n2*n3, data.get()); - } - /** Assignment operator assigning the arrays with the same dimensions. */ - const IntegerArray3 &operator=(const IntegerArray3 &ia3); - int & - operator()(int i, int j, int k) - { - return data[i+j*n1+k*n1*n2]; - } - const int & - operator()(int i, int j, int k) const - { - return data[i+j*n1+k*n1*n2]; - } - int - dim1() const - { - return n1; - } - int - dim2() const - { - return n2; - } - int - dim3() const - { - return n3; - } - }; - - /** This struct encapsulates information about the building of a - * planner's problem. */ - struct PlannerInfo - { - int num_lagrange_mults{0}; - int num_aux_variables{0}; - int num_new_terms{0}; - }; - - class MultInitSS; - class DynareModel; - - /** This class builds the first order conditions of the social - * planner problem with constraints being the equations in the - * model. The model is non-const parameter to the constructor - * which adds appropriate FOCs to the system. It also allows for - * an estimation of the lagrange multipliers given all other - * endogenous variables of the static system. For this purpose we - * need to create static atoms and static versions of all the tree - * index matrices. The algorithm and algebra are documented in - * dynare++-ramsey.pdf. */ - class PlannerBuilder - { - friend class MultInitSS; - public: - /** Type for a set of variable names. */ - using Tvarset = unordered_set<string>; - /** Type for a set of equations. An equation is identified by - * an index to an equation in the equation vector given by - * DynareModel::eqs. The tree index of the i-th formula is - * retrieved as DynareModel::egs.formula(i). */ - using Teqset = vector<int>; - protected: - /** This is a set of variables wrt which the planner - * optimizes. These could be all endogenous variables, but it - * is beneficial to exclude all variables which are - * deterministic transformations of past exogenous variables, - * since the planner cannot influence them. This could save a - * few equations. This is not changed after it is constructed, - * but it is constructed manually, so it cannot be declared as - * const. */ - Tvarset yset; - /** These are the equation indices constituing the constraints - * for the planner. Again, it is beneficial to exclude all - * equations defining exogenous variables excluded from - * yset. */ - const Teqset fset; - /** Reference to the model. */ - ogdyn::DynareModel &model; - /** Tree index of the planner objective. */ - int tb; - /** Tree index of the planner discount parameter. */ - int tbeta; - /** The maximum lead in the model including the planner's - * objective before building the planner's FOCs. */ - const int maxlead; - /** The minimum lag in the model including the planner's objective - * before building the planner's FOCs. */ - const int minlag; - /** Tree indices of formulas in the planner FOCs involving - * derivatives of the planner's objective. Rows correspond to the - * endogenous variables, columns correspond to lags in the - * objective function. The contents of the matrix will evolve as - * the algorithm proceeds. */ - IntegerMatrix diff_b; - /** Tree indices of formulas in the planner FOCs involving - * derivatives of the model equations (constraints). The first - * dimension corresponds to endogenous variables, the second to - * the constraints, the third to lags or leads of endogenous - * variables in the constraints. The contents of the array will - * evolve as the algorithm proceeds.*/ - IntegerArray3 diff_f; - /** Static version of the model atoms. It is needed to build - * static version of diff_b and diff_f. */ - ogp::StaticFineAtoms static_atoms; - /** Static version of all the trees of diff_b and diff_f build - * over static_atoms. */ - ogp::OperationTree static_tree; - /** Tree indices of static version of diff_b over static_atoms and static_tree. */ - IntegerMatrix diff_b_static; - /** Tree indices of static version of diff_f over static_atoms - * and static_tree. This member is created before calling - * lagrange_mult_f(), so it does not contain the - * multiplication with the lagrange multipliers. */ - IntegerArray3 diff_f_static; - /** Auxiliary variables mapping. During the algorithm, some - * auxiliary variables for the terms might be created, so we - * remember their names and tree indices of the terms. This - * maps a name to the tree index of an expression equal to the - * auxiliary variable at time zero. The auxiliary variables - * names point to the dynamic atoms storage, tree inidices to - * the dynamic model tree. */ - Tsubstmap aux_map; - /** Static version of aux_map. The names point to static_atoms - * storage, the tree indices to the static_tree. */ - Tsubstmap static_aux_map; - /** Information about the number of various things. */ - PlannerInfo info; - public: - /** Build the planner problem for the given model optimizing - * through the given endogenous variables with the given - * constraints. We allow for a selection of a subset of - * equations and variables in order to eliminate exogenous - * predetermined process which cannot be influenced by the - * social planner. */ - PlannerBuilder(ogdyn::DynareModel &m, const Tvarset &yyset, - Teqset ffset); - /** Construct a copy of the builder with provided model, which - * is supposed to be the copy of the model in the builder. */ - PlannerBuilder(const PlannerBuilder &pb, ogdyn::DynareModel &m); - /** Avoid copying from only PlannerBuilder. */ - PlannerBuilder(const PlannerBuilder &pb) = delete; - /** Return the information. */ - const PlannerInfo & - get_info() const - { - return info; - } - protected: - /** Differentiate the planner objective wrt endogenous - * variables with different lags. */ - void add_derivatives_of_b(); - /** Differentiate the constraints wrt endogenous variables - * with different lags and leads. */ - void add_derivatives_of_f(); - /** Shift derivatives of diff_b. */ - void shift_derivatives_of_b(); - /** Shift derivatives of diff_ff. */ - void shift_derivatives_of_f(); - /** Multiply with the discount factor terms in diff_b. */ - void beta_multiply_b(); - /** Multiply with the discount factor terms in diff_f. */ - void beta_multiply_f(); - /** Fill static_atoms and static_tree and build diff_b_static, - * diff_f_static and aux_map_static with static versions of diff_b, - * diff_f and aux_map. */ - void make_static_version(); - /** Multiply diff_f with Langrange multipliers. */ - void lagrange_mult_f(); - /** Add the equations to the mode, including equation for auxiliary variables. */ - void form_equations(); - private: - /** Fill yset for a given yyset and given name storage. */ - void fill_yset(const ogp::NameStorage &ns, const Tvarset &yyset); - /** Fill aux_map and aux_map_static for a given aaux_map and - * aaux_map_static for a given storage of dynamic atoms (used - * for aux_map) and static atoms storage from this object for - * aux_map_static. */ - void fill_aux_map(const ogp::NameStorage &ns, const Tsubstmap &aaux_map, - const Tsubstmap &astatic_aux_map); - }; - - /** This class only calculates for the given initial guess of - * endogenous variables, initial guess of the Langrange - * multipliers of the social planner problem yielding the least - * square error. It is used by just calling its constructor. The - * constructor takes non-const reference to the vector of - * endogenous variables, calculates lambdas and put the values of - * lambdas to the vector. The algbera is found in - * dynare++-ramsey.pdf. - * - * The code can be run only after the parsing has been finished in - * atoms. */ - class MultInitSS : public ogp::FormulaEvalLoader - { - protected: - /** The constant reference to the builder. */ - const PlannerBuilder &builder; - /** The constant term of the problem. Its length is the number - * of endogenous variable wrt the planner optimizes. */ - Vector b; - /** The matrix of the overdetermined problem. The number of - * rows is equal to the number of endogenous variables wrt - * which the planner optimizes, the number of columns is equal - * to the number of Langrange multipliers which is equal to - * the number of constraints which is smaller than the number - * of endogenous variables. Hence the system b+F*lambda=0 is - * overdetermined. */ - GeneralMatrix F; - public: - /** The constructor of the object which does everything. Its - * main goal is to update yy. Note that if an item of yy - * corresponding to a lagrange multiplier is already set, it - * is not reset. */ - MultInitSS(const PlannerBuilder &pb, const Vector &pvals, Vector &yy); - /** This loads evaluated parts of b or F and decodes i and - * advances b or F depending on the decoded i. The decoding is - * dependent on the way how the terms of builder.diff_b and - * builder.diff_f_save have been put the the - * ogp::FormulaCustomEvaluator. This is documented in the code - * of the constructor. */ - void load(int i, double res) override; - }; -}; - -#endif diff --git a/dynare++/sylv/Makefile.am b/dynare++/sylv/Makefile.am deleted file mode 100644 index ffebab6fe3641d3346316761575936e56f4be6f5..0000000000000000000000000000000000000000 --- a/dynare++/sylv/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = cc testing diff --git a/dynare++/sylv/cc/Makefile.am b/dynare++/sylv/cc/Makefile.am deleted file mode 100644 index d1e88bbc3272b8155fe00818f0d19baa038f0069..0000000000000000000000000000000000000000 --- a/dynare++/sylv/cc/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -noinst_LIBRARIES = libsylv.a - -# For dynblas.h and dynlapack.h -libsylv_a_CPPFLAGS = -I$(top_srcdir)/mex/sources -I../../utils/cc - -libsylv_a_SOURCES = \ - BlockDiagonal.cc \ - BlockDiagonal.hh \ - GeneralMatrix.cc \ - GeneralMatrix.hh \ - GeneralSylvester.cc \ - GeneralSylvester.hh \ - IterativeSylvester.cc \ - IterativeSylvester.hh \ - KronUtils.cc \ - KronUtils.hh \ - KronVector.cc \ - KronVector.hh \ - QuasiTriangular.cc \ - QuasiTriangular.hh \ - QuasiTriangularZero.cc \ - QuasiTriangularZero.hh \ - SchurDecomp.cc \ - SchurDecomp.hh \ - SchurDecompEig.cc \ - SchurDecompEig.hh \ - SimilarityDecomp.cc \ - SimilarityDecomp.hh \ - SylvException.cc \ - SylvException.hh \ - SylvMatrix.cc \ - SylvMatrix.hh \ - SylvParams.cc \ - SylvParams.hh \ - SylvesterSolver.hh \ - SymSchurDecomp.cc \ - SymSchurDecomp.hh \ - TriangularSylvester.cc \ - TriangularSylvester.hh \ - Vector.cc \ - Vector.hh diff --git a/dynare++/tests/Makefile.am b/dynare++/tests/Makefile.am deleted file mode 100644 index e98e408637a5ee497d19c07d1c0f2bd0e6eca6f8..0000000000000000000000000000000000000000 --- a/dynare++/tests/Makefile.am +++ /dev/null @@ -1,46 +0,0 @@ -MODFILES = \ - asset.mod \ - c20.mod \ - czech2.mod \ - dm7.mod \ - example1.mod \ - example1_optim.mod \ - gentay1a.mod \ - judd.mod \ - judd_norm.mod \ - kp1980_1.mod \ - kp1980_2.mod \ - kp1980_3.mod \ - lucas78.mod \ - m_0_3_0_0_0_0_0_0.mod \ - m_1_3_0_0_0_0_0_0.mod \ - m_1_3_0_0_0_0_0_1.mod \ - or0a.mod \ - portfolio4.mod \ - portfolio4_norm.mod \ - portfolio.mod \ - psd_exo3.mod \ - q3a2.mod \ - q3a50.mod \ - sedmodel1.mod \ - swma_pie.mod \ - test1.mod \ - test2a.mod \ - test2.mod \ - test3.mod \ - test4.mod \ - test5.mod \ - test6.mod \ - test7.mod \ - test.mod - -EXTRA_DIST = $(MODFILES) \ - sw_euro.mod # This one crashes at steady state computation - -check-local: $(MODFILES:%.mod=%.jnl) - -%.jnl: %.mod - ../src/dynare++ --sim 2 $< - -clean-local: - rm -f *.jnl *_f.m *_ff.m *.dump diff --git a/dynare++/tests/asset.mod b/dynare++/tests/asset.mod deleted file mode 100644 index c9a5b9e2877ac6ec4b5ad3de84e35513582c315a..0000000000000000000000000000000000000000 --- a/dynare++/tests/asset.mod +++ /dev/null @@ -1,28 +0,0 @@ -var y, x; -varexo e; - -parameters theta, rho, bet, xbar; - -xbar = 0.0179; -rho = -0.139; -theta = -10; -bet = 0.95; - -model; -y = bet*exp(theta*x(+1))*(1+y(+1)); -x = (1-rho)*xbar + rho*x(-1) + e; -end; - -initval; -x = 0.0179; -y = 0.3; -e = 0; -end; - -vcov = [ 0.0012110]; - -order = 6; - - - - diff --git a/dynare++/tests/c20.mod b/dynare++/tests/c20.mod deleted file mode 100644 index a3b7bd1fabfa3dd28c68daaa7a51bac15898811f..0000000000000000000000000000000000000000 --- a/dynare++/tests/c20.mod +++ /dev/null @@ -1,497 +0,0 @@ -var C10_PIE C10_RR C10_RS C10_Y C11_PIE C11_RR C11_RS C11_Y C12_PIE C12_RR C12_RS C12_Y C13_PIE C13_RR C13_RS C13_Y C14_PIE C14_RR C14_RS C14_Y C15_PIE C15_RR C15_RS C15_Y C16_PIE C16_RR C16_RS C16_Y C17_PIE C17_RR C17_RS C17_Y C18_PIE C18_RR C18_RS C18_Y C19_PIE C19_RR C19_RS C19_Y C1_PIE C1_RR C1_RS C1_Y C20_PIE C20_RR C20_RS C20_Y C2_PIE C2_RR C2_RS C2_Y C3_PIE C3_RR C3_RS C3_Y C4_PIE C4_RR C4_RS C4_Y C5_PIE C5_RR C5_RS C5_Y C6_PIE C6_RR C6_RS C6_Y C7_PIE C7_RR C7_RS C7_Y C8_PIE C8_RR C8_RS C8_Y C9_PIE C9_RR C9_RS C9_Y; - -varexo C1_EPIE C1_EY C1_ERS C2_EPIE C2_EY C2_ERS C3_EPIE C3_EY C3_ERS C4_EPIE C4_EY C4_ERS C5_EPIE C5_EY C5_ERS C6_EPIE C6_EY C6_ERS C7_EPIE C7_EY C7_ERS C8_EPIE C8_EY C8_ERS C9_EPIE C9_EY C9_ERS C10_EPIE C10_EY C10_ERS C11_EPIE C11_EY C11_ERS C12_EPIE C12_EY C12_ERS C13_EPIE C13_EY C13_ERS C14_EPIE C14_EY C14_ERS C15_EPIE C15_EY C15_ERS C16_EPIE C16_EY C16_ERS C17_EPIE C17_EY C17_ERS C18_EPIE C18_EY C18_ERS C19_EPIE C19_EY C19_ERS C20_EPIE C20_EY C20_ERS; - -parameters C10_CALFA1 C10_CALFA2 C10_CALFA3 C10_CALFA4 C10_CALFA5 C10_CALFA6 C10_CALFA7 C10_CALFA8 C10_CALFA9 C11_CALFA1 C11_CALFA2 C11_CALFA3 C11_CALFA4 C11_CALFA5 C11_CALFA6 C11_CALFA7 C11_CALFA8 C11_CALFA9 C12_CALFA1 C12_CALFA2 C12_CALFA3 C12_CALFA4 C12_CALFA5 C12_CALFA6 C12_CALFA7 C12_CALFA8 C12_CALFA9 C13_CALFA1 C13_CALFA2 C13_CALFA3 C13_CALFA4 C13_CALFA5 C13_CALFA6 C13_CALFA7 C13_CALFA8 C13_CALFA9 C14_CALFA1 C14_CALFA2 C14_CALFA3 C14_CALFA4 C14_CALFA5 C14_CALFA6 C14_CALFA7 C14_CALFA8 C14_CALFA9 C15_CALFA1 C15_CALFA2 C15_CALFA3 C15_CALFA4 C15_CALFA5 C15_CALFA6 C15_CALFA7 C15_CALFA8 C15_CALFA9 C16_CALFA1 C16_CALFA2 C16_CALFA3 C16_CALFA4 C16_CALFA5 C16_CALFA6 C16_CALFA7 C16_CALFA8 C16_CALFA9 C17_CALFA1 C17_CALFA2 C17_CALFA3 C17_CALFA4 C17_CALFA5 C17_CALFA6 C17_CALFA7 C17_CALFA8 C17_CALFA9 C18_CALFA1 C18_CALFA2 C18_CALFA3 C18_CALFA4 C18_CALFA5 C18_CALFA6 C18_CALFA7 C18_CALFA8 C18_CALFA9 C19_CALFA1 C19_CALFA2 C19_CALFA3 C19_CALFA4 C19_CALFA5 C19_CALFA6 C19_CALFA7 C19_CALFA8 C19_CALFA9 C1_CALFA1 C1_CALFA2 C1_CALFA3 C1_CALFA4 C1_CALFA5 C1_CALFA6 C1_CALFA7 C1_CALFA8 C1_CALFA9 C20_CALFA1 C20_CALFA2 C20_CALFA3 C20_CALFA4 C20_CALFA5 C20_CALFA6 C20_CALFA7 C20_CALFA8 C20_CALFA9 C2_CALFA1 C2_CALFA2 C2_CALFA3 C2_CALFA4 C2_CALFA5 C2_CALFA6 C2_CALFA7 C2_CALFA8 C2_CALFA9 C3_CALFA1 C3_CALFA2 C3_CALFA3 C3_CALFA4 C3_CALFA5 C3_CALFA6 C3_CALFA7 C3_CALFA8 C3_CALFA9 C4_CALFA1 C4_CALFA2 C4_CALFA3 C4_CALFA4 C4_CALFA5 C4_CALFA6 C4_CALFA7 C4_CALFA8 C4_CALFA9 C5_CALFA1 C5_CALFA2 C5_CALFA3 C5_CALFA4 C5_CALFA5 C5_CALFA6 C5_CALFA7 C5_CALFA8 C5_CALFA9 C6_CALFA1 C6_CALFA2 C6_CALFA3 C6_CALFA4 C6_CALFA5 C6_CALFA6 C6_CALFA7 C6_CALFA8 C6_CALFA9 C7_CALFA1 C7_CALFA2 C7_CALFA3 C7_CALFA4 C7_CALFA5 C7_CALFA6 C7_CALFA7 C7_CALFA8 C7_CALFA9 C8_CALFA1 C8_CALFA2 C8_CALFA3 C8_CALFA4 C8_CALFA5 C8_CALFA6 C8_CALFA7 C8_CALFA8 C8_CALFA9 C9_CALFA1 C9_CALFA2 C9_CALFA3 C9_CALFA4 C9_CALFA5 C9_CALFA6 C9_CALFA7 C9_CALFA8 C9_CALFA9 C10_PIESTAR C11_PIESTAR C12_PIESTAR C13_PIESTAR C14_PIESTAR C15_PIESTAR C16_PIESTAR C17_PIESTAR C18_PIESTAR C19_PIESTAR C1_PIESTAR C20_PIESTAR C2_PIESTAR C3_PIESTAR C4_PIESTAR C5_PIESTAR C6_PIESTAR C7_PIESTAR C8_PIESTAR C9_PIESTAR; -C10_CALFA1=0.5; -C10_CALFA2=0.5; -C10_CALFA3=0.5; -C10_CALFA4=0; -C10_CALFA5=0.75; -C10_CALFA6=-0.25; -C10_CALFA7=0.1; -C10_CALFA8=0.5; -C10_CALFA9=0.5; -C11_CALFA1=0.5; -C11_CALFA2=0.5; -C11_CALFA3=0.5; -C11_CALFA4=0; -C11_CALFA5=0.75; -C11_CALFA6=-0.25; -C11_CALFA7=0.1; -C11_CALFA8=0.5; -C11_CALFA9=0.5; -C12_CALFA1=0.5; -C12_CALFA2=0.5; -C12_CALFA3=0.5; -C12_CALFA4=0; -C12_CALFA5=0.75; -C12_CALFA6=-0.25; -C12_CALFA7=0.1; -C12_CALFA8=0.5; -C12_CALFA9=0.5; -C13_CALFA1=0.5; -C13_CALFA2=0.5; -C13_CALFA3=0.5; -C13_CALFA4=0; -C13_CALFA5=0.75; -C13_CALFA6=-0.25; -C13_CALFA7=0.1; -C13_CALFA8=0.5; -C13_CALFA9=0.5; -C14_CALFA1=0.5; -C14_CALFA2=0.5; -C14_CALFA3=0.5; -C14_CALFA4=0; -C14_CALFA5=0.75; -C14_CALFA6=-0.25; -C14_CALFA7=0.1; -C14_CALFA8=0.5; -C14_CALFA9=0.5; -C15_CALFA1=0.5; -C15_CALFA2=0.5; -C15_CALFA3=0.5; -C15_CALFA4=0; -C15_CALFA5=0.75; -C15_CALFA6=-0.25; -C15_CALFA7=0.1; -C15_CALFA8=0.5; -C15_CALFA9=0.5; -C16_CALFA1=0.5; -C16_CALFA2=0.5; -C16_CALFA3=0.5; -C16_CALFA4=0; -C16_CALFA5=0.75; -C16_CALFA6=-0.25; -C16_CALFA7=0.1; -C16_CALFA8=0.5; -C16_CALFA9=0.5; -C17_CALFA1=0.5; -C17_CALFA2=0.5; -C17_CALFA3=0.5; -C17_CALFA4=0; -C17_CALFA5=0.75; -C17_CALFA6=-0.25; -C17_CALFA7=0.1; -C17_CALFA8=0.5; -C17_CALFA9=0.5; -C18_CALFA1=0.5; -C18_CALFA2=0.5; -C18_CALFA3=0.5; -C18_CALFA4=0; -C18_CALFA5=0.75; -C18_CALFA6=-0.25; -C18_CALFA7=0.1; -C18_CALFA8=0.5; -C18_CALFA9=0.5; -C19_CALFA1=0.5; -C19_CALFA2=0.5; -C19_CALFA3=0.5; -C19_CALFA4=0; -C19_CALFA5=0.75; -C19_CALFA6=-0.25; -C19_CALFA7=0.1; -C19_CALFA8=0.5; -C19_CALFA9=0.5; -C1_CALFA1=0.5; -C1_CALFA2=0.5; -C1_CALFA3=0.5; -C1_CALFA4=0; -C1_CALFA5=0.75; -C1_CALFA6=-0.25; -C1_CALFA7=0.1; -C1_CALFA8=0.5; -C1_CALFA9=0.5; -C20_CALFA1=0.5; -C20_CALFA2=0.5; -C20_CALFA3=0.5; -C20_CALFA4=0; -C20_CALFA5=0.75; -C20_CALFA6=-0.25; -C20_CALFA7=0.1; -C20_CALFA8=0.5; -C20_CALFA9=0.5; -C2_CALFA1=0.5; -C2_CALFA2=0.5; -C2_CALFA3=0.5; -C2_CALFA4=0; -C2_CALFA5=0.75; -C2_CALFA6=-0.25; -C2_CALFA7=0.1; -C2_CALFA8=0.5; -C2_CALFA9=0.5; -C3_CALFA1=0.5; -C3_CALFA2=0.5; -C3_CALFA3=0.5; -C3_CALFA4=0; -C3_CALFA5=0.75; -C3_CALFA6=-0.25; -C3_CALFA7=0.1; -C3_CALFA8=0.5; -C3_CALFA9=0.5; -C4_CALFA1=0.5; -C4_CALFA2=0.5; -C4_CALFA3=0.5; -C4_CALFA4=0; -C4_CALFA5=0.75; -C4_CALFA6=-0.25; -C4_CALFA7=0.1; -C4_CALFA8=0.5; -C4_CALFA9=0.5; -C5_CALFA1=0.5; -C5_CALFA2=0.5; -C5_CALFA3=0.5; -C5_CALFA4=0; -C5_CALFA5=0.75; -C5_CALFA6=-0.25; -C5_CALFA7=0.1; -C5_CALFA8=0.5; -C5_CALFA9=0.5; -C6_CALFA1=0.5; -C6_CALFA2=0.5; -C6_CALFA3=0.5; -C6_CALFA4=0; -C6_CALFA5=0.75; -C6_CALFA6=-0.25; -C6_CALFA7=0.1; -C6_CALFA8=0.5; -C6_CALFA9=0.5; -C7_CALFA1=0.5; -C7_CALFA2=0.5; -C7_CALFA3=0.5; -C7_CALFA4=0; -C7_CALFA5=0.75; -C7_CALFA6=-0.25; -C7_CALFA7=0.1; -C7_CALFA8=0.5; -C7_CALFA9=0.5; -C8_CALFA1=0.5; -C8_CALFA2=0.5; -C8_CALFA3=0.5; -C8_CALFA4=0; -C8_CALFA5=0.75; -C8_CALFA6=-0.25; -C8_CALFA7=0.1; -C8_CALFA8=0.5; -C8_CALFA9=0.5; -C9_CALFA1=0.5; -C9_CALFA2=0.5; -C9_CALFA3=0.5; -C9_CALFA4=0; -C9_CALFA5=0.75; -C9_CALFA6=-0.25; -C9_CALFA7=0.1; -C9_CALFA8=0.5; -C9_CALFA9=0.5; -C10_PIESTAR=2.5; -C11_PIESTAR=2.5; -C12_PIESTAR=2.5; -C13_PIESTAR=2.5; -C14_PIESTAR=2.5; -C15_PIESTAR=2.5; -C16_PIESTAR=2.5; -C17_PIESTAR=2.5; -C18_PIESTAR=2.5; -C19_PIESTAR=2.5; -C1_PIESTAR=2.5; -C20_PIESTAR=2.5; -C2_PIESTAR=2.5; -C3_PIESTAR=2.5; -C4_PIESTAR=2.5; -C5_PIESTAR=2.5; -C6_PIESTAR=2.5; -C7_PIESTAR=2.5; -C8_PIESTAR=2.5; -C9_PIESTAR=2.5; - -model; - C1_PIE = C1_CALFA1*C1_PIE(1)+(1-C1_CALFA1)*C1_PIE(-1)+C1_CALFA2*(C1_Y+0.1)+C1_CALFA3*(C1_Y+0.1)^2/2+C1_EPIE ; - C1_Y = C1_CALFA4*C1_Y(1)+C1_CALFA5*C1_Y(-1)+C1_CALFA6*C1_RR+C1_EY+C1_CALFA7*(0+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C1_RR = C1_RS-C1_PIE(1) ; - C1_RS = C1_PIE(1)+C1_CALFA8*(C1_PIE-C1_PIESTAR)+C1_CALFA9*C1_Y+C1_ERS ; - C2_PIE = C2_CALFA1*C2_PIE(1)+(1-C2_CALFA1)*C2_PIE(-1)+C2_CALFA2*(C2_Y+0.1)+C2_CALFA3*(C2_Y+0.1)^2/2+C2_EPIE ; - C2_Y = C2_CALFA4*C2_Y(1)+C2_CALFA5*C2_Y(-1)+C2_CALFA6*C2_RR+C2_EY+C2_CALFA7*(0+C1_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C2_RR = C2_RS-C2_PIE(1) ; - C2_RS = C2_PIE(1)+C2_CALFA8*(C2_PIE-C2_PIESTAR)+C2_CALFA9*C2_Y+C2_ERS ; - C3_PIE = C3_CALFA1*C3_PIE(1)+(1-C3_CALFA1)*C3_PIE(-1)+C3_CALFA2*(C3_Y+0.1)+C3_CALFA3*(C3_Y+0.1)^2/2+C3_EPIE ; - C3_Y = C3_CALFA4*C3_Y(1)+C3_CALFA5*C3_Y(-1)+C3_CALFA6*C3_RR+C3_EY+C3_CALFA7*(0+C1_Y+C2_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C3_RR = C3_RS-C3_PIE(1) ; - C3_RS = C3_PIE(1)+C3_CALFA8*(C3_PIE-C3_PIESTAR)+C3_CALFA9*C3_Y+C3_ERS ; - C4_PIE = C4_CALFA1*C4_PIE(1)+(1-C4_CALFA1)*C4_PIE(-1)+C4_CALFA2*(C4_Y+0.1)+C4_CALFA3*(C4_Y+0.1)^2/2+C4_EPIE ; - C4_Y = C4_CALFA4*C4_Y(1)+C4_CALFA5*C4_Y(-1)+C4_CALFA6*C4_RR+C4_EY+C4_CALFA7*(0+C1_Y+C2_Y+C3_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C4_RR = C4_RS-C4_PIE(1) ; - C4_RS = C4_PIE(1)+C4_CALFA8*(C4_PIE-C4_PIESTAR)+C4_CALFA9*C4_Y+C4_ERS ; - C5_PIE = C5_CALFA1*C5_PIE(1)+(1-C5_CALFA1)*C5_PIE(-1)+C5_CALFA2*(C5_Y+0.1)+C5_CALFA3*(C5_Y+0.1)^2/2+C5_EPIE ; - C5_Y = C5_CALFA4*C5_Y(1)+C5_CALFA5*C5_Y(-1)+C5_CALFA6*C5_RR+C5_EY+C5_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C5_RR = C5_RS-C5_PIE(1) ; - C5_RS = C5_PIE(1)+C5_CALFA8*(C5_PIE-C5_PIESTAR)+C5_CALFA9*C5_Y+C5_ERS ; - C6_PIE = C6_CALFA1*C6_PIE(1)+(1-C6_CALFA1)*C6_PIE(-1)+C6_CALFA2*(C6_Y+0.1)+C6_CALFA3*(C6_Y+0.1)^2/2+C6_EPIE ; - C6_Y = C6_CALFA4*C6_Y(1)+C6_CALFA5*C6_Y(-1)+C6_CALFA6*C6_RR+C6_EY+C6_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C6_RR = C6_RS-C6_PIE(1) ; - C6_RS = C6_PIE(1)+C6_CALFA8*(C6_PIE-C6_PIESTAR)+C6_CALFA9*C6_Y+C6_ERS ; - C7_PIE = C7_CALFA1*C7_PIE(1)+(1-C7_CALFA1)*C7_PIE(-1)+C7_CALFA2*(C7_Y+0.1)+C7_CALFA3*(C7_Y+0.1)^2/2+C7_EPIE ; - C7_Y = C7_CALFA4*C7_Y(1)+C7_CALFA5*C7_Y(-1)+C7_CALFA6*C7_RR+C7_EY+C7_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C7_RR = C7_RS-C7_PIE(1) ; - C7_RS = C7_PIE(1)+C7_CALFA8*(C7_PIE-C7_PIESTAR)+C7_CALFA9*C7_Y+C7_ERS ; - C8_PIE = C8_CALFA1*C8_PIE(1)+(1-C8_CALFA1)*C8_PIE(-1)+C8_CALFA2*(C8_Y+0.1)+C8_CALFA3*(C8_Y+0.1)^2/2+C8_EPIE ; - C8_Y = C8_CALFA4*C8_Y(1)+C8_CALFA5*C8_Y(-1)+C8_CALFA6*C8_RR+C8_EY+C8_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C8_RR = C8_RS-C8_PIE(1) ; - C8_RS = C8_PIE(1)+C8_CALFA8*(C8_PIE-C8_PIESTAR)+C8_CALFA9*C8_Y+C8_ERS ; - C9_PIE = C9_CALFA1*C9_PIE(1)+(1-C9_CALFA1)*C9_PIE(-1)+C9_CALFA2*(C9_Y+0.1)+C9_CALFA3*(C9_Y+0.1)^2/2+C9_EPIE ; - C9_Y = C9_CALFA4*C9_Y(1)+C9_CALFA5*C9_Y(-1)+C9_CALFA6*C9_RR+C9_EY+C9_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C9_RR = C9_RS-C9_PIE(1) ; - C9_RS = C9_PIE(1)+C9_CALFA8*(C9_PIE-C9_PIESTAR)+C9_CALFA9*C9_Y+C9_ERS ; - C10_PIE = C10_CALFA1*C10_PIE(1)+(1-C10_CALFA1)*C10_PIE(-1)+C10_CALFA2*(C10_Y+0.1)+C10_CALFA3*(C10_Y+0.1)^2/2+C10_EPIE ; - C10_Y = C10_CALFA4*C10_Y(1)+C10_CALFA5*C10_Y(-1)+C10_CALFA6*C10_RR+C10_EY+C10_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C10_RR = C10_RS-C10_PIE(1) ; - C10_RS = C10_PIE(1)+C10_CALFA8*(C10_PIE-C10_PIESTAR)+C10_CALFA9*C10_Y+C10_ERS ; - C11_PIE = C11_CALFA1*C11_PIE(1)+(1-C11_CALFA1)*C11_PIE(-1)+C11_CALFA2*(C11_Y+0.1)+C11_CALFA3*(C11_Y+0.1)^2/2+C11_EPIE ; - C11_Y = C11_CALFA4*C11_Y(1)+C11_CALFA5*C11_Y(-1)+C11_CALFA6*C11_RR+C11_EY+C11_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C11_RR = C11_RS-C11_PIE(1) ; - C11_RS = C11_PIE(1)+C11_CALFA8*(C11_PIE-C11_PIESTAR)+C11_CALFA9*C11_Y+C11_ERS ; - C12_PIE = C12_CALFA1*C12_PIE(1)+(1-C12_CALFA1)*C12_PIE(-1)+C12_CALFA2*(C12_Y+0.1)+C12_CALFA3*(C12_Y+0.1)^2/2+C12_EPIE ; - C12_Y = C12_CALFA4*C12_Y(1)+C12_CALFA5*C12_Y(-1)+C12_CALFA6*C12_RR+C12_EY+C12_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C12_RR = C12_RS-C12_PIE(1) ; - C12_RS = C12_PIE(1)+C12_CALFA8*(C12_PIE-C12_PIESTAR)+C12_CALFA9*C12_Y+C12_ERS ; - C13_PIE = C13_CALFA1*C13_PIE(1)+(1-C13_CALFA1)*C13_PIE(-1)+C13_CALFA2*(C13_Y+0.1)+C13_CALFA3*(C13_Y+0.1)^2/2+C13_EPIE ; - C13_Y = C13_CALFA4*C13_Y(1)+C13_CALFA5*C13_Y(-1)+C13_CALFA6*C13_RR+C13_EY+C13_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C13_RR = C13_RS-C13_PIE(1) ; - C13_RS = C13_PIE(1)+C13_CALFA8*(C13_PIE-C13_PIESTAR)+C13_CALFA9*C13_Y+C13_ERS ; - C14_PIE = C14_CALFA1*C14_PIE(1)+(1-C14_CALFA1)*C14_PIE(-1)+C14_CALFA2*(C14_Y+0.1)+C14_CALFA3*(C14_Y+0.1)^2/2+C14_EPIE ; - C14_Y = C14_CALFA4*C14_Y(1)+C14_CALFA5*C14_Y(-1)+C14_CALFA6*C14_RR+C14_EY+C14_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C14_RR = C14_RS-C14_PIE(1) ; - C14_RS = C14_PIE(1)+C14_CALFA8*(C14_PIE-C14_PIESTAR)+C14_CALFA9*C14_Y+C14_ERS ; - C15_PIE = C15_CALFA1*C15_PIE(1)+(1-C15_CALFA1)*C15_PIE(-1)+C15_CALFA2*(C15_Y+0.1)+C15_CALFA3*(C15_Y+0.1)^2/2+C15_EPIE ; - C15_Y = C15_CALFA4*C15_Y(1)+C15_CALFA5*C15_Y(-1)+C15_CALFA6*C15_RR+C15_EY+C15_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C16_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C15_RR = C15_RS-C15_PIE(1) ; - C15_RS = C15_PIE(1)+C15_CALFA8*(C15_PIE-C15_PIESTAR)+C15_CALFA9*C15_Y+C15_ERS ; - C16_PIE = C16_CALFA1*C16_PIE(1)+(1-C16_CALFA1)*C16_PIE(-1)+C16_CALFA2*(C16_Y+0.1)+C16_CALFA3*(C16_Y+0.1)^2/2+C16_EPIE ; - C16_Y = C16_CALFA4*C16_Y(1)+C16_CALFA5*C16_Y(-1)+C16_CALFA6*C16_RR+C16_EY+C16_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C17_Y+C18_Y+C19_Y+C20_Y)/19 ; - C16_RR = C16_RS-C16_PIE(1) ; - C16_RS = C16_PIE(1)+C16_CALFA8*(C16_PIE-C16_PIESTAR)+C16_CALFA9*C16_Y+C16_ERS ; - C17_PIE = C17_CALFA1*C17_PIE(1)+(1-C17_CALFA1)*C17_PIE(-1)+C17_CALFA2*(C17_Y+0.1)+C17_CALFA3*(C17_Y+0.1)^2/2+C17_EPIE ; - C17_Y = C17_CALFA4*C17_Y(1)+C17_CALFA5*C17_Y(-1)+C17_CALFA6*C17_RR+C17_EY+C17_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C18_Y+C19_Y+C20_Y)/19 ; - C17_RR = C17_RS-C17_PIE(1) ; - C17_RS = C17_PIE(1)+C17_CALFA8*(C17_PIE-C17_PIESTAR)+C17_CALFA9*C17_Y+C17_ERS ; - C18_PIE = C18_CALFA1*C18_PIE(1)+(1-C18_CALFA1)*C18_PIE(-1)+C18_CALFA2*(C18_Y+0.1)+C18_CALFA3*(C18_Y+0.1)^2/2+C18_EPIE ; - C18_Y = C18_CALFA4*C18_Y(1)+C18_CALFA5*C18_Y(-1)+C18_CALFA6*C18_RR+C18_EY+C18_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C19_Y+C20_Y)/19 ; - C18_RR = C18_RS-C18_PIE(1) ; - C18_RS = C18_PIE(1)+C18_CALFA8*(C18_PIE-C18_PIESTAR)+C18_CALFA9*C18_Y+C18_ERS ; - C19_PIE = C19_CALFA1*C19_PIE(1)+(1-C19_CALFA1)*C19_PIE(-1)+C19_CALFA2*(C19_Y+0.1)+C19_CALFA3*(C19_Y+0.1)^2/2+C19_EPIE ; - C19_Y = C19_CALFA4*C19_Y(1)+C19_CALFA5*C19_Y(-1)+C19_CALFA6*C19_RR+C19_EY+C19_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C20_Y)/19 ; - C19_RR = C19_RS-C19_PIE(1) ; - C19_RS = C19_PIE(1)+C19_CALFA8*(C19_PIE-C19_PIESTAR)+C19_CALFA9*C19_Y+C19_ERS ; - C20_PIE = C20_CALFA1*C20_PIE(1)+(1-C20_CALFA1)*C20_PIE(-1)+C20_CALFA2*(C20_Y+0.1)+C20_CALFA3*(C20_Y+0.1)^2/2+C20_EPIE ; - C20_Y = C20_CALFA4*C20_Y(1)+C20_CALFA5*C20_Y(-1)+C20_CALFA6*C20_RR+C20_EY+C20_CALFA7*(0+C1_Y+C2_Y+C3_Y+C4_Y+C5_Y+C6_Y+C7_Y+C8_Y+C9_Y+C10_Y+C11_Y+C12_Y+C13_Y+C14_Y+C15_Y+C16_Y+C17_Y+C18_Y+C19_Y)/19 ; - C20_RR = C20_RS-C20_PIE(1) ; - C20_RS = C20_PIE(1)+C20_CALFA8*(C20_PIE-C20_PIESTAR)+C20_CALFA9*C20_Y+C20_ERS ; -end; - -initval; -C10_PIE=2.5; -C10_RR=0; -C10_RS=2.5; -C10_Y=0; -C11_PIE=2.5; -C11_RR=0; -C11_RS=2.5; -C11_Y=0; -C12_PIE=2.5; -C12_RR=0; -C12_RS=2.5; -C12_Y=0; -C13_PIE=2.5; -C13_RR=0; -C13_RS=2.5; -C13_Y=0; -C14_PIE=2.5; -C14_RR=0; -C14_RS=2.5; -C14_Y=0; -C15_PIE=2.5; -C15_RR=0; -C15_RS=2.5; -C15_Y=0; -C16_PIE=2.5; -C16_RR=0; -C16_RS=2.5; -C16_Y=0; -C17_PIE=2.5; -C17_RR=0; -C17_RS=2.5; -C17_Y=0; -C18_PIE=2.5; -C18_RR=0; -C18_RS=2.5; -C18_Y=0; -C19_PIE=2.5; -C19_RR=0; -C19_RS=2.5; -C19_Y=0; -C1_PIE=2.5; -C1_RR=0; -C1_RS=2.5; -C1_Y=0; -C20_PIE=2.5; -C20_RR=0; -C20_RS=2.5; -C20_Y=0; -C2_PIE=2.5; -C2_RR=0; -C2_RS=2.5; -C2_Y=0; -C3_PIE=2.5; -C3_RR=0; -C3_RS=2.5; -C3_Y=0; -C4_PIE=2.5; -C4_RR=0; -C4_RS=2.5; -C4_Y=0; -C5_PIE=2.5; -C5_RR=0; -C5_RS=2.5; -C5_Y=0; -C6_PIE=2.5; -C6_RR=0; -C6_RS=2.5; -C6_Y=0; -C7_PIE=2.5; -C7_RR=0; -C7_RS=2.5; -C7_Y=0; -C8_PIE=2.5; -C8_RR=0; -C8_RS=2.5; -C8_Y=0; -C9_PIE=2.5; -C9_RR=0; -C9_RS=2.5; -C9_Y=0; -C1_EPIE=0; -C1_EY=0; -C1_ERS=0; -C2_EPIE=0; -C2_EY=0; -C2_ERS=0; -C3_EPIE=0; -C3_EY=0; -C3_ERS=0; -C4_EPIE=0; -C4_EY=0; -C4_ERS=0; -C5_EPIE=0; -C5_EY=0; -C5_ERS=0; -C6_EPIE=0; -C6_EY=0; -C6_ERS=0; -C7_EPIE=0; -C7_EY=0; -C7_ERS=0; -C8_EPIE=0; -C8_EY=0; -C8_ERS=0; -C9_EPIE=0; -C9_EY=0; -C9_ERS=0; -C10_EPIE=0; -C10_EY=0; -C10_ERS=0; -C11_EPIE=0; -C11_EY=0; -C11_ERS=0; -C12_EPIE=0; -C12_EY=0; -C12_ERS=0; -C13_EPIE=0; -C13_EY=0; -C13_ERS=0; -C14_EPIE=0; -C14_EY=0; -C14_ERS=0; -C15_EPIE=0; -C15_EY=0; -C15_ERS=0; -C16_EPIE=0; -C16_EY=0; -C16_ERS=0; -C17_EPIE=0; -C17_EY=0; -C17_ERS=0; -C18_EPIE=0; -C18_EY=0; -C18_ERS=0; -C19_EPIE=0; -C19_EY=0; -C19_ERS=0; -C20_EPIE=0; -C20_EY=0; -C20_ERS=0; -end; - -vcov = [ -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -]; - -order = 1; - diff --git a/dynare++/tests/czech2.mod b/dynare++/tests/czech2.mod deleted file mode 100644 index 2e7adeb785fc5b17f19408c2226f34b086cec925..0000000000000000000000000000000000000000 --- a/dynare++/tests/czech2.mod +++ /dev/null @@ -1,712 +0,0 @@ -var PIE4EU ZZ_PIE4EU ZZ_RNOMEU GDPGAPEU ZZ_DRNOMEU AF AH BIGGAMF BIGGAMH BIGGAMIMPF BIGGAMIMPH BIGGAMMF BIGGAMMH BIGGAMNF BIGGAMNH BIGGAMQF BIGGAMQH BIGGAM_MONF BIGGAM_MONH BIGGAM_MOTF BIGGAM_MOTH BIGGAM_O_NF BIGGAM_O_NH BIGGAM_O_TF BIGGAM_O_TH CAPAF CAPAH CF CF_NAT CH CH_NAT CURBALF_RAT CURBALH_RAT DEEF DEEH DEPEX EXPORTSF EXPORTSF_NAT EXPORTSH EXPORTSH_NAT EYEF EYEH GAF GAH GAMMAF GAMMAH GDPF GDPF_NAT GDPGAPF GDPGAPH GDPH GDPH_NAT GF_NAT GH_NAT GNF GNH HF HH IMPORTSF IMPORTSF_NAT IMPORTSH IMPORTSH_NAT KF KH KNF KNF_RAT KNH KNH_RAT KTF KTF_RAT KTH KTH_RAT K_OF K_OF_RAT K_OH K_OH_RAT LANDF LANDH LF LH LNF LNH LTF LTH L_OF L_OH MARGUTF MARGUTH MF MF_NAT MH MH_NAT M_ONF M_ONH M_OTF M_OTH NF NH NNF NNH O_NF O_NH O_TF O_TH PIE4F PIE4H PIE4TARF PIE4TARH PIEBARMF PIEBARMH PIEBARQF PIEBARQH PIEF PIEH PIENF PIENH PIEWF PIEWH PSIF PSIH PSIPRIMEF PSIPRIMEH QF QH Q_ONF Q_ONH Q_OTF Q_OTH REALBF REALBH REALEX REALEXF REALEXH REALFINH REALMCNF REALMCNH REALMCTF REALMCTH REALMONEYF REALMONEYH REALPBARMF REALPBARMH REALPBARQF REALPBARQH REALPLANDF REALPLANDH REALPMF REALPMH REALPNF REALPNH REALPQF REALPQH REALPXF REALPXH REALP_MOF REALP_MOH REALP_ONF REALP_ONH REALP_OTF REALP_OTH REALP_QOF REALP_QOH REALRF REALRH REALTBALF REALTBALH REALWF REALWH RNOMF RNOMH SHOPF SHOPH SHOPPRIMEF SHOPPRIMEH TF TH T_OF T_OH VELOF VELOH VPRIMEF VPRIMEH XF_NAT XH_NAT XI ZBF ZBH ZEYEF ZEYEH ZNF ZNH ZTF ZTH ZUF ZUH ZZ_CF ZZ_CH ZZ_CURBALF_RAT ZZ_CURBALH_RAT ZZ_C_SHARF ZZ_C_SHARH ZZ_DPIE4F ZZ_DPIE4H ZZ_DRNOMF ZZ_DRNOMH ZZ_EXPORTSF ZZ_EXPORTSH ZZ_EYEF ZZ_EYEH ZZ_EYE_SHARF ZZ_EYE_SHARH ZZ_GDPF ZZ_GDPH ZZ_GDP_PPP_RATH ZZ_GF ZZ_GH ZZ_IMPORTSF ZZ_IMPORTSH ZZ_M_ON_SHARF ZZ_M_ON_SHARH ZZ_M_OT_SHARF ZZ_M_OT_SHARH ZZ_M_O_SHARF ZZ_M_O_SHARH ZZ_M_SHARF ZZ_M_SHARH ZZ_N_SHARF ZZ_N_SHARH ZZ_PIE4F ZZ_PIE4H ZZ_REALEX ZZ_RNOMF ZZ_RNOMH ZZ_UTILITYF ZZ_UTILITYH ZZ_XBALF_TOT_RAT ZZ_XBALH_TOT_RAT Z_OF Z_OH PIEH_1 PIEH_2 PIEF_1 PIEF_2 REALBH_1 VALUE VALUE2; - -varexo E_ZBH E_ZUH E_ZUF E_ZEYEH E_ZEYEF E_GAMMAH E_GAMMAF E_LANDH E_LANDF E_GAH E_GAF E_CAPAH E_CAPAF; - -parameters COSTLF COSTLH EPSF EPSH EPSQMF EPSQMH GLAMBDAF GLAMBDAH SIGMAF SIGMAH SSF SSH XR1F XR1H XR2F XR2H XR3F XR3H XR4F XR4H ALPHANF ALPHANH ALPHATF ALPHATH ALPHA_OF ALPHA_OH A_ONEF A_ONEH A_ZEROF A_ZEROH B0F B0H B1F B1H B2F B2H BET CAPAF_SS CAPAH_SS CHI0 CHI1 CHI2 CHI3 COSTF COSTH COST_MONF COST_MONH COST_MOTF COST_MOTH COST_O_NF COST_O_NH COST_O_TF COST_O_TH DELTAF DELTAH EPS_ONF EPS_ONH EPS_OTF EPS_OTH ETAF ETAH E_PIE4TARF E_PIE4TARH E_ZBF GAMA_NF GAMA_NH GAMA_TF GAMA_TH GAMMAF_SS GAMMAH_SS GAMMA_LANDF GAMMA_LANDH GA_RATF GA_RATH GDPF_EXOG GDPH_EXOG GN_RATF GN_RATH LANDF_SS LANDH_SS LILCAPPA1F LILCAPPA1H LILCAPPA2F LILCAPPA2H LILCAPPA3F LILCAPPA3H LILCAPPA4F LILCAPPA4H LILCAPPA5F LILCAPPA5H LILCAPPA6F LILCAPPA6H LILCAPPA7F LILCAPPA7H LILCAPPA8F LILCAPPA8H NYF NYH NY_NF NY_NH NY_TF NY_TH OMEGA0F OMEGA0H OMEGAF OMEGAH PHIF PHIH PIE4TARF_SS PIE4TARH_SS REALEX_EXOG REALPBARMF_EXOG REALPBARMH_EXOG REALPNF_EXOG REALPNH_EXOG REALP_MOF_EXOG REALP_MOH_EXOG RNOM_EXOGF RNOM_EXOGH THETAF THETAH XDUMF XDUMH XIXI_NF XIXI_NH XIXI_OF XIXI_OH XIXI_TF XIXI_TH ZBF_SS ZBH_SS ZEDF ZEDH ZEYEF_SS ZEYEH_SS ZNF_SS ZNH_SS ZTF_SS ZTH_SS ZUF_SS ZUH_SS Z_OF_SS Z_OH_SS; - -COSTLF=5; -COSTLH=5; -EPSF=1.1; -EPSH=1.1; -EPSQMF=4; -EPSQMH=1.1; -GLAMBDAF=0; -GLAMBDAH=0; -SIGMAF=0.333333333333333; -SIGMAH=0.333333333333333; -SSF=0.95; -SSH=0.05; -XR1F=1; -XR1H=1; -XR2F=0; -XR2H=0; -XR3F=0.5; -XR3H=0.5; -XR4F=0; -XR4H=0; -ALPHANF=0.33; -ALPHANH=0.4; -ALPHATF=0.33; -ALPHATH=0.4; -ALPHA_OF=0.2; -ALPHA_OH=0.2; -A_ONEF=0.075; -A_ONEH=0.075; -A_ZEROF=0.011; -A_ZEROH=0.011; -B0F=1; -B0H=1; -B1F=0.95; -B1H=0.95; -B2F=1; -B2H=1; -BET=0.99263753614514; -CAPAF_SS=11; -CAPAH_SS=11; -CHI0=0.05; -CHI1=.1; -CHI2=0; -CHI3=0; -COSTF=5; -COSTH=5; -COST_MONF=5; -COST_MONH=5; -COST_MOTF=5; -COST_MOTH=5; -COST_O_NF=5; -COST_O_NH=5; -COST_O_TF=5; -COST_O_TH=5; -DELTAF=0.025; -DELTAH=0.025; -EPS_ONF=3; -EPS_ONH=3; -EPS_OTF=3; -EPS_OTH=3; -ETAF=0.35; -ETAH=0.2; -E_PIE4TARF=0; -E_PIE4TARH=0; -E_ZBF=0; -GAMA_NF=0.3; -GAMA_NH=0.1; -GAMA_TF=0.3; -GAMA_TH=0.5; -GAMMAF_SS=0.5; -GAMMAH_SS=0.25; -GAMMA_LANDF=0.1; -GAMMA_LANDH=0.1; -GA_RATF=0.05; -GA_RATH=0.05; -GDPF_EXOG=2.41500497257461; -GDPH_EXOG=2.90512477822209; -GN_RATF=0.1; -GN_RATH=0.1; -LANDF_SS=0.1; -LANDH_SS=0.1; -LILCAPPA1F=0; -LILCAPPA1H=0; -LILCAPPA2F=800; -LILCAPPA2H=400; -LILCAPPA3F=0; -LILCAPPA3H=0; -LILCAPPA4F=800; -LILCAPPA4H=400; -LILCAPPA5F=0; -LILCAPPA5H=0; -LILCAPPA6F=800; -LILCAPPA6H=400; -LILCAPPA7F=0; -LILCAPPA7H=0; -LILCAPPA8F=0; -LILCAPPA8H=0; -NYF=0.98; -NYH=0.0499999999999999; -NY_NF=0.98; -NY_NH=0.0499999999999999; -NY_TF=0.98; -NY_TH=0.02; -OMEGA0F=60; -OMEGA0H=60; -OMEGAF=5; -OMEGAH=5; -PHIF=3; -PHIH=3; -PIE4TARF_SS=1.125; -PIE4TARH_SS=1.125; -REALEX_EXOG=1.3734519289908; -REALPBARMF_EXOG=0.87146958398196; -REALPBARMH_EXOG=1.19072687148694; -REALPNF_EXOG=0.840675522925242; -REALPNH_EXOG=0.902486321747893; -REALP_MOF_EXOG=0.966533486000563; -REALP_MOH_EXOG=1.63690883121281; -RNOM_EXOGF=1.00741707177773; -RNOM_EXOGH=1.00741707177773; -THETAF=6; -THETAH=6; -XDUMF=1; -XDUMH=1; -XIXI_NF=0.75; -XIXI_NH=0.75; -XIXI_OF=0.75; -XIXI_OH=0.75; -XIXI_TF=0.75; -XIXI_TH=0.75; -ZBF_SS=0; -ZBH_SS=0; -ZEDF=2.5; -ZEDH=2.5; -ZEYEF_SS=0; -ZEYEH_SS=0; -ZNF_SS=1; -ZNH_SS=1; -ZTF_SS=1; -ZTH_SS=0.6; -ZUF_SS=1; -ZUH_SS=1; -Z_OF_SS=1; -Z_OH_SS=1; - -model; -PIE4EU = SSH*PIE4H+(1-SSH)*PIE4F; -ZZ_PIE4EU = SSH*ZZ_PIE4H+(1-SSH)*ZZ_PIE4F; -ZZ_RNOMEU = SSH*ZZ_RNOMH+(1-SSH)*ZZ_RNOMF; - -ZZ_DRNOMEU = SSH*ZZ_DRNOMH+(1-SSH)*ZZ_DRNOMF; -GDPGAPEU = SSH*GDPGAPH+(1-SSH)*GDPGAPF; - - ZZ_UTILITYH = (ZUH*(CH-HH)^(1-SIGMAH)-1)/(1-SIGMAH)-CAPAH*LH^(1+ZEDH)/(1+ZEDH) ; - ZZ_GH = 100*log(GH_NAT) ; - ZZ_CURBALH_RAT = CURBALH_RAT*100 ; - ZZ_M_SHARH = REALPBARMH*MH/AH ; - ZZ_M_O_SHARH = (REALP_MOH*M_ONH+REALP_MOH*M_OTH)/AH ; - ZZ_M_ON_SHARH = REALP_MOH*M_ONH/AH ; - ZZ_M_OT_SHARH = REALP_MOH*M_OTH/AH ; - ZZ_N_SHARH = NH*REALPNH/AH ; - ZZ_EYE_SHARH = EYEH/GDPH ; - ZZ_C_SHARH = CH/GDPH ; - ZZ_GDPH = 100*log(GDPH_NAT) ; - ZZ_CH = 100*log(CH_NAT) ; - ZZ_EYEH = 100*log(EYEH) ; - ZZ_EXPORTSH = 100*log(EXPORTSH_NAT) ; - ZZ_IMPORTSH = 100*log(IMPORTSH_NAT) ; - ZZ_XBALH_TOT_RAT = 100*(EXPORTSH_NAT-IMPORTSH_NAT)/GDPH_NAT ; - ZZ_PIE4H = 100*(PIE4H-1) ; - ZZ_DPIE4H = ZZ_PIE4H-ZZ_PIE4H(-1) ; - ZZ_RNOMH = 100*(RNOMH^4-1) ; - ZZ_DRNOMH = ZZ_RNOMH-ZZ_RNOMH(-1) ; - 100*(PIE4TARH-1) = 1*100*(PIE4TARH_SS-1)+(1-1)*100*(PIE4TARH(-1)-1)+E_PIE4TARH ; - log(ZUH) = 0.3*log(ZUH_SS)+0.7*log(ZUH(-1))+E_ZUH ; - ZBH = 0.3*ZBH_SS+0.7*ZBH(-1)+E_ZBH ; - log(LANDH) = 0.05*log(LANDH_SS)+0.95*log(LANDH(-1))+E_LANDH ; - log(ZTH) = 0.05*log(ZTH_SS)+0.95*log(ZTH(-1))+E_LANDH ; - log(ZNH) = 0.05*log(ZNH_SS)+0.95*log(ZNH(-1))+E_LANDH ; - log(Z_OH) = 0.05*log(Z_OH_SS)+0.95*log(Z_OH(-1))+E_LANDH ; - ZEYEH = 0.05*ZEYEH_SS+0.95*ZEYEH(-1)+E_ZEYEH ; - CAPAH = 0.05*CAPAH_SS+0.95*CAPAH(-1)+E_CAPAH ; - log(GAMMAH) = 0.05*log(GAMMAH_SS)+0.95*log(GAMMAH(-1))+E_GAMMAH ; - BIGGAM_O_NH = 1-COST_O_NH/2*(O_NH/NH/(O_NH(-1)/NH(-1))-1)^2 ; - BIGGAM_O_TH = 1-COST_O_TH/2*(O_TH/TH/(O_TH(-1)/TH(-1))-1)^2 ; - O_NH = GAMA_NH*NH/ZNH*(REALP_ONH/(REALMCNH*ZNH))^(-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^XIXI_NH/BIGGAM_O_NH ; - O_TH = GAMA_TH*TH/ZTH*(REALP_OTH/(REALMCTH*ZTH))^(-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^XIXI_NH/BIGGAM_O_TH ; - NH = ZNH*((1-ALPHANH-GAMA_NH)^(1/XIXI_NH)*LNH^(1-1/XIXI_NH)+ALPHANH^(1/XIXI_NH)*KNH^(1-1/XIXI_NH)+GAMA_NH^(1/XIXI_NH)*(BIGGAM_O_NH*O_NH)^(1-1/XIXI_NH))^(XIXI_NH/(XIXI_NH-1)) ; - TH = ZTH*((1-ALPHATH-GAMA_TH)^(1/XIXI_TH)*LTH^(1-1/XIXI_TH)+ALPHATH^(1/XIXI_TH)*KTH^(1-1/XIXI_TH)+GAMA_TH^(1/XIXI_TH)*(BIGGAM_O_TH*O_TH)^(1-1/XIXI_TH))^(XIXI_TH/(XIXI_TH-1)) ; - REALMCNH = 1/ZNH*((1-ALPHANH-GAMA_NH)*REALWH^(1-XIXI_NH)+ALPHANH*REALRH^(1-XIXI_NH)+GAMA_NH*REALP_ONH^(1-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^(XIXI_NH-1))^(1/(1-XIXI_NH)) ; - REALMCTH = 1/ZTH*((1-ALPHATH-GAMA_TH)*REALWH^(1-XIXI_TH)+ALPHATH*REALRH^(1-XIXI_TH)+GAMA_TH*REALP_OTH^(1-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^(XIXI_TH-1))^(1/(1-XIXI_TH)) ; - MARGUTH = (CH-B2H*HH)^(-SIGMAH)*ZUH ; - HH = (1-B0H)*HH(-1)+B0H*B1H*CH(-1) ; - VPRIMEH = CAPAH*LH^ZEDH ; - AH^(1-1/EPSH) = GAMMAH^(1/EPSH)*(NYH^(1/EPSQMH)*QH^(1-1/EPSQMH)+(1-NYH)^(1/EPSQMH)*(MH*BIGGAMIMPH)^(1-1/EPSQMH))^(EPSQMH/(EPSQMH-1)*(1-1/EPSH))+(1-GAMMAH)^(1/EPSH)*NNH^(1-1/EPSH) ; - QH = GAMMAH*NYH*REALPQH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH) ; - MH = GAMMAH*(1-NYH)*REALPMH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH)*1/BIGGAMIMPH*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^EPSQMH ; - REALPXH = (NYH*REALPQH^(1-EPSQMH)+(1-NYH)*REALPMH^(1-EPSQMH)*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^(EPSQMH-1))^(1/(1-EPSQMH)) ; - BIGGAMIMPH = 1-COSTH/2*(MH/AH/(MH(-1)/AH(-1))-1)^2 ; - NNH = (1-GAMMAH)*REALPNH^(-EPSH)*AH ; - NH = NNH+ETAH*MH+ETAH*QH+GNH ; - PIENH = REALPNH/REALPNH(-1)*PIEH ; - BIGGAMNH = LILCAPPA3H/2*(PIENH/PIE4TARH^0.25-1)^2+LILCAPPA4H/2*(PIENH/PIENH(-1)-1)^2 ; - -(1-BIGGAMNH)*(REALPNH*(1-THETAH)+THETAH*REALMCNH) = -(REALPNH-REALMCNH)*(LILCAPPA3H*PIENH/PIE4TARH^0.25*(PIENH/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH/PIENH(-1)*(PIENH/PIENH(-1)-1))+DEEH*PIEH(+1)*(REALPNH(+1)-REALMCNH(+1))*NH(+1)/NH*(LILCAPPA3H*PIENH(+1)/PIE4TARH^0.25*(PIENH(+1)/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH(+1)/PIENH*(PIENH(+1)/PIENH-1)) ; - PIEBARQH = PIEH*REALPBARQH/REALPBARQH(-1) ; - BIGGAMQH = LILCAPPA5H/2*(PIEBARQH/PIE4TARH^0.25-1)^2+LILCAPPA6H/2*(PIEBARQH/PIEBARQH(-1)-1)^2 ; - -(1-BIGGAMQH)*REALPBARQH/REALPQH*(REALPBARQH*(1-THETAH)+ETAH*REALPNH+THETAH*REALMCTH) = -(REALPBARQH-REALMCTH)*(LILCAPPA5H*PIEBARQH/PIE4TARH^0.25*(PIEBARQH/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH/PIEBARQH(-1)*(PIEBARQH/PIEBARQH(-1)-1))+DEEH*PIEH(+1)*(REALPBARQH(+1)-REALMCTH(+1))*QH(+1)/QH*(LILCAPPA5H*PIEBARQH(+1)/PIE4TARH^0.25*(PIEBARQH(+1)/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH(+1)/PIEBARQH*(PIEBARQH(+1)/PIEBARQH-1)) ; - REALPQH = REALPBARQH+ETAH*REALPNH ; - KH = KH(-1)*(1-DELTAH)+PSIH(-1)*KH(-1) ; - PSIH = EYEH/KH-OMEGAH/2*(EYEH/KH-DELTAH*(1+ZEYEH))^2-OMEGA0H/2*(EYEH/KH-EYEH(-1)/KH(-1))^2 ; - PSIPRIMEH = 1-OMEGAH*(EYEH/KH-DELTAH*(1+ZEYEH))-OMEGA0H*(EYEH/KH-EYEH(-1)/KH(-1)) ; - 1/PSIPRIMEH = DEEH*PIEH(+1)*(REALRH(+1)+1/PSIPRIMEH(+1)*(1-DELTAH+PSIH(+1)*(1-PSIPRIMEH(+1)*EYEH(+1)/(PSIH(+1)*KH(+1))))) ; - BIGGAMH = LILCAPPA1H/2*(PIEWH/PIE4TARH^0.25-1)^2+LILCAPPA2H/2*(PIEWH/PIEWH(-1)-1)^2 ; - PIEH*REALWH/REALWH(-1) = PIEWH ; - REALWH = PHIH*VPRIMEH/MARGUTH*((PHIH-1)*(1-BIGGAMH)+PIEWH*LILCAPPA1H/PIE4TARH^0.25*(PIEWH/PIE4TARH^0.25-1)+PIEWH/PIEWH(-1)*LILCAPPA2H*(PIEWH/PIEWH(-1)-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA1H*PIEWH(+1)/PIE4TARH^0.25*(PIEWH(+1)/PIE4TARH^0.25-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA2H*PIEWH(+1)/(REALWH/REALWH(-1))*(PIEWH(+1)/PIEWH-1))^(-1) ; - DEEH = BET*MARGUTH(+1)/PIEH(+1)/MARGUTH*(1+SHOPH+SHOPPRIMEH*VELOH)/(1+SHOPH(+1)+SHOPPRIMEH(+1)*VELOH(+1)) ; - SHOPH = A_ZEROH*VELOH+A_ONEH/VELOH-2*(A_ZEROH*A_ONEH)^0.5 ; - SHOPPRIMEH = A_ZEROH-A_ONEH*VELOH^(-2) ; - VELOH = CH/REALMONEYH ; - DEEH = 1-SHOPPRIMEH*VELOH^2 ; - 1 = RNOMH*DEEH ; -/* - 100*(RNOMH^4-1) = (1-XDUMH)*100*(RNOM_EXOGH^4-1)+XDUMH*(XR3H*100*(RNOMH(-1)^4-1)+(1-XR3H)*(100*((1/BET*PIE4H^0.25)^4-1))+XR1H*(100*(PIE4H-1)-100*(PIE4TARH-1))+XR4H*100*(DEPEX^4-1)+XR2H*GDPGAPH) ; -*/ - 100*(RNOMH^4-1) = 100*(RNOMH(-1)^4-1)+1000*100*(DEPEX^4-1); - GDPGAPH = 100*(GDPH_NAT-GDPH_EXOG)/GDPH_EXOG ; - PIE4H = PIEH*PIEH(-1)*PIEH_1(-1)*PIEH_2(-1) ; - AH = CH*(1+SHOPH)+EYEH+GAH ; - GAH = .05*(GA_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG))+.95*GAH(-1)+E_GAH; - GNH = GN_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG)/REALPNH_EXOG ; - PIEBARMH = PIEH*REALPBARMH/REALPBARMH(-1) ; - BIGGAMMH = LILCAPPA7H/2*(PIEBARMH/PIE4TARH^0.25-1)^2+LILCAPPA8H/2*(PIEBARMH/PIEBARMH(-1)-1)^2 ; - REALPMH = REALPBARMH+ETAH*REALPNH ; - KNH_RAT = ALPHANH/(1-ALPHANH-GAMA_NH)*(REALWH/REALRH)^XIXI_NH ; - KTH_RAT = ALPHATH/(1-ALPHATH-GAMA_TH)*(REALWH/REALRH)^XIXI_TH ; - KNH_RAT = KNH/LNH ; - KTH_RAT = KTH/LTH ; - KH = KTH+KNH+K_OH ; - LH = (LNH+LTH+L_OH)*(1-COSTLH/2*(LNH/(LTH+L_OH)/(LNH(-1)/(LTH(-1)+L_OH(-1)))-1)^2) ; - T_OH = Z_OH*((1-ALPHA_OH-GAMMA_LANDH)^(1/XIXI_OH)*L_OH^(1-1/XIXI_OH)+ALPHA_OH^(1/XIXI_OH)*K_OH^(1-1/XIXI_OH)+GAMMA_LANDH^(1/XIXI_OH)*LANDH^(1-1/XIXI_OH))^(XIXI_OH/(XIXI_OH-1)) ; - Q_ONH = NY_NH*(REALP_QOH/REALP_ONH)^(-EPS_ONH)*O_NH ; - Q_OTH = NY_TH*(REALP_QOH/REALP_OTH)^(-EPS_OTH)*O_TH ; - M_ONH = (1-NY_NH)*(REALP_MOH/REALP_ONH)^(-EPS_ONH)*O_NH*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^EPS_ONH/BIGGAM_MONH ; - M_OTH = (1-NY_TH)*(REALP_MOH/REALP_OTH)^(-EPS_OTH)*O_TH*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^EPS_OTH/BIGGAM_MOTH ; - BIGGAM_MONH = 1-COST_MONH/2*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)^2 ; - BIGGAM_MOTH = 1-COST_MOTH/2*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)^2 ; - K_OH_RAT = ALPHA_OH/(1-ALPHA_OH-GAMMA_LANDH)*(REALWH/REALRH)^XIXI_OH ; - K_OH_RAT = K_OH/L_OH ; - REALP_QOH = 1/Z_OH*((1-ALPHA_OH-GAMMA_LANDH)*REALWH^(1-XIXI_OH)+ALPHA_OH*REALRH^(1-XIXI_OH)+GAMMA_LANDH*REALPLANDH^(1-XIXI_OH))^(1/(1-XIXI_OH)) ; - LANDH = GAMMA_LANDH*(REALPLANDH/(REALP_QOH*Z_OH))^(-XIXI_OH)*T_OH/Z_OH ; - REALP_ONH = (NY_NH*REALP_QOH^(1-EPS_ONH)+(1-NY_NH)*REALP_MOH^(1-EPS_ONH)*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^(EPS_ONH-1))^(1/(1-EPS_ONH)) ; - REALP_OTH = (NY_TH*REALP_QOH^(1-EPS_OTH)+(1-NY_TH)*REALP_MOH^(1-EPS_OTH)*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^(EPS_OTH-1))^(1/(1-EPS_OTH)) ; - SSH*TH = SSH*QH+SSF*MF ; - SSH*T_OH = SSH*Q_ONH+SSH*Q_OTH+SSF*M_ONF+SSF*M_OTF ; - REALP_MOH = REALP_QOF*REALEXH ; - ZZ_GDP_PPP_RATH = GDPH/REALEX/GDPF ; - XI = CHI0*(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH_1(-1)/PIEF(-1))/GDPH(-1))^2-1)/(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH_1(-1)/PIEF(-1))/GDPH(-1))^2+1)+ZBH ; - 1 = RNOMF*(1-XI)*DEEH*DEPEX(+1) ; - DEPEX = PIEH/PIEF*REALEX/REALEX(-1) ; - REALFINH = RNOMF(-1)*(1-XI(-1))*REALEX*REALBH(-1)/PIEF ; - SSH*DEEH*PIEH(+1)*REALFINH(+1) = SSH*REALFINH+SSH*RNOMF(-1)*XI(-1)*REALEX*REALBH(-1)/PIEF+REALTBALH ; - REALEXH = REALEX ; - REALEXF = 1/REALEXH ; - ZZ_REALEX = 100*log(REALEX) ; - -(1-BIGGAMMH)*REALPBARMH/REALPMH*(REALPBARMH/REALEX*(1-THETAF)+ETAH*REALPNH/REALEX+THETAF*REALMCTF) = -(REALPBARMH/REALEX-REALMCTF)*(LILCAPPA7H*PIEBARMH/PIE4TARH^0.25*(PIEBARMH/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH/PIEBARMH(-1)*(PIEBARMH/PIEBARMH(-1)-1))+DEEF*PIEF(+1)*(REALPBARMH(+1)/REALEX(+1)-REALMCTF(+1))*MH(+1)/MH*(LILCAPPA7H*PIEBARMH(+1)/PIE4TARH^0.25*(PIEBARMH(+1)/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH(+1)/PIEBARMH*(PIEBARMH(+1)/PIEBARMH-1)) ; - GDPH = AH+REALPNH*GNH+EXPORTSH-IMPORTSH+(RNOMF(-1)-1)*REALEX*REALBH(-1)/PIEF ; - GDPH_NAT = AH+REALPNH_EXOG*GNH+EXPORTSH_NAT-IMPORTSH_NAT ; - CH_NAT = CH*(1+SHOPH) ; - GH_NAT = GAH+REALPNH_EXOG*GNH ; - XH_NAT = SSF/SSH*REALEX_EXOG*REALPBARMF_EXOG*MF ; - MH_NAT = REALPBARMH_EXOG*MH ; - CURBALH_RAT = REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH ; - REALTBALH = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH) ; - EXPORTSH = SSF/SSH*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX ; - IMPORTSH = REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH ; - EXPORTSH_NAT = SSF/SSH*(REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF)*REALEX_EXOG ; - IMPORTSH_NAT = REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH ; - ZZ_UTILITYF = (ZUF*(CF-HF)^(1-SIGMAF)-1)/(1-SIGMAF)-CAPAF*LF^(1+ZEDF)/(1+ZEDF) ; - ZZ_GF = 100*log(GF_NAT) ; - ZZ_CURBALF_RAT = CURBALF_RAT*100 ; - ZZ_M_SHARF = REALPBARMF*MF/AF ; - ZZ_M_O_SHARF = (REALP_MOF*M_ONF+REALP_MOF*M_OTF)/AF ; - ZZ_M_ON_SHARF = REALP_MOF*M_ONF/AF ; - ZZ_M_OT_SHARF = REALP_MOF*M_OTF/AF ; - ZZ_N_SHARF = NF*REALPNF/AF ; - ZZ_EYE_SHARF = EYEF/GDPF ; - ZZ_C_SHARF = CF/GDPF ; - ZZ_GDPF = 100*log(GDPF_NAT) ; - ZZ_CF = 100*log(CF_NAT) ; - ZZ_EYEF = 100*log(EYEF) ; - ZZ_EXPORTSF = 100*log(EXPORTSF_NAT) ; - ZZ_IMPORTSF = 100*log(IMPORTSF_NAT) ; - ZZ_XBALF_TOT_RAT = 100*(EXPORTSF_NAT-IMPORTSF_NAT)/GDPF_NAT ; - ZZ_PIE4F = 100*(PIE4F-1) ; - ZZ_DPIE4F = ZZ_PIE4F-ZZ_PIE4F(-1) ; - ZZ_RNOMF = 100*(RNOMF^4-1) ; - ZZ_DRNOMF = ZZ_RNOMF-ZZ_RNOMF(-1) ; - 100*(PIE4TARF-1) = 1*100*(PIE4TARF_SS-1)+(1-1)*100*(PIE4TARF(-1)-1)+E_PIE4TARF ; - log(ZUF) = 0.3*log(ZUF_SS)+0.7*log(ZUF(-1))+E_ZUF ; - ZBF = 0.3*ZBF_SS+0.7*ZBF(-1)+E_ZBF ; - log(LANDF) = 0.05*log(LANDF_SS)+0.95*log(LANDF(-1))+E_LANDF ; - log(ZTF) = 0.05*log(ZTF_SS)+0.95*log(ZTF(-1))+E_LANDF ; - log(ZNF) = 0.05*log(ZNF_SS)+0.95*log(ZNF(-1))+E_LANDF ; - log(Z_OF) = 0.05*log(Z_OF_SS)+0.95*log(Z_OF(-1))+E_LANDF ; - ZEYEF = 0.05*ZEYEF_SS+0.95*ZEYEF(-1)+E_ZEYEF ; - CAPAF = 0.05*CAPAF_SS+0.95*CAPAF(-1)+E_CAPAF ; - log(GAMMAF) = 0.05*log(GAMMAF_SS)+0.95*log(GAMMAF(-1))+E_GAMMAF ; - BIGGAM_O_NF = 1-COST_O_NF/2*(O_NF/NF/(O_NF(-1)/NF(-1))-1)^2 ; - BIGGAM_O_TF = 1-COST_O_TF/2*(O_TF/TF/(O_TF(-1)/TF(-1))-1)^2 ; - O_NF = GAMA_NF*NF/ZNF*(REALP_ONF/(REALMCNF*ZNF))^(-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^XIXI_NF/BIGGAM_O_NF ; - O_TF = GAMA_TF*TF/ZTF*(REALP_OTF/(REALMCTF*ZTF))^(-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^XIXI_NF/BIGGAM_O_TF ; - NF = ZNF*((1-ALPHANF-GAMA_NF)^(1/XIXI_NF)*LNF^(1-1/XIXI_NF)+ALPHANF^(1/XIXI_NF)*KNF^(1-1/XIXI_NF)+GAMA_NF^(1/XIXI_NF)*(BIGGAM_O_NF*O_NF)^(1-1/XIXI_NF))^(XIXI_NF/(XIXI_NF-1)) ; - TF = ZTF*((1-ALPHATF-GAMA_TF)^(1/XIXI_TF)*LTF^(1-1/XIXI_TF)+ALPHATF^(1/XIXI_TF)*KTF^(1-1/XIXI_TF)+GAMA_TF^(1/XIXI_TF)*(BIGGAM_O_TF*O_TF)^(1-1/XIXI_TF))^(XIXI_TF/(XIXI_TF-1)) ; - REALMCNF = 1/ZNF*((1-ALPHANF-GAMA_NF)*REALWF^(1-XIXI_NF)+ALPHANF*REALRF^(1-XIXI_NF)+GAMA_NF*REALP_ONF^(1-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^(XIXI_NF-1))^(1/(1-XIXI_NF)) ; - REALMCTF = 1/ZTF*((1-ALPHATF-GAMA_TF)*REALWF^(1-XIXI_TF)+ALPHATF*REALRF^(1-XIXI_TF)+GAMA_TF*REALP_OTF^(1-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^(XIXI_TF-1))^(1/(1-XIXI_TF)) ; - MARGUTF = (CF-B2F*HF)^(-SIGMAF)*ZUF ; - HF = (1-B0F)*HF(-1)+B0F*B1F*CF(-1) ; - VPRIMEF = CAPAF*LF^ZEDF ; - AF^(1-1/EPSF) = GAMMAF^(1/EPSF)*(NYF^(1/EPSQMF)*QF^(1-1/EPSQMF)+(1-NYF)^(1/EPSQMF)*(MF*BIGGAMIMPF)^(1-1/EPSQMF))^(EPSQMF/(EPSQMF-1)*(1-1/EPSF))+(1-GAMMAF)^(1/EPSF)*NNF^(1-1/EPSF) ; - QF = GAMMAF*NYF*REALPQF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF) ; - MF = GAMMAF*(1-NYF)*REALPMF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF)*1/BIGGAMIMPF*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^EPSQMF ; - REALPXF = (NYF*REALPQF^(1-EPSQMF)+(1-NYF)*REALPMF^(1-EPSQMF)*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^(EPSQMF-1))^(1/(1-EPSQMF)) ; - BIGGAMIMPF = 1-COSTF/2*(MF/AF/(MF(-1)/AF(-1))-1)^2 ; - NNF = (1-GAMMAF)*REALPNF^(-EPSF)*AF ; - NF = NNF+ETAF*MF+ETAF*QF+GNF ; - PIENF = REALPNF/REALPNF(-1)*PIEF ; - BIGGAMNF = LILCAPPA3F/2*(PIENF/PIE4TARF^0.25-1)^2+LILCAPPA4F/2*(PIENF/PIENF(-1)-1)^2 ; - -(1-BIGGAMNF)*(REALPNF*(1-THETAF)+THETAF*REALMCNF) = -(REALPNF-REALMCNF)*(LILCAPPA3F*PIENF/PIE4TARF^0.25*(PIENF/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF/PIENF(-1)*(PIENF/PIENF(-1)-1))+DEEF*PIEF(+1)*(REALPNF(+1)-REALMCNF(+1))*NF(+1)/NF*(LILCAPPA3F*PIENF(+1)/PIE4TARF^0.25*(PIENF(+1)/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF(+1)/PIENF*(PIENF(+1)/PIENF-1)) ; - PIEBARQF = PIEF*REALPBARQF/REALPBARQF(-1) ; - BIGGAMQF = LILCAPPA5F/2*(PIEBARQF/PIE4TARF^0.25-1)^2+LILCAPPA6F/2*(PIEBARQF/PIEBARQF(-1)-1)^2 ; - -(1-BIGGAMQF)*REALPBARQF/REALPQF*(REALPBARQF*(1-THETAF)+ETAF*REALPNF+THETAF*REALMCTF) = -(REALPBARQF-REALMCTF)*(LILCAPPA5F*PIEBARQF/PIE4TARF^0.25*(PIEBARQF/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF/PIEBARQF(-1)*(PIEBARQF/PIEBARQF(-1)-1))+DEEF*PIEF(+1)*(REALPBARQF(+1)-REALMCTF(+1))*QF(+1)/QF*(LILCAPPA5F*PIEBARQF(+1)/PIE4TARF^0.25*(PIEBARQF(+1)/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF(+1)/PIEBARQF*(PIEBARQF(+1)/PIEBARQF-1)) ; - REALPQF = REALPBARQF+ETAF*REALPNF ; - KF = KF(-1)*(1-DELTAF)+PSIF(-1)*KF(-1) ; - PSIF = EYEF/KF-OMEGAF/2*(EYEF/KF-DELTAF*(1+ZEYEF))^2-OMEGA0F/2*(EYEF/KF-EYEF(-1)/KF(-1))^2 ; - PSIPRIMEF = 1-OMEGAF*(EYEF/KF-DELTAF*(1+ZEYEF))-OMEGA0F*(EYEF/KF-EYEF(-1)/KF(-1)) ; - 1/PSIPRIMEF = DEEF*PIEF(+1)*(REALRF(+1)+1/PSIPRIMEF(+1)*(1-DELTAF+PSIF(+1)*(1-PSIPRIMEF(+1)*EYEF(+1)/(PSIF(+1)*KF(+1))))) ; - BIGGAMF = LILCAPPA1F/2*(PIEWF/PIE4TARF^0.25-1)^2+LILCAPPA2F/2*(PIEWF/PIEWF(-1)-1)^2 ; - PIEF*REALWF/REALWF(-1) = PIEWF ; - REALWF = PHIF*VPRIMEF/MARGUTF*((PHIF-1)*(1-BIGGAMF)+PIEWF*LILCAPPA1F/PIE4TARF^0.25*(PIEWF/PIE4TARF^0.25-1)+PIEWF/PIEWF(-1)*LILCAPPA2F*(PIEWF/PIEWF(-1)-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA1F*PIEWF(+1)/PIE4TARF^0.25*(PIEWF(+1)/PIE4TARF^0.25-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA2F*PIEWF(+1)/(REALWF/REALWF(-1))*(PIEWF(+1)/PIEWF-1))^(-1) ; - DEEF = BET*MARGUTF(+1)/PIEF(+1)/MARGUTF*(1+SHOPF+SHOPPRIMEF*VELOF)/(1+SHOPF(+1)+SHOPPRIMEF(+1)*VELOF(+1)) ; - SHOPF = A_ZEROF*VELOF+A_ONEF/VELOF-2*(A_ZEROF*A_ONEF)^0.5 ; - SHOPPRIMEF = A_ZEROF-A_ONEF*VELOF^(-2) ; - VELOF = CF/REALMONEYF ; - DEEF = 1-SHOPPRIMEF*VELOF^2 ; - 1 = RNOMF*DEEF ; - - 100*(RNOMF^4-1) = (1-XDUMF)*100*(RNOM_EXOGF^4-1) - +XDUMF*(XR3F*100*(RNOMF(-1)^4-1)+ - (1-XR3F)*(100*((1/BET*PIE4EU^0.25)^4-1)) - +XR1F*(100*(PIE4EU-1)-100*(PIE4TARF-1))+XR4F*100*(DEPEX^4-1)+XR2F*GDPGAPEU) ; - - - - GDPGAPF = 100*(GDPF_NAT-GDPF_EXOG)/GDPF_EXOG ; - PIE4F = PIEF*PIEF(-1)*PIEF_1(-1)*PIEF_2(-1) ; - AF = CF*(1+SHOPF)+EYEF+GAF ; - GAF = .05*(GA_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG))+.95*GAF(-1)+E_GAF; - GNF = GN_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG)/REALPNF_EXOG ; - PIEBARMF = PIEF*REALPBARMF/REALPBARMF(-1) ; - BIGGAMMF = LILCAPPA7F/2*(PIEBARMF/PIE4TARF^0.25-1)^2+LILCAPPA8F/2*(PIEBARMF/PIEBARMF(-1)-1)^2 ; - REALPMF = REALPBARMF+ETAF*REALPNF ; - KNF_RAT = ALPHANF/(1-ALPHANF-GAMA_NF)*(REALWF/REALRF)^XIXI_NF ; - KTF_RAT = ALPHATF/(1-ALPHATF-GAMA_TF)*(REALWF/REALRF)^XIXI_TF ; - KNF_RAT = KNF/LNF ; - KTF_RAT = KTF/LTF ; - KF = KTF+KNF+K_OF ; - LF = (LNF+LTF+L_OF)*(1-COSTLF/2*(LNF/(LTF+L_OF)/(LNF(-1)/(LTF(-1)+L_OF(-1)))-1)^2) ; - T_OF = Z_OF*((1-ALPHA_OF-GAMMA_LANDF)^(1/XIXI_OF)*L_OF^(1-1/XIXI_OF)+ALPHA_OF^(1/XIXI_OF)*K_OF^(1-1/XIXI_OF)+GAMMA_LANDF^(1/XIXI_OF)*LANDF^(1-1/XIXI_OF))^(XIXI_OF/(XIXI_OF-1)) ; - Q_ONF = NY_NF*(REALP_QOF/REALP_ONF)^(-EPS_ONF)*O_NF ; - Q_OTF = NY_TF*(REALP_QOF/REALP_OTF)^(-EPS_OTF)*O_TF ; - M_ONF = (1-NY_NF)*(REALP_MOF/REALP_ONF)^(-EPS_ONF)*O_NF*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^EPS_ONF/BIGGAM_MONF ; - M_OTF = (1-NY_TF)*(REALP_MOF/REALP_OTF)^(-EPS_OTF)*O_TF*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^EPS_OTF/BIGGAM_MOTF ; - BIGGAM_MONF = 1-COST_MONF/2*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)^2 ; - BIGGAM_MOTF = 1-COST_MOTF/2*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)^2 ; - K_OF_RAT = ALPHA_OF/(1-ALPHA_OF-GAMMA_LANDF)*(REALWF/REALRF)^XIXI_OF ; - K_OF_RAT = K_OF/L_OF ; - REALP_QOF = 1/Z_OF*((1-ALPHA_OF-GAMMA_LANDF)*REALWF^(1-XIXI_OF)+ALPHA_OF*REALRF^(1-XIXI_OF)+GAMMA_LANDF*REALPLANDF^(1-XIXI_OF))^(1/(1-XIXI_OF)) ; - LANDF = GAMMA_LANDF*(REALPLANDF/(REALP_QOF*Z_OF))^(-XIXI_OF)*T_OF/Z_OF ; - REALP_ONF = (NY_NF*REALP_QOF^(1-EPS_ONF)+(1-NY_NF)*REALP_MOF^(1-EPS_ONF)*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^(EPS_ONF-1))^(1/(1-EPS_ONF)) ; - REALP_OTF = (NY_TF*REALP_QOF^(1-EPS_OTF)+(1-NY_TF)*REALP_MOF^(1-EPS_OTF)*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^(EPS_OTF-1))^(1/(1-EPS_OTF)) ; - SSF*TF = SSF*QF+SSH*MH ; - SSF*T_OF = SSF*Q_ONF+SSF*Q_OTF+SSH*M_ONH+SSH*M_OTH ; - REALP_MOF = REALP_QOH*REALEXF ; - SSH*REALBH+SSF*REALBF = 0 ; - REALTBALF = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - EXPORTSF = SSH/SSF*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - IMPORTSF = REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF ; - EXPORTSF_NAT = SSH/SSF*(REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH)*1/REALEX_EXOG ; - IMPORTSF_NAT = REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF ; - -(1-BIGGAMMF)*REALPBARMF/REALPMF*(REALPBARMF*REALEX*(1-THETAH)+ETAF*REALPNF*REALEX+THETAH*REALMCTH) = -(REALPBARMF*REALEX-REALMCTH)*(LILCAPPA7F*PIEBARMF/PIE4TARF^0.25*(PIEBARMF/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF/PIEBARMF(-1)*(PIEBARMF/PIEBARMF(-1)-1))+DEEH*PIEH(+1)*(REALPBARMF(+1)*REALEX(+1)-REALMCTH(+1))*MF(+1)/MF*(LILCAPPA7F*PIEBARMF(+1)/PIE4TARF^0.25*(PIEBARMF(+1)/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF(+1)/PIEBARMF*(PIEBARMF(+1)/PIEBARMF-1)) ; - GDPF = AF+REALPNF*GNF+EXPORTSF-IMPORTSF+(RNOMF(-1)-1)*REALBF(-1)/PIEF ; - GDPF_NAT = AF+REALPNF_EXOG*GNF+EXPORTSF_NAT-IMPORTSF_NAT ; - CF_NAT = CF*(1+SHOPF) ; - GF_NAT = GAF+REALPNF_EXOG*GNF ; - XF_NAT = SSH/SSF*1/REALEX_EXOG*REALPBARMH_EXOG*MH ; - MF_NAT = REALPBARMF_EXOG*MF ; - CURBALF_RAT = -(REALTBALH/REALEX/SSF/GDPF)+(RNOMF(-1)-1)*REALBF(-1)/PIEF/GDPF ; -PIEH_1 = PIEH(-1); -PIEH_2 = PIEH_1(-1); -PIEF_1 = PIEF(-1); -PIEF_2 = PIEF_1(-1); -REALBH_1 = REALBH(-1); - -VALUE = ZZ_UTILITYH + BET*VALUE(+1); -VALUE2 = ZUH*CH^(1-SIGMAH)/(1-SIGMAH)-CAPAH*LH^(1+ZEDH)/(1+ZEDH) + BET*VALUE2(+1); -end; - -initval; -AF=2.17350447531715; -AH=2.61461230039988; -BIGGAMF=0; -BIGGAMH=0; -BIGGAMIMPF=1; -BIGGAMIMPH=1; -BIGGAMMF=0; -BIGGAMMH=0; -BIGGAMNF=0; -BIGGAMNH=0; -BIGGAMQF=0; -BIGGAMQH=0; -BIGGAM_MONF=1; -BIGGAM_MONH=1; -BIGGAM_MOTF=1; -BIGGAM_MOTH=1; -BIGGAM_O_NF=1; -BIGGAM_O_NH=1; -BIGGAM_O_TF=1; -BIGGAM_O_TH=1; -CAPAF=11; -CAPAH=11; -CF=1.77599320017707; -CF_NAT=1.77797456682707; -CH=2.10139281352027; -CH_NAT=2.10373720855446; -CURBALF_RAT=2.20209042676066e-018; -CURBALH_RAT=0; -DEEF=0.963834712172592; -DEEH=0.963834712172592; -DEPEX=1; -EXPORTSF=0.0374229290542059; -EXPORTSF_NAT=0.0374229290542059; -EXPORTSH=0.976573287861717; -EXPORTSH_NAT=0.976573287861717; -EYEF=0.27477965986135; -EYEH=0.365618852934316; -GAF=0.12075024862873; -GAH=0.145256238911104; -GAMMAF=0.5; -GAMMAH=0.25; -GDPF=2.41500497257461; -GDPF_NAT=2.41500497257461; -GDPGAPF=0; -GDPGAPH=0; -GDPH=2.90512477822209; -GDPH_NAT=2.90512477822209; -GF_NAT=0.362250745886191; -GH_NAT=0.435768716733313; -GNF=0.287269571519256; -GNH=0.321902361090147; -HF=1.68719354016822; -HH=1.99632317284426; -IMPORTSF=0.0374229290542059; -IMPORTSF_NAT=0.0374229290542059; -IMPORTSH=0.976573287861718; -IMPORTSH_NAT=0.976573287861718; -KF=10.991186394454; -KH=14.6247541173726; -KNF=6.33686501417153; -KNF_RAT=22.6981730731029; -KNH=11.034700665508; -KNH_RAT=22.8755992006951; -KTF=2.97137434524903; -KTF_RAT=22.6981730731029; -KTH=2.23720856941572; -KTH_RAT=114.377996003476; -K_OF=1.68294703503345; -K_OF_RAT=7.27127622255245; -K_OH=1.35284488244891; -K_OH_RAT=8.16985685739111; -LANDF=0.1; -LANDH=0.1; -LF=0.64153899810027; -LH=0.667528221502678; -LNF=0.279179517830034; -LNH=0.482378650224502; -LTF=0.130908083909629; -LTH=0.019559781143112; -L_OF=0.231451396360608; -L_OH=0.165589790135064; -MARGUTF=2.24145263303312; -MARGUTH=2.11921125101343; -MF=0.0196445696804563; -MF_NAT=0.0171196449669319; -MH=0.438784845846124; -MH_NAT=0.522472906750236; -M_ONF=0.0143006671963624; -M_ONH=0.134410532365428; -M_OTF=0.00670562423725087; -M_OTH=0.143002828997546; -NF=1.91582345366461; -NH=2.609674642079; -NNF=1.31534385473198; -NNH=2.19524942542191; -O_NF=0.387338325509274; -O_NH=0.147043832240678; -O_TF=0.18162406186278; -O_TH=0.148205762233076; -PIE4F=1.125; -PIE4H=1.125; -PIE4TARF=1.125; -PIE4TARH=1.125; -PIEBARMF=1.02988357195356; -PIEBARMH=1.02988357195356; -PIEBARQF=1.02988357195356; -PIEBARQH=1.02988357195356; -PIEF=1.02988357195356; -PIEF_1=1.02988357195356; -PIEF_2=1.02988357195356; -PIEH=1.02988357195356; -PIEH_1=1.02988357195356; -PIEH_2=1.02988357195356; -PIENF=1.02988357195356; -PIENH=1.02988357195356; -PIEWF=1.02988357195356; -PIEWH=1.02988357195356; -PSIF=0.025; -PSIH=0.025; -PSIPRIMEF=1; -PSIPRIMEH=1; -QF=0.875241222929181; -QH=0.0238294319885835; -Q_ONF=0.373740369418894; -Q_ONH=0.0132636199615755; -Q_OTF=0.175247940896905; -Q_OTH=0.00547180886242481; -REALBF=0; -REALBH=0; -REALBH_1=0; -REALEX=1.3734519289908; -REALEXF=0.728092464608345; -REALEXH=1.3734519289908; -REALFINH=0; -REALMCNF=0.700562935771035; -REALMCNH=0.752071934789911; -REALMCTF=0.700562935771035; -REALMCTH=0.930081384894704; -REALMONEYF=0.558667031035572; -REALMONEYH=0.661026677383566; -REALPBARMF=0.87146958398196; -REALPBARMH=1.19072687148694; -REALPBARQF=0.899522809530009; -REALPBARQH=1.15219711474356; -REALPLANDF=0.554831427212494; -REALPLANDH=0.414697221827051; -REALPMF=1.16570601700579; -REALPMH=1.37122413583652; -REALPNF=0.840675522925242; -REALPNH=0.902486321747893; -REALPQF=1.19375924255384; -REALPQH=1.33269437909314; -REALPXF=1.19317131724075; -REALPXH=1.36926881180313; -REALP_MOF=0.966533486000563; -REALP_MOH=1.63690883121281; -REALP_ONF=1.18566549908199; -REALP_ONH=1.61601524261254; -REALP_OTF=1.18566549908199; -REALP_OTH=1.62845456685201; -REALP_QOF=1.1918209852569; -REALP_QOH=1.32748728078168; -REALRF=0.0324170717777328; -REALRH=0.0324170717777329; -REALTBALF=-6.93889390390723e-018; -REALTBALH=-6.93889390390723e-018; -REALWF=2.42667732699502; -REALWH=2.83454771236558; -RNOMF=1.03752229232945; -RNOMH=1.03752229232945; -SHOPF=0.00111563864647424; -SHOPH=0.00111563864647424; -SHOPPRIMEF=0.00357861859467432; -SHOPPRIMEH=0.00357861859467432; -TF=0.89833516218424; -TH=0.397076255917254; -T_OF=0.563589013545429; -T_OH=0.417854966062653; -VALUE=-2.621110285550203e+02; -VALUE2=2.305114066037580e+02; -VELOF=3.17898336847443; -VELOH=3.17898336847443; -VPRIMEF=3.62618818940983; -VPRIMEH=4.00467026905301; -XF_NAT=0.0200215045456245; -XH_NAT=0.446747178665936; -XI=0; -ZBF=0; -ZBH=0; -ZEYEF=0; -ZEYEH=0; -ZNF=1; -ZNH=1; -ZTF=1; -ZTH=0.6; -ZUF=1; -ZUH=1; -ZZ_CF=57.5474832617676; -ZZ_CH=74.3715386197541; -ZZ_CURBALF_RAT=2.20209042676066e-016; -ZZ_CURBALH_RAT=0; -ZZ_C_SHARF=0.735399396831762; -ZZ_C_SHARH=0.723339950584259; -ZZ_DPIE4F=0; -ZZ_DPIE4H=0; -ZZ_DRNOMF=0; -ZZ_DRNOMH=0; -ZZ_EXPORTSF=-328.547168610049; -ZZ_EXPORTSH=-2.37054799079326; -ZZ_EYEF=-129.17857393452; -ZZ_EYEH=-100.616387362469; -ZZ_EYE_SHARF=0.113780163180538; -ZZ_EYE_SHARH=0.12585306341233; -ZZ_GDPF=88.1701346139521; -ZZ_GDPH=106.647634229781; -ZZ_GDP_PPP_RATH=0.875857186130553; -ZZ_GF=-101.541863874636; -ZZ_GH=-83.0643642588075; -ZZ_IMPORTSF=-328.547168610049; -ZZ_IMPORTSH=-2.37054799079323; -ZZ_M_ON_SHARF=0.0063593490946998; -ZZ_M_ON_SHARH=0.084149297164759; -ZZ_M_OT_SHARF=0.00298191719568198; -ZZ_M_OT_SHARH=0.0895286056899133; -ZZ_M_O_SHARF=0.00934126629038178; -ZZ_M_O_SHARH=0.173677902854672; -ZZ_M_SHARF=0.00787651700806085; -ZZ_M_SHARH=0.19982806118916; -ZZ_N_SHARF=0.741008772713445; -ZZ_N_SHARH=0.90078198910348; -ZZ_PIE4F=12.5; -ZZ_PIE4H=12.5; -ZZ_REALEX=31.7327227026121; -ZZ_RNOMF=15.8749999999999; -ZZ_RNOMH=15.8749999999999; -ZZ_UTILITYF=-1.86610854895021; -ZZ_UTILITYH=-1.9297829736965; -ZZ_XBALF_TOT_RAT=0; -ZZ_XBALH_TOT_RAT=-7.6432037132987e-015; -Z_OF=1; -Z_OH=1; - -E_ZBH=0; - -E_ZUH=0; -E_ZUF=0; - -E_ZEYEH=0; -E_ZEYEF=0; - -E_GAMMAH=0; -E_GAMMAF=0; - -E_LANDH=0; -E_LANDF=0; - -E_GAH = 0; -E_GAF = 0; - -E_CAPAH=0; -E_CAPAF=0; - -ZZ_PIE4EU= 12.5; -ZZ_RNOMEU=15.8749999999999; -GDPGAPEU= 0; -ZZ_DRNOMEU=0; -PIE4EU = 1.125; -end; - -vcov = [ -/* E_ZBH 0.000289 */ - 0.000289 0 0 0 0 0 0 0 0 0 0 0 0; -/* E_ZUH */ -0 0.000016 0 0 0 0 0 0 0 0 0 0 0; -/* E_ZUF */ -0 0 0.000001 0 0 0 0 0 0 0 0 0 0; -/* E_ZEYEH */ -0 0 0 0.0049 0 0 0 0 0 0 0 0 0; -/* E_ZEYEF */ -0 0 0 0 0.000025 0 0 0 0 0 0 0 0; -/* E_GAMMAH */ -0 0 0 0 0 0.0004 0 0 0 0 0 0 0; -/* E_GAMMAF */ -0 0 0 0 0 0 0.000324 0 0 0 0 0 0; -/* E_LANDH */ -0 0 0 0 0 0 0 0.000004 0 0 0 0 0; -/* E_LANDF */ -0 0 0 0 0 0 0 0 0.00000001 0 0 0 0; -/* E_GAH */ -0 0 0 0 0 0 0 0 0 0.00001225 0 0 0; -/* E_GAF */ -0 0 0 0 0 0 0 0 0 0 0.0000005625 0 0; -/* E_CAPAH */ -0 0 0 0 0 0 0 0 0 0 0 0.1 0; -/* E_CAPAF */ -0 0 0 0 0 0 0 0 0 0 0 0 0.0001 -]; - -order = 2; \ No newline at end of file diff --git a/dynare++/tests/dm7.mod b/dynare++/tests/dm7.mod deleted file mode 100644 index 0a31faf4b466af0f07cca1cbaefe6759f46cc103..0000000000000000000000000000000000000000 --- a/dynare++/tests/dm7.mod +++ /dev/null @@ -1,40 +0,0 @@ -var C K r w N tau I; -varexo e; - -parameters alph bet delt thet tau_m rho; -alph = 0.3; -bet = 0.96; -thet = 0.3; -delt = 0.05; -tau_m = 0.35; -rho = 0.8; - -model; -C = C(+1)/(bet*(r(+1)+1-delt)); -I = K(-1)^alph*N^(1-alph)-C; -K = I+(1-delt)*K(-1); -N = 1-(1-thet)*C/(thet*w); -r = (1-tau)*alph*(K(-1)/N)^(alph-1); -w = (1-tau)*(1-alph)*(K(-1)/N)^alph; -tau = (1-rho)*tau_m + rho*tau(-1)+e; -end; - -initval; -C=0.2; -I=0.02; -K=0.5; -N=0.18; -r=0.09; -w=0.6; -tau=0.35; -e=0; -end; - -vcov = [0.007208]; - -order=7; - - - - - diff --git a/dynare++/tests/example1.mod b/dynare++/tests/example1.mod deleted file mode 100644 index ca528c0d9a6aaa7652fcb3fb9dc845c00926374f..0000000000000000000000000000000000000000 --- a/dynare++/tests/example1.mod +++ /dev/null @@ -1,41 +0,0 @@ -// this is an example from the tutorial - -var Y, C, K, A, H, B; - -varexo EPS, NU; - -parameters rho, beta, alpha, delta, theta, psi, tau; -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 1/(1.03^0.25); -delta = 0.025; -psi = 0; -theta = 2.95; - - -model; -C*theta*H^(1+psi) = (1-alpha)*Y; -beta*exp(B)*C/exp(B(1))/C(1)* - (exp(B(1))*alpha*Y(1)/K(1)+1-delta) = 1; -Y = exp(A)*K^alpha*H^(1-alpha); -K = exp(B(-1))*(Y(-1)-C(-1)) + (1-delta)*K(-1); -A = rho*A(-1) + tau*B(-1) + EPS; -B = tau*A(-1) + rho*B(-1) + NU; -end; - -initval; -A = 0; -B = 0; -H = ((1-alpha)/(theta*(1-(delta*alpha)/(1/beta-1+delta))))^(1/(1+psi)); -Y = (alpha/(1/beta-1+delta))^(alpha/(1-alpha))*H; -K = alpha/(1/beta-1+delta)*Y; -C = Y - delta*K; -end; - -vcov = [ - 0.0002 0.00005; - 0.00005 0.0001 -]; - -order = 7; diff --git a/dynare++/tests/example1_optim.mod b/dynare++/tests/example1_optim.mod deleted file mode 100644 index 0bd57477c7b3dbfb2f36058406daba905729a9d2..0000000000000000000000000000000000000000 --- a/dynare++/tests/example1_optim.mod +++ /dev/null @@ -1,43 +0,0 @@ -// this is a file trying to replicate example1.mod as optimization of a social planner -// it serves also as an example combining +2 lead and optimal policy - -var Y, C, K, A, H, B; - -varexo EPS, NU; - -parameters rho, beta, alpha, delta, theta, psi, tau; -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 1/(1.03^0.25); -delta = 0.025; -psi = 0; -theta = 2.95; - -planner_objective log(C)-theta*H^(1+psi)/(1+psi); - -planner_discount beta; - -model; -//Y = exp(A)*K^alpha*H^(1-alpha); -Y = exp(A)*exp(A(+1))*exp(A(+2))*K^alpha*H^(1-alpha); -K = exp(B(-1))*(Y(-1)-C(-1)) + (1-delta)*K(-1); -A = rho*A(-1) + tau*B(-1) + EPS; -B = tau*A(-1) + rho*B(-1) + NU; -end; - -initval; -A = 0; -B = 0; -H = ((1-alpha)/(theta*(1-(delta*alpha)/(1/beta-1+delta))))^(1/(1+psi)); -Y = (alpha/(1/beta-1+delta))^(alpha/(1-alpha))*H; -K = alpha/(1/beta-1+delta)*Y; -C = Y - delta*K; -end; - -vcov = [ - 0.0002 0.00005; - 0.00005 0.0001 -]; - -order = 2; diff --git a/dynare++/tests/gentay1a.mod b/dynare++/tests/gentay1a.mod deleted file mode 100644 index 8c2a9566d6104daba72f1a09268667ff889056c2..0000000000000000000000000000000000000000 --- a/dynare++/tests/gentay1a.mod +++ /dev/null @@ -1,671 +0,0 @@ -var AF AH BIGGAMF BIGGAMH BIGGAMIMPF BIGGAMIMPH BIGGAMMF BIGGAMMH BIGGAMNF BIGGAMNH BIGGAMQF BIGGAMQH BIGGAM_MONF BIGGAM_MONH BIGGAM_MOTF BIGGAM_MOTH BIGGAM_O_NF BIGGAM_O_NH BIGGAM_O_TF BIGGAM_O_TH CAPAF CAPAH CF CF_NAT CH CH_NAT CURBALF_RAT CURBALH_RAT DEEF DEEH DEPEX EXPORTSF EXPORTSF_NAT EXPORTSH EXPORTSH_NAT EYEF EYEH GAF GAH GAMMAF GAMMAH GDPF GDPF_NAT GDPGAPF GDPGAPH GDPH GDPH_NAT GF_NAT GH_NAT GNF GNH HF HH IMPORTSF IMPORTSF_NAT IMPORTSH IMPORTSH_NAT KF KH KNF KNF_RAT KNH KNH_RAT KTF KTF_RAT KTH KTH_RAT K_OF K_OF_RAT K_OH K_OH_RAT LANDF LANDH LF LH LNF LNH LTF LTH L_OF L_OH MARGUTF MARGUTH MF MF_NAT MH MH_NAT M_ONF M_ONH M_OTF M_OTH NF NH NNF NNH O_NF O_NH O_TF O_TH PIE4F PIE4H PIE4TARF PIE4TARH PIEBARMF PIEBARMH PIEBARQF PIEBARQH PIEF PIEH PIENF PIENH PIEWF PIEWH PSIF PSIH PSIPRIMEF PSIPRIMEH QF QH Q_ONF Q_ONH Q_OTF Q_OTH REALBF REALBH REALEX REALEXF REALEXH REALFINH REALMCNF REALMCNH REALMCTF REALMCTH REALMONEYF REALMONEYH REALPBARMF REALPBARMH REALPBARQF REALPBARQH REALPLANDF REALPLANDH REALPMF REALPMH REALPNF REALPNH REALPQF REALPQH REALPXF REALPXH REALP_MOF REALP_MOH REALP_ONF REALP_ONH REALP_OTF REALP_OTH REALP_QOF REALP_QOH REALRF REALRH REALTBALF REALTBALH REALWF REALWH RNOMF RNOMH SHOPF SHOPH SHOPPRIMEF SHOPPRIMEH TF TH T_OF T_OH VELOF VELOH VPRIMEF VPRIMEH XF_NAT XH_NAT XI ZBF ZBH ZEYEF ZEYEH ZNF ZNH ZTF ZTH ZUF ZUH ZZ_CF ZZ_CH ZZ_CURBALF_RAT ZZ_CURBALH_RAT ZZ_C_SHARF ZZ_C_SHARH ZZ_DPIE4F ZZ_DPIE4H ZZ_DRNOMF ZZ_DRNOMH ZZ_EXPORTSF ZZ_EXPORTSH ZZ_EYEF ZZ_EYEH ZZ_EYE_SHARF ZZ_EYE_SHARH ZZ_GDPF ZZ_GDPH ZZ_GDP_PPP_RATH ZZ_GF ZZ_GH ZZ_IMPORTSF ZZ_IMPORTSH ZZ_M_ON_SHARF ZZ_M_ON_SHARH ZZ_M_OT_SHARF ZZ_M_OT_SHARH ZZ_M_O_SHARF ZZ_M_O_SHARH ZZ_M_SHARF ZZ_M_SHARH ZZ_N_SHARF ZZ_N_SHARH ZZ_PIE4F ZZ_PIE4H ZZ_REALEX ZZ_RNOMF ZZ_RNOMH ZZ_UTILITYF ZZ_UTILITYH ZZ_XBALF_TOT_RAT ZZ_XBALH_TOT_RAT Z_OF Z_OH PIEF1 PIEF2 PIEH1 PIEH2 REALBH1; - -varexo E_ZBH E_ZUH E_ZUF E_ZEYEH E_ZEYEF E_GAMMAH E_GAMMAF E_LANDH E_LANDF E_GAH E_GAF E_CAPAH E_CAPAF; - -parameters COSTLF COSTLH EPSF EPSH EPSQMF EPSQMH GLAMBDAF GLAMBDAH SIGMAF SIGMAH SSF SSH XR1F XR1H XR2F XR2H XR3F XR3H XR4F XR4H ALPHANF ALPHANH ALPHATF ALPHATH ALPHA_OF ALPHA_OH A_ONEF A_ONEH A_ZEROF A_ZEROH B0F B0H B1F B1H B2F B2H BET CAPAF_SS CAPAH_SS CHI0 CHI1 CHI2 CHI3 COSTF COSTH COST_MONF COST_MONH COST_MOTF COST_MOTH COST_O_NF COST_O_NH COST_O_TF COST_O_TH DELTAF DELTAH EPS_ONF EPS_ONH EPS_OTF EPS_OTH ETAF ETAH E_PIE4TARF E_PIE4TARH E_ZBF GAMA_NF GAMA_NH GAMA_TF GAMA_TH GAMMAF_SS GAMMAH_SS GAMMA_LANDF GAMMA_LANDH GA_RATF GA_RATH GDPF_EXOG GDPH_EXOG GN_RATF GN_RATH LANDF_SS LANDH_SS LILCAPPA1F LILCAPPA1H LILCAPPA2F LILCAPPA2H LILCAPPA3F LILCAPPA3H LILCAPPA4F LILCAPPA4H LILCAPPA5F LILCAPPA5H LILCAPPA6F LILCAPPA6H LILCAPPA7F LILCAPPA7H LILCAPPA8F LILCAPPA8H NYF NYH NY_NF NY_NH NY_TF NY_TH OMEGA0F OMEGA0H OMEGAF OMEGAH PHIF PHIH PIE4TARF_SS PIE4TARH_SS REALEX_EXOG REALPBARMF_EXOG REALPBARMH_EXOG REALPNF_EXOG REALPNH_EXOG REALP_MOF_EXOG REALP_MOH_EXOG RNOM_EXOGF RNOM_EXOGH THETAF THETAH XDUMF XDUMH XIXI_NF XIXI_NH XIXI_OF XIXI_OH XIXI_TF XIXI_TH ZBF_SS ZBH_SS ZEDF ZEDH ZEYEF_SS ZEYEH_SS ZNF_SS ZNH_SS ZTF_SS ZTH_SS ZUF_SS ZUH_SS Z_OF_SS Z_OH_SS; - -COSTLF=5; -COSTLH=5; -EPSF=1.1; -EPSH=1.1; -EPSQMF=4; -EPSQMH=1.1; -GLAMBDAF=0; -GLAMBDAH=0; -SIGMAF=0.333333333333333; -SIGMAH=0.333333333333333; -SSF=0.95; -SSH=0.05; -XR1F=1; -XR1H=0.40; -XR2F=0; -XR2H=0.1; -XR3F=0.5; -XR3H=0.84; -XR4F=0; -XR4H=0; -ALPHANF=0.33; -ALPHANH=0.4; -ALPHATF=0.33; -ALPHATH=0.4; -ALPHA_OF=0.2; -ALPHA_OH=0.2; -A_ONEF=0.075; -A_ONEH=0.075; -A_ZEROF=0.011; -A_ZEROH=0.011; -B0F=1; -B0H=1; -B1F=0.95; -B1H=0.95; -B2F=1; -B2H=1; -BET=0.99263753614514; -CAPAF_SS=11; -CAPAH_SS=11; -CHI0=0.05; -CHI1=.1; -CHI2=0; -CHI3=0; -COSTF=5; -COSTH=5; -COST_MONF=5; -COST_MONH=5; -COST_MOTF=5; -COST_MOTH=5; -COST_O_NF=5; -COST_O_NH=5; -COST_O_TF=5; -COST_O_TH=5; -DELTAF=0.025; -DELTAH=0.025; -EPS_ONF=3; -EPS_ONH=3; -EPS_OTF=3; -EPS_OTH=3; -ETAF=0.35; -ETAH=0.2; -E_PIE4TARF=0; -E_PIE4TARH=0; -E_ZBF=0; -GAMA_NF=0.3; -GAMA_NH=0.1; -GAMA_TF=0.3; -GAMA_TH=0.5; -GAMMAF_SS=0.5; -GAMMAH_SS=0.25; -GAMMA_LANDF=0.1; -GAMMA_LANDH=0.1; -GA_RATF=0.05; -GA_RATH=0.05; -GDPF_EXOG=2.41500497257461; -GDPH_EXOG=2.90512477822209; -GN_RATF=0.1; -GN_RATH=0.1; -LANDF_SS=0.1; -LANDH_SS=0.1; -LILCAPPA1F=0; -LILCAPPA1H=0; -LILCAPPA2F=800; -LILCAPPA2H=400; -LILCAPPA3F=0; -LILCAPPA3H=0; -LILCAPPA4F=800; -LILCAPPA4H=400; -LILCAPPA5F=0; -LILCAPPA5H=0; -LILCAPPA6F=800; -LILCAPPA6H=400; -LILCAPPA7F=0; -LILCAPPA7H=0; -LILCAPPA8F=0; -LILCAPPA8H=0; -NYF=0.98; -NYH=0.0499999999999999; -NY_NF=0.98; -NY_NH=0.0499999999999999; -NY_TF=0.98; -NY_TH=0.02; -OMEGA0F=60; -OMEGA0H=60; -OMEGAF=5; -OMEGAH=5; -PHIF=3; -PHIH=3; -PIE4TARF_SS=1.125; -PIE4TARH_SS=1.125; -REALEX_EXOG=1.3734519289908; -REALPBARMF_EXOG=0.87146958398196; -REALPBARMH_EXOG=1.19072687148694; -REALPNF_EXOG=0.840675522925242; -REALPNH_EXOG=0.902486321747893; -REALP_MOF_EXOG=0.966533486000563; -REALP_MOH_EXOG=1.63690883121281; -RNOM_EXOGF=1.00741707177773; -RNOM_EXOGH=1.00741707177773; -THETAF=6; -THETAH=6; -XDUMF=1; -XDUMH=1; -XIXI_NF=0.75; -XIXI_NH=0.75; -XIXI_OF=0.75; -XIXI_OH=0.75; -XIXI_TF=0.75; -XIXI_TH=0.75; -ZBF_SS=0; -ZBH_SS=0; -ZEDF=2.5; -ZEDH=2.5; -ZEYEF_SS=0; -ZEYEH_SS=0; -ZNF_SS=1; -ZNH_SS=1; -ZTF_SS=1; -ZTH_SS=0.6; -ZUF_SS=1; -ZUH_SS=1; -Z_OF_SS=1; -Z_OH_SS=1; - -model; - ZZ_UTILITYH = (ZUH*(CH-HH)^(1-SIGMAH)-1)/(1-SIGMAH)-CAPAH*LH^(1+ZEDH)/(1+ZEDH) ; - ZZ_GH = 100*log(GH_NAT) ; - ZZ_CURBALH_RAT = CURBALH_RAT*100 ; - ZZ_M_SHARH = REALPBARMH*MH/AH ; - ZZ_M_O_SHARH = (REALP_MOH*M_ONH+REALP_MOH*M_OTH)/AH ; - ZZ_M_ON_SHARH = REALP_MOH*M_ONH/AH ; - ZZ_M_OT_SHARH = REALP_MOH*M_OTH/AH ; - ZZ_N_SHARH = NH*REALPNH/AH ; - ZZ_EYE_SHARH = EYEH/GDPH ; - ZZ_C_SHARH = CH/GDPH ; - ZZ_GDPH = 100*log(GDPH_NAT) ; - ZZ_CH = 100*log(CH_NAT) ; - ZZ_EYEH = 100*log(EYEH) ; - ZZ_EXPORTSH = 100*log(EXPORTSH_NAT) ; - ZZ_IMPORTSH = 100*log(IMPORTSH_NAT) ; - ZZ_XBALH_TOT_RAT = 100*(EXPORTSH_NAT-IMPORTSH_NAT)/GDPH_NAT ; - ZZ_PIE4H = 100*(PIE4H-1) ; - ZZ_DPIE4H = ZZ_PIE4H-ZZ_PIE4H(-1) ; - ZZ_RNOMH = 100*(RNOMH^4-1) ; - ZZ_DRNOMH = ZZ_RNOMH-ZZ_RNOMH(-1) ; - 100*(PIE4TARH-1) = 1*100*(PIE4TARH_SS-1)+(1-1)*100*(PIE4TARH(-1)-1)+E_PIE4TARH ; - log(ZUH) = 0.3*log(ZUH_SS)+0.7*log(ZUH(-1))+E_ZUH ; - ZBH = 0.3*ZBH_SS+0.7*ZBH(-1)+E_ZBH ; - log(LANDH) = 0.05*log(LANDH_SS)+0.95*log(LANDH(-1))+E_LANDH ; - log(ZTH) = 0.05*log(ZTH_SS)+0.95*log(ZTH(-1))+E_LANDH ; - log(ZNH) = 0.05*log(ZNH_SS)+0.95*log(ZNH(-1))+E_LANDH ; - log(Z_OH) = 0.05*log(Z_OH_SS)+0.95*log(Z_OH(-1))+E_LANDH ; - ZEYEH = 0.05*ZEYEH_SS+0.95*ZEYEH(-1)+E_ZEYEH ; - CAPAH = 0.05*CAPAH_SS+0.95*CAPAH(-1)+E_CAPAH ; - log(GAMMAH) = 0.05*log(GAMMAH_SS)+0.95*log(GAMMAH(-1))+E_GAMMAH ; - BIGGAM_O_NH = 1-COST_O_NH/2*(O_NH/NH/(O_NH(-1)/NH(-1))-1)^2 ; - BIGGAM_O_TH = 1-COST_O_TH/2*(O_TH/TH/(O_TH(-1)/TH(-1))-1)^2 ; - O_NH = GAMA_NH*NH/ZNH*(REALP_ONH/(REALMCNH*ZNH))^(-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^XIXI_NH/BIGGAM_O_NH ; - O_TH = GAMA_TH*TH/ZTH*(REALP_OTH/(REALMCTH*ZTH))^(-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^XIXI_NH/BIGGAM_O_TH ; - NH = ZNH*((1-ALPHANH-GAMA_NH)^(1/XIXI_NH)*LNH^(1-1/XIXI_NH)+ALPHANH^(1/XIXI_NH)*KNH^(1-1/XIXI_NH)+GAMA_NH^(1/XIXI_NH)*(BIGGAM_O_NH*O_NH)^(1-1/XIXI_NH))^(XIXI_NH/(XIXI_NH-1)) ; - TH = ZTH*((1-ALPHATH-GAMA_TH)^(1/XIXI_TH)*LTH^(1-1/XIXI_TH)+ALPHATH^(1/XIXI_TH)*KTH^(1-1/XIXI_TH)+GAMA_TH^(1/XIXI_TH)*(BIGGAM_O_TH*O_TH)^(1-1/XIXI_TH))^(XIXI_TH/(XIXI_TH-1)) ; - REALMCNH = 1/ZNH*((1-ALPHANH-GAMA_NH)*REALWH^(1-XIXI_NH)+ALPHANH*REALRH^(1-XIXI_NH)+GAMA_NH*REALP_ONH^(1-XIXI_NH)*(BIGGAM_O_NH-COST_O_NH*(O_NH/NH/(O_NH(-1)/NH(-1))-1)*O_NH/NH/(O_NH(-1)/NH(-1)))^(XIXI_NH-1))^(1/(1-XIXI_NH)) ; - REALMCTH = 1/ZTH*((1-ALPHATH-GAMA_TH)*REALWH^(1-XIXI_TH)+ALPHATH*REALRH^(1-XIXI_TH)+GAMA_TH*REALP_OTH^(1-XIXI_TH)*(BIGGAM_O_TH-COST_O_TH*(O_TH/TH/(O_TH(-1)/TH(-1))-1)*O_TH/TH/(O_TH(-1)/TH(-1)))^(XIXI_TH-1))^(1/(1-XIXI_TH)) ; - MARGUTH = (CH-B2H*HH)^(-SIGMAH)*ZUH ; - HH = (1-B0H)*HH(-1)+B0H*B1H*CH(-1) ; - VPRIMEH = CAPAH*LH^ZEDH ; - AH^(1-1/EPSH) = GAMMAH^(1/EPSH)*(NYH^(1/EPSQMH)*QH^(1-1/EPSQMH)+(1-NYH)^(1/EPSQMH)*(MH*BIGGAMIMPH)^(1-1/EPSQMH))^(EPSQMH/(EPSQMH-1)*(1-1/EPSH))+(1-GAMMAH)^(1/EPSH)*NNH^(1-1/EPSH) ; - QH = GAMMAH*NYH*REALPQH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH) ; - MH = GAMMAH*(1-NYH)*REALPMH^(-EPSQMH)*AH*REALPXH^(EPSQMH-EPSH)*1/BIGGAMIMPH*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^EPSQMH ; - REALPXH = (NYH*REALPQH^(1-EPSQMH)+(1-NYH)*REALPMH^(1-EPSQMH)*(BIGGAMIMPH-COSTH*(MH/AH/(MH(-1)/AH(-1))-1)*MH/AH/(MH(-1)/AH(-1)))^(EPSQMH-1))^(1/(1-EPSQMH)) ; - BIGGAMIMPH = 1-COSTH/2*(MH/AH/(MH(-1)/AH(-1))-1)^2 ; - NNH = (1-GAMMAH)*REALPNH^(-EPSH)*AH ; - NH = NNH+ETAH*MH+ETAH*QH+GNH ; - PIENH = REALPNH/REALPNH(-1)*PIEH ; - BIGGAMNH = LILCAPPA3H/2*(PIENH/PIE4TARH^0.25-1)^2+LILCAPPA4H/2*(PIENH/PIENH(-1)-1)^2 ; - -(1-BIGGAMNH)*(REALPNH*(1-THETAH)+THETAH*REALMCNH) = -(REALPNH-REALMCNH)*(LILCAPPA3H*PIENH/PIE4TARH^0.25*(PIENH/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH/PIENH(-1)*(PIENH/PIENH(-1)-1))+DEEH*PIEH(+1)*(REALPNH(+1)-REALMCNH(+1))*NH(+1)/NH*(LILCAPPA3H*PIENH(+1)/PIE4TARH^0.25*(PIENH(+1)/PIE4TARH^0.25-1)+LILCAPPA4H*PIENH(+1)/PIENH*(PIENH(+1)/PIENH-1)) ; - PIEBARQH = PIEH*REALPBARQH/REALPBARQH(-1) ; - BIGGAMQH = LILCAPPA5H/2*(PIEBARQH/PIE4TARH^0.25-1)^2+LILCAPPA6H/2*(PIEBARQH/PIEBARQH(-1)-1)^2 ; - -(1-BIGGAMQH)*REALPBARQH/REALPQH*(REALPBARQH*(1-THETAH)+ETAH*REALPNH+THETAH*REALMCTH) = -(REALPBARQH-REALMCTH)*(LILCAPPA5H*PIEBARQH/PIE4TARH^0.25*(PIEBARQH/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH/PIEBARQH(-1)*(PIEBARQH/PIEBARQH(-1)-1))+DEEH*PIEH(+1)*(REALPBARQH(+1)-REALMCTH(+1))*QH(+1)/QH*(LILCAPPA5H*PIEBARQH(+1)/PIE4TARH^0.25*(PIEBARQH(+1)/PIE4TARH^0.25-1)+LILCAPPA6H*PIEBARQH(+1)/PIEBARQH*(PIEBARQH(+1)/PIEBARQH-1)) ; - REALPQH = REALPBARQH+ETAH*REALPNH ; - KH = KH(-1)*(1-DELTAH)+PSIH(-1)*KH(-1) ; - PSIH = EYEH/KH-OMEGAH/2*(EYEH/KH-DELTAH*(1+ZEYEH))^2-OMEGA0H/2*(EYEH/KH-EYEH(-1)/KH(-1))^2 ; - PSIPRIMEH = 1-OMEGAH*(EYEH/KH-DELTAH*(1+ZEYEH))-OMEGA0H*(EYEH/KH-EYEH(-1)/KH(-1)) ; - 1/PSIPRIMEH = DEEH*PIEH(+1)*(REALRH(+1)+1/PSIPRIMEH(+1)*(1-DELTAH+PSIH(+1)*(1-PSIPRIMEH(+1)*EYEH(+1)/(PSIH(+1)*KH(+1))))) ; - BIGGAMH = LILCAPPA1H/2*(PIEWH/PIE4TARH^0.25-1)^2+LILCAPPA2H/2*(PIEWH/PIEWH(-1)-1)^2 ; - PIEH*REALWH/REALWH(-1) = PIEWH ; - REALWH = PHIH*VPRIMEH/MARGUTH*((PHIH-1)*(1-BIGGAMH)+PIEWH*LILCAPPA1H/PIE4TARH^0.25*(PIEWH/PIE4TARH^0.25-1)+PIEWH/PIEWH(-1)*LILCAPPA2H*(PIEWH/PIEWH(-1)-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA1H*PIEWH(+1)/PIE4TARH^0.25*(PIEWH(+1)/PIE4TARH^0.25-1)-DEEH*PIEWH(+1)*LH(+1)/LH*LILCAPPA2H*PIEWH(+1)/(REALWH/REALWH(-1))*(PIEWH(+1)/PIEWH-1))^(-1) ; - DEEH = BET*MARGUTH(+1)/PIEH(+1)/MARGUTH*(1+SHOPH+SHOPPRIMEH*VELOH)/(1+SHOPH(+1)+SHOPPRIMEH(+1)*VELOH(+1)) ; - SHOPH = A_ZEROH*VELOH+A_ONEH/VELOH-2*(A_ZEROH*A_ONEH)^0.5 ; - SHOPPRIMEH = A_ZEROH-A_ONEH*VELOH^(-2) ; - VELOH = CH/REALMONEYH ; - DEEH = 1-SHOPPRIMEH*VELOH^2 ; - 1 = RNOMH*DEEH ; - 100*(RNOMH^4-1) = (1-XDUMH)*100*(RNOM_EXOGH^4-1)+XDUMH*(XR3H*100*(RNOMH(-1)^4-1)+(1-XR3H)*(100*((1/BET*PIE4H^0.25)^4-1))+XR1H*(100*(PIE4H-1)-100*(PIE4TARH-1))+XR4H*100*(DEPEX^4-1)+XR2H*GDPGAPH) ; - GDPGAPH = 100*(GDPH_NAT-GDPH_EXOG)/GDPH_EXOG ; - PIE4H = PIEH*PIEH(-1)*PIEH1(-1)*PIEH2(-1) ; - AH = CH*(1+SHOPH)+EYEH+GAH ; - GAH = .05*(GA_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG))+.95*GAH(-1)+E_GAH; - GNH = GN_RATH*(GLAMBDAH*GDPH_NAT+(1-GLAMBDAH)*GDPH_EXOG)/REALPNH_EXOG ; - PIEBARMH = PIEH*REALPBARMH/REALPBARMH(-1) ; - BIGGAMMH = LILCAPPA7H/2*(PIEBARMH/PIE4TARH^0.25-1)^2+LILCAPPA8H/2*(PIEBARMH/PIEBARMH(-1)-1)^2 ; - REALPMH = REALPBARMH+ETAH*REALPNH ; - KNH_RAT = ALPHANH/(1-ALPHANH-GAMA_NH)*(REALWH/REALRH)^XIXI_NH ; - KTH_RAT = ALPHATH/(1-ALPHATH-GAMA_TH)*(REALWH/REALRH)^XIXI_TH ; - KNH_RAT = KNH/LNH ; - KTH_RAT = KTH/LTH ; - KH = KTH+KNH+K_OH ; - LH = (LNH+LTH+L_OH)*(1-COSTLH/2*(LNH/(LTH+L_OH)/(LNH(-1)/(LTH(-1)+L_OH(-1)))-1)^2) ; - T_OH = Z_OH*((1-ALPHA_OH-GAMMA_LANDH)^(1/XIXI_OH)*L_OH^(1-1/XIXI_OH)+ALPHA_OH^(1/XIXI_OH)*K_OH^(1-1/XIXI_OH)+GAMMA_LANDH^(1/XIXI_OH)*LANDH^(1-1/XIXI_OH))^(XIXI_OH/(XIXI_OH-1)) ; - Q_ONH = NY_NH*(REALP_QOH/REALP_ONH)^(-EPS_ONH)*O_NH ; - Q_OTH = NY_TH*(REALP_QOH/REALP_OTH)^(-EPS_OTH)*O_TH ; - M_ONH = (1-NY_NH)*(REALP_MOH/REALP_ONH)^(-EPS_ONH)*O_NH*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^EPS_ONH/BIGGAM_MONH ; - M_OTH = (1-NY_TH)*(REALP_MOH/REALP_OTH)^(-EPS_OTH)*O_TH*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^EPS_OTH/BIGGAM_MOTH ; - BIGGAM_MONH = 1-COST_MONH/2*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)^2 ; - BIGGAM_MOTH = 1-COST_MOTH/2*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)^2 ; - K_OH_RAT = ALPHA_OH/(1-ALPHA_OH-GAMMA_LANDH)*(REALWH/REALRH)^XIXI_OH ; - K_OH_RAT = K_OH/L_OH ; - REALP_QOH = 1/Z_OH*((1-ALPHA_OH-GAMMA_LANDH)*REALWH^(1-XIXI_OH)+ALPHA_OH*REALRH^(1-XIXI_OH)+GAMMA_LANDH*REALPLANDH^(1-XIXI_OH))^(1/(1-XIXI_OH)) ; - LANDH = GAMMA_LANDH*(REALPLANDH/(REALP_QOH*Z_OH))^(-XIXI_OH)*T_OH/Z_OH ; - REALP_ONH = (NY_NH*REALP_QOH^(1-EPS_ONH)+(1-NY_NH)*REALP_MOH^(1-EPS_ONH)*(BIGGAM_MONH-COST_MONH*(M_ONH/O_NH/(M_ONH(-1)/O_NH(-1))-1)*M_ONH/O_NH/(M_ONH(-1)/O_NH(-1)))^(EPS_ONH-1))^(1/(1-EPS_ONH)) ; - REALP_OTH = (NY_TH*REALP_QOH^(1-EPS_OTH)+(1-NY_TH)*REALP_MOH^(1-EPS_OTH)*(BIGGAM_MOTH-COST_MOTH*(M_OTH/O_TH/(M_OTH(-1)/O_TH(-1))-1)*M_OTH/O_TH/(M_OTH(-1)/O_TH(-1)))^(EPS_OTH-1))^(1/(1-EPS_OTH)) ; - SSH*TH = SSH*QH+SSF*MF ; - SSH*T_OH = SSH*Q_ONH+SSH*Q_OTH+SSF*M_ONF+SSF*M_OTF ; - REALP_MOH = REALP_QOF*REALEXH ; - ZZ_GDP_PPP_RATH = GDPH/REALEX/GDPF ; - XI = CHI0*(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH1(-1)/PIEF(-1))/GDPH(-1))^2-1)/(exp(CHI1*REALEX*REALBH)+CHI2*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH)^2+CHI3*(REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH-REALEX(-1)*(REALBH(-1)-REALBH1(-1)/PIEF(-1))/GDPH(-1))^2+1)+ZBH ; - 1 = RNOMF*(1-XI)*DEEH*DEPEX(+1) ; - DEPEX = PIEH/PIEF*REALEX/REALEX(-1) ; - REALFINH = RNOMF(-1)*(1-XI(-1))*REALEX*REALBH(-1)/PIEF ; - SSH*DEEH*PIEH(+1)*REALFINH(+1) = SSH*REALFINH+SSH*RNOMF(-1)*XI(-1)*REALEX*REALBH(-1)/PIEF+REALTBALH ; - REALEXH = REALEX ; - REALEXF = 1/REALEXH ; - ZZ_REALEX = 100*log(REALEX) ; - -(1-BIGGAMMH)*REALPBARMH/REALPMH*(REALPBARMH/REALEX*(1-THETAF)+ETAH*REALPNH/REALEX+THETAF*REALMCTF) = -(REALPBARMH/REALEX-REALMCTF)*(LILCAPPA7H*PIEBARMH/PIE4TARH^0.25*(PIEBARMH/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH/PIEBARMH(-1)*(PIEBARMH/PIEBARMH(-1)-1))+DEEF*PIEF(+1)*(REALPBARMH(+1)/REALEX(+1)-REALMCTF(+1))*MH(+1)/MH*(LILCAPPA7H*PIEBARMH(+1)/PIE4TARH^0.25*(PIEBARMH(+1)/PIE4TARH^0.25-1)+LILCAPPA8H*PIEBARMH(+1)/PIEBARMH*(PIEBARMH(+1)/PIEBARMH-1)) ; - GDPH = AH+REALPNH*GNH+EXPORTSH-IMPORTSH+(RNOMF(-1)-1)*REALEX*REALBH(-1)/PIEF ; - GDPH_NAT = AH+REALPNH_EXOG*GNH+EXPORTSH_NAT-IMPORTSH_NAT ; - CH_NAT = CH*(1+SHOPH) ; - GH_NAT = GAH+REALPNH_EXOG*GNH ; - XH_NAT = SSF/SSH*REALEX_EXOG*REALPBARMF_EXOG*MF ; - MH_NAT = REALPBARMH_EXOG*MH ; - CURBALH_RAT = REALEX*(REALBH-REALBH(-1)/PIEF)/GDPH ; - REALTBALH = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH) ; - EXPORTSH = SSF/SSH*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)*REALEX ; - IMPORTSH = REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH ; - EXPORTSH_NAT = SSF/SSH*(REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF)*REALEX_EXOG ; - IMPORTSH_NAT = REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH ; - ZZ_UTILITYF = (ZUF*(CF-HF)^(1-SIGMAF)-1)/(1-SIGMAF)-CAPAF*LF^(1+ZEDF)/(1+ZEDF) ; - ZZ_GF = 100*log(GF_NAT) ; - ZZ_CURBALF_RAT = CURBALF_RAT*100 ; - ZZ_M_SHARF = REALPBARMF*MF/AF ; - ZZ_M_O_SHARF = (REALP_MOF*M_ONF+REALP_MOF*M_OTF)/AF ; - ZZ_M_ON_SHARF = REALP_MOF*M_ONF/AF ; - ZZ_M_OT_SHARF = REALP_MOF*M_OTF/AF ; - ZZ_N_SHARF = NF*REALPNF/AF ; - ZZ_EYE_SHARF = EYEF/GDPF ; - ZZ_C_SHARF = CF/GDPF ; - ZZ_GDPF = 100*log(GDPF_NAT) ; - ZZ_CF = 100*log(CF_NAT) ; - ZZ_EYEF = 100*log(EYEF) ; - ZZ_EXPORTSF = 100*log(EXPORTSF_NAT) ; - ZZ_IMPORTSF = 100*log(IMPORTSF_NAT) ; - ZZ_XBALF_TOT_RAT = 100*(EXPORTSF_NAT-IMPORTSF_NAT)/GDPF_NAT ; - ZZ_PIE4F = 100*(PIE4F-1) ; - ZZ_DPIE4F = ZZ_PIE4F-ZZ_PIE4F(-1) ; - ZZ_RNOMF = 100*(RNOMF^4-1) ; - ZZ_DRNOMF = ZZ_RNOMF-ZZ_RNOMF(-1) ; - 100*(PIE4TARF-1) = 1*100*(PIE4TARF_SS-1)+(1-1)*100*(PIE4TARF(-1)-1)+E_PIE4TARF ; - log(ZUF) = 0.3*log(ZUF_SS)+0.7*log(ZUF(-1))+E_ZUF ; - ZBF = 0.3*ZBF_SS+0.7*ZBF(-1)+E_ZBF ; - log(LANDF) = 0.05*log(LANDF_SS)+0.95*log(LANDF(-1))+E_LANDF ; - log(ZTF) = 0.05*log(ZTF_SS)+0.95*log(ZTF(-1))+E_LANDF ; - log(ZNF) = 0.05*log(ZNF_SS)+0.95*log(ZNF(-1))+E_LANDF ; - log(Z_OF) = 0.05*log(Z_OF_SS)+0.95*log(Z_OF(-1))+E_LANDF ; - ZEYEF = 0.05*ZEYEF_SS+0.95*ZEYEF(-1)+E_ZEYEF ; - CAPAF = 0.05*CAPAF_SS+0.95*CAPAF(-1)+E_CAPAF ; - log(GAMMAF) = 0.05*log(GAMMAF_SS)+0.95*log(GAMMAF(-1))+E_GAMMAF ; - BIGGAM_O_NF = 1-COST_O_NF/2*(O_NF/NF/(O_NF(-1)/NF(-1))-1)^2 ; - BIGGAM_O_TF = 1-COST_O_TF/2*(O_TF/TF/(O_TF(-1)/TF(-1))-1)^2 ; - O_NF = GAMA_NF*NF/ZNF*(REALP_ONF/(REALMCNF*ZNF))^(-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^XIXI_NF/BIGGAM_O_NF ; - O_TF = GAMA_TF*TF/ZTF*(REALP_OTF/(REALMCTF*ZTF))^(-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^XIXI_NF/BIGGAM_O_TF ; - NF = ZNF*((1-ALPHANF-GAMA_NF)^(1/XIXI_NF)*LNF^(1-1/XIXI_NF)+ALPHANF^(1/XIXI_NF)*KNF^(1-1/XIXI_NF)+GAMA_NF^(1/XIXI_NF)*(BIGGAM_O_NF*O_NF)^(1-1/XIXI_NF))^(XIXI_NF/(XIXI_NF-1)) ; - TF = ZTF*((1-ALPHATF-GAMA_TF)^(1/XIXI_TF)*LTF^(1-1/XIXI_TF)+ALPHATF^(1/XIXI_TF)*KTF^(1-1/XIXI_TF)+GAMA_TF^(1/XIXI_TF)*(BIGGAM_O_TF*O_TF)^(1-1/XIXI_TF))^(XIXI_TF/(XIXI_TF-1)) ; - REALMCNF = 1/ZNF*((1-ALPHANF-GAMA_NF)*REALWF^(1-XIXI_NF)+ALPHANF*REALRF^(1-XIXI_NF)+GAMA_NF*REALP_ONF^(1-XIXI_NF)*(BIGGAM_O_NF-COST_O_NF*(O_NF/NF/(O_NF(-1)/NF(-1))-1)*O_NF/NF/(O_NF(-1)/NF(-1)))^(XIXI_NF-1))^(1/(1-XIXI_NF)) ; - REALMCTF = 1/ZTF*((1-ALPHATF-GAMA_TF)*REALWF^(1-XIXI_TF)+ALPHATF*REALRF^(1-XIXI_TF)+GAMA_TF*REALP_OTF^(1-XIXI_TF)*(BIGGAM_O_TF-COST_O_TF*(O_TF/TF/(O_TF(-1)/TF(-1))-1)*O_TF/TF/(O_TF(-1)/TF(-1)))^(XIXI_TF-1))^(1/(1-XIXI_TF)) ; - MARGUTF = (CF-B2F*HF)^(-SIGMAF)*ZUF ; - HF = (1-B0F)*HF(-1)+B0F*B1F*CF(-1) ; - VPRIMEF = CAPAF*LF^ZEDF ; - AF^(1-1/EPSF) = GAMMAF^(1/EPSF)*(NYF^(1/EPSQMF)*QF^(1-1/EPSQMF)+(1-NYF)^(1/EPSQMF)*(MF*BIGGAMIMPF)^(1-1/EPSQMF))^(EPSQMF/(EPSQMF-1)*(1-1/EPSF))+(1-GAMMAF)^(1/EPSF)*NNF^(1-1/EPSF) ; - QF = GAMMAF*NYF*REALPQF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF) ; - MF = GAMMAF*(1-NYF)*REALPMF^(-EPSQMF)*AF*REALPXF^(EPSQMF-EPSF)*1/BIGGAMIMPF*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^EPSQMF ; - REALPXF = (NYF*REALPQF^(1-EPSQMF)+(1-NYF)*REALPMF^(1-EPSQMF)*(BIGGAMIMPF-COSTF*(MF/AF/(MF(-1)/AF(-1))-1)*MF/AF/(MF(-1)/AF(-1)))^(EPSQMF-1))^(1/(1-EPSQMF)) ; - BIGGAMIMPF = 1-COSTF/2*(MF/AF/(MF(-1)/AF(-1))-1)^2 ; - NNF = (1-GAMMAF)*REALPNF^(-EPSF)*AF ; - NF = NNF+ETAF*MF+ETAF*QF+GNF ; - PIENF = REALPNF/REALPNF(-1)*PIEF ; - BIGGAMNF = LILCAPPA3F/2*(PIENF/PIE4TARF^0.25-1)^2+LILCAPPA4F/2*(PIENF/PIENF(-1)-1)^2 ; - -(1-BIGGAMNF)*(REALPNF*(1-THETAF)+THETAF*REALMCNF) = -(REALPNF-REALMCNF)*(LILCAPPA3F*PIENF/PIE4TARF^0.25*(PIENF/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF/PIENF(-1)*(PIENF/PIENF(-1)-1))+DEEF*PIEF(+1)*(REALPNF(+1)-REALMCNF(+1))*NF(+1)/NF*(LILCAPPA3F*PIENF(+1)/PIE4TARF^0.25*(PIENF(+1)/PIE4TARF^0.25-1)+LILCAPPA4F*PIENF(+1)/PIENF*(PIENF(+1)/PIENF-1)) ; - PIEBARQF = PIEF*REALPBARQF/REALPBARQF(-1) ; - BIGGAMQF = LILCAPPA5F/2*(PIEBARQF/PIE4TARF^0.25-1)^2+LILCAPPA6F/2*(PIEBARQF/PIEBARQF(-1)-1)^2 ; - -(1-BIGGAMQF)*REALPBARQF/REALPQF*(REALPBARQF*(1-THETAF)+ETAF*REALPNF+THETAF*REALMCTF) = -(REALPBARQF-REALMCTF)*(LILCAPPA5F*PIEBARQF/PIE4TARF^0.25*(PIEBARQF/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF/PIEBARQF(-1)*(PIEBARQF/PIEBARQF(-1)-1))+DEEF*PIEF(+1)*(REALPBARQF(+1)-REALMCTF(+1))*QF(+1)/QF*(LILCAPPA5F*PIEBARQF(+1)/PIE4TARF^0.25*(PIEBARQF(+1)/PIE4TARF^0.25-1)+LILCAPPA6F*PIEBARQF(+1)/PIEBARQF*(PIEBARQF(+1)/PIEBARQF-1)) ; - REALPQF = REALPBARQF+ETAF*REALPNF ; - KF = KF(-1)*(1-DELTAF)+PSIF(-1)*KF(-1) ; - PSIF = EYEF/KF-OMEGAF/2*(EYEF/KF-DELTAF*(1+ZEYEF))^2-OMEGA0F/2*(EYEF/KF-EYEF(-1)/KF(-1))^2 ; - PSIPRIMEF = 1-OMEGAF*(EYEF/KF-DELTAF*(1+ZEYEF))-OMEGA0F*(EYEF/KF-EYEF(-1)/KF(-1)) ; - 1/PSIPRIMEF = DEEF*PIEF(+1)*(REALRF(+1)+1/PSIPRIMEF(+1)*(1-DELTAF+PSIF(+1)*(1-PSIPRIMEF(+1)*EYEF(+1)/(PSIF(+1)*KF(+1))))) ; - BIGGAMF = LILCAPPA1F/2*(PIEWF/PIE4TARF^0.25-1)^2+LILCAPPA2F/2*(PIEWF/PIEWF(-1)-1)^2 ; - PIEF*REALWF/REALWF(-1) = PIEWF ; - REALWF = PHIF*VPRIMEF/MARGUTF*((PHIF-1)*(1-BIGGAMF)+PIEWF*LILCAPPA1F/PIE4TARF^0.25*(PIEWF/PIE4TARF^0.25-1)+PIEWF/PIEWF(-1)*LILCAPPA2F*(PIEWF/PIEWF(-1)-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA1F*PIEWF(+1)/PIE4TARF^0.25*(PIEWF(+1)/PIE4TARF^0.25-1)-DEEF*PIEWF(+1)*LF(+1)/LF*LILCAPPA2F*PIEWF(+1)/(REALWF/REALWF(-1))*(PIEWF(+1)/PIEWF-1))^(-1) ; - DEEF = BET*MARGUTF(+1)/PIEF(+1)/MARGUTF*(1+SHOPF+SHOPPRIMEF*VELOF)/(1+SHOPF(+1)+SHOPPRIMEF(+1)*VELOF(+1)) ; - SHOPF = A_ZEROF*VELOF+A_ONEF/VELOF-2*(A_ZEROF*A_ONEF)^0.5 ; - SHOPPRIMEF = A_ZEROF-A_ONEF*VELOF^(-2) ; - VELOF = CF/REALMONEYF ; - DEEF = 1-SHOPPRIMEF*VELOF^2 ; - 1 = RNOMF*DEEF ; - 100*(RNOMF^4-1) = (1-XDUMF)*100*(RNOM_EXOGF^4-1)+XDUMF*(XR3F*100*(RNOMF(-1)^4-1)+(1-XR3F)*(100*((1/BET*PIE4F^0.25)^4-1)+XR1F*(100*(PIE4F-1)-100*(PIE4TARF-1))+XR4F*100*(DEPEX^4-1)+XR2F*GDPGAPF)) ; - GDPGAPF = 100*(GDPF_NAT-GDPF_EXOG)/GDPF_EXOG ; - PIE4F = PIEF*PIEF(-1)*PIEF1(-1)*PIEF2(-1) ; - AF = CF*(1+SHOPF)+EYEF+GAF ; - GAF = .05*(GA_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG))+.95*GAF(-1)+E_GAF; - GNF = GN_RATF*(GLAMBDAF*GDPF_NAT+(1-GLAMBDAF)*GDPF_EXOG)/REALPNF_EXOG ; - PIEBARMF = PIEF*REALPBARMF/REALPBARMF(-1) ; - BIGGAMMF = LILCAPPA7F/2*(PIEBARMF/PIE4TARF^0.25-1)^2+LILCAPPA8F/2*(PIEBARMF/PIEBARMF(-1)-1)^2 ; - REALPMF = REALPBARMF+ETAF*REALPNF ; - KNF_RAT = ALPHANF/(1-ALPHANF-GAMA_NF)*(REALWF/REALRF)^XIXI_NF ; - KTF_RAT = ALPHATF/(1-ALPHATF-GAMA_TF)*(REALWF/REALRF)^XIXI_TF ; - KNF_RAT = KNF/LNF ; - KTF_RAT = KTF/LTF ; - KF = KTF+KNF+K_OF ; - LF = (LNF+LTF+L_OF)*(1-COSTLF/2*(LNF/(LTF+L_OF)/(LNF(-1)/(LTF(-1)+L_OF(-1)))-1)^2) ; - T_OF = Z_OF*((1-ALPHA_OF-GAMMA_LANDF)^(1/XIXI_OF)*L_OF^(1-1/XIXI_OF)+ALPHA_OF^(1/XIXI_OF)*K_OF^(1-1/XIXI_OF)+GAMMA_LANDF^(1/XIXI_OF)*LANDF^(1-1/XIXI_OF))^(XIXI_OF/(XIXI_OF-1)) ; - Q_ONF = NY_NF*(REALP_QOF/REALP_ONF)^(-EPS_ONF)*O_NF ; - Q_OTF = NY_TF*(REALP_QOF/REALP_OTF)^(-EPS_OTF)*O_TF ; - M_ONF = (1-NY_NF)*(REALP_MOF/REALP_ONF)^(-EPS_ONF)*O_NF*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^EPS_ONF/BIGGAM_MONF ; - M_OTF = (1-NY_TF)*(REALP_MOF/REALP_OTF)^(-EPS_OTF)*O_TF*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^EPS_OTF/BIGGAM_MOTF ; - BIGGAM_MONF = 1-COST_MONF/2*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)^2 ; - BIGGAM_MOTF = 1-COST_MOTF/2*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)^2 ; - K_OF_RAT = ALPHA_OF/(1-ALPHA_OF-GAMMA_LANDF)*(REALWF/REALRF)^XIXI_OF ; - K_OF_RAT = K_OF/L_OF ; - REALP_QOF = 1/Z_OF*((1-ALPHA_OF-GAMMA_LANDF)*REALWF^(1-XIXI_OF)+ALPHA_OF*REALRF^(1-XIXI_OF)+GAMMA_LANDF*REALPLANDF^(1-XIXI_OF))^(1/(1-XIXI_OF)) ; - LANDF = GAMMA_LANDF*(REALPLANDF/(REALP_QOF*Z_OF))^(-XIXI_OF)*T_OF/Z_OF ; - REALP_ONF = (NY_NF*REALP_QOF^(1-EPS_ONF)+(1-NY_NF)*REALP_MOF^(1-EPS_ONF)*(BIGGAM_MONF-COST_MONF*(M_ONF/O_NF/(M_ONF(-1)/O_NF(-1))-1)*M_ONF/O_NF/(M_ONF(-1)/O_NF(-1)))^(EPS_ONF-1))^(1/(1-EPS_ONF)) ; - REALP_OTF = (NY_TF*REALP_QOF^(1-EPS_OTF)+(1-NY_TF)*REALP_MOF^(1-EPS_OTF)*(BIGGAM_MOTF-COST_MOTF*(M_OTF/O_TF/(M_OTF(-1)/O_TF(-1))-1)*M_OTF/O_TF/(M_OTF(-1)/O_TF(-1)))^(EPS_OTF-1))^(1/(1-EPS_OTF)) ; - SSF*TF = SSF*QF+SSH*MH ; - SSF*T_OF = SSF*Q_ONF+SSF*Q_OTF+SSH*M_ONH+SSH*M_OTH ; - REALP_MOF = REALP_QOH*REALEXF ; - SSH*REALBH+SSF*REALBF = 0 ; - REALTBALF = SSF*(REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF)-SSH*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - EXPORTSF = SSH/SSF*(REALPBARMH*MH+REALP_MOH*M_ONH+REALP_MOH*M_OTH)*1/REALEX ; - IMPORTSF = REALPBARMF*MF+REALP_MOF*M_ONF+REALP_MOF*M_OTF ; - EXPORTSF_NAT = SSH/SSF*(REALPBARMH_EXOG*MH+REALP_MOH_EXOG*M_ONH+REALP_MOH_EXOG*M_OTH)*1/REALEX_EXOG ; - IMPORTSF_NAT = REALPBARMF_EXOG*MF+REALP_MOF_EXOG*M_ONF+REALP_MOF_EXOG*M_OTF ; - -(1-BIGGAMMF)*REALPBARMF/REALPMF*(REALPBARMF*REALEX*(1-THETAH)+ETAF*REALPNF*REALEX+THETAH*REALMCTH) = -(REALPBARMF*REALEX-REALMCTH)*(LILCAPPA7F*PIEBARMF/PIE4TARF^0.25*(PIEBARMF/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF/PIEBARMF(-1)*(PIEBARMF/PIEBARMF(-1)-1))+DEEH*PIEH(+1)*(REALPBARMF(+1)*REALEX(+1)-REALMCTH(+1))*MF(+1)/MF*(LILCAPPA7F*PIEBARMF(+1)/PIE4TARF^0.25*(PIEBARMF(+1)/PIE4TARF^0.25-1)+LILCAPPA8F*PIEBARMF(+1)/PIEBARMF*(PIEBARMF(+1)/PIEBARMF-1)) ; - GDPF = AF+REALPNF*GNF+EXPORTSF-IMPORTSF+(RNOMF(-1)-1)*REALBF(-1)/PIEF ; - GDPF_NAT = AF+REALPNF_EXOG*GNF+EXPORTSF_NAT-IMPORTSF_NAT ; - CF_NAT = CF*(1+SHOPF) ; - GF_NAT = GAF+REALPNF_EXOG*GNF ; - XF_NAT = SSH/SSF*1/REALEX_EXOG*REALPBARMH_EXOG*MH ; - MF_NAT = REALPBARMF_EXOG*MF ; - CURBALF_RAT = -(REALTBALH/REALEX/SSF/GDPF)+(RNOMF(-1)-1)*REALBF(-1)/PIEF/GDPF ; - PIEF1 = PIEF(-1); - PIEF2 = PIEF1(-1); - PIEH1 = PIEH(-1); - PIEH2 = PIEH1(-1); - REALBH1 = REALBH(-1); -end; - -initval; -AF=2.17350447531715; -AH=2.61461230039988; -BIGGAMF=0; -BIGGAMH=0; -BIGGAMIMPF=1; -BIGGAMIMPH=1; -BIGGAMMF=0; -BIGGAMMH=0; -BIGGAMNF=0; -BIGGAMNH=0; -BIGGAMQF=0; -BIGGAMQH=0; -BIGGAM_MONF=1; -BIGGAM_MONH=1; -BIGGAM_MOTF=1; -BIGGAM_MOTH=1; -BIGGAM_O_NF=1; -BIGGAM_O_NH=1; -BIGGAM_O_TF=1; -BIGGAM_O_TH=1; -CAPAF=11; -CAPAH=11; -CF=1.77599320017707; -CF_NAT=1.77797456682707; -CH=2.10139281352027; -CH_NAT=2.10373720855446; -CURBALF_RAT=2.20209042676066e-018; -CURBALH_RAT=0; -DEEF=0.963834712172592; -DEEH=0.963834712172592; -DEPEX=1; -EXPORTSF=0.0374229290542059; -EXPORTSF_NAT=0.0374229290542059; -EXPORTSH=0.976573287861717; -EXPORTSH_NAT=0.976573287861717; -EYEF=0.27477965986135; -EYEH=0.365618852934316; -GAF=0.12075024862873; -GAH=0.145256238911104; -GAMMAF=0.5; -GAMMAH=0.25; -GDPF=2.41500497257461; -GDPF_NAT=2.41500497257461; -GDPGAPF=0; -GDPGAPH=0; -GDPH=2.90512477822209; -GDPH_NAT=2.90512477822209; -GF_NAT=0.362250745886191; -GH_NAT=0.435768716733313; -GNF=0.287269571519256; -GNH=0.321902361090147; -HF=1.68719354016822; -HH=1.99632317284426; -IMPORTSF=0.0374229290542059; -IMPORTSF_NAT=0.0374229290542059; -IMPORTSH=0.976573287861718; -IMPORTSH_NAT=0.976573287861718; -KF=10.991186394454; -KH=14.6247541173726; -KNF=6.33686501417153; -KNF_RAT=22.6981730731029; -KNH=11.034700665508; -KNH_RAT=22.8755992006951; -KTF=2.97137434524903; -KTF_RAT=22.6981730731029; -KTH=2.23720856941572; -KTH_RAT=114.377996003476; -K_OF=1.68294703503345; -K_OF_RAT=7.27127622255245; -K_OH=1.35284488244891; -K_OH_RAT=8.16985685739111; -LANDF=0.1; -LANDH=0.1; -LF=0.64153899810027; -LH=0.667528221502678; -LNF=0.279179517830034; -LNH=0.482378650224502; -LTF=0.130908083909629; -LTH=0.019559781143112; -L_OF=0.231451396360608; -L_OH=0.165589790135064; -MARGUTF=2.24145263303312; -MARGUTH=2.11921125101343; -MF=0.0196445696804563; -MF_NAT=0.0171196449669319; -MH=0.438784845846124; -MH_NAT=0.522472906750236; -M_ONF=0.0143006671963624; -M_ONH=0.134410532365428; -M_OTF=0.00670562423725087; -M_OTH=0.143002828997546; -NF=1.91582345366461; -NH=2.609674642079; -NNF=1.31534385473198; -NNH=2.19524942542191; -O_NF=0.387338325509274; -O_NH=0.147043832240678; -O_TF=0.18162406186278; -O_TH=0.148205762233076; -PIE4F=1.125; -PIE4H=1.125; -PIE4TARF=1.125; -PIE4TARH=1.125; -PIEBARMF=1.02988357195356; -PIEBARMH=1.02988357195356; -PIEBARQF=1.02988357195356; -PIEBARQH=1.02988357195356; -PIEF=1.02988357195356; -PIEF1=1.02988357195356; -PIEF2=1.02988357195356; -PIEH=1.02988357195356; -PIEH1=1.02988357195356; -PIEH2=1.02988357195356; -PIENF=1.02988357195356; -PIENH=1.02988357195356; -PIEWF=1.02988357195356; -PIEWH=1.02988357195356; -PSIF=0.025; -PSIH=0.025; -PSIPRIMEF=1; -PSIPRIMEH=1; -QF=0.875241222929181; -QH=0.0238294319885835; -Q_ONF=0.373740369418894; -Q_ONH=0.0132636199615755; -Q_OTF=0.175247940896905; -Q_OTH=0.00547180886242481; -REALBF=0; -REALBH=0; -REALBH1=0; -REALEX=1.3734519289908; -REALEXF=0.728092464608345; -REALEXH=1.3734519289908; -REALFINH=0; -REALMCNF=0.700562935771035; -REALMCNH=0.752071934789911; -REALMCTF=0.700562935771035; -REALMCTH=0.930081384894704; -REALMONEYF=0.558667031035572; -REALMONEYH=0.661026677383566; -REALPBARMF=0.87146958398196; -REALPBARMH=1.19072687148694; -REALPBARQF=0.899522809530009; -REALPBARQH=1.15219711474356; -REALPLANDF=0.554831427212494; -REALPLANDH=0.414697221827051; -REALPMF=1.16570601700579; -REALPMH=1.37122413583652; -REALPNF=0.840675522925242; -REALPNH=0.902486321747893; -REALPQF=1.19375924255384; -REALPQH=1.33269437909314; -REALPXF=1.19317131724075; -REALPXH=1.36926881180313; -REALP_MOF=0.966533486000563; -REALP_MOH=1.63690883121281; -REALP_ONF=1.18566549908199; -REALP_ONH=1.61601524261254; -REALP_OTF=1.18566549908199; -REALP_OTH=1.62845456685201; -REALP_QOF=1.1918209852569; -REALP_QOH=1.32748728078168; -REALRF=0.0324170717777328; -REALRH=0.0324170717777329; -REALTBALF=-6.93889390390723e-018; -REALTBALH=-6.93889390390723e-018; -REALWF=2.42667732699502; -REALWH=2.83454771236558; -RNOMF=1.03752229232945; -RNOMH=1.03752229232945; -SHOPF=0.00111563864647424; -SHOPH=0.00111563864647424; -SHOPPRIMEF=0.00357861859467432; -SHOPPRIMEH=0.00357861859467432; -TF=0.89833516218424; -TH=0.397076255917254; -T_OF=0.563589013545429; -T_OH=0.417854966062653; -VELOF=3.17898336847443; -VELOH=3.17898336847443; -VPRIMEF=3.62618818940983; -VPRIMEH=4.00467026905301; -XF_NAT=0.0200215045456245; -XH_NAT=0.446747178665936; -XI=0; -ZBF=0; -ZBH=0; -ZEYEF=0; -ZEYEH=0; -ZNF=1; -ZNH=1; -ZTF=1; -ZTH=0.6; -ZUF=1; -ZUH=1; -ZZ_CF=57.5474832617676; -ZZ_CH=74.3715386197541; -ZZ_CURBALF_RAT=2.20209042676066e-016; -ZZ_CURBALH_RAT=0; -ZZ_C_SHARF=0.735399396831762; -ZZ_C_SHARH=0.723339950584259; -ZZ_DPIE4F=0; -ZZ_DPIE4H=0; -ZZ_DRNOMF=0; -ZZ_DRNOMH=0; -ZZ_EXPORTSF=-328.547168610049; -ZZ_EXPORTSH=-2.37054799079326; -ZZ_EYEF=-129.17857393452; -ZZ_EYEH=-100.616387362469; -ZZ_EYE_SHARF=0.113780163180538; -ZZ_EYE_SHARH=0.12585306341233; -ZZ_GDPF=88.1701346139521; -ZZ_GDPH=106.647634229781; -ZZ_GDP_PPP_RATH=0.875857186130553; -ZZ_GF=-101.541863874636; -ZZ_GH=-83.0643642588075; -ZZ_IMPORTSF=-328.547168610049; -ZZ_IMPORTSH=-2.37054799079323; -ZZ_M_ON_SHARF=0.0063593490946998; -ZZ_M_ON_SHARH=0.084149297164759; -ZZ_M_OT_SHARF=0.00298191719568198; -ZZ_M_OT_SHARH=0.0895286056899133; -ZZ_M_O_SHARF=0.00934126629038178; -ZZ_M_O_SHARH=0.173677902854672; -ZZ_M_SHARF=0.00787651700806085; -ZZ_M_SHARH=0.19982806118916; -ZZ_N_SHARF=0.741008772713445; -ZZ_N_SHARH=0.90078198910348; -ZZ_PIE4F=12.5; -ZZ_PIE4H=12.5; -ZZ_REALEX=31.7327227026121; -ZZ_RNOMF=15.8749999999999; -ZZ_RNOMH=15.8749999999999; -ZZ_UTILITYF=-1.86610854895021; -ZZ_UTILITYH=-1.9297829736965; -ZZ_XBALF_TOT_RAT=0; -ZZ_XBALH_TOT_RAT=-7.6432037132987e-015; -Z_OF=1; -Z_OH=1; - -E_ZBH=0; - -E_ZUH=0; -E_ZUF=0; - -E_ZEYEH=0; -E_ZEYEF=0; - -E_GAMMAH=0; -E_GAMMAF=0; - -E_LANDH=0; -E_LANDF=0; - -E_GAH = 0; -E_GAF = 0; - -E_CAPAH=0; -E_CAPAF=0; -end; - -vcov = [ -0.000324 0 0 0 0 0 0 0 0 0 0 0 0; -0 0.0004 0 0 0 0 0 0 0 0 0 0 0; -0 0 0.00000001 0 0 0 0 0 0 0 0 0 0; -0 0 0 0.000004 0 0 0 0 0 0 0 0 0; -0 0 0 0 0.000289 0 0 0 0 0 0 0 0; -0 0 0 0 0 0.000025 0 0 0 0 0 0 0; -0 0 0 0 0 0 0.0049 0 0 0 0 0 0; -0 0 0 0 0 0 0 0.000001 0 0 0 0 0; -0 0 0 0 0 0 0 0 0.000016 0 0 0 0; -0 0 0 0 0 0 0 0 0 0.00001225 0 0 0; -0 0 0 0 0 0 0 0 0 0 0.0000005625 0 0; -0 0 0 0 0 0 0 0 0 0 0 0.01 0; -0 0 0 0 0 0 0 0 0 0 0 0 0.0001 -]; - -order=2; \ No newline at end of file diff --git a/dynare++/tests/judd.mod b/dynare++/tests/judd.mod deleted file mode 100644 index 7acfb1218c13241bc31235bd23956faa1e940b9f..0000000000000000000000000000000000000000 --- a/dynare++/tests/judd.mod +++ /dev/null @@ -1,50 +0,0 @@ -var C K1 K2 L S1 S2 THETA V V1 V2; - -varexo KSI; - -parameters theta_ss lambda delta1 delta2 alpha1 alpha2 eta beta gamma depr1 depr2; - -theta_ss=1; -lambda=0.8; -delta1=0.1; -delta2=0.05; -alpha1=0.3; -alpha2=0.15; -eta=3; -beta=0.95; -gamma=0.5; -depr1=0.1; -depr2=0.05; - -model; -C = THETA*K1^alpha1*K2^alpha2*L^(1-alpha1-alpha2)-S1*K1-S2*K2; -K1 = (1-depr1+(1-0.5*delta1*S1)*S1)*K1(-1); -K2 = (1-depr2+(1-0.5*delta2*S2)*S2)*K2(-1); -THETA = THETA(-1)^lambda*theta_ss^(1-lambda)*exp(KSI); -/* -THETA = THETA(-1)*lambda+theta_ss*(1-lambda)+KSI; -*/ -C^(-gamma)*THETA*K1^alpha1*K2^alpha2*L^(-alpha1-alpha2)*(1-alpha1-alpha2) = L^eta; -C^(-gamma) = beta*V1(+1)*(1-delta1*S1); -C^(-gamma) = beta*V2(+1)*(1-delta2*S2); -V1 = C^(-gamma)*(alpha1*THETA*K1^(alpha1-1)*K2^alpha2*L^(1-alpha1-alpha2)-S1)+beta*V1(+1)*(1-depr1+(1-0.5*delta1*S1)*S1); -V2 = C^(-gamma)*(alpha2*THETA*K1^alpha1*K2^(alpha2-1)*L^(1-alpha1-alpha2)-S2)+beta*V2(+1)*(1-depr2+(1-0.5*delta2*S2)*S2); -V = (C^(1-gamma)/(1-gamma)-L^(1+eta)/(1+eta)) + beta*V(+1); -end; - -initval; -C= 1.33341818203972; -K1= 3.80023995548668; -K2= 3.80023995563911; -L= 0.85120255261552; -S1= 0; -S2= 0; -THETA= 1.00000000000000; -V1= 0.59202988402399; -V2= 0.59202988402399; -V= -17.6239; -end; - -vcov = [ 0.001 ]; - -order = 6; diff --git a/dynare++/tests/judd_norm.mod b/dynare++/tests/judd_norm.mod deleted file mode 100644 index 30a74af3e6c4a8c2ae99c24d89cc2c99a5d83cc3..0000000000000000000000000000000000000000 --- a/dynare++/tests/judd_norm.mod +++ /dev/null @@ -1,50 +0,0 @@ -var C K1 K2 L S1 S2 THETA V V1 V2; - -varexo KSI; - -parameters theta_ss lambda delta1 delta2 alpha1 alpha2 eta beta gamma depr1 depr2; - -theta_ss=1; -lambda=0.5; -delta1=0.05; -delta2=0.2; -alpha1=0.3; -alpha2=0.3; -eta=3; -beta=0.95; -gamma=0.5; -depr1=0.1; -depr2=0.05; - -model; -1 = (THETA*K1^alpha1*K2^alpha2*L^(1-alpha1-alpha2)-S1*K1-S2*K2)/C; -1 = (1-depr1+(1-0.5*delta1*S1)*S1)*K1(-1)/K1; -1 = (1-depr2+(1-0.5*delta2*S2)*S2)*K2(-1)/K2; -1 = THETA(-1)^lambda/THETA*theta_ss^(1-lambda)*exp(KSI); -/* -1 = (THETA(-1)*lambda+theta_ss*(1-lambda)+KSI)/THETA; -*/ -C^(-gamma)*THETA*K1^alpha1*K2^alpha2*L^(-alpha1-alpha2)*(1-alpha1-alpha2)*L^(-eta)=1; -1 = beta*V1(+1)*(1-delta1*S1)*C^gamma; -1 = beta*V2(+1)*(1-delta2*S2)*C^gamma; -1 = (C^(-gamma)*(alpha1*THETA*K1^(alpha1-1)*K2^alpha2*L^(1-alpha1-alpha2)-S1)+beta*V1(+1)*(1-depr1+(1-0.5*delta1*S1)*S1))/V1; -1 = (C^(-gamma)*(alpha2*THETA*K1^alpha1*K2^(alpha2-1)*L^(1-alpha1-alpha2)-S2)+beta*V2(+1)*(1-depr2+(1-0.5*delta2*S2)*S2))/V2; -1 = (C^(1-gamma)/(1-gamma)-L^(1+eta)/(1+eta) + beta*V(+1))/V; -end; - -initval; -C =1.0997055 ; -L =0.9425540 ; -S1 =0.1005051 ; -S2 =0.0500627 ; -K1 =2.9378521 ; -K2 =2.1952681 ; -THETA =1. ; -V =38.000392 ; -V1 =1.0139701 ; -V2 =1.0062981 ; -end; - -vcov = [ 0.05 ]; - -order = 5; diff --git a/dynare++/tests/kp1980_1.mod b/dynare++/tests/kp1980_1.mod deleted file mode 100644 index 8083544a1b34753dcc8bdf69c9699c29d522a769..0000000000000000000000000000000000000000 --- a/dynare++/tests/kp1980_1.mod +++ /dev/null @@ -1,41 +0,0 @@ -// Model from Kydland & Prescott JEDC 1980 - -// case 1: optimal policy, in fact, optimal control - -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; - -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; - -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -end; - -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/alpha)^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -end; - -order = 4; - -vcov = [ - 0.01 -]; diff --git a/dynare++/tests/kp1980_2.mod b/dynare++/tests/kp1980_2.mod deleted file mode 100644 index 6d9d58f73396f30744ea9dde4d043195a0ae84c9..0000000000000000000000000000000000000000 --- a/dynare++/tests/kp1980_2.mod +++ /dev/null @@ -1,42 +0,0 @@ -// Model from Kydland & Prescott JEDC 1980 - -// case 2: time inconsistent optimal policy with different policy and consumer objectives - -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; - -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; - -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -C^(-eta) = beta*C(+1)^(-eta)*(1-delta+exp(Z(+1))*alpha*K(+1)^(alpha-1)*(1-alpha*TAU(+1))); -end; - -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/(alpha*(1-alpha*TAU)))^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -end; - -order = 4; - -vcov = [ - 0.01 -]; diff --git a/dynare++/tests/kp1980_3.mod b/dynare++/tests/kp1980_3.mod deleted file mode 100644 index 9bb36f12680c72698c289166966747c8dde9a43f..0000000000000000000000000000000000000000 --- a/dynare++/tests/kp1980_3.mod +++ /dev/null @@ -1,42 +0,0 @@ -// Model from Kydland & Prescott JEDC 1980 - -// case 3: optimal policy with consistent objective (equivalent to kp1980_1.dyn) - -var C G K TAU Z; - -varexo EPS; - -parameters eta beta alpha delta phi a rho; - -eta = 2; -beta = 0.99; -alpha = 0.3; -delta = 0.10; -phi = 2.5; -a = 0.1; -rho = 0.7; - -planner_objective C^(1-eta)/(1-eta) + a*G^(1-phi)/(1-phi); - -planner_discount beta; - -model; -K = (1-delta)*K(-1) + (exp(Z(-1))*K(-1)^alpha - C(-1) - G(-1)); -G = TAU*alpha*K^alpha; -Z = rho*Z(-1) + EPS; -C^(-eta) = beta*C(+1)^(-eta)*(1-delta+exp(Z(+1))*alpha*K(+1)^(alpha-1)*(1-alpha*TAU(+1))) + beta*a*G(+1)^(-phi)*TAU(+1)*exp(Z(+1))*alpha^2*K(+1)^(alpha-1); -end; - -initval; -TAU = 0.70; -K = ((delta+1/beta-1)/alpha)^(1/(alpha-1)); -G = TAU*alpha*K^alpha; -C = K^alpha - delta*K - G; -Z = 0; -end; - -order = 4; - -vcov = [ - 0.01 -]; diff --git a/dynare++/tests/lucas78.mod b/dynare++/tests/lucas78.mod deleted file mode 100644 index c4c1a8ae1836db2bbeaed62a50ff76ac9c67dbaf..0000000000000000000000000000000000000000 --- a/dynare++/tests/lucas78.mod +++ /dev/null @@ -1,26 +0,0 @@ -var Y P; - -varexo EXO_Y; - -parameters beta gamma rho y_ss; - -beta = 0.95; -gamma= 0.5; -rho = 0.9; -y_ss = 2; - -model; -Y-y_ss = rho*(Y(-1)-y_ss) + EXO_Y; -Y^(-gamma)*P = beta*Y(+1)^(-gamma)*(P(+1) + Y(+1)); -end; - -initval; -Y = 2; -P = 38; -end; - -vcov = [ -10 -]; - -order = 7; diff --git a/dynare++/tests/m_0_3_0_0_0_0_0_0.mod b/dynare++/tests/m_0_3_0_0_0_0_0_0.mod deleted file mode 100644 index 1d7c522b441eceb1bc99c7aa561dc7645488287e..0000000000000000000000000000000000000000 --- a/dynare++/tests/m_0_3_0_0_0_0_0_0.mod +++ /dev/null @@ -1,47 +0,0 @@ -var lambda a1 a2 k1 k2 i1 i2 c1 c2 l1 l2; -varexo e e1 e2; -parameters beta delta rho sigma phi AA alpha gamma mu chi b Le tau; -beta = 0.99; -delta = 0.025; -rho = 0.95; -sigma = 0.001; -phi = 0.5; -alpha = 0.36; -AA = 0.028058361; -tau = 6.36522e-11; -gamma = 0.25; -mu = -0.2; -chi = 0.83; -b = 2.16872693993; -Le = 2.5; - -model; -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -lambda = tau*c1^(-1/chi)*(c1^(1-1/chi)+b*(Le-l1)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1); -lambda = tau*c2^(-1/chi)*(c2^(1-1/chi)+b*(Le-l2)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1); -tau*(-b)*(Le-l1)^(-1/chi)*(c1^(1-1/chi)+b*(Le-l1)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1) = -lambda*a1*AA*(1-alpha)*l1^(mu-1)*(alpha*k1(-1)^mu+(1-alpha)*l1^mu)^(1/mu-1); -tau*(-b)*(Le-l2)^(-1/chi)*(c2^(1-1/chi)+b*(Le-l2)^(1-1/chi))^((1-1/gamma)/(1-1/chi)-1) = -lambda*a2*AA*(1-alpha)*l2^(mu-1)*(alpha*k2(-1)^mu+(1-alpha)*l2^mu)^(1/mu-1); -lambda*(1+phi*(i1/k1(-1)-delta)) =beta*lambda(+1)*(1+a1(+1)*AA*alpha*k1^(mu-1)*(alpha*k1^mu+(1-alpha)*l1(+1)^mu)^(1/mu-1)+phi*(1-delta+i1(+1)/k1-0.5*(i1(+1)/k1-delta))*(i1(+1)/k1-delta)); -lambda*(1+phi*(i2/k2(-1)-delta)) =beta*lambda(+1)*(1+a2(+1)*AA*alpha*k2^(mu-1)*(alpha*k2^mu+(1-alpha)*l2(+1)^mu)^(1/mu-1)+phi*(1-delta+i2(+1)/k2-0.5*(i2(+1)/k2-delta))*(i2(+1)/k2-delta)); -k1 = i1 + (1-delta)*k1(-1); -k2 = i2 + (1-delta)*k2(-1); -c1+i1-delta*k1(-1) + c2+i2-delta*k2(-1) = a1*AA*(alpha*k1(-1)^mu+(1-alpha)*l1^mu)^(1/mu)-(phi/2)*k1(-1)*(i1/k1(-1)-delta)^2 + a2*AA*(alpha*k2(-1)^mu+(1-alpha)*l2^mu)^(1/mu)-(phi/2)*k2(-1)*(i2/k2(-1)-delta)^2; -end; -initval; -a1 = 1; -a2 = 1; -k1 = 1; -k2 = 1; -c1 = 0.028058361; -c2 = 0.028058361; -i1 = 0.025; -i2 = 0.025; -l1 = 1; -l2 = 1; -lambda = 1; -end; - -vcov = [1 0 0; 0 1 0; 0 0 1]; - -order = 4; \ No newline at end of file diff --git a/dynare++/tests/m_1_3_0_0_0_0_0_0.mod b/dynare++/tests/m_1_3_0_0_0_0_0_0.mod deleted file mode 100644 index a95e8137d9c3ef1d0e7d6665a2ec1c9b6af4efa6..0000000000000000000000000000000000000000 --- a/dynare++/tests/m_1_3_0_0_0_0_0_0.mod +++ /dev/null @@ -1,53 +0,0 @@ -var lambda a1 a2 k1 k2 i1 i2 c1 c2 l1 l2; -varexo e e1 e2; -parameters beta delta rho sigma phi AA alpha Le gamma1 gamma2 mu1 mu2 chi1 chi2 b1 b2 tau1 tau2; -beta = 0.99; -delta = 0.025; -rho = 0.95; -sigma = 0.01; -phi = 0.5; -alpha = 0.36; -AA = 0.028058361; -tau1 = 1.0604611e-11; -tau2 = 2.9305887e-08; -Le = 2.5; -gamma1 = 0.2; -gamma2 = 0.4; -chi1 = 0.75; -chi2 = 0.9; -mu1 = -0.3; -mu2 = 0.3; -b1 = 3.6164368; -b2 = 1.4937381; - -model; -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -lambda = tau1*c1^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1); -lambda = tau2*c2^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1); -tau1*(-b1)*(Le-l1)^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1) = -lambda*a1*AA*(1-alpha)*l1^(mu1-1)*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1-1); -tau2*(-b2)*(Le-l2)^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1) = -lambda*a2*AA*(1-alpha)*l2^(mu2-1)*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2-1); -lambda*(1+phi*(i1/k1(-1)-delta)) =beta*lambda(+1)*(1+a1(+1)*AA*alpha*k1^(mu1-1)*(alpha*k1^mu1+(1-alpha)*l1(+1)^mu1)^(1/mu1-1)+phi*(1-delta+i1(+1)/k1-0.5*(i1(+1)/k1-delta))*(i1(+1)/k1-delta)); -lambda*(1+phi*(i2/k2(-1)-delta)) =beta*lambda(+1)*(1+a2(+1)*AA*alpha*k2^(mu2-1)*(alpha*k2^mu2+(1-alpha)*l2(+1)^mu2)^(1/mu2-1)+phi*(1-delta+i2(+1)/k2-0.5*(i2(+1)/k2-delta))*(i2(+1)/k2-delta)); -k1 = i1 + (1-delta)*k1(-1); -k2 = i2 + (1-delta)*k2(-1); -c1+i1-delta*k1(-1) + c2+i2-delta*k2(-1) = a1*AA*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1)-(phi/2)*k1(-1)*(i1/k1(-1)-delta)^2 + a2*AA*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2)-(phi/2)*k2(-1)*(i2/k2(-1)-delta)^2; -end; - -initval; -a1 = 1; -a2 = 1; -k1 = 1; -k2 = 1; -c1 = 0.028058361; -c2 = 0.028058361; -i1 = 0.025; -i2 = 0.025; -l1 = 1; -l2 = 1; -lambda = 1; -end; - -vcov = [1 0 0; 0 1 0; 0 0 1]; - -order = 4; diff --git a/dynare++/tests/m_1_3_0_0_0_0_0_1.mod b/dynare++/tests/m_1_3_0_0_0_0_0_1.mod deleted file mode 100644 index 05e29ffd81f6b96b239692f63fa69323e1361d95..0000000000000000000000000000000000000000 --- a/dynare++/tests/m_1_3_0_0_0_0_0_1.mod +++ /dev/null @@ -1,82 +0,0 @@ -var lambda a1 a2 a3 a4 k1 k2 k3 k4 i1 i2 i3 i4 c1 c2 c3 c4 l1 l2 l3 l4; -varexo e e1 e2 e3 e4; -parameters beta delta rho sigma phi AA alpha Le gamma1 gamma2 gamma3 gamma4 mu1 mu2 mu3 mu4 chi1 chi2 chi3 chi4 b1 b2 b3 b4 tau1 tau2 tau3 tau4; -beta = 0.99; -delta = 0.025; -rho = 0.95; -sigma = 0.001; -phi = 0.5; -alpha = 0.36; -AA = 0.028058361; -tau1 = 1.0604611e-11; -tau2 = 1.8099765e-09; -tau3 = 2.1096359e-08; -tau4 = 2.9305887e-08; -Le = 2.5; -gamma1 = 0.2; -gamma2 = 0.266666666667; -gamma3 = 0.333333333333; -gamma4 = 0.4; -chi1 = 0.75; -chi2 = 0.8; -chi3 = 0.85; -chi4 = 0.9; -mu1 = -0.3; -mu2 = -0.1; -mu3 = 0.1; -mu4 = 0.3; -b1 = 3.6164368; -b2 = 2.5958433; -b3 = 1.9373921; -b4 = 1.4937381; - -model; -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -log(a3) = rho*log(a3(-1))+sigma*(e+e3); -log(a4) = rho*log(a4(-1))+sigma*(e+e4); -lambda = tau1*c1^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1); -lambda = tau2*c2^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1); -lambda = tau3*c3^(-1/chi3)*(c3^(1-1/chi3)+b3*(Le-l3)^(1-1/chi3))^((1-1/gamma3)/(1-1/chi3)-1); -lambda = tau4*c4^(-1/chi4)*(c4^(1-1/chi4)+b4*(Le-l4)^(1-1/chi4))^((1-1/gamma4)/(1-1/chi4)-1); -tau1*(-b1)*(Le-l1)^(-1/chi1)*(c1^(1-1/chi1)+b1*(Le-l1)^(1-1/chi1))^((1-1/gamma1)/(1-1/chi1)-1) = -lambda*a1*AA*(1-alpha)*l1^(mu1-1)*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1-1); -tau2*(-b2)*(Le-l2)^(-1/chi2)*(c2^(1-1/chi2)+b2*(Le-l2)^(1-1/chi2))^((1-1/gamma2)/(1-1/chi2)-1) = -lambda*a2*AA*(1-alpha)*l2^(mu2-1)*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2-1); -tau3*(-b3)*(Le-l3)^(-1/chi3)*(c3^(1-1/chi3)+b3*(Le-l3)^(1-1/chi3))^((1-1/gamma3)/(1-1/chi3)-1) = -lambda*a3*AA*(1-alpha)*l3^(mu3-1)*(alpha*k3(-1)^mu3+(1-alpha)*l3^mu3)^(1/mu3-1); -tau4*(-b4)*(Le-l4)^(-1/chi4)*(c4^(1-1/chi4)+b4*(Le-l4)^(1-1/chi4))^((1-1/gamma4)/(1-1/chi4)-1) = -lambda*a4*AA*(1-alpha)*l4^(mu4-1)*(alpha*k4(-1)^mu4+(1-alpha)*l4^mu4)^(1/mu4-1); -lambda*(1+phi*(i1/k1(-1)-delta)) =beta*lambda(+1)*(1+a1(+1)*AA*alpha*k1^(mu1-1)*(alpha*k1^mu1+(1-alpha)*l1(+1)^mu1)^(1/mu1-1)+phi*(1-delta+i1(+1)/k1-0.5*(i1(+1)/k1-delta))*(i1(+1)/k1-delta)); -lambda*(1+phi*(i2/k2(-1)-delta)) =beta*lambda(+1)*(1+a2(+1)*AA*alpha*k2^(mu2-1)*(alpha*k2^mu2+(1-alpha)*l2(+1)^mu2)^(1/mu2-1)+phi*(1-delta+i2(+1)/k2-0.5*(i2(+1)/k2-delta))*(i2(+1)/k2-delta)); -lambda*(1+phi*(i3/k3(-1)-delta)) =beta*lambda(+1)*(1+a3(+1)*AA*alpha*k3^(mu3-1)*(alpha*k3^mu3+(1-alpha)*l3(+1)^mu3)^(1/mu3-1)+phi*(1-delta+i3(+1)/k3-0.5*(i3(+1)/k3-delta))*(i3(+1)/k3-delta)); -lambda*(1+phi*(i4/k4(-1)-delta)) =beta*lambda(+1)*(1+a4(+1)*AA*alpha*k4^(mu4-1)*(alpha*k4^mu4+(1-alpha)*l4(+1)^mu4)^(1/mu4-1)+phi*(1-delta+i4(+1)/k4-0.5*(i4(+1)/k4-delta))*(i4(+1)/k4-delta)); -k1 = i1 + (1-delta)*k1(-1); -k2 = i2 + (1-delta)*k2(-1); -k3 = i3 + (1-delta)*k3(-1); -k4 = i4 + (1-delta)*k4(-1); -c1+i1-delta*k1(-1) + c2+i2-delta*k2(-1) + c3+i3-delta*k3(-1) + c4+i4-delta*k4(-1) = a1*AA*(alpha*k1(-1)^mu1+(1-alpha)*l1^mu1)^(1/mu1)-(phi/2)*k1(-1)*(i1/k1(-1)-delta)^2 + a2*AA*(alpha*k2(-1)^mu2+(1-alpha)*l2^mu2)^(1/mu2)-(phi/2)*k2(-1)*(i2/k2(-1)-delta)^2 + a3*AA*(alpha*k3(-1)^mu3+(1-alpha)*l3^mu3)^(1/mu3)-(phi/2)*k3(-1)*(i3/k3(-1)-delta)^2 + a4*AA*(alpha*k4(-1)^mu4+(1-alpha)*l4^mu4)^(1/mu4)-(phi/2)*k4(-1)*(i4/k4(-1)-delta)^2; -end; -initval; -a1 = 1; -a2 = 1; -a3 = 1; -a4 = 1; -k1 = 1; -k2 = 1; -k3 = 1; -k4 = 1; -c1 = 0.028058361; -c2 = 0.028058361; -c3 = 0.028058361; -c4 = 0.028058361; -i1 = 0.025; -i2 = 0.025; -i3 = 0.025; -i4 = 0.025; -l1 = 1; -l2 = 1; -l3 = 1; -l4 = 1; -lambda = 1; -end; - -vcov = [1.0 0 0 0 0; 0 1.0 0 0 0; 0 0 1.0 0 0; 0 0 0 1.0 0; 0 0 0 0 1.0]; - -order = 4; diff --git a/dynare++/tests/or0a.mod b/dynare++/tests/or0a.mod deleted file mode 100644 index 20b962e284c71e5743eb4f2595d19e45d8ac9dce..0000000000000000000000000000000000000000 --- a/dynare++/tests/or0a.mod +++ /dev/null @@ -1,119 +0,0 @@ -var -C -CF -CF_STAR -CH -CH_STAR -CN -CN_STAR -CT -CT_STAR -C_STAR -E -KE -KE_STAR -L -L_STAR -P -PF -PF_STAR -PH -PH_STAR -PN -PN_STAR -PT -PT_STAR -P_STAR -W -W_STAR -Y -Y_STAR -; - -varexo k k_star m m_star; - -parameters epsi chi thet nu phi gam; - -epsi = 0.5; -nu = 3; -chi = 1.2; -phi = 4; -thet = 3; -gam = 0.5; - -model; -C = (1/chi)*(exp(m)/P)^epsi; -C_STAR = (1/chi)*(exp(m_star)/P_STAR)^epsi; -CN = (1-gam)*(P/PN)*C; -CN_STAR = (1-gam)*(P_STAR/PN_STAR)*C_STAR; -CT = gam*(P/PT)*C; -CT_STAR = gam*(P_STAR/PT_STAR)*C_STAR; -CH = 0.5*(PT/PH)*CT; -CH_STAR = 0.5*(PT_STAR/PH_STAR)*CT_STAR; -CF = 0.5*(PT/PF)*CT; -CF_STAR = 0.5*(PT_STAR/PF_STAR)*CT_STAR; -P = PT^gam*PN^(1-gam); -P_STAR = PT_STAR^gam*PN_STAR^(1-gam); -PT = sqrt(PH*PF); -PT_STAR = sqrt(PH_STAR*PF_STAR); -PH = (thet/(thet-1))*W(-1); -PF_STAR = (thet/(thet-1))*W_STAR(-1); -PN = PH; -PN_STAR = PF_STAR; -L = Y; -L_STAR = Y_STAR; -(L(+1)/(P(+1)*C(+1)))*W = (phi/(phi-1))*KE(+1)*L(+1)^nu; -(L_STAR(+1)/(P_STAR(+1)*C_STAR(+1)))*W_STAR = (phi/(phi-1))*KE_STAR(+1)*L_STAR(+1)^nu; -P*C = Y*PH; -P_STAR*C_STAR = Y_STAR*PF_STAR; -Y = CH + CH_STAR + CN; -Y_STAR = CF + CF_STAR + CN_STAR; -PT = E*PT_STAR; -KE = exp(k); -KE_STAR = exp(k_star); -end; - -initval; -C = 1; -PH = 1; -P = 1; -PN = 1; -PT = 1; -L = 1; -Y = 1; -W = 1; -CF = 0.25; -CH = 0.25; -CT = 0.5; -CN = 0.5; -PF = 1; -C_STAR = 1; -PH_STAR = 1; -P_STAR = 1; -PN_STAR = 1; -PT_STAR = 1; -L_STAR = 1; -Y_STAR = 1; -W_STAR = 1; -CF_STAR = 0.25; -CH_STAR = 0.25; -CT_STAR = 0.5; -CN_STAR = 0.5; -PF_STAR = 1; -KE = 1; -KE_STAR = 1; -E = 1; -k = 0; -k_star = 0; -m = 0; -m_star = 0; -end; - -vcov = [ -0.01 0 -0.01 0; -0 0.01 0 -0.01; --0.01 0 0.01 0; -0 -0.01 0 0.01 -]; - -order=4; diff --git a/dynare++/tests/portfolio.mod b/dynare++/tests/portfolio.mod deleted file mode 100644 index 5309dce0bf15dad4f40bbf6e0a8abd70ba18e772..0000000000000000000000000000000000000000 --- a/dynare++/tests/portfolio.mod +++ /dev/null @@ -1,52 +0,0 @@ -var DOTQ Q1 Q2 X1 X2 C D1 D2; - -varexo E_D1 E_D2; - -parameters beta, r1, r2, gamma, d, rho1, rho2; - -beta = 0.95; -r1 = 0.2; -r2 = 0.05; - -gamma = 0.78; -d = 0.10; - -rho1 = 0.8; -rho2 = 0.2; - -model; -C + X1 + X2 = D1*Q1 + D2*Q2; -Q1+Q2 = 1; -C^(-gamma)/(1-2*r1*X1) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r1*X1(+1))*(D1(+1)*(1-2*r1*X1(+1))+1); -C^(-gamma)/(1-2*r2*X2) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r2*X2(+1))*(D2(+1)*(1-2*r2*X2(+1))+1); -DOTQ*Q1 = Q1(-1) + X1(-1) - r1*X1(-1)^2; -DOTQ*Q2 = Q2(-1) + X2(-1) - r2*X2(-1)^2; - -D1/d = D1(-1)^rho1/(d^rho1)*exp(E_D1); -D2/d = D2(-1)^rho2/(d^rho2)*exp(E_D2); - -/* -D1-d = rho1*(D1(-1)-d) + E_D1; -D2-d = rho2*(D2(-1)-d) + E_D2; -*/ -end; - -initval; -C =0.0441234; -D1 =0.1000000000000; -D2 =0.1000000000000; - -DOTQ =1.05567; -Q1 =0.333333; -Q2 =0.666667; - -X1 =0.0186255; -X2 =0.0372511; -end; - -vcov = [ -0.04 0; -0 0.01 -]; - -order=5; diff --git a/dynare++/tests/portfolio4.mod b/dynare++/tests/portfolio4.mod deleted file mode 100644 index 4413aa5ed72ab702c97f0c4c3a14e62f081104d3..0000000000000000000000000000000000000000 --- a/dynare++/tests/portfolio4.mod +++ /dev/null @@ -1,86 +0,0 @@ -var DOTQ Q1 Q2 Q3 Q4 X1 X2 X3 X4 C D1 D2 D3 D4 V; - -varexo E_D1 E_D2 E_D3 E_D4; - -parameters beta, r1, r2, r3, r4, gamma, ed1, ed2, ed3, ed4, rho1, rho2, rho3, rho4; - -beta = 0.95; -r1 = 0.2; -r2 = 0.1; -r3 = 0.06; -r4 = 0.03; - -gamma = 0.7; -ed1 = 0.1; -ed2 = 0.1; -ed3 = 0.1; -ed4 = 0.1; - -rho1 = 0.3; -rho2 = 0.01; -rho3 = 0.6; -rho4 = 0.6; - -model; -Q1+Q2+Q3+Q4 = 1; -C + X1 + X2 + X3 + X4 = D1*Q1 + D2*Q2 + D3*Q3 + D4*Q4; -DOTQ*Q1 = Q1(-1) + X1(-1) - r1*X1(-1)*X1(-1); -DOTQ*Q2 = Q2(-1) + X2(-1) - r2*X2(-1)*X2(-1); -DOTQ*Q3 = Q3(-1) + X3(-1) - r3*X3(-1)*X3(-1); -DOTQ*Q4 = Q4(-1) + X4(-1) - r4*X4(-1)*X4(-1); -C^(-gamma)/(1-2*r1*X1) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r1*X1(+1))*(D1(+1)*(1-2*r1*X1(+1))+1); -C^(-gamma)/(1-2*r2*X2) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r2*X2(+1))*(D2(+1)*(1-2*r2*X2(+1))+1); -C^(-gamma)/(1-2*r3*X3) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r3*X3(+1))*(D3(+1)*(1-2*r3*X3(+1))+1); -C^(-gamma)/(1-2*r4*X4) = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r4*X4(+1))*(D4(+1)*(1-2*r4*X4(+1))+1); - -V = C^(1-gamma)/(1-gamma) + beta*V(+1); - -D1/ed1 = D1(-1)^rho1/(ed1^rho1)*exp(E_D1); -D2/ed2 = D2(-1)^rho2/(ed2^rho2)*exp(E_D2); -D3/ed3 = D3(-1)^rho3/(ed3^rho3)*exp(E_D3); -D4/ed4 = D4(-1)^rho4/(ed4^rho4)*exp(E_D4); - -/* -D1-ed1 = rho1*(D1(-1)-ed1) + E_D1; -D2-ed2 = rho2*(D2(-1)-ed2) + E_D2; -D3-ed3 = rho3*(D3(-1)-ed3) + E_D3; -D4-ed4 = rho4*(D4(-1)-ed4) + E_D4; -*/ - -end; - -initval; -D1 = ed1; -D2 = ed2; -D3 = ed3; -D4 = ed4; -DOTQ = 1.05; // provide a guess not larger than the true value -X1 = 1/2/r1*(1-1/D1*(1/beta*DOTQ^gamma - 1)); -X2 = 1/2/r2*(1-1/D2*(1/beta*DOTQ^gamma - 1)); -X3 = 1/2/r3*(1-1/D3*(1/beta*DOTQ^gamma - 1)); -X4 = 1/2/r4*(1-1/D4*(1/beta*DOTQ^gamma - 1)); -Q1 = 1/(DOTQ-1)*(X1 - r1*X1*X1); -Q2 = 1/(DOTQ-1)*(X2 - r2*X2*X2); -Q3 = 1/(DOTQ-1)*(X3 - r3*X3*X3); -Q4 = 1/(DOTQ-1)*(X4 - r4*X4*X4); -C = ed1*Q1 + ed2*Q2 + ed3*Q3 + ed4*Q4 - X1 - X2 - X3 - X4; -V = 1/(1-beta)*C^(1-gamma)/(1-gamma); -end; - -/* -vcov = [ -0.0005 0 0 0; -0 0.00025 0 0; -0 0 0.0005 0; -0 0 0 0.00025 -]; -*/ - -vcov = [ -0.05 0 0 0; -0 0.025 0 0; -0 0 0.05 0; -0 0 0 0.025 -]; - -order=5; diff --git a/dynare++/tests/portfolio4_norm.mod b/dynare++/tests/portfolio4_norm.mod deleted file mode 100644 index fdedaaa5a2278b640863e4f71964102f86761692..0000000000000000000000000000000000000000 --- a/dynare++/tests/portfolio4_norm.mod +++ /dev/null @@ -1,86 +0,0 @@ -var DOTQ Q1 Q2 Q3 Q4 X1 X2 X3 X4 C D1 D2 D3 D4 V; - -varexo E_D1 E_D2 E_D3 E_D4; - -parameters beta, r1, r2, r3, r4, gamma, ed1, ed2, ed3, ed4, rho1, rho2, rho3, rho4; - -beta = 0.95; -r1 = 0.2; -r2 = 0.1; -r3 = 0.06; -r4 = 0.03; - -gamma = 0.7; -ed1 = 0.1; -ed2 = 0.1; -ed3 = 0.1; -ed4 = 0.1; - -rho1 = 0.3; -rho2 = 0.01; -rho3 = 0.6; -rho4 = 0.6; - -model; -1 = (C + X1 + X2 + X3 + X4)/ (D1*Q1 + D2*Q2 + D3*Q3 + D4*Q4); -1 = (Q1(-1) + X1(-1) - r1*X1(-1)*X1(-1))/(DOTQ*Q1); -1 = (Q2(-1) + X2(-1) - r2*X2(-1)*X2(-1))/(DOTQ*Q2); -1 = (Q3(-1) + X3(-1) - r3*X3(-1)*X3(-1))/(DOTQ*Q3); -1 = (Q4(-1) + X4(-1) - r4*X4(-1)*X4(-1))/(DOTQ*Q4); -Q1+Q2+Q3+Q4 = 1; -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r1*X1(+1))*(D1(+1)*(1-2*r1*X1(+1))+1)/(C^(-gamma)/(1-2*r1*X1)); -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r2*X2(+1))*(D2(+1)*(1-2*r2*X2(+1))+1)/(C^(-gamma)/(1-2*r2*X2)); -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r3*X3(+1))*(D3(+1)*(1-2*r3*X3(+1))+1)/(C^(-gamma)/(1-2*r3*X3)); -1 = beta*DOTQ(+1)^(-gamma)*C(+1)^(-gamma)/(1-2*r4*X4(+1))*(D4(+1)*(1-2*r4*X4(+1))+1)/(C^(-gamma)/(1-2*r4*X4)); - - -1 = D1(-1)^rho1/D1*ed1^(1-rho1)*exp(E_D1); -1 = D2(-1)^rho2/D2*ed2^(1-rho2)*exp(E_D2); -1 = D3(-1)^rho3/D3*ed3^(1-rho3)*exp(E_D3); -1 = D4(-1)^rho4/D4*ed4^(1-rho4)*exp(E_D4); - -/* -D1-ed1 = rho1*(D1(-1)-ed1) + E_D1; -D2-ed2 = rho2*(D2(-1)-ed2) + E_D2; -D3-ed3 = rho3*(D3(-1)-ed3) + E_D3; -D4-ed4 = rho4*(D4(-1)-ed4) + E_D4; -*/ - -V/(C^(1-gamma)/(1-gamma) + beta*V(+1)) = 1; -end; - -initval; -Q1 =0.0769231; -Q2 =0.1538462; -Q3 =0.2564103; -Q4 =0.5128205; -X1 =0.0049761; -X2 =0.0099522; -X3 =0.0165871; -X4 =0.0331741; -D1 =0.1; -D2 =0.1; -D3 =0.1; -D4 =0.1; -DOTQ =1.0646251; -C =0.0353105; -V =24.450057; -end; - -/* -vcov = [ -0.0005 0 0 0; -0 0.00025 0 0; -0 0 0.0005 0; -0 0 0 0.00025 -]; -*/ - -vcov = [ -0.05 0 0 0; -0 0.025 0 0; -0 0 0.05 0; -0 0 0 0.025 -]; - -order=4; diff --git a/dynare++/tests/psd_exo3.mod b/dynare++/tests/psd_exo3.mod deleted file mode 100644 index ff59dab3604e5d162bb7830ae17481d01902d49e..0000000000000000000000000000000000000000 --- a/dynare++/tests/psd_exo3.mod +++ /dev/null @@ -1,26 +0,0 @@ -var c k x; -varexo rho; - -parameters a alph gam bet lamb; -alph = 0.7; -bet = 0.95; -gam = 2; -a = 1.052632; -lamb = 0.9; - -model; -c^(-gam) = bet*c(+1)^(-gam)*a*exp(x(+1))*k^(-alph); -k = a*exp(x)*k(-1)^(1-alph)/(1-alph)-c; -x = lamb*x(-1)+rho; -end; - -initval; -k = 1; -c = 2.508; -x = 0; -rho = 0; -end; - -vcov=[0.0001]; - -order=6; \ No newline at end of file diff --git a/dynare++/tests/q3a2.mod b/dynare++/tests/q3a2.mod deleted file mode 100644 index 650b27d3f92d2d3ce54612012fc2e2d1b20cc7ab..0000000000000000000000000000000000000000 --- a/dynare++/tests/q3a2.mod +++ /dev/null @@ -1,33 +0,0 @@ -var c,a1,k1,a2,k2; -varexo e,e1,e2; -parameters beta, gamma, phi, delta, alpha, rho, zeta, sigma, N; -alpha = 0.36; -delta = 0.025; -phi = 2; -gamma = 1; -beta = 0.99; -rho = 0.95; -zeta = 2; -sigma = 0.005; -N = 2; -model; -c^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))+phi*(k1-k1(-1))^zeta/(2*k1(-1)^2)-delta+alpha*a1(+1)*k1^(alpha-1)); -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -c^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))+phi*(k2-k2(-1))^zeta/(2*k2(-1)^2)-delta+alpha*a2(+1)*k2^(alpha-1)); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -N*c+k1+phi*(k1-k1(-1))^zeta/(2*k1)-(1-delta)*k1(-1)+k2+phi*(k2-k2(-1))^zeta/(2*k2)-(1-delta)*k2(-1)= a1*k1(-1)^alpha+a2*k2(-1)^alpha; -end; -initval; -c=1; -e=0; -a1=1; -e1=0; -k1=10; -a2=1; -e2=0; -k2=10; -end; - -vcov=[1 0 0; 0 1 0; 0 0 1]; - -order = 4; \ No newline at end of file diff --git a/dynare++/tests/q3a50.mod b/dynare++/tests/q3a50.mod deleted file mode 100644 index df2fe4c6ef9e1f93d0afa25ec11c9ddd63acbccb..0000000000000000000000000000000000000000 --- a/dynare++/tests/q3a50.mod +++ /dev/null @@ -1,324 +0,0 @@ -var c,a1,k1,a2,k2,a3,k3,a4,k4,a5,k5,a6,k6,a7,k7,a8,k8,a9,k9,a10,k10,a11,k11,a12,k12,a13,k13,a14,k14,a15,k15,a16,k16,a17,k17,a18,k18,a19,k19,a20,k20,a21,k21,a22,k22,a23,k23,a24,k24,a25,k25,a26,k26,a27,k27,a28,k28,a29,k29,a30,k30,a31,k31,a32,k32,a33,k33,a34,k34,a35,k35,a36,k36,a37,k37,a38,k38,a39,k39,a40,k40,a41,k41,a42,k42,a43,k43,a44,k44,a45,k45,a46,k46,a47,k47,a48,k48,a49,k49,a50,k50; -varexo e,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16,e17,e18,e19,e20,e21,e22,e23,e24,e25,e26,e27,e28,e29,e30,e31,e32,e33,e34,e35,e36,e37,e38,e39,e40,e41,e42,e43,e44,e45,e46,e47,e48,e49,e50; -parameters beta, gamma, phi, delta, alpha, rho, zeta, sigma, N; -alpha = 0.36; -delta = 0.1; -phi = 2; -gamma = 1; -beta = 0.99; -rho = 0.95; -zeta = 2; -sigma = 2; -N = 50; -model; -c^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k1-k1(-1))^(zeta-1)/(2*k1(-1))+phi*(k1-k1(-1))^zeta/(2*k1(-1)^2)-delta+alpha*a1(+1)*k1^(alpha-1)); -log(a1) = rho*log(a1(-1))+sigma*(e+e1); -c^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k2-k2(-1))^(zeta-1)/(2*k2(-1))+phi*(k2-k2(-1))^zeta/(2*k2(-1)^2)-delta+alpha*a2(+1)*k2^(alpha-1)); -log(a2) = rho*log(a2(-1))+sigma*(e+e2); -c^(-gamma)*(1+phi*zeta*(k3-k3(-1))^(zeta-1)/(2*k3(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k3-k3(-1))^(zeta-1)/(2*k3(-1))+phi*(k3-k3(-1))^zeta/(2*k3(-1)^2)-delta+alpha*a3(+1)*k3^(alpha-1)); -log(a3) = rho*log(a3(-1))+sigma*(e+e3); -c^(-gamma)*(1+phi*zeta*(k4-k4(-1))^(zeta-1)/(2*k4(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k4-k4(-1))^(zeta-1)/(2*k4(-1))+phi*(k4-k4(-1))^zeta/(2*k4(-1)^2)-delta+alpha*a4(+1)*k4^(alpha-1)); -log(a4) = rho*log(a4(-1))+sigma*(e+e4); -c^(-gamma)*(1+phi*zeta*(k5-k5(-1))^(zeta-1)/(2*k5(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k5-k5(-1))^(zeta-1)/(2*k5(-1))+phi*(k5-k5(-1))^zeta/(2*k5(-1)^2)-delta+alpha*a5(+1)*k5^(alpha-1)); -log(a5) = rho*log(a5(-1))+sigma*(e+e5); -c^(-gamma)*(1+phi*zeta*(k6-k6(-1))^(zeta-1)/(2*k6(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k6-k6(-1))^(zeta-1)/(2*k6(-1))+phi*(k6-k6(-1))^zeta/(2*k6(-1)^2)-delta+alpha*a6(+1)*k6^(alpha-1)); -log(a6) = rho*log(a6(-1))+sigma*(e+e6); -c^(-gamma)*(1+phi*zeta*(k7-k7(-1))^(zeta-1)/(2*k7(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k7-k7(-1))^(zeta-1)/(2*k7(-1))+phi*(k7-k7(-1))^zeta/(2*k7(-1)^2)-delta+alpha*a7(+1)*k7^(alpha-1)); -log(a7) = rho*log(a7(-1))+sigma*(e+e7); -c^(-gamma)*(1+phi*zeta*(k8-k8(-1))^(zeta-1)/(2*k8(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k8-k8(-1))^(zeta-1)/(2*k8(-1))+phi*(k8-k8(-1))^zeta/(2*k8(-1)^2)-delta+alpha*a8(+1)*k8^(alpha-1)); -log(a8) = rho*log(a8(-1))+sigma*(e+e8); -c^(-gamma)*(1+phi*zeta*(k9-k9(-1))^(zeta-1)/(2*k9(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k9-k9(-1))^(zeta-1)/(2*k9(-1))+phi*(k9-k9(-1))^zeta/(2*k9(-1)^2)-delta+alpha*a9(+1)*k9^(alpha-1)); -log(a9) = rho*log(a9(-1))+sigma*(e+e9); -c^(-gamma)*(1+phi*zeta*(k10-k10(-1))^(zeta-1)/(2*k10(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k10-k10(-1))^(zeta-1)/(2*k10(-1))+phi*(k10-k10(-1))^zeta/(2*k10(-1)^2)-delta+alpha*a10(+1)*k10^(alpha-1)); -log(a10) = rho*log(a10(-1))+sigma*(e+e10); -c^(-gamma)*(1+phi*zeta*(k11-k11(-1))^(zeta-1)/(2*k11(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k11-k11(-1))^(zeta-1)/(2*k11(-1))+phi*(k11-k11(-1))^zeta/(2*k11(-1)^2)-delta+alpha*a11(+1)*k11^(alpha-1)); -log(a11) = rho*log(a11(-1))+sigma*(e+e11); -c^(-gamma)*(1+phi*zeta*(k12-k12(-1))^(zeta-1)/(2*k12(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k12-k12(-1))^(zeta-1)/(2*k12(-1))+phi*(k12-k12(-1))^zeta/(2*k12(-1)^2)-delta+alpha*a12(+1)*k12^(alpha-1)); -log(a12) = rho*log(a12(-1))+sigma*(e+e12); -c^(-gamma)*(1+phi*zeta*(k13-k13(-1))^(zeta-1)/(2*k13(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k13-k13(-1))^(zeta-1)/(2*k13(-1))+phi*(k13-k13(-1))^zeta/(2*k13(-1)^2)-delta+alpha*a13(+1)*k13^(alpha-1)); -log(a13) = rho*log(a13(-1))+sigma*(e+e13); -c^(-gamma)*(1+phi*zeta*(k14-k14(-1))^(zeta-1)/(2*k14(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k14-k14(-1))^(zeta-1)/(2*k14(-1))+phi*(k14-k14(-1))^zeta/(2*k14(-1)^2)-delta+alpha*a14(+1)*k14^(alpha-1)); -log(a14) = rho*log(a14(-1))+sigma*(e+e14); -c^(-gamma)*(1+phi*zeta*(k15-k15(-1))^(zeta-1)/(2*k15(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k15-k15(-1))^(zeta-1)/(2*k15(-1))+phi*(k15-k15(-1))^zeta/(2*k15(-1)^2)-delta+alpha*a15(+1)*k15^(alpha-1)); -log(a15) = rho*log(a15(-1))+sigma*(e+e15); -c^(-gamma)*(1+phi*zeta*(k16-k16(-1))^(zeta-1)/(2*k16(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k16-k16(-1))^(zeta-1)/(2*k16(-1))+phi*(k16-k16(-1))^zeta/(2*k16(-1)^2)-delta+alpha*a16(+1)*k16^(alpha-1)); -log(a16) = rho*log(a16(-1))+sigma*(e+e16); -c^(-gamma)*(1+phi*zeta*(k17-k17(-1))^(zeta-1)/(2*k17(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k17-k17(-1))^(zeta-1)/(2*k17(-1))+phi*(k17-k17(-1))^zeta/(2*k17(-1)^2)-delta+alpha*a17(+1)*k17^(alpha-1)); -log(a17) = rho*log(a17(-1))+sigma*(e+e17); -c^(-gamma)*(1+phi*zeta*(k18-k18(-1))^(zeta-1)/(2*k18(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k18-k18(-1))^(zeta-1)/(2*k18(-1))+phi*(k18-k18(-1))^zeta/(2*k18(-1)^2)-delta+alpha*a18(+1)*k18^(alpha-1)); -log(a18) = rho*log(a18(-1))+sigma*(e+e18); -c^(-gamma)*(1+phi*zeta*(k19-k19(-1))^(zeta-1)/(2*k19(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k19-k19(-1))^(zeta-1)/(2*k19(-1))+phi*(k19-k19(-1))^zeta/(2*k19(-1)^2)-delta+alpha*a19(+1)*k19^(alpha-1)); -log(a19) = rho*log(a19(-1))+sigma*(e+e19); -c^(-gamma)*(1+phi*zeta*(k20-k20(-1))^(zeta-1)/(2*k20(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k20-k20(-1))^(zeta-1)/(2*k20(-1))+phi*(k20-k20(-1))^zeta/(2*k20(-1)^2)-delta+alpha*a20(+1)*k20^(alpha-1)); -log(a20) = rho*log(a20(-1))+sigma*(e+e20); -c^(-gamma)*(1+phi*zeta*(k21-k21(-1))^(zeta-1)/(2*k21(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k21-k21(-1))^(zeta-1)/(2*k21(-1))+phi*(k21-k21(-1))^zeta/(2*k21(-1)^2)-delta+alpha*a21(+1)*k21^(alpha-1)); -log(a21) = rho*log(a21(-1))+sigma*(e+e21); -c^(-gamma)*(1+phi*zeta*(k22-k22(-1))^(zeta-1)/(2*k22(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k22-k22(-1))^(zeta-1)/(2*k22(-1))+phi*(k22-k22(-1))^zeta/(2*k22(-1)^2)-delta+alpha*a22(+1)*k22^(alpha-1)); -log(a22) = rho*log(a22(-1))+sigma*(e+e22); -c^(-gamma)*(1+phi*zeta*(k23-k23(-1))^(zeta-1)/(2*k23(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k23-k23(-1))^(zeta-1)/(2*k23(-1))+phi*(k23-k23(-1))^zeta/(2*k23(-1)^2)-delta+alpha*a23(+1)*k23^(alpha-1)); -log(a23) = rho*log(a23(-1))+sigma*(e+e23); -c^(-gamma)*(1+phi*zeta*(k24-k24(-1))^(zeta-1)/(2*k24(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k24-k24(-1))^(zeta-1)/(2*k24(-1))+phi*(k24-k24(-1))^zeta/(2*k24(-1)^2)-delta+alpha*a24(+1)*k24^(alpha-1)); -log(a24) = rho*log(a24(-1))+sigma*(e+e24); -c^(-gamma)*(1+phi*zeta*(k25-k25(-1))^(zeta-1)/(2*k25(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k25-k25(-1))^(zeta-1)/(2*k25(-1))+phi*(k25-k25(-1))^zeta/(2*k25(-1)^2)-delta+alpha*a25(+1)*k25^(alpha-1)); -log(a25) = rho*log(a25(-1))+sigma*(e+e25); -c^(-gamma)*(1+phi*zeta*(k26-k26(-1))^(zeta-1)/(2*k26(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k26-k26(-1))^(zeta-1)/(2*k26(-1))+phi*(k26-k26(-1))^zeta/(2*k26(-1)^2)-delta+alpha*a26(+1)*k26^(alpha-1)); -log(a26) = rho*log(a26(-1))+sigma*(e+e26); -c^(-gamma)*(1+phi*zeta*(k27-k27(-1))^(zeta-1)/(2*k27(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k27-k27(-1))^(zeta-1)/(2*k27(-1))+phi*(k27-k27(-1))^zeta/(2*k27(-1)^2)-delta+alpha*a27(+1)*k27^(alpha-1)); -log(a27) = rho*log(a27(-1))+sigma*(e+e27); -c^(-gamma)*(1+phi*zeta*(k28-k28(-1))^(zeta-1)/(2*k28(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k28-k28(-1))^(zeta-1)/(2*k28(-1))+phi*(k28-k28(-1))^zeta/(2*k28(-1)^2)-delta+alpha*a28(+1)*k28^(alpha-1)); -log(a28) = rho*log(a28(-1))+sigma*(e+e28); -c^(-gamma)*(1+phi*zeta*(k29-k29(-1))^(zeta-1)/(2*k29(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k29-k29(-1))^(zeta-1)/(2*k29(-1))+phi*(k29-k29(-1))^zeta/(2*k29(-1)^2)-delta+alpha*a29(+1)*k29^(alpha-1)); -log(a29) = rho*log(a29(-1))+sigma*(e+e29); -c^(-gamma)*(1+phi*zeta*(k30-k30(-1))^(zeta-1)/(2*k30(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k30-k30(-1))^(zeta-1)/(2*k30(-1))+phi*(k30-k30(-1))^zeta/(2*k30(-1)^2)-delta+alpha*a30(+1)*k30^(alpha-1)); -log(a30) = rho*log(a30(-1))+sigma*(e+e30); -c^(-gamma)*(1+phi*zeta*(k31-k31(-1))^(zeta-1)/(2*k31(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k31-k31(-1))^(zeta-1)/(2*k31(-1))+phi*(k31-k31(-1))^zeta/(2*k31(-1)^2)-delta+alpha*a31(+1)*k31^(alpha-1)); -log(a31) = rho*log(a31(-1))+sigma*(e+e31); -c^(-gamma)*(1+phi*zeta*(k32-k32(-1))^(zeta-1)/(2*k32(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k32-k32(-1))^(zeta-1)/(2*k32(-1))+phi*(k32-k32(-1))^zeta/(2*k32(-1)^2)-delta+alpha*a32(+1)*k32^(alpha-1)); -log(a32) = rho*log(a32(-1))+sigma*(e+e32); -c^(-gamma)*(1+phi*zeta*(k33-k33(-1))^(zeta-1)/(2*k33(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k33-k33(-1))^(zeta-1)/(2*k33(-1))+phi*(k33-k33(-1))^zeta/(2*k33(-1)^2)-delta+alpha*a33(+1)*k33^(alpha-1)); -log(a33) = rho*log(a33(-1))+sigma*(e+e33); -c^(-gamma)*(1+phi*zeta*(k34-k34(-1))^(zeta-1)/(2*k34(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k34-k34(-1))^(zeta-1)/(2*k34(-1))+phi*(k34-k34(-1))^zeta/(2*k34(-1)^2)-delta+alpha*a34(+1)*k34^(alpha-1)); -log(a34) = rho*log(a34(-1))+sigma*(e+e34); -c^(-gamma)*(1+phi*zeta*(k35-k35(-1))^(zeta-1)/(2*k35(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k35-k35(-1))^(zeta-1)/(2*k35(-1))+phi*(k35-k35(-1))^zeta/(2*k35(-1)^2)-delta+alpha*a35(+1)*k35^(alpha-1)); -log(a35) = rho*log(a35(-1))+sigma*(e+e35); -c^(-gamma)*(1+phi*zeta*(k36-k36(-1))^(zeta-1)/(2*k36(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k36-k36(-1))^(zeta-1)/(2*k36(-1))+phi*(k36-k36(-1))^zeta/(2*k36(-1)^2)-delta+alpha*a36(+1)*k36^(alpha-1)); -log(a36) = rho*log(a36(-1))+sigma*(e+e36); -c^(-gamma)*(1+phi*zeta*(k37-k37(-1))^(zeta-1)/(2*k37(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k37-k37(-1))^(zeta-1)/(2*k37(-1))+phi*(k37-k37(-1))^zeta/(2*k37(-1)^2)-delta+alpha*a37(+1)*k37^(alpha-1)); -log(a37) = rho*log(a37(-1))+sigma*(e+e37); -c^(-gamma)*(1+phi*zeta*(k38-k38(-1))^(zeta-1)/(2*k38(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k38-k38(-1))^(zeta-1)/(2*k38(-1))+phi*(k38-k38(-1))^zeta/(2*k38(-1)^2)-delta+alpha*a38(+1)*k38^(alpha-1)); -log(a38) = rho*log(a38(-1))+sigma*(e+e38); -c^(-gamma)*(1+phi*zeta*(k39-k39(-1))^(zeta-1)/(2*k39(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k39-k39(-1))^(zeta-1)/(2*k39(-1))+phi*(k39-k39(-1))^zeta/(2*k39(-1)^2)-delta+alpha*a39(+1)*k39^(alpha-1)); -log(a39) = rho*log(a39(-1))+sigma*(e+e39); -c^(-gamma)*(1+phi*zeta*(k40-k40(-1))^(zeta-1)/(2*k40(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k40-k40(-1))^(zeta-1)/(2*k40(-1))+phi*(k40-k40(-1))^zeta/(2*k40(-1)^2)-delta+alpha*a40(+1)*k40^(alpha-1)); -log(a40) = rho*log(a40(-1))+sigma*(e+e40); -c^(-gamma)*(1+phi*zeta*(k41-k41(-1))^(zeta-1)/(2*k41(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k41-k41(-1))^(zeta-1)/(2*k41(-1))+phi*(k41-k41(-1))^zeta/(2*k41(-1)^2)-delta+alpha*a41(+1)*k41^(alpha-1)); -log(a41) = rho*log(a41(-1))+sigma*(e+e41); -c^(-gamma)*(1+phi*zeta*(k42-k42(-1))^(zeta-1)/(2*k42(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k42-k42(-1))^(zeta-1)/(2*k42(-1))+phi*(k42-k42(-1))^zeta/(2*k42(-1)^2)-delta+alpha*a42(+1)*k42^(alpha-1)); -log(a42) = rho*log(a42(-1))+sigma*(e+e42); -c^(-gamma)*(1+phi*zeta*(k43-k43(-1))^(zeta-1)/(2*k43(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k43-k43(-1))^(zeta-1)/(2*k43(-1))+phi*(k43-k43(-1))^zeta/(2*k43(-1)^2)-delta+alpha*a43(+1)*k43^(alpha-1)); -log(a43) = rho*log(a43(-1))+sigma*(e+e43); -c^(-gamma)*(1+phi*zeta*(k44-k44(-1))^(zeta-1)/(2*k44(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k44-k44(-1))^(zeta-1)/(2*k44(-1))+phi*(k44-k44(-1))^zeta/(2*k44(-1)^2)-delta+alpha*a44(+1)*k44^(alpha-1)); -log(a44) = rho*log(a44(-1))+sigma*(e+e44); -c^(-gamma)*(1+phi*zeta*(k45-k45(-1))^(zeta-1)/(2*k45(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k45-k45(-1))^(zeta-1)/(2*k45(-1))+phi*(k45-k45(-1))^zeta/(2*k45(-1)^2)-delta+alpha*a45(+1)*k45^(alpha-1)); -log(a45) = rho*log(a45(-1))+sigma*(e+e45); -c^(-gamma)*(1+phi*zeta*(k46-k46(-1))^(zeta-1)/(2*k46(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k46-k46(-1))^(zeta-1)/(2*k46(-1))+phi*(k46-k46(-1))^zeta/(2*k46(-1)^2)-delta+alpha*a46(+1)*k46^(alpha-1)); -log(a46) = rho*log(a46(-1))+sigma*(e+e46); -c^(-gamma)*(1+phi*zeta*(k47-k47(-1))^(zeta-1)/(2*k47(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k47-k47(-1))^(zeta-1)/(2*k47(-1))+phi*(k47-k47(-1))^zeta/(2*k47(-1)^2)-delta+alpha*a47(+1)*k47^(alpha-1)); -log(a47) = rho*log(a47(-1))+sigma*(e+e47); -c^(-gamma)*(1+phi*zeta*(k48-k48(-1))^(zeta-1)/(2*k48(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k48-k48(-1))^(zeta-1)/(2*k48(-1))+phi*(k48-k48(-1))^zeta/(2*k48(-1)^2)-delta+alpha*a48(+1)*k48^(alpha-1)); -log(a48) = rho*log(a48(-1))+sigma*(e+e48); -c^(-gamma)*(1+phi*zeta*(k49-k49(-1))^(zeta-1)/(2*k49(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k49-k49(-1))^(zeta-1)/(2*k49(-1))+phi*(k49-k49(-1))^zeta/(2*k49(-1)^2)-delta+alpha*a49(+1)*k49^(alpha-1)); -log(a49) = rho*log(a49(-1))+sigma*(e+e49); -c^(-gamma)*(1+phi*zeta*(k50-k50(-1))^(zeta-1)/(2*k50(-1))) = beta*c(+1)^(-gamma)*(1+phi*zeta*(k50-k50(-1))^(zeta-1)/(2*k50(-1))+phi*(k50-k50(-1))^zeta/(2*k50(-1)^2)-delta+alpha*a50(+1)*k50^(alpha-1)); -log(a50) = rho*log(a50(-1))+sigma*(e+e50); -N*c+k1+phi*(k1-k1(-1))^zeta/(2*k1)-(1-delta)*k1(-1)+k2+phi*(k2-k2(-1))^zeta/(2*k2)-(1-delta)*k2(-1)+k3+phi*(k3-k3(-1))^zeta/(2*k3)-(1-delta)*k3(-1)+k4+phi*(k4-k4(-1))^zeta/(2*k4)-(1-delta)*k4(-1)+k5+phi*(k5-k5(-1))^zeta/(2*k5)-(1-delta)*k5(-1)+k6+phi*(k6-k6(-1))^zeta/(2*k6)-(1-delta)*k6(-1)+k7+phi*(k7-k7(-1))^zeta/(2*k7)-(1-delta)*k7(-1)+k8+phi*(k8-k8(-1))^zeta/(2*k8)-(1-delta)*k8(-1)+k9+phi*(k9-k9(-1))^zeta/(2*k9)-(1-delta)*k9(-1)+k10+phi*(k10-k10(-1))^zeta/(2*k10)-(1-delta)*k10(-1)+k11+phi*(k11-k11(-1))^zeta/(2*k11)-(1-delta)*k11(-1)+k12+phi*(k12-k12(-1))^zeta/(2*k12)-(1-delta)*k12(-1)+k13+phi*(k13-k13(-1))^zeta/(2*k13)-(1-delta)*k13(-1)+k14+phi*(k14-k14(-1))^zeta/(2*k14)-(1-delta)*k14(-1)+k15+phi*(k15-k15(-1))^zeta/(2*k15)-(1-delta)*k15(-1)+k16+phi*(k16-k16(-1))^zeta/(2*k16)-(1-delta)*k16(-1)+k17+phi*(k17-k17(-1))^zeta/(2*k17)-(1-delta)*k17(-1)+k18+phi*(k18-k18(-1))^zeta/(2*k18)-(1-delta)*k18(-1)+k19+phi*(k19-k19(-1))^zeta/(2*k19)-(1-delta)*k19(-1)+k20+phi*(k20-k20(-1))^zeta/(2*k20)-(1-delta)*k20(-1)+k21+phi*(k21-k21(-1))^zeta/(2*k21)-(1-delta)*k21(-1)+k22+phi*(k22-k22(-1))^zeta/(2*k22)-(1-delta)*k22(-1)+k23+phi*(k23-k23(-1))^zeta/(2*k23)-(1-delta)*k23(-1)+k24+phi*(k24-k24(-1))^zeta/(2*k24)-(1-delta)*k24(-1)+k25+phi*(k25-k25(-1))^zeta/(2*k25)-(1-delta)*k25(-1)+k26+phi*(k26-k26(-1))^zeta/(2*k26)-(1-delta)*k26(-1)+k27+phi*(k27-k27(-1))^zeta/(2*k27)-(1-delta)*k27(-1)+k28+phi*(k28-k28(-1))^zeta/(2*k28)-(1-delta)*k28(-1)+k29+phi*(k29-k29(-1))^zeta/(2*k29)-(1-delta)*k29(-1)+k30+phi*(k30-k30(-1))^zeta/(2*k30)-(1-delta)*k30(-1)+k31+phi*(k31-k31(-1))^zeta/(2*k31)-(1-delta)*k31(-1)+k32+phi*(k32-k32(-1))^zeta/(2*k32)-(1-delta)*k32(-1)+k33+phi*(k33-k33(-1))^zeta/(2*k33)-(1-delta)*k33(-1)+k34+phi*(k34-k34(-1))^zeta/(2*k34)-(1-delta)*k34(-1)+k35+phi*(k35-k35(-1))^zeta/(2*k35)-(1-delta)*k35(-1)+k36+phi*(k36-k36(-1))^zeta/(2*k36)-(1-delta)*k36(-1)+k37+phi*(k37-k37(-1))^zeta/(2*k37)-(1-delta)*k37(-1)+k38+phi*(k38-k38(-1))^zeta/(2*k38)-(1-delta)*k38(-1)+k39+phi*(k39-k39(-1))^zeta/(2*k39)-(1-delta)*k39(-1)+k40+phi*(k40-k40(-1))^zeta/(2*k40)-(1-delta)*k40(-1)+k41+phi*(k41-k41(-1))^zeta/(2*k41)-(1-delta)*k41(-1)+k42+phi*(k42-k42(-1))^zeta/(2*k42)-(1-delta)*k42(-1)+k43+phi*(k43-k43(-1))^zeta/(2*k43)-(1-delta)*k43(-1)+k44+phi*(k44-k44(-1))^zeta/(2*k44)-(1-delta)*k44(-1)+k45+phi*(k45-k45(-1))^zeta/(2*k45)-(1-delta)*k45(-1)+k46+phi*(k46-k46(-1))^zeta/(2*k46)-(1-delta)*k46(-1)+k47+phi*(k47-k47(-1))^zeta/(2*k47)-(1-delta)*k47(-1)+k48+phi*(k48-k48(-1))^zeta/(2*k48)-(1-delta)*k48(-1)+k49+phi*(k49-k49(-1))^zeta/(2*k49)-(1-delta)*k49(-1)+k50+phi*(k50-k50(-1))^zeta/(2*k50)-(1-delta)*k50(-1)= a1*k1(-1)^alpha+a2*k2(-1)^alpha+a3*k3(-1)^alpha+a4*k4(-1)^alpha+a5*k5(-1)^alpha+a6*k6(-1)^alpha+a7*k7(-1)^alpha+a8*k8(-1)^alpha+a9*k9(-1)^alpha+a10*k10(-1)^alpha+a11*k11(-1)^alpha+a12*k12(-1)^alpha+a13*k13(-1)^alpha+a14*k14(-1)^alpha+a15*k15(-1)^alpha+a16*k16(-1)^alpha+a17*k17(-1)^alpha+a18*k18(-1)^alpha+a19*k19(-1)^alpha+a20*k20(-1)^alpha+a21*k21(-1)^alpha+a22*k22(-1)^alpha+a23*k23(-1)^alpha+a24*k24(-1)^alpha+a25*k25(-1)^alpha+a26*k26(-1)^alpha+a27*k27(-1)^alpha+a28*k28(-1)^alpha+a29*k29(-1)^alpha+a30*k30(-1)^alpha+a31*k31(-1)^alpha+a32*k32(-1)^alpha+a33*k33(-1)^alpha+a34*k34(-1)^alpha+a35*k35(-1)^alpha+a36*k36(-1)^alpha+a37*k37(-1)^alpha+a38*k38(-1)^alpha+a39*k39(-1)^alpha+a40*k40(-1)^alpha+a41*k41(-1)^alpha+a42*k42(-1)^alpha+a43*k43(-1)^alpha+a44*k44(-1)^alpha+a45*k45(-1)^alpha+a46*k46(-1)^alpha+a47*k47(-1)^alpha+a48*k48(-1)^alpha+a49*k49(-1)^alpha+a50*k50(-1)^alpha; -end; -initval; -c=1; -e=0; -a1=1; -e1=0; -k1=10; -a2=1; -e2=0; -k2=10; -a3=1; -e3=0; -k3=10; -a4=1; -e4=0; -k4=10; -a5=1; -e5=0; -k5=10; -a6=1; -e6=0; -k6=10; -a7=1; -e7=0; -k7=10; -a8=1; -e8=0; -k8=10; -a9=1; -e9=0; -k9=10; -a10=1; -e10=0; -k10=10; -a11=1; -e11=0; -k11=10; -a12=1; -e12=0; -k12=10; -a13=1; -e13=0; -k13=10; -a14=1; -e14=0; -k14=10; -a15=1; -e15=0; -k15=10; -a16=1; -e16=0; -k16=10; -a17=1; -e17=0; -k17=10; -a18=1; -e18=0; -k18=10; -a19=1; -e19=0; -k19=10; -a20=1; -e20=0; -k20=10; -a21=1; -e21=0; -k21=10; -a22=1; -e22=0; -k22=10; -a23=1; -e23=0; -k23=10; -a24=1; -e24=0; -k24=10; -a25=1; -e25=0; -k25=10; -a26=1; -e26=0; -k26=10; -a27=1; -e27=0; -k27=10; -a28=1; -e28=0; -k28=10; -a29=1; -e29=0; -k29=10; -a30=1; -e30=0; -k30=10; -a31=1; -e31=0; -k31=10; -a32=1; -e32=0; -k32=10; -a33=1; -e33=0; -k33=10; -a34=1; -e34=0; -k34=10; -a35=1; -e35=0; -k35=10; -a36=1; -e36=0; -k36=10; -a37=1; -e37=0; -k37=10; -a38=1; -e38=0; -k38=10; -a39=1; -e39=0; -k39=10; -a40=1; -e40=0; -k40=10; -a41=1; -e41=0; -k41=10; -a42=1; -e42=0; -k42=10; -a43=1; -e43=0; -k43=10; -a44=1; -e44=0; -k44=10; -a45=1; -e45=0; -k45=10; -a46=1; -e46=0; -k46=10; -a47=1; -e47=0; -k47=10; -a48=1; -e48=0; -k48=10; -a49=1; -e49=0; -k49=10; -a50=1; -e50=0; -k50=10; -end; - -vcov = [ -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0; -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]; - -order = 2; diff --git a/dynare++/tests/sedmodel1.mod b/dynare++/tests/sedmodel1.mod deleted file mode 100644 index a8ad536980ec01c971da60d570cc4d31c964ddf8..0000000000000000000000000000000000000000 --- a/dynare++/tests/sedmodel1.mod +++ /dev/null @@ -1,77 +0,0 @@ -var A, Disp, G, Int, L, - LStar, pi, Welf, WelfStar, x0, - Y, YGap, YStar, z1, z2, Cbar, Cequiv; -varexo eps1 eps2 eps3; - -parameters alpha beta gamma rhoa rhog rho phi chi chi0 theta xi -ABar GBar KBar ZBar piBar Istar; -alpha = 0.3; - beta = 0.99; - gamma = 15; - rhoa = 0.8; - rhog = 0.7; - phi = 1.5; - chi = 1.5; - chi0 = 1; - theta = 0.333333333333; - xi = 0.75; - ABar = 4.0266; - GBar = 0.3163; - KBar = 9.489; - ZBar = .03; - piBar = 1; - rho=.8; - Istar=1.01010101010101; - - -model; -z1 - ((Y-G)^(1-phi) + beta *xi *piBar *pi(+1)^(1/theta) *z1(+1)); -z2 - (Y *chi0 *(1-L-ZBar)^(-chi) / ((1-alpha) *A *KBar^alpha - *L^(-alpha)) + beta *xi *pi(+1)^((1+theta)/theta) *z2(+1)); -x0 - (1+theta)*z2 /z1; -pi^(-1/theta) - ((1-xi) *(x0*pi)^(-1/theta) + xi *piBar^(-1/theta)); -Y - (Disp^(-1) *A *KBar^alpha *L^(1-alpha)); -Disp - ((1-xi) *x0^(-(1+theta)/theta) - + xi *(piBar/pi)^(-(1+theta)/theta) *Disp(-1)); -log(A/ABar) - (rhoa *log(A(-1)/ABar) + eps1); -log(G/GBar) - (rhog *log(G(-1)/GBar) + eps2); -(Y-G)^(-phi) - (beta *(Int/pi(+1)) *(Y(+1)-G(+1))^(-phi)); -Welf - ((Y-G)^(1-phi) /(1-phi) - + chi0*(1-L-ZBar)^(1-chi) /(1-chi) + beta *Welf(+1)); -Cequiv = (((1-beta)*Welf-chi0*(1-LStar-ZBar)^(1-chi) /(1-chi))*(1-phi))^(1/(1-phi)); -(1-alpha) *A *KBar^alpha *LStar^(-alpha) - - (1+theta) *YStar *(YStar-G)^(phi-1) *chi0 - *(1-LStar-ZBar)^(-chi); -YStar - A *KBar^alpha *LStar^(1-alpha); -YGap - (log(Y/YStar)); -WelfStar - ((YStar-G)^(1-phi) /(1-phi) - + chi0*(1-LStar-ZBar)^(1-chi) /(1-chi) + beta *WelfStar(+1)); -Int = (Int(-1)^rho)*((Istar*(pi/piBar)^gamma)^(1-rho))*exp(eps3); -Cbar=(1/100)*((1-phi)*((1-beta)*WelfStar-chi0*(1-LStar-ZBar)^(1-chi)/(1-chi)))^(1/(1-phi)); -end; - -initval; -A= 4.022; -Disp= 1; -G= 0.3; -Int= 1.0101; -L= 0.22; -LStar= 0.22; -pi= 1; -Welf= -359; -WelfStar= -359; -x0= 1; -Y= 2.8; -YGap= 0; -YStar= 2.8; -z1= 2.5; -z2= 1.8; -Cbar= 0.024; -Cequiv = 0.024; -end; - -vcov = [0.001 0 0 ; 0 0.001 0; 0 0 0.001]; - -order=4; - - diff --git a/dynare++/tests/sw_euro.mod b/dynare++/tests/sw_euro.mod deleted file mode 100644 index fc6da21fb7221781489394a8607b86f65370c782..0000000000000000000000000000000000000000 --- a/dynare++/tests/sw_euro.mod +++ /dev/null @@ -1,98 +0,0 @@ -var MC EH EF R_KF QF CF IF YF LF PIEF WF RF R_KH QH CH IH YH LH PIEH WH RH EE_A PIE_BAR EE_B EE_G EE_L EE_I KF KH ONE; - -varexo E_A E_B E_G E_L E_I ETA_R E_PIE_BAR ETA_Q ETA_P ETA_W ; - -parameters xi_e lambda_w alpha czcap beta phi_i tau sig_c hab ccs cinvs phi_y gamma_w xi_w gamma_p xi_p sig_l r_dpi r_pie r_dy r_y rho rho_a rho_pb rho_b rho_g rho_l rho_i ; -alpha=.30; -beta=0.99; -tau=0.025; -ccs=0.6; -cinvs=.22; -lambda_w = 0.5; -phi_i= 6.771; -sig_c= 1.353; -hab= 0.573; -xi_w= 0.737; -sig_l= 2.400; -xi_p= 0.908; -xi_e= 0.599; -gamma_w= 0.763; -gamma_p= 0.469; -czcap= 0.169; -phi_y= 1.408; -r_pie= 1.684; -r_dpi= 0.14; -rho= 0.961; -r_y= 0.099; -r_dy= 0.159; -rho_a= 0.823; -rho_b= 0.855; -rho_g= 0.949; -rho_l= 0.889; -rho_i= 0.927; -rho_pb= 0.924; - - -model; - CF = (1/(1+hab))*(CF(1)+hab*CF(-1))-((1-hab)/((1+hab)*sig_c))*(RF-PIEF(1)-EE_B) ; - 0 = alpha*R_KF+(1-alpha)*WF -EE_A ; - PIEF = 0*ONE; - IF = (1/(1+beta))* (( IF(-1) + beta*(IF(1)))+(1/phi_i)*QF)+0*ETA_Q+EE_I ; - QF = -(RF-PIEF(1))+(1-beta*(1-tau))*((1+czcap)/czcap)*R_KF(1)+beta*(1-tau)*QF(1) +0*EE_I ; - KF = (1-tau)*KF(-1)+tau*IF(-1) ; - YF = (ccs*CF+cinvs*IF)+EE_G ; - YF = 1*phi_y*( alpha*KF+alpha*(1/czcap)*R_KF+(1-alpha)*LF+EE_A ) ; - WF = (sig_c/(1-hab))*(CF-hab*CF(-1)) + sig_l*LF - EE_L ; - LF = R_KF*((1+czcap)/czcap)-WF+KF ; - EF = EF(-1)+EF(1)-EF+(LF-EF)*((1-xi_e)*(1-xi_e*beta)/(xi_e)); - - CH = (hab/(1+hab))*CH(-1)+(1/(1+hab))*CH(1)-((1-hab)/((1+hab)*sig_c))*(RH-PIEH(1)-EE_B) ; - IH = (1/(1+beta))* (( IH(-1) + beta*(IH(1)))+(1/phi_i)*QH )+1*ETA_Q+1*EE_I ; - QH = -(RH-PIEH(1))+(1-beta*(1-tau))*((1+czcap)/czcap)*R_KH(1)+beta*(1-tau)*QH(1) +EE_I*0+0*ETA_Q ; - KH = (1-tau)*KH(-1)+tau*IH(-1) ; - YH = (ccs*CH+cinvs*IH)+ EE_G ; - YH = phi_y*( alpha*KH+alpha*(1/czcap)*R_KH+(1-alpha)*LH ) +phi_y*EE_A ; - PIEH = (1/(1+beta*gamma_p))* - ( - (beta)*(PIEH(1)) +(gamma_p)*(PIEH(-1)) - +((1-xi_p)*(1-beta*xi_p)/(xi_p))*(MC) - ) + ETA_P ; - - MC = alpha*R_KH+(1-alpha)*WH -EE_A; - WH = (1/(1+beta))*(beta*WH(+1)+WH(-1)) - +(beta/(1+beta))*(PIEH(+1)) - -((1+beta*gamma_w)/(1+beta))*(PIEH) - +(gamma_w/(1+beta))*(PIEH(-1)) - -(1/(1+beta))*(((1-beta*xi_w)*(1-xi_w))/(((1+(((1+lambda_w)*sig_l)/(lambda_w))))*xi_w))*(WH-sig_l*LH-(sig_c/(1-hab))*(CH-hab*CH(-1))+EE_L) - +ETA_W; - LH = R_KH*((1+czcap)/czcap)-WH+KH ; - RH = r_dpi*(PIEH-PIEH(-1)) - +(1-rho)*(r_pie*(PIEH(-1)-PIE_BAR)+r_y*(YH-YF)) - +r_dy*(YH-YF-(YH(-1)-YF(-1))) - +rho*(RH(-1)-PIE_BAR) - +PIE_BAR - +ETA_R; - EH = EH(-1)+EH(1)-EH+(LH-EH)*((1-xi_e)*(1-xi_e*beta)/(xi_e)); - - - EE_A = (rho_a)*EE_A(-1) + E_A; - PIE_BAR = rho_pb*PIE_BAR(-1)+ E_PIE_BAR ; - EE_B = rho_b*EE_B(-1) + E_B ; - EE_G = rho_g*EE_G(-1) + E_G ; - EE_L = rho_l*EE_L(-1) + E_L ; - EE_I = rho_i*EE_I(-1) + E_I ; - ONE = 0*ONE(-1) ; -end; - -vcov = [0.357604 0 0 0 0 0 0 0 0 0; - 0 0.112896 0 0 0 0 0 0 0 0; - 0 0 0.105625 0 0 0 0 0 0 0; - 0 0 0 12.39040 0 0 0 0 0 0; - 0 0 0 0 0.722500 0 0 0 0 0; - 0 0 0 0 0 0.656100 0 0 0 0; - 0 0 0 0 0 0 0.000289 0 0 0; - 0 0 0 0 0 0 0 0.364816 0 0; - 0 0 0 0 0 0 0 0 0.025600 0; - 0 0 0 0 0 0 0 0 0 0.083521]; - -order = 1; diff --git a/dynare++/tests/swma_pie.mod b/dynare++/tests/swma_pie.mod deleted file mode 100644 index bf6183ba6dcb57c623a82749e9074a7676e39060..0000000000000000000000000000000000000000 --- a/dynare++/tests/swma_pie.mod +++ /dev/null @@ -1,187 +0,0 @@ -// this model has sticky wages and adjustment costs in -// investment, consumer goods sector is perfectly competitive, thus MC=1 -// with money and transaction costs based on money velocity -// and it has a financial accelerator -// wage is indexed to past consumer price inflation - -// LAMBDA Lagrange multiplier on household's budget constraint (divided by price level) -// PIE inflation of CPI -// PIETILDE to what inflation new wage setters index (here PIE(-1) but could be PIEW(-1)) -// INT nominal interest rate -// C real consumption -// I real investment -// K real capital -// R real rental rate of capital -// W real wage -// L labour -// Y real output -// PIEW nominal wage inflation -// VW wage front loading term for newly set wages -// BBD, BBE, BBF, BBG terms in nominator and denominator in wage FOC -// G government -// SL process for labor shock -// SC process for consumption shock -// SY process for technology shock -// RM real money balances hold -// Q real price of capital -// Q_M1 lagged Q -// RK nominal return of capital for enterpreneurs -// OMEGABAR threshold value for idiosyncratic shock -// N real net worth of borrowers -// WF lifetime utility - -var LAMBDA PIE PIETILDE INT C I K R W L Y PIEW VW BBD BBE BBF BBG G SL SC SY RM - Q Q_M1 RK OMEGABAR N ACAL ACALPRIME BCAL BCALPRIME WF; - -varexo E_C E_L E_Y E_GOV E_INT; - -parameters dep beta gamma eta biga alpha sigmaw phiw deltaw sg pietar h psi nu osigma mu tc1 tc2 ksi1 ksi2 c_weight rho_g rho_l rho_c rho_y; -dep = 0.025; -beta = 0.99; -gamma = 1; -eta = 2; -alpha = 0.30; -biga = alpha^(-alpha)*(1-alpha)^(alpha-1); -sigmaw = 11; -phiw = 2; -deltaw = 0.75; -sg = 0.18; -pietar = 1.03^0.25; -h = 0.8; -// investment adjustment costs -psi = 12; -// enterpreneur saving rate -nu = 0.94; -// stderr of enterpreneur's idiosyncratic shocks -osigma = 0.5; -// monitoring cost for lender -mu = 0.2; -// consumption transaction costs -tc1 = 0.05; -tc2 = 0.5; -// Taylor rule -ksi1 = 0.106; -ksi2 = 3; -rho_g = 0.90; -rho_l = 0.90; -rho_c = 0.90; -rho_y = 0.90; -// weight of consumption utility -c_weight = 1; - -model; -// capital accumulation -K = (1 - dep - psi/2*(I(-1)/K(-1)-dep)^2)*K(-1) + I(-1); -// FOC bonds -LAMBDA = beta*INT*LAMBDA(+1)/PIE(+1); -// FOC consumption (right hand side is equal to LAMBDA*(1+TC+TCPRIME*C/RM)) -SC*c_weight*(C-h*C(-1))^(-eta) = LAMBDA*(1+2*tc1*C/RM-2*sqrt(tc1*tc2)); -// FOC money (right hand side is equal to 1 - TCPRIME*C*C/RM/RM) -beta*LAMBDA(+1)/LAMBDA/PIE(+1) = 1 - tc1*C*C/RM/RM + tc2; -// FOC investment removed -// FOC capital(+1) removed -// real price of capital -Q = (1-psi*(I/K-dep))^(-1); -// nominal return on capital -RK = PIE*(R + Q*(1 - dep + psi*(I/K-dep)*I/K -psi/2*(I/K-dep)^2))/Q(-1); -// FOC in optimal contract for K(+1) -RK(+1)*(BCAL(+1)*ACALPRIME(+1)/BCALPRIME(+1)-ACAL(+1)) = INT(+1)*ACALPRIME(+1)/BCALPRIME(+1); -// Participation constraint -//RK(+1)*BCAL(+1) = INT(+1)*(1-N(+1)*PIE(+1)/Q/K(+1)); -RK*BCAL = INT*(1-N*PIE/Q(-1)/K); -// evolution of net worth (real) -N*PIE*PIE(-1) = nu*(ACAL(-1)+BCAL(-1))*RK(-1)*Q_M1(-1)*K(-1) - nu*INT(-1)*(Q_M1(-1)*K(-1)-N(-1)*PIE); -// marginal cost is 1 -1 = biga*(W/SY)^(1-alpha)*R^alpha; -// labor attaining minimal MC -L = (1-alpha)/W*Y; -// capital attaining minimal MC -K = alpha/R*Y; -// FOC for newly set wages -W*VW = sigmaw/(sigmaw-1)*(BBD*VW^(-sigmaw*gamma) + phiw*BBE*VW^(-sigmaw) - phiw*BBF)/BBG; -// definition of BBD -BBD = SL*L^(1+gamma) + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-sigmaw*(1+gamma))*BBD(+1); -// definition of BBE -BBE = LAMBDA*L*W + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-2*sigmaw)*BBE(+1); -// definition of BBF -BBF = LAMBDA*L*W + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-sigmaw)*BBF(+1); -// definition of BBG -BBG = LAMBDA*L + deltaw*beta*(PIETILDE(+1)/PIEW(+1))^(-sigmaw)*PIETILDE(+1)/PIE(+1)*BBG(+1); -// price index -1 = (1-deltaw)*VW^(1-sigmaw) + deltaw*(PIETILDE/PIEW)^(1-sigmaw); -// definition of ACAL -ACAL = 0.5*erfc((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0)) - OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -// definition of BCAL -BCAL = OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)) + (1-mu)/2*(1+erf((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0))); -// definition of ACALPRIME -ACALPRIME = -0.5*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -// definition of BCALPRIME -BCALPRIME = -ACALPRIME - mu/osigma/2.506628274631*exp(-((log(OMEGABAR) + 0.5*osigma)^2)/2/osigma/osigma); -// identity for PIEW -PIEW = PIE*W/W(-1); -// welfare identity -WF = SC*c_weight*(C-h*C(-1))^(1-eta)/(1-eta) - SL*L^(1+gamma)/(1+gamma) + beta*WF(+1); -// interest rate rule -INT = INT(-1)^ksi1*((PIE/beta)*(PIE/pietar)^ksi2)^(1-ksi1)*exp(E_INT); -// aggregate constraint -Y = C + I + G + (1-ACAL-BCAL)*RK*Q(-1)*K; -//Y = C + I + G; -// process for government -G/Y = (G(-1)/Y(-1))^rho_g*sg^(1-rho_g)*exp(E_GOV/sg); -// to what do they index (pietar, past inflation, past indexed inflation) -PIETILDE = PIE(-1); -//PIETILDE = pietar; -// exo processes -SL = SL(-1)^rho_l*exp(E_L); -SC = SC(-1)^rho_c*exp(E_C); -SY = SY(-1)^rho_y*exp(E_Y); -// lagged Q -Q_M1 = Q(-1); -end; - -initval; -RM = 0.1; -INT = pietar/beta; -PIE = pietar; -PIEW = pietar; -PIETILDE = pietar; -//R = dep/beta; -R = 0.1; -W = (1/biga/(R)^alpha)^(1/(1-alpha)); -LAMBDA = ((1-dep*alpha/R-sg)*(1-h)*c_weight/(1-alpha)*W^(1/gamma+1)*((sigmaw-1)/sigmaw)^(1/gamma))^(-1/(1/eta+1/gamma)); -L = (W*LAMBDA*(sigmaw-1)/sigmaw)^(1/gamma); -Y = W*L/(1-alpha); -K = alpha/R*Y; -I = dep*K; -G = sg*Y; -VW = 1; -BBD = L^(1+gamma)/(1-deltaw*beta); -BBE = LAMBDA*L*W/(1-deltaw*beta); -BBF = LAMBDA*L*W/(1-deltaw*beta); -BBG = LAMBDA*L/(1-deltaw*beta); -Q = 1; -Q_M1 = Q; -RK = 1/Q*PIE*(R+(1-dep)*Q); -OMEGABAR = 0.5; -ACAL = 0.5*erfc((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0)) - OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -BCAL = OMEGABAR/2*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)) + (1-mu)/2*(1+erf((log(OMEGABAR) - 0.5*osigma^2)/osigma/sqrt(2.0))); -ACALPRIME = -0.5*erfc((log(OMEGABAR) + 0.5*osigma^2)/osigma/sqrt(2.0)); -BCALPRIME = -ACALPRIME - mu/osigma/2.506628274631*exp(-((log(OMEGABAR) + 0.5*osigma)^2)/2/osigma/osigma); -N = (nu*(ACAL+BCAL)*RK*Q*K-nu*INT*Q*K)/(PIE*PIE-nu*INT*PIE); -C = Y - I - G - (1-ACAL-BCAL)*RK*Q*K; -SL = 1; -SC = 1; -SY = 1; -WF = 1/(1-beta)*(SC*c_weight*((1-h)*C)^(1-eta)/(1-eta) - SL*L^(1+gamma)/(1+gamma)); -end; - -vcov = [ -0.0001 0 0 0 0; -0 0.0001 0 0 0; -0 0 0.0001 0 0; -0 0 0 0.0001 0; -0 0 0 0 0.0001 -]; - -order = 4; - diff --git a/dynare++/tests/test.mod b/dynare++/tests/test.mod deleted file mode 100644 index 98b7158a7071436211d4fbdfb22034be78559db9..0000000000000000000000000000000000000000 --- a/dynare++/tests/test.mod +++ /dev/null @@ -1,39 +0,0 @@ -var a, b, c, h, k, y; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) + e; -b = tau*a(-1)+rho*b(-1) + u; -end; - -initval; -y = 1; -c = 0.7; -h = 0.1; -k = 11; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.000081 0.000008;0.000008 0.000081]; - -order = 2; - diff --git a/dynare++/tests/test1.mod b/dynare++/tests/test1.mod deleted file mode 100644 index 04e7f6196ebccf4fbf3dfab1c22f595803ab073b..0000000000000000000000000000000000000000 --- a/dynare++/tests/test1.mod +++ /dev/null @@ -1,42 +0,0 @@ -var y, c, k, a, h, b; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) + e; -b = tau*a(-1)+rho*b(-1) + u; -end; - -initval; -y = 1; -c = 0.7; -h = 0.1; -k = 11; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.000081 0.0000081; 0.0000081 0.000081]; - -order = 1; - - - - diff --git a/dynare++/tests/test2.mod b/dynare++/tests/test2.mod deleted file mode 100644 index 0abc1dfa559b6c28d29feb90a09d220fb26f5f17..0000000000000000000000000000000000000000 --- a/dynare++/tests/test2.mod +++ /dev/null @@ -1,39 +0,0 @@ -var y, c, k, a, h, b; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) - rho*a(-2) - tau*b(-3) + e; -b = tau*a(-1)+rho*b(-1) - rho*b(-2) - tau*a(-3) + u; -end; - -initval; -y = 1.08; -c = 0.8; -h = 0.29; -k = 11.08; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.01 0.005; 0.005 0.01]; - -order = 1; - diff --git a/dynare++/tests/test2a.mod b/dynare++/tests/test2a.mod deleted file mode 100644 index f0b0441816bf1fbe7b755dc8c3da2194a6a8cd05..0000000000000000000000000000000000000000 --- a/dynare++/tests/test2a.mod +++ /dev/null @@ -1,39 +0,0 @@ -var y, c, k, a, h, b; -varexo e,u; - -parameters beta, rho, alpha, delta, theta, psi, tau, phi; - -alpha = 0.36; -rho = 0.95; -tau = 0.025; -beta = 0.99; -delta = 0.025; -psi = 0; -theta = 2.95; - -phi = 0.1; - -model; -c*theta*h^(1+psi)=(1-alpha)*y; -k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); -k = exp(b)*(y-c)+(1-delta)*k(-1); -a = rho*a(-1)+tau*b(-1) - rho*a(-2) - tau*b(-3) + e; -b = tau*a(-1)+rho*b(-1) - rho*b(-2) - tau*a(-3) + u; -end; - -initval; -y = 1.08; -c = 0.8; -h = 0.29; -k = 11.08; -a = 0; -b = 0; -e = 0; -u = 0; -end; - -vcov = [ 0.01 0.005; 0.005 0.01]; - -order = 2; - diff --git a/dynare++/tests/test3.mod b/dynare++/tests/test3.mod deleted file mode 100644 index 7f386f2a87fa9aa6a64f931760ac90bb916ca1fe..0000000000000000000000000000000000000000 --- a/dynare++/tests/test3.mod +++ /dev/null @@ -1,30 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, f, g, h, j; - -a=0.8; -b=0.9; -c=0.9; -d=1; -e=-0.556875; -f=-0.172125; -g=-0.9; -h=-0.2754; -j=-1.8; - - -model; -x=a*x(-1)+u; -c*y(+1)^2+d*y^2+e*x^2+f*u^2-d*v^2+g+h*x(-1)*u+j*x(-1)*v=0; -end; - -initval; -x=0; -y=0.7237469; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 2; \ No newline at end of file diff --git a/dynare++/tests/test4.mod b/dynare++/tests/test4.mod deleted file mode 100644 index 4250ac3a04f38f525c72f7563c1aefcffd0c76b6..0000000000000000000000000000000000000000 --- a/dynare++/tests/test4.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, f, m; - -a=0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -f = 1; - -model; -x = a*x(-1)+u; -c*y(+1)^2+d*y^2+e*x^2-(c+d)*m^2-(c*b*b*a*a+d*b*b+e*a*a)*x(-1)^2-(c*b*b+e)*u^2-2*(c*m*b*a+d*m*b)*x(-1)-2*c*m*b*u-2*(c*b*b*a+e*a)*x(-1)*u-d*f^2*v^2-2*d*m*f*v-2*d*b*f*x(-1)*v=0; -end; - -initval; -x=1; -y=21; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 2; diff --git a/dynare++/tests/test5.mod b/dynare++/tests/test5.mod deleted file mode 100644 index 4e2e5938a31f9307ada72a28af6e61900d116e23..0000000000000000000000000000000000000000 --- a/dynare++/tests/test5.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, m, n; - -a=-0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -n=0.2; - -model; -x=b*x(-1)+u; -a*y(+1)+y-(a*b^2+1)*x(-1)^2-2*a*b*x(-1)*u-a*u^2-a-2*x(-1)*v-v^2; -end; - -initval; -x=0; -y=0; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 3; diff --git a/dynare++/tests/test6.mod b/dynare++/tests/test6.mod deleted file mode 100644 index 53f4e826c21b7f4c09e05ad5a41f1cf64494ee80..0000000000000000000000000000000000000000 --- a/dynare++/tests/test6.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, m, n; - -a=-0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -n=0.2; - -model; -x=b*x(-1)+u; -a*y(+1)+y-(a*b^3+1)*x(-1)^3-3*a*b*x(-1)*u^2-3*a*b^2*x(-1)^2*u-a*u^3-a-v^2; -end; - -initval; -x=0; -y=0; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 3; diff --git a/dynare++/tests/test7.mod b/dynare++/tests/test7.mod deleted file mode 100644 index f520b9453622794c5e2971f2be137e2c074cdd3c..0000000000000000000000000000000000000000 --- a/dynare++/tests/test7.mod +++ /dev/null @@ -1,27 +0,0 @@ -var y,x; -varexo u,v; -parameters a, b, c, d, e, m, n; - -a=-0.8; -b=0.9; -c=0.9; -d=1; -e=1; -m=50; -n=0.2; - -model; -x=b*x(-1)+u; -a*y(+1)+y-(a*b^4+1)*x(-1)^4-4*a*b*x(-1)*u^3-4*a*b^3*x(-1)^3*u-6*a*(b*x(-1)*u)^2-a*u^4-v; -end; - -initval; -x=0; -y=0; -u=0; -v=0; -end; - -vcov=[1 0; 0 1]; - -order = 4; diff --git a/dynare++/tl/Makefile.am b/dynare++/tl/Makefile.am deleted file mode 100644 index ffebab6fe3641d3346316761575936e56f4be6f5..0000000000000000000000000000000000000000 --- a/dynare++/tl/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = cc testing diff --git a/dynare++/tl/cc/Makefile.am b/dynare++/tl/cc/Makefile.am deleted file mode 100644 index 026cb13f1df9b6dd5faa7c5478e241798405ef8a..0000000000000000000000000000000000000000 --- a/dynare++/tl/cc/Makefile.am +++ /dev/null @@ -1,45 +0,0 @@ -noinst_LIBRARIES = libtl.a - -libtl_a_SOURCES = \ - equivalence.cc \ - equivalence.hh \ - fine_container.cc \ - fine_container.hh \ - fs_tensor.cc \ - fs_tensor.hh \ - gs_tensor.cc \ - gs_tensor.hh \ - int_sequence.cc \ - int_sequence.hh \ - kron_prod.cc \ - kron_prod.hh \ - normal_moments.cc \ - normal_moments.hh \ - permutation.cc \ - permutation.hh \ - ps_tensor.cc \ - ps_tensor.hh \ - pyramid_prod.cc \ - pyramid_prod.hh \ - pyramid_prod2.cc \ - pyramid_prod2.hh \ - rfs_tensor.cc \ - rfs_tensor.hh \ - sparse_tensor.cc \ - sparse_tensor.hh \ - stack_container.cc \ - stack_container.hh \ - symmetry.cc \ - symmetry.hh \ - t_container.cc \ - t_container.hh \ - t_polynomial.cc \ - t_polynomial.hh \ - tensor.cc \ - tensor.hh \ - tl_exception.hh \ - tl_static.cc \ - tl_static.hh \ - twod_matrix.cc \ - twod_matrix.hh -libtl_a_CPPFLAGS = -I../../sylv/cc -I../../utils/cc $(CPPFLAGS_MATIO) diff --git a/dynare++/utils/cc/Makefile.am b/dynare++/utils/cc/Makefile.am deleted file mode 100644 index 93410c9b707c2ff1067fb9ad0ef26133b04c27d8..0000000000000000000000000000000000000000 --- a/dynare++/utils/cc/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -noinst_LIBRARIES = libutils.a - -libutils_a_SOURCES = \ - exception.hh \ - pascal_triangle.cc \ - pascal_triangle.hh \ - int_power.hh \ - int_power.cc \ - sthread.hh \ - sthread.cc diff --git a/license.txt b/license.txt index 1996d6c0a8b52e54fe37b50f6bbffbb0064e528e..34140b637c0a5c1a142687b74115f966f754ab8b 100644 --- a/license.txt +++ b/license.txt @@ -278,9 +278,8 @@ Copyright: 2007-2017 Sébastien Villemot 2016-2017 Johannes Pfeifer License: GFDL-NIV-1.3+ -Files: dynare++/* +Files: doc/sylvester.tex doc/tl.tex Copyright: 2004-2011 Ondra Kamenik - 2019-2023 Dynare Team License: GPL-3+ Files: m4/ax_compare_version.m4 @@ -303,8 +302,11 @@ Copyright: 2010 Yannick Kalantzis License: GPL-3+ Files: mex/sources/gensylv/gensylv.cc -Copyright: 2005-2011 Ondra Kamenik - 2019-2020 Dynare Team + mex/sources/libkorder/kord/* mex/sources/libkorder/integ/* + mex/sources/libkorder/sylv/* mex/sources/libkorder/tl/* + mex/sources/libkorder/utils/* +Copyright: 2004-2011 Ondra Kamenik + 2019-2023 Dynare Team License: GPL-3+ Files: mex/sources/sobol/sobol.f08 diff --git a/mex/build/gensylv.am b/mex/build/gensylv.am index b664759aa953422e0a58a06bbd2b0310e9506b12..9ac05d7d1978f1909e80e4dc46a473a43592fcc0 100644 --- a/mex/build/gensylv.am +++ b/mex/build/gensylv.am @@ -1,8 +1,10 @@ mex_PROGRAMS = gensylv -gensylv_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/utils/cc +LIBKORDER_DIR = $(top_srcdir)/../../sources/libkorder -gensylv_LDADD = ../libdynare++/libdynare++.a +gensylv_CPPFLAGS = $(AM_CPPFLAGS) -I$(LIBKORDER_DIR)/sylv -I$(LIBKORDER_DIR)/utils + +gensylv_LDADD = ../libkorder/libkorder.a nodist_gensylv_SOURCES = gensylv.cc diff --git a/mex/build/k_order_perturbation.am b/mex/build/k_order_perturbation.am index 5da9f5c79148118b4f0f610997aa74040a0de0fc..7102bc77e0e4add348366b9fa570a4b1c318c8c1 100644 --- a/mex/build/k_order_perturbation.am +++ b/mex/build/k_order_perturbation.am @@ -1,11 +1,12 @@ mex_PROGRAMS = k_order_perturbation TOPDIR = $(top_srcdir)/../../sources/k_order_perturbation +LIBKORDER_DIR = $(top_srcdir)/../../sources/libkorder -k_order_perturbation_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/../../../dynare++/src -I$(top_srcdir)/../../../dynare++/kord -I$(top_srcdir)/../../../dynare++/tl/cc -I$(top_srcdir)/../../../dynare++/utils/cc -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/integ/cc -I$(TOPDIR) $(CPPFLAGS_MATIO) +k_order_perturbation_CPPFLAGS = $(AM_CPPFLAGS) -I$(LIBKORDER_DIR) -I$(LIBKORDER_DIR)/kord -I$(LIBKORDER_DIR)/tl -I$(LIBKORDER_DIR)/utils -I$(LIBKORDER_DIR)/sylv -I$(LIBKORDER_DIR)/integ -I$(TOPDIR) $(CPPFLAGS_MATIO) k_order_perturbation_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) -k_order_perturbation_LDADD = ../libdynare++/libdynare++.a ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) +k_order_perturbation_LDADD = ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) nodist_k_order_perturbation_SOURCES = k_order_perturbation.cc diff --git a/mex/build/k_order_welfare.am b/mex/build/k_order_welfare.am index f927020359d241fbd1cf9b9b864a3be273a13bf2..26f24226ab5ab633468df791e07fa3a0ee0edaf7 100644 --- a/mex/build/k_order_welfare.am +++ b/mex/build/k_order_welfare.am @@ -1,11 +1,12 @@ mex_PROGRAMS = k_order_welfare TOPDIR = $(top_srcdir)/../../sources/k_order_welfare +LIBKORDER_DIR = $(top_srcdir)/../../sources/libkorder -k_order_welfare_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(TOPDIR)/../k_order_perturbation -I$(top_srcdir)/../../../dynare++/tl/cc -I$(top_srcdir)/../../../dynare++/kord -I$(top_srcdir)/../../../dynare++/src -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/utils/cc $(CPPFLAGS_MATIO) +k_order_welfare_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(LIBKORDER_DIR) -I$(LIBKORDER_DIR)/tl -I$(LIBKORDER_DIR)/kord -I$(LIBKORDER_DIR)/sylv -I$(LIBKORDER_DIR)/utils $(CPPFLAGS_MATIO) k_order_welfare_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) -k_order_welfare_LDADD = ../libdynare++/libdynare++.a ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) +k_order_welfare_LDADD = ../libkorder/libkorder.a $(LIBADD_DLOPEN) $(LIBADD_MATIO) nodist_k_order_welfare_SOURCES = \ k_order_welfare.cc \ diff --git a/mex/build/libdynare++.am b/mex/build/libdynare++.am deleted file mode 100644 index bb062275bedf0fa57a92fae24228fcf808dbb98b..0000000000000000000000000000000000000000 --- a/mex/build/libdynare++.am +++ /dev/null @@ -1,101 +0,0 @@ -noinst_LIBRARIES = libdynare++.a - -TOPDIR = $(top_srcdir)/../../../dynare++ - -libdynare___a_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR)/src -I$(TOPDIR)/kord -I$(TOPDIR)/tl/cc -I$(TOPDIR)/utils/cc -I$(TOPDIR)/sylv/cc -I$(TOPDIR)/integ/cc $(CPPFLAGS_MATIO) - -# TODO: fix the codebase so that the following line is no longer needed -libdynare___a_CXXFLAGS = $(AM_CXXFLAGS) -Wno-unused-parameter - -KORD_SRCS = \ - approximation.cc \ - decision_rule.cc \ - dynamic_model.cc \ - faa_di_bruno.cc \ - first_order.cc \ - global_check.cc \ - korder.cc \ - korder_stoch.cc \ - journal.cc \ - normal_conjugate.cc \ - seed_generator.cc - -SYLV_SRCS = \ - BlockDiagonal.cc \ - GeneralMatrix.cc \ - GeneralSylvester.cc \ - IterativeSylvester.cc \ - KronUtils.cc \ - KronVector.cc \ - QuasiTriangular.cc \ - QuasiTriangularZero.cc \ - SchurDecomp.cc \ - SchurDecompEig.cc \ - SimilarityDecomp.cc \ - SylvException.cc \ - SylvMatrix.cc \ - SylvParams.cc \ - SymSchurDecomp.cc \ - TriangularSylvester.cc \ - Vector.cc - -TL_SRCS = \ - equivalence.cc \ - fine_container.cc \ - fs_tensor.cc \ - gs_tensor.cc \ - int_sequence.cc \ - kron_prod.cc \ - normal_moments.cc \ - permutation.cc \ - ps_tensor.cc \ - pyramid_prod.cc \ - pyramid_prod2.cc \ - rfs_tensor.cc \ - sparse_tensor.cc \ - stack_container.cc \ - symmetry.cc \ - t_container.cc \ - t_polynomial.cc \ - tensor.cc \ - tl_static.cc \ - twod_matrix.cc - -INTEG_SRCS = \ - quadrature.cc \ - quasi_mcarlo.cc \ - product.cc \ - smolyak.cc \ - vector_function.cc - -UTILS_SRCS = \ - pascal_triangle.cc \ - int_power.cc \ - sthread.cc - -OTHER_SRCS = \ - nlsolve.cc - -nodist_libdynare___a_SOURCES = \ - $(KORD_SRCS) \ - $(TL_SRCS) \ - $(SYLV_SRCS) \ - $(INTEG_SRCS) \ - $(UTILS_SRCS) \ - $(OTHER_SRCS) - -BUILT_SOURCES = $(nodist_libdynare___a_SOURCES) -CLEANFILES = $(nodist_libdynare___a_SOURCES) - -$(KORD_SRCS): %.cc: $(TOPDIR)/kord/%.cc - $(LN_S) -f $< $@ -$(TL_SRCS): %.cc: $(TOPDIR)/tl/cc/%.cc - $(LN_S) -f $< $@ -$(SYLV_SRCS): %.cc: $(TOPDIR)/sylv/cc/%.cc - $(LN_S) -f $< $@ -$(INTEG_SRCS): %.cc: $(TOPDIR)/integ/cc/%.cc - $(LN_S) -f $< $@ -$(UTILS_SRCS): %.cc: $(TOPDIR)/utils/cc/%.cc - $(LN_S) -f $< $@ -$(OTHER_SRCS): %.cc: $(TOPDIR)/src/%.cc - $(LN_S) -f $< $@ diff --git a/mex/build/libkorder.am b/mex/build/libkorder.am index 093b68819c52d4c69108a06287b27f776183fefa..954ce022645dd8264c7a31461315c5dabcb14f64 100644 --- a/mex/build/libkorder.am +++ b/mex/build/libkorder.am @@ -1,16 +1,104 @@ noinst_LIBRARIES = libkorder.a -TOPDIR = $(top_srcdir)/../../sources/k_order_perturbation +TOPDIR = $(top_srcdir)/../../sources/libkorder -libkorder_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(top_srcdir)/../../../dynare++/tl/cc -I$(top_srcdir)/../../../dynare++/sylv/cc -I$(top_srcdir)/../../../dynare++/src -I$(top_srcdir)/../../../dynare++/kord -I$(top_srcdir)/../../../dynare++/utils/cc $(CPPFLAGS_MATIO) +libkorder_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(TOPDIR) -I$(TOPDIR)/tl -I$(TOPDIR)/sylv -I$(TOPDIR)/integ -I$(TOPDIR)/kord -I$(TOPDIR)/utils $(CPPFLAGS_MATIO) -nodist_libkorder_a_SOURCES = \ +# TODO: fix the codebase so that the following line is no longer needed +libkorder_a_CXXFLAGS = $(AM_CXXFLAGS) -Wno-unused-parameter + +KORD_SRCS = \ + approximation.cc \ + decision_rule.cc \ + dynamic_model.cc \ + faa_di_bruno.cc \ + first_order.cc \ + global_check.cc \ + korder.cc \ + korder_stoch.cc \ + journal.cc \ + normal_conjugate.cc \ + seed_generator.cc + +SYLV_SRCS = \ + BlockDiagonal.cc \ + GeneralMatrix.cc \ + GeneralSylvester.cc \ + IterativeSylvester.cc \ + KronUtils.cc \ + KronVector.cc \ + QuasiTriangular.cc \ + QuasiTriangularZero.cc \ + SchurDecomp.cc \ + SchurDecompEig.cc \ + SimilarityDecomp.cc \ + SylvException.cc \ + SylvMatrix.cc \ + SylvParams.cc \ + SymSchurDecomp.cc \ + TriangularSylvester.cc \ + Vector.cc + +TL_SRCS = \ + equivalence.cc \ + fine_container.cc \ + fs_tensor.cc \ + gs_tensor.cc \ + int_sequence.cc \ + kron_prod.cc \ + normal_moments.cc \ + permutation.cc \ + ps_tensor.cc \ + pyramid_prod.cc \ + pyramid_prod2.cc \ + rfs_tensor.cc \ + sparse_tensor.cc \ + stack_container.cc \ + symmetry.cc \ + t_container.cc \ + t_polynomial.cc \ + tensor.cc \ + tl_static.cc \ + twod_matrix.cc + +INTEG_SRCS = \ + quadrature.cc \ + quasi_mcarlo.cc \ + product.cc \ + smolyak.cc \ + vector_function.cc + +UTILS_SRCS = \ + pascal_triangle.cc \ + int_power.cc \ + sthread.cc \ + nlsolve.cc + +TOPDIR_SRCS = \ k_ord_dynare.cc \ dynamic_dll.cc \ dynamic_m.cc +nodist_libkorder_a_SOURCES = \ + $(KORD_SRCS) \ + $(TL_SRCS) \ + $(SYLV_SRCS) \ + $(INTEG_SRCS) \ + $(UTILS_SRCS) \ + $(TOPDIR_SRCS) + BUILT_SOURCES = $(nodist_libkorder_a_SOURCES) CLEANFILES = $(nodist_libkorder_a_SOURCES) -%.cc: $(TOPDIR)/%.cc +$(TOPDIR_SRCS): %.cc: $(TOPDIR)/%.cc + $(LN_S) -f $< $@ +$(KORD_SRCS): %.cc: $(TOPDIR)/kord/%.cc + $(LN_S) -f $< $@ +$(TL_SRCS): %.cc: $(TOPDIR)/tl/%.cc + $(LN_S) -f $< $@ +$(SYLV_SRCS): %.cc: $(TOPDIR)/sylv/%.cc + $(LN_S) -f $< $@ +$(INTEG_SRCS): %.cc: $(TOPDIR)/integ/%.cc + $(LN_S) -f $< $@ +$(UTILS_SRCS): %.cc: $(TOPDIR)/utils/%.cc $(LN_S) -f $< $@ diff --git a/mex/build/matlab/Makefile.am b/mex/build/matlab/Makefile.am index 54a7dc1f6d965c7ca1943dc1b0dee125d190a099..d822bc07b1df3de4e9b1215b035ab28493ada249 100644 --- a/mex/build/matlab/Makefile.am +++ b/mex/build/matlab/Makefile.am @@ -2,9 +2,9 @@ ACLOCAL_AMFLAGS = -I ../../../m4 SUBDIRS = mjdgges kronecker bytecode sobol perfect_foresight_problem num_procs block_trust_region disclyap_fast libkordersim local_state_space_iterations folded_to_unfolded_dr k_order_simul k_order_mean cycle_reduction logarithmic_reduction riccati_update -# libdynare++ must come before gensylv and k_order_perturbation -if ENABLE_MEX_DYNAREPLUSPLUS -SUBDIRS += libdynare++ gensylv libkorder k_order_perturbation k_order_welfare +# libkorder must come first +if ENABLE_MEX_GENSYLV_KORDER +SUBDIRS += libkorder gensylv k_order_perturbation k_order_welfare endif if ENABLE_MEX_MS_SBVAR diff --git a/mex/build/matlab/configure.ac b/mex/build/matlab/configure.ac index 67fa9913e854d79722c89b6e4a34cc1e30a6544c..db678163c55585b848335dc1945204d9a44413f0 100644 --- a/mex/build/matlab/configure.ac +++ b/mex/build/matlab/configure.ac @@ -64,8 +64,8 @@ AC_SUBST([LIBADD_DLOPEN]) AC_ARG_ENABLE([mex-ms-sbvar], AS_HELP_STRING([--disable-mex-ms-sbvar], [disable compilation of the MS-SBVAR MEX]), [], [enable_mex_ms_sbvar=yes]) AM_CONDITIONAL([ENABLE_MEX_MS_SBVAR], [test "$enable_mex_ms_sbvar" = yes]) -AC_ARG_ENABLE([mex-dynare++], AS_HELP_STRING([--disable-mex-dynare++], [disable compilation of MEX based on Dynare++]), [], [enable_mex_dynareplusplus=yes]) -AM_CONDITIONAL([ENABLE_MEX_DYNAREPLUSPLUS], [test "$enable_mex_dynareplusplus" = yes]) +AC_ARG_ENABLE([mex-gensylv-korder], AS_HELP_STRING([--disable-mex-gensylv-korder], [disable compilation of gensylv and k-order MEX]), [], [enable_mex_gensylv_korder=yes]) +AM_CONDITIONAL([ENABLE_MEX_GENSYLV_KORDER], [test "$enable_mex_gensylv_korder" = yes]) AC_ARG_ENABLE([mex-kalman-steady-state], AS_HELP_STRING([--disable-mex-kalman-steady-state], [disable compilation of the kalman_steady_state MEX]), [], [enable_mex_kalman_steady_state=yes]) AM_CONDITIONAL([ENABLE_MEX_KALMAN_STEADY_STATE], [test "$enable_mex_kalman_steady_state" = yes]) @@ -77,9 +77,9 @@ if test "$enable_mex_ms_sbvar" = yes; then fi # Check for libmatio, needed by MEX files using Dynare++ code -if test "$enable_mex_dynareplusplus" = yes; then +if test "$enable_mex_gensylv_korder" = yes; then AX_MATIO - test "$has_matio" != yes && AC_MSG_ERROR([libmatio cannot be found. If you want to skip the compilation of MEX files based Dynare++, pass the --disable-mex-dynare++ flag.]) + test "$has_matio" != yes && AC_MSG_ERROR([libmatio cannot be found. If you want to skip the compilation of gensylv and k-order MEX, pass the --disable-mex-gensylv-korder flag.]) fi # Check for libslicot, needed by kalman_steady_state @@ -115,10 +115,10 @@ AC_SUBST([M2HTML]) AM_CONDITIONAL([HAVE_M2HTML], [test "x$M2HTML" != "x"]) # Construct final output message -if test "$enable_mex_dynareplusplus" = yes; then - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_MATLAB="yes" +if test "$enable_mex_gensylv_korder" = yes; then + BUILD_GENSYLV_KORDER_MEX_MATLAB="yes" else - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_MATLAB="no" + BUILD_GENSYLV_KORDER_MEX_MATLAB="no" fi if test "$enable_mex_kalman_steady_state" = yes; then @@ -139,7 +139,7 @@ Dynare is now configured for building the following components... Binaries (with "make"): MEX files for MATLAB (except those listed below): yes - Gensylv, k-order and dynare_simul MEX files for MATLAB: $BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_MATLAB + Gensylv and k-order MEX files for MATLAB: $BUILD_GENSYLV_KORDER_MEX_MATLAB MS-SBVAR MEX files for MATLAB: $BUILD_MS_SBVAR_MEX_MATLAB Kalman Steady State MEX file for MATLAB: $BUILD_KALMAN_STEADY_STATE_MATLAB M2HTML documentation: $BUILD_M2HTML @@ -150,7 +150,6 @@ AC_CONFIG_FILES([Makefile mjdgges/Makefile kronecker/Makefile bytecode/Makefile - libdynare++/Makefile gensylv/Makefile libkorder/Makefile k_order_perturbation/Makefile diff --git a/mex/build/matlab/libdynare++/Makefile.am b/mex/build/matlab/libdynare++/Makefile.am deleted file mode 100644 index c1283b13cdd77e87a6a1704503b546e05a267a65..0000000000000000000000000000000000000000 --- a/mex/build/matlab/libdynare++/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -include ../mex.am -include ../../libdynare++.am diff --git a/mex/build/octave/Makefile.am b/mex/build/octave/Makefile.am index c89c9de0bf84933a506e9072fd98c15b6116e0bc..7c47da953054ef577390e38a4c03916f105a736b 100644 --- a/mex/build/octave/Makefile.am +++ b/mex/build/octave/Makefile.am @@ -2,9 +2,9 @@ ACLOCAL_AMFLAGS = -I ../../../m4 SUBDIRS = mjdgges kronecker bytecode sobol perfect_foresight_problem num_procs block_trust_region disclyap_fast libkordersim local_state_space_iterations folded_to_unfolded_dr k_order_simul k_order_mean cycle_reduction logarithmic_reduction riccati_update -# libdynare++ must come before gensylv and k_order_perturbation -if ENABLE_MEX_DYNAREPLUSPLUS -SUBDIRS += libdynare++ gensylv libkorder k_order_perturbation k_order_welfare +# libkorder must come first +if ENABLE_MEX_GENSYLV_KORDER +SUBDIRS += libkorder gensylv k_order_perturbation k_order_welfare endif if ENABLE_MEX_MS_SBVAR diff --git a/mex/build/octave/configure.ac b/mex/build/octave/configure.ac index 001f6facdc7af4b323ebf2b15a215a283a0a41b7..2b0f46f48b6454512d6af94fd7661dafa70d0a30 100644 --- a/mex/build/octave/configure.ac +++ b/mex/build/octave/configure.ac @@ -66,8 +66,8 @@ AC_SUBST([LIBADD_DLOPEN]) AC_ARG_ENABLE([mex-ms-sbvar], AS_HELP_STRING([--disable-mex-ms-sbvar], [disable compilation of the MS-SBVAR MEX]), [], [enable_mex_ms_sbvar=yes]) AM_CONDITIONAL([ENABLE_MEX_MS_SBVAR], [test "$enable_mex_ms_sbvar" = yes]) -AC_ARG_ENABLE([mex-dynare++], AS_HELP_STRING([--disable-mex-dynare++], [disable compilation of MEX based on Dynare++]), [], [enable_mex_dynareplusplus=yes]) -AM_CONDITIONAL([ENABLE_MEX_DYNAREPLUSPLUS], [test "$enable_mex_dynareplusplus" = yes]) +AC_ARG_ENABLE([mex-gensylv-korder], AS_HELP_STRING([--disable-mex-gensylv-korder], [disable compilation of gensylv and k-order MEX]), [], [enable_mex_gensylv_korder=yes]) +AM_CONDITIONAL([ENABLE_MEX_GENSYLV_KORDER], [test "$enable_mex_gensylv_korder" = yes]) AC_ARG_ENABLE([mex-kalman-steady-state], AS_HELP_STRING([--disable-mex-kalman-steady-state], [disable compilation of the kalman_steady_state MEX]), [], [enable_mex_kalman_steady_state=yes]) AM_CONDITIONAL([ENABLE_MEX_KALMAN_STEADY_STATE], [test "$enable_mex_kalman_steady_state" = yes]) @@ -79,9 +79,9 @@ if test "$enable_mex_ms_sbvar" = yes; then fi # Check for libmatio, needed by MEX files using Dynare++ code, and by ms-sbvar (the latter only under Octave, as an alternative to MATLAB's libmat) -if test "$enable_mex_dynareplusplus" = yes -o "$enable_mex_ms_sbvar" = yes; then +if test "$enable_mex_gensylv_korder" = yes -o "$enable_mex_ms_sbvar" = yes; then AX_MATIO - test "$has_matio" != yes && AC_MSG_ERROR([libmatio cannot be found. If you want to skip the compilation of MS-SBVAR MEX and MEX files based Dynare++, pass the --disable-mex-dynare++ and --disable-mex-ms-sbvar flags.]) + test "$has_matio" != yes && AC_MSG_ERROR([libmatio cannot be found. If you want to skip the compilation of MS-SBVAR, gensylv and k-order MEX, pass the --disable-mex-gensylv-korder and --disable-mex-ms-sbvar flags.]) fi # Check for libslicot, needed by kalman_steady_state @@ -127,10 +127,10 @@ esac AM_CONDITIONAL([LINK_OCTAVE_LIBS], [test ${link_octave_libs} = yes]) # Construct final output message -if test "$enable_mex_dynareplusplus" = yes; then - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_OCTAVE="yes" +if test "$enable_mex_gensylv_korder" = yes; then + BUILD_GENSYLV_KORDER_MEX_OCTAVE="yes" else - BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_OCTAVE="no" + BUILD_GENSYLV_KORDER_MEX_OCTAVE="no" fi if test "$enable_mex_kalman_steady_state" = yes; then @@ -151,7 +151,7 @@ Dynare is now configured for building the following components... Binaries (with "make"): MEX files for Octave (except those listed below): yes - Gensylv, k-order and dynare_simul MEX for Octave: $BUILD_GENSYLV_KORDER_DYNSIMUL_MEX_OCTAVE + Gensylv and k-order MEX for Octave: $BUILD_GENSYLV_KORDER_MEX_OCTAVE MS-SBVAR MEX files for Octave: $BUILD_MS_SBVAR_MEX_OCTAVE Kalman Steady State MEX file for Octave: $BUILD_KALMAN_STEADY_STATE_OCTAVE @@ -161,7 +161,6 @@ AC_CONFIG_FILES([Makefile mjdgges/Makefile kronecker/Makefile bytecode/Makefile - libdynare++/Makefile gensylv/Makefile libkorder/Makefile k_order_perturbation/Makefile diff --git a/mex/build/octave/libdynare++/Makefile.am b/mex/build/octave/libdynare++/Makefile.am deleted file mode 100644 index 6ab9e430a68704c91d3beabb29f78f14f67371b7..0000000000000000000000000000000000000000 --- a/mex/build/octave/libdynare++/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -EXEEXT = .mex -include ../mex.am -include ../../libdynare++.am diff --git a/mex/sources/k_order_perturbation/dynamic_abstract_class.hh b/mex/sources/libkorder/dynamic_abstract_class.hh similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_abstract_class.hh rename to mex/sources/libkorder/dynamic_abstract_class.hh diff --git a/mex/sources/k_order_perturbation/dynamic_dll.cc b/mex/sources/libkorder/dynamic_dll.cc similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_dll.cc rename to mex/sources/libkorder/dynamic_dll.cc diff --git a/mex/sources/k_order_perturbation/dynamic_dll.hh b/mex/sources/libkorder/dynamic_dll.hh similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_dll.hh rename to mex/sources/libkorder/dynamic_dll.hh diff --git a/mex/sources/k_order_perturbation/dynamic_m.cc b/mex/sources/libkorder/dynamic_m.cc similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_m.cc rename to mex/sources/libkorder/dynamic_m.cc diff --git a/mex/sources/k_order_perturbation/dynamic_m.hh b/mex/sources/libkorder/dynamic_m.hh similarity index 100% rename from mex/sources/k_order_perturbation/dynamic_m.hh rename to mex/sources/libkorder/dynamic_m.hh diff --git a/dynare++/integ/cc/precalc_quadrature.hh b/mex/sources/libkorder/integ/precalc_quadrature.hh similarity index 100% rename from dynare++/integ/cc/precalc_quadrature.hh rename to mex/sources/libkorder/integ/precalc_quadrature.hh diff --git a/dynare++/integ/cc/product.cc b/mex/sources/libkorder/integ/product.cc similarity index 100% rename from dynare++/integ/cc/product.cc rename to mex/sources/libkorder/integ/product.cc diff --git a/dynare++/integ/cc/product.hh b/mex/sources/libkorder/integ/product.hh similarity index 100% rename from dynare++/integ/cc/product.hh rename to mex/sources/libkorder/integ/product.hh diff --git a/dynare++/integ/cc/quadrature.cc b/mex/sources/libkorder/integ/quadrature.cc similarity index 100% rename from dynare++/integ/cc/quadrature.cc rename to mex/sources/libkorder/integ/quadrature.cc diff --git a/dynare++/integ/cc/quadrature.hh b/mex/sources/libkorder/integ/quadrature.hh similarity index 100% rename from dynare++/integ/cc/quadrature.hh rename to mex/sources/libkorder/integ/quadrature.hh diff --git a/dynare++/integ/cc/quasi_mcarlo.cc b/mex/sources/libkorder/integ/quasi_mcarlo.cc similarity index 100% rename from dynare++/integ/cc/quasi_mcarlo.cc rename to mex/sources/libkorder/integ/quasi_mcarlo.cc diff --git a/dynare++/integ/cc/quasi_mcarlo.hh b/mex/sources/libkorder/integ/quasi_mcarlo.hh similarity index 100% rename from dynare++/integ/cc/quasi_mcarlo.hh rename to mex/sources/libkorder/integ/quasi_mcarlo.hh diff --git a/dynare++/integ/cc/smolyak.cc b/mex/sources/libkorder/integ/smolyak.cc similarity index 100% rename from dynare++/integ/cc/smolyak.cc rename to mex/sources/libkorder/integ/smolyak.cc diff --git a/dynare++/integ/cc/smolyak.hh b/mex/sources/libkorder/integ/smolyak.hh similarity index 100% rename from dynare++/integ/cc/smolyak.hh rename to mex/sources/libkorder/integ/smolyak.hh diff --git a/dynare++/integ/testing/Makefile.am b/mex/sources/libkorder/integ/tests/Makefile.am similarity index 100% rename from dynare++/integ/testing/Makefile.am rename to mex/sources/libkorder/integ/tests/Makefile.am diff --git a/dynare++/integ/testing/tests.cc b/mex/sources/libkorder/integ/tests/tests.cc similarity index 100% rename from dynare++/integ/testing/tests.cc rename to mex/sources/libkorder/integ/tests/tests.cc diff --git a/dynare++/integ/cc/vector_function.cc b/mex/sources/libkorder/integ/vector_function.cc similarity index 100% rename from dynare++/integ/cc/vector_function.cc rename to mex/sources/libkorder/integ/vector_function.cc diff --git a/dynare++/integ/cc/vector_function.hh b/mex/sources/libkorder/integ/vector_function.hh similarity index 100% rename from dynare++/integ/cc/vector_function.hh rename to mex/sources/libkorder/integ/vector_function.hh diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.cc b/mex/sources/libkorder/k_ord_dynare.cc similarity index 100% rename from mex/sources/k_order_perturbation/k_ord_dynare.cc rename to mex/sources/libkorder/k_ord_dynare.cc diff --git a/mex/sources/k_order_perturbation/k_ord_dynare.hh b/mex/sources/libkorder/k_ord_dynare.hh similarity index 100% rename from mex/sources/k_order_perturbation/k_ord_dynare.hh rename to mex/sources/libkorder/k_ord_dynare.hh diff --git a/dynare++/kord/approximation.cc b/mex/sources/libkorder/kord/approximation.cc similarity index 100% rename from dynare++/kord/approximation.cc rename to mex/sources/libkorder/kord/approximation.cc diff --git a/dynare++/kord/approximation.hh b/mex/sources/libkorder/kord/approximation.hh similarity index 100% rename from dynare++/kord/approximation.hh rename to mex/sources/libkorder/kord/approximation.hh diff --git a/dynare++/kord/decision_rule.cc b/mex/sources/libkorder/kord/decision_rule.cc similarity index 100% rename from dynare++/kord/decision_rule.cc rename to mex/sources/libkorder/kord/decision_rule.cc diff --git a/dynare++/kord/decision_rule.hh b/mex/sources/libkorder/kord/decision_rule.hh similarity index 100% rename from dynare++/kord/decision_rule.hh rename to mex/sources/libkorder/kord/decision_rule.hh diff --git a/dynare++/kord/dynamic_model.cc b/mex/sources/libkorder/kord/dynamic_model.cc similarity index 100% rename from dynare++/kord/dynamic_model.cc rename to mex/sources/libkorder/kord/dynamic_model.cc diff --git a/dynare++/kord/dynamic_model.hh b/mex/sources/libkorder/kord/dynamic_model.hh similarity index 100% rename from dynare++/kord/dynamic_model.hh rename to mex/sources/libkorder/kord/dynamic_model.hh diff --git a/dynare++/kord/faa_di_bruno.cc b/mex/sources/libkorder/kord/faa_di_bruno.cc similarity index 100% rename from dynare++/kord/faa_di_bruno.cc rename to mex/sources/libkorder/kord/faa_di_bruno.cc diff --git a/dynare++/kord/faa_di_bruno.hh b/mex/sources/libkorder/kord/faa_di_bruno.hh similarity index 100% rename from dynare++/kord/faa_di_bruno.hh rename to mex/sources/libkorder/kord/faa_di_bruno.hh diff --git a/dynare++/kord/first_order.cc b/mex/sources/libkorder/kord/first_order.cc similarity index 100% rename from dynare++/kord/first_order.cc rename to mex/sources/libkorder/kord/first_order.cc diff --git a/dynare++/kord/first_order.hh b/mex/sources/libkorder/kord/first_order.hh similarity index 100% rename from dynare++/kord/first_order.hh rename to mex/sources/libkorder/kord/first_order.hh diff --git a/dynare++/kord/global_check.cc b/mex/sources/libkorder/kord/global_check.cc similarity index 100% rename from dynare++/kord/global_check.cc rename to mex/sources/libkorder/kord/global_check.cc diff --git a/dynare++/kord/global_check.hh b/mex/sources/libkorder/kord/global_check.hh similarity index 100% rename from dynare++/kord/global_check.hh rename to mex/sources/libkorder/kord/global_check.hh diff --git a/dynare++/kord/journal.cc b/mex/sources/libkorder/kord/journal.cc similarity index 100% rename from dynare++/kord/journal.cc rename to mex/sources/libkorder/kord/journal.cc diff --git a/dynare++/kord/journal.hh b/mex/sources/libkorder/kord/journal.hh similarity index 100% rename from dynare++/kord/journal.hh rename to mex/sources/libkorder/kord/journal.hh diff --git a/dynare++/kord/kord_exception.hh b/mex/sources/libkorder/kord/kord_exception.hh similarity index 100% rename from dynare++/kord/kord_exception.hh rename to mex/sources/libkorder/kord/kord_exception.hh diff --git a/dynare++/kord/korder.cc b/mex/sources/libkorder/kord/korder.cc similarity index 100% rename from dynare++/kord/korder.cc rename to mex/sources/libkorder/kord/korder.cc diff --git a/dynare++/kord/korder.hh b/mex/sources/libkorder/kord/korder.hh similarity index 100% rename from dynare++/kord/korder.hh rename to mex/sources/libkorder/kord/korder.hh diff --git a/dynare++/kord/korder_stoch.cc b/mex/sources/libkorder/kord/korder_stoch.cc similarity index 100% rename from dynare++/kord/korder_stoch.cc rename to mex/sources/libkorder/kord/korder_stoch.cc diff --git a/dynare++/kord/korder_stoch.hh b/mex/sources/libkorder/kord/korder_stoch.hh similarity index 100% rename from dynare++/kord/korder_stoch.hh rename to mex/sources/libkorder/kord/korder_stoch.hh diff --git a/dynare++/kord/normal_conjugate.cc b/mex/sources/libkorder/kord/normal_conjugate.cc similarity index 100% rename from dynare++/kord/normal_conjugate.cc rename to mex/sources/libkorder/kord/normal_conjugate.cc diff --git a/dynare++/kord/normal_conjugate.hh b/mex/sources/libkorder/kord/normal_conjugate.hh similarity index 100% rename from dynare++/kord/normal_conjugate.hh rename to mex/sources/libkorder/kord/normal_conjugate.hh diff --git a/dynare++/kord/seed_generator.cc b/mex/sources/libkorder/kord/seed_generator.cc similarity index 100% rename from dynare++/kord/seed_generator.cc rename to mex/sources/libkorder/kord/seed_generator.cc diff --git a/dynare++/kord/seed_generator.hh b/mex/sources/libkorder/kord/seed_generator.hh similarity index 100% rename from dynare++/kord/seed_generator.hh rename to mex/sources/libkorder/kord/seed_generator.hh diff --git a/mex/sources/libkorder/kord/tests/Makefile.am b/mex/sources/libkorder/kord/tests/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..14d4022280a3b1ce0c8fa65ad0491b7e945a3e12 --- /dev/null +++ b/mex/sources/libkorder/kord/tests/Makefile.am @@ -0,0 +1,11 @@ +check_PROGRAMS = tests + +tests_SOURCES = tests.cc +tests_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -I../utils/cc -I$(top_srcdir)/mex/sources +tests_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_MATIO) +tests_LDADD = libkord.a ../tl/cc/libtl.a ../sylv/cc/libsylv.a ../utils/cc/libutils.a $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) $(LIBADD_MATIO) + +check-local: + ./tests + +CLEANFILES = out.txt diff --git a/dynare++/kord/tests.cc b/mex/sources/libkorder/kord/tests/tests.cc similarity index 100% rename from dynare++/kord/tests.cc rename to mex/sources/libkorder/kord/tests/tests.cc diff --git a/dynare++/sylv/cc/BlockDiagonal.cc b/mex/sources/libkorder/sylv/BlockDiagonal.cc similarity index 100% rename from dynare++/sylv/cc/BlockDiagonal.cc rename to mex/sources/libkorder/sylv/BlockDiagonal.cc diff --git a/dynare++/sylv/cc/BlockDiagonal.hh b/mex/sources/libkorder/sylv/BlockDiagonal.hh similarity index 100% rename from dynare++/sylv/cc/BlockDiagonal.hh rename to mex/sources/libkorder/sylv/BlockDiagonal.hh diff --git a/dynare++/sylv/cc/GeneralMatrix.cc b/mex/sources/libkorder/sylv/GeneralMatrix.cc similarity index 100% rename from dynare++/sylv/cc/GeneralMatrix.cc rename to mex/sources/libkorder/sylv/GeneralMatrix.cc diff --git a/dynare++/sylv/cc/GeneralMatrix.hh b/mex/sources/libkorder/sylv/GeneralMatrix.hh similarity index 100% rename from dynare++/sylv/cc/GeneralMatrix.hh rename to mex/sources/libkorder/sylv/GeneralMatrix.hh diff --git a/dynare++/sylv/cc/GeneralSylvester.cc b/mex/sources/libkorder/sylv/GeneralSylvester.cc similarity index 100% rename from dynare++/sylv/cc/GeneralSylvester.cc rename to mex/sources/libkorder/sylv/GeneralSylvester.cc diff --git a/dynare++/sylv/cc/GeneralSylvester.hh b/mex/sources/libkorder/sylv/GeneralSylvester.hh similarity index 100% rename from dynare++/sylv/cc/GeneralSylvester.hh rename to mex/sources/libkorder/sylv/GeneralSylvester.hh diff --git a/dynare++/sylv/cc/IterativeSylvester.cc b/mex/sources/libkorder/sylv/IterativeSylvester.cc similarity index 100% rename from dynare++/sylv/cc/IterativeSylvester.cc rename to mex/sources/libkorder/sylv/IterativeSylvester.cc diff --git a/dynare++/sylv/cc/IterativeSylvester.hh b/mex/sources/libkorder/sylv/IterativeSylvester.hh similarity index 100% rename from dynare++/sylv/cc/IterativeSylvester.hh rename to mex/sources/libkorder/sylv/IterativeSylvester.hh diff --git a/dynare++/sylv/cc/KronUtils.cc b/mex/sources/libkorder/sylv/KronUtils.cc similarity index 100% rename from dynare++/sylv/cc/KronUtils.cc rename to mex/sources/libkorder/sylv/KronUtils.cc diff --git a/dynare++/sylv/cc/KronUtils.hh b/mex/sources/libkorder/sylv/KronUtils.hh similarity index 100% rename from dynare++/sylv/cc/KronUtils.hh rename to mex/sources/libkorder/sylv/KronUtils.hh diff --git a/dynare++/sylv/cc/KronVector.cc b/mex/sources/libkorder/sylv/KronVector.cc similarity index 100% rename from dynare++/sylv/cc/KronVector.cc rename to mex/sources/libkorder/sylv/KronVector.cc diff --git a/dynare++/sylv/cc/KronVector.hh b/mex/sources/libkorder/sylv/KronVector.hh similarity index 100% rename from dynare++/sylv/cc/KronVector.hh rename to mex/sources/libkorder/sylv/KronVector.hh diff --git a/dynare++/sylv/cc/QuasiTriangular.cc b/mex/sources/libkorder/sylv/QuasiTriangular.cc similarity index 100% rename from dynare++/sylv/cc/QuasiTriangular.cc rename to mex/sources/libkorder/sylv/QuasiTriangular.cc diff --git a/dynare++/sylv/cc/QuasiTriangular.hh b/mex/sources/libkorder/sylv/QuasiTriangular.hh similarity index 100% rename from dynare++/sylv/cc/QuasiTriangular.hh rename to mex/sources/libkorder/sylv/QuasiTriangular.hh diff --git a/dynare++/sylv/cc/QuasiTriangularZero.cc b/mex/sources/libkorder/sylv/QuasiTriangularZero.cc similarity index 100% rename from dynare++/sylv/cc/QuasiTriangularZero.cc rename to mex/sources/libkorder/sylv/QuasiTriangularZero.cc diff --git a/dynare++/sylv/cc/QuasiTriangularZero.hh b/mex/sources/libkorder/sylv/QuasiTriangularZero.hh similarity index 100% rename from dynare++/sylv/cc/QuasiTriangularZero.hh rename to mex/sources/libkorder/sylv/QuasiTriangularZero.hh diff --git a/dynare++/sylv/cc/SchurDecomp.cc b/mex/sources/libkorder/sylv/SchurDecomp.cc similarity index 100% rename from dynare++/sylv/cc/SchurDecomp.cc rename to mex/sources/libkorder/sylv/SchurDecomp.cc diff --git a/dynare++/sylv/cc/SchurDecomp.hh b/mex/sources/libkorder/sylv/SchurDecomp.hh similarity index 100% rename from dynare++/sylv/cc/SchurDecomp.hh rename to mex/sources/libkorder/sylv/SchurDecomp.hh diff --git a/dynare++/sylv/cc/SchurDecompEig.cc b/mex/sources/libkorder/sylv/SchurDecompEig.cc similarity index 100% rename from dynare++/sylv/cc/SchurDecompEig.cc rename to mex/sources/libkorder/sylv/SchurDecompEig.cc diff --git a/dynare++/sylv/cc/SchurDecompEig.hh b/mex/sources/libkorder/sylv/SchurDecompEig.hh similarity index 100% rename from dynare++/sylv/cc/SchurDecompEig.hh rename to mex/sources/libkorder/sylv/SchurDecompEig.hh diff --git a/dynare++/sylv/cc/SimilarityDecomp.cc b/mex/sources/libkorder/sylv/SimilarityDecomp.cc similarity index 100% rename from dynare++/sylv/cc/SimilarityDecomp.cc rename to mex/sources/libkorder/sylv/SimilarityDecomp.cc diff --git a/dynare++/sylv/cc/SimilarityDecomp.hh b/mex/sources/libkorder/sylv/SimilarityDecomp.hh similarity index 100% rename from dynare++/sylv/cc/SimilarityDecomp.hh rename to mex/sources/libkorder/sylv/SimilarityDecomp.hh diff --git a/dynare++/sylv/cc/SylvException.cc b/mex/sources/libkorder/sylv/SylvException.cc similarity index 100% rename from dynare++/sylv/cc/SylvException.cc rename to mex/sources/libkorder/sylv/SylvException.cc diff --git a/dynare++/sylv/cc/SylvException.hh b/mex/sources/libkorder/sylv/SylvException.hh similarity index 100% rename from dynare++/sylv/cc/SylvException.hh rename to mex/sources/libkorder/sylv/SylvException.hh diff --git a/dynare++/sylv/cc/SylvMatrix.cc b/mex/sources/libkorder/sylv/SylvMatrix.cc similarity index 100% rename from dynare++/sylv/cc/SylvMatrix.cc rename to mex/sources/libkorder/sylv/SylvMatrix.cc diff --git a/dynare++/sylv/cc/SylvMatrix.hh b/mex/sources/libkorder/sylv/SylvMatrix.hh similarity index 100% rename from dynare++/sylv/cc/SylvMatrix.hh rename to mex/sources/libkorder/sylv/SylvMatrix.hh diff --git a/dynare++/sylv/cc/SylvParams.cc b/mex/sources/libkorder/sylv/SylvParams.cc similarity index 100% rename from dynare++/sylv/cc/SylvParams.cc rename to mex/sources/libkorder/sylv/SylvParams.cc diff --git a/dynare++/sylv/cc/SylvParams.hh b/mex/sources/libkorder/sylv/SylvParams.hh similarity index 100% rename from dynare++/sylv/cc/SylvParams.hh rename to mex/sources/libkorder/sylv/SylvParams.hh diff --git a/dynare++/sylv/cc/SylvesterSolver.hh b/mex/sources/libkorder/sylv/SylvesterSolver.hh similarity index 100% rename from dynare++/sylv/cc/SylvesterSolver.hh rename to mex/sources/libkorder/sylv/SylvesterSolver.hh diff --git a/dynare++/sylv/cc/SymSchurDecomp.cc b/mex/sources/libkorder/sylv/SymSchurDecomp.cc similarity index 100% rename from dynare++/sylv/cc/SymSchurDecomp.cc rename to mex/sources/libkorder/sylv/SymSchurDecomp.cc diff --git a/dynare++/sylv/cc/SymSchurDecomp.hh b/mex/sources/libkorder/sylv/SymSchurDecomp.hh similarity index 100% rename from dynare++/sylv/cc/SymSchurDecomp.hh rename to mex/sources/libkorder/sylv/SymSchurDecomp.hh diff --git a/dynare++/sylv/cc/TriangularSylvester.cc b/mex/sources/libkorder/sylv/TriangularSylvester.cc similarity index 100% rename from dynare++/sylv/cc/TriangularSylvester.cc rename to mex/sources/libkorder/sylv/TriangularSylvester.cc diff --git a/dynare++/sylv/cc/TriangularSylvester.hh b/mex/sources/libkorder/sylv/TriangularSylvester.hh similarity index 100% rename from dynare++/sylv/cc/TriangularSylvester.hh rename to mex/sources/libkorder/sylv/TriangularSylvester.hh diff --git a/dynare++/sylv/cc/Vector.cc b/mex/sources/libkorder/sylv/Vector.cc similarity index 100% rename from dynare++/sylv/cc/Vector.cc rename to mex/sources/libkorder/sylv/Vector.cc diff --git a/dynare++/sylv/cc/Vector.hh b/mex/sources/libkorder/sylv/Vector.hh similarity index 100% rename from dynare++/sylv/cc/Vector.hh rename to mex/sources/libkorder/sylv/Vector.hh diff --git a/dynare++/sylv/testing/MMMatrix.cc b/mex/sources/libkorder/sylv/tests/MMMatrix.cc similarity index 100% rename from dynare++/sylv/testing/MMMatrix.cc rename to mex/sources/libkorder/sylv/tests/MMMatrix.cc diff --git a/dynare++/sylv/testing/MMMatrix.hh b/mex/sources/libkorder/sylv/tests/MMMatrix.hh similarity index 100% rename from dynare++/sylv/testing/MMMatrix.hh rename to mex/sources/libkorder/sylv/tests/MMMatrix.hh diff --git a/dynare++/sylv/testing/Makefile.am b/mex/sources/libkorder/sylv/tests/Makefile.am similarity index 100% rename from dynare++/sylv/testing/Makefile.am rename to mex/sources/libkorder/sylv/tests/Makefile.am diff --git a/dynare++/sylv/testing/a20x20.mm b/mex/sources/libkorder/sylv/tests/a20x20.mm similarity index 100% rename from dynare++/sylv/testing/a20x20.mm rename to mex/sources/libkorder/sylv/tests/a20x20.mm diff --git a/dynare++/sylv/testing/a2x2.mm b/mex/sources/libkorder/sylv/tests/a2x2.mm similarity index 100% rename from dynare++/sylv/testing/a2x2.mm rename to mex/sources/libkorder/sylv/tests/a2x2.mm diff --git a/dynare++/sylv/testing/a30x30.mm b/mex/sources/libkorder/sylv/tests/a30x30.mm similarity index 100% rename from dynare++/sylv/testing/a30x30.mm rename to mex/sources/libkorder/sylv/tests/a30x30.mm diff --git a/dynare++/sylv/testing/b20x15.mm b/mex/sources/libkorder/sylv/tests/b20x15.mm similarity index 100% rename from dynare++/sylv/testing/b20x15.mm rename to mex/sources/libkorder/sylv/tests/b20x15.mm diff --git a/dynare++/sylv/testing/b20x4.mm b/mex/sources/libkorder/sylv/tests/b20x4.mm similarity index 100% rename from dynare++/sylv/testing/b20x4.mm rename to mex/sources/libkorder/sylv/tests/b20x4.mm diff --git a/dynare++/sylv/testing/b2x1.mm b/mex/sources/libkorder/sylv/tests/b2x1.mm similarity index 100% rename from dynare++/sylv/testing/b2x1.mm rename to mex/sources/libkorder/sylv/tests/b2x1.mm diff --git a/dynare++/sylv/testing/b30x25.mm b/mex/sources/libkorder/sylv/tests/b30x25.mm similarity index 100% rename from dynare++/sylv/testing/b30x25.mm rename to mex/sources/libkorder/sylv/tests/b30x25.mm diff --git a/dynare++/sylv/testing/c20x20.mm b/mex/sources/libkorder/sylv/tests/c20x20.mm similarity index 100% rename from dynare++/sylv/testing/c20x20.mm rename to mex/sources/libkorder/sylv/tests/c20x20.mm diff --git a/dynare++/sylv/testing/c3x3.mm b/mex/sources/libkorder/sylv/tests/c3x3.mm similarity index 100% rename from dynare++/sylv/testing/c3x3.mm rename to mex/sources/libkorder/sylv/tests/c3x3.mm diff --git a/dynare++/sylv/testing/c50x50.mm b/mex/sources/libkorder/sylv/tests/c50x50.mm similarity index 100% rename from dynare++/sylv/testing/c50x50.mm rename to mex/sources/libkorder/sylv/tests/c50x50.mm diff --git a/dynare++/sylv/testing/c50x50sing.mm b/mex/sources/libkorder/sylv/tests/c50x50sing.mm similarity index 100% rename from dynare++/sylv/testing/c50x50sing.mm rename to mex/sources/libkorder/sylv/tests/c50x50sing.mm diff --git a/dynare++/sylv/testing/d20x125000.mm b/mex/sources/libkorder/sylv/tests/d20x125000.mm similarity index 100% rename from dynare++/sylv/testing/d20x125000.mm rename to mex/sources/libkorder/sylv/tests/d20x125000.mm diff --git a/dynare++/sylv/testing/d2x9.mm b/mex/sources/libkorder/sylv/tests/d2x9.mm similarity index 100% rename from dynare++/sylv/testing/d2x9.mm rename to mex/sources/libkorder/sylv/tests/d2x9.mm diff --git a/dynare++/sylv/testing/d30x400.mm b/mex/sources/libkorder/sylv/tests/d30x400.mm similarity index 100% rename from dynare++/sylv/testing/d30x400.mm rename to mex/sources/libkorder/sylv/tests/d30x400.mm diff --git a/dynare++/sylv/testing/ill_cond15x15.mm b/mex/sources/libkorder/sylv/tests/ill_cond15x15.mm similarity index 100% rename from dynare++/sylv/testing/ill_cond15x15.mm rename to mex/sources/libkorder/sylv/tests/ill_cond15x15.mm diff --git a/dynare++/sylv/testing/qt250x250.mm b/mex/sources/libkorder/sylv/tests/qt250x250.mm similarity index 100% rename from dynare++/sylv/testing/qt250x250.mm rename to mex/sources/libkorder/sylv/tests/qt250x250.mm diff --git a/dynare++/sylv/testing/qt2x2.mm b/mex/sources/libkorder/sylv/tests/qt2x2.mm similarity index 100% rename from dynare++/sylv/testing/qt2x2.mm rename to mex/sources/libkorder/sylv/tests/qt2x2.mm diff --git a/dynare++/sylv/testing/qt30x30.mm b/mex/sources/libkorder/sylv/tests/qt30x30.mm similarity index 100% rename from dynare++/sylv/testing/qt30x30.mm rename to mex/sources/libkorder/sylv/tests/qt30x30.mm diff --git a/dynare++/sylv/testing/qt30x30eig011-095.mm b/mex/sources/libkorder/sylv/tests/qt30x30eig011-095.mm similarity index 100% rename from dynare++/sylv/testing/qt30x30eig011-095.mm rename to mex/sources/libkorder/sylv/tests/qt30x30eig011-095.mm diff --git a/dynare++/sylv/testing/qt3x3.mm b/mex/sources/libkorder/sylv/tests/qt3x3.mm similarity index 100% rename from dynare++/sylv/testing/qt3x3.mm rename to mex/sources/libkorder/sylv/tests/qt3x3.mm diff --git a/dynare++/sylv/testing/qt40x40.mm b/mex/sources/libkorder/sylv/tests/qt40x40.mm similarity index 100% rename from dynare++/sylv/testing/qt40x40.mm rename to mex/sources/libkorder/sylv/tests/qt40x40.mm diff --git a/dynare++/sylv/testing/qt5x5.mm b/mex/sources/libkorder/sylv/tests/qt5x5.mm similarity index 100% rename from dynare++/sylv/testing/qt5x5.mm rename to mex/sources/libkorder/sylv/tests/qt5x5.mm diff --git a/dynare++/sylv/testing/qt7x7.mm b/mex/sources/libkorder/sylv/tests/qt7x7.mm similarity index 100% rename from dynare++/sylv/testing/qt7x7.mm rename to mex/sources/libkorder/sylv/tests/qt7x7.mm diff --git a/dynare++/sylv/testing/qt7x7eig06-09.mm b/mex/sources/libkorder/sylv/tests/qt7x7eig06-09.mm similarity index 100% rename from dynare++/sylv/testing/qt7x7eig06-09.mm rename to mex/sources/libkorder/sylv/tests/qt7x7eig06-09.mm diff --git a/dynare++/sylv/testing/qt_eps3x3.mm b/mex/sources/libkorder/sylv/tests/qt_eps3x3.mm similarity index 100% rename from dynare++/sylv/testing/qt_eps3x3.mm rename to mex/sources/libkorder/sylv/tests/qt_eps3x3.mm diff --git a/dynare++/sylv/testing/qt_frank12x12.mm b/mex/sources/libkorder/sylv/tests/qt_frank12x12.mm similarity index 100% rename from dynare++/sylv/testing/qt_frank12x12.mm rename to mex/sources/libkorder/sylv/tests/qt_frank12x12.mm diff --git a/dynare++/sylv/testing/tests.cc b/mex/sources/libkorder/sylv/tests/tests.cc similarity index 100% rename from dynare++/sylv/testing/tests.cc rename to mex/sources/libkorder/sylv/tests/tests.cc diff --git a/dynare++/sylv/testing/tr2x2.mm b/mex/sources/libkorder/sylv/tests/tr2x2.mm similarity index 100% rename from dynare++/sylv/testing/tr2x2.mm rename to mex/sources/libkorder/sylv/tests/tr2x2.mm diff --git a/dynare++/sylv/testing/tr300x300.mm b/mex/sources/libkorder/sylv/tests/tr300x300.mm similarity index 100% rename from dynare++/sylv/testing/tr300x300.mm rename to mex/sources/libkorder/sylv/tests/tr300x300.mm diff --git a/dynare++/sylv/testing/tr5x5.mm b/mex/sources/libkorder/sylv/tests/tr5x5.mm similarity index 100% rename from dynare++/sylv/testing/tr5x5.mm rename to mex/sources/libkorder/sylv/tests/tr5x5.mm diff --git a/dynare++/sylv/testing/v12r.mm b/mex/sources/libkorder/sylv/tests/v12r.mm similarity index 100% rename from dynare++/sylv/testing/v12r.mm rename to mex/sources/libkorder/sylv/tests/v12r.mm diff --git a/dynare++/sylv/testing/v1715.mm b/mex/sources/libkorder/sylv/tests/v1715.mm similarity index 100% rename from dynare++/sylv/testing/v1715.mm rename to mex/sources/libkorder/sylv/tests/v1715.mm diff --git a/dynare++/sylv/testing/v1920000.mm b/mex/sources/libkorder/sylv/tests/v1920000.mm similarity index 100% rename from dynare++/sylv/testing/v1920000.mm rename to mex/sources/libkorder/sylv/tests/v1920000.mm diff --git a/dynare++/sylv/testing/v2.mm b/mex/sources/libkorder/sylv/tests/v2.mm similarity index 100% rename from dynare++/sylv/testing/v2.mm rename to mex/sources/libkorder/sylv/tests/v2.mm diff --git a/dynare++/sylv/testing/v24.mm b/mex/sources/libkorder/sylv/tests/v24.mm similarity index 100% rename from dynare++/sylv/testing/v24.mm rename to mex/sources/libkorder/sylv/tests/v24.mm diff --git a/dynare++/sylv/testing/v245.mm b/mex/sources/libkorder/sylv/tests/v245.mm similarity index 100% rename from dynare++/sylv/testing/v245.mm rename to mex/sources/libkorder/sylv/tests/v245.mm diff --git a/dynare++/sylv/testing/v245r.mm b/mex/sources/libkorder/sylv/tests/v245r.mm similarity index 100% rename from dynare++/sylv/testing/v245r.mm rename to mex/sources/libkorder/sylv/tests/v245r.mm diff --git a/dynare++/sylv/testing/v250.mm b/mex/sources/libkorder/sylv/tests/v250.mm similarity index 100% rename from dynare++/sylv/testing/v250.mm rename to mex/sources/libkorder/sylv/tests/v250.mm diff --git a/dynare++/sylv/testing/v300.mm b/mex/sources/libkorder/sylv/tests/v300.mm similarity index 100% rename from dynare++/sylv/testing/v300.mm rename to mex/sources/libkorder/sylv/tests/v300.mm diff --git a/dynare++/sylv/testing/v48000.mm b/mex/sources/libkorder/sylv/tests/v48000.mm similarity index 100% rename from dynare++/sylv/testing/v48000.mm rename to mex/sources/libkorder/sylv/tests/v48000.mm diff --git a/dynare++/sylv/testing/v490.mm b/mex/sources/libkorder/sylv/tests/v490.mm similarity index 100% rename from dynare++/sylv/testing/v490.mm rename to mex/sources/libkorder/sylv/tests/v490.mm diff --git a/dynare++/sylv/testing/v5.mm b/mex/sources/libkorder/sylv/tests/v5.mm similarity index 100% rename from dynare++/sylv/testing/v5.mm rename to mex/sources/libkorder/sylv/tests/v5.mm diff --git a/dynare++/sylv/testing/v7.mm b/mex/sources/libkorder/sylv/tests/v7.mm similarity index 100% rename from dynare++/sylv/testing/v7.mm rename to mex/sources/libkorder/sylv/tests/v7.mm diff --git a/dynare++/sylv/testing/vcheck1715.mm b/mex/sources/libkorder/sylv/tests/vcheck1715.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715.mm diff --git a/dynare++/sylv/testing/vcheck1715a.mm b/mex/sources/libkorder/sylv/tests/vcheck1715a.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715a.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715a.mm diff --git a/dynare++/sylv/testing/vcheck1715b.mm b/mex/sources/libkorder/sylv/tests/vcheck1715b.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715b.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715b.mm diff --git a/dynare++/sylv/testing/vcheck1715c.mm b/mex/sources/libkorder/sylv/tests/vcheck1715c.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715c.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715c.mm diff --git a/dynare++/sylv/testing/vcheck1715d.mm b/mex/sources/libkorder/sylv/tests/vcheck1715d.mm similarity index 100% rename from dynare++/sylv/testing/vcheck1715d.mm rename to mex/sources/libkorder/sylv/tests/vcheck1715d.mm diff --git a/dynare++/sylv/testing/vcheck2.mm b/mex/sources/libkorder/sylv/tests/vcheck2.mm similarity index 100% rename from dynare++/sylv/testing/vcheck2.mm rename to mex/sources/libkorder/sylv/tests/vcheck2.mm diff --git a/dynare++/sylv/testing/vcheck24.mm b/mex/sources/libkorder/sylv/tests/vcheck24.mm similarity index 100% rename from dynare++/sylv/testing/vcheck24.mm rename to mex/sources/libkorder/sylv/tests/vcheck24.mm diff --git a/dynare++/sylv/testing/vcheck245.mm b/mex/sources/libkorder/sylv/tests/vcheck245.mm similarity index 100% rename from dynare++/sylv/testing/vcheck245.mm rename to mex/sources/libkorder/sylv/tests/vcheck245.mm diff --git a/dynare++/sylv/testing/vcheck245a.mm b/mex/sources/libkorder/sylv/tests/vcheck245a.mm similarity index 100% rename from dynare++/sylv/testing/vcheck245a.mm rename to mex/sources/libkorder/sylv/tests/vcheck245a.mm diff --git a/dynare++/sylv/testing/vcheck24q.mm b/mex/sources/libkorder/sylv/tests/vcheck24q.mm similarity index 100% rename from dynare++/sylv/testing/vcheck24q.mm rename to mex/sources/libkorder/sylv/tests/vcheck24q.mm diff --git a/dynare++/sylv/testing/vcheck2a.mm b/mex/sources/libkorder/sylv/tests/vcheck2a.mm similarity index 100% rename from dynare++/sylv/testing/vcheck2a.mm rename to mex/sources/libkorder/sylv/tests/vcheck2a.mm diff --git a/dynare++/sylv/testing/vcheck490.mm b/mex/sources/libkorder/sylv/tests/vcheck490.mm similarity index 100% rename from dynare++/sylv/testing/vcheck490.mm rename to mex/sources/libkorder/sylv/tests/vcheck490.mm diff --git a/dynare++/sylv/testing/vcheck490q.mm b/mex/sources/libkorder/sylv/tests/vcheck490q.mm similarity index 100% rename from dynare++/sylv/testing/vcheck490q.mm rename to mex/sources/libkorder/sylv/tests/vcheck490q.mm diff --git a/dynare++/tl/cc/equivalence.cc b/mex/sources/libkorder/tl/equivalence.cc similarity index 100% rename from dynare++/tl/cc/equivalence.cc rename to mex/sources/libkorder/tl/equivalence.cc diff --git a/dynare++/tl/cc/equivalence.hh b/mex/sources/libkorder/tl/equivalence.hh similarity index 100% rename from dynare++/tl/cc/equivalence.hh rename to mex/sources/libkorder/tl/equivalence.hh diff --git a/dynare++/tl/cc/fine_container.cc b/mex/sources/libkorder/tl/fine_container.cc similarity index 100% rename from dynare++/tl/cc/fine_container.cc rename to mex/sources/libkorder/tl/fine_container.cc diff --git a/dynare++/tl/cc/fine_container.hh b/mex/sources/libkorder/tl/fine_container.hh similarity index 100% rename from dynare++/tl/cc/fine_container.hh rename to mex/sources/libkorder/tl/fine_container.hh diff --git a/dynare++/tl/cc/fs_tensor.cc b/mex/sources/libkorder/tl/fs_tensor.cc similarity index 100% rename from dynare++/tl/cc/fs_tensor.cc rename to mex/sources/libkorder/tl/fs_tensor.cc diff --git a/dynare++/tl/cc/fs_tensor.hh b/mex/sources/libkorder/tl/fs_tensor.hh similarity index 100% rename from dynare++/tl/cc/fs_tensor.hh rename to mex/sources/libkorder/tl/fs_tensor.hh diff --git a/dynare++/tl/cc/gs_tensor.cc b/mex/sources/libkorder/tl/gs_tensor.cc similarity index 100% rename from dynare++/tl/cc/gs_tensor.cc rename to mex/sources/libkorder/tl/gs_tensor.cc diff --git a/dynare++/tl/cc/gs_tensor.hh b/mex/sources/libkorder/tl/gs_tensor.hh similarity index 100% rename from dynare++/tl/cc/gs_tensor.hh rename to mex/sources/libkorder/tl/gs_tensor.hh diff --git a/dynare++/tl/cc/int_sequence.cc b/mex/sources/libkorder/tl/int_sequence.cc similarity index 100% rename from dynare++/tl/cc/int_sequence.cc rename to mex/sources/libkorder/tl/int_sequence.cc diff --git a/dynare++/tl/cc/int_sequence.hh b/mex/sources/libkorder/tl/int_sequence.hh similarity index 100% rename from dynare++/tl/cc/int_sequence.hh rename to mex/sources/libkorder/tl/int_sequence.hh diff --git a/dynare++/tl/cc/kron_prod.cc b/mex/sources/libkorder/tl/kron_prod.cc similarity index 100% rename from dynare++/tl/cc/kron_prod.cc rename to mex/sources/libkorder/tl/kron_prod.cc diff --git a/dynare++/tl/cc/kron_prod.hh b/mex/sources/libkorder/tl/kron_prod.hh similarity index 100% rename from dynare++/tl/cc/kron_prod.hh rename to mex/sources/libkorder/tl/kron_prod.hh diff --git a/dynare++/tl/cc/normal_moments.cc b/mex/sources/libkorder/tl/normal_moments.cc similarity index 100% rename from dynare++/tl/cc/normal_moments.cc rename to mex/sources/libkorder/tl/normal_moments.cc diff --git a/dynare++/tl/cc/normal_moments.hh b/mex/sources/libkorder/tl/normal_moments.hh similarity index 100% rename from dynare++/tl/cc/normal_moments.hh rename to mex/sources/libkorder/tl/normal_moments.hh diff --git a/dynare++/tl/cc/permutation.cc b/mex/sources/libkorder/tl/permutation.cc similarity index 100% rename from dynare++/tl/cc/permutation.cc rename to mex/sources/libkorder/tl/permutation.cc diff --git a/dynare++/tl/cc/permutation.hh b/mex/sources/libkorder/tl/permutation.hh similarity index 100% rename from dynare++/tl/cc/permutation.hh rename to mex/sources/libkorder/tl/permutation.hh diff --git a/dynare++/tl/cc/ps_tensor.cc b/mex/sources/libkorder/tl/ps_tensor.cc similarity index 100% rename from dynare++/tl/cc/ps_tensor.cc rename to mex/sources/libkorder/tl/ps_tensor.cc diff --git a/dynare++/tl/cc/ps_tensor.hh b/mex/sources/libkorder/tl/ps_tensor.hh similarity index 100% rename from dynare++/tl/cc/ps_tensor.hh rename to mex/sources/libkorder/tl/ps_tensor.hh diff --git a/dynare++/tl/cc/pyramid_prod.cc b/mex/sources/libkorder/tl/pyramid_prod.cc similarity index 100% rename from dynare++/tl/cc/pyramid_prod.cc rename to mex/sources/libkorder/tl/pyramid_prod.cc diff --git a/dynare++/tl/cc/pyramid_prod.hh b/mex/sources/libkorder/tl/pyramid_prod.hh similarity index 100% rename from dynare++/tl/cc/pyramid_prod.hh rename to mex/sources/libkorder/tl/pyramid_prod.hh diff --git a/dynare++/tl/cc/pyramid_prod2.cc b/mex/sources/libkorder/tl/pyramid_prod2.cc similarity index 100% rename from dynare++/tl/cc/pyramid_prod2.cc rename to mex/sources/libkorder/tl/pyramid_prod2.cc diff --git a/dynare++/tl/cc/pyramid_prod2.hh b/mex/sources/libkorder/tl/pyramid_prod2.hh similarity index 100% rename from dynare++/tl/cc/pyramid_prod2.hh rename to mex/sources/libkorder/tl/pyramid_prod2.hh diff --git a/dynare++/tl/cc/rfs_tensor.cc b/mex/sources/libkorder/tl/rfs_tensor.cc similarity index 100% rename from dynare++/tl/cc/rfs_tensor.cc rename to mex/sources/libkorder/tl/rfs_tensor.cc diff --git a/dynare++/tl/cc/rfs_tensor.hh b/mex/sources/libkorder/tl/rfs_tensor.hh similarity index 100% rename from dynare++/tl/cc/rfs_tensor.hh rename to mex/sources/libkorder/tl/rfs_tensor.hh diff --git a/dynare++/tl/cc/sparse_tensor.cc b/mex/sources/libkorder/tl/sparse_tensor.cc similarity index 100% rename from dynare++/tl/cc/sparse_tensor.cc rename to mex/sources/libkorder/tl/sparse_tensor.cc diff --git a/dynare++/tl/cc/sparse_tensor.hh b/mex/sources/libkorder/tl/sparse_tensor.hh similarity index 100% rename from dynare++/tl/cc/sparse_tensor.hh rename to mex/sources/libkorder/tl/sparse_tensor.hh diff --git a/dynare++/tl/cc/stack_container.cc b/mex/sources/libkorder/tl/stack_container.cc similarity index 100% rename from dynare++/tl/cc/stack_container.cc rename to mex/sources/libkorder/tl/stack_container.cc diff --git a/dynare++/tl/cc/stack_container.hh b/mex/sources/libkorder/tl/stack_container.hh similarity index 100% rename from dynare++/tl/cc/stack_container.hh rename to mex/sources/libkorder/tl/stack_container.hh diff --git a/dynare++/tl/cc/symmetry.cc b/mex/sources/libkorder/tl/symmetry.cc similarity index 100% rename from dynare++/tl/cc/symmetry.cc rename to mex/sources/libkorder/tl/symmetry.cc diff --git a/dynare++/tl/cc/symmetry.hh b/mex/sources/libkorder/tl/symmetry.hh similarity index 100% rename from dynare++/tl/cc/symmetry.hh rename to mex/sources/libkorder/tl/symmetry.hh diff --git a/dynare++/tl/cc/t_container.cc b/mex/sources/libkorder/tl/t_container.cc similarity index 100% rename from dynare++/tl/cc/t_container.cc rename to mex/sources/libkorder/tl/t_container.cc diff --git a/dynare++/tl/cc/t_container.hh b/mex/sources/libkorder/tl/t_container.hh similarity index 100% rename from dynare++/tl/cc/t_container.hh rename to mex/sources/libkorder/tl/t_container.hh diff --git a/dynare++/tl/cc/t_polynomial.cc b/mex/sources/libkorder/tl/t_polynomial.cc similarity index 100% rename from dynare++/tl/cc/t_polynomial.cc rename to mex/sources/libkorder/tl/t_polynomial.cc diff --git a/dynare++/tl/cc/t_polynomial.hh b/mex/sources/libkorder/tl/t_polynomial.hh similarity index 100% rename from dynare++/tl/cc/t_polynomial.hh rename to mex/sources/libkorder/tl/t_polynomial.hh diff --git a/dynare++/tl/cc/tensor.cc b/mex/sources/libkorder/tl/tensor.cc similarity index 100% rename from dynare++/tl/cc/tensor.cc rename to mex/sources/libkorder/tl/tensor.cc diff --git a/dynare++/tl/cc/tensor.hh b/mex/sources/libkorder/tl/tensor.hh similarity index 100% rename from dynare++/tl/cc/tensor.hh rename to mex/sources/libkorder/tl/tensor.hh diff --git a/dynare++/tl/testing/Makefile.am b/mex/sources/libkorder/tl/tests/Makefile.am similarity index 100% rename from dynare++/tl/testing/Makefile.am rename to mex/sources/libkorder/tl/tests/Makefile.am diff --git a/dynare++/tl/testing/factory.cc b/mex/sources/libkorder/tl/tests/factory.cc similarity index 100% rename from dynare++/tl/testing/factory.cc rename to mex/sources/libkorder/tl/tests/factory.cc diff --git a/dynare++/tl/testing/factory.hh b/mex/sources/libkorder/tl/tests/factory.hh similarity index 100% rename from dynare++/tl/testing/factory.hh rename to mex/sources/libkorder/tl/tests/factory.hh diff --git a/dynare++/tl/testing/monoms.cc b/mex/sources/libkorder/tl/tests/monoms.cc similarity index 100% rename from dynare++/tl/testing/monoms.cc rename to mex/sources/libkorder/tl/tests/monoms.cc diff --git a/dynare++/tl/testing/monoms.hh b/mex/sources/libkorder/tl/tests/monoms.hh similarity index 100% rename from dynare++/tl/testing/monoms.hh rename to mex/sources/libkorder/tl/tests/monoms.hh diff --git a/dynare++/tl/testing/tests.cc b/mex/sources/libkorder/tl/tests/tests.cc similarity index 100% rename from dynare++/tl/testing/tests.cc rename to mex/sources/libkorder/tl/tests/tests.cc diff --git a/dynare++/tl/cc/tl_exception.hh b/mex/sources/libkorder/tl/tl_exception.hh similarity index 100% rename from dynare++/tl/cc/tl_exception.hh rename to mex/sources/libkorder/tl/tl_exception.hh diff --git a/dynare++/tl/cc/tl_static.cc b/mex/sources/libkorder/tl/tl_static.cc similarity index 100% rename from dynare++/tl/cc/tl_static.cc rename to mex/sources/libkorder/tl/tl_static.cc diff --git a/dynare++/tl/cc/tl_static.hh b/mex/sources/libkorder/tl/tl_static.hh similarity index 100% rename from dynare++/tl/cc/tl_static.hh rename to mex/sources/libkorder/tl/tl_static.hh diff --git a/dynare++/tl/cc/twod_matrix.cc b/mex/sources/libkorder/tl/twod_matrix.cc similarity index 100% rename from dynare++/tl/cc/twod_matrix.cc rename to mex/sources/libkorder/tl/twod_matrix.cc diff --git a/dynare++/tl/cc/twod_matrix.hh b/mex/sources/libkorder/tl/twod_matrix.hh similarity index 100% rename from dynare++/tl/cc/twod_matrix.hh rename to mex/sources/libkorder/tl/twod_matrix.hh diff --git a/dynare++/src/dynare_exception.hh b/mex/sources/libkorder/utils/dynare_exception.hh similarity index 100% rename from dynare++/src/dynare_exception.hh rename to mex/sources/libkorder/utils/dynare_exception.hh diff --git a/dynare++/utils/cc/exception.hh b/mex/sources/libkorder/utils/exception.hh similarity index 100% rename from dynare++/utils/cc/exception.hh rename to mex/sources/libkorder/utils/exception.hh diff --git a/dynare++/utils/cc/int_power.cc b/mex/sources/libkorder/utils/int_power.cc similarity index 100% rename from dynare++/utils/cc/int_power.cc rename to mex/sources/libkorder/utils/int_power.cc diff --git a/dynare++/utils/cc/int_power.hh b/mex/sources/libkorder/utils/int_power.hh similarity index 100% rename from dynare++/utils/cc/int_power.hh rename to mex/sources/libkorder/utils/int_power.hh diff --git a/dynare++/src/nlsolve.cc b/mex/sources/libkorder/utils/nlsolve.cc similarity index 100% rename from dynare++/src/nlsolve.cc rename to mex/sources/libkorder/utils/nlsolve.cc diff --git a/dynare++/src/nlsolve.hh b/mex/sources/libkorder/utils/nlsolve.hh similarity index 100% rename from dynare++/src/nlsolve.hh rename to mex/sources/libkorder/utils/nlsolve.hh diff --git a/dynare++/utils/cc/pascal_triangle.cc b/mex/sources/libkorder/utils/pascal_triangle.cc similarity index 100% rename from dynare++/utils/cc/pascal_triangle.cc rename to mex/sources/libkorder/utils/pascal_triangle.cc diff --git a/dynare++/utils/cc/pascal_triangle.hh b/mex/sources/libkorder/utils/pascal_triangle.hh similarity index 100% rename from dynare++/utils/cc/pascal_triangle.hh rename to mex/sources/libkorder/utils/pascal_triangle.hh diff --git a/dynare++/utils/cc/sthread.cc b/mex/sources/libkorder/utils/sthread.cc similarity index 100% rename from dynare++/utils/cc/sthread.cc rename to mex/sources/libkorder/utils/sthread.cc diff --git a/dynare++/utils/cc/sthread.hh b/mex/sources/libkorder/utils/sthread.hh similarity index 100% rename from dynare++/utils/cc/sthread.hh rename to mex/sources/libkorder/utils/sthread.hh diff --git a/windows/dynare.nsi b/windows/dynare.nsi index bf297bd26c2850a5f978c1ebe68cbd1b2084f4d2..a9f8d9b0b1f128c1ae6bc84343670e34aa3f45d3 100644 --- a/windows/dynare.nsi +++ b/windows/dynare.nsi @@ -112,7 +112,7 @@ SectionEnd Section "Documentation and examples" SetOutPath $INSTDIR\doc - File ..\doc\manual\build\latex\dynare-manual.pdf ..\doc\guide.pdf ..\doc\bvar-a-la-sims.pdf ..\doc\dr.pdf ..\preprocessor\doc\macroprocessor\macroprocessor.pdf ..\preprocessor\doc\preprocessor\preprocessor.pdf ..\doc\parallel\parallel.pdf ..\doc\gsa\gsa.pdf ..\doc\dseries-and-reporting\dseriesReporting.pdf + File ..\doc\manual\build\latex\dynare-manual.pdf ..\doc\guide.pdf ..\doc\bvar-a-la-sims.pdf ..\doc\dr.pdf ..\doc\sylvester.pdf ..\doc\tl.pdf ..\preprocessor\doc\macroprocessor\macroprocessor.pdf ..\preprocessor\doc\preprocessor\preprocessor.pdf ..\doc\parallel\parallel.pdf ..\doc\gsa\gsa.pdf ..\doc\dseries-and-reporting\dseriesReporting.pdf SetOutPath $INSTDIR\doc\dynare-manual.html File /r ..\doc\manual\build\html\*