Neural Mastery

Advanced RL

RL Fundamentals covered tabular methods — a QQ-value stored explicitly for every state-action pair, which only works for small, discrete state spaces. Everything on this page addresses what happens once state spaces get too large for a table, action spaces become continuous, or the clean "agent interacts live with an environment" assumption itself breaks down.

Tabular RL is like a lookup table you could actually print out — one row per situation, one column per action. That stops working the moment "situation" means "raw pixels from a camera" (infinite possible situations) or "action" means "how hard to press the accelerator" (infinite possible actions, not a short list to pick from). Everything below swaps the lookup table for a neural network that can generalize to situations it's never exactly seen before — and then deals with the new, specific ways that swap breaks things a table never had to worry about.

Intuition: Each Method Fixes One Specific Assumption Break

Every topic below exists because one specific assumption from RL Fundamentals stopped holding, and each fix is narrowly scoped to that one break: SAC and TD3 fix specific statistical failure modes of actor-critic methods once a neural network stands in for the Q-table. Offline RL breaks the "agent can freely explore" assumption. Imitation and inverse RL break the "a reward function is given" assumption. Keep that mapping in mind — it turns this page from a list of algorithm names into "here's the assumption, here's exactly what breaks, here's the fix."

Deep RL: DQN, Policy Gradients, Actor-Critic, PPO

Covered as architectures in Advanced Architectures — Reinforcement Learning Networks: DQN replaces the Q-table with a neural network (necessary once the state space is too large to enumerate — an image-based state space, for instance, has no finite table to fill in), policy gradient methods directly parameterize and optimize the policy for continuous action spaces where "take the argmax" isn't well-defined, actor-critic combines both for better sample efficiency, and PPO constrains policy updates to a trust region for training stability. Revisit that page for the architectural detail — this page assumes it and covers what sits beyond it.

SAC and TD3: Refining Continuous Control

Two widely-used refinements specifically for continuous action spaces (robotics, physical control), addressing specific weaknesses in vanilla actor-critic/policy-gradient methods.

TD3: Fixing Overestimation Bias

Overestimation bias is a specific, well-documented statistical failure: once a neural network approximates QQ, its estimates carry noise — and taking a max\max over noisy estimates is a biased estimator of the true max, even when the noise itself averages to zero, because the max operation systematically favors whichever estimate got lucky. Run the real simulation below — 400 trials, one Monte Carlo run each:

Single critic
critic's estimate
1.306
true value there
0.946
Twin critics (TD3)
critic's estimate
1.100
true value there
0.946
true optimal value (at the real best action): 1.000
The gap isn't a fluke of one bad run -- re-running with a fresh seed keeps producing a real gap for the single critic, because taking a max over noisy estimates is a statistically biased estimator of the max of the true values, regardless of which specific noise was drawn.
400 real Monte Carlo trials: each critic scores 21 candidate actions as trueQ(a) + noise, and the "policy" greedily picks the action with the highest score. Single critic's own estimate at its chosen action averages 1.306 -- but that action's REAL value is only 0.946, a real 0.360 overestimation gap. Twin critics (min of two independent noisy estimates) narrow that gap to 0.154.

TD3 (Twin Delayed DDPG) fixes this with three specific tricks: training two independent value networks and using the more conservative (minimum) of the two as the target (directly counteracting the upward-bias direction, exactly as shown above), delaying policy updates relative to value updates (letting the value estimate stabilize first), and adding noise to the target action (smoothing the value estimate against small errors in the exact action taken).

SAC: Trading Off Return Against Exploration

SAC (Soft Actor-Critic) adds an entropy bonus to the objective — the agent is rewarded not just for expected return, but for maintaining some randomness in its policy: J=E[Q]+αH(π)J = \mathbb{E}[Q] + \alpha H(\pi). This explicitly trades off exploration against exploitation within the objective itself, rather than requiring a separately-tuned exploration schedule. Drag α\alpha and watch which of two real policies — one peaked and greedy, one spread and exploratory — the objective actually prefers:

Peaked policy (near-greedy)
E[Q]=0.947, H=0.627, J=1.041
Spread policy (more exploratory)
E[Q]=0.735, H=1.584, J=0.973
Both E[Q] (dot product of the real probabilities above with each action's real Q-value) and H (real Shannon entropy, −Σp·log p) are computed live from the bars, not hand-picked to match the story.
J = E[Q] + α·H(π). At α=0.15: J(peaked) = 0.947 + 0.15×0.627 = 1.041; J(spread) = 0.735 + 0.15×1.584 = 0.973. SAC's objective currently prefers policy A. Real crossover at α* = 0.222 -- push the slider past it and the winner flips.

This tends to produce more robust policies that don't collapse prematurely onto a single, possibly-suboptimal deterministic behavior — exactly the failure mode a purely greedy objective (α=0) is prone to.

Offline RL

Standard RL assumes the agent can freely interact with the environment, collecting new experience as it learns. Offline RL removes that assumption entirely — the agent learns from a fixed, pre-collected dataset of past experience, with no ability to try new actions and see what happens. This matters enormously wherever live experimentation is expensive, slow, or unsafe — a physical robot, a medical treatment policy, a recommender system where "trying a bad action" means showing a real user a bad recommendation.

The core added difficulty beyond standard RL: without the ability to explore, the algorithm has no way to correct a value-function error for actions poorly represented in the fixed dataset. Watch a real regression fit exploit exactly that gap:

never visited by the dataset
offline dataset (what the model actually saw) true value naive fitted value
A real degree-4 least-squares fit to only the 6 visible dots (no data in the middle gap) claims action a=0.02 is worth 1.00 -- its real value is only 1.00. The naive offline policy would confidently pick an action it has essentially no evidence for.

Naively extrapolating can produce a policy that looks good on paper (high estimated value) but fails badly in practice specifically because it exploits the value function's errors on data it never saw — a distribution-shift problem closely related to training-serving skew in the classical ML sense, just for RL's action distribution instead of a feature distribution.

Imitation Learning

Instead of learning from a reward signal at all, learn a policy directly from demonstrations of the desired behavior — a human (or existing expert policy) performing the task, with the agent trained (often via straightforward supervised learning) to reproduce the demonstrated actions given the observed states. The most direct form, behavioral cloning, is simple but has a well-known compounding-error problem: small mistakes push the agent into states slightly outside the demonstrated distribution, where it's never been trained and makes further mistakes. Same-sized per-step errors, fed two different ways:

expert trajectory (0 deviation)
behavioral cloning (compounding) with expert correction (bounded)
Same per-step prediction error (a real random draw each step, std ≈0.12) fed two different ways: behavioral cloning (red) feeds its own drifted state back into itself, so error accumulates -- a real running sum, ending 0.79 away from the expert after 30 steps. An expert-corrected variant (green, e.g. DAgger-style) resets from the true state each step, so the same-sized errors never accumulate -- ends within 0.20.

Behavioral cloning's error accumulates because the agent's own (already-drifted) state feeds into its next decision — a real feedback loop, not a metaphor, and exactly what the red trace above is doing: a genuine running sum of per-step error. Techniques that actively query the expert during training (rather than training purely offline on a fixed demonstration set) break that feedback loop by periodically resetting to the true state, exactly like the bounded green trace.

Inverse RL

The reverse problem from imitation learning's direct behavior-cloning: instead of directly copying demonstrated actions, infer the reward function that would explain why an expert behaved the way they did, then solve the resulting RL problem to derive a policy. This is more information-rich than plain imitation learning when it works — a recovered reward function can generalize to states/situations the original demonstrations never covered, where a directly-cloned policy has no principled way to generalize — at the cost of being a fundamentally harder, underdetermined problem (many different reward functions can rationalize the same observed behavior equally well).

RLHF, RLAIF, and GRPO in the RL Framework

Training Pipeline — RLHF and GRPO are genuine instances of this page's framework. Click through the mapping below to see exactly how each piece of RL vocabulary lands on the LLM side:

Policy π
The LLM itself
State s
Prompt + tokens generated so far
Action a
The next token (or a full response)
Reward R(s,a)
Reward model score (RLHF) or AI judge score (RLAIF)
Environment
The reward model / judge + the KL penalty toward the reference model
Policy-gradient algorithm
PPO or GRPO
Once every row here reads as "just RL," the KL-divergence penalty, reward hacking, and GRPO's critic-free design all stop being LLM-specific magic and become specific engineering responses to specific, generic RL problems.
The thing being optimized -- in standard RL a mapping states→actions, here the model's own next-token distribution.

Seeing RLHF as "just RL, with a learned reward model standing in for the environment's reward function" is what makes the KL-divergence penalty, the reward-hacking failure mode (see Alignment & RLHF), and GRPO's critic-free design all make sense as specific engineering responses to specific, generic RL problems, not LLM-specific magic.

Code: TD3's Twin-Critic Target, For Real

import torch

# TD3's core fix -- take the MIN of two critics as the target, exactly
# what closed the overestimation gap in the diagram above.
def td3_target(critic1, critic2, target_actor, reward, next_state, gamma, noise_std=0.2):
    next_action = target_actor(next_state)
    next_action += torch.clamp(torch.randn_like(next_action) * noise_std, -0.5, 0.5)  # target policy smoothing
    q1 = critic1(next_state, next_action)
    q2 = critic2(next_state, next_action)
    target_q = reward + gamma * torch.min(q1, q2)  # the twin-critic min, not a single critic's estimate
    return target_q

Next: Multi-Armed & Contextual Bandits — the degenerate, single-state special case of everything above, and the actual production answer to the explore/exploit problem this site's recommendation-system material has been gesturing at.

Last updated Sep 5, 2026Edit this pageReport an issue
← Previous
RL Fundamentals
Next →
Multi-Armed & Contextual Bandits