spkit
.transfer_entropy¶
- spkit.transfer_entropy(X, Y, present_first=True)¶
Transfer Entropy \(TE_{X->Y}\)
Transfer Entropy
\(TE_{X->Y} = I(Y_{i+1}, X_i | Y_i)\)
\(TE_{X->Y} = H(Y_{i+1} | Y_i) - H(Y_{i+1} | X_i, Y_i)\) [Eq1]
\(TE_{X->Y} = H(Y_{i+1}, Y_i) - H(Y_i) - H(Y_{i+1},X_i,Y_i) + H(X_i,Y_i)\)
\(TE_{X->Y} = H(X_i,Y_i) + H(Y_{i+1}, Y_i) - H(Y_{i+1},X_i,Y_i) - H(Y_i)\) [Eq2]
- Using:
\(H(X_{i+1}|X_i) = H(X_{i+1}, X_i) - H(X_i)\) - entropy_diff_cond_self(X)
\(H(X_{i+1}|X_i,Y_i) = H(X_{i+1},X_i,Y_i) - H(X_i,Y_i)\) - entropy_diff_cond(X,Y)
- Parameters:
- X: 2d-array,
multi-dimentional signal space, where each column (axis=1) are the delayed signals
- Y: 2d-array,
multi-dimentional signal space, where each column (axis=1) are the delayed signals
- present_first: bool, default=True
if True, X[:,0] is present, and X[:,1:] is past, in incresing order
if True, X[:,-1] is present, and X[:,:-1] is past
- Returns:
- TE_x2y: scaler
Transfer Entropy from x to y
See also
transfer_entropy_cond
Conditional Transfer Entropy
partial_transfer_entropy
Partial Transfer Entropy
entropy_granger_causality
Granger Causality based on Differential Entropy
References
wikipedia - https://en.wikipedia.org/wiki/Transfer_entropy
Examples
#sp.transfer_entropy import numpy as np import matplotlib.pyplot as plt import spkit as sp X, fs, ch_names = sp.data.eeg_sample_14ch() X = X - X.mean(1)[:, None] # Example 1 X1 = sp.signal_delayed_space(X[:,0].copy(),emb_dim=5,delay=2) Y1 = sp.signal_delayed_space(X[:,2].copy(),emb_dim=5,delay=2) Y2 = sp.add_noise(Y1,snr_db=0) TE_x_y1 = sp.transfer_entropy(X1,Y1) TE_x_y2 = sp.transfer_entropy(X1,Y2) TE_y1_x = sp.transfer_entropy(Y1,X1) TE_y2_x = sp.transfer_entropy(Y2,X1) TE_y1_y2 = sp.transfer_entropy(Y1,Y2) print('Transfer Entropy') print(f'- TE(X1->Y1) = {TE_x_y1}') print(f'- TE(X1->Y2) = {TE_x_y2}') print(f'- TE(Y1->X1) = {TE_y1_x}') print(f'- TE(Y2->X1) = {TE_y2_x}') print(f'- TE(Y1->Y2) = {TE_y1_y2}')