Commit Graph

332 Commits (74ef3457b4805099ee9885b34173a0d0fd6aca61)

Author SHA1 Message Date
Sébastien Villemot 8496979375
Block decomposition: remove useless “y” output for static/dynamic files of solved blocks 2020-06-16 10:38:16 +02:00
Sébastien Villemot ad583adcd4
Block decomposition: for evaluate blocks, move the iteration loop outside the dynamic file 2020-06-15 18:13:17 +02:00
Sébastien Villemot f022c0e16e
Block decomposition: remove duplicate “periods” arg. to dynamic file of complete two-boundaries blocks 2020-06-15 16:54:11 +02:00
Sébastien Villemot b402e35683
In the driver file, provide mapping between model local variables and indices in the temporary terms vector
The structures are M_.model_local_variables_{dynamic,static}_tt_idxs.

Ref. dynare#1722
2020-06-05 17:12:15 +02:00
Sébastien Villemot 90b9b6a1e4
JSON output: write model local variables in parsed model (modfile.json)
Ref. dynare#1723
2020-06-05 16:10:38 +02:00
Sébastien Villemot 050f1cdd74
Block decomposition: remove unused 2nd and 3rd derivatives in output of dynamic functions 2020-06-03 16:59:04 +02:00
Sébastien Villemot f0c8a14551
Block decomposition: no longer compute deterministic simulation from dynamic.m file 2020-06-02 17:42:00 +02:00
Sébastien Villemot 2caad3ee84
Block decomposition: simplify DynamicModel::writeDynamicBlockMFile() 2020-05-29 16:48:38 +02:00
Sébastien Villemot 7b11898689
use_dll: merge the two generated C source files into a single one
Also, do various other cosmetic/simplification changes.
2020-05-29 16:12:01 +02:00
Sébastien Villemot 3ca1914e03
Block decomposition: fix simulation of blocks of type "evaluate backward" (without bytecode)
Ref. dynare#1727
2020-05-26 17:00:21 +02:00
Sébastien Villemot faa6666abe
Block decomposition: no longer use global variables for temporary terms in the dynamic M-file
Rather use a single vector as in non-block mode.

By the way, change the order of output arguments in static functions, to be
closer to the dynamic ones.
2020-05-26 16:21:11 +02:00
Sébastien Villemot 04b7d4386d
Block decomposition: no longer use global variables for temporary terms in the static M-file
Rather use a single vector as in non-block mode.
2020-05-25 18:35:36 +02:00
Sébastien Villemot a5abbae46a
use_dll: remove workaround for char16_t type
Should no longer be needed now that the minimal MATLAB version is R2014a.
2020-05-25 16:06:17 +02:00
Sébastien Villemot 7b1a77ca47
Block decomposition: use logical values for some inputs to solve_{one_boundary,two_boundaries} 2020-05-25 15:12:43 +02:00
Sébastien Villemot a6d9ba6e55
Rename EquationType::evaluate_s to evaluateRenormalized, for clarity 2020-05-20 11:49:32 +02:00
Sébastien Villemot c6a17913b4
Rename {Static,Dynamic}Model::writeOutput() to ::writeDriverOutput() for clarity 2020-05-20 11:44:40 +02:00
Sébastien Villemot becc433d56
Rename byte_code to bytecode for consistency with user option name 2020-05-20 11:39:59 +02:00
Sébastien Villemot 96657b4974
Block decomposition: refactor code that writes the block structure to the driver file 2020-05-20 11:35:14 +02:00
Sébastien Villemot 2944484442
Bytecode: rename output methods for better consistency 2020-05-19 17:45:33 +02:00
Sébastien Villemot 1d838e96ff
Block decomposition: simplify routines for writing output dynamic/static M files 2020-05-19 17:33:58 +02:00
Sébastien Villemot a2bea00fee
Block decomposition: another fix related to temporary terms refactoring
Temporary terms need to be computed per equation (as was done previously), and
not simply per block.

It’s necessary to track temporary terms per equation, because some equations
are evaluated instead of solved, and an equation E1 may depend on the value of
an endogenous Y computed by a previously evaluated equation E2; in this case,
if some temporary term TT of equation E2 contains Y, then TT needs to be
computed after E1, but before E2.
2020-05-13 16:58:19 +02:00
Sébastien Villemot c9388da649
Bytecode: still another fix for temporary terms 2020-05-13 15:16:38 +02:00
Sébastien Villemot 2e6bc7ecaa
Bytecode: fix handling of temporary terms
They were broken by 49036f166d
2020-05-13 12:53:47 +02:00
Sébastien Villemot 49036f166d
Block decomposition: refactor code for computing temporary terms
In particular, in dynamic models, temporary terms are now computed for
derivatives w.r.t. exogenous, and also w.r.t. endogenous variables that do not
belong to the block.
2020-05-12 18:39:13 +02:00
Sébastien Villemot 928aa977b6
Block decomposition: replace expr_t by BinaryOpNode * in a couple of places 2020-05-07 15:24:35 +02:00
Sébastien Villemot c699d57308
Block decomposition: no longer compute static Jacobian, it’s not used
Also remove a message about elements below the cutoff that was no longer
correct (elements below the cutoff have no impact on the incidence matrix
outside of normalization).
2020-05-06 18:11:11 +02:00
Sébastien Villemot a1b37288f9
Block decomposition: do not write unnecessary zeros in dynamic Jacobian
Also do cosmetic change in the corresponding code for static Jacobian.
2020-05-06 14:22:04 +02:00
Sébastien Villemot 9f361e9e37
Block decomposition: simplify code for ordering dynamic Jacobian columns 2020-05-06 14:21:24 +02:00
Sébastien Villemot 38ccd5e0cf
Block decomposition: remove unneeded code for bytecode 2020-05-05 17:15:08 +02:00
Sébastien Villemot 5f22f00436
PAC models: handle PAC data in DynamicModel copy constructor and assignment operator 2020-05-05 16:34:51 +02:00
Sébastien Villemot 4f453320d1
Block decomposition: remove unneeded code for exogenous 2020-05-05 16:17:22 +02:00
Sébastien Villemot cb61ee8506
Block decomposition: make structures storing derivatives w.r.t. other endo/exo symmetric with those for endos belonging to the block 2020-04-30 18:24:24 +02:00
Sébastien Villemot b1a739c56a
DynamicModel: add missing members in copy constructor/assignment operator 2020-04-30 14:57:50 +02:00
Sébastien Villemot a8c2defe26
Block decomposition: compute simulation types into separate function; prologue and epilogue are no longer class members
By the way, remove the BlockType stuff which was purely informative (and it’s
not worth carrying over prologue and epilogue information just for that).
2020-04-30 12:48:16 +02:00
Sébastien Villemot 26fc71ffa7
Block decomposition: store max lead/lag of all variables in the “blocks” structure
By the way, regroup all code that computes the dynamic structure of a block
into a single function.
2020-04-30 12:03:14 +02:00
Sébastien Villemot 4948adf2cd
Block decomposition: remove unused data structure 2020-04-29 17:47:48 +02:00
Sébastien Villemot f39c687d85
Block decomposition: store mapping between endos/eqs and their block
Previously this computation was done at several places.
2020-04-29 17:42:46 +02:00
Sébastien Villemot 39407083be
Block decomposition: ensure that the cutoff option only impacts normalization
Previously, the cutoff option would also impact the block decomposition itself,
since it would had an influence on the incidence matrix used for computing the
blocks and their derivatives.

The problem is that, in the general case, it’s quite possible that an element
of the numerical Jacobian be zero at the evaluation point, while being quite
different from zero along the simulation path. A typical example is an
expression of the type x*y, where y is an endogenous and x is an exogenous not
present in the initval block (and hence initialized to zero).
2020-04-29 12:41:39 +02:00
Sébastien Villemot 470cb5fcb0
Block decomposition: remove mostly unused structure ModelTree::derivative_endo
It has been superseded by ModelTree::blocks_derivatives.

By the way, fix the initial number of non-zero elements in sparse Jacobian.

Also avoid computing suboptimal temporary terms.
2020-04-28 14:12:29 +02:00
Sébastien Villemot 2e136cae56
Block decomposition: simplify computation of block derivatives
— use a std::map for storing block derivatives
— remove redundant ModelTree::first_chain_rule_derivatives structure
— remove unused codepaths in StaticModel
— DynamicModel: simplify code that determines the type of derivatives in a
  block. We now use a slightly different categorization.
— by the way, fix the max lead/lag information for blocks that are obtained via
  merging. A workaround was previously implemented in
  DynamicModel::get_Derivative(), but it is no longer needed with this fix.
2020-04-28 12:26:51 +02:00
Sébastien Villemot 5ee45f5bd4
Block decomposition: remove helpers that are no longer needed since data structure are cleaner
Add a new helper for getting the number of recursive variables in a block.
2020-04-23 16:31:57 +02:00
Sébastien Villemot 118ceab85b
Block decomposition: reorganize data structures storing block information 2020-04-21 18:25:33 +02:00
Sébastien Villemot 8eafd9ab4f
Block decomposition: various refactorings 2020-04-17 19:23:52 +02:00
Sébastien Villemot 7327fb9f17
Block decomposition: give more explicit names to ModelTree::{inv_,}{equation,variable}_reordered 2020-04-17 15:09:22 +02:00
Sébastien Villemot 4e819f09b2
Block decomposition: various refactorings 2020-04-15 17:56:28 +02:00
Sébastien Villemot e88c05e3b8
Change prototype of DataTree::AddEqual()
This permits some simplifications.
2020-04-02 19:19:57 +02:00
Sébastien Villemot 4d30f17e0b
Block decomposition: move collectFirstOrderDerivativesEndogenous in ModelTree
By the way, use camel case for the function name.
2020-03-30 14:51:53 +02:00
Sébastien Villemot ad48697abe
Block decomposition without bytecode: fix call to solve_one_boundary
Ref. dynare#1717
2020-03-30 12:44:01 +02:00
Sébastien Villemot 50776a766a
Remove the unsignedness of many integer variables and function arguments
This was only adding unneeded complexity, for no clear reason (we’re very far
from reaching 2³¹ equations, and if we wanted to support models that large, it
would be better to use long integers to avoid being limited to 2³²).
2020-03-24 18:28:03 +01:00
Sébastien Villemot ce1cbb3e52
Block decomposition: turn EquationType into an enum class 2020-03-20 18:00:56 +01:00
Sébastien Villemot 8b4d046f9f
Block decomposition: turn BlockSimulationType into an enum class 2020-03-20 17:31:14 +01:00
Sébastien Villemot f1061e8df1
Block decomposition: turn BlockType into an enum class 2020-03-20 16:38:43 +01:00
Sébastien Villemot fcef9cf8b9
Block decomposition: further streamlining of function prototypes 2020-03-20 15:23:23 +01:00
Sébastien Villemot bd6eee93df
Block decomposition: refactor the prototypes of various functions
— return output arguments on the left-hand side
— do not pass class members as input/output arguments

By the way, fix a (benign) vector allocation bug in
{Static,Dynamic}Model::computeChainRuleJacobian().
2020-03-19 17:47:12 +01:00
Sébastien Villemot 76c2e87c3b
Block decomposition: factorize data structures between StaticModel and DynamicModel 2020-03-17 18:58:34 +01:00
Michel Juillard d668590ff8 modify Julia output for mapping eqidx 2020-03-17 09:27:10 +01:00
Sébastien Villemot 9ff10f482a
Fix typos (thanks lintian) 2020-02-25 15:20:33 +01:00
Houtan Bastani 7371558321
rework equation tags
Create new EquationTags class to simplify use of equation tags throughout the code and avoid repeated code

issue #38
2020-02-21 17:49:38 +01:00
Houtan Bastani 14be6bad00
occbin: support occbin tags in equation tags, add occbin_likelihood and occbin_smoother as options to estimation 2020-02-11 14:24:06 +01:00
Houtan Bastani 3fec11b183
code simplifications 2020-01-30 14:55:39 +01:00
Sébastien Villemot a8b7bd31c5
Fix bug introduced in use_dll mode in 23a08a3662
Ref. #40
2020-01-20 18:33:31 +01:00
Sébastien Villemot 23a08a3662
Ensure that dynamic model files contains all the derivatives that have been computed
Previously, there could be a discrepancy if the order mandated by
“identification” was less that the one mandated by “stoch_simul”.

Ref. #40
2020-01-20 17:22:32 +01:00
Sébastien Villemot 4e2538a2a2
Ensure original tags and line numbers are preserved with ramsey_model
In particular, introduce a method for clearing all equations, so that tags and
line numbers are also cleared.

Ref. dynare#1685
2020-01-06 18:26:35 +01:00
Sébastien Villemot e2d5a83592
Global reindentation 2019-12-20 16:59:30 +01:00
Sébastien Villemot 031c0cff5f
Various code simplifications and modernizations 2019-12-16 19:42:59 +01:00
Sébastien Villemot 97fa005b33
Use 1-based indexing in M_.nonzero_hessian_eqs 2019-12-13 22:31:49 +01:00
Sébastien Villemot 141cff0761
New field M_.endo_trends
For each endogenous variable, gives the deflator and the growth factor (as well
as the “log” versions).

Ref. dynare#1648
2019-12-13 18:02:37 +01:00
Sébastien Villemot 2af26ee2c2
Ramsey: use information from transformed model for filling M_.nonzero_hessian_eqs
Since commit 9c9e8f816f, it’s the information
from the original model which was in this field, which is not what is expected.

By the way, do not output this field (and the related M_.hessian_eq_zero) when
the Hessian is not computed by the preprocessor (i.e. in practice for perfect
foresight), since they would otherwise contain incorrect information.

Ref. dynare#1681
2019-12-13 18:02:35 +01:00
Houtan Bastani 5430bb4bc6
simplify for statement 2019-12-11 16:21:18 +01:00
Sébastien Villemot 23ff36a0dd
Systematically compute recursive ordering of auxiliary equations
Auxiliary equations appearing in set_auxiliary_variables.m and
dynamic_set_auxiliary_series.m need to appear in recursive ordering, since
those files are used for sequential evaluation.

Previously, the recursive ordering was guaranteed by a set of ad hoc rules and
workarounds, but that would not cover certain edge cases.

With this commit, the recursive ordering is systematically computed, using a
topological sort on the directed acyclic graph whose vertices are auxiliary
equations and whose edges are dependency relationships.

Closes: #22
2019-12-03 14:26:13 +01:00
Houtan Bastani 0ff7a9d2ab
introduce command line options: `exclude_eqs` and `include_eqs`
Allows for the inclusion/exclusion of a set of equations, specified either on the command line or in a text file.

If the equation has a single endogenous variable on the LHS, then the equation is moved. If not, if the equation has an `endogenous` tag then that variable is removed along with this equation. If not, then an error is thrown.

As a command line argument, `exclude_eqs` can take the form (same syntax for `include_eqs`):
* `exclude_eqs=eq1 to remove all equations declared as `[name=eq1]`
* `exclude_eqs=[eq 1, eq 2]` to remove all equations declared as `[name=eq 1]` or `[name=eq 2]`
* `exclude_eqs=[tagname=X]` to remove all equations declared as `[tagname=X]`
* `exclude_eqs=[tagname=(X, Y)]` to remove all equations declared as `[tagname=X]` or `[tagname=Y]`

When declared in a file, the file should be of the form:
```
eq 1
eq 2
```
to remove all equations declared as `[name=eq 1]` or `[name=eq 2]`.

It should be of the form:
```
tagname=
X
Y
```
to remove all equations declared as `[tagname=X]` or `[tagname=Y]`.
2019-11-26 14:16:00 +01:00
Sébastien Villemot 5a5817b4fe
Improvements to the test for balanced growth path
— Raise the default tolerance for cross-derivatives to 1e-6, to reduce the
  number of false positives

— New option “balanced_growth_test_tol” to the “model” block for changing that
  tolerance

— Turn back test failures into errors. Since there is now an option for
  controlling the tolerance, the user always has the possibility of making the
  test pass.

Closes: dynare#1389
2019-11-14 17:55:17 +01:00
Houtan Bastani 0f0299bc1c
fix to allow for diffs of unary ops to go through variable mapping 2019-11-07 16:15:49 -05:00
Houtan Bastani 0bb233d291
fix bug causing auxiliary variables for pac growth parameters not to contain their original symbol id 2019-11-07 14:17:49 -05:00
Dóra Kocsis 7a78593df4 introduce variableMapping, default equation name tags in M_ and JSON output 2019-10-30 16:30:51 +01:00
Houtan Bastani 217dadabbd
Use `if` statements with initializers allowed by C++17 2019-10-29 11:20:13 +01:00
Sébastien Villemot ecdca502aa
Modernization: stop using make_pair() and make_tuple()
In many cases, they can be replaced by the curly braces syntax.

Otherwise, we can now use the pair() and tuple() constructors, without the need
to specify template parameters, thanks to class template argument
deduction (new in C++17).
2019-10-24 10:49:13 +02:00
Sébastien Villemot 2a127b1f23
VAR/TCM models: use lag-equivalence relationship to compute maximum lags
This is made possible by the getLagEquivalenceClass() method introduced in the
previous commit.

Previously, the static version of the LHS expressions was used.

As a consequence, drop ModFile::diff_static_model, now useless.
2019-10-22 16:04:24 +02:00
Sébastien Villemot 8a83e08e79
Fix bug with diff or unary ops that have same static representation
Previously, for testing whether two diff() expressions or two unary ops were
the lead/lag of each other, the preprocessor would test whether they have the
same static representation. This is ok for simple expressions (e.g.
diff(x(-1))), but not for more complex ones (e.g. diff(x-y) and diff(x(-1)-y)
should not be given the same auxiliary variable).

This commit fixes this by properly constructing the equivalence relationship
and choosing a representative within each equivalence class. See the comments
above lag_equivalence_table_t in ExprNode.hh for more details.

Closes #27
2019-10-22 15:01:06 +02:00
Sébastien Villemot d38ac48cfa
Create set_auxiliary_series routine in use_dll, block/bytecode and julia modes
Closes #34
2019-10-17 15:03:26 +02:00
Houtan Bastani fac9e4436c
fix bug in `fast` option: printing temporary terms hid changes in model when the temporary term changed as the temporary terms themselves were not printed. closes dynare#1661
Furthermore, modifications to model local variables were not taken into account.

To fix, take checksum of model local variables, temporary terms, and equations

Also, use existing functions to print these to a stringstream instead of repeating print functionality in this function
2019-10-07 18:55:20 +02:00
Houtan Bastani 6e92f79c13
simplify isChecksumMatching, move to filesystem::path 2019-10-07 17:43:45 +02:00
Houtan Bastani 6191c69d74
move to hash algorithm defined since C++11 for calculating checksums. dynare#1661 2019-10-07 17:43:16 +02:00
Sébastien Villemot b0ac4a4e51
Cosmetic change 2019-09-24 18:47:43 +02:00
Houtan Bastani 92ad5aad2c
Revert "add info about max endo/exo lag by variable. closes dynare#1596"
This reverts commit 7827d2e04d.
2019-09-24 14:03:38 +02:00
Sébastien Villemot 2c6fa34a1f
C++17: use structured bindings instead of std::tie whenever possible 2019-09-11 16:40:19 +02:00
Houtan Bastani 9a5ad17349
suppress sign comparison warnings when compiling with g++-9 2019-09-11 16:25:10 +02:00
Sébastien Villemot 0c755460b1
Use std::filesystem instead of boost::filesystem
Note that there is no equivalent of boost::filesystem::unique_path(), so I
implemented ModFile::unique_path() which does something similar.
2019-09-11 14:47:48 +02:00
Houtan Bastani 7827d2e04d
add info about max endo/exo lag by variable. closes dynare#1596 2019-09-09 14:29:22 +02:00
Sébastien Villemot db6d4fb0cd
Support identification(order=3)
In that case, the preprocessor outputs g4 (4th derivatives of model) and
g3p (1st derivs of g3 w.r.t. parameters).

Ref #10
2019-08-22 17:02:40 +02:00
Sébastien Villemot 1491b2d225
Give better names to ostringstream variables storing derivs w.r.t. params. 2019-08-22 17:02:39 +02:00
Sébastien Villemot 4594fdd0fd
More comment improvements in relation to diff operator expansion/substitution 2019-08-20 18:22:02 +02:00
Sébastien Villemot 3941278832
Add more comments in routines for aux vars for unary ops / diff operators
By the way, do some small code simplifications.
2019-08-19 18:27:57 +02:00
Sébastien Villemot 8e9f6e4c57
Improve some function prototypes for better distinction between input and output arguments 2019-08-19 18:27:57 +02:00
Sébastien Villemot 0988a1f755
Generated LaTeX files are now under <basename>/latex/ 2019-07-11 17:33:53 +02:00
Sébastien Villemot 271a579808
Remove symmetric elements in 3rd derivatives 2019-06-17 15:28:33 +02:00
Sébastien Villemot 51beb9c2ef
New M_.has_external_function field 2019-05-15 15:02:36 +02:00
Sébastien Villemot 840b5f4f7f
Bugfix for M_.dynamic_tmp_nbr: first element was not including temp. terms for model local vars 2019-05-14 17:08:38 +02:00
Houtan Bastani a0f74f5c16
pac growth: allow linear combination 2019-05-14 12:33:59 +02:00
Sébastien Villemot 40ef954802
Add new dynamic_g1_nz.m generated file, for perfect_foresight_stacked_solver DLL 2019-05-03 19:25:23 +02:00