Batch Constrained Q-Learning (BCQ)
Instead of letting an agent dream up risky actions no human ever demonstrated, BCQ confines its choices to tracks already in the dataset, tuning them only with a short mathematical leash.
Why Does This Exist?
Offline reinforcement learning learns from a fixed log with no fresh environment interaction. That is the only option when interaction is slow, costly, or unsafe, and it is exactly where standard off policy methods break. The background on the setting is in offline batch reinforcement learning and the failure pattern is named in distributional shift in offline RL.
The break has a name: extrapolation error. A Bellman backup queries , and in continuous control the actor actively hunts for the action with the largest predicted value. For actions far from the logged data, the critic has seen no ground truth, so its output is an accident of function approximation. The actor latches onto the tallest hallucination, the backup bakes that fantasy into earlier states, and the deployed policy drives off the data manifold. Online learning would correct this by visiting the suspect action and observing the truth. Offline learning cannot.
Batch Constrained Q-Learning (Fujimoto, Meger, and Precup, 2019) was the first deep method built to stop this loop. It never asks the critic about arbitrary actions. It samples candidate actions from a generative model of the logged behavior, allows only tiny bounded adjustments, and scores candidates pessimistically. A later, more explicitly pessimistic alternative is conservative Q-learning.
Think of It Like This
Ski tracks after fresh snow
Fresh snow covers a mountainside and you must ski down without hitting rocks. Earlier skiers left visible tracks. You do not know why each turn was chosen, but every track is proof that path was survivable.
Standard off policy RL ignores the tracks and heads for the line its map says is fastest, straight over an unmarked cliff. BCQ skis inside the existing tracks, shifting a few centimeters left or right to find smoother snow, and asks two guides for the safer read on each option before committing.
Where the analogy stops: ski tracks are visible lines on a hill. A behavior distribution over continuous actions is a high dimensional density that must be learned, and the safe sideways shift needs a number, which is the perturbation bound below.
How It Actually Works
BCQ has three coupled parts. is a conditional variational autoencoder modeling logged actions . is a perturbation network capped by . and are twin critics. Here is the next state, are sampled candidates, are perturbed candidates, is the reward, and is the discount factor.
Candidate generation from the behavior model
The C-VAE trains on logged pairs with an encoder and decoder . At decision time BCQ draws latent codes from a standard Gaussian and decodes . Because the decoder only ever learned logged behavior, these candidates sit on the data manifold by construction. Sampling more candidates (commonly to ) covers multimodal behavior better at the cost of more critic evaluations.
Bounded perturbation
Pure sampling would only clone the logger. BCQ adds with , so no tweak exceeds in each action dimension. A typical setting is times the action range. The perturbation network trains to maximize , which is local hill climbing on a short leash: enough to beat a mediocre logger, too short to wander into unsupported regions.
Pessimistic twin critic target
Each perturbed candidate is scored with , the lower of the two critic reads. The policy picks the argmax of that minimum, and the Bellman target mixes min and max with weight in :
With the target is the pure minimum, the most conservative choice.
Worked example
Logged actions near state concentrate in . Fix , , , , and .
- The C-VAE samples , , . All three sit inside the logged band.
- Perturbations: , , , all within . Perturbed actions are , , .
- Twin critic reads: for giving minimum ; for giving minimum ; for giving minimum .
- The policy picks with value .
- The target is .
An unconstrained actor would instead query an unseen action such as , where one critic hallucinates and the target inflates to . BCQ never samples , so the hallucination never enters the update. The diagram draws the three valid candidates, the rejected , and the winning target .
Code
The snippet replays the same selection and target so you can verify the arithmetic.
def conservative_value(q1: float, q2: float, lam: float = 1.0) -> float: """BCQ critic mix: lam * min + (1 - lam) * max.""" return lam * min(q1, q2) + (1.0 - lam) * max(q1, q2)
if __name__ == "__main__": raw = [0.90, 1.05, 1.15] deltas = [0.02, -0.01, 0.03] perturbed = [round(a + d, 4) for a, d in zip(raw, deltas)] reads = [(3.80, 4.00), (4.50, 4.30), (4.10, 4.20)] scored = [conservative_value(q1, q2) for q1, q2 in reads] best = max(range(3), key=lambda i: scored[i]) target = 1.5 + 0.95 * scored[best] print(perturbed) print(scored) print(perturbed[best], round(scored[best], 2), round(target, 4))# -> expected output:[0.92, 1.04, 1.18][3.8, 4.3, 4.1]1.04 4.3 5.585Watch Out For
Setting the perturbation leash too long or to zero
The symptom tells you which side you are on. With too large, training reports climbing values while real evaluation collapses, because the actor has slipped back into unsupported actions. With , performance freezes at the logger's average score, because pure sampling can only clone and never improve.
The fix: scale to the action range, starting near of it, and watch a held out batch Bellman error alongside training error. If held out error rises while training error falls, shorten the leash or raise before touching anything else.
Trusting a single critic on logged but rare actions
The symptom: even inside the data support, rarely seen state action pairs get noisy reads, and the max over candidates keeps picking the noisiest one. Values creep upward for reasons that have nothing to do with better behavior.
The fix: keep both critics and the minimum. If values still drift, raise toward rather than adding network capacity, and check that the C-VAE actually reconstructs rare actions instead of collapsing onto the majority mode.
The Quick Version
- BCQ is an offline method that restricts every critic query to actions sampled from a generative model of the logged behavior.
- A conditional VAE supplies in support candidates, so out of distribution hallucinations are never sampled.
- A perturbation network adds tweaks capped at , giving local improvement without leaving the data manifold.
- Twin critics score candidates with the minimum, and the policy takes the argmax of that pessimistic read.
- In the worked example, candidates 0.90, 1.05, and 1.15 become 0.92, 1.04, and 1.18, and the winner 1.04 gives target 5.585.