All problems
Transfer Entropy (Lag 1)
Problem
Compute the lag-1 transfer entropy in bits from X to Y given the joint joint[x_prev][y_prev][y_t]:
T = H(Y_t | Y_prev) - H(Y_t | X_prev, Y_prev)
Build the needed marginals and use entropy in bits for every term.
Hint
Transfer entropy is zero when the past of X adds nothing beyond Y's own past.
Test cases
case 1
in: [[[[0.125,0.125],[0.125,0.125]],[[0.125,0.125],[0.125,0.125]]]]
expected: 0
case 2
in: [[[[0.25,0],[0.25,0]],[[0,0.25],[0,0.25]]]]
expected: 1
case 3
in: [[[[0.4,0.1],[0.1,0.4]],[[0.4,0.1],[0.1,0.4]]]]
expected: 0
case 4
in: [[[[0.15,0.1],[0.1,0.15]],[[0.05,0.2],[0.2,0.05]]]]
expected: 0.12451124978365313
Starter codePython
import math
def transfer_entropy(joint):
# Your code here
pass4 test cases · run your code against them in the editor