get_gaf

eyefeatures.features.feature_maps.get_gaf(data, x, y, t=None, field_type='difference', to_polar='cosine', flatten=False)[source]

Calculates Gramian Angular Field for (x,y) coordinates.

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

  • x (str) – X coordinate column name.

  • y (str) – Y coordinate column name.

  • t (str) – timestamps column name.

  • field_type (Literal['difference', 'sum']) – which type of field to calculate. If “difference”, then GADF is returned, otherwise (“sum”) GASF is returned.

  • to_polar (Literal['regular', 'cosine']) –

    conversion from cartesian to polar coordinates. * ‘regular’: standard conversion calculating arctan(y/x). * ‘cosine’: angle is calculated as cosine of series data,

    radius is taken as timestamps.

  • 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\}\) of \(n\) real-valued observations, GAF is build using the following procedure:

1. Series is rescaled to \([0, 1]\) using min-max scaling (or assumed to be already scaled, look at scale parameter of get_gaf method):

\[\tilde{x}_i = \frac{x_i - \min X}{\max X - \min X}\]

2. Scaled time series \(\tilde{X}\) is converted to polar coordinates using one of two methods (\(t_i\) is corresponding timestamp):

  • Trigonometric formula (to_polar='regular')

\[r_i = \sqrt{\tilde{x}_i^2 + t_i^2}, \ \phi_i = arctan\left(\frac{t_i}{\tilde{x}_i}\right)\]
  • Cosine formula (to_polar='cosine')

\[r_i = \frac{t_i}{n}, \ \phi_i = arccos(\tilde{x}_i)\]
  1. Then matrix \(M\) is constructed, again with one of two ways:
    • Cosine of sum (field_type='sum')

    \[(M)_{ij} = \cos(\phi_i + \phi_j)\]
    • Sine of difference (field_type=’difference’)

    \[(M)_{ij} = \sin(\phi_i - \phi_j)\]

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.