Update Log
2021-12-17: Initial Upload
The Gramian Angular Field is a tool which can convert 1-D time series data into 2-D images for further analysis.
Mapping from Catesian Coordinates to Polar Coordinates
The first step of this algorithm is to rescale the data in Catesian coordinates to [0, 1] or [-1, 1] by one of the following methods:
or
Then the timestamps of time series are divided by depending on how many points in time are there in the time series, and it determines the size of the converted Gram matrix. After the division, the intermediate results are mapped to in the polar coordinate, while the cosine value are mapped to . That’s why we need to have them rescaled before the mapping to make sure that they fall within the range of cosine function. [0, 1] corresponds to the cosine function in [0, π/2], while cosine values in the interval [−1, 1] fall into the angular bounds [0, π]. See the definition below.
Generating Gram Matrix
Gram Matrix is a useful tool in linear algebra. It is defined as a matrix generated by dot product of a group of n-dimension vectors.
They symbol and are vectors, and indicates the dot product of vector and . The authors defined two specific dot product operations for data in polar coordinate, to better exploit the information stored in angles:
\begin{align} u \oplus v=\cos \left(\theta_{u}+\theta_{v}\right)\\ u \oplus v=\sin \left(\theta_{u}-\theta_{v}\right) \end{align}
where indicates the angle of vector and in the polar coordinate, and the subscripts corresponds to the . Under this condition, the Gram Matrix of the rescaled 1-D time series data becomes
\begin{equation} G=\left(\begin{array}{cccc} \cos \left(\phi_{1}+\phi_{1}\right) & \cos \left(\phi_{1}+\phi_{2}\right) & \cdots & \cos \left(\phi_{1}+\phi_{n}\right) \\ \cos \left(\phi_{2}+\phi_{1}\right) & \cos \left(\phi_{2}+\phi_{2}\right) & \cdots & \cos \left(\phi_{2}+\phi_{n}\right) \\ \vdots & \vdots & \ddots & \vdots \\ \cos \left(\phi_{n}+\phi_{1}\right) & \cos \left(\phi_{n}+\phi_{2}\right) & \cdots & \cos \left(\phi_{n}+\phi_{n}\right) \end{array}\right) \end{equation}
or
\begin{equation} G=\left(\begin{array}{cccc} \sin \left(\phi_{1}-\phi_{1}\right) & \sin \left(\phi_{1}-\phi_{2}\right) & \cdots & \sin \left(\phi_{1}-\phi_{n}\right) \\ \sin \left(\phi_{2}-\phi_{1}\right) & \sin \left(\phi_{2}-\phi_{2}\right) & \cdots & \sin \left(\phi_{2}-\phi_{n}\right) \\ \vdots & \vdots & \ddots & \vdots \\ \sin \left(\phi_{n}-\phi_{1}\right) & \sin \left(\phi_{n}-\phi_{2}\right) & \cdots & \sin \left(\phi_{n}-\phi_{n}\right) \end{array}\right) \end{equation}
depending on which operation is taken to form the matrix. Equation (3) is called Gramian Angular Summation Fields (GASF), and Gramian Angular Differnce Fields (GADF) for equation (4). Note that unlike a standard dot production operation the customized one is not linear, nor positive definite, so the authors used a different symbol here.
Thie presentation of time series has a inherent advantage which is the ability to keep the absolute temporal relations, and time increases as the position moves from top-left to bottom-right. You may notice that elements lie on the main diagonal are in the temporal order, and every other element indicate the relation of any two points in time.
Final Image
Finally, the color coded images are generated by using normalisation and a colormap, see[1].
Sparse Representation
Let’s check out the density of Gramian Angular Field.

From the above figure, we can see that Gramian Angular Field is quite sparse. To explain this feature, let’s check the formula of back in Catesian coordinate.
It can be seen from the above the equation that the newly defined dot production operation is actually a standard dot production plus a penalty item, which pushes the result towards . For and closer to 1, the penalty increases, because these samples are more likely to be gaussian noise.
Others
- Limitation: if the length of time series data is , the size of generated matrix will be . The authors recommend to use Piecewise Aggregation Approximation to smooth the input data and limit the size.
- Library: a third-party library ‘pyts’[2] has a built-in function to do the conversion with GAF.