Skip to content

Deep reinforcement learning and decision models · Method reference · DRL012 · Algorithm

Implicit Q-learning (IQL)

Learn from logged actions without explicitly maximizing Q over unsupported actions during training. IQL fits an upper-expectile value function and extracts a policy with advantage-weighted behavior cloning, separating…

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through decide.offline_rl. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Learn from logged actions without explicitly maximizing Q over unsupported actions during training. IQL fits an upper-expectile value function and extracts a policy with advantage-weighted behavior cloning, separating value estimation from action-generation optimization.

Question / hypotheses

Can higher-value behavior present in the data be emphasized without querying out-of-distribution actions in the Bellman update? The method depends on useful behavior coverage and function approximation; it cannot create evidence about completely unsupported transitions.

Architecture / computational structure

Neural Q critics, a state-value network, and a policy are fitted using offline minibatches. The value network uses asymmetric squared loss on logged-action Q values; Q bootstraps from the next-state value, and the actor imitates logged actions weighted by estimated advantage.

Assumptions

The dataset contains informative actions and coherent trajectories; state/action normalization and terminal masks are correct. Expectile optimization is not quantile regression. Generalization across states may improve on individual trajectories but remains dependent on data support.

Formula / computational definition

LV=E[∣τ−1u<0∣u2]L_V=\mathbb E[|\tau-\mathbf1_{u<0}|u^2], u=Q(s,a)−V(s)u=Q(s,a)-V(s); LQ=E[(Q(s,a)−r−γ(1−d)V(s′))2]L_Q=\mathbb E[(Q(s,a)-r-\gamma(1-d)V(s^\prime))^2]; Lπ=−E[eβ(Q−V)log⁡π(a∣s)]L_\pi=-\mathbb E[e^{\beta(Q-V)}\log\pi(a\mid s)], often with clipped weights.

Parameters and notation

Learned parameters belong to Q, V, and policy networks; delayed critic parameters may stabilize value fitting. Hyperparameters include expectile tau, advantage inverse-temperature beta, weight cap, learning rates, discount, target averaging, batch size, architecture, and reward scaling.

Fitting, fine-tuning, and adaptation

Warm-start representation layers where feature meaning matches. Adapt Q and V to the target reward before trusting weighted imitation. Optional online fine-tuning needs new data and a documented update protocol; evaluate frozen-encoder, partial-unfreeze, and full-update variants without reusing final evaluation trajectories for tuning.

How to use and calibrate

Compare with behavior cloning and CQL using trajectory-level splits and matched offline datasets. Monitor advantage-weight concentration, expectile residuals, and returns from an appropriate evaluation environment. Tune tau and beta on validation tasks rather than relying on a single reported default.

Example application

Select better behavior from a mixed-quality dataset of continuous-control trajectories. The code computes expectile loss and a capped advantage-weighted imitation objective for supplied Q, V, and action log probabilities; it does not fit the networks.

Interpretation / pitfalls

Watch out

Large beta can let a few noisy advantages dominate training, while tau near one can amplify optimistic approximation errors. Clipping weights changes the extraction objective. Calling IQL ordinary behavior cloning misses the learned value-dependent weighting, but offline support limitations remain.

Python and R code examples

Scope: computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. Dependencies/validation: Python with NumPy executed successfully; base R not executed. Targets and supplied network outputs are ordinary arrays here, so this does not validate automatic-differentiation boundaries.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. · needs numpy

import numpy as np
q=np.array([2.,.5,1.2]); value=np.array([1.,1.,1.]); residual=q-value
tau=.7; weights=np.where(residual>=0,tau,1-tau)
value_loss=np.mean(weights*residual**2)
beta=3.; imitation_weights=np.minimum(np.exp(beta*residual),20.)
logp=np.array([-.2,-1.,-.5]); actor_loss=-np.mean(imitation_weights*logp)
print(value_loss,imitation_weights,actor_loss)
R

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop.

q <- c(2,.5,1.2); value <- c(1,1,1); residual <- q-value
tau <- .7; weights <- ifelse(residual>=0,tau,1-tau)
value_loss <- mean(weights*residual^2)
beta <- 3; imitation_weights <- pmin(exp(beta*residual),20)
logp <- c(-.2,-1,-.5); actor_loss <- -mean(imitation_weights*logp)
print(value_loss); print(imitation_weights); print(actor_loss)

Sources

From the CodeSplash reference, entry DRL012.