Implicit Q-Learning
Learn strong values from logged data only. You fit the top of what you saw with expectile regression and clone the good moves with weights.
Why Does This Exist?
Offline RL has one trap. Your data came from some old behavior policy, but your Bellman update wants to ask what would happen for a new action nobody tried. Neural nets answer with confident nonsense, and the policy chases that hallucination. That gap is distributional shift.
Earlier fixes wrestle the unseen actions directly. Batch constrained Q-learning learns a model of allowed actions. Conservative Q-learning pushes unseen values down. Both need extra sampling and tuning. Start with offline batch RL for the setup, then see this page as the in sample alternative.
This page teaches the method from Kostrikov and coauthors that never asks about unseen actions at all. You learn a value upper envelope from logged pairs only, back it into Q with plain regression, and extract the policy by weighted cloning.
The one idea you need first
A Bellman target for is . Here is the logged reward, is the discount, is the value of the next state. No max over actions appears, so you never need to invent an action at .
Think of It Like This
Picking the best logged bus route
Your city keeps logs of bus trips, with travel times for routes drivers actually drove. You cannot run test buses. You want the fastest reliable route per intersection.
You do not draw a straight line through a park and claim 30 seconds. You look only at logged roads. At each crossing you take a high percentile of logged times, say the 70th percentile good trip, not the average. Then you tell new drivers to copy the trips that beat that bar and ignore the slow ones.
Where the analogy stops: streets have hard curbs, so allowed versus forbidden is crisp. In control, allowed is a soft data cloud, so the percentile becomes a smooth expectile loss instead of a hard filter.
How It Actually Works
Three steps run together, all on dataset pairs from . Symbols: is the state value net, is the action value net, is the expectile level, is the policy temperature.
First, fit with asymmetric squared loss:
with when and otherwise. When you get the mean. When or you pull toward the good logged actions. As nears 1, nears the best logged value.
Next, fit with the state value as target:
The target touches only the observed next state . No candidate action at is scored.
Finally, extract the policy with advantage :
Good moves get copied hard, bad moves get near zero weight. No backprop through Q is needed.
Worked example
One state has two logged actions. Target Q values are and . Current . Set , , .
Expectile gaps are and :
The upside error costs 2.33 times the downside, so drifts up toward 6.0.
Take transition with :
No action was invented at .
Advantages are and . Weights:
Ratio . The actor copies about four hundred times harder than , which is the filtering the diagram shows.
Code
This snippet mirrors the worked numbers with no dependencies.
"""Mirror the IQL worked numbers from the page."""
import math
tau = 0.7beta = 3.0gamma = 0.9
u_good = 6.0 - 5.0u_bad = 4.0 - 5.0loss_good = (tau if u_good >= 0 else 1 - tau) * u_good**2loss_bad = (tau if u_bad >= 0 else 1 - tau) * u_bad**2print(round(loss_good, 4), round(loss_bad, 4))# -> 0.7 0.3
print(round(1.0 + gamma * 4.5, 2))# -> 5.05
print(round(math.exp(beta * 1.0), 4), round(math.exp(beta * -1.0), 4))# -> 20.0855 0.0498Watch Out For
Pushing tau to 1.0 on noisy logs
High hugs the best logged return. On noisy data that best return is often a lucky outlier, so chases noise and targets wobble. The symptom is strong training curves on clean demos but shaky values on mixed logs.
Stay near , move to only for expert heavy data, and watch the gap between and median . If sits far above most logged values, lower before touching anything else.
Letting exp beta advantage explode
Large turns weights into spikes. One transition dominates the batch, gradients jump, and the policy collapses onto a few demos. The symptom is NaN loss or a policy that repeats one move.
Keep in and clip weights at . If the top weight hits the clip often, lower instead of raising the clip.
The Quick Version
- IQL trains offline with no queries to unseen actions.
- Expectile loss with fits toward good logged values, here losses versus .
- Q targets use , here , with no max over actions.
- Advantage weights copy winners, here versus .
- Tune and carefully and clip weights, or noise and overflow undo the stability.