Skip to content

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

Conservative Q-learning (CQL)

Reduce value overestimation for actions poorly supported by a fixed dataset by adding a conservative regularizer to Bellman fitting. CQL is an offline-RL method;

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

Reduce value overestimation for actions poorly supported by a fixed dataset by adding a conservative regularizer to Bellman fitting. CQL is an offline-RL method; it explicitly addresses a distribution shift that ordinary replay-based online algorithms can handle poorly without new exploration.

Question / hypotheses

Can a policy improve using logged transitions while discouraging unsupported optimistic values? Conservative lower-bound interpretations depend on the specified variant and theoretical conditions; they are not universal finite-sample confidence guarantees for arbitrary neural implementations.

Architecture / computational structure

Use a neural Q-function, often twin critics and a stochastic actor in continuous control. A Bellman fitting term is augmented by a penalty that increases values of dataset actions relative to a broader action distribution. Continuous-action versions approximate integrals through sampled actions and importance corrections.

Assumptions

Logged actions must provide sufficient support for useful policies, and rewards, terminal flags, and action normalization must be reliable. No algorithm can identify arbitrary unseen outcomes from a dataset with inadequate coverage without additional assumptions. Offline data do not remove environment-model bias.

Formula / computational definition

A discrete-action CQL(H) form is LQ=LBellman+α[Es∼Dlog⁡∑aeQ(s,a)−E(s,a)∼DQ(s,a)]\mathcal L_Q=\mathcal L_{\mathrm{Bellman}}+\alpha[\mathbb E_{s\sim\mathcal D}\log\sum_a e^{Q(s,a)}-\mathbb E_{(s,a)\sim\mathcal D}Q(s,a)]. Continuous variants require an integral/sampling construction rather than literally summing all actions.

Parameters and notation

Learned quantities include critics, actor where used, and optionally a dual conservatism coefficient. Hyperparameters include conservative weight/target gap, action-sampling count, temperature convention, Bellman loss, target updates, learning rates, batch size, and dataset filtering. Regularization strength trades optimism against excessive pessimism.

Fitting, fine-tuning, and adaptation

Pretrain encoders if appropriate, then fit offline critics with explicit conservatism and validate coefficient sensitivity. If later online interaction is permitted, transition gradually with refreshed replay and reassess the penalty; blindly retaining strong offline pessimism may hinder improvement. Compare frozen and fully adapted encoders.

How to use and calibrate

Split data by trajectory or collection context, evaluate with a trustworthy simulator or carefully justified off-policy evaluation, and compare against behavior cloning. Monitor value gaps and policy distance from logged behavior. A held-out TD loss alone cannot validate real policy return.

Example application

Learn a control policy from a fixed archive of simulator trajectories. The code evaluates the exact discrete log-sum-exp penalty for supplied Q-values and logged actions; Bellman targets, continuous-action sampling, and policy optimization are additional components.

Interpretation / pitfalls

Watch out

An excessively large penalty can undervalue useful supported actions, while weak penalties can leave extrapolation errors. Dataset reward scaling affects the tradeoff. A conservative objective is not a guarantee of safe deployment or evidence that every out-of-dataset action has truly low value.

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([[1.,3.,.5],[.2,.4,2.]]); logged_action=np.array([0,1])
maximum=q.max(axis=1,keepdims=True)
logsumexp=maximum[:,0]+np.log(np.exp(q-maximum).sum(axis=1))
penalty=np.mean(logsumexp-q[np.arange(2),logged_action])
bellman_loss=.3; alpha=.5; total=bellman_loss+alpha*penalty
assert penalty>=0; print(penalty,total)
R

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

q <- matrix(c(1,3,.5,.2,.4,2),2,byrow=TRUE); logged_action <- c(1,2)
maximum <- apply(q,1,max)
logsumexp <- maximum+log(rowSums(exp(q-maximum)))
penalty <- mean(logsumexp-q[cbind(1:2,logged_action)])
bellman_loss <- .3; alpha <- .5; total <- bellman_loss+alpha*penalty
stopifnot(penalty>=0); print(c(penalty,total))

Sources

From the CodeSplash reference, entry DRL011.