gCastle
Introduction
gCastle is a causal structure learning toolchain developed by Huawei Noah's Ark Lab. 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 (based on data) | Description |
|---|---|---|
| PC | IID | A classic causal discovery algorithm based on conditional independence tests |
| DirectLiNGAM | IID | A direct learning algorithm for linear non-Gaussian acyclic model (LiNGAM) |
| ICALiNGAM | IID | An ICA-based learning algorithm for linear non-Gaussian acyclic model (LiNGAM) |
| NOTEARS | IID | A gradient-based algorithm for linear data models (typically with least-squares loss) |
| NOTEARS-MLP | IID | A gradient-based algorithm using neural network modeling for non-linear causal relationships |
| NOTEARS-SOB | IID | A gradient-based algorithm using Sobolev space modeling for non-linear causal relationships |
| NOTEARS-lOW-RANK | IID | Adapting NOTEARS for large problems with low-rank causal graphs |
| GOLEM | IID | A more efficient version of NOTEARS that can reduce number of optimization iterations |
| GraN_DAG | IID | A gradient-based algorithm using neural network modeling for non-linear additive noise data |
| MCSL | IID | A gradient-based algorithm for non-linear additive noise data by learning the binary adjacency matrix |
| GAE | IID | A gradient-based algorithm using graph autoencoder to model non-linear causal relationships |
| RL | IID | A RL-based algorithm that can work with flexible score functions (including non-smooth ones) |
| CORL1 | IID | A RL- and order-based algorithm that improves the efficiency and scalability of previous RL-based approach |
| CORL2 | IID | A RL- and order-based algorithm that improves the efficiency and scalability of previous RL-based approach |
| TTPM | EVENT SEQUENCE | A causal structure learning algorithm based on Topological Hawkes process for spatio-temporal event sequences |
Installation
Dependencies
gCastle requires:
- python (>= 3.6)
- tqdm (>= 4.48.2)
- numpy (>= 1.19.1)
- pandas (>= 0.22.0)
- scipy (>= 1.4.1)
- scikit-learn (>= 0.21.1)
- matplotlib (>=2.1.2)
- python-igraph (>= 0.8.2)
- loguru (>= 0.5.3)
- networkx (>= 2.5)
- torch (>= 1.4.0)
- tensorflow (>= 1.15.0)
PIP installation
pip install gcastle
Usage Example (PC algorithm)
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)
# calculate metrics
mt = MetricsDAG(pc.causal_matrix, true_causal_matrix)
print(mt.metrics)
You can visit examples to find more examples.
Next Up & Contributing
You can find more news about gCastle on the github website.
Release files for gcastle 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gcastle-1.0.2.tar.gz | 103.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gcastle-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 300.9 kB
Release files / gcastle-1.0.2.tar.gz
| Download URL | gcastle-1.0.2.tar.gz |
|---|---|
| Size | 103.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24f70df7de3f579589bba0bc75dded1247f052a766195916b4652745af342975
|
|
BLAKE2b-256 checksum How to use checksums |
6983c17b813f1356c78cbcd6b822b204330489e0c2408865c06791906add1d09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Release files / gcastle-1.0.2-py3-none-any.whl
| Download URL | gcastle-1.0.2-py3-none-any.whl |
|---|---|
| Size | 197.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
50ca6455373a8ecbb4b954cf2eaec3872ef4e2aeebfa2bc6af0828bb2b5edecb
|
|
BLAKE2b-256 checksum How to use checksums |
de9d73d09e17e3057dc6ecfc47fbfbbbbe2cc9dcc0289b740b05fad01e98cde7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|