Thompson sampling draws from the posterior law of (§8.1.2, p. 73)
ProvedThompsonTutorial.Regret.ts_posterior_matchingWork on a probability space . A random parameter takes values in a measurable space , the disturbances are i.i.d. and independent of , and in period the agent takes an action in a measurable space (finite or infinite) and observes the outcome , earning the reward . The mean reward is , the history is identified with the -algebra it generates, and Thompson sampling chooses , where is a fresh sample from the posterior law of given and is a measurable selector of . The optimal action is .
Then for every period and every measurable set ,
That is, given the history, the action of Thompson sampling has the same conditional distribution as the optimal action. This is the property the paper invokes for the middle equality of (8.4): "TS samples from the posterior distribution of ".
Formalization Note is history g θ w xs t, conditional probabilities are Mathlib conditional expectations of indicators, and is fun ω => f (θ ω).
Differences from the source:
- reading: x* ∈ argmax_x µ(x, θ), and TS's line 6 xt ← argmax_x µ(x, θ̂) (tie-breaking unspecified) → one measurable selector f : Θ → X of argmax_x µ(x, ·), with x* = f(θ) and x_t = f(θ̂_t); reason: the paper's claim that TS samples x_t from the posterior of x* presupposes the same rule; with different tie-breaking the identity is false (θ constant, X = {1, 2}, µ ≡ 0, x* = 1, x_t = 2, U_t(1) = 0, U_t(2) = 1 gives 0 = 0 + 1)
- generalization: a run of Algorithm 4 (sample θ̂ from the current posterior p, act greedily, update p by Bayes' rule) → IsThompsonRun: P(θ̂_t ∈ A | H_{t−1}) = P(θ ∈ A | H_{t−1}) a.s. for every measurable A, and θ̂_t conditionally independent of (θ, w) given H_{t−1}, stated set-wise; reason: every run of Algorithm 4 with a measurable tie-breaking rule satisfies these clauses (iterating the Bayes update gives the posterior given H_{t−1}); the clauses also admit samples that depend on earlier samples beyond H_{t−1}, and need no regular conditional distribution or standard-Borel space
- generalization: µ(x, θ) = E[r(g(x, θ, w_t)) | θ], defined when the expectation exists → meanReward = ∫ r(g(x, ϑ, v)) d(law of w_1)(v), with no integrability assumed (Bochner value 0 where r ∘ g is not integrable); reason: by independence and identical distribution this is a version of the paper's µ wherever the paper's µ is defined; the statement holds for any values of µ, so it specializes to the paper's case
- encoding: period t ∈ N and history H_{t−1} = ((x_1, y_1), …, (x_{t−1}, y_{t−1})) → t : ℕ with 1 ≤ t; H_{t−1} is the σ-algebra history g θ w xs t generated by (x_s, g(x_s, θ, w_s)) for 1 ≤ s < t; reason: 1-based periods without natural-number subtraction; conditioning on the history is conditioning on the σ-algebra it generates
- encoding: θ a random variable, (w_t) i.i.d. and independent of θ, g and r known functions → IsBayesModel: θ, w_t measurable, g jointly measurable, r measurable, (w_{i+1})_i iIndepFun and IdentDistrib, θ independent of the whole sequence; f measurable; reason: measurability is the standing convention implicit in the paper's random variables and expectations
- encoding: TS samples x_t from the posterior distribution of x* → P(x_t ∈ B | H_{t−1}) = P(f(θ) ∈ B | H_{t−1}) almost surely, for every measurable B ⊆ X; reason: equality of conditional distributions stated set-wise, which needs no regular conditional distribution
import Mathlib import Definitions.Def_ThompsonTutorial_Regret_meanReward import Definitions.Def_ThompsonTutorial_Regret_IsBayesModel import Definitions.Def_ThompsonTutorial_Regret_history import Definitions.Def_ThompsonTutorial_Regret_IsThompsonRun open MeasureTheory ProbabilityTheory
namespace ThompsonTutorial.Regret
/-- **Thompson sampling samples `x_t` from the posterior distribution of `x*`.**
Russo, Van Roy, Kazerouni, Osband, Wen, *A Tutorial on Thompson Sampling*, Found. Trends Mach.
Learn. 11(1) (2018), §8.1.2, p. 73 (PDF p. 76): "The second equation holds because TS samples xt
from the posterior distribution of x∗."
In the Bayesian model of §8.1.2, for a run of Thompson sampling (Algorithm 4) with argmax selector
`f`, and the optimal action `x* = f(θ)`, at every period `t ≥ 1` and for every measurable set
`B ⊆ X`, `P(x_t ∈ B | H_{t−1}) = P(x* ∈ B | H_{t−1})` almost surely.
**Formalization Note.** "Samples from the posterior distribution of `x*`" is encoded set-wise, as
equality of the conditional probabilities of every measurable set; `H_{t−1}` is
`history g θ w xs t` (1-based periods). The optimal action uses the same selector `f` as the
algorithm's argmax. -/
theorem ts_posterior_matching {Ω Θ X Y W : Type*} [MeasurableSpace Ω] [MeasurableSpace Θ]
[MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace W]
(P : Measure Ω) [IsProbabilityMeasure P] (θ : Ω → Θ) (w : ℕ → Ω → W)
(g : X → Θ → W → Y) (r : Y → ℝ) (f : Θ → X) (θhat : ℕ → Ω → Θ) (xs : ℕ → Ω → X)
(hM : IsBayesModel P θ w g r) (hTS : IsThompsonRun P θ w g r f θhat xs)
(t : ℕ) (ht : 1 ≤ t) (B : Set X) (hB : MeasurableSet B) :
P[(xs t ⁻¹' B).indicator (fun _ => (1 : ℝ)) | history g θ w xs t]
=ᵐ[P] P[((fun ω => f (θ ω)) ⁻¹' B).indicator (fun _ => (1 : ℝ)) | history g θ w xs t] := by sorry
end ThompsonTutorial.Regret