spkit.transfer_entropy_cond

spkit.transfer_entropy_cond(X, Y, Z, present_first=True)

Conditional Transfer Entopry Or Partial Transfer Entropy \(TE_{X->Y | Z}\)

Conditional Transfer Entopry Or Partial Transfer Entropy

\[TE_{X->Y | Z} = I(Y_{i+1}, X_i | Y_i, Z_i)\]
\[TE_{X->Y | Z} = H(X_i,Y_i, Z_i) + H(Y_{i+1}, Y_i, Z_i) - H(Y_{i+1},X_i,Y_i, Z_i) - H(Y_i, Z_i)\]
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

Z: 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_x2y1z: scaler
  • Conditional Transfer Entropy, transfer entropy from x to y, given z

See also

transfer_entropy

Transfer Entropy

partial_transfer_entropy

Partial Transfer Entropy

entropy_granger_causality

Granger Causality based on Differential Entropy

References

Examples

#sp.transfer_entropy_cond
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)
Z1 = sp.signal_delayed_space(X[:,4].copy(),emb_dim=5,delay=2)
Y2 = sp.add_noise(Y1,snr_db=0)
TE_x_y1_1z = sp.transfer_entropy_cond(X1,Y1,Z1)
TE_x_y2_1z = sp.transfer_entropy_cond(X1,Y2,Z1)
TE_y1_x_1z = sp.transfer_entropy_cond(Y1,X1,Z1)
TE_y2_x_1z = sp.transfer_entropy_cond(Y2,X1,Z1)
print('Conditional Transfer Entropy')
print(f'- TE(X1->Y1 | Z1) = {TE_x_y1_1z}')
print(f'- TE(X1->Y2 | Z1) = {TE_x_y2_1z}')
print(f'- TE(Y1->X1 | Z1) = {TE_y1_x_1z}')
print(f'- TE(Y2->X1 | Z1) = {TE_y2_x_1z}')