|
1 | 1 | import numpy as np |
2 | 2 | import pytest |
3 | 3 |
|
| 4 | +from respy.config import CHAOSPY_INSTALLED |
4 | 5 | from respy.config import EXAMPLE_MODELS |
5 | 6 | from respy.config import INDEXER_INVALID_INDEX |
6 | 7 | from respy.config import KEANE_WOLPIN_1994_MODELS |
@@ -274,58 +275,61 @@ def test_dense_choice_cores(): |
274 | 275 | where this is not the case! |
275 | 276 |
|
276 | 277 | """ |
277 | | - point_constr = {"n_periods": 6, "observables": [3], "n_lagged_choices": 1} |
| 278 | + if CHAOSPY_INSTALLED: |
| 279 | + point_constr = {"n_periods": 6, "observables": [3], "n_lagged_choices": 1} |
278 | 280 |
|
279 | | - params, options = generate_random_model(point_constr=point_constr) |
280 | | - options["monte_carlo_sequence"] = "sobol" |
281 | | - |
282 | | - # Add some inadmissible states |
283 | | - optim_paras, _ = process_params_and_options(params, options) |
284 | | - |
285 | | - # Solve the base model |
286 | | - solve = get_solve_func(params, options) |
287 | | - state_space = solve(params) |
| 281 | + params, options = generate_random_model(point_constr=point_constr) |
| 282 | + options["monte_carlo_sequence"] = "sobol" |
288 | 283 |
|
289 | | - # Retrieve index |
290 | | - edu_start = np.random.choice(list(optim_paras["choices"]["edu"]["start"].keys())) |
291 | | - state = (3, 0, 3, edu_start, 1) |
292 | | - core_ix = state_space.indexer[state] |
| 284 | + # Add some inadmissible states |
| 285 | + optim_paras, _ = process_params_and_options(params, options) |
293 | 286 |
|
294 | | - # Choose dense covar |
295 | | - pos = np.random.choice(range(len(state_space.dense))) |
| 287 | + # Solve the base model |
| 288 | + solve = get_solve_func(params, options) |
| 289 | + state_space = solve(params) |
296 | 290 |
|
297 | | - # Get indices |
298 | | - dense_combination = list(state_space.dense.keys())[pos] |
299 | | - dense_index = state_space.dense_covariates_to_dense_index[dense_combination] |
300 | | - ix = ( |
301 | | - state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], |
302 | | - core_ix[1], |
303 | | - ) |
| 291 | + # Retrieve index |
| 292 | + edu_start = np.random.choice( |
| 293 | + list(optim_paras["choices"]["edu"]["start"].keys()) |
| 294 | + ) |
| 295 | + state = (3, 0, 3, edu_start, 1) |
| 296 | + core_ix = state_space.indexer[state] |
| 297 | + |
| 298 | + # Choose dense covar |
| 299 | + pos = np.random.choice(range(len(state_space.dense))) |
| 300 | + |
| 301 | + # Get indices |
| 302 | + dense_combination = list(state_space.dense.keys())[pos] |
| 303 | + dense_index = state_space.dense_covariates_to_dense_index[dense_combination] |
| 304 | + ix = ( |
| 305 | + state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], |
| 306 | + core_ix[1], |
| 307 | + ) |
304 | 308 |
|
305 | | - unrestricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] |
| 309 | + unrestricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] |
306 | 310 |
|
307 | | - # Impose some restriction |
308 | | - options["negative_choice_set"] = {"a": ["period == 4 & exp_b ==4"]} |
| 311 | + # Impose some restriction |
| 312 | + options["negative_choice_set"] = {"a": ["period == 4 & exp_b ==4"]} |
309 | 313 |
|
310 | | - # Solve the restricted model |
311 | | - solve = get_solve_func(params, options) |
312 | | - state_space = solve(params) |
313 | | - core_ix = state_space.indexer[state] |
| 314 | + # Solve the restricted model |
| 315 | + solve = get_solve_func(params, options) |
| 316 | + state_space = solve(params) |
| 317 | + core_ix = state_space.indexer[state] |
314 | 318 |
|
315 | | - # Get indices |
316 | | - dense_combination = list(state_space.dense.keys())[pos] |
317 | | - dense_index = state_space.dense_covariates_to_dense_index[dense_combination] |
318 | | - ix = ( |
319 | | - state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], |
320 | | - core_ix[1], |
321 | | - ) |
| 319 | + # Get indices |
| 320 | + dense_combination = list(state_space.dense.keys())[pos] |
| 321 | + dense_index = state_space.dense_covariates_to_dense_index[dense_combination] |
| 322 | + ix = ( |
| 323 | + state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], |
| 324 | + core_ix[1], |
| 325 | + ) |
322 | 326 |
|
323 | | - # Check some features of the state_space |
324 | | - restricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] |
| 327 | + # Check some features of the state_space |
| 328 | + restricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] |
325 | 329 |
|
326 | | - for i in [0, 2, 3]: |
327 | | - assert restricted_cont[i] == unrestricted_cont[i] |
328 | | - assert restricted_cont[1] != unrestricted_cont[1] |
| 330 | + for i in [0, 2, 3]: |
| 331 | + assert restricted_cont[i] == unrestricted_cont[i] |
| 332 | + assert restricted_cont[1] != unrestricted_cont[1] |
329 | 333 |
|
330 | 334 |
|
331 | 335 | @pytest.mark.end_to_end |
|
0 commit comments