---
title: Gramian Angular Field (GAF)
url: https://www.emergentmind.com/topics/gramian-angular-field-gaf
type: topic
---

# Gramian Angular Field (GAF)

Gramian Angular Field (GAF) is a two-dimensional encoding of a one-dimensional ordered signal in which normalized sample values are mapped to angular coordinates, temporal indices are mapped to radii, and pairwise angular interactions are assembled into a square Gramian matrix. In the imaging-time-series formulation associated with Wang and Oates, GAF was introduced to spatially encode temporal correlations so that temporal data could be analyzed with computer-vision methods such as convolutional neural networks [1509.07481]. Subsequent work has treated GAF as a representation layer for ECG, EEG, fMRI, anomalous diffusion trajectories, hyperspectral spectra, financial series, wearable gait signals, and autonomous-vehicle behavior, largely because it preserves temporal dependency while exposing structured image patterns to 2D models [2105.13536][2310.13906].

## 1. Concept and historical development

The original GAF program was framed as an off-line method for explicitly encoding temporal patterns spatially as images, alongside Markov Transition Fields, so that convolutional models could learn high-level features from temporal data [1509.07481]. In that formulation, the attraction of GAF was not merely that it produced an image, but that the image retained an interpretable temporal geometry: time progresses from the top-left to the bottom-right, the main diagonal is special, and the resulting matrix can preserve information about the original series.

Later application papers restated the same rationale in domain-specific language. In ECG, GAF has been used as a heartbeat representation that preserves temporal correlation through angular encoding and pairwise cosine interactions, so that AlexNet or other CNNs can operate on heartbeats as images rather than on handcrafted features or raw 1D vectors [2105.13536]. In autonomous-vehicle behavior analysis, GAF is described as capturing pairwise angular relationships between points in multivariate behavior sequences and converting those sequences into multi-channel images for Vision Transformer classification [2310.13906]. Across these settings, the recurring conceptual role of GAF is the same: it acts as a bridge from sequential structure to spatial structure.

## 2. Mathematical formulation and principal variants

The canonical construction starts from a real-valued time series
\[
X=\{x_1,x_2,\dots,x_n\}.
\]
A first step rescales the series into a bounded interval. The original imaging-time-series formulation gives both
\[
\tilde{x}^{\,i}_{-1}=\frac{(x_i-\max(X))+(x_i-\min(X))}{\max(X)-\min(X)}
\]
for scaling to \([-1,1]\), and
\[
\tilde{x}^{\,i}_{0}=\frac{x_i-\min(X)}{\max(X)-\min(X)}
\]
for scaling to \([0,1]\) [1509.07481]. Later implementations instantiate both choices: ECG heartbeat imaging in the IFM pipeline explicitly rescales to \([0,1]\) before angular encoding [2105.13536], whereas EEG epilepsy diagnosis and inferior myocardial infarction detection use the \([-1,1]\) form before applying \(\arccos\) [2003.04534][2302.13011].

After rescaling, the series is represented in polar form by encoding the value as an angle and the timestamp as a radius:
\[
\phi_i=\arccos(\tilde{x}_i), \qquad r_i=\frac{t_i}{N}.
\]
The two standard Gramian variants are then formed by pairwise trigonometric interactions:
\[
\mathrm{GASF}_{i,j}=\cos(\phi_i+\phi_j),
\qquad
\mathrm{GADF}_{i,j}=\sin(\phi_i-\phi_j).
\]
The original paper writes the summation-field matrix in closed form as
\[
\mathrm{GASF}=\tilde{X}'\tilde{X}-\sqrt{I-\tilde{X}^2}'\sqrt{I-\tilde{X}^2},
\]
and later hyperspectral work gives the same GASF and GADF identities in expanded algebraic form over normalized inputs [1509.07481][2204.10099].

The distinction between the two variants is operationally important. GASF uses cosine of angular sums and is the form used in many ECG and trajectory papers [2105.13536][2310.01416]. GADF uses sine of angular differences and is explicit in EEG attention regression, ECG myocardial infarction detection, and some multichannel representations [2110.12503][2302.13011]. Several papers mention both variants conceptually but implement only one; others concatenate both as complementary image channels.

## 3. Representation properties and image organization

A GAF image has native size \(n\times n\) for an input of length \(n\), because every time point is paired with every other time point. This representation preserves temporal ordering through matrix coordinates, while the main diagonal stores transformed self-information. In the summation-field case,
\[
\mathrm{GASF}_{i,i}=\cos(2\phi_i),
\]
and the original formulation notes that the normalized series can be approximately reconstructed from the diagonal via
\[
\cos(\phi)=\sqrt{\frac{\cos(2\phi)+1}{2}}.
\]
This diagonal structure is one reason GAF has been treated as more interpretable than some alternative time-series image encodings [1509.07481].

Practical systems rarely stop at a single grayscale matrix. Multivariate or multi-sensor data are commonly transformed channelwise and then stacked. In candlestick classification, four feature sequences—either OHLC or CULR—are each converted to a \(10\times 10\) GASF image and stacked into a \(10\times 10\times 4\) tensor [1901.05237]. In EEG attention regression, each of 14 electrodes is transformed independently into a GADF image, and the 14 images are stacked into a single 14-channel tensor [2110.12503]. In autonomous-vehicle behavior analysis, each of the three behavior variables is transformed into both GASF and GADF, and the resulting images are concatenated into a multi-channel representation [2310.13906]. In ECG multimodal fusion, GAF, recurrence plot, and Markov Transition Field are treated as three orthogonal channels “like three different colors in RGB image space” [2105.13536].

Resizing is also common, because downstream vision backbones usually expect fixed spatial dimensions. ECG heartbeats of length 187 imply a native \(187\times 187\) GAF, but AlexNet-based pipelines resize the images to \(227\times 227\) [2105.13536]. EEG epochs of 256 samples yield \(256\times 256\) GASF images that are subsequently prepared for \(224\times 224\times 3\) CNN input through pseudocolor and resizing [2003.04534]. Inferior myocardial infarction detection converts 651-sample beats into \(128\times 128\) grayscale images, although the paper does not fully specify whether resizing is applied before or after native Gramian formation [2302.13011].

## 4. Integration with learning architectures

GAF has been coupled to a wide range of vision architectures. The earliest benchmark study used Tiled CNNs with Topographic ICA pretraining and a final linear soft-margin SVM on GAF, MTF, and GAF-MTF images [1509.07481]. Later biomedical work used transfer-learning style image classifiers such as AlexNet, VGG16, and VGG19 on GASF-derived EEG images, alongside a custom CNN specifically designed for those images [2003.04534]. In anomalous diffusion analysis, GAF images enable the use of pretrained ResNet and MobileNet backbones on short noisy trajectories [2310.01416].

The representation has also been embedded in explicitly multimodal systems. GAF-FusionNet treats GAF as one of two primary modalities, pairing a GAF image branch with a raw time-series branch and fusing the resulting features through a dual-layer cross-channel split attention module; in the ablation study, the GAF-only branch slightly outperformed the time-series-only branch on MIT-BIH, while the fused system was best overall [2501.01960]. In autonomous-vehicle behavior recognition, GAF-generated multichannel images are reweighted by a channel-attention module and then passed to a multi-channel Vision Transformer [2310.13906]. In hyperspectral image classification, single-pixel spectra are converted into GASF and GADF images and then processed by a neighborhood-attention U-Net rather than by a 1D spectral model [2204.10099].

These architectures reflect three distinct integration patterns. One is **direct substitution**, in which GAF simply replaces the raw sequence as the model input. Another is **channelwise fusion**, in which GAF is combined with other 2D encodings such as RP or MTF. A third is **cross-modal fusion**, in which the raw 1D sequence and the GAF image are processed in parallel and merged later. The literature now contains examples of all three.

## 5. Application domains and empirical record

The empirical record is broad rather than uniform. Many biomedical classification tasks report strong gains from GAF-based encodings, whereas some forecasting tasks do not.

| Domain | Representative finding | Paper |
|---|---|---|
| ECG heartbeat classification | GAF alone reached 97.3% accuracy on MIT-BIH and 98.4% on PTB; the fused IFM reached 98.6% and 98.4% | [2105.13536] |
| Inferior MI detection from lead II ECG | Best result was 99.84% accuracy with GADF after noise and baseline-wander removal | [2302.13011] |
| EEG epilepsy diagnosis | Custom CNN on GASF images achieved average Precision 0.885, Recall 0.92, F1-score 0.90, and AUC 0.92 | [2003.04534] |
| fMRI BOLD categorization | Single CNN with GASF achieved 0.87 mean 3-class accuracy, GADF 0.85, and parallel GAF+MTF 0.94 | [2309.03590] |
| Anomalous diffusion trajectories | GASF/ResNet reached F1-score 0.581 and AUC 0.89; GADF/ResNet achieved MAE 0.33 for \(\alpha\) regression | [2310.01416] |
| Freezing-of-gait detection | Single-axis AccV GAF achieved 96.3% accuracy and 96.3% F1 | [2411.11764] |
| AV driving behavior classification | GAF-ViT achieved Accuracy 0.9209 and F1 0.8747 | [2310.13906] |
| Pixel-wise HSI classification | GAF-NAU reached OA 81.07 on Indian Pines, 91.12 on University of Pavia, and 94.59 on Salinas Valley | [2204.10099] |

Financial and market applications have also used GAF successfully in some classification settings. Encoding candlesticks as multichannel GASF images yielded 90.7% average accuracy on real-world EUR/USD data and outperformed an LSTM baseline [1901.05237]. By contrast, transfer learning in stock forecasting uses GAF differently: it converts source and target series into GAF images so that similarity functions such as CORAL or CMD can select more appropriate source domains before DNN or LSTM training [2504.00378].

A clear pattern emerges from these results. GAF is repeatedly effective in classification and representation-learning settings where discriminative structure lies in morphology, temporal correlation, or pairwise dynamics. It is also effective when multichannel composition itself is informative, as in EEG electrodes, accelerometer axes, driving features, or hyperspectral bands.

## 6. Limitations, methodological caveats, and common misconceptions

The literature also shows substantial methodological variability. Preprocessing details are often underreported. The ECG IFM paper specifies lead II, resampling to 125 Hz, heartbeat length 187 for MIT-BIH, normalization to \([0,1]\), and resizing to \(227\times 227\), but it does not describe R-peak detection, explicit heartbeat windowing, denoising, or baseline-wander removal [2105.13536]. The inferior-MI ECG paper gives explicit beat extraction around R-peaks and explicit GASF/GADF formulas, but does not specify the interpolation or resizing step that maps 651-sample beats to \(128\times 128\) images [2302.13011]. The fMRI pilot study omits the exact GAF image size \(m\), the exact subsequence lengths after splitting by dataset, and whether resizing was applied [2309.03590]. The freezing-of-gait paper reports \(64\times 64\) GAF inputs from 4-second windows at 64 Hz, but does not explicitly state how 256 samples become \(64\times 64\) images [2411.11764].

Normalization conventions are similarly heterogeneous. Some pipelines use \([0,1]\), some use \([-1,1]\), and some describe both a mean-centering or z-score stage and a later min-max stage before angular encoding [2105.13536][2411.11764]. This matters because \(\arccos\) imposes a hard domain constraint, and small changes in scaling alter the image numerics even when the downstream architecture is unchanged.

Because every pixel depends on a pair of time indices, a plausible implication is quadratic native image growth with sequence length. That implication is consistent with the original reliance on Piecewise Aggregate Approximation before GAF construction and with later widespread post-encoding resizing [1509.07481]. The growth is not only a memory issue; it can also alter the inductive bias of the system, because aggressive downsampling or resizing may erase the very correlations the encoding was meant to preserve.

A common misconception is that GAF is universally beneficial once a task is recast as image recognition. The bond-index forecasting study directly contradicts that view: CNN-GAF models produced uniformly negative out-of-sample \(R^2\) on levels, returns, and fractionally differenced series, and the authors concluded that GAF-based CNNs are better suited to pattern-based tasks than to persistence-dominated next-step prediction [2605.27977]. The limitation is therefore not merely implementation noise; it is a representational mismatch in some forecasting regimes.

## 7. Extensions and current directions

Recent work has pushed GAF beyond its classical formulation in three directions: alternative construction rules, domain-adaptive similarity, and privacy-preserving deployment. Quantum Gramian Angular Field (QGAF) replaces explicit normalization and inverse-cosine calculation with single-qubit \(R_y\) rotations and measurement probabilities, and the reported stock-return experiments show average error reductions of 25% in MAE and 48% in MSE relative to classical GAF [2310.07427]. This is a direct attempt to modify the encoding stage itself rather than only the downstream classifier.

Another direction treats GAF as a representation for domain comparison rather than end-task classification. In financial transfer learning, source and target time series are first converted into GAF images and then compared with similarity functions; under that protocol, Coral (GAF) for DNN and CMD (GAF) for LSTM are reported as the strongest choices across several source-selection settings [2504.00378]. Here GAF is not the final predictive modality but the basis for source-domain selection.

A third direction is deployment under decentralized or resource-constrained conditions. In federated ECG classification, 1D ECG signals are transformed locally into \(32\times 32\) GAF images and used to train a CNN across a server, a laptop, and a Raspberry Pi 4; the multi-client setup achieved 95.18% test accuracy versus 87.30% for the single-client baseline [2511.03753]. That work also makes an important conceptual distinction: privacy is provided by federated learning, not by GAF itself.

Taken together, these developments indicate that GAF has evolved from a specific imaging-time-series construction into a broader representational family. The core idea remains stable—angular encoding plus pairwise temporal interaction—but current work explores where in the pipeline GAF should appear, how it should be parameterized, and when it is preferable to raw sequential modeling.

Source: https://www.emergentmind.com/topics/gramian-angular-field-gaf