ai theory
Reinforcement Learning Basics (17) — Can an Agent Learn from Already Collected Data Alone?
Junyoung Park · 2024-07-05 · 6 min
Introduction
Until now, our agents could keep interacting with the environment to generate new experience. They could retry after a failure and explore actions they did not understand.
That assumption is often unrealistic.
- We cannot try a dangerous medical treatment merely for training.
- A robot will break if we make it fall millions of times.
- We may have only recorded user logs and no way to run a new experiment.
This creates the problem of learning a policy from a fixed dataset
alone.
This article compares imitation learning, which copies an expert's actions, with offline RL, which also uses rewards in a fixed dataset to search for a better policy.
Behavior Cloning: Treat the Action as a Label
Suppose a demonstration dataset contains pairs of states and expert actions.
Behavior Cloning treats this as supervised classification or regression. For discrete actions, it can minimize the negative log-likelihood
The equation increases the probability of the action selected by the expert in the dataset. Its advantage is that neither rewards nor next states are required.
A Small Mistake Creates a New State
A policy can fail during execution even when its supervised validation accuracy is high.
The expert dataset is concentrated on states visited by the expert. A small action error moves the learned policy slightly away from the expert path. The new state barely appears in the dataset, so the next action error becomes larger, pushing the trajectory farther away.
This is covariate shift. During training,
but during execution,
The distribution of input states has changed.
DAgger Also Asks About States Visited by the Policy
DAgger reduces this distribution gap.
- Run the current policy in the environment.
- Collect the states it actually visits.
- Ask the expert for the correct action in those states.
- Add the new labels to the dataset and train again.
The dataset now contains expert examples for states reached after a mistake. DAgger, however, requires access to the environment during training and the ability to query the expert again. It cannot be used in a completely fixed offline setting.
What Makes Offline RL Different?
An offline RL dataset includes rewards and next states.
Behavior Cloning asks only which action appears in the data. Offline RL uses the reward and future following that action and attempts to improve upon the behavior policy that generated the dataset.
For example, action A may appear frequently near a state but produce a low reward, while action B appears rarely but produces a high reward. Offline RL can increase the weight of B.
That possibility is attractive, but it also creates the central difficulty: we cannot observe the outcome of actions absent from the dataset.
The Q-Value of an Unseen Action
In online Q-Learning, an agent can execute an action with a high Q-value and test the prediction. If it is wrong, a new transition corrects the Q-value.
Offline RL cannot execute an action outside the dataset. If function approximation accidentally gives that action a high Q-value, no contradictory data arrives.
If the selects an that appears rarely in the dataset, an unsupported Q-value enters the bootstrap target. Training Q on that target can amplify the error. This is called extrapolation error, or the out-of-distribution action problem.
Staying Close to the Dataset
Offline RL methods generally prevent the policy or value function from moving too far outside the dataset's support.
Policy Constraints
Restrict the learned policy from becoming too different from the behavior policy.
is the behavior policy that generated the dataset.
Conservative Values
Penalize Q-values for actions absent from the dataset: if there is no evidence, do not assume the action is good.
Advantage-Weighted Imitation
Rather than copy every data action equally, imitate actions with high advantages more strongly.
is larger for better actions.
Dataset Quality Determines the Algorithm's Limits
Offline RL cannot magically evaluate behavior entirely absent from the dataset.
When examining a dataset, ask:
- Coverage: does it contain the important states and actions?
- Quality: does it include both successes and failures, or is it skewed toward one side?
- Reward: does the recorded reward represent the real objective?
- Behavior policy: who generated the data, and under what rule?
- Confounding: did an unrecorded variable affect both the action and its outcome?
When only good trajectories are available, Behavior Cloning can be a strong baseline. When the data contains diverse successes and failures and the rewards are reliable, offline RL can make better use of the relative value of actions.
Comparing the Four Settings
| Setting | New environment interaction | Uses reward | Central risk |
|---|---|---|---|
| Behavior Cloning | Not required | Not required | Covariate shift; copying expert errors |
| DAgger | Required | Optional | Cost of expert queries |
| Offline RL | None | Yes | Value errors for actions outside the dataset |
| Online RL | Continuous | Yes | Exploration cost and safety |
The question “Can we generate new data during training?” often reveals the nature of the problem more clearly than the terminology does.
What to Remember
Imitation learning learns to follow actions in a dataset. Offline RL uses rewards and transitions in a fixed dataset to search for better behavior, while guarding against optimistic estimates outside that dataset.
- Behavior Cloning is supervised learning that minimizes .
- Small execution errors can lead to states outside the training distribution and accumulate.
- DAgger adds expert labels for states visited by the current policy.
- Offline RL uses rewards, but cannot collect new experience to verify Q-values for OOD actions.
- Dataset coverage and quality strongly limit the policies that can be learned.
The next article turns offline trajectories into token sequences of returns, states, and actions, allowing a Transformer to predict actions as a Decision Transformer.