Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Graphs that change over time
Some graphs are not fixed pictures but streams of events: who messaged whom, which vehicles passed close to each other, which machines exchanged data, each with a time stamp. Old events matter less than recent ones, and relationships change. Temporal graph networks give every node a memory that is updated with each new event and gradually forgets the past. The demo shows how information travels over a graph; in a temporal graph it also has to travel forward in time.
Fraud detection, network intrusion detection, traffic and contact tracing, and multi-robot interaction logs are all event streams. Predicting the next interaction needs models that respect time.
- 1. A temporal graph is…
- 2. Each node in a TGN keeps…
- 3. Recent events usually matter…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Events: (u, v, t, e) are interactions between u and v at time t, with features e.
- TGN components:
- memory s_u, updated after each event by a GRU from a message m = msg(s_u, s_v, Δt, e);
- embedding z_u(t): attention over u’s recent temporal neighbours, using their memories and time encodings;
- decoder: for example an MLP on (z_u, z_v) for link prediction.
- Time encoding (TGAT): φ(Δt) = cos(ωΔt + b) over learned frequencies, so the model can tell recent from old.
- Forgetting: with a half-life h, a memory decays by 0.5^(Δt/h). After 3 half-lives, 1/8 remains.
- Evaluation:
- train on the past and test on the future (never shuffle across time);
- report hits@1, mean reciprocal rank (MRR; ranks 2 and 4 give 0.375) or AUC.
- 1. Decay after 3 half-lives:
- 2. MRR for ranks 2 and 4:
- 3. Temporal evaluation must…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Temporal graph networks in code
Exercise 1.
- The time encoding gave cos values at the right phases.
- The memory decayed to a quarter after two half-lives.
- MRR was implemented.
Practice.
- PyTorch Geometric provides
TGNMemory,TransformerConvwith time encodings andTemporalDataloaders. The TGB benchmark suite gives standard temporal splits. - Batch events in time order; update memories after predicting each batch, never before.
- Always compare against memorisation baselines such as EdgeBank, which predicts edges seen recently or ever. They are surprisingly strong.
from torch_geometric.nn import TGNMemory
memory = TGNMemory(num_nodes, raw_msg_dim, memory_dim, time_dim, message_module, aggregator_module)
for batch in loader: # in time order
z = embed(memory(n_id)[0], batch) # predict with memories from BEFORE the batch
loss = link_loss(z, batch); loss.backward(); opt.step()
memory.update_state(batch.src, batch.dst, batch.t, batch.msg) # then update memories- 1. PyG module for node memory:
- 2. Memories must be updated…
- 3. A strong memorisation baseline:
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why static snapshots fail.
- Aggregating all events into one static graph weights a relationship from long ago as much as one from yesterday.
- When relationships drift, static counts keep predicting the old partners.
- Memory with forgetting tracks the current state. The forgetting rate sets a bias–variance trade-off: fast forgetting adapts quickly but relies on few events; slow forgetting is stable but stale.
Continuous time.
- Events arrive at irregular times. Time encodings let attention weigh neighbours by elapsed time, and memories make information persist between events.
- Together they act like a recurrent network running over each node’s event sequence, coupled across nodes by interactions.
Information leakage. Using future events, even indirectly through memories updated before prediction, inflates results. Temporal splits and careful batching are essential, and simple baselines often reveal leakage.
- 1. Fast forgetting gives…
- 2. TGN's memory acts like…
- 3. Updating memories before prediction causes…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does forgetting help predict a changing graph?
History.
- S. Kumar, X. Zhang and J. Leskovec, “Predicting dynamic embedding trajectory in temporal interaction networks” (JODIE, KDD 2019).
- D. Xu et al., “Inductive representation learning on temporal graphs” (TGAT, ICLR 2020), introduced functional time encodings.
- E. Rossi et al., “Temporal graph networks for deep learning on dynamic graphs” (2020).
- F. Poursafaei et al. (NeurIPS 2022) showed that memorisation baselines (EdgeBank) are strong.
Exercise 2.
- Stream: 50 nodes and 6000 steps. At each step, a random node interacts with one of its 3 current partners (80%) or a random node (20%). Every node’s partners are redrawn every 1500 steps.
- Task: for each event after step 1000, rank all nodes as the likely partner of the source node, using only past events.
- Methods: static counts of all past interactions, against a memory of counts with exponential forgetting (half-life h). The best possible hits@1 is 0.8/3 + 0.2/50 = 0.271.
| method | hits@1 | MRR |
|---|---|---|
| static counts (all history) | 0.067 | 0.228 |
| memory, half-life 100 | 0.247 | 0.442 |
| memory, half-life 300 | 0.242 | 0.441 |
| memory, half-life 1000 | 0.178 | 0.365 |
| memory, half-life 3000 | 0.119 | 0.287 |
- Forgetting is essential: after partners change, static counts keep favouring old partners, so hits@1 is only 0.067. A memory with a 100-step half-life reached 0.247, 91% of the ceiling.
- The half-life sets the trade-off: short memories adapt within a few events of a switch. Long ones (3000) behave increasingly like static counts.
- Seeds: seeds 1 and 2 gave the same picture (static 0.07, best memory 0.24).
- Caveat: this memory is a hand-designed heuristic, close to a time-windowed EdgeBank. A learned TGN can learn the forgetting rate and use node features, but must at least match this baseline.
Temporal graphs in AI, robotics and aerospace
- Security and fraud: detecting unusual new connections in network traffic or transactions as they happen.
- Traffic and airspace: predicting encounters between vehicles or aircraft from evolving proximity graphs.
- Fleet operations: modelling interactions between robots, tasks and stations over time.
- Design lesson: match the model’s memory to how fast the world changes, evaluate strictly forward in time, and beat memorisation baselines before claiming progress.
References
- E. Rossi et al. (2020). “Temporal graph networks for deep learning on dynamic graphs.” ICML Workshop on Graph Representation Learning.
- D. Xu, C. Ruan, E. Korpeoglu, S. Kumar and K. Achan (2020). “Inductive representation learning on temporal graphs.” ICLR.
- F. Poursafaei, S. Huang, K. Pelrine and R. Rabbany (2022). “Towards better evaluation for dynamic link prediction.” NeurIPS Datasets and Benchmarks.