Learning Distinguishable Trajectory Representation with Contrastive Loss

Tianxu Li, Kun Zhu, Juan Li, Yang Zhang

In the world of Multi-Agent Reinforcement Learning (MARL), there is a classic double-edged sword called parameter sharing. To make training efficient, researchers often force all agents to use the exact same neural network. While this helps them learn faster by sharing experiences, it often turns them into "clones" that behave identically, leading to poor exploration and a lack of specialized roles.

A new paper from researchers at the Nanjing University of Aeronautics and Astronautics, titled "Learning Distinguishable Trajectory Representation with Contrastive Loss," presents a clever way to fix this "homogeneity" problem without sacrificing the efficiency of shared parameters.

TL;DR

The authors propose Contrastive Trajectory Representation (CTR), a method that uses contrastive learning to force agents to develop unique behavioral "signatures." By maximizing the mutual information between an agent's path and a learnable identity, CTR encourages multi-agent diversity and significantly boosts performance in complex tasks like StarCraft II.

What Problem Does This Paper Address?

When agents share a policy network, they tend to converge on the same behaviors because they receive similar inputs. To combat this, previous researchers tried to maximize the "Mutual Information" (MI) between an agent’s trajectory and its identity. Essentially, they wanted to be able to look at a path and guess which agent took it.

However, older methods used variational inference, which often backfired. Agents would become "afraid" to explore new areas because doing so might make their identity less clear. They would overfit to known paths just to remain distinguishable, leading to stagnant learning. The challenge is: how do we make agents diverse while still encouraging them to explore the unknown?

Methods

The authors introduce CTR, which integrates a "representation learning" step directly into the MARL training loop.

The Contrastive Trajectory Representation (CTR) architecture.
  1. The Architecture: Each agent uses an Encoder (to process current observations) and an Autoregressive Model (a GRU) to summarize its entire history into a "trajectory representation."
  2. Learnable Identities: Unlike previous work that used fixed "one-hot" vectors (like Agent 1, Agent 2, etc.), CTR uses learnable identity representations. These are vectors that evolve during training to better "classify" the agents' unique behaviors.
  3. Contrastive Loss (InfoNCE): This is the core innovation. The model is trained to pull an agent's trajectory representation closer to its own identity vector while pushing it away from the identities of other agents on a high-dimensional hypersphere.
  4. Integration: This contrastive loss is added as an auxiliary objective to standard MARL algorithms like QMIX or MAPPO. It doesn't interfere with the main goal (winning the game), but it acts as a nudge toward diversity.

Datasets

The researchers evaluated CTR across three increasingly difficult environments:

  • Pac-Men: A custom grid-world maze where agents must split up to find "dots" in different rooms.
  • SMAC (StarCraft Multi-Agent Challenge): The gold standard for MARL, featuring complex combat scenarios.
  • SMACv2: An updated version of the StarCraft benchmark that adds stochasticity (randomized unit types and starting positions) to prevent agents from just memorizing fixed sequences.

Key Insights and Ideas

  • The Hypersphere Advantage: By mapping trajectories to a contrastive hypersphere, the model ensures that agents aren't just "different," but that their differences are linearly separable. This makes it much easier for the policy network to learn distinct roles (like a "kiter" vs. a "tank").
  • Avoiding the Overfitting Trap: Because contrastive learning focuses on distinguishing between samples rather than generating them, it is less prone to the "exploration collapse" seen in variational methods.
  • Learnable vs. Fixed IDs: One of the biggest "aha" moments in the paper is that fixed one-hot IDs actually hurt performance. Learnable identities allow the system to find the most efficient way to represent "agent-ness" as the task evolves.

Key Results

The results are impressive, particularly in "Super Hard" scenarios:

Pac-Men environment and visitation heatmaps comparing QMIX and CTR.
  • Diversity in Action: In the Pac-Men environment, visualization showed that while standard QMIX agents all crowded into the same room (competing for the same reward), CTR agents naturally split up to explore all four corners of the map.
  • Win Rates: In the StarCraft 6h_vs_8z scenario, CTR achieved a win rate of nearly 80%, while the baseline QMIX struggled below 25%.
  • Scalability: The method proved robust as the number of agents increased (tested up to 20 agents in SMACv2), maintaining a significant lead over state-of-the-art methods like MAVEN and EOI.

Limitations and Future Work

While CTR is powerful, the authors acknowledge a few hurdles:

  • Centralized Training: The contrastive loss requires comparing all agents' trajectories simultaneously, meaning it currently only works in Centralized Training, Decentralized Execution (CTDE) frameworks.
  • The "Focus Fire" Paradox: In some simple games, you want agents to act identically (e.g., everyone shooting the same target). The authors note that finding the perfect balance between "automatic diversity" and "necessary homogeneity" is a key direction for future research.
  • Sample Size: Contrastive learning thrives on having many "negative samples." In environments with very few agents, the contrastive signal might be weaker.

For researchers looking to push the boundaries of how groups of AI agents coordinate without losing their "individuality," CTR offers a promising, mathematically grounded path forward.

Summary updated

BibTeX
@inproceedings{li2024learning,
  author = {Tianxu Li and Kun Zhu and Juan Li and Yang Zhang},
  title = {{Learning Distinguishable Trajectory Representation with Contrastive Loss}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=D6nlm2AYHi},
}
Figure