pythonpython-3.xnumpyentropyinformation-theory

Conditional Mutual information


The theoretical approach,i want to convert this into a python program[![][1]]2Was trying to test this package for calculation of conditional mutual information from a dataset .The package name-"dit"

My code:

from __future__ import division
import numpy as np
import dit
from dit import Distribution as D
from dit.multivariate import coinformation as I
from dit.example_dists import Xor

d=Xor()
d.set_rv_names(['X','Y','Z'])
X=111010
Y=101101
Z=001011

a=dit.multivariate.coinformation(d,'XY','Z')
print(a)

While running this program,the result i always get is "1.0".
The result come as negative or positive value like "-0.0023" or "0.120"

Basically,i want to do this https://stats.stackexchange.com/questions/147401/estimating-mutual-information-using-r in Python. A little bit of help will be highly appreciated


Solution

  • Tell me if this is the solution for you: set_rv_names to d:

    d=Xor()
    
    ## ADD THIS LINE OF CODE BELOW
    d.set_rv_names(['X', 'Y', 'Z'])
    
    X=0.052290766
    Y=0.004951425
    Z=0.000246642
    
    a=dit.multivariate.coinformation(d,'XY','Z')
    print(a)