lean/FeedbackChannel/SelectionTieRules.lean

View on GitHub

  1import FeedbackChannel.SelectionContainment
  2
  3/-!
  4# Theorem A (tie rules) and Theorem B for every tie rule
  5
  6Source: `paper/selection_law_kl_containment.md`, draft 0.3, §1–§2.
  7
  8Draw `ω₁, …, ω_K` i.i.d. from `p₀` and keep one of maximal score. A *tie rule* is a kept index
  9`J = pick(r, (S ω₁, …, S ω_K))`, a function of the score vector and of randomness `r ~ ν`
 10independent of the sample, lying in the argmax set (the first-index rule takes `r` trivial; the
 11uniform rule takes `r` a uniformly random order).
 12
 13**Theorem A.** The kept record has law `π_K(ω) = p₀(ω) m_K(S ω)/q(S ω)` (`keptLaw_eq`), whatever the
 14tie rule. The proof here is the conditioning argument of the note made combinatorial: swapping the
 15kept record with an independent record of the same score is a weight-preserving bijection
 16(`swap_sum`), which gives `P(ω_J = ω) q(S ω) = p₀(ω) P(max score = S ω)`, and
 17`P(max score = s) = F(s)^K - F(s-)^K` (`prob_max_score_eq`).
 18
 19**Theorem B for every tie rule** (`theoremB_every_tie_rule`): `KL(law of the kept record ‖ p₀) ≤
 20ln K - (K - 1)/K`.
 21-/
 22
 23namespace FeedbackChannel.SelectionTieRules
 24
 25open Finset Real FeedbackChannel.SelectionContainment
 26
 27variable {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (p0 : Ω → ℝ) (S : Ω → ℝ) {K : ℕ}
 28
 29/-- A tie rule with auxiliary randomness in `R`: the kept index is in the argmax set. -/
 30structure TieRule (R : Type*) (K : ℕ) where
 31  pick : R → (Fin K → ℝ) → Fin K
 32  pick_max : ∀ (r : R) (v : Fin K → ℝ) (k : Fin K), v k ≤ v (pick r v)
 33
 34/-- Law of the kept record: `K` i.i.d. draws with law `p₀`, independent randomness `r ~ ν`. -/
 35def keptLaw {R : Type*} [Fintype R] (ν : R → ℝ) (T : TieRule R K) (ω0 : Ω) : ℝ :=
 36  ∑ r, ν r * ∑ ω : Fin K → Ω, (∏ k, p0 (ω k)) * if ω (T.pick r (S ∘ ω)) = ω0 then 1 else 0
 37
 38/-- `P(every draw satisfies P) = P(P)^K` for i.i.d. draws. -/
 39theorem prob_all (P : Ω → Prop) [DecidablePred P] :
 40    ∑ ω : Fin K → Ω, (∏ k, p0 (ω k)) * (if ∀ k, P (ω k) then 1 else 0) =
 41      (∑ x, if P x then p0 x else 0) ^ K := by
 42  conv_rhs => rw [← Finset.card_fin K, ← Finset.prod_const]
 43  rw [Finset.prod_univ_sum, Fintype.piFinset_univ]
 44  apply Finset.sum_congr rfl
 45  intro ω _
 46  by_cases h : ∀ k, P (ω k)
 47  · rw [ite_eq_left h, mul_one]
 48    exact Finset.prod_congr rfl fun k _ => (ite_eq_left (h k)).symm
 49  · rw [ite_eq_right h, mul_zero]
 50    obtain ⟨k, hk⟩ := not_forall.mp h
 51    exact (Finset.prod_eq_zero (mem_univ k) (ite_eq_right hk)).symm
 52
 53/-- The law of the maximum of `K` i.i.d. scores, read off any argmax index:
 54`P(S(ω_J) = s) = F(s)^K - F(s-)^K = m_K(s)`. -/
 55theorem prob_max_score_eq (J : (Fin K → ℝ) → Fin K) (hJ : ∀ (v : Fin K → ℝ) (k : Fin K), v k ≤ v (J v)) (s0 : ℝ) :
 56    ∑ ω : Fin K → Ω, (∏ k, p0 (ω k)) * (if S (ω (J (S ∘ ω))) = s0 then 1 else 0) =
 57      maxLaw p0 S K s0 := by
 58  have hpt : ∀ ω : Fin K → Ω, (if S (ω (J (S ∘ ω))) = s0 then (1 : ℝ) else 0) =
 59      (if ∀ k, S (ω k) ≤ s0 then 1 else 0) - (if ∀ k, S (ω k) < s0 then 1 else 0) := by
 60    intro ω
 61    have hmax : ∀ k, S (ω k) ≤ S (ω (J (S ∘ ω))) := fun k => hJ (S ∘ ω) k
 62    rcases lt_trichotomy (S (ω (J (S ∘ ω)))) s0 with h | h | h
 63    · rw [ite_eq_right h.ne, ite_eq_left (fun k => (hmax k).trans h.le),
 64        ite_eq_left (fun k => lt_of_le_of_lt (hmax k) h)]
 65      ring
 66    · rw [ite_eq_left h, ite_eq_left (fun k => h ▸ hmax k), ite_eq_right (fun hall => (hall _).ne h)]
 67      ring
 68    · rw [ite_eq_right h.ne', ite_eq_right (fun hall => not_le.mpr h (hall _)),
 69        ite_eq_right (fun hall => (lt_asymm h) (hall _))]
 70      ring
 71  simp_rw [hpt, mul_sub, Finset.sum_sub_distrib]
 72  rw [prob_all p0 (fun x => S x ≤ s0), prob_all p0 (fun x => S x < s0)]
 73  unfold maxLaw cdf cdfLt
 74  rw [Finset.sum_filter, Finset.sum_filter]
 75
 76/-- Swap the kept record (index `J`) with an extra record. -/
 77def swap (J : (Fin K → ℝ) → Fin K) (x : (Fin K → Ω) × Ω) : (Fin K → Ω) × Ω :=
 78  (Function.update x.1 (J (S ∘ x.1)) x.2, x.1 (J (S ∘ x.1)))
 79
 80omit [Fintype Ω] [DecidableEq Ω] in
 81theorem score_update (ω : Fin K → Ω) (j : Fin K) (v : Ω) (h : S v = S (ω j)) :
 82    S ∘ Function.update ω j v = S ∘ ω := by
 83  rw [Function.comp_update, h]
 84  exact Function.update_eq_self j (S ∘ ω)
 85
 86/-- **The swap bijection.** Exchanging the kept record with an independent record of the same
 87score preserves the product weight and maps `{ω_J = ω₀, S ω' = S ω₀}` onto
 88`{S(ω_J) = S ω₀, ω' = ω₀}`. -/
 89theorem swap_sum (J : (Fin K → ℝ) → Fin K) (ω0 : Ω) :
 90    ∑ x ∈ univ.filter (fun x : (Fin K → Ω) × Ω => x.1 (J (S ∘ x.1)) = ω0 ∧ S x.2 = S ω0),
 91        (∏ k, p0 (x.1 k)) * p0 x.2 =
 92      ∑ x ∈ univ.filter (fun x : (Fin K → Ω) × Ω => S (x.1 (J (S ∘ x.1))) = S ω0 ∧ x.2 = ω0),
 93        (∏ k, p0 (x.1 k)) * p0 x.2 := by
 94  apply Finset.sum_nbij' (swap S J) (swap S J)
 95  · rintro ⟨ω, ω'⟩ hx
 96    simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢
 97    obtain ⟨h1, h2⟩ := hx
 98    have hS := score_update S ω (J (S ∘ ω)) ω' (by rw [h2, h1])
 99    simp only [swap, hS, Function.update_self]
100    exact ⟨h2, h1⟩
101  · rintro ⟨ω, z⟩ hx
102    simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hx ⊢
103    obtain ⟨h1, h2⟩ := hx
104    have hS := score_update S ω (J (S ∘ ω)) z (by rw [h2, h1])
105    simp only [swap, hS, Function.update_self]
106    exact ⟨h2, h1⟩
107  · rintro ⟨ω, ω'⟩ hx
108    simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hx
109    obtain ⟨h1, h2⟩ := hx
110    have hS := score_update S ω (J (S ∘ ω)) ω' (by rw [h2, h1])
111    simp only [swap, hS, Function.update_self, Function.update_idem, Function.update_eq_self]
112  · rintro ⟨ω, z⟩ hx
113    simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hx
114    obtain ⟨h1, h2⟩ := hx
115    have hS := score_update S ω (J (S ∘ ω)) z (by rw [h2, h1])
116    simp only [swap, hS, Function.update_self, Function.update_idem, Function.update_eq_self]
117  · rintro ⟨ω, ω'⟩ _
118    simp only [swap]
119    set j := J (S ∘ ω)
120    have hupd : ∀ k, p0 (Function.update ω j ω' k) =
121        Function.update (fun k => p0 (ω k)) j (p0 ω') k :=
122      fun k => Function.apply_update (fun _ => p0) ω j ω' k
123    simp_rw [hupd]
124    rw [Finset.prod_update_of_mem (mem_univ j),
125      Finset.prod_eq_mul_prod_sdiff_singleton_of_mem (mem_univ j) (fun k => p0 (ω k))]
126    ring
127
128/-- `P(ω_J = ω₀) · q(S ω₀) = p₀(ω₀) · m_K(S ω₀)` for every deterministic argmax rule. -/
129theorem kept_mul_scoreMass (J : (Fin K → ℝ) → Fin K) (hJ : ∀ (v : Fin K → ℝ) (k : Fin K), v k ≤ v (J v)) (ω0 : Ω) :
130    (∑ ω : Fin K → Ω, (∏ k, p0 (ω k)) * if ω (J (S ∘ ω)) = ω0 then 1 else 0) *
131        scoreMass p0 S (S ω0) =
132      p0 ω0 * maxLaw p0 S K (S ω0) := by
133  rw [← prob_max_score_eq p0 S J hJ (S ω0)]
134  unfold scoreMass
135  rw [Finset.sum_filter, Finset.sum_mul_sum, Finset.mul_sum]
136  have hR : ∀ ω : Fin K → Ω, p0 ω0 * ((∏ k, p0 (ω k)) *
137      (if S (ω (J (S ∘ ω))) = S ω0 then 1 else 0)) =
138      ∑ z, (∏ k, p0 (ω k)) * p0 z * (if S (ω (J (S ∘ ω))) = S ω0 ∧ z = ω0 then 1 else 0) := by
139    intro ω
140    rw [Finset.sum_eq_single ω0]
141    · by_cases h : S (ω (J (S ∘ ω))) = S ω0
142      · rw [ite_eq_left h, ite_eq_left ⟨h, rfl⟩]; ring
143      · rw [ite_eq_right h, ite_eq_right (fun hh => h hh.1)]; ring
144    · intro z _ hz
145      rw [ite_eq_right (fun hh => hz hh.2), mul_zero]
146    · intro h; exact absurd (mem_univ ω0) h
147  simp_rw [hR]
148  have hL : ∀ (ω : Fin K → Ω) (z : Ω), (∏ k, p0 (ω k)) * (if ω (J (S ∘ ω)) = ω0 then 1 else 0) *
149      (if S z = S ω0 then p0 z else 0) =
150      (∏ k, p0 (ω k)) * p0 z * (if ω (J (S ∘ ω)) = ω0 ∧ S z = S ω0 then 1 else 0) := by
151    intro ω z
152    by_cases h1 : ω (J (S ∘ ω)) = ω0 <;> by_cases h2 : S z = S ω0 <;> simp [h1, h2]
153  simp_rw [hL]
154  have hswap := swap_sum p0 S J ω0
155  rw [Finset.sum_filter, Finset.sum_filter, Fintype.sum_prod_type, Fintype.sum_prod_type] at hswap
156  dsimp only at hswap
157  simp only [mul_ite, mul_one, mul_zero]
158  exact hswap
159
160/-- **Theorem A.** For every tie rule (deterministic in the score vector up to independent
161randomness `r ~ ν`, with the kept index in the argmax set), the kept record has law
162`π_K(ω) = p₀(ω) m_K(S ω)/q(S ω)`. -/
163theorem keptLaw_eq (hp0 : ∀ ω, 0 ≤ p0 ω) {R : Type*} [Fintype R] (ν : R → ℝ)
164    (hν : ∑ r, ν r = 1) (T : TieRule R K) (ω0 : Ω) :
165    keptLaw p0 S ν T ω0 = bestOfK p0 S K ω0 := by
166  have hr : ∀ r, (∑ ω : Fin K → Ω, (∏ k, p0 (ω k)) * if ω (T.pick r (S ∘ ω)) = ω0 then 1 else 0)
167      = bestOfK p0 S K ω0 := by
168    intro r
169    unfold bestOfK
170    by_cases hq : scoreMass p0 S (S ω0) = 0
171    · have hp : p0 ω0 = 0 :=
172        le_antisymm (hq ▸ p0_le_scoreMass p0 S hp0 ω0) (hp0 ω0)
173      rw [hq, div_zero]
174      apply Finset.sum_eq_zero
175      intro ω _
176      by_cases h : ω (T.pick r (S ∘ ω)) = ω0
177      · rw [ite_eq_left h, mul_one]
178        exact Finset.prod_eq_zero (mem_univ (T.pick r (S ∘ ω))) (by rw [h, hp])
179      · rw [ite_eq_right h, mul_zero]
180    · rw [eq_div_iff hq]
181      exact kept_mul_scoreMass p0 S (T.pick r) (T.pick_max r) ω0
182  unfold keptLaw
183  simp_rw [hr]
184  rw [← Finset.sum_mul, hν, one_mul]
185
186/-- **Theorem B, for every tie rule.** For every finite base law `p₀`, score `S`, `K ≥ 1` and tie
187rule, `KL(law of the kept record ‖ p₀) ≤ ln K - (K - 1)/K`. -/
188theorem theoremB_every_tie_rule (hp0 : ∀ ω, 0 ≤ p0 ω) (hsum : ∑ ω, p0 ω = 1) (hK : 1 ≤ K)
189    {R : Type*} [Fintype R] (ν : R → ℝ) (hν : ∑ r, ν r = 1) (T : TieRule R K) :
190    kl (keptLaw p0 S ν T) p0 ≤ lam K := by
191  have : keptLaw p0 S ν T = bestOfK p0 S K := funext (keptLaw_eq p0 S hp0 ν hν T)
192  rw [this]
193  exact theoremB p0 S hp0 hsum hK
194
195/-- **Theorem B, equality case, for every tie rule:** `KL = λ_K` iff `K = 1`; for `K ≥ 2` the
196inequality is strict. -/
197theorem theoremB_every_tie_rule_eq_iff (hp0 : ∀ ω, 0 ≤ p0 ω) (hsum : ∑ ω, p0 ω = 1)
198    (hK : 1 ≤ K) {R : Type*} [Fintype R] (ν : R → ℝ) (hν : ∑ r, ν r = 1) (T : TieRule R K) :
199    kl (keptLaw p0 S ν T) p0 = lam K ↔ K = 1 := by
200  have : keptLaw p0 S ν T = bestOfK p0 S K := funext (keptLaw_eq p0 S hp0 ν hν T)
201  rw [this]
202  exact theoremB_eq_iff p0 S hp0 hsum hK
203
204end FeedbackChannel.SelectionTieRules