:py:mod:`causal_testing.testing.metamorphic_relation` ===================================================== .. py:module:: causal_testing.testing.metamorphic_relation .. autoapi-nested-parse:: This module contains the ShouldCause and ShouldNotCause metamorphic relations as defined in our ICST paper [https://eprints.whiterose.ac.uk/195317/]. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: causal_testing.testing.metamorphic_relation.MetamorphicRelation causal_testing.testing.metamorphic_relation.ShouldCause causal_testing.testing.metamorphic_relation.ShouldNotCause Functions ~~~~~~~~~ .. autoapisummary:: causal_testing.testing.metamorphic_relation.generate_metamorphic_relation causal_testing.testing.metamorphic_relation.generate_metamorphic_relations causal_testing.testing.metamorphic_relation.generate_causal_tests Attributes ~~~~~~~~~~ .. autoapisummary:: causal_testing.testing.metamorphic_relation.logger .. py:data:: logger .. py:class:: MetamorphicRelation Class representing a metamorphic relation. .. py:attribute:: base_test_case :type: causal_testing.testing.base_test_case.BaseTestCase .. py:attribute:: adjustment_vars :type: Iterable[str] .. py:method:: __eq__(other) Return self==value. .. py:method:: to_json_stub(skip: bool = False, estimate_type: str = 'coefficient', effect_type: str = 'direct', estimator: str = 'LinearRegressionEstimator', alpha: float = 0.05) -> dict Convert to a JSON frontend stub string for user customisation. :param skip: Whether to skip the test (default False). :param effect_type: The type of causal effect to consider (total or direct) :param estimate_type: The estimate type to use when evaluating tests :param estimator: The name of the estimator class to use when evaluating the test :param alpha: The significance level to use when calculating the confidence intervals .. py:class:: ShouldCause Bases: :py:obj:`MetamorphicRelation` Class representing a should cause metamorphic relation. .. py:method:: to_json_stub(skip: bool = False, estimate_type: str = 'coefficient', effect_type: str = 'direct', estimator: str = 'LinearRegressionEstimator', alpha: float = 0.05) -> dict Convert to a JSON frontend stub string for user customisation. :param skip: Whether to skip the test (default False). :param effect_type: The type of causal effect to consider (total or direct) :param estimate_type: The estimate type to use when evaluating tests :param estimator: The name of the estimator class to use when evaluating the test :param alpha: The significance level to use when calculating the confidence intervals .. py:method:: __str__() Return str(self). .. py:class:: ShouldNotCause Bases: :py:obj:`MetamorphicRelation` Class representing a should cause metamorphic relation. .. py:method:: to_json_stub(skip: bool = False, estimate_type: str = 'coefficient', effect_type: str = 'direct', estimator: str = 'LinearRegressionEstimator', alpha: float = 0.05) -> dict Convert to a JSON frontend stub string for user customisation. :param skip: Whether to skip the test (default False). :param effect_type: The type of causal effect to consider (total or direct) :param estimate_type: The estimate type to use when evaluating tests :param estimator: The name of the estimator class to use when evaluating the test :param alpha: The significance level to use when calculating the confidence intervals .. py:method:: __str__() Return str(self). .. py:function:: generate_metamorphic_relation(node_pair: tuple[str, str], dag: causal_testing.specification.causal_dag.CausalDAG, nodes_to_ignore: set = None) -> MetamorphicRelation Construct a metamorphic relation for a given node pair implied by the Causal DAG, or None if no such relation can be constructed (e.g. because every valid adjustment set contains a node to ignore). :param node_pair: The pair of nodes to consider. :param dag: Causal DAG from which the metamorphic relations will be generated. :param nodes_to_ignore: Set of nodes which will be excluded from causal tests. :return: A list containing ShouldCause and ShouldNotCause metamorphic relations. .. py:function:: generate_metamorphic_relations(dag: causal_testing.specification.causal_dag.CausalDAG, nodes_to_ignore: set = None, threads: int = 0, nodes_to_test: set = None) -> list[MetamorphicRelation] Construct a list of metamorphic relations implied by the Causal DAG. This list of metamorphic relations contains a ShouldCause relation for every edge, and a ShouldNotCause relation for every (minimal) conditional independence relation implied by the structure of the DAG. :param dag: Causal DAG from which the metamorphic relations will be generated. :param nodes_to_ignore: Set of nodes which will be excluded from causal tests. :param threads: Number of threads to use (if generating in parallel). :param nodes_to_test: Set of nodes to test the relationships between (defaults to all nodes). :return: A list containing ShouldCause and ShouldNotCause metamorphic relations. .. py:function:: generate_causal_tests(dag_path: str, output_path: str, ignore_cycles: bool = False, threads: int = 0, test_inputs: bool = False, **json_stub_kargs) Generate and output causal tests for a given DAG. :param dag_path: Path to the DOT file that specifies the causal DAG. :param output_path: Path to save the JSON output. :param ignore_cycles: Whether to bypass the check that the DAG is actually acyclic. If set to true, tests that include variables that are part of a cycle as either treatment, outcome, or adjustment will be omitted from the test set. :param threads: The number of threads to use to generate tests in parallel. If unspecified, tests are generated in serial. This is tylically fine unless the number of tests to be generated is >10000. :param test_inputs: Whether to test independences between inputs (i.e. root nodes in the DAG). Defaults to False as they will typically be independent by construction. :param json_stub_kargs: Kwargs to pass into `to_json_stub` (see docstring for details.)