spkit.entropy_granger_causality

spkit.entropy_granger_causality(X, Y, present_first=True, normalize=False)

Granger Causality based on Differential Entropy \(GC_{X->Y}, GC_{Y->X}, GC_{X.Y}\)

Granger Causality based on Differential Entropy

    1. \(GC_{XY} (X->Y)\) : \(H(Y_{i+1}|Y_i) - H(Y_{i+1}|X_i,Y_i)\)

    1. \(GC_{YX} (Y->X)\) : \(H(X_{i+1}|X_i) - H(X_{i+1}|X_i,Y_i)\)

    1. \(GC_{XdY} (X.Y)\) : \(H(Y_{i+1}|X_i,Y_i) + H(X_{i+1}|X_i,Y_i) - H(X_{i+1},Y_{i+1}|X_i,Y_i)\)

if normalize True
  • \(GC_{XY} = GC_{XY}/(I(Y_{i+1}; Y_i) + GC_{XY})\)

  • \(GC_{YX} = GC_{YX}/(I(X_{i+1}; X_i) + GC_{YX})\)

Using:
  • \(H(Y_{i+1}|Y_i) = H(Y_{i+1}, Y_i) - H(Y_i)\)

  • \(H(X_{i+1}|X_i) = H(X_{i+1}, X_i) - H(X_i)\)

  • \(H(Y_{i+1}|X_i,Y_i) = H(Y_{i+1},X_i,Y_i) - H(X_i,Y_i)\)

  • \(H(X_{i+1}|X_i,Y_i) = H(X_{i+1},X_i,Y_i) - H(X_i,Y_i)\)

  • \(H(X_{i+1},Y_{i+1}|X_i,Y_i) = H(X_{i+1},Y_{i+1},X_i,Y_i) - H(X_i,Y_i)\)

  • \(I(X_{i+1}; X_i) = H(X_{i+1}) - H(X_{i+1} | X_i)\)

  • \(I(Y_{i+1}; Y_i) = H(Y_{i+1}) - H(Y_{i+1} | Y_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

normalize: bool, default=False
  • if True, GC is normalised

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:
gc_xy: scaler
  • Granger Causality from x to y

gc_yx: scaler
  • Granger Causality from y to x

gc_xdy: scaler
  • Granger Causality (x y)

See also

transfer_entropy

Transfer Entropy

transfer_entropy_cond

Conditional Transfer Entropy

partial_transfer_entropy

Partial Transfer Entropy

References

  • wikipedia

Examples

#sp.entropy_granger_causality
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)
gc_x1y1, gc_y1x1,gc_x1dy1 = sp.entropy_granger_causality(X1,Y1)
gc_x1y2, gc_y2x1,gc_x1dy2 = sp.entropy_granger_causality(X1,Y2)
print('Granger Causality : X1,Y1')
print(f'- GC(X1->Y1) = {gc_x1y1}')
print(f'- GC(Y1->X1) = {gc_y1x1}')
print(f'- GC(X1,Y1)  = {gc_x1dy1}')
print('-'*10)
print('Granger Causality : X1,Y2')
print(f'- GC(X1->Y2) = {gc_x1y2}')
print(f'- GC(Y2->X1) = {gc_y2x1}')
print(f'- GC(X1,Y2)  = {gc_x1dy2}')