Choosing an RL Algorithm
Start with the decision problem and the data you can collect. Use action space, online interaction, replay, safety, and compute to narrow the algorithm family before tuning it.
Jump to a section
Why this matters
There is no generally best reinforcement-learning algorithm. First ask what decisions the agent makes, how experience is obtained, and what failure costs. A method that looks strong on a cheap simulator may be unsuitable when each real action is expensive or unsafe.
Choose a family before tuning a library: small discrete problem and known state, high-dimensional observations, continuous control, fixed logged data, or a useful dynamics model. Then compare candidates under the same environment, observation and reward definitions, interaction budget, compute budget, and evaluation protocol.
Build the mental model
Use this table as a shortlist, not an automatic winner. The right branch depends on data quality and engineering constraints.
| Situation | Candidate starting point | Main cost or failure mode |
|---|---|---|
| Small, discrete state and action spaces | Tabular Q-learning or SARSA | Tables scale poorly; exploration still matters |
| Large observations, discrete actions, online interaction | DQN-style value learning | Replay and bootstrapped value error need care |
| Online policy learning with discrete or continuous actions | PPO | Fresh rollouts can be expensive in environment steps |
| Continuous control with costly online interactions | SAC | Reused data helps, but critic bias and tuning still matter |
| Fixed logged dataset, no safe interaction | Offline RL such as CQL, plus behavioral baseline | Out-of-distribution actions can receive unreliable values |
| Learnable dynamics and costly interaction | Model-based methods | Model error can compound over imagined rollouts |
Safety is a constraint on the experiment, not a property inferred from an algorithm name. If a bad exploratory action is unacceptable, define a safe simulator, action shield, constrained policy, or offline evaluation plan before running online RL. A reward score alone does not establish safety.
Match the learning signal to the task
Action space, data availability, and interaction cost constrain the choice of learning method.
Exact inputs and equations appear with the figure.
Preparing the scientific figure…
A comparison map, not an automatic recommendation or a universal ranking of RL algorithms.
Authored analytic exampleWork through the math
Start with the discounted return . Value-based methods estimate expected return for an action; policy-gradient methods adjust action probabilities to improve expected return. An off-policy method can train from data generated by another behavior policy; an on-policy method such as PPO uses fresh samples from a recent policy for its update.
For Q-learning, a one-step target is for a nonterminal transition. For PPO, the update uses an advantage-weighted likelihood ratio clipped in its surrogate objective. SAC uses replay with an entropy-regularized actor-critic objective, often improving interaction efficiency on the continuous-control tasks it was designed for. These are different optimization signals; they do not form an accuracy ranking.
Offline data add a coverage problem. A learned policy may choose actions absent from the log, while bootstrapped value estimates can assign those actions undeserved high value. CQL addresses this by learning conservative values, but its assumptions and evaluation still matter. Model-based methods trade more computation for simulated experience and must control model bias.
Two budgets must stay separate: environment steps measure interaction cost; wall-clock time includes simulation, model training, data transfer, and evaluation. Compare performance against both axes, across seeds, with the same termination and truncation semantics.
Read the implementation
Write the experiment contract before running candidates. This standard-library sketch records the metrics that let a reviewer compare runs; the values come from actual run logs, never from the shortlist table.
1from statistics import median
2
3
4def summarize_run(env_steps, eval_returns, safety_violations, wall_seconds):
5 assert env_steps > 0 and wall_seconds > 0
6 assert eval_returns, "evaluate complete episodes"
7 assert safety_violations >= 0
8 return {
9 "env_steps": env_steps,
10 "median_eval_return": median(eval_returns),
11 "eval_episodes": len(eval_returns),
12 "safety_violations": safety_violations,
13 "wall_seconds": wall_seconds,
14 }For each candidate, fix action and observation spaces, reward and constraint definitions, evaluation episodes, random seeds, and stop budget. Log behavior-policy coverage for offline data. Inspect learning curves, uncertainty across runs, and the worst safety outcomes. A single best seed or one final score is not enough to select a deployable policy.
Questions and trade-offs
- Data: Why can PPO be a poor fit for expensive real-world interaction? (It needs fresh rollouts for updates; wall-clock throughput cannot create free environment data.)
- Actions: Why test DQN for discrete actions and SAC for continuous control? (Those are the settings each method was designed around; adaptation is possible but needs a reason.)
- Offline: Why not simply train standard Q-learning on a fixed log? (Bootstrapping may overvalue actions the dataset rarely or never contains.)
- Safety: Does a high average return show that exploration was safe? (No. Measure violations and tail failures during both training and evaluation.)
- Systems: What must be held fixed in a fair algorithm comparison? (Environment and reward definitions, interaction and compute budgets, seeds, eval protocol, and termination semantics.)
Check your understanding
Choose candidate families for three cases: a tiny gridworld, online continuous control with expensive samples, and a fixed robot-operation log where new actions cannot be tried. For each, state one plausible method, one reason it fits, one serious failure mode, and the evidence you would require before use. Compare environment steps separately from wall-clock time.
Sources and further reading
- Mnih et al., Human-level Control through Deep Reinforcement Learning (2015): DQN on high-dimensional observations and discrete game actions.
- Schulman et al., Proximal Policy Optimization Algorithms (2017): on-policy clipped surrogate.
- Haarnoja et al., Soft Actor-Critic (2018): off-policy continuous-control actor-critic method.
- Kumar et al., Conservative Q-Learning for Offline Reinforcement Learning (2020): fixed-data distribution-shift problem and conservative values.
- Janner et al., When to Trust Your Model (2019): model-generated experience versus model bias.
Oliver Perrin
Machine Learning Engineer · Founder, LiminalML
LiminalML brings together concept explanations, mathematical examples, and working visuals. Find more writing by Oliver on the LiminalML Substack.
Keep exploring the idea.
Ask a follow-up in a guided session, work through the self-check, or open the visual in Studio to build on it.
Related concepts
Reinforcement Learning
PufferLib and PPO Engineering
Understand what PPO optimizes and what PufferLib changes in the surrounding training system. Keep throughput claims tied to a version, workload, and measurement.
Deep Learning
Recurrent Neural Networks (RNNs, LSTMs, GRUs)
Trace state through time and compare a plain RNN with gated LSTM and GRU cells. Learn what gating helps, what it does not guarantee, and when recurrence is useful.
Optimization
Gradient Descent (SGD, Momentum, Adam)
Follow updates across a loss surface, then connect learning rate, momentum, and Adam to the update equations.