Skip to content

Commit 2d6f1d3

Browse files
authored
[ENH] Adding multi-domain functional linear graph and fix bug related to drawing causal graphs (#77)
* Adding multi-domain linear func graph * Adding user-guide doc for functional graphical models's * Refactoring the augmented graph * Update poetry to v1.5 * Fix bug in draw for CPDAG and casual graphs that draw edges between node and its descendants --------- Signed-off-by: Adam Li <[email protected]>
1 parent 3de911e commit 2d6f1d3

24 files changed

+1250
-254
lines changed

.circleci/config.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- run:
4747
name: Install the latest version of Poetry
4848
command: |
49-
curl -sSL https://install.python-poetry.org | python3 - --version 1.3.0
49+
curl -sSL https://install.python-poetry.org | python3 - --version 1.5.0
5050
poetry --version
5151
- run:
5252
name: Set BASH_ENV
@@ -64,10 +64,11 @@ jobs:
6464
- run:
6565
name: Install pysal dependencies
6666
command: |
67-
sudo apt install libspatialindex-dev xdg-utils
67+
sudo apt install libspatialindex-dev xdg-utils shared-mime-info
6868
- run:
6969
name: Setup pandoc
7070
command: sudo apt update && sudo apt install -y pandoc optipng
71+
7172
- python/install-packages:
7273
pkg-manager: poetry
7374
cache-version: "v1" # change to clear cache

docs/api.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ graphs encountered in the literature.
2929
CPDAG
3030
PAG
3131
AugmentedGraph
32-
IPAG
33-
PsiPAG
32+
AugmentedPAG
3433

3534
:mod:`pywhy_graphs.algorithms`: Algorithms for Mixed-Edge Graphs
3635
================================================================
@@ -55,6 +54,9 @@ causal graph operations.
5554
uncovered_pd_path
5655
acyclification
5756
is_definite_noncollider
57+
find_connected_pairs
58+
add_all_snode_combinations
59+
compute_invariant_domains_per_node
5860

5961
Conversions between other package's causal graphs
6062
=================================================
@@ -158,6 +160,9 @@ linear structural equation Gaussian models (SEMs).
158160
:toctree: generated/
159161

160162
make_graph_linear_gaussian
163+
apply_linear_soft_intervention
164+
set_node_attributes_with_G
165+
make_graph_multidomain
161166

162167
Visualization of causal graphs
163168
==============================

docs/reference/classes/index.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ the addition of "F-nodes", which represent interventions :footcite:`pearl1993asp
4949
+===================+==========================================+==============+
5050
| AugmentedGraph | directed, undirected, bidirected | Yes |
5151
+-------------------+------------------------------------------+--------------+
52-
| IPAG | directed, undirected, bidirected, circle | Yes |
53-
+-------------------+------------------------------------------+--------------+
54-
| PsiPAG | directed, undirected, bidirected, circle | No |
52+
| AugmentedPAG | directed, undirected, bidirected, circle | Yes |
5553
+-------------------+------------------------------------------+--------------+
5654

5755
Finally, we also support time-series and create graphs that represent

docs/reference/functional/index.rst

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
.. _functional-causal-graphical-models:
2+
3+
**********************************
4+
Functional Causal Graphical Models
5+
**********************************
6+
7+
.. automodule:: pywhy_graphs.functional
8+
:no-members:
9+
:no-inherited-members:
10+
11+
Pywhy-graphs provides a layer to convert imbue causal graphs with a data-generating
12+
model. Currently, we only support linear models, but we plan to support non-linear
13+
and we also do not support latent confounders yet.
14+
15+
To add a latent confounder, one can add a confounder explicitly, generate the data
16+
and then drop the confounder varialble in the final dataset. In the roadmap of this submodule,
17+
the plan is to represent any bidirected edge as a uniformly randomly distributed variable
18+
that has an additive noise effect on both variables simulatanously.
19+
20+
Linear
21+
======
22+
23+
In order to represent linear functions, we imbue nodes with a set of node attributes:
24+
25+
- ``parent_functions``: a mapping of functions that map each node to a nested dictionary
26+
of parents and their corresponding weight and function that map parent values to
27+
values that are input to the node value with the weight.
28+
- ``gaussian_noise_function``: a dictionary with keys ``mean`` and ``std`` that
29+
encodes the data-generating function for the Gaussian noise.
30+
31+
For example, if the node
32+
is :math:`X` and its parents are :math:`Y` and :math:`Z`, then ``parent_functions``
33+
and ``gaussian_noise_function`` for node :math:`X` is:
34+
35+
.. code-block:: python
36+
37+
{
38+
'X': {
39+
'parent_functions': {
40+
'Y': {
41+
'weight': <weight of Y added to X>,
42+
'func': <function that takes input Y>,
43+
},
44+
'Z': {
45+
'weight': <weight of Z added to X>,
46+
'func': <function that takes input Z>,
47+
},
48+
},
49+
'gaussian_noise_function': {
50+
'mean': <mean of gaussian noise added to X>,
51+
'std': <std of gaussian noise added to X>,
52+
}
53+
}
54+
}
55+
56+
Linear functional graphs
57+
========================
58+
.. currentmodule:: pywhy_graphs.functional
59+
60+
.. autosummary::
61+
:toctree: ../../generated/
62+
63+
make_graph_linear_gaussian
64+
apply_linear_soft_intervention
65+
66+
Multidomain
67+
===========
68+
69+
Currently, this submodule only supports linear functions.
70+
71+
Multiple-domain causal graphs are represented by selection diagrams :footcite:`bareinboim_causal_2016`,
72+
or augmented selection diagrams (TODO: CITATION FOR LEARNING SEL DIAGRAMS).
73+
74+
In order to represent multidomain functions, we imbue nodes with a set of node attributes
75+
in addition to the ones for linear functions. The nodes that are imbued with extra attributes
76+
are the direct children of an S-node.
77+
78+
- ``invariant_domains``: a list of domain IDs that are invariant for this node.
79+
- ``domain_gaussian_noise_function``: a dictionary with keys ``mean`` and ``std`` that
80+
encodes the data-generating function for the Gaussian noise for each non-invariant domain.
81+
82+
.. code-block:: python
83+
84+
{
85+
'X': {
86+
'domain_gaussian_noise_function': {
87+
<domain_id>: {
88+
'mean': <mean of gaussian noise added to X>,
89+
'std': <std of gaussian noise added to X>,
90+
},
91+
'invariant_domains': [<domain_id>, ...],
92+
}
93+
}
94+
}
95+
96+
Linear functional selection diagrams
97+
====================================
98+
.. currentmodule:: pywhy_graphs.functional
99+
100+
.. autosummary::
101+
:toctree: ../../generated/
102+
103+
make_graph_multidomain

docs/references.bib

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
% Encoding: UTF-8
22
% Try to keep this list in alphabetical order based on citing name
33
4+
5+
@article{bareinboim_causal_2016,
6+
title = {Causal inference and the data-fusion problem},
7+
volume = {113},
8+
url = {https://www.pnas.org/content/113/27/7345},
9+
doi = {10.1073/PNAS.1510507113},
10+
number = {27},
11+
journal = {Proceedings of the National Academy of Sciences},
12+
author = {Bareinboim, Elias and Pearl, Judea},
13+
month = jul,
14+
year = {2016},
15+
note = {Publisher: National Academy of Sciences},
16+
keywords = {Causal inference, Counterfactuals, External validity, Selection bias, Transportability},
17+
pages = {7345--7352},
18+
}
19+
420
@article{Colombo2012,
521
author = {Diego Colombo and Marloes H. Maathuis and Markus Kalisch and Thomas S. Richardson},
622
title = {{Learning high-dimensional directed acyclic graphs with latent and selection variables}},

docs/user_guide.rst

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ User Guide
1515
:maxdepth: 2
1616

1717
reference/classes/index
18+
reference/functional/index
1819
reference/algorithms/index
1920
reference/simulation/index
2021
reference/export/index

docs/whats_new/v0.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Changelog
4444
- |Feature| Implement export/import functions to go to/from pywhy-graphs to ananke-causal, by `Jaron Lee`_ (:pr:`63`)
4545
- |Feature| Implement pre-commit hooks for development, by `Jaron Lee`_ (:pr:`68`)
4646
- |Feature| Implement a new submodule for converting graphs to a functional model, with :func:`pywhy_graphs.functional.make_graph_linear_gaussian`, by `Adam Li`_ (:pr:`75`)
47+
- |Feature| Implement a multidomain linear functional graph, with :func:`pywhy_graphs.functional.make_graph_multidomain`, by `Adam Li`_ (:pr:`77`)
4748

4849
Code and Documentation Contributors
4950
-----------------------------------

0 commit comments

Comments
 (0)