File size: 13,136 Bytes
1258e8b
 
 
 
 
 
 
 
 
7f6e981
 
1258e8b
 
 
 
 
7f6e981
1258e8b
7f6e981
 
 
 
 
1258e8b
 
 
 
7f6e981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258e8b
 
 
7f6e981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258e8b
 
 
7f6e981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258e8b
 
 
7f6e981
 
 
 
 
 
 
 
 
 
 
 
 
1258e8b
 
 
7f6e981
 
1258e8b
7f6e981
 
 
1258e8b
7f6e981
 
 
 
 
 
 
 
1258e8b
 
 
 
 
 
 
7f6e981
 
 
1258e8b
7f6e981
1258e8b
 
 
7f6e981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258e8b
 
 
 
7f6e981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258e8b
 
 
7f6e981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
---
license: apache-2.0
tags:
- trajectory-prediction
- aviation
- adsb
- time-series
- llm-reprogramming
- gpt2
- air-traffic-management
- spatiotemporal
datasets:
- petchthwr/ATFMTraj
pipeline_tag: time-series-forecasting
---

# LLM4AirTrack: LLM-Driven Multi-Feature Fusion for Aircraft Trajectory Prediction

## Overview

**LLM4AirTrack** adapts the [LLM4STP](https://github.com/Joker-hang/LLM4STP) (Large Language Model for Ship Trajectory Prediction) framework from maritime AIS to aviation ADS-B domain. The core insight is that pre-trained LLMs encode powerful sequential pattern recognition that transfers to spatiotemporal trajectory data through lightweight reprogramming β€” without full fine-tuning.

The framework uses a **frozen GPT-2 backbone** with trainable adapter modules (~2.4% of total parameters) to predict future aircraft positions and classify flight routes/procedures.

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    LLM4AirTrack Framework                       β”‚
β”‚                                                                  β”‚
β”‚  ADS-B Features (9-dim: xyz + direction + polar)                β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                           β”‚
β”‚  β”‚ RevIN Normalizer  β”‚  Instance normalization per feature       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                           β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                           β”‚
β”‚  β”‚ Patch Tokenizer   β”‚  Overlapping temporal patches (8Γ—9=72)   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                           β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
β”‚  β”‚ Patch Embedder    β”‚   β”‚ Text Prototype Bank  β”‚                β”‚
β”‚  β”‚ (72 β†’ 768)        β”‚   β”‚ (256 learned protos) β”‚                β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β”‚       β”‚                         β”‚                                β”‚
β”‚       β–Ό                         β–Ό                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                       β”‚
β”‚  β”‚  Cross-Attention Reprogrammer        β”‚                       β”‚
β”‚  β”‚  Q=patches, K=V=prototypes (8-head)  β”‚                       β”‚
β”‚  β”‚  Maps trajectory β†’ LLM text space   β”‚                       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                       β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                           β”‚
β”‚  β”‚ Prompt-as-Prefix  β”‚  Aviation context prompt prepended       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                           β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                           β”‚
β”‚  β”‚  Frozen GPT-2     β”‚  124M params frozen, language knowledge  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                           β”‚
β”‚       β”‚                                                          β”‚
β”‚       β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                      β”‚
β”‚       β–Ό                  β–Ό                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                           β”‚
β”‚  β”‚ Traj Headβ”‚   β”‚ Classification   β”‚                           β”‚
β”‚  β”‚ (xyz)    β”‚   β”‚ Head (route/rwy) β”‚                           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Key Components

1. **9-Dimensional Kinematic Features** (from [ATSCC](https://arxiv.org/abs/2407.20028)):
   - Position: (x, y, z) in East-North-Up coordinates
   - Directional unit vectors: (ux, uy, uz) β€” velocity direction
   - Polar components: (r, sin ΞΈ, cos ΞΈ) β€” angular position

2. **Patch Tokenization**: Overlapping temporal windows (patch_len=8, stride=4) β†’ 14 patches from 60-step context

3. **Cross-Attention Reprogramming** (from [Time-LLM](https://arxiv.org/abs/2310.01728)): 256 learned text prototypes serve as a "translation dictionary" between trajectory and language domains

4. **Frozen GPT-2 Backbone**: 124M frozen parameters preserve pre-trained language understanding while keeping training efficient

5. **Dual Output Heads**:
   - **Trajectory Prediction**: Future (x, y, z) positions via Smooth L1 loss
   - **Route Classification**: STAR/IAF/Runway procedure via Cross-Entropy loss

### Parameter Efficiency

| Component | Parameters | Trainable |
|-----------|-----------|-----------|
| GPT-2 Backbone | 124,439,808 | 0 (frozen) |
| Patch Embedder | 57,600 | 57,600 |
| Cross-Attention Reprogrammer | 2,560,512 | 2,560,512 |
| Trajectory Head | 329,946 | 329,946 |
| Classification Head | 150,543 | 150,543 |
| **Total** | **127,543,059** | **3,103,251 (2.43%)** |

## Training

### Dataset
- **Source**: [ATFMTraj](https://huggingface.co/datasets/petchthwr/ATFMTraj) β€” RKSIa (Incheon International Airport arrivals)
- **Origin**: OpenSky ADS-B recordings, 2018-2023
- **Preprocessing**: Raw lat/lon/alt β†’ ENU coordinates β†’ normalized to [-1,1] by r_max=120km
- **Trajectories**: 8,091 training + 8,092 test (16,183 total flights)
- **Windows**: 282,191 training + 20,000 evaluation sliding windows
- **Context**: 60 timesteps (1-second intervals = 1 minute of flight)
- **Prediction**: 30 timesteps ahead (30 seconds)
- **Classes**: 39 route labels (STAR Γ— IAF Γ— Runway combinations)

### Hyperparameters
| Parameter | Value |
|-----------|-------|
| LLM Backbone | `openai-community/gpt2` (768 hidden, 12 layers) |
| Optimizer | AdamW (β₁=0.9, Ξ²β‚‚=0.999) |
| Learning Rate | 5Γ—10⁻⁴ with cosine annealing warm restarts |
| Weight Decay | 1Γ—10⁻⁡ |
| Batch Size | 128 |
| Epochs | 5 |
| Gradient Clipping | max_norm=1.0 |
| Multi-task Weight | Ξ»_traj=1.0, Ξ»_cls=0.1 |
| Loss (trajectory) | Smooth L1 (Huber) |
| Loss (classification) | Cross-Entropy |
| Hardware | NVIDIA T4 (16GB VRAM, used ~1.4GB) |

## Results

| Epoch | Train Loss | ADE | FDE | Route Accuracy |
|-------|-----------|-----|-----|----------------|
| 1 | 0.2335 | 0.01500 | 0.02047 | 34.7% |
| 2 | 0.2110 | 0.01200 | 0.01635 | 36.1% |
| **3** | **0.2033** | **0.01026** | **0.01426** | **36.3%** |
| 4 | 0.2037 | 0.01345 | 0.01858 | 34.9% |
| 5 | 0.2003 | 0.01518 | 0.02043 | 36.5% |

**Best model (epoch 3)**:
- **ADE: 0.01026** (normalized ENU scale; with r_max=120km β†’ ~1.23km average displacement)
- **FDE: 0.01426** (~1.71km final displacement error at 30s horizon)
- **Route Classification: 36.3%** accuracy over 39 classes (14Γ— above random baseline of 2.6%)
- **RMSE**: x=0.00957, y=0.00942, z=0.00072 (altitude prediction is very accurate)

## Usage

### Quick Inference

```python
import torch
import json
from huggingface_hub import hf_hub_download

# Download model files
config_path = hf_hub_download("Jdice27/LLM4AirTrack", "config.json")
weights_path = hf_hub_download("Jdice27/LLM4AirTrack", "adapter_weights.pt")

# You can use the self-contained train_full.py or the modular llm4airtrack package
from llm4airtrack.model import LLM4AirTrack

with open(config_path) as f:
    cfg = json.load(f)

model = LLM4AirTrack(
    llm_name=cfg["llm_name"],
    context_len=cfg["context_len"],
    pred_len=cfg["pred_len"],
    n_classes=cfg["n_classes"],
    n_prototypes=cfg["n_prototypes"],
    patch_len=cfg["patch_len"],
    patch_stride=cfg["patch_stride"],
)
state = torch.load(weights_path, map_location="cpu")
model.load_state_dict(state, strict=False)
model.eval()

# Input: 60 timesteps Γ— 9 kinematic features
# Features: [x, y, z, ux, uy, uz, r, sin_ΞΈ, cos_ΞΈ] in ENU coordinates
context = torch.randn(1, 60, 9)  # Replace with real data
outputs = model(context, task="both")

future_xyz = outputs["pred_trajectory"]  # (1, 30, 3) β€” future ENU positions
route_probs = outputs["pred_class"].softmax(-1)  # (1, 39) β€” route probabilities
```

### Data Pipeline

```python
from llm4airtrack.data import download_atfm_dataset, load_atfm_raw, compute_kinematic_features

# Download and load ATFMTraj
download_atfm_dataset("RKSIa", cache_dir="./data")
data, labels = load_atfm_raw("RKSIa", "TEST", "./data")

# Get kinematic features for a single trajectory
traj = data[0]  # (T_max, 3) ENU coordinates
valid = ~np.isnan(traj[:, 0])
features = compute_kinematic_features(traj[valid])  # (T, 9)
```

## Downstream Tasks

The model produces rich trajectory representations suitable for:

| Task | How to Use |
|------|-----------|
| **Track Activity Classification** | Use `pred_class` output β€” identifies STAR/IAF/runway procedure |
| **Trajectory Prediction** | Use `pred_trajectory` β€” 30-second position forecast |
| **Anomaly Detection** | Compare `pred_trajectory` vs actual β€” large deviations flag anomalies |
| **Conflict Detection** | Run on multiple aircraft, check predicted trajectory intersections |
| **ETA Prediction** | Extract LLM hidden states as features for regression head |
| **Transfer to New Airports** | Fine-tune adapter weights on new airport data (ESSA, LSZH included in ATFMTraj) |

## Design Decisions & Adaptation from Maritime (LLM4STP) to Aviation (ADS-B)

| Aspect | LLM4STP (Maritime AIS) | LLM4AirTrack (Aviation ADS-B) |
|--------|----------------------|-------------------------------|
| Dimensionality | 2D (lat, lon) | **3D (lat, lon, altitude β†’ ENU xyz)** |
| Features | SOG, COG, ROT | Ground speed β†’ directional vectors; vertical rate β†’ uz |
| Update Rate | ~10s intervals | **1s intervals** (higher resolution) |
| Route Structure | Free navigation | **Defined STARs/SIDs** (structured procedures) |
| Context | Port/strait proximity | Airport/procedure context (encoded in prompt) |
| Phase Segmentation | Anchoring/transiting | Climb/cruise/descent/approach |
| Classification | Vessel type | **Route procedure (39 STARΓ—IAFΓ—RWY classes)** |
| Spatial Encoding | Lat/lon directly | **ENU Cartesian + polar components** |

## References

### Foundational Work
- **LLM4STP**: [GitHub](https://github.com/Joker-hang/LLM4STP) β€” Original maritime trajectory prediction framework
- **Time-LLM**: [arXiv 2310.01728](https://arxiv.org/abs/2310.01728) β€” LLM reprogramming for time series (ICLR 2024)

### Aviation Domain
- **ATSCC**: [arXiv 2407.20028](https://arxiv.org/abs/2407.20028) β€” Self-supervised trajectory representation, 9-dim feature engineering
- **LLM4Delay**: [arXiv 2510.23636](https://arxiv.org/abs/2510.23636) β€” Cross-modality LLM for aviation delay prediction
- **ATFMTraj**: [HuggingFace Dataset](https://huggingface.co/datasets/petchthwr/ATFMTraj) β€” Aircraft trajectory classification data

### Related Approaches
- **Flight2Vec**: [arXiv 2412.16581](https://arxiv.org/abs/2412.16581) β€” Behavior-adaptive patching for flight trajectories
- **H3+CLM**: [arXiv 2405.09596](https://arxiv.org/abs/2405.09596) β€” Spatial tokenization for trajectory prediction
- **SKETCH**: [arXiv 2601.18537](https://arxiv.org/abs/2601.18537) β€” Semantic key-point conditioning

## Citation

```bibtex
@misc{llm4airtrack2026,
  title={LLM4AirTrack: LLM-Driven Multi-Feature Fusion for Aircraft Trajectory Prediction},
  author={Jdice27},
  year={2026},
  url={https://huggingface.co/Jdice27/LLM4AirTrack},
  note={Adapted from LLM4STP for aviation ADS-B domain}
}
```