y0


Namey0 JSON
Version 0.2.10 PyPI version JSON
download
home_pagehttps://github.com/y0-causal-inference/y0
SummaryPython code for causal modeling.
upload_time2024-04-25 08:23:27
maintainerCharles Tapley Hoyt
docs_urlNone
authorJeremy Zucker
requires_python>=3.10
licenseBSD-3-Clause
keywords cthoyt cookiecutter structural causal modeling
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="docs/source/logo.png" height="120">
</p>

<h1 align="center">
  y0
</h1>

<p align="center">
    <a href="https://github.com/y0-causal-inference/y0/actions?query=workflow%3ATests">
        <img alt="Tests" src="https://github.com/y0-causal-inference/y0/workflows/Tests/badge.svg" />
    </a>
   <a href="https://github.com/cthoyt/cookiecutter-python-package">
      <img alt="Cookiecutter template from @cthoyt" src="https://img.shields.io/badge/Cookiecutter-snekpack-blue" /> 
   </a>
    <a href="https://pypi.org/project/y0">
        <img alt="PyPI" src="https://img.shields.io/pypi/v/y0" />
    </a>
    <a href="https://pypi.org/project/y0">
        <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/y0" />
    </a>
    <a href="https://github.com/y0-causal-inference/y0/blob/main/LICENSE">
        <img alt="PyPI - License" src="https://img.shields.io/pypi/l/y0" />
    </a>
    <a href='https://y0.readthedocs.io/en/latest/?badge=latest'>
        <img src='https://readthedocs.org/projects/y0/badge/?version=latest' alt='Documentation Status' />
    </a>
    <a href="https://zenodo.org/badge/latestdoi/328745468">
        <img src="https://zenodo.org/badge/328745468.svg" alt="DOI">
    </a>
    <a href="https://github.com/psf/black">
        <img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black" />
    </a>
</p>

`y0` (pronounced "why not?") is Python code for causal inference.

## 💪 Getting Started

### Representing Probability Expressions

`y0` has a fully featured internal domain specific language for representing
probability expressions:

```python
from y0.dsl import P, A, B

# The probability of A given B
expr_1 = P(A | B)

# The probability of A given not B
expr_2 = P(A | ~B)

# The joint probability of A and B
expr_3 = P(A, B)
```

It can also be used to manipulate expressions:

```python
from y0.dsl import P, A, B, Sum

P(A, B).marginalize(A) == Sum[A](P(A, B))
P(A, B).conditional(A) == P(A, B) / Sum[A](P(A, B))
```

DSL objects can be converted into strings with `str()` and parsed back
using `y0.parser.parse_y0()`.

A full demo of the DSL can be found in this
[Jupyter Notebook](https://github.com/y0-causal-inference/y0/blob/main/notebooks/DSL%20Demo.ipynb)

### Representing Causality

`y0` has a notion of acyclic directed mixed graphs built on top of
`networkx` that can be used to model causality:

```python
from y0.graph import NxMixedGraph
from y0.dsl import X, Y, Z1, Z2

# Example from:
#   J. Pearl and D. Mackenzie (2018)
#   The Book of Why: The New Science of Cause and Effect.
#   Basic Books, p. 240.
napkin = NxMixedGraph.from_edges(
    directed=[
        (Z2, Z1),
        (Z1, X),
        (X, Y),
    ],
    undirected=[
        (Z2, X),
        (Z2, Y),
    ],
)
```

`y0` has many pre-written examples in `y0.examples` from Pearl, Shpitser,
Bareinboim, and others.

### do Calculus

`y0` provides _actual_ implementations of many algorithms that have remained
unimplemented for the last 15 years of publications including:

| Algorithm          | Reference                                                                   |
|--------------------|-----------------------------------------------------------------------------|
| ID                 | [Shpitser and Pearl, 2006](https://dl.acm.org/doi/10.5555/1597348.1597382)  |
| IDC                | [Shpitser and Pearl, 2008](https://www.jmlr.org/papers/v9/shpitser08a.html) |
| ID*                | [Shpitser and Pearl, 2012](https://arxiv.org/abs/1206.5294)                 |
| IDC*               | [Shpitser and Pearl, 2012](https://arxiv.org/abs/1206.5294)                 |
| Surrogate Outcomes | [Tikka and Karvanen, 2018](https://arxiv.org/abs/1806.07172)                |

Apply an algorithm to an ADMG and a causal query to generate an estimand
represented in the DSL like:

```python
from y0.dsl import P, X, Y
from y0.examples import napkin
from y0.algorithm.identify import Identification, identify

# TODO after ID* and IDC* are done, we'll update this interface
query = Identification.from_expression(graph=napkin, query=P(Y @ X))
estimand = identify(query)
assert estimand == P(Y @ X)
```

## 🚀 Installation

The most recent release can be installed from
[PyPI](https://pypi.org/project/y0/) with:

```bash
$ pip install y0
```

The most recent code and data can be installed directly from GitHub with:

```bash
$ pip install git+https://github.com/y0-causal-inference/y0.git
```

## 👐 Contributing

Contributions, whether filing an issue, making a pull request, or forking, are appreciated. See
[CONTRIBUTING.md](https://github.com/y0-causal-inference/y0/blob/master/.github/CONTRIBUTING.md) for more information on getting
involved.

## 👋 Attribution

### ⚖️ License

The code in this package is licensed under the [BSD-3-Clause
license](https://github.com/y0-causal-inference/y0/blob/master/LICENSE).

### 📖 Citation

Before we publish an application note on `y0`, you can cite this software
via our Zenodo record (also see the badge above):

```bibtex
@software{y0,
  author       = {Charles Tapley Hoyt and
                  Jeremy Zucker and
                  Marc-Antoine Parent},
  title        = {y0-causal-inference/y0},
  month        = jun,
  year         = 2021,
  publisher    = {Zenodo},
  version      = {v0.1.0},
  doi          = {10.5281/zenodo.4950768},
  url          = {https://doi.org/10.5281/zenodo.4950768}
}
```

### 🙏 Supporters

This project has been supported by several organizations (in alphabetical order):

- [Harvard Program in Therapeutic Science - Laboratory of Systems Pharmacology](https://hits.harvard.edu/the-program/laboratory-of-systems-pharmacology/)
- [Pacific Northwest National Laboratory](https://www.pnnl.org/)

### 💰 Funding

The development of the Y0 Causal Inference Engine has been funded by the following grants:

| Funding Body                                             | Program                                                                                                                       | Grant           |
|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------|
| DARPA                                                    | [Automating Scientific Knowledge Extraction (ASKE)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction) | HR00111990009   |
| PNNL Data Model Convergence Initiative    | [Causal Inference and Machine Learning Methods for Analysis of Security Constrained Unit Commitment (SCY0)](https://www.pnnl.gov/projects/dmc/converged-applications-projects) | 90001   |
| DARPA                                                    |  [Automating Scientific Knowledge Extraction and Modeling (ASKEM)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction-and-modeling) |  HR00112220036  |

### 🍪 Cookiecutter

This package was created with [@audreyfeldroy](https://github.com/audreyfeldroy)'s
[cookiecutter](https://github.com/cookiecutter/cookiecutter) package using [@cthoyt](https://github.com/cthoyt)'s
[cookiecutter-python-package](https://github.com/cthoyt/cookiecutter-python-package) template.

## 🛠️ Development

<details>
  <summary>See developer instructions</summary>

The final section of the README is for if you want to get involved by making a code contribution.

### Developer Installation

To install in development mode, use the following:

```bash
$ git clone git+https://github.com/y0-causal-inference/y0.git
$ cd y0
$ pip install -e .
```

### ❓ Testing

After cloning the repository and installing `tox` with `pip install tox`, the unit tests in the `tests/` folder can be
run reproducibly with:

```shell
$ tox
```

Additionally, these tests are automatically re-run with each commit in a [GitHub Action](https://github.com/y0-causal-inference/y0/actions?query=workflow%3ATests).

### 📦 Making a Release

After installing the package in development mode and installing
`tox` with `pip install tox`, the commands for making a new release are contained within the `finish` environment
in `tox.ini`. Run the following from the shell:

```shell
$ tox -e finish
```

This script does the following:

1. Uses BumpVersion to switch the version number in the `setup.cfg` and
   `src/y0/version.py` to not have the `-dev` suffix
2. Packages the code in both a tar archive and a wheel
3. Uploads to PyPI using `twine`. Be sure to have a `.pypirc` file configured to avoid the need for manual input at this
   step
4. Push to GitHub. You'll need to make a release going with the commit where the version was bumped.
5. Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can
   use `tox -e bumpversion minor` after.

</details>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/y0-causal-inference/y0",
    "name": "y0",
    "maintainer": "Charles Tapley Hoyt",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "cthoyt@gmail.com",
    "keywords": "cthoyt, cookiecutter, structural causal modeling",
    "author": "Jeremy Zucker",
    "author_email": "jeremy.zucker@pnnl.gov",
    "download_url": "https://files.pythonhosted.org/packages/2b/31/365528b96ac8b90410eeade26302cdae23003a25a167cd62243234eed319/y0-0.2.10.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"docs/source/logo.png\" height=\"120\">\n</p>\n\n<h1 align=\"center\">\n  y0\n</h1>\n\n<p align=\"center\">\n    <a href=\"https://github.com/y0-causal-inference/y0/actions?query=workflow%3ATests\">\n        <img alt=\"Tests\" src=\"https://github.com/y0-causal-inference/y0/workflows/Tests/badge.svg\" />\n    </a>\n   <a href=\"https://github.com/cthoyt/cookiecutter-python-package\">\n      <img alt=\"Cookiecutter template from @cthoyt\" src=\"https://img.shields.io/badge/Cookiecutter-snekpack-blue\" /> \n   </a>\n    <a href=\"https://pypi.org/project/y0\">\n        <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/y0\" />\n    </a>\n    <a href=\"https://pypi.org/project/y0\">\n        <img alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/y0\" />\n    </a>\n    <a href=\"https://github.com/y0-causal-inference/y0/blob/main/LICENSE\">\n        <img alt=\"PyPI - License\" src=\"https://img.shields.io/pypi/l/y0\" />\n    </a>\n    <a href='https://y0.readthedocs.io/en/latest/?badge=latest'>\n        <img src='https://readthedocs.org/projects/y0/badge/?version=latest' alt='Documentation Status' />\n    </a>\n    <a href=\"https://zenodo.org/badge/latestdoi/328745468\">\n        <img src=\"https://zenodo.org/badge/328745468.svg\" alt=\"DOI\">\n    </a>\n    <a href=\"https://github.com/psf/black\">\n        <img src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Code style: black\" />\n    </a>\n</p>\n\n`y0` (pronounced \"why not?\") is Python code for causal inference.\n\n## \ud83d\udcaa Getting Started\n\n### Representing Probability Expressions\n\n`y0` has a fully featured internal domain specific language for representing\nprobability expressions:\n\n```python\nfrom y0.dsl import P, A, B\n\n# The probability of A given B\nexpr_1 = P(A | B)\n\n# The probability of A given not B\nexpr_2 = P(A | ~B)\n\n# The joint probability of A and B\nexpr_3 = P(A, B)\n```\n\nIt can also be used to manipulate expressions:\n\n```python\nfrom y0.dsl import P, A, B, Sum\n\nP(A, B).marginalize(A) == Sum[A](P(A, B))\nP(A, B).conditional(A) == P(A, B) / Sum[A](P(A, B))\n```\n\nDSL objects can be converted into strings with `str()` and parsed back\nusing `y0.parser.parse_y0()`.\n\nA full demo of the DSL can be found in this\n[Jupyter Notebook](https://github.com/y0-causal-inference/y0/blob/main/notebooks/DSL%20Demo.ipynb)\n\n### Representing Causality\n\n`y0` has a notion of acyclic directed mixed graphs built on top of\n`networkx` that can be used to model causality:\n\n```python\nfrom y0.graph import NxMixedGraph\nfrom y0.dsl import X, Y, Z1, Z2\n\n# Example from:\n#   J. Pearl and D. Mackenzie (2018)\n#   The Book of Why: The New Science of Cause and Effect.\n#   Basic Books, p. 240.\nnapkin = NxMixedGraph.from_edges(\n    directed=[\n        (Z2, Z1),\n        (Z1, X),\n        (X, Y),\n    ],\n    undirected=[\n        (Z2, X),\n        (Z2, Y),\n    ],\n)\n```\n\n`y0` has many pre-written examples in `y0.examples` from Pearl, Shpitser,\nBareinboim, and others.\n\n### do Calculus\n\n`y0` provides _actual_ implementations of many algorithms that have remained\nunimplemented for the last 15 years of publications including:\n\n| Algorithm          | Reference                                                                   |\n|--------------------|-----------------------------------------------------------------------------|\n| ID                 | [Shpitser and Pearl, 2006](https://dl.acm.org/doi/10.5555/1597348.1597382)  |\n| IDC                | [Shpitser and Pearl, 2008](https://www.jmlr.org/papers/v9/shpitser08a.html) |\n| ID*                | [Shpitser and Pearl, 2012](https://arxiv.org/abs/1206.5294)                 |\n| IDC*               | [Shpitser and Pearl, 2012](https://arxiv.org/abs/1206.5294)                 |\n| Surrogate Outcomes | [Tikka and Karvanen, 2018](https://arxiv.org/abs/1806.07172)                |\n\nApply an algorithm to an ADMG and a causal query to generate an estimand\nrepresented in the DSL like:\n\n```python\nfrom y0.dsl import P, X, Y\nfrom y0.examples import napkin\nfrom y0.algorithm.identify import Identification, identify\n\n# TODO after ID* and IDC* are done, we'll update this interface\nquery = Identification.from_expression(graph=napkin, query=P(Y @ X))\nestimand = identify(query)\nassert estimand == P(Y @ X)\n```\n\n## \ud83d\ude80 Installation\n\nThe most recent release can be installed from\n[PyPI](https://pypi.org/project/y0/) with:\n\n```bash\n$ pip install y0\n```\n\nThe most recent code and data can be installed directly from GitHub with:\n\n```bash\n$ pip install git+https://github.com/y0-causal-inference/y0.git\n```\n\n## \ud83d\udc50 Contributing\n\nContributions, whether filing an issue, making a pull request, or forking, are appreciated. See\n[CONTRIBUTING.md](https://github.com/y0-causal-inference/y0/blob/master/.github/CONTRIBUTING.md) for more information on getting\ninvolved.\n\n## \ud83d\udc4b Attribution\n\n### \u2696\ufe0f License\n\nThe code in this package is licensed under the [BSD-3-Clause\nlicense](https://github.com/y0-causal-inference/y0/blob/master/LICENSE).\n\n### \ud83d\udcd6 Citation\n\nBefore we publish an application note on `y0`, you can cite this software\nvia our Zenodo record (also see the badge above):\n\n```bibtex\n@software{y0,\n  author       = {Charles Tapley Hoyt and\n                  Jeremy Zucker and\n                  Marc-Antoine Parent},\n  title        = {y0-causal-inference/y0},\n  month        = jun,\n  year         = 2021,\n  publisher    = {Zenodo},\n  version      = {v0.1.0},\n  doi          = {10.5281/zenodo.4950768},\n  url          = {https://doi.org/10.5281/zenodo.4950768}\n}\n```\n\n### \ud83d\ude4f Supporters\n\nThis project has been supported by several organizations (in alphabetical order):\n\n- [Harvard Program in Therapeutic Science - Laboratory of Systems Pharmacology](https://hits.harvard.edu/the-program/laboratory-of-systems-pharmacology/)\n- [Pacific Northwest National Laboratory](https://www.pnnl.org/)\n\n### \ud83d\udcb0 Funding\n\nThe development of the Y0 Causal Inference Engine has been funded by the following grants:\n\n| Funding Body                                             | Program                                                                                                                       | Grant           |\n|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------|\n| DARPA                                                    | [Automating Scientific Knowledge Extraction (ASKE)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction) | HR00111990009   |\n| PNNL Data Model Convergence Initiative    | [Causal Inference and Machine Learning Methods for Analysis of Security Constrained Unit Commitment (SCY0)](https://www.pnnl.gov/projects/dmc/converged-applications-projects) | 90001   |\n| DARPA                                                    |  [Automating Scientific Knowledge Extraction and Modeling (ASKEM)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction-and-modeling) |  HR00112220036  |\n\n### \ud83c\udf6a Cookiecutter\n\nThis package was created with [@audreyfeldroy](https://github.com/audreyfeldroy)'s\n[cookiecutter](https://github.com/cookiecutter/cookiecutter) package using [@cthoyt](https://github.com/cthoyt)'s\n[cookiecutter-python-package](https://github.com/cthoyt/cookiecutter-python-package) template.\n\n## \ud83d\udee0\ufe0f Development\n\n<details>\n  <summary>See developer instructions</summary>\n\nThe final section of the README is for if you want to get involved by making a code contribution.\n\n### Developer Installation\n\nTo install in development mode, use the following:\n\n```bash\n$ git clone git+https://github.com/y0-causal-inference/y0.git\n$ cd y0\n$ pip install -e .\n```\n\n### \u2753 Testing\n\nAfter cloning the repository and installing `tox` with `pip install tox`, the unit tests in the `tests/` folder can be\nrun reproducibly with:\n\n```shell\n$ tox\n```\n\nAdditionally, these tests are automatically re-run with each commit in a [GitHub Action](https://github.com/y0-causal-inference/y0/actions?query=workflow%3ATests).\n\n### \ud83d\udce6 Making a Release\n\nAfter installing the package in development mode and installing\n`tox` with `pip install tox`, the commands for making a new release are contained within the `finish` environment\nin `tox.ini`. Run the following from the shell:\n\n```shell\n$ tox -e finish\n```\n\nThis script does the following:\n\n1. Uses BumpVersion to switch the version number in the `setup.cfg` and\n   `src/y0/version.py` to not have the `-dev` suffix\n2. Packages the code in both a tar archive and a wheel\n3. Uploads to PyPI using `twine`. Be sure to have a `.pypirc` file configured to avoid the need for manual input at this\n   step\n4. Push to GitHub. You'll need to make a release going with the commit where the version was bumped.\n5. Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can\n   use `tox -e bumpversion minor` after.\n\n</details>\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Python code for causal modeling.",
    "version": "0.2.10",
    "project_urls": {
        "Bug Tracker": "https://github.com/y0-causal-inference/y0/issues",
        "Download": "https://github.com/y0-causal-inference/y0/releases",
        "Homepage": "https://github.com/y0-causal-inference/y0",
        "Source Code": "https://github.com/y0-causal-inference/y0"
    },
    "split_keywords": [
        "cthoyt",
        " cookiecutter",
        " structural causal modeling"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "268a4d4a619c163400645ecc2d6b6b0ebc1525b3e5a3c26814dc37cb2bdaaf30",
                "md5": "1890c6cbf48b14cf379b659c8f2aaf39",
                "sha256": "43d939cbeb2d96b54002de1afdf8c356156d28aaaf800370075aefc213454828"
            },
            "downloads": -1,
            "filename": "y0-0.2.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1890c6cbf48b14cf379b659c8f2aaf39",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 135915,
            "upload_time": "2024-04-25T08:23:24",
            "upload_time_iso_8601": "2024-04-25T08:23:24.808915Z",
            "url": "https://files.pythonhosted.org/packages/26/8a/4d4a619c163400645ecc2d6b6b0ebc1525b3e5a3c26814dc37cb2bdaaf30/y0-0.2.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b31365528b96ac8b90410eeade26302cdae23003a25a167cd62243234eed319",
                "md5": "f5d5c46a0d533a994d2ee9729b7fb853",
                "sha256": "a2aeacf91979e8e0ec74cd527afa5b81141c58e408b9b792207b8c24574d0469"
            },
            "downloads": -1,
            "filename": "y0-0.2.10.tar.gz",
            "has_sig": false,
            "md5_digest": "f5d5c46a0d533a994d2ee9729b7fb853",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 280458,
            "upload_time": "2024-04-25T08:23:27",
            "upload_time_iso_8601": "2024-04-25T08:23:27.119992Z",
            "url": "https://files.pythonhosted.org/packages/2b/31/365528b96ac8b90410eeade26302cdae23003a25a167cd62243234eed319/y0-0.2.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 08:23:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "y0-causal-inference",
    "github_project": "y0",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "y0"
}
        
Elapsed time: 0.27269s