Skip to content

Instantly share code, notes, and snippets.

@akelleh
Last active August 29, 2015 14:26
Show Gist options
  • Save akelleh/19961f2b16d6bdab56ac to your computer and use it in GitHub Desktop.
Save akelleh/19961f2b16d6bdab56ac to your computer and use it in GitHub Desktop.
from causality.nonparametric.causal_reg import MutualInformation
import numpy as np
import pandas as pd
K = [[1., 0.5, 0.25],
[0.5, 1., 0.5],
[0.25, 0.5, 1.]]
X = np.random.multivariate_normal(mean=[0,0,0],cov=K, size=1000)
X = pd.DataFrame(X,columns=['x1','x2','x3'])
X.cov()
Ihat = MutualInformation()
Ihat.estimate(X, ['x1'], ['x2','x3'])
# compare with the exact value:
# - 0.5 * np.log( 1 - X.corr()['x1']['x2']**2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment