Name | causalite JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | Python package for defining and interacting with causal models, with a particular emphasis on Structural Causal Models |
upload_time | 2024-12-02 16:05:37 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | Apache-2.0 |
keywords |
causality
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# causalite
## Overview
**Causalite** is a Python package for
defining and interacting with causal models, with a particular emphasis on
**Structural Causal Models** (SCMs). It aims to be an accessible tool that enables users to develop their understanding of
causal models and test their own ideas.
Functionality is provided for:
* Defining an SCM by specifying causal mechanisms for each variable/node in the
corresponding **Directed Acyclic Graph**
* Sampling from the SCM
* Simulating **Randomised Controlled Trials** (RCT) by intervening on a 'treatment' variable
in the SCM
* Applying the **do-operator** to the SCM to generate interventional samples
* Computing deterministic **Counterfactuals** given an SCM and a set of observed data
### Disclaimer
Versions 0.y.z of **causalite** may include breaking changes to the API. Changes to each release are [documented](https://github.com/awrao/causalite/blob/main/CHANGELOG.md).
## Installation
We recommend you install **causalite** using pip. We also recommend that you install it into a virtual environment to avoid
potential conflicts with other packages. Once you have created and activated the virtual environment, you can install **causalite**
as follows:
$ pip install causalite
## Getting Started
Below we demonstrate how to use **causalite** to create and sample from a Structural Causal Model.
We firstly do some imports:
```python
>>> from causalite import causal_models as cm
>>> from causalite import node_models as nm
>>> import pandas as pd
```
We define an SCM consisting of 3 variables/nodes A, X and Y by specifying
the models representing the causal mechanisms for each node. (We use the words
'variable' and 'node' interchangeably.)
```python
>>> model = cm.StructuralCausalModel(node_models=[
nm.NodeAdditiveNoiseModel('A'),
nm.NodeAdditiveNoiseModel('X', parent_polys={'A': [1., 0., -3.]}),
nm.NodeAdditiveNoiseModel('Y', parent_polys={'X': [-0.5, 0., 1.2], 'A': [1.4], 'XA': [3.]})
])
```
This results in the following SCM:
```python
>>> print(model)
```
Structural Causal Model
=======================
A <- U_A
X <- 1.0A - 3.0A^3 + U_X
Y <- - 0.5X + 1.2X^3 + 1.4A + 3.0XA + U_Y
Here, U_A, U_X and U_Y represent the exogenous noise for variables A, X and Y respectively. We can draw a
sample from the SCM and store it in a pandas dataframe as follows:
```python
>>> samples = model.draw_sample(size=50000)
>>> samples.head()
```
| | A | X | Y |
|:---|---------:|-----------:|--------------:|
|0 | 1.764052 | -13.080164 | -2746.102137 |
|1 | 0.400157 | -0.403826 | 0.142060 |
|2 | 0.978738 | -2.362115 | -22.336143 |
|3 | 2.240893 | -32.590699 | -41737.620108 |
|4 | 1.867558 | -16.807889 | -5782.921438 |
For more detail and demonstrations of functionality such as simulation of interventions and counterfactual computation, please see
this [notebook](https://github.com/awrao/causalite/blob/main/examples/GettingStarted.ipynb).
## Documentation
Further illustrations of usage will be added to [examples](https://github.com/awrao/causalite/tree/main/examples) in due course.
## Contributing
Please read [this](https://github.com/awrao/causalite/blob/main/CONTRIBUTING.md) if you wish to help or contribute to **causalite** in any way whatsoever.
## License
This project is licensed according to the [Apache 2.0 software license](https://github.com/awrao/causalite/blob/main/LICENSE).
Raw data
{
"_id": null,
"home_page": null,
"name": "causalite",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "causality",
"author": null,
"author_email": "Anil Rao <anilwrao.projects@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/af/e1/448e190a3ba4c76260dcaad80395b6c8369cfe2e837b54182d644a488fd1/causalite-0.1.0.tar.gz",
"platform": null,
"description": "# causalite\n## Overview\n**Causalite** is a Python package for \ndefining and interacting with causal models, with a particular emphasis on \n**Structural Causal Models** (SCMs). It aims to be an accessible tool that enables users to develop their understanding of\ncausal models and test their own ideas.\n\nFunctionality is provided for:\n* Defining an SCM by specifying causal mechanisms for each variable/node in the\ncorresponding **Directed Acyclic Graph**\n* Sampling from the SCM\n* Simulating **Randomised Controlled Trials** (RCT) by intervening on a 'treatment' variable\nin the SCM\n* Applying the **do-operator** to the SCM to generate interventional samples\n* Computing deterministic **Counterfactuals** given an SCM and a set of observed data\n\n### Disclaimer\nVersions 0.y.z of **causalite** may include breaking changes to the API. Changes to each release are [documented](https://github.com/awrao/causalite/blob/main/CHANGELOG.md).\n\n## Installation\nWe recommend you install **causalite** using pip. We also recommend that you install it into a virtual environment to avoid\npotential conflicts with other packages. Once you have created and activated the virtual environment, you can install **causalite**\nas follows:\n\n $ pip install causalite\n\n## Getting Started\nBelow we demonstrate how to use **causalite** to create and sample from a Structural Causal Model.\nWe firstly do some imports:\n```python\n>>> from causalite import causal_models as cm\n>>> from causalite import node_models as nm\n>>> import pandas as pd\n```\n\nWe define an SCM consisting of 3 variables/nodes A, X and Y by specifying\nthe models representing the causal mechanisms for each node. (We use the words\n'variable' and 'node' interchangeably.) \n```python\n>>> model = cm.StructuralCausalModel(node_models=[\n nm.NodeAdditiveNoiseModel('A'),\n nm.NodeAdditiveNoiseModel('X', parent_polys={'A': [1., 0., -3.]}),\n nm.NodeAdditiveNoiseModel('Y', parent_polys={'X': [-0.5, 0., 1.2], 'A': [1.4], 'XA': [3.]})\n ])\n```\n\nThis results in the following SCM:\n```python\n>>> print(model)\n```\n Structural Causal Model\n =======================\n\n A <- U_A\n\n X <- 1.0A - 3.0A^3 + U_X\n\n Y <- - 0.5X + 1.2X^3 + 1.4A + 3.0XA + U_Y\n\nHere, U_A, U_X and U_Y represent the exogenous noise for variables A, X and Y respectively. We can draw a \nsample from the SCM and store it in a pandas dataframe as follows:\n```python\n>>> samples = model.draw_sample(size=50000)\n>>> samples.head()\n``` \n\n\n| | A | X | Y |\n|:---|---------:|-----------:|--------------:|\n|0 | 1.764052 | -13.080164 | -2746.102137 |\n|1 | 0.400157 | -0.403826 | 0.142060 |\n|2 | 0.978738 | -2.362115 | -22.336143 |\n|3 | 2.240893 | -32.590699 | -41737.620108 |\n|4 | 1.867558 | -16.807889 | -5782.921438 | \n\nFor more detail and demonstrations of functionality such as simulation of interventions and counterfactual computation, please see\nthis [notebook](https://github.com/awrao/causalite/blob/main/examples/GettingStarted.ipynb).\n\n## Documentation\nFurther illustrations of usage will be added to [examples](https://github.com/awrao/causalite/tree/main/examples) in due course.\n\n## Contributing\nPlease read [this](https://github.com/awrao/causalite/blob/main/CONTRIBUTING.md) if you wish to help or contribute to **causalite** in any way whatsoever.\n\n## License\nThis project is licensed according to the [Apache 2.0 software license](https://github.com/awrao/causalite/blob/main/LICENSE).\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Python package for defining and interacting with causal models, with a particular emphasis on Structural Causal Models",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/awrao/causalite"
},
"split_keywords": [
"causality"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f03dbc4094f275f444d5c8522e454f053a5d4daad48dfa97d9008bb7db975b2c",
"md5": "9d4d156d003c1260ae2d560462bcb78f",
"sha256": "b86832713d0cd9d458fc48d27cc616ade6d20da611482a44561b3065ec13ba1c"
},
"downloads": -1,
"filename": "causalite-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9d4d156d003c1260ae2d560462bcb78f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 16107,
"upload_time": "2024-12-02T16:05:36",
"upload_time_iso_8601": "2024-12-02T16:05:36.637898Z",
"url": "https://files.pythonhosted.org/packages/f0/3d/bc4094f275f444d5c8522e454f053a5d4daad48dfa97d9008bb7db975b2c/causalite-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "afe1448e190a3ba4c76260dcaad80395b6c8369cfe2e837b54182d644a488fd1",
"md5": "1c9022e5412ee9a0b00fb803da1a49bd",
"sha256": "e4ff4a11bab89ec93cd5be96434ea47b2375317c027838a074503a5e8e6134e2"
},
"downloads": -1,
"filename": "causalite-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "1c9022e5412ee9a0b00fb803da1a49bd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 16236,
"upload_time": "2024-12-02T16:05:37",
"upload_time_iso_8601": "2024-12-02T16:05:37.955980Z",
"url": "https://files.pythonhosted.org/packages/af/e1/448e190a3ba4c76260dcaad80395b6c8369cfe2e837b54182d644a488fd1/causalite-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 16:05:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "awrao",
"github_project": "causalite",
"github_not_found": true,
"lcname": "causalite"
}