Skip to main content

statistical causality discovery based on cyclic model

Project description


Statistical causal discovery based on cyclic model.
This project is under development.


Python package that performs statistical causal discovery under the following condition:

  1. there are unobserved common factors
  2. two-way causal relationship exists

cyclicmodel has been developed based on bmlingam, which implemented bayesian mixed LiNGAM.


import numpy as np
import pymc3 as pm
import cyclicmodel as cym

# Generate synthetic data,
# which assumes causal relation from x1 to x2
n = 200
x1 = np.random.randn(n)
x2 = x1 + np.random.uniform(low=-0.5, high=0.5, size=n)
xs = np.vstack([x1, x2]).T

# Model settings
hyper_params = cym.define_model.CyclicModelParams(
    dist_l_cov_21='uniform, -0.9, 0.9',
    dist_scale_indvdl='uniform, 0.1, 1.0',
    dist_beta_noise='uniform, 0.5, 6.0')

# Generate PyMC3 model
model = cym.define_model.get_pm3_model(xs, hyper_params, verbose=10)

# Run variational inference with PyMC3
with model:
  fit = pm.FullRankADVI().fit(n=100000)
  trace = fit.sample(1000, include_transformed=True)

# Check the posterior mean of the coefficients
print(np.mean(trace['b_21']))  # from x1 to x2
print(np.mean(trace['b_12']))  # from x2 to x1


pip install cyclicmodel


Project details

Download files

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

Files for cyclicmodel, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size cyclicmodel-0.0.4-py3-none-any.whl (5.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size cyclicmodel-0.0.4.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page