Skip to content

Commit

Permalink
more removing get_backdoor_variables
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Parente <[email protected]>
  • Loading branch information
nparent1 committed Jan 28, 2025
1 parent 710b045 commit fcbc05c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions dowhy/causal_refuters/assess_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, *args, **kwargs):
"""
super().__init__(*args, **kwargs)
# TODO: Check that the target estimand has backdoor variables?
# TODO: Is this algorithm compatible with other adjustment criterions, besides backdoor?
self._backdoor_vars = self._target_estimand.get_backdoor_variables()
self._cat_feats = kwargs.pop("cat_feats", [])
self._support_config = kwargs.pop("support_config", None)
Expand Down
14 changes: 7 additions & 7 deletions dowhy/do_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def __init__(
self.dep_type = [self._variable_types[var] for var in self._outcome_names]

self.indep_type = [
self._variable_types[var] for var in self._treatment_names + self._target_estimand.get_backdoor_variables()
self._variable_types[var] for var in self._treatment_names + self._target_estimand.get_adjustment_set()
]
self.density_types = [self._variable_types[var] for var in self._target_estimand.get_backdoor_variables()]
self.density_types = [self._variable_types[var] for var in self._target_estimand.get_adjustment_set()]

self.outcome_lower_support = self._data[self._outcome_names].min().values
self.outcome_upper_support = self._data[self._outcome_names].max().values
Expand All @@ -98,9 +98,9 @@ def __init__(

def _sample_point(self, x_z):
"""
OVerride this if your sampling method only allows sampling a point at a time.
Override this if your sampling method only allows sampling a point at a time.
:param : numpy.array: x_z is a numpy array containing the values of x and z in the order of the list given by
self._treatment_names + self._target_estimand.get_backdoor_variables()
self._treatment_names + self._target_estimand.get_adjustment_set()
:return: numpy.array: a sampled outcome point
"""
raise NotImplementedError
Expand Down Expand Up @@ -132,7 +132,7 @@ def disrupt_causes(self):

def point_sample(self):
if self.num_cores == 1:
sampled_outcomes = self._df[self._treatment_names + self._target_estimand.get_backdoor_variables()].apply(
sampled_outcomes = self._df[self._treatment_names + self._target_estimand.get_adjustment_set()].apply(
self._sample_point, axis=1
)
else:
Expand All @@ -142,7 +142,7 @@ def point_sample(self):
sampled_outcomes = np.array(
p.map(
self.sampler.sample_point,
self._df[self._treatment_names + self._target_estimand.get_backdoor_variables()].values,
self._df[self._treatment_names + self._target_estimand.get_adjustment_set()].values,
)
)
sampled_outcomes = pd.DataFrame(sampled_outcomes, columns=self._outcome_names)
Expand All @@ -155,7 +155,7 @@ def sample(self):
:return:
"""
sampled_outcomes = self.sampler.sample(
self._df[self._treatment_names + self._target_estimand.get_backdoor_variables()].values
self._df[self._treatment_names + self._target_estimand.get_adjustment_set()].values
)
sampled_outcomes = pd.DataFrame(sampled_outcomes, columns=self._outcome_names)
self._df[self._outcome_names] = sampled_outcomes
Expand Down
8 changes: 4 additions & 4 deletions dowhy/do_samplers/kernel_density_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __init__(self, *args, **kwargs):
if (
len(self._data) > 300
or max(
len(self._treatment_names + self._target_estimand.get_backdoor_variables()),
len(self._outcome_names + self._target_estimand.get_backdoor_variables()),
len(self._treatment_names + self._target_estimand.get_adjustment_set()),
len(self._outcome_names + self._target_estimand.get_adjustment_set()),
)
>= 3
):
Expand All @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs):
def _fit_conditional(self):
self.conditional_density = KDEMultivariateConditional(
endog=self._data[self._outcome_names],
exog=self._data[self._treatment_names + self._target_estimand.get_backdoor_variables()],
exog=self._data[self._treatment_names + self._target_estimand.get_adjustment_set()],
dep_type="".join(self.dep_type),
indep_type="".join(self.indep_type),
bw=self.bw,
Expand All @@ -51,7 +51,7 @@ def _construct_sampler(self):
self.outcome_lower_support,
self._outcome_names,
self._treatment_names,
self._target_estimand.get_backdoor_variables(),
self._target_estimand.get_adjustment_set(),
self._data,
self.dep_type,
self.indep_type,
Expand Down
2 changes: 1 addition & 1 deletion dowhy/do_samplers/multivariate_weighting_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def make_treatment_effective(self, x):
def disrupt_causes(self):
self._df["state_propensity"] = state_propensity_score(
self._data,
self._target_estimand.get_backdoor_variables(),
self._target_estimand.get_adjustment_set(),
self._treatment_names,
variable_types=self._variable_types,
)
Expand Down
2 changes: 1 addition & 1 deletion dowhy/do_samplers/weighting_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def make_treatment_effective(self, x):
def disrupt_causes(self):
self._df["propensity_score"] = state_propensity_score(
self._data,
self._target_estimand.get_backdoor_variables(),
self._target_estimand.get_adjustment_set(),
self._treatment_names,
variable_types=self._variable_types,
)
Expand Down

0 comments on commit fcbc05c

Please sign in to comment.