in dowhy/causal_identifier.py [0:0]
def find_valid_adjustment_sets(self, treatment_name, outcome_name,
backdoor_paths, bdoor_graph, dseparation_algo,
backdoor_sets, filt_eligible_variables,
method_name, max_iterations):
num_iterations = 0
found_valid_adjustment_set = False
all_nodes_observed = self._graph.all_observed(self._graph.get_all_nodes())
# If `minimal-adjustment` method is specified, start the search from the set with minimum size. Otherwise, start from the largest.
set_sizes = range(1, len(filt_eligible_variables) + 1, 1) if method_name == CausalIdentifier.BACKDOOR_MIN else range(len(filt_eligible_variables), 0, -1)
for size_candidate_set in set_sizes:
for candidate_set in itertools.combinations(filt_eligible_variables, size_candidate_set):
check = self._graph.check_valid_backdoor_set(treatment_name,
outcome_name, candidate_set,
backdoor_paths=backdoor_paths,
new_graph = bdoor_graph,
dseparation_algo = dseparation_algo)
self.logger.debug("Candidate backdoor set: {0}, is_dseparated: {1}".format(candidate_set, check["is_dseparated"]))
if check["is_dseparated"]:
backdoor_sets.append({'backdoor_set': candidate_set})
found_valid_adjustment_set = True
num_iterations += 1
if method_name == CausalIdentifier.BACKDOOR_EXHAUSTIVE and num_iterations > max_iterations:
self.logger.warning(f"Max number of iterations {max_iterations} reached.")
break
# If the backdoor method is `maximal-adjustment` or `minimal-adjustment`, return the first found adjustment set.
if method_name in {CausalIdentifier.BACKDOOR_DEFAULT, CausalIdentifier.BACKDOOR_MAX, CausalIdentifier.BACKDOOR_MIN} and found_valid_adjustment_set:
break
# If all variables are observed, and the biggest eligible set
# does not satisfy backdoor, then none of its subsets will.
if method_name in {CausalIdentifier.BACKDOOR_DEFAULT, CausalIdentifier.BACKDOOR_MAX} and all_nodes_observed:
break
if num_iterations > max_iterations:
self.logger.warning(f"Max number of iterations {max_iterations} reached. Could not find a valid backdoor set.")
break
return backdoor_sets, found_valid_adjustment_set