Reinforcement Learning: Theory Notes
last updated
Reinforcement Learning
Rather than explicitly modelling the dynamics of the robot and its environment, reinforcement learning (RL) allows an autonomous system (agent) to learn a control strategy (policy) through interaction with its environment.
At each timestep, the agent observes the current state of the environment, chooses an action according to its policy, and receives a reward indicating how useful that action was.
The agent observes state sₜ and sends action aₜ to the environment.
This interaction is typically modelled through a Markov Decision Process (MDP). More formally, a length- MDP is a tuple:
where:
- is the state space. A state describes the state of the robot and environment at timestep . For a robot, this might include joint positions, joint velocities, and camera observations.
- is the action space. An action is a command sent to the robot, such as a joint velocity, torque, or target joint position.
- represents the environment dynamics: how the current state and action lead to the next state.
- is the reward function, which assigns a scalar reward to a transition.
- is the discount factor, which determines how much the agent values future rewards compared to immediate rewards.
- describes the distribution of possible starting states.
- is the number of timesteps in the trajectory.
As the agent interacts with the environment over time, it generates a trajectory:
A natural question is: what is the probability that a particular trajectory occurs? In general, the probability of what happens next could depend on the entire history of everything that has happened before it. For example, the probability of reaching might depend on
and the action chosen by the agent could similarly depend on its entire history:
The Markov assumption simplifies this by assuming that the current state contains all the information we need about the past. Therefore, the next state only depends on the current state and action:
and the agent's action only depends on the current state:
This lets us factor the probability of an entire trajectory into a much simpler expression:
We already defined the initial-state distribution as , the environment dynamics as , and the agent's policy as , so we can rewrite this as:
We often write the policy as because it is parameterized by learnable parameters , which are optimized to maximize the return associated with the trajectories the policy produces.
To evaluate how good a trajectory is, we define its return as the sum of the rewards collected over the trajectory:
The discount factor determines how strongly we value rewards further into the future.
However, a policy can produce many different trajectories, so rather than optimizing the return of one individual trajectory, we care about the expected return across trajectories generated by the policy:
The goal of reinforcement learning is therefore to find the policy parameters that maximize this expected return.
Unlike classical model-based approaches, reinforcement learning does not require us to explicitly derive the dynamics of the robot and its environment. Instead, the policy can learn directly from interaction data, allowing it to handle dynamics that are difficult to model and potentially learn directly from high-dimensional sensor observations such as images.
Learning-based approaches also provide a way to improve performance as more data becomes available, rather than requiring us to manually redesign a controller for every new condition or task.
Despite these advantages, reinforcement learning introduces its own limitations. Learning through interaction can require large amounts of experience, and collecting that experience on a physical robot can be slow, expensive, and potentially unsafe. Simulation makes it possible to generate experience much more easily, but introduces a gap between simulated and real-world physics. RL also depends heavily on the reward signal: poorly specified or sparse rewards can make learning difficult or lead to unintended behaviours.
Soft Actor-Critic (SAC)
Now we know in RL, we need a way to learn the parameters for the policy. For my experiment, I used Soft Actor-Critic (SAC), which is an off-policy actor-critic RL algorithm designed for continuous action spaces.[1]
SAC is good for robotics because it handles continuous control well, reuses data efficiently through replay buffers, and integrates nicely with demonstration- and intervention-based training.
The stochastic actor samples an action and applies it to the environment.
SAC learns two main components: an actor and a critic. The actor is just our policy:
Given the current state , it determines which action the robot should take.
The critic learns a "Q-function":
Which estimates how much future reward we can expect if we take action in state and continue following our policy afterward.
Every time the robot interacts with the environment it generates transitions:
And these are stored in the "replay buffer".
SAC repeatedly samples transitions from the replay buffer to train the critic. So for a transition , the basic idea is that the value of taking the current action should be equal to the reward we receive now plus the expected value of what happens afterward:
Once the critic can estimate which actions are valuable, the actor can then be trained to produce actions that receive higher Q-values.
So together, the critic learns which actions are good, while the actor learns to choose those actions.
One of the key characteristics of SAC is that the actor does not output one deterministic action, it is stochastic. This is typically represented using a Gaussian distribution:
This allows the policy to explore different actions instead of immediately committing to the first behaviour that appears to work. SAC explicitly encourages this exploration by modifying the reward objective with an entropy term:
The term controls how strongly exploration is encouraged. A larger encourages a more stochastic policy, while a smaller focuses more strongly on maximizing reward.[1]
HIL-SERL
We can extend SAC into Human-in-the-Loop Sample-Efficient Reinforcement Learning (HIL-SERL). Instead of forcing the robot to discover the task entirely through random exploration, HIL-SERL begins by collecting a small number of successful human demonstrations.[2] These demonstrations generate the same transitions we saw before:
but now, the action can be influenced by a human! The human-in-the-loop part comes in when the policy begins to fail. A human supervisor can temporarily take control of the robot, perform a corrective action, and then return control back to the policy.[2]
So the data used by SAC now comes from three sources: