causal_testing.discovery.abstract_discovery

This module implements the abstract Discovery class to infer causal DAGs from data.

Module Contents

Classes

Discovery

Abstract class for causal discovery.

Functions

simple_cycle(causal_dag)

Find a cycle in the given CausalDAG, if one exists, returns the first found.

is_match(u, v, patterns)

Check whether a given edge matches a given pattern.

causal_testing.discovery.abstract_discovery.simple_cycle(causal_dag: causal_testing.specification.causal_dag.CausalDAG)

Find a cycle in the given CausalDAG, if one exists, returns the first found.

Parameters:

causal_dag – The CausalDAG to check for cycles.

Returns:

A list of edges in the cycle, or an empty list if there are no cycles.

causal_testing.discovery.abstract_discovery.is_match(u: str, v: str, patterns: list[str])

Check whether a given edge matches a given pattern.

Parameters:
  • u – The origin node of the edge.

  • v – The destination node of the edge.

  • patterns – A list of tuples containing the patterns to check against.

Returns:

True if the edge matches the pattern, False otherwise.

class causal_testing.discovery.abstract_discovery.Discovery(df: pandas.DataFrame, random_seed: int = 0, exclude_edges: str = None, include_edges: str = None, alpha: float = 0.05)

Bases: abc.ABC

Abstract class for causal discovery.

abstract discover() → causal_testing.specification.causal_dag.CausalDAG

Discover the causal DAG.

Returns:

The inferred causal DAG.

remove_cycles(causal_dag: causal_testing.specification.causal_dag.CausalDAG)

Remove cycles from individuals by iteratively deleting a random edge from each cycle until there are no more cycles.

Parameters:

causal_dag – The CausalDAG to be repaired.

evaluate_tests(causal_dag: causal_testing.specification.causal_dag.CausalDAG) → pandas.DataFrame

Generate and evaluate causal test cases from the supplied CausalDAG and return a list of edges for which the corresponding causal test case failed. These results are then assigned to a new attribute test_results within the individual for later reuse.

Parameters:

causal_dag – The CausalDAG to evaluate.

Returns:

Pandas dataframe with test outcome details (result, expected effect, treatment, outcome, effect direction).