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

# Gramian Angular Field (GAF) Transformation

The Gramian Angular Field (GAF) transformation is a family of mathematically principled mappings that encode a one-dimensional sequence—typically a univariate time series or spectral signature—into a 2D matrix designed for image-based analysis. By representing each time point as an angle on the unit circle and expressing the pairwise angular sum or difference relationships as trigonometric matrix entries, GAF exposes the temporal and magnitude correlations as spatial patterns. This transformation is now a widely deployed foundation for leveraging convolutional and transformer-based models designed for images in time series classification, regression, and transfer learning across domains such as medicine, finance, industrial monitoring, and physical trajectory analysis.

## 1. Mathematical Foundations and Variants

The construction of the Gramian Angular Field proceeds in three algorithmic steps: rescaling, angular (polar) encoding, and matrix formation.

**a. Normalization and Polar Encoding**  
Given a univariate sequence $x = [x_1, x_2, \ldots, x_N]$, the data are first rescaled to $[-1, 1]$ or $[0, 1]$:

\[
\tilde{x}_i = \frac{x_i - \min(x)}{\max(x) - \min(x)} \times 2 - 1,\quad \tilde{x}_i \in [-1, 1]
\]

or equivalently, in $[0, 1]$ for some variants.

Each normalized value is then mapped to an angle:

\[
\phi_i = \arccos(\tilde{x}_i), \qquad r_i = \frac{i}{N}
\]

where $r_i$ (radius) is optional and primarily used for visualization or indexing.

**b. Gramian Matrices: GASF and GADF**  
From the collection of angles $\{\phi_i\}$, two matrix-valued fields are constructed:

- **Gramian Angular Summation Field (GASF):**
  \[
  \mathrm{GASF}_{i,j} = \cos(\phi_i + \phi_j) = \tilde{x}_i \tilde{x}_j - \sqrt{1-\tilde{x}_i^2}\sqrt{1-\tilde{x}_j^2}
  \]
  GASF is symmetric.

- **Gramian Angular Difference Field (GADF):**
  \[
  \mathrm{GADF}_{i,j} = \sin(\phi_i - \phi_j) = \sqrt{1-\tilde{x}_i^2} \tilde{x}_j - \tilde{x}_i \sqrt{1-\tilde{x}_j^2}
  \]
  GADF is skew-symmetric.

These definitions appear consistently across applications and are mathematically justified through trigonometric identities [1509.07481, 2504.00378, 2302.13011, 2310.01416, 2512.05830, 2511.03753, 2204.10099].

## 2. Algorithmic Implementation and Practical Pipeline

The GAF can be constructed as follows:

```python
# Pseudocode for computing GASF from a time series x[1..N]
min_x = min(x)
max_x = max(x)
x_scaled = [2*(xi - min_x)/(max_x - min_x) - 1 for xi in x]            # normalize to [-1,1]
phi = [arccos(z) for z in x_scaled]                                   # map to angle in [0,π]
G = np.zeros((N, N))
for i in range(N):
    for j in range(N):
        G[i, j] = cos(phi[i] + phi[j])                                # GASF
```

The typical computational cost is $O(N^2)$ per matrix; output matrices are commonly resized (e.g., to $32 \times 32$, $128 \times 128$, or $224 \times 224$) to fit modern CNN input requirements [2511.03753, 2308.02395, 2310.13906, 2512.05830]. Multiple channels or features can be handled by stacking GASF/GADF tensors across the channel dimension [2310.13906, 2204.10099].

Normalization to $[-1,1]$ is required before applying $\arccos$ to avoid domain errors [1509.07481, 2310.01416, 2512.05830].

## 3. Theoretical Properties and Intuitive Insights

Several invariants and properties characterize GAF images:

- **Temporal Dependency Preservation:** As both axes of the GAF correspond to time indices, the spatial structure of the matrix preserves the global and local temporal dependencies in the original sequence; lags correspond to off-diagonals [1509.07481, 2310.01416].

- **Magnitude and Correlation Encoding:** The diagonal encodes the self-relations (absolute values), while off-diagonal patterns capture pairwise (co-)evolution. Symmetry and skew-symmetry (for GASF and GADF, respectively) encode additive and subtractive angular relationships [2512.05830, 2302.13011, 2204.10099, 2310.13906].

- **Bijectivity:** The mapping is invertible up to a sign ambiguity, as the main diagonal ($\cos(2\phi_i)$) allows for original values to be approximately reconstructed [1509.07481, 1901.05237].

- **Robustness:** The angular representation constrains the feature space, improving robustness to amplitude scaling and some forms of outlier distortion [2501.01960, 2310.01416].

- **Channel and Feature Fusion:** Stacking multiple GASF/GADF objects or combining with other representations (recurrence plots, Markov transition fields) allows for multi-view learning [2512.05830, 2310.13906, 1509.07481].

## 4. Applications and Empirical Impact

GAF has enabled advances in a wide array of sequence modeling domains:

| Domain          | Paper Reference             | GAF Role                        |
|-----------------|----------------------------|----------------------------------|
| ECG Analysis    | [2501.01960, 2308.02395, 2302.13011, 2511.03753] | Image representation for CNN classification, federated learning, arrhythmia and MI detection |
| EEG/fNIRS       | [2003.04534, 2110.12503]   | Epilepsy/attention detection, formation of RGB/14-channel images for CNNs/autoencoders |
| BOLD fMRI       | [2309.03590]               | Image-based classification of brain signals, outperforming LSTM with 2D CNNs         |
| Finance         | [2504.00378, 2310.07427, 1901.05237] | Domain similarity for transfer learning, pattern classification, quantum GAF for error reduction |
| Optical Fiber   | [2512.05830]               | Multi-channel event detection, EfficientNet/DenseNet with GASF/GADF/RP channels      |
| Hyperspectral   | [2204.10099]               | Pixel-wise classification, 2-channel GAF with Neighborhood Attention U-Net           |
| Single-particle | [2310.01416]               | Trajectory analysis, pretrained ResNet/MobileNet, outperforming ConvLSTM and Transformers |

Empirical improvements reported include 2–3% gains in ECG classification tasks over pure time series models [2501.01960], up to 22.2% F1-score lift in wearable sensor-based disease detection [2411.11764], and significant error reduction in financial forecasting using GAF-based similarity measures over baseline CMD/Coral metrics [2504.00378]. In federated IoT medical challenges, GAF-based pipelines achieved ~8 pp higher accuracy relative to single-client setups while remaining computationally viable on edge devices [2511.03753].

## 5. Architectural Integration and Design Considerations

The dominant paradigm since GAF's introduction is to use the produced image-like matrices as direct input to deep convolutional backbones (ResNet, EfficientNet, U-Net, ViT, etc.) either as single-channel or multi-channel composites [2501.01960, 2204.10099, 2310.13906, 2512.05830]. Typical configurations include:

- **Image resizing:** After GAF computation, raw $N\times N$ is interpolated or downsampled (commonly $224\times224$, $128\times128$, or $32\times32$) for compatibility with pretrained computer vision networks [2511.03753, 2512.05830].
- **Multi-view stacking:** GASF, GADF, and other texture fields (e.g., recurrence plots) concatenated as RGB or higher-order tensors [2512.05830, 2310.13906].
- **Attention and fusion:** Integration of spatial/channel attention modules to emphasize relevant 2D angular features [2204.10099, 2501.01960, 2310.13906].
- **Sliding window and padding:** Windowing for fixed-size matrix generation, optional zero-padding to harmonize sequence lengths [2310.01416, 2310.13906].
- **Resource constraints:** On-device pipelines compress GAF to $32\times32$ for memory-efficient federated learning [2511.03753].
- **Quantum-classical hybrid:** Quantum GAF (QGAF) implements the inner product in single-qubit circuits, reducing the need for explicit normalization or $\arccos$ [2310.07427].

The construction and application of GAF require careful normalization to $[-1,1]$ to prevent numerical errors, balancing compute/memory cost with window size and resolution, and, in large-scale contexts, batching or approximation to mitigate $O(N^2)$ complexity [2308.02395, 2504.00378, 2310.01416].

## 6. Limitations and Best Practices

The GAF approach exhibits quadratic complexity in both compute and memory, posing challenges for extremely long sequences or real-time applications. Downsampling, approximate GAF construction, or tiling is recommended for scalability [2512.05830, 2310.01416, 2511.03753]. While GAF images encode comprehensive temporal correlations, the information is "entangled" and spatially distributed; thus, some fine detail or local context may be lost upon aggressive downscaling [2310.01416, 2308.02395].

Best practices include:

- Strict normalization to $[-1,1]$ before angular mapping.
- Consistent use of $\arccos$ (vs.\ $\arcsin$) to ensure interpretive stability.
- Generation of both GASF and GADF for complementary correlation pattern coverage.
- Adaptation of image size to balance resolution demands and CNN scalability.
- Multi-channel/fusion architectures when multiple signals are present.
- Validation and tuning for downstream deep models, as hyperparameters (window size, stride, resizing) significantly influence performance [2512.05830, 2511.03753, 2310.01416].

## 7. Future Directions

Recent developments encompass the integration of quantum circuits for GAF computation, purportedly removing normalization and $\arccos$ requirements and accelerating training convergence (QGAF) [2310.07427]. Another trend includes expanding GAF utility for multi-modal fusion (combining raw sequences, GAFs, recurrence plots, and MTFs) to improve domain transfer and temporal pattern recognition [2504.00378, 2512.05830]. Applications are rapidly growing, from federated and privacy-preserving healthcare on IoT to robust autonomous vehicle behavior analysis [2411.11764, 2310.13906].

Open research questions remain on approximating GAF for online/streaming settings, optimal resizing without loss of crucial temporal features, formal analysis of information loss across channel fusion, and extending GAFs to non-Euclidean or irregularly sampled data. There is also ongoing interest in interpretable models that leverage the structured 2D output of GAF for attribution and model explanation in time series-based decision systems [2310.01416, 1509.07481].

---

The Gramian Angular Field formulation offers a unified mathematical and computational framework for translating sequential amplitude and temporal correlation structure into spatially organized representations that are both theoretically appealing and empirically powerful in the context of modern image-based machine learning [1509.07481, 2501.01960, 2512.05830, 2511.03753, 2310.13906, 2310.01416, 2302.13011, 2308.02395, 2204.10099, 2110.12503, 2003.04534, 2411.11764, 2504.00378, 2310.07427, 2309.03590, 1901.05237].

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