WRITE · TRACE · UNDERSTAND

Audit a clipped inverse-propensity estimate

Events are [reward, logging_probability, target_probability].

Read lesson: Audit a clipped inverse-propensity estimate →

Your experiment

Events are [reward, logging_probability, target_probability]. Return value=mean(reward*min(target/logging,clip)), mean_weight, and ESS=(sum weights)**2/sum squared weights (zero if all weights vanish). This is clipped IPS, not self-normalized IPS. Require nonempty finite events, logging probabilities in (0,1], target probabilities in [0,1], and positive finite clip.

Python runs in your browser. Your draft stays on this device.

What to look for

Review propensity provenance, exploration support, clipping bias and the independent unit. A large ESS does not establish unbiased logged data.

Watch your code work

Ready to experiment

Write a solution or load the worked answer, then choose Trace & check.

Step through arrays, variables and training curves produced by your own Python.

About this algorithm

How Audit a clipped inverse-propensity estimate works

The idea

Off-policy evaluation estimates how a new policy would perform using only logs collected under an old one. Each logged event records the reward, the probability the logging policy gave to the action it took, and the probability the target policy would give to that same action.

Inverse propensity scoring reweights each reward by target / logging: actions the new policy prefers count more, actions it avoids count less. Rarely logged actions create huge weights and unstable estimates, so offpolicy_value caps each weight at clip, which lowers variance and adds bias. It divides by the number of events, not by the sum of weights, and reports mean_weight and the effective sample size so you can see how much the logs really support the estimate.

How it works

  1. Require a nonempty list of events and a positive finite clip.
  2. Unpack each event into reward, propensity and target, rejecting non-finite values, a logging probability outside (0, 1] or a target probability outside [0, 1].
  3. Compute the weight as min(target / propensity, clip).
  4. Record the weight and the contribution weight * reward.
  5. Return value as the sum of contributions divided by the number of events, and mean_weight as the average weight.
  6. Compute ess as the squared sum of weights over the sum of squared weights, or 0 when all weights are zero.

What it costs

Time
O(n)
Space
O(n)

One pass computes a weight and a contribution per event, and both lists are kept for the three summaries.

Where it is used

  • Vowpal Wabbit's contextual bandit learner offers inverse propensity scoring as one of its estimators, selected with --cb_type ips.
  • The Open Bandit Pipeline library provides an InverseProbabilityWeighting estimator with a clipping hyperparameter.
  • Bottou and co-authors used clipped importance weights to evaluate changes to Bing's ad placement system from logged data.

Watch out for

  • Dividing by the sum of weights, which is self-normalised IPS, a different estimator from the one this Lab defines.
  • Accepting a logging probability of zero: an action the logging policy could never take leaves the logs with no information about it.
  • Trusting a value whose ess is far below the number of events; a few large weights are then deciding the estimate.