Skip to content

Commit

Permalink
Release 2.1.1 (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
amageh authored Aug 26, 2021
1 parent b3851cd commit c52f645
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ build:

requirements:
host:
- python >=3.6
- python >=3.7
run:
- python >=3.6
- python >=3.7
- click
- estimagic >=0.1.2
- hypothesis
- joblib
- fastparquet
- mkl
- numba >=0.42
- numpy
- numpy>=1.21.0
- pandas >=0.24
- pytest
- python-snappy
Expand Down
11 changes: 7 additions & 4 deletions respy/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import pytest

from respy.config import CHAOSPY_INSTALLED
from respy.config import TEST_RESOURCES_DIR
from respy.config import TOL_REGRESSION_TESTS
from respy.likelihood import get_log_like_func
Expand Down Expand Up @@ -37,8 +38,10 @@ def regression_vault():
def test_single_regression(regression_vault, index):
"""Run a single regression test."""
params, options, exp_val = regression_vault[index]
crit_val = compute_log_likelihood(params, options)

assert np.isclose(
crit_val, exp_val, rtol=TOL_REGRESSION_TESTS, atol=TOL_REGRESSION_TESTS
)
if CHAOSPY_INSTALLED or options["monte_carlo_sequence"] == "random":
crit_val = compute_log_likelihood(params, options)

assert np.isclose(
crit_val, exp_val, rtol=TOL_REGRESSION_TESTS, atol=TOL_REGRESSION_TESTS
)
88 changes: 46 additions & 42 deletions respy/tests/test_solve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytest

from respy.config import CHAOSPY_INSTALLED
from respy.config import EXAMPLE_MODELS
from respy.config import INDEXER_INVALID_INDEX
from respy.config import KEANE_WOLPIN_1994_MODELS
Expand Down Expand Up @@ -274,58 +275,61 @@ def test_dense_choice_cores():
where this is not the case!
"""
point_constr = {"n_periods": 6, "observables": [3], "n_lagged_choices": 1}
if CHAOSPY_INSTALLED:
point_constr = {"n_periods": 6, "observables": [3], "n_lagged_choices": 1}

params, options = generate_random_model(point_constr=point_constr)
options["monte_carlo_sequence"] = "sobol"

# Add some inadmissible states
optim_paras, _ = process_params_and_options(params, options)

# Solve the base model
solve = get_solve_func(params, options)
state_space = solve(params)
params, options = generate_random_model(point_constr=point_constr)
options["monte_carlo_sequence"] = "sobol"

# Retrieve index
edu_start = np.random.choice(list(optim_paras["choices"]["edu"]["start"].keys()))
state = (3, 0, 3, edu_start, 1)
core_ix = state_space.indexer[state]
# Add some inadmissible states
optim_paras, _ = process_params_and_options(params, options)

# Choose dense covar
pos = np.random.choice(range(len(state_space.dense)))
# Solve the base model
solve = get_solve_func(params, options)
state_space = solve(params)

# Get indices
dense_combination = list(state_space.dense.keys())[pos]
dense_index = state_space.dense_covariates_to_dense_index[dense_combination]
ix = (
state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index],
core_ix[1],
)
# Retrieve index
edu_start = np.random.choice(
list(optim_paras["choices"]["edu"]["start"].keys())
)
state = (3, 0, 3, edu_start, 1)
core_ix = state_space.indexer[state]

# Choose dense covar
pos = np.random.choice(range(len(state_space.dense)))

# Get indices
dense_combination = list(state_space.dense.keys())[pos]
dense_index = state_space.dense_covariates_to_dense_index[dense_combination]
ix = (
state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index],
core_ix[1],
)

unrestricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]]
unrestricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]]

# Impose some restriction
options["negative_choice_set"] = {"a": ["period == 4 & exp_b ==4"]}
# Impose some restriction
options["negative_choice_set"] = {"a": ["period == 4 & exp_b ==4"]}

# Solve the restricted model
solve = get_solve_func(params, options)
state_space = solve(params)
core_ix = state_space.indexer[state]
# Solve the restricted model
solve = get_solve_func(params, options)
state_space = solve(params)
core_ix = state_space.indexer[state]

# Get indices
dense_combination = list(state_space.dense.keys())[pos]
dense_index = state_space.dense_covariates_to_dense_index[dense_combination]
ix = (
state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index],
core_ix[1],
)
# Get indices
dense_combination = list(state_space.dense.keys())[pos]
dense_index = state_space.dense_covariates_to_dense_index[dense_combination]
ix = (
state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index],
core_ix[1],
)

# Check some features of the state_space
restricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]]
# Check some features of the state_space
restricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]]

for i in [0, 2, 3]:
assert restricted_cont[i] == unrestricted_cont[i]
assert restricted_cont[1] != unrestricted_cont[1]
for i in [0, 2, 3]:
assert restricted_cont[i] == unrestricted_cont[i]
assert restricted_cont[1] != unrestricted_cont[1]


@pytest.mark.end_to_end
Expand Down

0 comments on commit c52f645

Please sign in to comment.