Skip to content

Commit c387f8a

Browse files
authored
[ENH] Adding intervention graph classes for known graphs and equivalence classes and improve graph class documentation (#49)
* Adding intervention classes * Adding ADMG, CPDAG and PAG subsection in Notes --------- Signed-off-by: Adam Li <adam2392@gmail.com>
1 parent 4e9cef8 commit c387f8a

File tree

14 files changed

+703
-25
lines changed

14 files changed

+703
-25
lines changed

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ graphs encountered in the literature.
2828
ADMG
2929
CPDAG
3030
PAG
31+
AugmentedGraph
32+
IPAG
33+
PsiPAG
3134

3235
Algorithms for Markov Equivalence Classes
3336
=========================================

docs/conf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def setup(app):
8080
autosummary_generate = True
8181
autodoc_default_options = {
8282
"inherited-members": False,
83+
"private-members": False,
8384
}
8485
autodoc_inherit_docstrings = False
8586
# autodoc_typehints = "signature"
@@ -354,3 +355,15 @@ def setup(app):
354355
('py:obj', r'pywhy_graphs.*timeseries.*'),
355356
('py:obj', r"networkx*"),
356357
]
358+
359+
360+
# -- Other extension configuration -------------------------------------------
361+
362+
linkcheck_request_headers = dict(
363+
user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
364+
) # noqa: E501
365+
linkcheck_anchors = False # saves a bit of time
366+
linkcheck_timeout = 15 # some can be quite slow
367+
linkcheck_ignore = [
368+
"https://github.com/{group}/{project}/pull/", # sphinx-issues will render this properly
369+
]

docs/references.bib

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ @article{Gamez2011
4545
doi = {10.1007/s10618-010-0178-6}
4646
}
4747

48+
@article{Jaber2020causal,
49+
title={Causal discovery from soft interventions with unknown targets: Characterization and learning},
50+
author={Jaber, Amin and Kocaoglu, Murat and Shanmugam, Karthikeyan and Bareinboim, Elias},
51+
journal={Advances in neural information processing systems},
52+
volume={33},
53+
pages={9551--9561},
54+
year={2020}
55+
}
56+
57+
@article{Kocaoglu2019characterization,
58+
title={Characterization and learning of causal graphs with latent variables from soft interventions},
59+
author={Kocaoglu, Murat and Jaber, Amin and Shanmugam, Karthikeyan and Bareinboim, Elias},
60+
journal={Advances in Neural Information Processing Systems},
61+
volume={32},
62+
year={2019}
63+
}
64+
65+
4866
@article{gerhardus2021characterization,
4967
title = {Characterization of causal ancestral graphs for time series with latent confounders},
5068
author = {Gerhardus, Andreas},
@@ -109,6 +127,15 @@ @book{Neapolitan2003
109127
doi = {10.1145/1327942.1327961}
110128
}
111129

130+
@article{pearl_aspects_1993,
131+
title = {Aspects of graphical models connected with causality},
132+
journal = {Proceedings of the 49th Session of the International Statistical Institute},
133+
author = {Pearl, Judea},
134+
year = {1993},
135+
pages = {399--401},
136+
file = {R195-LL.pdf:/Users/adam2392/Zotero/storage/F5RI5D8V/R195-LL.pdf:application/pdf},
137+
}
138+
112139
@book{Pearl_causality_2009,
113140
author = {Pearl, Judea},
114141
title = {Causality: Models, Reasoning and Inference},

docs/whats_new/v0.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Changelog
3838
- |Feature| Adding a layout for the nodes positions in the :func:`pywhy_graphs.viz.draw` function, by `Julien Siebert`_ (:pr:`26`)
3939
- |Feature| Add :class:`pywhy_graphs.networkx.MixedEdgeGraph` for mixed-edge graphs, by `Adam Li`_ (:pr:`29`)
4040
- |MajorFeature| Implement a series of graph classes for time-series graphs, such as ``pywhy_graphs.classes.timeseries.StationaryTimeSeriesMixedEdgeGraph``, by `Adam Li`_ (:pr:`21`)
41+
- |MajorFeature| Implement a series of graph classes for modeling interventions, such as :class:`pywhy_graphs.AugmentedGraph`, by `Adam Li`_ (:pr:`49`)
4142

4243
Code and Documentation Contributors
4344
-----------------------------------

pywhy_graphs/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
ADMG,
44
CPDAG,
55
PAG,
6+
AugmentedGraph,
7+
IPAG,
8+
PsiPAG,
69
StationaryTimeSeriesGraph,
710
StationaryTimeSeriesDiGraph,
811
StationaryTimeSeriesMixedEdgeGraph,

pywhy_graphs/algorithms/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def _check_adding_pag_edge(graph: PAG, u_of_edge: Node, v_of_edge: Node, edge_ty
206206
):
207207
raise_error = True
208208
elif edge_type == EdgeType.DIRECTED.value:
209-
# there should not be a circle edge, or a bidirected edge
209+
# there should not be a circle edge in the same direction, or a bidirected edge
210210
if graph.has_edge(u_of_edge, v_of_edge, graph.circle_edge_name) or graph.has_edge(
211211
u_of_edge, v_of_edge, graph.bidirected_edge_name
212212
):

pywhy_graphs/algorithms/pag.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ def pds(
544544
545545
If Y is a triangle, then it will be uncertain with circular edges
546546
due to the fact that it is a shielded triple, not allowing us to infer
547-
that it is a collider. These are defined in :footcite:`Colombo2012`.
547+
that it is a collider. These are defined in :footcite:`Colombo2012`
548+
and :footcite:`Spirtes1993`.
548549
549550
References
550551
----------

pywhy_graphs/classes/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from . import timeseries
22
from .admg import ADMG
33
from .cpdag import CPDAG
4+
from .intervention import IPAG, AugmentedGraph, PsiPAG
45
from .pag import PAG
56
from .timeseries import (
67
StationaryTimeSeriesCPDAG,

pywhy_graphs/classes/admg.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,32 @@ class ADMG(pywhy_nx.MixedEdgeGraph, AncestralMixin):
4242
4343
Notes
4444
-----
45+
**Edge Type Subgraphs**
46+
4547
The data structure underneath the hood is stored in two networkx graphs:
4648
``networkx.Graph`` and ``networkx.DiGraph`` to represent the non-directed
4749
edges and directed edges. Non-directed edges in an ADMG can be present as
4850
bidirected edges standing for latent confounders, or undirected edges
4951
standing for selection bias.
5052
51-
- Normal directed edges (<-, ->, indicating causal relationship) = `networkx.DiGraph`
53+
- Directed edges (<-, ->, indicating causal relationship) = `networkx.DiGraph`
54+
The subgraph of directed edges may be accessed by the
55+
`ADMG.sub_directed_graph`. Their edges in networkx format can be
56+
accessed by `ADMG.directed_edges` and the corresponding name of the
57+
edge type by `ADMG.directed_edge_name`.
5258
- Bidirected edges (<->, indicating latent confounder) = `networkx.Graph`
59+
The subgraph of bidirected edges may be accessed by the
60+
`ADMG.sub_bidirected_graph`. Their edges in networkx format can be
61+
accessed by `ADMG.bidirected_edges` and the corresponding name of the
62+
edge type by `ADMG.bidirected_edge_name`.
5363
- Undirected edges (--, indicating selection bias) = `networkx.Graph`
64+
The subgraph of undirected edges may be accessed by the
65+
`ADMG.sub_undirected_graph`. Their edges in networkx format can be
66+
accessed by `ADMG.undirected_edges` and the corresponding name of the
67+
edge type by `ADMG.undirected_edge_name`.
68+
69+
By definition, no cycles may exist due to the directed edges. However, beyond
70+
that multiple types of edges between the same pairs of nodes are possible.
5471
"""
5572

5673
def __init__(

pywhy_graphs/classes/cpdag.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ class CPDAG(pywhy_nx.MixedEdgeGraph, AncestralMixin, ConservativeMixin):
4646
(such as the PC algorithm) approaches for causal structure learning.
4747
4848
One should not use CPDAGs if they suspect their data has unobserved latent confounders.
49+
50+
**Edge Type Subgraphs**
51+
52+
The data structure underneath the hood is stored in two networkx graphs:
53+
``networkx.Graph`` and ``networkx.DiGraph`` to represent the non-directed
54+
edges and directed edges. Non-directed edges in an CPDAG can be present as
55+
undirected edges standing for uncertainty in which directino the directed
56+
edge is in.
57+
58+
- Directed edges (<-, ->, indicating causal relationship) = `networkx.DiGraph`
59+
The subgraph of directed edges may be accessed by the
60+
`CPDAG.sub_directed_graph`. Their edges in networkx format can be
61+
accessed by `CPDAG.directed_edges` and the corresponding name of the
62+
edge type by `CPDAG.directed_edge_name`.
63+
- Undirected edges (--, indicating uncertainty) = `networkx.Graph`
64+
The subgraph of undirected edges may be accessed by the
65+
`CPDAG.sub_undirected_graph`. Their edges in networkx format can be
66+
accessed by `CPDAG.undirected_edges` and the corresponding name of the
67+
edge type by `CPDAG.undirected_edge_name`.
68+
69+
By definition, no cycles may exist due to the directed edges.
4970
"""
5071

5172
def __init__(

0 commit comments

Comments
 (0)