get_mtf

eyefeatures.features.feature_maps.get_mtf(data, x, y, n_bins=10, output_size=1.0, shrink_strategy='normal', flatten=False)[source]

Calculates Markov Transition Field for (x,y) coordinates.

Parameters:
  • data (DataFrame) – input Dataframe with fixations.

  • x (str) – X coordinate column name.

  • y (str) – Y coordinate column name.

  • n_bins (int) – number of bins to discretize time series into.

  • output_size (int | float) – fraction between 0 and 1. Specifies fraction of input series length to shrink output to.

  • shrink_strategy (Literal['max', 'mean', 'normal']) – strategy to use for convolution while shrinking. Ignored if ‘output_size’ is equal to size of ‘data’.

  • flatten (bool) – bool, whether to flatten the array.

Returns:

tensor of shape (2, n_coords, n_coords), where n_coords is the length of input dataframe.

Return type:

ndarray

Given time series \(X = \{x_1, .., x_n\}\), we define its quantile bins as \(Q = \{q_1, ..., q_m\}\) and assign each \(x_i\) with the corresponding bin \(q_j\), \(f: X \mapsto \{1, ..., m\}\). Then, we construct an \(m\times m\) weighted adjacency matrix \(W\), such that \(W_{ij}\) is number of transitions from \(q_i\) to \(q_j\). After, we normalize rows of \(W\) such that \(\forall i \in \{1, ..., m\}: \sum_{j=1}^{m}W_{ij} = 1\), we have \(W_{ij} = P(x_k \in q_i|x_{k - 1} \in q_j)\), probability of transitioning from bin \(i\) to bin \(j\) in one step, which is a definition of Markov Transitional Matrix (MTM).

The problem of MTM is that it does not capture the time domain information, i.e. timestamps of \(X\). Instead, define Markov Transitional Field (MTF) as a \(n \times n\) matrix \(M\), where \(M_{ij} = W_{f(x_i), f(x_j)}\), the probability of going from bin \(f(x_i)\) to bin \(f(x_j)\) in \(k = |i - j|\) steps.

Reference

Zhiguang Wang & Tim Oates (2015). Spatial Encoding Temporal Correlations to Classify Temporal Data Using Convolutional Neural Networks. Served as a resource of MFT and GAF description.