diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 08b2a7a..373f0ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: (bin/run-figures) repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.1.0 + rev: v4.2.0 hooks: - id: check-added-large-files args: ['--maxkb=10000'] # 100 is too small for graphs @@ -13,21 +13,21 @@ repos: - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/asottile/blacken-docs - rev: v1.7.0 + rev: v1.12.1 hooks: - id: blacken-docs files: '(\.md|\.rst)$' additional_dependencies: [black] - repo: https://github.com/psf/black - rev: 20.8b0 + rev: 22.3.0 hooks: - id: black args: ['--line-length=100'] files: '(\.pyi?|wscript|ipynb)$' language_version: python3 additional_dependencies: [black-nb] -- repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.3 +- repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 hooks: - id: flake8 files: '(\.pyi?|wscript|ipynb)$' @@ -41,13 +41,13 @@ repos: # flake8-todo, flake8-unused-arguments, pep8-naming, pydocstyle, Pygments, # ] - repo: https://github.com/asottile/reorder_python_imports - rev: v2.3.0 + rev: v3.1.0 hooks: - id: reorder-python-imports files: '(\.pyi?|wscript)$' exclude: '.*conf(ig)*\.py' - repo: https://github.com/asottile/add-trailing-comma - rev: v2.0.1 + rev: v2.2.3 hooks: - id: add-trailing-comma args: [--py36-plus] diff --git a/econsa/quantile_measures.py b/econsa/quantile_measures.py index 4c53083..886656e 100644 --- a/econsa/quantile_measures.py +++ b/econsa/quantile_measures.py @@ -250,16 +250,16 @@ def _dlr_conditional_samples(x): n_draws, n_params = x.shape # The dependence of m versus n_draws accroding to S. Kucherenko and S. Song(2017). - if n_draws == 2 ** 6: - m = 2 ** 3 - elif n_draws in [2 ** 7, 2 ** 8, 2 ** 9]: - m = 2 ** 4 - elif n_draws == 2 ** 10: - m = 2 ** 5 - elif n_draws in [2 ** 11, 2 ** 12, 2 ** 13]: - m = 2 ** 6 - elif n_draws in [2 ** 14, 2 ** 15]: - m = 2 ** 7 + if n_draws == 2**6: + m = 2**3 + elif n_draws in [2**7, 2**8, 2**9]: + m = 2**4 + elif n_draws == 2**10: + m = 2**5 + elif n_draws in [2**11, 2**12, 2**13]: + m = 2**6 + elif n_draws in [2**14, 2**15]: + m = 2**7 else: raise NotImplementedError diff --git a/econsa/shapley.py b/econsa/shapley.py index bd6bd50..99585ef 100644 --- a/econsa/shapley.py +++ b/econsa/shapley.py @@ -186,14 +186,14 @@ def get_shapley( delta = estimated_cost - previous_cost shapley_effects[perms[j]] = shapley_effects[perms[j]] + delta - shapley_effects_squared[perms[j]] = shapley_effects_squared[perms[j]] + delta ** 2 + shapley_effects_squared[perms[j]] = shapley_effects_squared[perms[j]] + delta**2 previous_cost = estimated_cost shapley_effects = shapley_effects / n_perms / output_variance - shapley_effects_squared = shapley_effects_squared / n_perms / (output_variance ** 2) + shapley_effects_squared = shapley_effects_squared / n_perms / (output_variance**2) standard_errors = np.sqrt( - (shapley_effects_squared - shapley_effects ** 2) / n_perms, + (shapley_effects_squared - shapley_effects**2) / n_perms, ) # confidence intervals diff --git a/econsa/tests/test_quantile_measures.py b/econsa/tests/test_quantile_measures.py index 914396d..8ae2787 100644 --- a/econsa/tests/test_quantile_measures.py +++ b/econsa/tests/test_quantile_measures.py @@ -77,7 +77,7 @@ def test_1(test_1_fixture): for estimator, n_draws, decimal in zip( ["DLR", "DLR", "DLR", "DLR", "brute force"], - [2 ** 6, 2 ** 9, 2 ** 10, 2 ** 13, 3000], + [2**6, 2**9, 2**10, 2**13, 3000], [0, 1, 1, 2, 2], ): norm_q_2_solve = p_measures( @@ -97,7 +97,7 @@ def test_wrong_value_criterion(test_1_fixture): # remove the last item in dictionary. test_1_fixture.popitem() - p_measures = partial(mc_quantile_measures, n_draws=2 ** 10, **test_1_fixture) + p_measures = partial(mc_quantile_measures, n_draws=2**10, **test_1_fixture) for estimator, scheme in zip(["double loop reordering", "DLR"], ["sobol", "halton"]): with pytest.raises(ValueError): @@ -112,7 +112,7 @@ def test_not_implemented_criterion(test_1_fixture): p_measures = partial(mc_quantile_measures, estimator="DLR", **test_1_fixture) - for dist_type, n_draws in zip(["Gamma", "Normal"], [2 ** 10, 2 ** 5]): + for dist_type, n_draws in zip(["Gamma", "Normal"], [2**10, 2**5]): with pytest.raises(NotImplementedError): p_measures(dist_type=dist_type, n_draws=n_draws) @@ -169,7 +169,7 @@ def simple_linear_function_modified(x): for estimator, n_draws in zip( ["DLR", "brute force"], - [2 ** 14, 3000], + [2**14, 3000], ): norm_q_2_solve = mc_quantile_measures( estimator=estimator, @@ -242,7 +242,7 @@ def ishigami_transposed(x, a=7, b=0.1): # Here we test naive monte carlo estimates by specifying `sampling_scheme` to "random". for estimator, n_draws in zip( ["DLR", "brute force"], - [2 ** 14, 3000], + [2**14, 3000], ): norm_q_2_solve = mc_quantile_measures( estimator=estimator, diff --git a/econsa/tests/test_shapley.py b/econsa/tests/test_shapley.py index 2a1fc17..dde179e 100644 --- a/econsa/tests/test_shapley.py +++ b/econsa/tests/test_shapley.py @@ -43,9 +43,9 @@ def x_cond(n, subset_j, subsetj_conditional, xjc): cov = np.array([[1.0, 0, 0], [0, 1.0, 1.8], [0, 1.8, 4.0]]) method = "exact" n_perms = None - n_output = 10 ** 4 - n_outer = 10 ** 3 - n_inner = 10 ** 2 + n_output = 10**4 + n_outer = 10**3 + n_inner = 10**2 col = ["X" + str(i) for i in np.arange(n_inputs) + 1] names = ["Shapley effects", "std. errors", "CI_min", "CI_max"] @@ -107,7 +107,7 @@ def x_cond(n, subset_j, subsetj_conditional, xjc): cov = np.array([[1.0, 0, 0], [0, 1.0, 1.8], [0, 1.8, 4.0]]) method = "random" n_perms = 30000 - n_output = 10 ** 4 + n_output = 10**4 n_outer = 1 n_inner = 3