-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example model with very large state-choice space (#54)
- Loading branch information
Showing
14 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ dependencies: | |
- pre-commit | ||
- pydot | ||
- snakeviz | ||
- memory_profiler | ||
|
||
# Documentation | ||
- sphinx | ||
|
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"""Define example model specifications.""" | ||
|
||
import jax.numpy as jnp | ||
|
||
RETIREMENT_AGE = 65 | ||
N_CHOICE_GRID_POINTS = 200 | ||
N_STATE_GRID_POINTS = 100 | ||
|
||
|
||
def phelps_deaton_utility(consumption, working, health, sport, delta): | ||
return jnp.log(consumption) - (delta - health) * working - sport | ||
|
||
|
||
def working(retirement): | ||
return 1 - retirement | ||
|
||
|
||
def next_wealth_with_shock( | ||
wealth, | ||
consumption, | ||
working, | ||
wage, | ||
wage_shock, | ||
interest_rate, | ||
): | ||
return interest_rate * (wealth - consumption) + wage * wage_shock * working | ||
|
||
|
||
def next_wealth(wealth, consumption, working, wage, interest_rate): | ||
return (1 + interest_rate) * (wealth - consumption) + wage * working | ||
|
||
|
||
def next_health(health, sport, working): | ||
return health * (1 + sport - working / 2) | ||
|
||
|
||
def consumption_constraint(consumption, wealth): | ||
return consumption <= wealth | ||
|
||
|
||
def wage(age): | ||
return 1 + 0.1 * age | ||
|
||
|
||
def age(_period): | ||
return _period + 18 | ||
|
||
|
||
PHELPS_DEATON = { | ||
"functions": { | ||
"utility": phelps_deaton_utility, | ||
"next_wealth": next_wealth, | ||
"consumption_constraint": consumption_constraint, | ||
"working": working, | ||
"wage": wage, | ||
"age": age, | ||
"next_health": next_health, | ||
}, | ||
"choices": { | ||
"retirement": {"options": [0, 1]}, | ||
"consumption": { | ||
"grid_type": "linspace", | ||
"start": 1, | ||
"stop": 100, | ||
"n_points": N_CHOICE_GRID_POINTS, | ||
}, | ||
"sport": { | ||
"grid_type": "linspace", | ||
"start": 0, | ||
"stop": 1, | ||
"n_points": N_CHOICE_GRID_POINTS, | ||
}, | ||
}, | ||
"states": { | ||
"wealth": { | ||
"grid_type": "linspace", | ||
"start": 1, | ||
"stop": 100, | ||
"n_points": N_STATE_GRID_POINTS, | ||
}, | ||
"health": { | ||
"grid_type": "linspace", | ||
"start": 0, | ||
"stop": 1, | ||
"n_points": N_STATE_GRID_POINTS, | ||
}, | ||
}, | ||
"n_periods": RETIREMENT_AGE - 18, | ||
} | ||
|
||
PARAMS = { | ||
"beta": 0.95, | ||
"utility": {"delta": 0.05}, | ||
"next_wealth": {"interest_rate": 0.05}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
from lcm.entry_point import get_lcm_function | ||
from lcm.example_models.testing_example_models import PARAMS, PHELPS_DEATON | ||
|
||
SKIP_REASON = """The test is designed to run approximately 1 minute on a standard | ||
laptop, such that we can differentiate the performance of running LCM on a GPU versus | ||
on the CPU.""" | ||
|
||
|
||
@pytest.mark.skip(reason=SKIP_REASON) | ||
def test_long(): | ||
solve_model, template = get_lcm_function(PHELPS_DEATON, targets="solve") | ||
solve_model(PARAMS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters