Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vasilis/docs #370

Merged
merged 39 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
05d824a
re-structured public module in docs
vasilismsr Jan 13, 2021
d7abbcc
re-structured public module in docs
vasilismsr Jan 13, 2021
4134e8f
fixed map and comparison table
vasilismsr Jan 13, 2021
7987042
fixed inference test
vasilismsr Jan 13, 2021
b9cfdf4
Merge branch 'master' into vasilis/docs
vsyrgkanis Jan 14, 2021
c774ab9
moved orf to folder. moved automl to folder. changed docs. fixed doct…
vasilismsr Jan 14, 2021
fe1112e
added deprecated orf
vasilismsr Jan 14, 2021
427aedb
doc fixes
vasilismsr Jan 14, 2021
77db23e
auto init missing
vasilismsr Jan 14, 2021
b435131
small fixes
vasilismsr Jan 14, 2021
f7629d7
removed explicit automl docs until azureml fix
vasilismsr Jan 14, 2021
c16e424
removed automl for now from docs until import is fixed
vasilismsr Jan 14, 2021
7ccaa8d
restructured to folders
vasilismsr Jan 14, 2021
c1c4159
added iv/nnet init
vasilismsr Jan 14, 2021
34289a7
fixed import
vasilismsr Jan 14, 2021
7092741
fixed relative importst
vasilismsr Jan 14, 2021
95edf8f
fixed bootstrap relative imports
vasilismsr Jan 14, 2021
f3b0033
fixed relative imports
vasilismsr Jan 15, 2021
d93c188
fxed imports
vasilismsr Jan 15, 2021
3c126a9
lasso doctest
vasilismsr Jan 15, 2021
d5d3f2c
doctest in ofrest
vasilismsr Jan 15, 2021
f02978e
changed to NonParamTSLS
vasilismsr Jan 15, 2021
8ea3976
added more text to bootstrap deprecation warning
vasilismsr Jan 15, 2021
dba96ad
fixed review feedback
vasilismsr Jan 15, 2021
0ba268f
merged with master
vasilismsr Jan 16, 2021
fae4f01
merge master
vasilismsr Jan 16, 2021
04f0afb
changed to particular shap commit
vasilismsr Jan 16, 2021
d2ecaf8
reverted shap and added intersphinx
vasilismsr Jan 16, 2021
f160711
reverted to commit shap
vasilismsr Jan 16, 2021
d5e61bc
fixed wording in hyperparm tuning
vasilismsr Jan 16, 2021
e36347e
Merge branch 'master' into vasilis/docs
vsyrgkanis Jan 16, 2021
7795d80
fixed reference to hoenst forest in docs
vasilismsr Jan 16, 2021
80781e8
moved tsls under sieve submodule
vasilismsr Jan 16, 2021
2bdbb37
changed tsls to sieve.SieveTSLS
vasilismsr Jan 16, 2021
66729bc
fixed azure pipes
vasilismsr Jan 16, 2021
352772b
fixed azure pipes
vasilismsr Jan 16, 2021
cfc93f2
added verbosity to bootstrap
vasilismsr Jan 16, 2021
70337ce
mvoed bootstrap to private
vasilismsr Jan 18, 2021
4b8730e
made deprecation changes
vasilismsr Jan 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions econml/inference/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class BootstrapEstimator:
This object must support a `fit` method which takes numpy arrays with consistent first dimensions
as arguments.

n_bootstrap_samples : int
n_bootstrap_samples : int, default: 100
How many draws to perform.

n_jobs: int, default: None
The maximum number of concurrently running jobs, as in joblib.Parallel.

verbose: int, default: 0
Verbosity level

compute_means : bool, default: True
Whether to pass calls through to the underlying collection and return the mean. Setting this
to ``False`` can avoid ambiguities if the wrapped object itself has method names with an `_interval` suffix.
Expand All @@ -50,10 +53,16 @@ class BootstrapEstimator:
assuming the replicates are normally distributed.
"""

def __init__(self, wrapped, n_bootstrap_samples=1000, n_jobs=None, compute_means=True, bootstrap_type='pivot'):
def __init__(self, wrapped,
n_bootstrap_samples=100,
n_jobs=None,
verbose=0,
compute_means=True,
bootstrap_type='pivot'):
self._instances = [clone(wrapped, safe=False) for _ in range(n_bootstrap_samples)]
self._n_bootstrap_samples = n_bootstrap_samples
self._n_jobs = n_jobs
self._verbose = verbose
self._compute_means = compute_means
self._bootstrap_type = bootstrap_type
self._wrapped = wrapped
Expand Down Expand Up @@ -109,7 +118,7 @@ def convertArg(arg, inds):
else: # arg was a scalar, so we shouldn't have converted it
return arg

self._instances = Parallel(n_jobs=self._n_jobs, prefer='threads', verbose=3)(
self._instances = Parallel(n_jobs=self._n_jobs, prefer='threads', verbose=self._verbose)(
delayed(fit)(obj,
*[convertArg(arg, inds) for arg in args],
**{arg: convertArg(named_args[arg], inds) for arg in named_args})
Expand All @@ -130,7 +139,7 @@ def __getattr__(self, name):

def proxy(make_call, name, summary):
def summarize_with(f):
results = np.array(Parallel(n_jobs=self._n_jobs, prefer='threads', verbose=3)(
results = np.array(Parallel(n_jobs=self._n_jobs, prefer='threads', verbose=self._verbose)(
(f, (obj, name), {}) for obj in self._instances)), f(self._wrapped, name)
return summary(*results)
if make_call:
Expand Down
8 changes: 6 additions & 2 deletions econml/inference/_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class BootstrapInference(Inference):
n_jobs: int, optional (default -1)
The maximum number of concurrently running jobs, as in joblib.Parallel.

verbose: int, default: 0
Verbosity level

bootstrap_type: 'percentile', 'pivot', or 'normal', default 'pivot'
Bootstrap method used to compute results.
'percentile' will result in using the empiracal CDF of the replicated computations of the statistics.
Expand All @@ -76,14 +79,15 @@ class BootstrapInference(Inference):
'normal' will instead compute a pivot interval assuming the replicates are normally distributed.
"""

def __init__(self, n_bootstrap_samples=100, n_jobs=-1, bootstrap_type='pivot'):
def __init__(self, n_bootstrap_samples=100, n_jobs=-1, bootstrap_type='pivot', verbose=0):
self._n_bootstrap_samples = n_bootstrap_samples
self._n_jobs = n_jobs
self._bootstrap_type = bootstrap_type
self._verbose = verbose

def fit(self, estimator, *args, **kwargs):
est = BootstrapEstimator(estimator, self._n_bootstrap_samples, self._n_jobs, compute_means=False,
bootstrap_type=self._bootstrap_type)
bootstrap_type=self._bootstrap_type, verbose=self._verbose)
est.fit(*args, **kwargs)
self._est = est
self._d_t = estimator._d_t
Expand Down
6 changes: 3 additions & 3 deletions econml/tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_stratify(self):
Y = [1, 2, 3, 4, 5, 6]
X = np.array([1, 1, 2, 2, 1, 2]).reshape(-1, 1)
est = LinearDML(model_y=LinearRegression(), model_t=LogisticRegression(), discrete_treatment=True)
inference = BootstrapInference(n_bootstrap_samples=5)
inference = BootstrapInference(n_bootstrap_samples=5, n_jobs=-1, verbose=0)
est.fit(Y, T, inference=inference)
est.const_marginal_effect_interval()

Expand All @@ -292,7 +292,7 @@ def test_stratify_orthoiv(self):
X = np.array([1, 1, 2, 2, 1, 2, 1, 2]).reshape(-1, 1)
est = LinearIntentToTreatDRIV(model_Y_X=LinearRegression(), model_T_XZ=LogisticRegression(),
flexible_model_effect=LinearRegression(), cv=2)
inference = BootstrapInference(n_bootstrap_samples=20)
inference = BootstrapInference(n_bootstrap_samples=20, n_jobs=-1, verbose=3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be testing that the output is more verbose in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to do that easily. I’d say lets postpone

est.fit(Y, T, Z=Z, X=X, inference=inference)
est.const_marginal_effect_interval(X)

Expand All @@ -303,7 +303,7 @@ def test_all_kinds(self):
est = LinearDML(cv=2)
for kind in ['percentile', 'pivot', 'normal']:
with self.subTest(kind=kind):
inference = BootstrapInference(n_bootstrap_samples=5, bootstrap_type=kind)
inference = BootstrapInference(n_bootstrap_samples=5, n_jobs=-1, verbose=0, bootstrap_type=kind)
est.fit(Y, T, inference=inference)
i = est.const_marginal_effect_interval()
inf = est.const_marginal_effect_inference()
Expand Down