Inferensys

Glossary

Trajectory

In reinforcement learning, a trajectory is a sequence of states, actions, and rewards experienced by an agent from an initial state to a terminal state, representing one complete trial of interaction.
Developer reviewing multi-agent chat interface on laptop, agent conversation logs visible, casual coding session at WeWork desk.
REINFORCEMENT LEARNING FOR ROBOTICS

What is a Trajectory?

In reinforcement learning, a trajectory is the complete record of an agent's interaction with its environment during a single trial, from start to finish.

A trajectory, also known as an episode or a rollout, is a sequence of states, actions, and rewards ((\mathbf{s}_0, \mathbf{a}_0, r_1, \mathbf{s}_1, \mathbf{a}_1, r_2, ...)) experienced by an agent from an initial state to a terminal state. It represents one complete trial of interaction, capturing the agent's entire decision-making history and the environment's responses. This sequence is the fundamental unit of data used for training in model-free RL algorithms, where the policy is improved by analyzing the outcomes of past trajectories.

For sim-to-real transfer learning, trajectories generated in high-fidelity physics simulations are critical. They provide a low-cost, parallelizable source of training data for learning complex robotic skills. The quality and diversity of these simulated trajectories directly influence policy robustness. Techniques like domain randomization explicitly vary simulation parameters across trajectories to ensure the learned policy generalizes to the physical world's unpredictable dynamics, enabling successful zero-shot transfer.

REINFORCEMENT LEARNING FOR ROBOTICS

Key Components of a Trajectory

A trajectory, or episode, is the fundamental unit of experience in reinforcement learning. It represents one complete trial of an agent's interaction with its environment, from an initial state to a terminal state. Understanding its constituent parts is essential for analyzing learning algorithms and designing effective training regimes.

01

State Sequence

The state sequence is the ordered list of observations the agent receives from the environment. In robotics, a state can be high-dimensional, including:

  • Proprioceptive data: Joint angles, velocities, and motor torques.
  • Exteroceptive data: Camera images, LiDAR point clouds, or depth sensor readings.
  • Task-specific variables: The position of a target object or the remaining time in an episode. The sequence (s₀, s₁, ..., s_T) captures the environment's evolution, forming the primary observational input for the agent's policy and value functions.
02

Action Sequence

The action sequence comprises the decisions made by the agent's policy at each timestep. For robotic control, actions are typically continuous vectors specifying:

  • Joint position or torque targets for a manipulator arm.
  • Velocity commands for a mobile robot base.
  • Gripper open/close signals. The sequence (a₀, a₁, ..., a_{T-1}) represents the agent's direct influence on the environment. The policy's role is to map from the current state s_t to an action a_t that maximizes cumulative reward.
03

Reward Signal

The reward signal r_t is a scalar feedback provided by the environment after each action. It quantifies the desirability of the transition from state s_t to s_{t+1} after taking action a_t. In robotics, rewards are carefully engineered to guide learning:

  • Sparse rewards: A large positive reward only upon task completion (e.g., +1000 for inserting a peg).
  • Dense rewards: Shaped feedback at every step (e.g., -distance to goal, -effort penalty).
  • Composite rewards: A weighted sum of multiple objectives (e.g., α * (progress) - β * (energy_used)). The trajectory's total return, G_t = Σ γ^k * r_{t+k}, is the ultimate objective the agent seeks to maximize.
04

Terminal Condition

The terminal condition defines when a trajectory ends. It is a crucial component for structuring the learning problem and defining an episode's horizon. Common terminal conditions in robotic RL include:

  • Task Success: The goal is achieved (e.g., object grasped, door opened).
  • Task Failure: An irreversible error occurs (e.g., robot falls over, object dropped).
  • Timeout: A maximum episode length T_max is reached.
  • Constraint Violation: A safety limit is breached (e.g., joint torque exceeds a threshold). Terminal states are often absorbing, meaning no further actions or rewards occur. Distinguishing between terminal states due to success or failure is vital for credit assignment.
05

Transition Tuples

A trajectory is fundamentally decomposed into a sequence of transition tuples (s_t, a_t, r_t, s_{t+1}, done_t). This atomic unit of experience is the core data structure for most RL algorithms.

  • s_t, a_t, r_t, s_{t+1}: Used in Temporal Difference (TD) learning and Q-Learning to update value functions via the Bellman equation.
  • done_t: A boolean flag indicating if s_{t+1} is terminal. These tuples are stored in a replay buffer for off-policy algorithms like DDPG and SAC, enabling sample-efficient learning by breaking temporal correlations through random minibatch sampling from past experiences.
06

Return and Discounting

The return G_t is the total discounted future reward from timestep t onward: G_t = r_t + γr_{t+1} + γ²r_{t+2} + ... + γ^{T-t-1}r_{T-1}.

  • Discount factor (γ): A value between 0 and 1 that determines the present value of future rewards. A γ near 1 makes the agent far-sighted, while a γ near 0 makes it short-sighted.
  • Undiscounted return: Used in episodic tasks with a natural horizon (γ=1). The value function V(s) or Q(s,a) is an estimate of the expected return, and the entire trajectory is used to compute or refine these estimates, either through Monte Carlo methods (using the full return) or TD methods (using bootstrapped estimates).
FOUNDATIONAL CONCEPT

The Role of Trajectories in RL Training

In reinforcement learning, a trajectory is the fundamental unit of experience used for training. It encapsulates a complete trial of an agent's interaction with its environment.

A trajectory (also called an episode or rollout) is a sequence of states, actions, and rewards ((s_0, a_0, r_1, s_1, a_1, r_2, ...)) experienced by an agent from an initial state to a terminal state. It represents one complete attempt at a task, such as a robot completing a grasp or a game reaching its conclusion. Trajectories are the raw data from which value functions and policy gradients are estimated, making them the primary input for most RL algorithms.

During training, algorithms like Policy Gradient and Actor-Critic methods sample trajectories—often stored in a replay buffer—to compute updates. The sequential nature of a trajectory is crucial for calculating discounted returns and understanding long-term consequences via the Bellman equation. In sim-to-real transfer, generating vast quantities of diverse trajectories in simulation is essential for learning robust policies that can generalize to physical hardware with minimal online fine-tuning.

COMPARATIVE ANALYSIS

Types and Characteristics of Trajectories

A comparison of trajectory types based on their defining characteristics, data structure, and typical use cases in reinforcement learning for robotics.

CharacteristicDeterministic TrajectoryStochastic TrajectoryOptimal TrajectoryExpert Demonstration Trajectory

Definition

A fixed sequence of states and actions produced by a deterministic policy.

A probable sequence generated by a stochastic policy, representing a distribution over possible paths.

A trajectory that maximizes the expected cumulative reward for a given task and reward function.

A trajectory generated by a human or algorithmic expert, used as ground truth for imitation learning.

Policy Type Source

Deterministic Policy

Stochastic Policy

Optimal Policy

Expert Policy (often unknown)

Primary Use Case

Deployment, reproducibility testing, and deterministic control.

Exploration, capturing environmental uncertainty, and policy gradient training.

Benchmarking, reward shaping analysis, and optimal control reference.

Behavioral cloning, dataset creation for inverse reinforcement learning.

Data Variability

Contains Reward Signal

Varies (often yes)

Key RL Algorithm Association

DDPG, TD3

PPO, SAC, Vanilla Policy Gradient

Value Iteration, Q-Learning (theoretically)

Behavioral Cloning, DAGGER

Critical for Sim-to-Real Transfer

High (for reproducible deployment)

High (for learning robust policies via domain randomization)

High (as a performance target)

Medium (for bootstrapping or reward learning)

Storage in Replay Buffer

TRAJECTORY

Frequently Asked Questions

A trajectory, or episode, is the fundamental unit of experience in reinforcement learning, representing a complete sequence of interactions between an agent and its environment. These FAQs address its role in training, analysis, and the sim-to-real transfer process.

A trajectory (also called an episode or rollout) is a complete sequence of states, actions, and rewards experienced by an agent from an initial state to a terminal state, representing one full trial of interaction with an environment. Formally, a trajectory τ is denoted as τ = (s₀, a₀, r₁, s₁, a₁, r₂, ..., s_T), where s is state, a is action, and r is reward. It is the atomic data structure for model-free learning algorithms, which use collections of trajectories to estimate value functions or compute policy gradients. In sim-to-real transfer learning, trajectories generated in high-fidelity physics simulations are the primary training data used to develop robust policies before any real-world deployment.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.