Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gcastle

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gcastle

gCastle is the fundamental package for causal structure learning with Python.

  • 1.0.3
  • PyPI
  • Socket score

Maintainers
2

gCastle

中文版本

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. 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

AlgorithmCategoryDescriptionStatus
PCIID/Constraint-basedA classic causal discovery algorithm based on conditional independence testsv1.0.3
ANMIID/Function-basedNonlinear causal discovery with additive noise modelsv1.0.3
DirectLiNGAMIID/Function-basedA direct learning algorithm for linear non-Gaussian acyclic model (LiNGAM)v1.0.3
ICALiNGAMIID/Function-basedAn ICA-based learning algorithm for linear non-Gaussian acyclic model (LiNGAM)v1.0.3
GESIID/Score-basedA classical Greedy Equivalence Search algorithmv1.0.3
PNLIID/Funtion-basedCausal discovery based on the post-nonlinear causal assumptionv1.0.3
NOTEARSIID/Gradient-basedA gradient-based algorithm for linear data models (typically with least-squares loss)v1.0.3
NOTEARS-MLPIID/Gradient-basedA gradient-based algorithm using neural network modeling for non-linear causal relationshipsv1.0.3
NOTEARS-SOBIID/Gradient-basedA gradient-based algorithm using Sobolev space modeling for non-linear causal relationshipsv1.0.3
NOTEARS-lOW-RANKIID/Gradient-basedAdapting NOTEARS for large problems with low-rank causal graphsv1.0.3
DAG-GNNIID/Gradient-basedDAG Structure Learning with Graph Neural Networksv1.0.3
GOLEMIID/Gradient-basedA more efficient version of NOTEARS that can reduce number of optimization iterationsv1.0.3
GraNDAGIID/Gradient-basedA gradient-based algorithm using neural network modeling for non-linear additive noise datav1.0.3
MCSLIID/Gradient-basedA gradient-based algorithm for non-linear additive noise data by learning the binary adjacency matrixv1.0.3
GAEIID/Gradient-basedA gradient-based algorithm using graph autoencoder to model non-linear causal relationshipsv1.0.3
RLIID/Gradient-basedA RL-based algorithm that can work with flexible score functions (including non-smooth ones)v1.0.3
CORLIID/Gradient-basedA RL- and order-based algorithm that improves the efficiency and scalability of previous RL-based approachv1.0.3
TTPMEventSequence/Function-basedA causal structure learning algorithm based on Topological Hawkes process for spatio-temporal event sequencesv1.0.3
HPCIEventSequence/HybridA causal structure learning algorithm based on Hawkes process and CI tests for event sequencesunder 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

pip install gcastle==1.0.3

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, 'result')

# calculate metrics
mt = MetricsDAG(pc.causal_matrix, true_causal_matrix)
print(mt.metrics)

You can visit examples to find more examples.

Citation

If you find gCastle useful in your research, please consider citing the the following paper:

@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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc