Skip to main content

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

Metadata

Release files for bel2scm 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bel2scm 0.0.4
File Size Uploaded
bel2scm-0.0.4.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bel2scm 0.0.4
File Interpreter ABI Platform
bel2scm-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 35.0 kB

Release files / bel2scm-0.0.4.tar.gz

Download URL bel2scm-0.0.4.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
36c445d7e455fcf850e343c9a90c33dea885a4cae69c6c9b07636981bc2e272b
BLAKE2b-256 checksum
How to use checksums
1772fadf49319f177d10cb0e489d95538a323f87ad940c14cdfe076cbcb885dd
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / bel2scm-0.0.4-py3-none-any.whl

Download URL bel2scm-0.0.4-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d740d24b41428f8f7fe877a558f9b0e925e81a2a71afb2e6c9f373f724f87707
BLAKE2b-256 checksum
How to use checksums
ec3450e699d7964d012367f1cd451a4fd1e1f09930b3fc308e7254b600737048
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page