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

added full bootstrap results returning #217

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run(self):
# Run the setup
setup(
name="tigramite",
version="5.0.1.17",
version="5.0.1.18",
packages=["tigramite", "tigramite.independence_tests", "tigramite.toymodels"],
license="GNU General Public License v3.0",
description="Tigramite causal discovery for time series",
Expand Down
24 changes: 15 additions & 9 deletions tigramite/causal_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ def __init__(self,
if len(self.hidden_variables.intersection(self.X.union(self.Y).union(self.S))) > 0:
raise ValueError("XYS overlaps with hidden_variables!")



# Only needed for later extension to MAG/PAGs
if 'pag' in graph_type:
self.possible = True
Expand Down Expand Up @@ -146,8 +144,6 @@ def __init__(self,
self.no_causal_path = True
if self.verbosity > 0:
print("No causal path from X to Y exists.")

# raise ValueError("No causal path from X to Y exists.")
else:
self.no_causal_path = False

Expand All @@ -164,17 +160,17 @@ def __init__(self,
raise ValueError("X, Y, S must have time lags inside graph.")

if len(self.X.intersection(self.Y)) > 0:
raise ValueError("Overlap between X and Y")
raise ValueError("Overlap between X and Y.")

if len(self.S.intersection(self.Y.union(self.X))) > 0:
raise ValueError("Conditions S overlap with X or Y")
raise ValueError("Conditions S overlap with X or Y.")

# # TODO: need to prove that this is sufficient for non-identifiability!
# if len(self.X.intersection(self._get_descendants(self.M))) > 0:
# raise ValueError("Not identifiable: Overlap between X and des(M)")

if check_SM_overlap and len(self.S.intersection(self.M)) > 0:
raise ValueError("Conditions S overlap with mediators M!")
raise ValueError("Conditions S overlap with mediators M.")

self.desX = self._get_descendants(self.X)
self.desY = self._get_descendants(self.Y)
Expand All @@ -194,7 +190,7 @@ def __init__(self,
# Here only check if S overlaps with des(Y), leave the option that S
# contains variables in des(M) to the user
if len(self.S.intersection(self.desY)) > 0:
raise ValueError("Not identifiable: Conditions S overlap with des(Y)")
raise ValueError("Not identifiable: Conditions S overlap with des(Y).")

if self.verbosity > 0:
print("\n##\n## Initializing CausalEffects class\n##"
Expand Down Expand Up @@ -1861,6 +1857,10 @@ def fit_total_effect(self,
self.dataframe = dataframe
self.conditional_estimator = conditional_estimator

if self.N != self.dataframe.N:
raise ValueError("Dataset dimensions inconsistent with number of variables in graph.")


if adjustment_set == 'optimal':
# Check optimality and use either optimal or colliders_only set
adjustment_set = self.get_optimal_set()
Expand Down Expand Up @@ -2380,7 +2380,8 @@ def fit_bootstrap_of(self, method, method_args,


def predict_bootstrap_of(self, method, method_args,
conf_lev=0.9):
conf_lev=0.9,
return_individual_bootstrap_results=False):
"""Predicts with fitted bootstraps.

To be used after fitting with fit_bootstrap_of. Only uses the
Expand All @@ -2394,6 +2395,8 @@ def predict_bootstrap_of(self, method, method_args,
Arguments passed to method.
conf_lev : float, optional (default: 0.9)
Two-sided confidence interval.
return_individual_bootstrap_results : bool
Returns the individual bootstrap predictions.

Returns
-------
Expand Down Expand Up @@ -2431,6 +2434,9 @@ def predict_bootstrap_of(self, method, method_args,
bootstrap_predicted_array, axis=0,
q = [100*(1. - c_int), 100*c_int])[:,:,0]

if return_individual_bootstrap_results:
return bootstrap_predicted_array, confidence_interval

return confidence_interval


Expand Down
4 changes: 2 additions & 2 deletions tigramite/independence_tests/cmiknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CMIknn(CondIndTest):
computed as a fraction of T, hence knn=knn*T. For knn larger or equal to
1, this is the absolute number.

shuffle_neighbors : int, optional (default: 10)
shuffle_neighbors : int, optional (default: 5)
Number of nearest-neighbors within Z for the shuffle surrogates which
determines the size of hyper-cubes around each (high-dimensional) sample
point.
Expand All @@ -79,7 +79,7 @@ class CMIknn(CondIndTest):

workers : int (optional, default = -1)
Number of workers to use for parallel processing. If -1 is given
all processors are used. Default: 1.
all processors are used. Default: -1.

significance : str, optional (default: 'shuffle_test')
Type of significance test to use. For CMIknn only 'fixed_thres' and
Expand Down