Skip to content

Commit

Permalink
[ENH] Consistent extension sampling of CPDAG, PDAG and DAG (#102)
Browse files Browse the repository at this point in the history
* Add sampling a consistent extension of a CPDAG/PDAG
* Also enable conversion from DAG to CPDAG

---------

Signed-off-by: Adam Li <[email protected]>
  • Loading branch information
adam2392 authored Dec 6, 2023
1 parent 9c6a556 commit ed4cb7f
Show file tree
Hide file tree
Showing 13 changed files with 630 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ jobs:
if: "matrix.os == 'ubuntu'"
shell: bash
run: |
sudo apt-get update
sudo apt-get install nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc
- name: Run pytest # headless via Xvfb on linux
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ To install the package from github, clone the repository and then `cd` into the

Pywhy-Graphs is always looking for new contributors to help make the package better, whether it is algorithms, documentation, examples of graph usage, and more! Contributing to Pywhy-Graphs will be rewarding because you will contribute to a much needed package for causal inference.

See our [contributing guide](https://github.com/py-why/pywhy-graphs/CONTRIBUTING.md) for more details.
See our [contributing guide](https://github.com/py-why/pywhy-graphs/blob/main/CONTRIBUTING.md) for more details.

# Citing

Expand Down
20 changes: 20 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ causal graph operations.
is_semi_directed_path
all_semi_directed_paths

:mod:`pywhy_graphs.algorithms`: Algorithms for dealing with CPDAGs
==================================================================
With Markov equivalence classes of DAGs in a Markovian SCM setting, we obtain
a potentially directed acyclic graph (PDAG), which may be completed (CPDAG).
We may want to generate a consistent DAG extension (i.e. Markov equivalent) of a CPDAG
then we may use some of the algorithms described here. Or perhaps one may want to
convert a DAG to its corresponding CPDAG.

.. currentmodule:: pywhy_graphs.algorithms

.. autosummary::
:toctree: generated/

pdag_to_dag
dag_to_cpdag
pdag_to_cpdag
order_edges
label_edges


Conversions between other package's causal graphs
=================================================
Other packages, such as `causal-learn <https://github.com/cmu-phil/causal-learn>`_,
Expand Down
8 changes: 5 additions & 3 deletions doc/installation.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Installation
============

**pywhy-graphs** supports Python >= 3.8.
**pywhy-graphs** closely follows the NetworkX dependencies and thus supports Python >= 3.9.

## Installing with ``pip``
Installing with ``pip``
-----------------------

**pywhy-graphs** is available [on PyPI](https://pypi.org/project/pywhy-graphs/). Just run

Expand All @@ -12,7 +13,8 @@ Installation
# or if you use poetry which is recommended
poetry add pywhy-graphs

## Installing from source
Installing from source
----------------------

To install **pywhy-graphs** from source, first clone [the repository](https://github.com/py-why/pywhy-graphs):

Expand Down
10 changes: 10 additions & 0 deletions doc/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ @article{bareinboim_causal_2016
pages = {7345--7352}
}

@article{chickering2002learning,
title = {Learning equivalence classes of Bayesian-network structures},
author = {Chickering, David Maxwell},
journal = {The Journal of Machine Learning Research},
volume = {2},
pages = {445--498},
year = {2002},
publisher = {JMLR}
}

@article{Colombo2012,
author = {Diego Colombo and Marloes H. Maathuis and Markus Kalisch and Thomas S. Richardson},
title = {{Learning high-dimensional directed acyclic graphs with latent and selection variables}},
Expand Down
1 change: 1 addition & 0 deletions doc/whats_new/v0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Changelog
- |Feature| Implement and test functions to convert a PAG to MAG, by `Aryan Roy`_ (:pr:`93`)
- |API| Remove support for Python 3.8 by `Adam Li`_ (:pr:`99`)
- |Feature| Implement a suite of functions for finding and checking semi-directed paths on a mixed-edge graph, by `Adam Li`_ (:pr:`101`)
- |Feature| Implement functions for converting between a DAG and PDAG and CPDAG for generating consistent extensions of a CPDAG for example. These functions are :func:`pywhy_graphs.algorithms.pdag_to_cpdag`, :func:`pywhy_graphs.algorithms.pdag_to_dag` and :func:`pywhy_graphs.algorithms.dag_to_cpdag`, by `Adam Li`_ (:pr:`102`)

Code and Documentation Contributors
-----------------------------------
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude_dirs = ["tests"]

[tool.black]
line-length = 100
target-version = ['py38']
target-version = ['py39']
include = '\.pyi?$'
extend-exclude = '''
(
Expand Down Expand Up @@ -102,10 +102,10 @@ readme = "README.md"
classifiers = [
'Development Status :: 4 - Beta',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11'
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12'
]
keywords = ['causality', 'graphs', 'causal-inference', 'graphical-model']

Expand Down
1 change: 1 addition & 0 deletions pywhy_graphs/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .cpdag import * # noqa: F403
from .cyclic import * # noqa: F403
from .generic import * # noqa: F403
from .multidomain import * # noqa: F403
Expand Down
Loading

0 comments on commit ed4cb7f

Please sign in to comment.