dirconn.TE#

class dirconn.TE(mode: Literal['multivariate', 'pairwise', 'conditional'] = 'multivariate', target_history: int | str = 'bic', max_order: int = 10, source_history: int = 1, max_delay: int = 5, n_neighbors: int = 4, workers: int = 1, alpha: float = 0.05, n_perm_max_stat: int = 200, n_perm_min_stat: int = 200, n_perm_omnibus: int = 500, n_perm_max_seq: int = 500, fdr: bool = False, seed: int = 0, device: str | None = None, dtype: Literal['float64', 'float32'] = 'float64')#

Transfer entropy with the KSG estimator: multivariate (default), pairwise or conditional.

multivariate (default): for every target the past variables that carry information about its present are selected greedily and tested by permutation, as in IDTxl (Novelli et al. 2019): first the target’s own past among lags 1 .. max_order, then the sources’ past among lags 1 .. max_delay, then pruning, an omnibus test per target and a sequential test per source (the steps are described in dirconn.methods._greedy). values[i, j] is the information of the selected variables of i about j_t given the selected past of j and of the other selected sources, in nats, and 0 for a source that is not selected. The tests are built in and use seed, so the result is already a decision; running dirconn.significance_test() on top repeats the testing. This mode is much slower than the others (thousands of estimates per target); see workers and device.

pairwise: values[i, j] = I(j_t ; i_{t-u}, ..., i_{t-u-l+1} | j_{t-1}, ..., j_{t-k}) with k = target_history and l = source_history, for the delay u in 1 .. max_delay that gives the largest value (Wibral et al. 2013); the chosen delays and the values at every delay are in the provenance, and every delay uses the same rows. The estimate is raw and biased (the maximum over delays adds about 0.01 to 0.02 nats on non-edges): compare values with a surrogate test, not with each other across settings.

conditional: as pairwise, with the past of every other channel (target_history samples each) in the condition. The nearest-neighbour estimator degrades quickly as the dimension of the condition grows, which the multivariate mode avoids by selecting variables.

Rows are taken within trials and pooled. The diagonal is undefined (NaN). This is predictive information transfer, not interventional causality.

Parameters:
  • mode ({"multivariate", "pairwise", "conditional"}) – See above.

  • target_history (int or {"aic", "bic", "hqc", "cv"}) – Pairwise and conditional modes: target history length k in samples (the condition), or the criterion that picks it as the order of the pooled VAR model of all channels (as for GC), at most max_order. Too short a history makes the source’s past carry the target’s own memory and can reverse the direction: on the oscillating reference scenarios a history of one sample got the direction wrong where the BIC order (2) got it right. The multivariate mode selects the target past itself; setting this there raises.

  • max_order (int) – Largest target lag: the largest candidate of the criterion, or of the multivariate selection.

  • source_history (int) – Pairwise and conditional modes: source history length l in samples.

  • max_delay (int) – Largest source lag, in samples (from 1): the largest delay scanned, or the largest candidate of the multivariate selection.

  • n_neighbors (int) – Neighbours of the KSG estimator (Kraskov et al. recommend about 4).

  • workers (int) – Parallel work (-1: all cores); the values do not depend on it. In the pairwise and conditional modes, processes for the neighbour searches. In the multivariate mode on the CPU path, the targets run in parallel processes when joblib is installed (extra parallel), otherwise the neighbour searches are parallel.

  • alpha (float) – Multivariate mode: level of every permutation test.

  • n_perm_max_stat (int) – Multivariate mode: permutations of the inclusion (maximum statistic), pruning (minimum statistic), omnibus and sequential tests; the defaults are IDTxl’s. Each must reach alpha: at least 1 / alpha - 1.

  • n_perm_min_stat (int) – Multivariate mode: permutations of the inclusion (maximum statistic), pruning (minimum statistic), omnibus and sequential tests; the defaults are IDTxl’s. Each must reach alpha: at least 1 / alpha - 1.

  • n_perm_omnibus (int) – Multivariate mode: permutations of the inclusion (maximum statistic), pruning (minimum statistic), omnibus and sequential tests; the defaults are IDTxl’s. Each must reach alpha: at least 1 / alpha - 1.

  • n_perm_max_seq (int) – Multivariate mode: permutations of the inclusion (maximum statistic), pruning (minimum statistic), omnibus and sequential tests; the defaults are IDTxl’s. Each must reach alpha: at least 1 / alpha - 1.

  • fdr (bool) – Multivariate mode: correct the targets’ omnibus p-values with Benjamini-Hochberg and drop the sources of the targets that fail (the hierarchical correction of Novelli et al. 2019).

  • seed (int) – Multivariate mode: seed of the permutations; the default makes te(data) reproducible.

  • device (str, optional) – None (default) uses scipy’s cKDTree on the CPU. A torch device name ("cpu", "cuda", "xpu", "mps") computes the neighbours by brute force with PyTorch (extra gpu), which pays off for long data on a GPU.

  • dtype ({"float64", "float32"}) – Precision on a torch device. float64 gives the values of the CPU path; float32 is faster on most GPUs but neighbours that tie at float32 precision change the values slightly.

__init__(mode: Literal['multivariate', 'pairwise', 'conditional'] = 'multivariate', target_history: int | str = 'bic', max_order: int = 10, source_history: int = 1, max_delay: int = 5, n_neighbors: int = 4, workers: int = 1, alpha: float = 0.05, n_perm_max_stat: int = 200, n_perm_min_stat: int = 200, n_perm_omnibus: int = 500, n_perm_max_seq: int = 500, fdr: bool = False, seed: int = 0, device: str | None = None, dtype: Literal['float64', 'float32'] = 'float64') → None#

Methods

__init__([mode, target_history, max_order, ...])

fit(data)

Estimate directed connectivity.

get_params()

Return the constructor parameters as a dictionary.

Attributes

alpha

device

dtype

fdr

info

max_delay

max_order

mode

n_neighbors

n_perm_max_seq

n_perm_max_stat

n_perm_min_stat

n_perm_omnibus

seed

source_history

target_history

workers