ELIFE-ASU / PyInform

A Python Wrapper for the Inform Information Analysis Library
https://elife-asu.github.io/PyInform
MIT License
45 stars 9 forks source link

Implement complete/conditional transfer entropy #32

Closed dglmoore closed 4 years ago

dglmoore commented 4 years ago

In Inform, inform_transfer_entropy supports conditional TE through its third argument. This pull request implements that functionality in PyInform by adding a new keyword argument to the transfer_entropy function:

New API

def transfer_entropy(source, target, k, condition=None, local=False):
    pass

Example Usage

>>> from pyinform import transfer_entropy
>>> xs = [0,1,1,1,1,0,0,0,0]
>>> ys = [0,0,1,1,1,1,0,0,0]
>>> ws = [0,1,1,1,1,0,1,1,1]
>>> transfer_entropy(xs, ys, k=2, condition=ws)
0.2857142857142857
>>> transfer_entropy(ys, xs, k=2, condition=ws)
0.0
>>> ws = [[1,0,1,0,1,1,1,1,1],
...       [1,1,0,1,0,1,1,1,1]]
>>> transfer_entropy(xs, ys, k=2, condition=ws)
0.0

This closes #31

codecov-io commented 4 years ago

Codecov Report

Merging #32 into master will increase coverage by 0.32%. The diff coverage is 96.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #32      +/-   ##
==========================================
+ Coverage   96.06%   96.38%   +0.32%     
==========================================
  Files          15       15              
  Lines         533      554      +21     
==========================================
+ Hits          512      534      +22     
+ Misses         21       20       -1
Impacted Files Coverage Δ
pyinform/transferentropy.py 98.21% <96.42%> (+3.92%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update af09f11...c182204. Read the comment docs.