Skip to content

edge_differences

Signature/Parameters

def edge_differences(self, G2)

Compare edge sets between two DAGs by edge type.

Parameters:

Name Type Description Default
G2 DAG

Graph to compare with the current instance.

required

Returns:

Type Description
dict[str, dict[str, list]]

Dictionary with keys 'G1' and 'G2', each mapping to a dictionary keyed by edge type ('directed', 'undirected', 'bidirected') listing edges present in one graph but absent in the other.

Examples:

>>> G1 = DAG(graph="X -> Y")
>>> G2 = DAG(graph="X <- Y")
>>> diff = G1.edge_differences(G2)
>>> diff["G1"]["directed"]
[('X', 'Y')]
Source code in causalinf/gcm.py
def edge_differences(self, G2):
    """
    Compare edge sets between two DAGs by edge type.

    Parameters
    ----------
    G2 : DAG
        Graph to compare with the current instance.

    Returns
    -------
    dict[str, dict[str, list]]
        Dictionary with keys ``'G1'`` and ``'G2'``, each mapping to a
        dictionary keyed by edge type (``'directed'``, ``'undirected'``,
        ``'bidirected'``) listing edges present in one graph but absent in
        the other.

    Examples
    --------
    >>> G1 = DAG(graph="X -> Y")
    >>> G2 = DAG(graph="X <- Y")
    >>> diff = G1.edge_differences(G2)
    >>> diff["G1"]["directed"]
    [('X', 'Y')]
    """
    res1 = self.__edge_differences__(G2)
    res2 = G2.__edge_differences__(self)
    return {"G1":res1, "G2":res2}