Bandits.TS.p0_tsAlgorithm
From the authors
The first action of Thompson sampling is sampled according to its probability of being optimal under the prior over environments.
-
š : Type u_2MeasurableSpace šA measurable space is a space equipped with a Ļ-algebra.StandardBorelSpace šA standard Borel space is a measurable space arising as the Borel sets of some Polish topology.Nonempty š
-
K : āNeZero K -
Q : MeasureTheory.Measure šA measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure.MeasureTheory.IsProbabilityMeasure QA measureμis called a probability measure ifμ univ = 1. -
Īŗ : ProbabilityTheory.Kernel (š Ć Fin K) āA kernel from a measurable spaceαto another measurable spaceβis a measurable functionĪŗ : α ā Measure β.ProbabilityTheory.IsMarkovKernel ĪŗA kernel is a Markov kernel if every measure in its image is a probability measure.
(tsAlgorithm Q Īŗ).p0 () = MeasureTheory.Measure.map (Learning.IsBayesAlgEnvSeq.bestAction Īŗ id) QMeasurableSpace : Type u_6 ā Type u_6A measurable space is a space equipped with a Ļ-algebra.
StandardBorelSpace : (α : Type u_1) ā [MeasurableSpace α] ā PropA standard Borel space is a measurable space arising as the Borel sets of some Polish topology. This is useful in situations where a space has no natural topology or the natural topology in a space is non-Polish. To endow a standard Borel space `α` with a compatible Polish topology, use `letI := upgradeStandardBorel α`. One can then use `eq_borel_upgradeStandardBorel α` to rewrite the `MeasurableSpace α` instance to `borel α t`, where `t` is the new topology.
Nonempty : Sort u ā Prop`Nonempty α` is a typeclass that says that `α` is not an empty type, that is, there exists an element in the type. It differs from `Inhabited α` in that `Nonempty α` is a `Prop`, which means that it does not actually carry an element of `α`, only a proof that *there exists* such an element. Given `Nonempty α`, you can construct an element of `α` *nonconstructively* using `Classical.choice`.
NeZero : {R : Type u_1} ā [Zero R] ā R ā PropA type-class version of `n ā 0`.
Nat : TypeThe natural numbers, starting at zero. This type is special-cased by both the kernel and the compiler, and overridden with an efficient implementation. Both use a fast arbitrary-precision arithmetic library (usually [GMP](https://gmplib.org/)); at runtime, `Nat` values that are sufficiently small are unboxed.
MeasureTheory.IsProbabilityMeasure : {α : Type u_1} ā {m0 : MeasurableSpace α} ā MeasureTheory.Measure α ā PropA measure `μ` is called a probability measure if `μ univ = 1`.
MeasureTheory.Measure : (α : Type u_5) ā [MeasurableSpace α] ā Type u_5A measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. The measure of a set `s`, denoted `μ s`, is an extended nonnegative real. The real-valued version is written `μ.real s`.
ProbabilityTheory.IsMarkovKernel : {α : Type u_1} ā
{β : Type u_2} ā {mα : MeasurableSpace α} ā {mβ : MeasurableSpace β} ā ProbabilityTheory.Kernel α β ā PropA kernel is a Markov kernel if every measure in its image is a probability measure.
ProbabilityTheory.Kernel : (α : Type u_1) ā (β : Type u_2) ā [MeasurableSpace α] ā [MeasurableSpace β] ā Type (max u_1 u_2)A kernel from a measurable space `α` to another measurable space `β` is a measurable function `Īŗ : α ā Measure β`. The measurable space structure on `MeasureTheory.Measure β` is given by `MeasureTheory.Measure.instMeasurableSpace`. A map `Īŗ : α ā MeasureTheory.Measure β` is measurable iff `ā s : Set β, MeasurableSet s ā Measurable (fun a ⦠κ a s)`.
Prod : Type u ā Type v ā Type (max u v)The product type, usually written `α à β`. Product types are also called pair or tuple types. Elements of this type are pairs in which the first element is an `α` and the second element is a `β`. Products nest to the right, so `(x, y, z) : α à β à γ` is equivalent to `(x, (y, z)) : α Ć (β à γ)`. Conventions for notations in identifiers: * The recommended spelling of `Ć` in identifiers is `Prod`.
Fin : ā ā TypeNatural numbers less than some upper bound. In particular, a `Fin n` is a natural number `i` with the constraint that `i < n`. It is the canonical type with `n` elements.
Real : TypeThe type `ā` of real numbers constructed as equivalence classes of Cauchy sequences of rational numbers.
Eq : {α : Sort u_1} ā α ā α ā PropThe equality relation. It has one introduction rule, `Eq.refl`.
We use `a = b` as notation for `Eq a b`.
A fundamental property of equality is that it is an equivalence relation.
```
variable (α : Type) (a b c d : α)
variable (hab : a = b) (hcb : c = b) (hcd : c = d)
example : a = d :=
Eq.trans (Eq.trans hab (Eq.symm hcb)) hcd
```
Equality is much more than an equivalence relation, however. It has the important property that every assertion
respects the equivalence, in the sense that we can substitute equal expressions without changing the truth value.
That is, given `h1 : a = b` and `h2 : p a`, we can construct a proof for `p b` using substitution: `Eq.subst h1 h2`.
Example:
```
example (α : Type) (a b : α) (p : α ā Prop)
(h1 : a = b) (h2 : p a) : p b :=
Eq.subst h1 h2
example (α : Type) (a b : α) (p : α ā Prop)
(h1 : a = b) (h2 : p a) : p b :=
h1 āø h2
```
The triangle in the second presentation is a macro built on top of `Eq.subst` and `Eq.symm`, and you can enter it by typing `\t`.
For more information: [Equality](https://lean-lang.org/theorem_proving_in_lean4/quantifiers_and_equality.html#equality)
Conventions for notations in identifiers:
* The recommended spelling of `=` in identifiers is `eq`.Bandits.tsAlgorithm : {K : ā} ā
{š : Type u_1} ā
[inst : MeasurableSpace š] ā
[StandardBorelSpace š] ā
[Nonempty š] ā
[NeZero K] ā
(Q : MeasureTheory.Measure š) ā
[MeasureTheory.IsProbabilityMeasure Q] ā
(Īŗ : ProbabilityTheory.Kernel (š Ć Fin K) ā) ā
[ProbabilityTheory.IsMarkovKernel Īŗ] ā Learning.Algorithm Unit (Fin K) āThe Thompson sampling algorithm with actions in `Fin K`, where `Q : Measure š` is a prior distribution over parameters, and `Īŗ : Kernel (š Ć Fin K) ā` is a Markov kernel that defines the stationary environment `stationaryEnv (Īŗ.sectR e)` that corresponds to a parameter `e : š`. At every time `n`, the Thompson sampling policy uses the posterior over the parameters given the history up to time `n` to derive the probability of each action being optimal. The action for time `n` is sampled according to these probabilities.Go to its page
Learning.Algorithm.p0 : {š : Type u_1} ā
{š : Type u_2} ā
{šØ : Type u_3} ā
{mš : MeasurableSpace š} ā
{mš : MeasurableSpace š} ā {mšØ : MeasurableSpace šØ} ā Learning.Algorithm š š šØ ā ProbabilityTheory.Kernel š šDistribution of the first action given the first observation: the policy at time `0` applied to the empty history.Go to its page
Unit.unit : UnitThe only element of the unit type. It can be written as an empty tuple: `()`.
MeasureTheory.Measure.map : {α : Type u_4} ā
{β : Type u_5} ā
[inst : MeasurableSpace α] ā
[inst_1 : MeasurableSpace β] ā (α ā β) ā MeasureTheory.Measure α ā MeasureTheory.Measure βThe pushforward of a measure. If `f` is not an almost everywhere measurable function, we define it to be `0` if `μ = 0`, and to be an arbitrary Dirac mass otherwise. That way we always have `map f 0 = 0`, and the push-forward of a probability measure is always a probability measure.
Learning.IsBayesAlgEnvSeq.bestAction : {š : Type u_1} ā
{š : Type u_2} ā
{Ī© : Type u_4} ā
[inst : MeasurableSpace š] ā
[inst_1 : MeasurableSpace š] ā [Nonempty š] ā [Fintype š] ā ProbabilityTheory.Kernel (š Ć š) ā ā (Ī© ā š) ā Ī© ā šA random variable that gives the action with the highest mean feedback.Go to its page
id : {α : Sort u} ā α ā αThe identity function. `id` takes an implicit argument `α : Sort u` (a type in any universe), and an argument `a : α`, and returns `a`. Although this may look like a useless function, one application of the identity function is to explicitly put a type on an expression. If `e` has type `T`, and `T'` is definitionally equal to `T`, then `@id T' e` typechecks, and Lean knows that this expression has type `T'` rather than `T`. This can make a difference for typeclass inference, since `T` and `T'` may have different typeclass instances on them. `show T' from e` is sugar for an `@id T' e` expression.
Code
lemma TS.p0_tsAlgorithm :
(tsAlgorithm Q Īŗ).p0 () = Q.map (bestAction Īŗ id)Proof
by
rw [Algorithm.p0_apply]
dsimp only [tsAlgorithm]
rw [TS.policy, Kernel.prodMkRight_apply, Kernel.map_apply _ (by fun_prop),
IT.bayesTrajMeasurePosterior_zero, Kernel.const_apply]Meaning last changed in v4.35.0-rc2-1-g61e506b (2026-09-22), the 5th recorded change.
Self-contained, with its dependencies inlined and proofs replaced by sorry: download the raw file Ā· open it in the Lean web editor.
Dependency graph
Audit surface: 35 project declarations, 102 external constants
ā Proved: no sorry anywhere in its closure
This is the tool's own reading of one build's recorded axioms, and it is not robust against an author who wants it to pass. Checking meant to be relied on should go through Comparator, which replays the proof through the kernel from an export against an explicit list of permitted axioms.