diff --git a/tests/test_analytical_solution.py b/tests/test_analytical_solution.py index 46ef2fdd..76d5e231 100644 --- a/tests/test_analytical_solution.py +++ b/tests/test_analytical_solution.py @@ -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 @@ -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}}, }, } diff --git a/tests/test_entry_point.py b/tests/test_entry_point.py index 24db8d81..7364f3ca 100644 --- a/tests/test_entry_point.py +++ b/tests/test_entry_point.py @@ -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, } @@ -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): @@ -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): @@ -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): @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/tests/test_model_functions.py b/tests/test_model_functions.py index dfa58cbd..837f4146 100644 --- a/tests/test_model_functions.py +++ b/tests/test_model_functions.py @@ -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(): @@ -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, diff --git a/tests/test_models/phelps_deaton.py b/tests/test_models/deterministic.py similarity index 95% rename from tests/test_models/phelps_deaton.py rename to tests/test_models/deterministic.py index 0c344f40..80f682f4 100644 --- a/tests/test_models/phelps_deaton.py +++ b/tests/test_models/deterministic.py @@ -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). @@ -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, @@ -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, @@ -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, diff --git a/tests/test_models/stochastic.py b/tests/test_models/stochastic.py index 8d4707d3..8c1789de 100644 --- a/tests/test_models/stochastic.py +++ b/tests/test_models/stochastic.py @@ -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. """ diff --git a/tests/test_next_state.py b/tests/test_next_state.py index f37f02c9..3737ae86 100644 --- a/tests/test_next_state.py +++ b/tests/test_next_state.py @@ -5,7 +5,7 @@ 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 @@ -13,7 +13,7 @@ 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 = { diff --git a/tests/test_process_model.py b/tests/test_process_model.py index 53b1a3bc..c3acc07f 100644 --- a/tests/test_process_model.py +++ b/tests/test_process_model.py @@ -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, ) @@ -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 ( @@ -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() diff --git a/tests/test_regression_test.py b/tests/test_regression_test.py index 3f2e2630..8fdb29c8 100644 --- a/tests/test_regression_test.py +++ b/tests/test_regression_test.py @@ -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}, diff --git a/tests/test_simulate.py b/tests/test_simulate.py index fb5d268a..6291cc0e 100644 --- a/tests/test_simulate.py +++ b/tests/test_simulate.py @@ -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, ) # ====================================================================================== @@ -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( @@ -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 @@ -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") @@ -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 # ================================================================================== @@ -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 # ================================================================================== @@ -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]), diff --git a/tests/test_state_space.py b/tests/test_state_space.py index a5a5b8e0..7a2e7fe4 100644 --- a/tests/test_state_space.py +++ b/tests/test_state_space.py @@ -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,