Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic monte carlo simulation #1296

Merged
merged 30 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c9e06ba
basic implementation of generic sim_one_period. see #1295
sbenthall Jun 30, 2023
74382c3
draw_shocks and docs
sbenthall Jul 20, 2023
f6a672d
automated test for draw_shock
sbenthall Jul 20, 2023
0041d2c
AgentTypeMonteCarloSimulator class draft
sbenthall Jul 21, 2023
3004643
generic draw_shocks distinguishes between time-varying, non-time vary…
sbenthall Jul 24, 2023
53a7f65
Working test for AgentTypeMonteCarloSimulator.
sbenthall Jul 24, 2023
e8799da
var value updates working for Python 3.8 now
sbenthall Jul 24, 2023
98ca16f
tighter make_shock_history, with test
sbenthall Jul 26, 2023
ddaf185
fixing handling of saved newborn inits
sbenthall Jul 26, 2023
dde1e88
removing warning for very unlikely scenario (T_sim set by default)
sbenthall Jul 26, 2023
4ea021a
remove sim_death from MonteCarloSimulator, just use 'live' state
sbenthall Jul 27, 2023
411703a
use age-varying parameters in MonteCarloSimulator
sbenthall Aug 10, 2023
ea3e7b1
age-varying decision rules in generic monte carlo
sbenthall Aug 28, 2023
e858d2d
Merge branch 'master' into i1295
sbenthall Oct 9, 2023
ce1fe31
updating CHANGELOG
sbenthall Oct 9, 2023
4c0850c
use HARK.model classes in HARK.simulate functions
sbenthall Oct 9, 2023
5ef3a19
adjust PF python model so you only need to initialize p, not y
sbenthall Oct 9, 2023
2cc60bf
when creating new data arrays for variables NOW in generic monte carl…
sbenthall Oct 9, 2023
b95b0f4
adding example notebook for comparing HARK PF and Generic Monte Carlo
sbenthall Oct 9, 2023
0c52963
adding python model configuration for normalized perfect foresight; g…
sbenthall Oct 11, 2023
799de9a
put loading initial values to newborns with read_shocks into sim_birth
sbenthall Oct 17, 2023
2d212ae
track 'who_dies' to t-1 spot in history for HARK 0.13 core; generic m…
sbenthall Nov 13, 2023
e7a6981
Merge branch 'master' into i1295
sbenthall Nov 13, 2023
1bd53cf
black
sbenthall Nov 13, 2023
c4feeb3
Update core.py -- fixing bad merge
sbenthall Nov 13, 2023
1a33be6
pre-commit fixes
sbenthall Nov 13, 2023
62e8d5f
ruff format the example notebook
sbenthall Nov 13, 2023
4f4b9ba
improving documentation for Generic Monte Carlo
sbenthall Nov 27, 2023
cd4c05a
Merge branch 'master' into i1295
sbenthall Nov 27, 2023
a329473
adding model.rst file to docs
sbenthall Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Documentation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Release Date: TBD

- Adds `HARK.core.AgentPopulation` class to represent a population of agents with ex-ante heterogeneous parametrizations as distributions. [#1237](https://github.com/econ-ark/HARK/pull/1237)
- Adds `HARK.core.Parameters` class to represent a collection of time varying and time invariant parameters in a model. [#1240](https://github.com/econ-ark/HARK/pull/1240)
- Adds `HARK.simulation.monte_carlo` module for generic Monte Carlo simulation functions using Python model configurations. [1296](https://github.com/econ-ark/HARK/pull/1296)

### Minor Changes

Expand All @@ -26,6 +27,8 @@ Release Date: TBD
- Fixes bug that prevented risky-asset consumer types from working with time-varying interest rates `Rfree`. [1343](https://github.com/econ-ark/HARK/pull/1343)
- Overhauls and expands condition checking for the ConsIndShock model [#1294](https://github.com/econ-ark/HARK/pull/1294). Condition values and a description of their interpretation is stored in the bilt dictionary of IndShockConsumerType.
- Creates a `models/` directory with Python model configurations for perfect foresight and Fisher 2-period models. [1347](https://github.com/econ-ark/HARK/pull/1347)
- Fixes bug in AgentType simulations where 'who_dies' for period t was being recorded in period t-1in the history Carlo simulation functions using Python model configurations.[1296](https://github.com/econ-ark/HARK/pull/1296)
- Removes unused `simulation.py` .[1296](https://github.com/econ-ark/HARK/pull/1296)

### 0.13.0

Expand Down
1 change: 1 addition & 0 deletions Documentation/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ API Reference
tools/frame
tools/helpers
tools/interpolation
tools/model
tools/numba_tools
tools/parallel
tools/rewards
Expand Down
7 changes: 7 additions & 0 deletions Documentation/reference/tools/model.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Model
-------------

.. automodule:: HARK.model
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion Documentation/reference/tools/simulation.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation
------------

.. automodule:: HARK.simulation
.. automodule:: HARK.simulation.monte_carlo
:members:
:undoc-members:
:show-inheritance:
10 changes: 9 additions & 1 deletion HARK/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
problem by finding a general equilibrium dynamic rule.
"""
# Set logging and define basic functions
# Set logging and define basic functions
import logging
import sys
from collections import defaultdict, namedtuple
Expand Down Expand Up @@ -1061,7 +1062,14 @@
elif var_name in self.controls:
self.history[var_name][self.t_sim, :] = self.controls[var_name]
else:
self.history[var_name][self.t_sim, :] = getattr(self, var_name)
if var_name == "who_dies" and self.t_sim > 1:
self.history[var_name][self.t_sim - 1, :] = getattr(

Check warning on line 1066 in HARK/core.py

View check run for this annotation

Codecov / codecov/patch

HARK/core.py#L1066

Added line #L1066 was not covered by tests
self, var_name
)
else:
self.history[var_name][self.t_sim, :] = getattr(
self, var_name
)
self.t_sim += 1

return self.history
Expand Down
20 changes: 19 additions & 1 deletion HARK/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@
Tools for crafting models.
"""

from HARK.distribution import Distribution


class Aggregate:
"""
Used to designate a shock as an aggregate shock.
If so designated, draws from the shock will be scalar rather
than array valued.
"""

def __init__(self, dist: Distribution):
self.dist = dist


class Control:
"""
Should go in different model support module.
Used to designate a variabel that is a control variable.

Parameters
----------
args : list of str
The labels of the variables that are in the information set of this control.
"""

def __init__(self, args):
Expand Down
Empty file added HARK/models/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion HARK/models/perfect_foresight.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"BoroCnstArt": None,
},
"dynamics": {
"y": lambda p: p,
"m": lambda Rfree, a, y: Rfree * a + y,
"c": Control(["m"]),
"y": lambda p: p,
"p": lambda PermGroFac, p: PermGroFac * p,
"a": lambda m, c: m - c,
},
Expand Down
31 changes: 31 additions & 0 deletions HARK/models/perfect_foresight_normalized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from HARK.distribution import Bernoulli
from HARK.model import Control

Check warning on line 2 in HARK/models/perfect_foresight_normalized.py

View check run for this annotation

Codecov / codecov/patch

HARK/models/perfect_foresight_normalized.py#L1-L2

Added lines #L1 - L2 were not covered by tests

# This way of distributing parameters across the scope is clunky
# Can be handled better if parsed from a YAML file, probably
# But it would be better to have a more graceful Python version as well.
CRRA = (2.0,)
LivPrb = 0.98

Check warning on line 8 in HARK/models/perfect_foresight_normalized.py

View check run for this annotation

Codecov / codecov/patch

HARK/models/perfect_foresight_normalized.py#L7-L8

Added lines #L7 - L8 were not covered by tests

model = {

Check warning on line 10 in HARK/models/perfect_foresight_normalized.py

View check run for this annotation

Codecov / codecov/patch

HARK/models/perfect_foresight_normalized.py#L10

Added line #L10 was not covered by tests
"shocks": {
"live": Bernoulli(p=LivPrb),
},
"parameters": {
"DiscFac": 0.96,
"CRRA": CRRA,
"Rfree": 1.03,
"LivPrb": LivPrb,
"PermGroFac": 1.01,
"BoroCnstArt": None,
},
"dynamics": {
"p": lambda PermGroFac, p: PermGroFac * p,
"r_eff": lambda Rfree, PermGroFac: Rfree / PermGroFac,
"b_nrm": lambda r_eff, a_nrm: r_eff * a_nrm,
"m_nrm": lambda b_nrm: b_nrm + 1,
"c_nrm": Control(["m_nrm"]),
"a_nrm": lambda m_nrm, c_nrm: m_nrm - c_nrm,
},
"reward": {"u": lambda c: c ** (1 - CRRA) / (1 - CRRA)},
}
7 changes: 0 additions & 7 deletions HARK/simulation.py

This file was deleted.

Empty file added HARK/simulation/__init__.py
Empty file.
Loading