Skip to content

Commit

Permalink
Rename phelps_deaton -> deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens committed Feb 28, 2024
1 parent 4f75885 commit e4ebed3
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 52 deletions.
6 changes: 3 additions & 3 deletions tests/test_analytical_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lcm.entry_point import get_lcm_function
from numpy.testing import assert_array_almost_equal as aaae

from tests.test_models.phelps_deaton import PHELPS_DEATON_WITH_FILTERS
from tests.test_models.deterministic import BASE_MODEL_WITH_FILTERS

# ======================================================================================
# Model specifications
Expand All @@ -23,11 +23,11 @@

TEST_CASES = {
"iskhakov_2017_five_periods": {
"model": {**PHELPS_DEATON_WITH_FILTERS, "n_periods": 5},
"model": {**BASE_MODEL_WITH_FILTERS, "n_periods": 5},
"params": {**ISKHAVOV_2017_PARAMS, "utility": {"disutility_of_work": 1.0}},
},
"iskhakov_2017_low_delta": {
"model": {**PHELPS_DEATON_WITH_FILTERS, "n_periods": 3},
"model": {**BASE_MODEL_WITH_FILTERS, "n_periods": 3},
"params": {**ISKHAVOV_2017_PARAMS, "utility": {"disutility_of_work": 0.1}},
},
}
Expand Down
28 changes: 14 additions & 14 deletions tests/test_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
from lcm.state_space import create_state_choice_space
from pybaum import tree_equal, tree_map

from tests.test_models.phelps_deaton import (
PHELPS_DEATON,
PHELPS_DEATON_FULLY_DISCRETE,
PHELPS_DEATON_WITH_FILTERS,
from tests.test_models.deterministic import (
BASE_MODEL,
BASE_MODEL_FULLY_DISCRETE,
BASE_MODEL_WITH_FILTERS,
utility,
)

MODELS = {
"simple": PHELPS_DEATON,
"with_filters": PHELPS_DEATON_WITH_FILTERS,
"fully_discrete": PHELPS_DEATON_FULLY_DISCRETE,
"simple": BASE_MODEL,
"with_filters": BASE_MODEL_WITH_FILTERS,
"fully_discrete": BASE_MODEL_FULLY_DISCRETE,
}


Expand All @@ -45,7 +45,7 @@ def test_get_lcm_function_with_solve_target(user_model):

@pytest.mark.parametrize(
"user_model",
[PHELPS_DEATON, PHELPS_DEATON_FULLY_DISCRETE],
[BASE_MODEL, BASE_MODEL_FULLY_DISCRETE],
ids=["simple", "fully_discrete"],
)
def test_get_lcm_function_with_simulation_target_simple(user_model):
Expand All @@ -66,7 +66,7 @@ def test_get_lcm_function_with_simulation_target_simple(user_model):

@pytest.mark.parametrize(
"user_model",
[PHELPS_DEATON, PHELPS_DEATON_FULLY_DISCRETE],
[BASE_MODEL, BASE_MODEL_FULLY_DISCRETE],
ids=["simple", "fully_discrete"],
)
def test_get_lcm_function_with_simulation_is_coherent(user_model):
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_get_lcm_function_with_simulation_is_coherent(user_model):

@pytest.mark.parametrize(
"user_model",
[PHELPS_DEATON_WITH_FILTERS],
[BASE_MODEL_WITH_FILTERS],
ids=["with_filters"],
)
def test_get_lcm_function_with_simulation_target_with_filters(user_model):
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_get_lcm_function_with_simulation_target_with_filters(user_model):


def test_create_compute_conditional_continuation_value():
model = process_model(PHELPS_DEATON)
model = process_model(BASE_MODEL)

params = {
"beta": 1.0,
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_create_compute_conditional_continuation_value():


def test_create_compute_conditional_continuation_value_with_discrete_model():
model = process_model(PHELPS_DEATON_FULLY_DISCRETE)
model = process_model(BASE_MODEL_FULLY_DISCRETE)

params = {
"beta": 1.0,
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_create_compute_conditional_continuation_value_with_discrete_model():


def test_create_compute_conditional_continuation_policy():
model = process_model(PHELPS_DEATON)
model = process_model(BASE_MODEL)

params = {
"beta": 1.0,
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_create_compute_conditional_continuation_policy():


def test_create_compute_conditional_continuation_policy_with_discrete_model():
model = process_model(PHELPS_DEATON_FULLY_DISCRETE)
model = process_model(BASE_MODEL_FULLY_DISCRETE)

params = {
"beta": 1.0,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_model_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from lcm.state_space import create_state_choice_space
from numpy.testing import assert_array_equal

from tests.test_models.phelps_deaton import PHELPS_DEATON, utility
from tests.test_models.deterministic import BASE_MODEL, utility


def test_get_combined_constraint():
Expand Down Expand Up @@ -42,7 +42,7 @@ def h():


def test_get_utility_and_feasibility_function():
model = process_model(PHELPS_DEATON)
model = process_model(BASE_MODEL)

params = {
"beta": 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Example specifications of the Phelps-Deaton model.
"""Example specifications of a deterministic consumption-saving model.
This specification extends the example model presented in the paper: "The endogenous
This specification builds on the example model presented in the paper: "The endogenous
grid method for discrete-continuous dynamic choice models with (or without) taste
shocks" by Fedor Iskhakov, Thomas H. Jørgensen, John Rust and Bertel Schjerning (2017,
https://doi.org/10.3982/QE643).
Expand Down Expand Up @@ -84,10 +84,10 @@ def absorbing_retirement_filter(retirement, lagged_retirement):


# ======================================================================================
# Model specification and parameters
# Model specifications
# ======================================================================================

PHELPS_DEATON = {
BASE_MODEL = {
"functions": {
"utility": utility,
"next_wealth": next_wealth,
Expand Down Expand Up @@ -117,7 +117,7 @@ def absorbing_retirement_filter(retirement, lagged_retirement):
}


PHELPS_DEATON_FULLY_DISCRETE = {
BASE_MODEL_FULLY_DISCRETE = {
"functions": {
"utility": utility,
"next_wealth": next_wealth,
Expand All @@ -140,7 +140,7 @@ def absorbing_retirement_filter(retirement, lagged_retirement):
}


PHELPS_DEATON_WITH_FILTERS = {
BASE_MODEL_WITH_FILTERS = {
"functions": {
"utility": utility_with_filter,
"next_wealth": next_wealth,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/stochastic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Example specifications of a simple Phelps-Deaton style stochastic model.
"""Example specifications of a stochastic consumption-saving model.
This specification is motivated by the example model presented in the paper: "The
endogenous grid method for discrete-continuous dynamic choice models with (or without)
taste shocks" by Fedor Iskhakov, Thomas H. Jørgensen, John Rust and Bertel Schjerning
(2017, https://doi.org/10.3982/QE643).
See also the specifications in tests/test_models/phelps_deaton.py.
See also the specifications in tests/test_models/deterministic.py.
"""

Expand Down
4 changes: 2 additions & 2 deletions tests/test_next_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from lcm.process_model import process_model
from pybaum import tree_equal

from tests.test_models.phelps_deaton import PHELPS_DEATON
from tests.test_models.deterministic import BASE_MODEL

# ======================================================================================
# Solve target
# ======================================================================================


def test_get_next_state_function_with_solve_target():
model = process_model(PHELPS_DEATON)
model = process_model(BASE_MODEL)
got_func = get_next_state_function(model, target="solve")

params = {
Expand Down
14 changes: 7 additions & 7 deletions tests/test_process_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from numpy.testing import assert_array_equal
from pandas.testing import assert_frame_equal

from tests.test_models.phelps_deaton import (
from tests.test_models.deterministic import (
BASE_MODEL,
BASE_MODEL_WITH_FILTERS,
N_GRID_POINTS,
PHELPS_DEATON,
PHELPS_DEATON_WITH_FILTERS,
)


Expand Down Expand Up @@ -100,8 +100,8 @@ def test_get_grids(user_model):
assert_array_equal(got["c"], jnp.array([2, 3]))


def test_process_phelps_deaton_with_filters():
model = process_model(PHELPS_DEATON_WITH_FILTERS)
def test_process_model_with_filters():
model = process_model(BASE_MODEL_WITH_FILTERS)

# Variable Info
assert (
Expand Down Expand Up @@ -156,8 +156,8 @@ def test_process_phelps_deaton_with_filters():
assert ~model.function_info.loc["utility"].to_numpy().any()


def test_process_phelps_deaton():
model = process_model(PHELPS_DEATON)
def test_process_model():
model = process_model(BASE_MODEL)

# Variable Info
assert ~(model.variable_info["is_sparse"].to_numpy()).any()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_regression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from numpy.testing import assert_array_almost_equal as aaae
from pandas.testing import assert_frame_equal

from tests.test_models.phelps_deaton import PHELPS_DEATON
from tests.test_models.deterministic import BASE_MODEL

REGRESSION_TEST_MODEL = {**PHELPS_DEATON, "n_perids": 5}
REGRESSION_TEST_MODEL = {**BASE_MODEL, "n_perids": 5}
REGRESSION_TEST_PARAMS = {
"beta": 0.95,
"utility": {"disutility_of_work": 1.0},
Expand Down
24 changes: 12 additions & 12 deletions tests/test_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from numpy.testing import assert_array_almost_equal, assert_array_equal
from pybaum import tree_equal

from tests.test_models.phelps_deaton import (
from tests.test_models.deterministic import (
BASE_MODEL,
BASE_MODEL_WITH_FILTERS,
N_GRID_POINTS,
PHELPS_DEATON,
PHELPS_DEATON_WITH_FILTERS,
)

# ======================================================================================
Expand All @@ -40,7 +40,7 @@

@pytest.fixture()
def simulate_inputs():
user_model = {**PHELPS_DEATON, "n_periods": 1}
user_model = {**BASE_MODEL, "n_periods": 1}
model = process_model(user_model)

_, space_info, _, _ = create_state_choice_space(
Expand Down Expand Up @@ -104,9 +104,9 @@ def test_simulate_using_raw_inputs(simulate_inputs):


@pytest.fixture()
def phelps_deaton_model_solution():
def base_model_solution():
def _model_solution(n_periods):
model = {**PHELPS_DEATON, "n_periods": n_periods}
model = {**BASE_MODEL, "n_periods": n_periods}
model["functions"] = {
# remove dependency on age, so that wage becomes a parameter
name: func
Expand All @@ -130,9 +130,9 @@ def _model_solution(n_periods):
return _model_solution


@pytest.mark.parametrize("n_periods", range(3, PHELPS_DEATON["n_periods"] + 1))
def test_simulate_using_get_lcm_function(phelps_deaton_model_solution, n_periods):
vf_arr_list, params, model = phelps_deaton_model_solution(n_periods)
@pytest.mark.parametrize("n_periods", range(3, BASE_MODEL["n_periods"] + 1))
def test_simulate_using_get_lcm_function(base_model_solution, n_periods):
vf_arr_list, params, model = base_model_solution(n_periods)

simulate_model, _ = get_lcm_function(model=model, targets="simulate")

Expand Down Expand Up @@ -175,7 +175,7 @@ def test_simulate_using_get_lcm_function(phelps_deaton_model_solution, n_periods


def test_effect_of_beta_on_last_period():
model = {**PHELPS_DEATON, "n_periods": 5}
model = {**BASE_MODEL, "n_periods": 5}

# Model solutions
# ==================================================================================
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_effect_of_beta_on_last_period():


def test_effect_of_disutility_of_work():
model = {**PHELPS_DEATON, "n_periods": 5}
model = {**BASE_MODEL, "n_periods": 5}

# Model solutions
# ==================================================================================
Expand Down Expand Up @@ -404,7 +404,7 @@ def test_filter_ccv_policy():


def test_create_data_state_choice_space():
model = process_model(PHELPS_DEATON_WITH_FILTERS)
model = process_model(BASE_MODEL_WITH_FILTERS)
got_space, got_segment_info = create_data_scs(
states={
"wealth": jnp.array([10.0, 20.0]),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_state_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
)
from numpy.testing import assert_array_almost_equal as aaae

from tests.test_models.phelps_deaton import PHELPS_DEATON_WITH_FILTERS
from tests.test_models.deterministic import BASE_MODEL_WITH_FILTERS


def test_create_state_choice_space():
_model = process_model(PHELPS_DEATON_WITH_FILTERS)
_model = process_model(BASE_MODEL_WITH_FILTERS)
create_state_choice_space(
model=_model,
period=0,
Expand Down

0 comments on commit e4ebed3

Please sign in to comment.