Skip to main content

A package for creating causal graphs in pyro

Project description

bel2scm

This package is for creating Structural Causal Models (SCMs) in Pyro and evaluating various conditions with those models.

The causal model (example) can be created from a list of BEL statements strings (causal_graph.str_graph; http://language.bel.bio/language/structure/), a pyBEL graph (causal_graph.bel_graph; https://pypi.org/project/pybel/), or a json file created by exporting a causal graph from Causal Fusion (causal_graph.cf_graph; https://causalfusion.net/login). Each causal model consists of nodes connected by directed edges. Each node then has parameters defining the distribution of that node's variables conditioned on the values of the parent nodes. These parameters are learned from data -- each graph can learn these parameters either using Maximum Likelihood Estimation (for point estimates) or Stochastic Variational Inference (for Bayesian estimates). Currently, Bernoulli, Normal, Lognormal, Exponential, and Gamma output distributions are supported; the choice of distribution is either specified during the initialization or defaults to a hard-coded mapping from BEL object types to distributions.

Once the training process is complete, the causal model can be queried in several different fashions. The basic query is to sample all of the nodes of the model and return a dictionary of node names and samples (example.model_sample). Using built-in Pyro functionality, the model can then leverage this to calculate conditioned samples (example.model_cond_sample), interventional samples using the do-calculus (example.model_do_sample, example.model_do_cond_sample), and counterfactual samples (example.model_counterfact).

The package includes a method to calculate the Conditional Mutual Information of a target node with respect to a test node of interest (example.cond_mut_info). This calculation relies only on the input data, not the model itself. However, the SCM also has a built-in method to perform the G-test on a variable of interest (example.g_test) to determine if the SCM sufficiently captures the distribution represented by the provided data. Note that performing both of these calculations requires binning the data to produce discrete distributions.

With the various methods for sampling conditional, interventional, and counterfactual distributions from the model, the SCM can estimate the Controlled Direct Effect (example.cd_effect), the Natural Direct Effect (example.nd_effect), and the Natural Indirect Effect (example.ni_effect). Finally, the SCM can write itself to a json file that can then be imported directly to Causal Fusion (example.write_to_cf).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bel2scm-0.0.4.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bel2scm-0.0.4-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file bel2scm-0.0.4.tar.gz.

File metadata

  • Download URL: bel2scm-0.0.4.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.10

File hashes

Hashes for bel2scm-0.0.4.tar.gz
Algorithm Hash digest
SHA256 36c445d7e455fcf850e343c9a90c33dea885a4cae69c6c9b07636981bc2e272b
MD5 7aadc360b2053422bd8bda542b9181ea
BLAKE2b-256 1772fadf49319f177d10cb0e489d95538a323f87ad940c14cdfe076cbcb885dd

See more details on using hashes here.

File details

Details for the file bel2scm-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: bel2scm-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.10

File hashes

Hashes for bel2scm-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d740d24b41428f8f7fe877a558f9b0e925e81a2a71afb2e6c9f373f724f87707
MD5 0c516cecf0c30bc02e3304f782a00a1c
BLAKE2b-256 ec3450e699d7964d012367f1cd451a4fd1e1f09930b3fc308e7254b600737048

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page