Inferensys

Glossary

Counterfactual Policy Evaluation

A family of off-policy evaluation techniques that estimate how a new reinforcement learning policy would perform using only historical data, explaining potential outcomes without deployment.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
OFF-POLICY EVALUATION

What is Counterfactual Policy Evaluation?

Counterfactual Policy Evaluation (CPE) is a family of off-policy evaluation techniques that estimate the potential performance of a new policy using only historical data generated by a different behavior policy, without deploying the new policy in a live environment.

Counterfactual Policy Evaluation answers the fundamental 'what if' question in reinforcement learning by applying importance sampling or direct method estimators to logged data. It corrects for the distributional shift between the logging policy that collected the data and the target evaluation policy, providing an unbiased estimate of expected returns. This enables safe, pre-deployment auditing of autonomous systems.

Key CPE methods include Inverse Propensity Scoring (IPS), which reweights historical rewards by the probability ratio of actions under the target versus behavior policy, and Doubly Robust (DR) estimation, which combines a learned reward model with IPS to reduce variance. These techniques are critical for explaining potential policy outcomes in high-stakes domains like healthcare and finance before real-world execution.

OFF-POLICY EVALUATION

Key Features of CPE

Counterfactual Policy Evaluation estimates how a new policy would perform using only historical data, eliminating the risk of deploying untested policies in production environments.

01

Off-Policy Estimation Without Deployment

CPE answers the fundamental question: 'What would have happened if we used a different policy?' using only logged data from a previous behavior policy. This avoids costly and potentially dangerous online A/B testing. The core mechanism applies importance sampling or doubly robust estimation to reweight historical trajectories, correcting for the distribution shift between the logging policy and the target evaluation policy.

Zero
Production Risk
02

Inverse Propensity Scoring (IPS)

IPS is the foundational statistical technique for CPE. It reweights each observed trajectory by the ratio of the target policy's action probability to the behavior policy's action probability. Key properties:

  • Unbiased when the behavior policy has full support
  • High variance when the ratio is large, requiring clipping or self-normalization
  • Forms the basis for advanced estimators like Doubly Robust and Weighted IPS
03

Doubly Robust Estimation

The Doubly Robust (DR) estimator combines IPS with a direct method reward model. It remains consistent if either the propensity model or the reward model is correctly specified, providing a crucial safety net. The DR formula:

  • Starts with the direct method estimate of the value
  • Adds an IPS correction term on the residuals
  • Achieves lower variance than pure IPS while maintaining asymptotic unbiasedness
04

High-Confidence Off-Policy Evaluation

Beyond point estimates, CPE must quantify uncertainty to support safe policy deployment. Techniques include:

  • Bootstrap confidence intervals on the estimated policy value
  • Concentration inequalities like Hoeffding's or Bernstein bounds adapted for off-policy data
  • Studentized statistics that account for the heavy-tailed nature of importance-weighted returns This transforms CPE from a simple estimate into a rigorous statistical test for policy improvement.
05

Handling Sequential Decisions

In sequential settings like reinforcement learning, the importance weight becomes a product of action probabilities across the entire trajectory. This causes exponential variance growth with horizon length. Solutions include:

  • Step-wise importance sampling that reweights per-transition instead of per-trajectory
  • Marginalized importance sampling that estimates state distribution ratios directly
  • Stationary distribution correction for infinite-horizon average reward settings
06

Model-Based vs Model-Free CPE

CPE methods span a spectrum of model reliance:

  • Model-Free: Pure importance sampling approaches that require no environment model but suffer from high variance
  • Model-Based: Learn a transition and reward model from historical data, then simulate the target policy. Lower variance but introduces model bias
  • Hybrid: Methods like MAGIC (Model And Guided Importance sampling Combining) that blend both approaches, adaptively weighting model-based and model-free estimates to minimize mean squared error
COUNTERFACTUAL POLICY EVALUATION

Frequently Asked Questions

Addressing the most common technical questions about estimating new policy performance using only historical data, without the risk of online deployment.

Counterfactual policy evaluation (CPE) is a family of off-policy evaluation (OPE) techniques that estimate how a new target policy would perform using only historical data collected by a different logging policy. It answers the 'what if' question without deploying the new policy into a live environment. The core mechanism involves importance sampling (IS) to re-weight historical trajectories, correcting for the distributional shift between the logging policy and the target policy. Advanced methods like doubly robust (DR) estimation combine importance sampling with a learned reward model to reduce variance. For example, in a recommendation system, CPE can predict the click-through rate of a new ranking algorithm using logs from the current production algorithm, preventing costly A/B tests that might degrade user experience.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.