Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

[pre-commit.ci] pre-commit autoupdate #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions .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
Expand All @@ -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)$'
Expand All @@ -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]
Expand Down
20 changes: 10 additions & 10 deletions econsa/quantile_measures.py
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions econsa/shapley.py
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions econsa/tests/test_quantile_measures.py
Expand Up @@ -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(
Expand All @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions econsa/tests/test_shapley.py
Expand Up @@ -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"]
Expand Down Expand Up @@ -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

Expand Down