Skip to content

Causal / Temporal

Transfer entropy for detecting directed information flow between time series.

transfer_entropy(source, target, *, k=1, lag=1, base=np.e, knn_k=5)

Estimate transfer entropy from source to target time series.

.. math::

TE_{X \to Y} = I(Y_{t+1}; X_t^{(k)} \mid Y_t^{(l)})

Computed via the 4-entropy formulation:

.. math::

TE = H(Y_f, Y_p) + H(Y_p, X_p) - H(Y_f, Y_p, X_p) - H(Y_p)

where :math:Y_f is the future of Y, :math:Y_p is the past of Y (lag embedding of depth l), and :math:X_p is the past of X (lag embedding of depth k).

Parameters:

Name Type Description Default
source ndarray

Source time series, shape (T,).

required
target ndarray

Target time series, shape (T,).

required
k int

Embedding dimension for the source. Default is 1.

1
lag int

Embedding dimension for the target. Default is 1.

1
base float

Logarithm base. Default is np.e (nats).

e
knn_k int

Number of nearest neighbors for the kNN entropy estimator. Default is 5.

5

Returns:

Type Description
float

Estimated transfer entropy TE_{source -> target}.

Raises:

Type Description
ValueError

If the time series are too short for the given embedding dimensions.