# gCastle
[中文版本](https://github.com/huawei-noah/trustworthyAI/tree/master/gcastle/README.cn.md)
Version 1.0.3 released.
We'll release Version 1.0.3 on 2022/08/08.
## Introduction
gCastle is a causal structure learning toolchain developed by [Huawei Noah's Ark Lab](https://www.noahlab.com.hk/#/home). The package contains various functionality related to causal learning and evaluation, including:
* Data generation and processing: data simulation, data reading operators, and data pre-processing operators(such as prior injection and variable selection).
* Causal structure learning: causal structure learning methods, including both classic and recently developed methods, especially gradient-based ones that can handle large problems.
* Evaluation metrics: various commonly used metrics for causal structure learning, including F1, SHD, FDR, TPR, FDR, NNZ, etc.
## Algorithm List
| Algorithm | Category | Description | Status |
| :--: | :-- | :-- | :--: |
| [PC](https://arxiv.org/abs/math/0510436) | IID/Constraint-based | A classic causal discovery algorithm based on conditional independence tests | v1.0.3 |
| [ANM](https://webdav.tuebingen.mpg.de/causality/NIPS2008-Hoyer.pdf) | IID/Function-based | Nonlinear causal discovery with additive noise models | v1.0.3 |
| [DirectLiNGAM](https://arxiv.org/abs/1101.2489) | IID/Function-based | A direct learning algorithm for linear non-Gaussian acyclic model (LiNGAM) | v1.0.3 |
| [ICALiNGAM](https://dl.acm.org/doi/10.5555/1248547.1248619) | IID/Function-based | An ICA-based learning algorithm for linear non-Gaussian acyclic model (LiNGAM) | v1.0.3 |
| [GES](https://www.jmlr.org/papers/volume3/chickering02b/chickering02b.pdf?ref=https://githubhelp.com) | IID/Score-based | A classical Greedy Equivalence Search algorithm | v1.0.3 |
| [PNL](https://arxiv.org/abs/1205.2599) | IID/Funtion-based | Causal discovery based on the post-nonlinear causal assumption | v1.0.3 |
| [NOTEARS](https://arxiv.org/abs/1803.01422) | IID/Gradient-based | A gradient-based algorithm for linear data models (typically with least-squares loss) | v1.0.3 |
| [NOTEARS-MLP](https://arxiv.org/abs/1909.13189) | IID/Gradient-based | A gradient-based algorithm using neural network modeling for non-linear causal relationships | v1.0.3 |
| [NOTEARS-SOB](https://arxiv.org/abs/1909.13189) | IID/Gradient-based | A gradient-based algorithm using Sobolev space modeling for non-linear causal relationships | v1.0.3 |
| [NOTEARS-lOW-RANK](https://arxiv.org/abs/2006.05691) | IID/Gradient-based | Adapting NOTEARS for large problems with low-rank causal graphs | v1.0.3 |
| [DAG-GNN](https://arxiv.org/abs/1904.10098) | IID/Gradient-based | DAG Structure Learning with Graph Neural Networks | v1.0.3 |
| [GOLEM](https://arxiv.org/abs/2006.10201) | IID/Gradient-based | A more efficient version of NOTEARS that can reduce number of optimization iterations | v1.0.3 |
| [GraNDAG](https://arxiv.org/abs/1906.02226) | IID/Gradient-based | A gradient-based algorithm using neural network modeling for non-linear additive noise data | v1.0.3 |
| [MCSL](https://arxiv.org/abs/1910.08527) | IID/Gradient-based | A gradient-based algorithm for non-linear additive noise data by learning the binary adjacency matrix| v1.0.3 |
| [GAE](https://arxiv.org/abs/1911.07420) | IID/Gradient-based | A gradient-based algorithm using graph autoencoder to model non-linear causal relationships| v1.0.3 |
| [RL](https://arxiv.org/abs/1906.04477) | IID/Gradient-based | A RL-based algorithm that can work with flexible score functions (including non-smooth ones) | v1.0.3 |
| [CORL](https://arxiv.org/abs/2105.06631) | IID/Gradient-based | A RL- and order-based algorithm that improves the efficiency and scalability of previous RL-based approach | v1.0.3 |
| [TTPM](https://arxiv.org/abs/2105.10884) | EventSequence/Function-based | A causal structure learning algorithm based on Topological Hawkes process for spatio-temporal event sequences |v1.0.3 |
| [HPCI](https://arxiv.org/abs/2105.03092) | EventSequence/Hybrid | A causal structure learning algorithm based on Hawkes process and CI tests for event sequences | under development. |
## Installation
### Dependencies
gCastle requires:
- python (>= 3.6, <=3.9)
- tqdm (>= 4.48.2)
- numpy (>= 1.19.1)
- pandas (>= 0.22.0)
- scipy (>= 1.7.3)
- scikit-learn (>= 0.21.1)
- matplotlib (>=2.1.2)
- networkx (>= 2.5)
- torch (>= 1.9.0)
### PIP installation
```bash
pip install gcastle==1.0.3
```
## Usage Example (PC algorithm)
```python
from castle.common import GraphDAG
from castle.metrics import MetricsDAG
from castle.datasets import IIDSimulation, DAG
from castle.algorithms import PC
# data simulation, simulate true causal dag and train_data.
weighted_random_dag = DAG.erdos_renyi(n_nodes=10, n_edges=10,
weight_range=(0.5, 2.0), seed=1)
dataset = IIDSimulation(W=weighted_random_dag, n=2000, method='linear',
sem_type='gauss')
true_causal_matrix, X = dataset.B, dataset.X
# structure learning
pc = PC()
pc.learn(X)
# plot predict_dag and true_dag
GraphDAG(pc.causal_matrix, true_causal_matrix, 'result')
# calculate metrics
mt = MetricsDAG(pc.causal_matrix, true_causal_matrix)
print(mt.metrics)
```
You can visit [examples](https://github.com/huawei-noah/trustworthyAI/tree/master/gcastle/example) to find more examples.
## Citation
If you find gCastle useful in your research, please consider citing the the following [paper](https://arxiv.org/abs/2111.15155):
```
@misc{zhang2021gcastle,
title={gCastle: A Python Toolbox for Causal Discovery},
author={Keli Zhang and Shengyu Zhu and Marcus Kalander and Ignavier Ng and Junjian Ye and Zhitang Chen and Lujia Pan},
year={2021},
eprint={2111.15155},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
```
## Next Up & Contributing
This is the first released version of gCastle, we'll be continuously complementing and optimizing the code and documentation. We welcome new contributors of all experience levels, the specifications about how to contribute code will be coming out soon. If you have any questions or suggestions (such as, contributing new algorithms, optimizing code, improving documentation), please submit an issue here. We will reply as soon as possible.
Raw data
{
"_id": null,
"home_page": "https://github.com/huawei-noah/trustworthyAI/tree/master/gcastle",
"name": "gcastle",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Huawei Noah's Ark Lab",
"author_email": "zhangkeli1@huawei.com",
"download_url": "https://files.pythonhosted.org/packages/37/22/8505ddd00d21d8b4a93758bf637a177274c39dd6bc1a88e551b5ea87f8e7/gcastle-1.0.3.tar.gz",
"platform": null,
"description": "# gCastle\n[\u4e2d\u6587\u7248\u672c](https://github.com/huawei-noah/trustworthyAI/tree/master/gcastle/README.cn.md)\n\nVersion 1.0.3 released.\n\nWe'll release Version 1.0.3 on 2022/08/08.\n\n## Introduction\n\ngCastle is a causal structure learning toolchain developed by [Huawei Noah's Ark Lab](https://www.noahlab.com.hk/#/home). The package contains various functionality related to causal learning and evaluation, including: \n* Data generation and processing: data simulation, data reading operators, and data pre-processing operators\uff08such as prior injection and variable selection).\n* Causal structure learning: causal structure learning methods, including both classic and recently developed methods, especially gradient-based ones that can handle large problems.\n* Evaluation metrics: various commonly used metrics for causal structure learning, including F1, SHD, FDR, TPR, FDR, NNZ, etc.\n\n## Algorithm List\n\n| Algorithm | Category | Description | Status |\n| :--: | :-- | :-- | :--: |\n| [PC](https://arxiv.org/abs/math/0510436) | IID/Constraint-based | A classic causal discovery algorithm based on conditional independence tests | v1.0.3 |\n| [ANM](https://webdav.tuebingen.mpg.de/causality/NIPS2008-Hoyer.pdf) | IID/Function-based | Nonlinear causal discovery with additive noise models | v1.0.3 |\n| [DirectLiNGAM](https://arxiv.org/abs/1101.2489) | IID/Function-based | A direct learning algorithm for linear non-Gaussian acyclic model (LiNGAM) | v1.0.3 |\n| [ICALiNGAM](https://dl.acm.org/doi/10.5555/1248547.1248619) | IID/Function-based | An ICA-based learning algorithm for linear non-Gaussian acyclic model (LiNGAM) | v1.0.3 |\n| [GES](https://www.jmlr.org/papers/volume3/chickering02b/chickering02b.pdf?ref=https://githubhelp.com) | IID/Score-based | A classical Greedy Equivalence Search algorithm | v1.0.3 |\n| [PNL](https://arxiv.org/abs/1205.2599) | IID/Funtion-based | Causal discovery based on the post-nonlinear causal assumption | v1.0.3 |\n| [NOTEARS](https://arxiv.org/abs/1803.01422) | IID/Gradient-based | A gradient-based algorithm for linear data models (typically with least-squares loss) | v1.0.3 |\n| [NOTEARS-MLP](https://arxiv.org/abs/1909.13189) | IID/Gradient-based | A gradient-based algorithm using neural network modeling for non-linear causal relationships | v1.0.3 |\n| [NOTEARS-SOB](https://arxiv.org/abs/1909.13189) | IID/Gradient-based | A gradient-based algorithm using Sobolev space modeling for non-linear causal relationships | v1.0.3 |\n| [NOTEARS-lOW-RANK](https://arxiv.org/abs/2006.05691) | IID/Gradient-based | Adapting NOTEARS for large problems with low-rank causal graphs | v1.0.3 |\n| [DAG-GNN](https://arxiv.org/abs/1904.10098) | IID/Gradient-based | DAG Structure Learning with Graph Neural Networks | v1.0.3 |\n| [GOLEM](https://arxiv.org/abs/2006.10201) | IID/Gradient-based | A more efficient version of NOTEARS that can reduce number of optimization iterations | v1.0.3 |\n| [GraNDAG](https://arxiv.org/abs/1906.02226) | IID/Gradient-based | A gradient-based algorithm using neural network modeling for non-linear additive noise data | v1.0.3 |\n| [MCSL](https://arxiv.org/abs/1910.08527) | IID/Gradient-based | A gradient-based algorithm for non-linear additive noise data by learning the binary adjacency matrix| v1.0.3 |\n| [GAE](https://arxiv.org/abs/1911.07420) | IID/Gradient-based | A gradient-based algorithm using graph autoencoder to model non-linear causal relationships| v1.0.3 |\n| [RL](https://arxiv.org/abs/1906.04477) | IID/Gradient-based | A RL-based algorithm that can work with flexible score functions (including non-smooth ones) | v1.0.3 |\n| [CORL](https://arxiv.org/abs/2105.06631) | IID/Gradient-based | A RL- and order-based algorithm that improves the efficiency and scalability of previous RL-based approach | v1.0.3 |\n| [TTPM](https://arxiv.org/abs/2105.10884) | EventSequence/Function-based | A causal structure learning algorithm based on Topological Hawkes process for spatio-temporal event sequences |v1.0.3 |\n| [HPCI](https://arxiv.org/abs/2105.03092) | EventSequence/Hybrid | A causal structure learning algorithm based on Hawkes process and CI tests for event sequences | under development. |\n\n\n\n## Installation\n\n### Dependencies\ngCastle requires:\n- python (>= 3.6, <=3.9)\n- tqdm (>= 4.48.2)\n- numpy (>= 1.19.1)\n- pandas (>= 0.22.0)\n- scipy (>= 1.7.3)\n- scikit-learn (>= 0.21.1)\n- matplotlib (>=2.1.2)\n- networkx (>= 2.5)\n- torch (>= 1.9.0)\n\n\n### PIP installation\n```bash\npip install gcastle==1.0.3\n```\n\n## Usage Example (PC algorithm)\n```python\nfrom castle.common import GraphDAG\nfrom castle.metrics import MetricsDAG\nfrom castle.datasets import IIDSimulation, DAG\nfrom castle.algorithms import PC\n\n# data simulation, simulate true causal dag and train_data.\nweighted_random_dag = DAG.erdos_renyi(n_nodes=10, n_edges=10, \n weight_range=(0.5, 2.0), seed=1)\ndataset = IIDSimulation(W=weighted_random_dag, n=2000, method='linear', \n sem_type='gauss')\ntrue_causal_matrix, X = dataset.B, dataset.X\n\n# structure learning\npc = PC()\npc.learn(X)\n\n# plot predict_dag and true_dag\nGraphDAG(pc.causal_matrix, true_causal_matrix, 'result')\n\n# calculate metrics\nmt = MetricsDAG(pc.causal_matrix, true_causal_matrix)\nprint(mt.metrics)\n```\nYou can visit [examples](https://github.com/huawei-noah/trustworthyAI/tree/master/gcastle/example) to find more examples.\n\n\n## Citation\nIf you find gCastle useful in your research, please consider citing the the following [paper](https://arxiv.org/abs/2111.15155):\n```\n@misc{zhang2021gcastle,\n title={gCastle: A Python Toolbox for Causal Discovery}, \n author={Keli Zhang and Shengyu Zhu and Marcus Kalander and Ignavier Ng and Junjian Ye and Zhitang Chen and Lujia Pan},\n year={2021},\n eprint={2111.15155},\n archivePrefix={arXiv},\n primaryClass={cs.LG}\n}\n```\n\n## Next Up & Contributing\nThis is the first released version of gCastle, we'll be continuously complementing and optimizing the code and documentation. We welcome new contributors of all experience levels, the specifications about how to contribute code will be coming out soon. If you have any questions or suggestions (such as, contributing new algorithms, optimizing code, improving documentation), please submit an issue here. We will reply as soon as possible.\n\n\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "gCastle is the fundamental package for causal structure learning with Python.",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/huawei-noah/trustworthyAI/tree/master/gcastle"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "241dc12be2c0f35d3e9360fe0a561c32fe1caf826ac469dcb87f18a873c0917f",
"md5": "ce9dfa25249222aff0eb26a55c87af42",
"sha256": "703b38713e9459e4ca43a5547e83076b3a9a9b459f0279b84e953a6df71d74dc"
},
"downloads": -1,
"filename": "gcastle-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ce9dfa25249222aff0eb26a55c87af42",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 214903,
"upload_time": "2022-08-10T09:19:41",
"upload_time_iso_8601": "2022-08-10T09:19:41.673383Z",
"url": "https://files.pythonhosted.org/packages/24/1d/c12be2c0f35d3e9360fe0a561c32fe1caf826ac469dcb87f18a873c0917f/gcastle-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "37228505ddd00d21d8b4a93758bf637a177274c39dd6bc1a88e551b5ea87f8e7",
"md5": "32f6f89e2136608c03697412f3de8c96",
"sha256": "063065fb3cf130b25611a9a7afc9de9e0665f80537bf95cd47bbc9bbaf10f6cb"
},
"downloads": -1,
"filename": "gcastle-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "32f6f89e2136608c03697412f3de8c96",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 129279,
"upload_time": "2022-08-10T09:19:43",
"upload_time_iso_8601": "2022-08-10T09:19:43.639765Z",
"url": "https://files.pythonhosted.org/packages/37/22/8505ddd00d21d8b4a93758bf637a177274c39dd6bc1a88e551b5ea87f8e7/gcastle-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-08-10 09:19:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "huawei-noah",
"github_project": "trustworthyAI",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "gcastle"
}