:py:mod:`causal_testing.discovery.abstract_discovery` ===================================================== .. py:module:: causal_testing.discovery.abstract_discovery .. autoapi-nested-parse:: This module implements the abstract Discovery class to infer causal DAGs from data. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: causal_testing.discovery.abstract_discovery.Discovery Functions ~~~~~~~~~ .. autoapisummary:: causal_testing.discovery.abstract_discovery.simple_cycle causal_testing.discovery.abstract_discovery.effect_direction causal_testing.discovery.abstract_discovery.is_match Attributes ~~~~~~~~~~ .. autoapisummary:: causal_testing.discovery.abstract_discovery.TestResult .. py:data:: TestResult .. py:function:: simple_cycle(causal_dag: causal_testing.specification.causal_dag.CausalDAG) Find a cycle in the given CausalDAG, if one exists, returns the first found. :param 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. .. py:function:: effect_direction(result: causal_testing.testing.causal_test_result.CausalTestResult) -> str Check whether the estimated causal effect is negative or positive. :param result: The causal test result object. :returns: Whether the estimated causal test is positive or negative (or no effect). .. py:function:: is_match(u: str, v: str, patterns: list[str]) Check whether a given edge matches a given pattern. :param u: The origin node of the edge. :param v: The destination node of the edge. :param patterns: A list of tuples containing the patterns to check against. :returns: True if the edge matches the pattern, False otherwise. .. py:class:: Discovery(df: pandas.DataFrame, random_seed: int = 0, exclude_edges: str = None, include_edges: str = None, alpha: float = 0.05) Bases: :py:obj:`abc.ABC` Abstract class for causal discovery. .. py:method:: discover() -> causal_testing.specification.causal_dag.CausalDAG :abstractmethod: Discover the causal DAG. :returns: The inferred causal DAG. .. py:method:: 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. :param causal_dag: The CausalDAG to be repaired. .. py:method:: write_dot(individual: causal_testing.specification.causal_dag.CausalDAG, output_file: str) Write the given individual to the given output file. :param individual: The causal DAG to output. :param output_file: The name of the file to write to. .. py:method:: _json_stub_params(outcome: str) -> str .. py:method:: 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. :param causal_dag: The CausalDAG to evaluate. :returns: Pandas dataframe with test outcome details (result, expected effect, treatment, outcome, effect direction).