LeanMachineLearning exposition

Bandits.ArrayModel.hasCondDistrib_action'๐Ÿ”—

This page has the declaration's own card below, then its dependency graph, then a card for each dependency (type dependencies first, then the rest of the transitive closure). For a theorem, the graph and the dependency cards only follow its statement's dependencies (its proof is replaced by sorry, so what it proves doesn't depend on how); for everything else, both the type and the body/value are followed, since their content is part of what later declarations build on.

Minimal Lean file

hasCondDistrib_action'๐Ÿ”—

LemmaBandits.ArrayModel.hasCondDistrib_action'

No docstring.

๐Ÿ”—theorem
Bandits.ArrayModel.hasCondDistrib_action'.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] [DecidableEq ๐“] [Countable ๐“] [StandardBorelSpace R] [Nonempty R] (alg : Learning.Algorithm ๐“ R) (ฮฝ : ProbabilityTheory.Kernel ๐“ R) [ProbabilityTheory.IsMarkovKernel ฮฝ] (n : โ„•) : ProbabilityTheory.HasCondDistrib (action alg (n + 1)) (fun x => hist alg x n) (Learning.Algorithm.policy alg n) (arrayMeasure ฮฝ)
Bandits.ArrayModel.hasCondDistrib_action'.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] [DecidableEq ๐“] [Countable ๐“] [StandardBorelSpace R] [Nonempty R] (alg : Learning.Algorithm ๐“ R) (ฮฝ : ProbabilityTheory.Kernel ๐“ R) [ProbabilityTheory.IsMarkovKernel ฮฝ] (n : โ„•) : ProbabilityTheory.HasCondDistrib (action alg (n + 1)) (fun x => hist alg x n) (Learning.Algorithm.policy alg n) (arrayMeasure ฮฝ)

Code

lemma hasCondDistrib_action' (alg : Algorithm ๐“ R) (ฮฝ : Kernel ๐“ R) [IsMarkovKernel ฮฝ] (n : โ„•) :
    HasCondDistrib (action alg (n + 1)) (hist alg ยท n) (alg.policy n) (arrayMeasure ฮฝ)
Type uses (6)
Body uses (11)
Used by (1)

Actions: Source ยท Open Issue

Proof
by
  rw [action_add_one_eq]
  have h_fun ฯ‰ := algFunction_map alg n (hist alg ฯ‰ n)
  refine โŸจby fun_prop, ?_โŸฉ
  have h_indep : (arrayMeasure ฮฝ).map (fun ฯ‰ โ†ฆ (ฯ‰.1 (n + 1), hist alg ฯ‰ n)) =
      (โ„™).prod ((arrayMeasure ฮฝ).map (hist alg ยท n)) := by
    have h_indep' := indepFun_fst_add_one_hist alg ฮฝ n
    rw [indepFun_iff_map_prod_eq_prod_map_map (by fun_prop) (by fun_prop)] at h_indep'
    rw [h_indep']
    congr
    simp only [arrayMeasure]
    calc ((Measure.infinitePi fun x โ†ฆ โ„™).prod (streamMeasure ฮฝ)).map (fun ฯ‰ โ†ฆ ฯ‰.1 (n + 1))
    _ = (Measure.infinitePi fun x โ†ฆ โ„™).map (Function.eval (n + 1)) := by
      nth_rw 2 [โ† Measure.fst_prod (ฮผ := Measure.infinitePi fun x โ†ฆ โ„™)
        (ฮฝ := streamMeasure ฮฝ)]
      rw [Measure.fst, Measure.map_map (by fun_prop) (by fun_prop)]
      rfl
    _ = โ„™ := by rw [Measure.infinitePi_map_eval]
  have : (fun x โ†ฆ (hist alg x n, algFunction alg n (hist alg x n) (x.1 (n + 1)))) =
      (fun p โ†ฆ (p.2, algFunction alg n (p.2) (p.1))) โˆ˜ (fun x โ†ฆ (x.1 (n + 1), hist alg x n)) := rfl
  rw [this, โ† Measure.map_map (by fun_prop) (by fun_prop), h_indep]
  have : (โ„™ : Measure I).prod ((arrayMeasure ฮฝ).map (hist alg ยท n)) =
      ((Kernel.const _ โ„™) ร—โ‚– Kernel.id) โˆ˜โ‚˜ ((arrayMeasure ฮฝ).map (hist alg ยท n)) := by
    have h := Measure.compProd_const (ฮผ := (arrayMeasure ฮฝ).map (hist alg ยท n))
      (ฮฝ := (โ„™ : Measure I))
    rw [Measure.compProd_eq_comp_prod] at h
    rw [โ† Measure.prod_swap, โ† h, โ† Measure.deterministic_comp_eq_map (by fun_prop),
      Measure.comp_assoc, โ† Kernel.swap, Kernel.swap_prod]
  rw [this, โ† Measure.deterministic_comp_eq_map (by fun_prop),
    โ† Measure.deterministic_comp_eq_map (by fun_prop), Measure.compProd_eq_comp_prod,
    Measure.comp_assoc, Measure.comp_assoc, Measure.comp_assoc]
  congr 2
  ext ฯ‰ : 1
  simp only [Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap, Kernel.coe_comap,
    Function.comp_apply]
  rw [Kernel.map_apply _ (by fun_prop), Kernel.prod_apply, Kernel.const_apply, Kernel.id_apply,
    Kernel.prod_apply, Kernel.id_apply, โ† h_fun]
  calc (((โ„™).prod (Measure.dirac (hist alg ฯ‰ n)))).map (fun p โ†ฆ (p.2, algFunction alg n p.2 p.1))
  _ = (((โ„™).prod (Measure.dirac (hist alg ฯ‰ n))).map Prod.swap).map
      (fun p โ†ฆ (p.1, algFunction alg n p.1 p.2)) := by
    rw [Measure.map_map (by fun_prop) (by fun_prop)]
    rfl
  _ = ((Measure.dirac (hist alg ฯ‰ n)).prod โ„™).map (fun p โ†ฆ (p.1, algFunction alg n p.1 p.2)) := by
    rw [Measure.prod_swap]
  _ = (Measure.dirac (hist alg ฯ‰ n)).prod ((โ„™).map (algFunction alg n (hist alg ฯ‰ n))) := by
    ext s hs
    rw [Measure.map_apply (by fun_prop) hs, Measure.prod_apply, lintegral_dirac, Measure.prod_apply,
      lintegral_dirac, Measure.map_apply (by fun_prop)]
    ยท congr
    ยท exact hs.preimage (by fun_prop)
    ยท exact hs
    ยท exact hs.preimage (by fun_prop)

Dependency graph

Type dependencies (6)

Algorithm๐Ÿ”—

StructureLearning.Algorithm

A stochastic, sequential algorithm.

๐Ÿ”—structure
Learning.Algorithm.{u_4, u_5} (๐“ : Type u_4) (๐“จ : Type u_5) [MeasurableSpace ๐“] [MeasurableSpace ๐“จ] : Type (max u_4 u_5)
Learning.Algorithm.{u_4, u_5} (๐“ : Type u_4) (๐“จ : Type u_5) [MeasurableSpace ๐“] [MeasurableSpace ๐“จ] : Type (max u_4 u_5)

Code

structure Algorithm (๐“ ๐“จ : Type*) [MeasurableSpace ๐“] [MeasurableSpace ๐“จ] where
  /-- Policy or sampling rule: distribution of the next action. -/
  policy : (n : โ„•) โ†’ Kernel (Iic n โ†’ ๐“ ร— ๐“จ) ๐“
  /-- The policy is a Markov kernel. -/
  [h_policy : โˆ€ n, IsMarkovKernel (policy n)]
  /-- Distribution of the first action. -/
  p0 : Measure ๐“
  /-- The first action distribution is a probability measure. -/
  [hp0 : IsProbabilityMeasure p0]
Used by (216)

Actions: Source ยท Open Issue

probSpace๐Ÿ”—

DefinitionBandits.ArrayModel.probSpace

Probability space for the array model of stochastic bandits.

๐Ÿ”—def
Bandits.ArrayModel.probSpace.{u_1, u_2} (๐“ : Type u_1) (R : Type u_2) : Type (max u_1 u_2)
Bandits.ArrayModel.probSpace.{u_1, u_2} (๐“ : Type u_1) (R : Type u_2) : Type (max u_1 u_2)

Code

def probSpace : Type _ := (โ„• โ†’ I) ร— (โ„• โ†’ ๐“ โ†’ R)
Used by (64)

Actions: Source ยท Open Issue

instMeasurableSpaceProbSpace๐Ÿ”—

InstanceBandits.ArrayModel.instMeasurableSpaceProbSpace

No docstring.

๐Ÿ”—def
Bandits.ArrayModel.instMeasurableSpaceProbSpace.{u_3, u_4} {๐“ : Type u_3} {R : Type u_4} [MeasurableSpace R] : MeasurableSpace (probSpace ๐“ R)
Bandits.ArrayModel.instMeasurableSpaceProbSpace.{u_3, u_4} {๐“ : Type u_3} {R : Type u_4} [MeasurableSpace R] : MeasurableSpace (probSpace ๐“ R)

Code

instance {๐“ R : Type*} [MeasurableSpace R] : MeasurableSpace (probSpace ๐“ R)
Type uses (1)
Used by (41)

Actions: Source ยท Open Issue

Proof
inferInstanceAs (MeasurableSpace ((โ„• โ†’ I) ร— (โ„• โ†’ ๐“ โ†’ R)))

action๐Ÿ”—

DefinitionBandits.ArrayModel.action

Action taken at time n in the array model.

๐Ÿ”—def
Bandits.ArrayModel.action.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] [DecidableEq ๐“] (alg : Learning.Algorithm ๐“ R) (n : โ„•) (ฯ‰ : probSpace ๐“ R) : ๐“
Bandits.ArrayModel.action.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] [DecidableEq ๐“] (alg : Learning.Algorithm ๐“ R) (n : โ„•) (ฯ‰ : probSpace ๐“ R) : ๐“

Code

noncomputable
def action [DecidableEq ๐“] (alg : Algorithm ๐“ R) (n : โ„•) (ฯ‰ : probSpace ๐“ R) : ๐“ :=
  (hist alg ฯ‰ n โŸจn, by simpโŸฉ).1
Type uses (2)
Body uses (1)
Used by (43)

Actions: Source ยท Open Issue

hist๐Ÿ”—

DefinitionBandits.ArrayModel.hist

History of actions and rewards up to time n in the array model.

๐Ÿ”—def
Bandits.ArrayModel.hist.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] [DecidableEq ๐“] (alg : Learning.Algorithm ๐“ R) (ฯ‰ : probSpace ๐“ R) (n : โ„•) : โ†ฅ(Finset.Iic n) โ†’ ๐“ ร— R
Bandits.ArrayModel.hist.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] [DecidableEq ๐“] (alg : Learning.Algorithm ๐“ R) (ฯ‰ : probSpace ๐“ R) (n : โ„•) : โ†ฅ(Finset.Iic n) โ†’ ๐“ ร— R

Code

noncomputable
def hist [DecidableEq ๐“] (alg : Algorithm ๐“ R) (ฯ‰ : probSpace ๐“ R) : (n : โ„•) โ†’ Iic n โ†’ ๐“ ร— R
| 0 => fun _ โ†ฆ (initAlgFunction alg (ฯ‰.1 0), ฯ‰.2 0 (initAlgFunction alg (ฯ‰.1 0)))
| n + 1 =>
  let hn : Iic n โ†’ ๐“ ร— R := hist alg ฯ‰ n
  let a : ๐“ := algFunction alg n hn (ฯ‰.1 (n + 1))
  fun i โ†ฆ if hin : i โ‰ค n then hn โŸจi, by simp [hin]โŸฉ else (a, ฯ‰.2 (pullCount' n hn a) a)
Type uses (2)
Body uses (3)
Used by (30)

Actions: Source ยท Open Issue

arrayMeasure๐Ÿ”—

DefinitionBandits.ArrayModel.arrayMeasure

Probability measure for the array model of stochastic bandits.

๐Ÿ”—def
Bandits.ArrayModel.arrayMeasure.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} (ฮฝ : ProbabilityTheory.Kernel ๐“ R) : MeasureTheory.Measure (probSpace ๐“ R)
Bandits.ArrayModel.arrayMeasure.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} (ฮฝ : ProbabilityTheory.Kernel ๐“ R) : MeasureTheory.Measure (probSpace ๐“ R)

Code

noncomputable
def arrayMeasure (ฮฝ : Kernel ๐“ R) : Measure (probSpace ๐“ R) :=
  (Measure.infinitePi fun _ โ†ฆ volume).prod (streamMeasure ฮฝ)
Type uses (2)
Body uses (1)
Used by (29)

Actions: Source ยท Open Issue

All dependencies, transitively (6)

instIsProbabilityMeasureP0๐Ÿ”—

InstanceLearning.instIsProbabilityMeasureP0

No docstring.

๐Ÿ”—theorem
Learning.instIsProbabilityMeasureP0.{u_1, u_2} {๐“ : Type u_1} {๐“จ : Type u_2} {m๐“ : MeasurableSpace ๐“} {m๐“จ : MeasurableSpace ๐“จ} (alg : Algorithm ๐“ ๐“จ) : MeasureTheory.IsProbabilityMeasure (Algorithm.p0 alg)
Learning.instIsProbabilityMeasureP0.{u_1, u_2} {๐“ : Type u_1} {๐“จ : Type u_2} {m๐“ : MeasurableSpace ๐“} {m๐“จ : MeasurableSpace ๐“จ} (alg : Algorithm ๐“ ๐“จ) : MeasureTheory.IsProbabilityMeasure (Algorithm.p0 alg)

Code

instance (alg : Algorithm ๐“ ๐“จ) : IsProbabilityMeasure alg.p0
Type uses (1)
Used by (13)

Actions: Source ยท Open Issue

Proof
alg.hp0

initAlgFunction๐Ÿ”—

DefinitionBandits.ArrayModel.initAlgFunction

The initial action is the image of a uniform random variable by this function.

๐Ÿ”—def
Bandits.ArrayModel.initAlgFunction.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] (alg : Learning.Algorithm ๐“ R) : โ†‘unitInterval โ†’ ๐“
Bandits.ArrayModel.initAlgFunction.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] (alg : Learning.Algorithm ๐“ R) : โ†‘unitInterval โ†’ ๐“

Code

noncomputable
def initAlgFunction (alg : Algorithm ๐“ R) : I โ†’ ๐“ :=
  (Measure.exists_measurable_map_eq alg.p0).choose
Type uses (1)
Body uses (1)
Used by (12)

Actions: Source ยท Open Issue

instIsMarkovKernelForallSubtypeNatMemFinsetIicProdPolicy๐Ÿ”—

InstanceLearning.instIsMarkovKernelForallSubtypeNatMemFinsetIicProdPolicy

No docstring.

๐Ÿ”—theorem
Learning.instIsMarkovKernelForallSubtypeNatMemFinsetIicProdPolicy.{u_1, u_2} {๐“ : Type u_1} {๐“จ : Type u_2} {m๐“ : MeasurableSpace ๐“} {m๐“จ : MeasurableSpace ๐“จ} (alg : Algorithm ๐“ ๐“จ) (n : โ„•) : ProbabilityTheory.IsMarkovKernel (Algorithm.policy alg n)
Learning.instIsMarkovKernelForallSubtypeNatMemFinsetIicProdPolicy.{u_1, u_2} {๐“ : Type u_1} {๐“จ : Type u_2} {m๐“ : MeasurableSpace ๐“} {m๐“จ : MeasurableSpace ๐“จ} (alg : Algorithm ๐“ ๐“จ) (n : โ„•) : ProbabilityTheory.IsMarkovKernel (Algorithm.policy alg n)

Code

instance (alg : Algorithm ๐“ ๐“จ) (n : โ„•) : IsMarkovKernel (alg.policy n)
Type uses (1)
Used by (14)

Actions: Source ยท Open Issue

Proof
alg.h_policy n

algFunction๐Ÿ”—

DefinitionBandits.ArrayModel.algFunction

The next action is the image of the history and a uniform random variable by this function.

๐Ÿ”—def
Bandits.ArrayModel.algFunction.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] (alg : Learning.Algorithm ๐“ R) (n : โ„•) : (โ†ฅ(Finset.Iic n) โ†’ ๐“ ร— R) โ†’ โ†‘unitInterval โ†’ ๐“
Bandits.ArrayModel.algFunction.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} [Nonempty ๐“] [StandardBorelSpace ๐“] (alg : Learning.Algorithm ๐“ R) (n : โ„•) : (โ†ฅ(Finset.Iic n) โ†’ ๐“ ร— R) โ†’ โ†‘unitInterval โ†’ ๐“

Code

noncomputable
def algFunction (alg : Algorithm ๐“ R) (n : โ„•) :
    (Iic n โ†’ ๐“ ร— R) โ†’ I โ†’ ๐“ :=
  (Kernel.exists_measurable_map_eq_unitInterval (alg.policy n)).choose
Type uses (1)
Body uses (1)
Used by (17)

Actions: Source ยท Open Issue

pullCount'๐Ÿ”—

DefinitionLearning.pullCount'

Number of pulls of arm a up to (and including) time n. This is the number of entries in h in which the arm is a.

๐Ÿ”—def
Learning.pullCount'.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} [DecidableEq ๐“] (n : โ„•) (h : โ†ฅ(Finset.Iic n) โ†’ ๐“ ร— R) (a : ๐“) : โ„•
Learning.pullCount'.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} [DecidableEq ๐“] (n : โ„•) (h : โ†ฅ(Finset.Iic n) โ†’ ๐“ ร— R) (a : ๐“) : โ„•

Code

noncomputable
def pullCount' (n : โ„•) (h : Iic n โ†’ ๐“ ร— R) (a : ๐“) := #{s | (h s).1 = a}
Used by (29)

Actions: Source ยท Open Issue

streamMeasure๐Ÿ”—

DefinitionBandits.streamMeasure

Measure of an infinite stream of rewards from each action.

๐Ÿ”—def
Bandits.streamMeasure.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} (ฮฝ : ProbabilityTheory.Kernel ๐“ R) : MeasureTheory.Measure (โ„• โ†’ ๐“ โ†’ R)
Bandits.streamMeasure.{u_1, u_2} {๐“ : Type u_1} {R : Type u_2} {m๐“ : MeasurableSpace ๐“} {mR : MeasurableSpace R} (ฮฝ : ProbabilityTheory.Kernel ๐“ R) : MeasureTheory.Measure (โ„• โ†’ ๐“ โ†’ R)

Code

noncomputable
def streamMeasure (ฮฝ : Kernel ๐“ R) : Measure (โ„• โ†’ ๐“ โ†’ R) :=
  Measure.infinitePi fun _ โ†ฆ Measure.infinitePi ฮฝ
Used by (56)

Actions: Source ยท Open Issue