roseking's picture
Add lean source and binary files (part 45)
c270adf verified
Raw History Blame Contribute Delete
9.14 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Repetition.Scalar
import OAI.Combinatorics.IndependentSets.Repetition.CoordinateCompletion
namespace OAI
noncomputable section
namespace IndependentSetsGames.Foundations.Repetition
section
open scoped BigOperators
open Games CorrelatedSampling
variable {Q₁ Q₂ A₁ A₂ S : Type*}
[Fintype Q₁] [Fintype Q₂] [Fintype A₁] [Fintype A₂] [Fintype S]
[Nonempty A₁] [Nonempty A₂] [Nonempty S]
[DecidableEq Q₁] [DecidableEq Q₂] [DecidableEq S] {n : Nat}
theorem coordinate_probability_le_value_of_local_completion
(G : Game Q₁ Q₂ A₁ A₂) (j : Fin n)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(σ : FiniteDistribution ((Q₁ × Q₂) × S))
(profileL : Q₁ → FiniteDistribution S) (profileR : Q₂ → FiniteDistribution S)
(completionL : Q₁ × S → FiniteDistribution (Fin n → Q₁))
(completionR : Q₂ × S → FiniteDistribution (Fin n → Q₂))
(supportL : ∀ q xs, (completionL q).weight xs ≠ 0 → xs j = q.1)
(supportR : ∀ q ys, (completionR q).weight ys ≠ 0 → ys j = q.1)
(fallback : S) :
(σ.mixture (fun z => (completionL (z.1.1,z.2)).product
(completionR (z.1.2,z.2)))).probability (G.coordinateWin strategy j) ≤
G.value +
(2 * Information.totalVariation σ.weight
(fun z => G.questions.weight z.1 * (profileL z.1.1).weight z.2) +
2 * Information.totalVariation σ.weight
(fun z => G.questions.weight z.1 * (profileR z.1.2).weight z.2)) := by
let targetLaw := σ.mixture (fun z => (completionL (z.1.1,z.2)).product (completionR (z.1.2,z.2)))
let δ := 2 * Information.totalVariation σ.weight
(fun z => G.questions.weight z.1 * (profileL z.1.1).weight z.2) +
2 * Information.totalVariation σ.weight
(fun z => G.questions.weight z.1 * (profileR z.1.2).weight z.2)
change targetLaw.probability (G.coordinateWin strategy j) ≤ G.value + δ
by_contra h
have gap : 0 < targetLaw.probability (G.coordinateWin strategy j) - (G.value + δ) :=
sub_pos.mpr (lt_of_not_ge h)
let η := (targetLaw.probability (G.coordinateWin strategy j) - (G.value + δ)) / 2
have hη : 0 < η := by dsimp [η]; linarith
obtain ⟨N,hN⟩ := samplerOutputLaw_arbitrarily_close σ G.questions profileL profileR fallback η hη
let thresholds := sharedProfileThresholds profileL profileR
let γ := traceSeedLaw (rectangleDistribution (α := S) thresholds) N
let sL := samplerLocal thresholds profileL fallback N
let sR := samplerLocal thresholds profileR fallback N
have hvariation := CompletedSampling.coordinateOutputLaw_totalVariation_le
G.questions γ j sL sR completionL completionR supportL supportR σ
have hclose : (CompletedSampling.coordinateOutputLaw G.questions γ j sL sR completionL completionR).totalVariation targetLaw ≤ δ + η :=
hvariation.trans hN
have hsuccess := G.coordinate_probability_le_value_add_embedding_distance j targetLaw
(CompletedSampling.seedLaw γ completionL completionR)
(CompletedSampling.coordinateLeft j sL) (CompletedSampling.coordinateRight j sR)
(CompletedSampling.coordinateLeft_preserves j sL)
(CompletedSampling.coordinateRight_preserves j sR) strategy
have hsym : targetLaw.totalVariation
(G.localEmbeddingLaw (CompletedSampling.seedLaw γ completionL completionR)
(CompletedSampling.coordinateLeft j sL) (CompletedSampling.coordinateRight j sR)) =
(CompletedSampling.coordinateOutputLaw G.questions γ j sL sR completionL completionR).totalVariation targetLaw := by
unfold FiniteDistribution.totalVariation
congr 1
apply Finset.sum_congr rfl
intro q _
exact abs_sub_comm _ _
rw [hsym] at hsuccess
dsimp [η] at hclose
linarith
end
open scoped BigOperators
open Games
variable {Q₁ Q₂ A₁ A₂ : Type*}
[Fintype Q₁] [Fintype Q₂] [Fintype A₁] [Fintype A₂]
[DecidableEq Q₁] [DecidableEq Q₂] {n : ℕ}
theorem selectedLabels_card (selected : Finset (Fin n)) :
Fintype.card (SelectedLabels (A₁ := A₁) (A₂ := A₂) selected) =
(Fintype.card A₁ * Fintype.card A₂) ^ selected.card := by
simp [SelectedLabels, Fintype.card_prod, mul_pow]
theorem unusedCoordinates_card (selected : Finset (Fin n)) :
Fintype.card {i : Fin n // i ∉ selected} = n - selected.card := by
classical
simp
theorem unusedCoordinates_card_real (selected : Finset (Fin n)) :
(Fintype.card {i : Fin n // i ∉ selected} : ℝ) = (n : ℝ) - selected.card := by
have hs : selected.card ≤ n := by simpa using Finset.card_le_univ selected
rw [unusedCoordinates_card, Nat.cast_sub hs]
theorem log_le_logTwo {x : ℝ} (hx : 1 ≤ x) : Real.log x ≤ logTwo x := by
have hlog : 0 ≤ Real.log x := Real.log_nonneg hx
have htwo : 0 < Real.log 2 := Real.log_pos (by norm_num)
have htwo_le : Real.log 2 ≤ 1 := by
convert Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 2) using 1
norm_num
unfold logTwo
apply (le_div_iff₀ htwo).2
simpa using mul_le_mul_of_nonneg_left htwo_le hlog
theorem selectedLabels_log_le [Nonempty A₁] [Nonempty A₂]
(selected : Finset (Fin n)) (ell : ℝ)
(hell : logTwo ((Fintype.card A₁ : ℝ) * (Fintype.card A₂ : ℝ)) ≤ ell) :
Real.log (Fintype.card (SelectedLabels (A₁ := A₁) (A₂ := A₂) selected) : ℝ) ≤
(selected.card : ℝ) * ell := by
have ha : (1 : ℝ) ≤ Fintype.card A₁ := by exact_mod_cast Fintype.card_pos (α := A₁)
have hb : (1 : ℝ) ≤ Fintype.card A₂ := by exact_mod_cast Fintype.card_pos (α := A₂)
have hab : (1 : ℝ) ≤ (Fintype.card A₁ : ℝ) * (Fintype.card A₂ : ℝ) := by nlinarith
rw [selectedLabels_card, Nat.cast_pow, Nat.cast_mul, Real.log_pow]
exact mul_le_mul_of_nonneg_left ((log_le_logTwo hab).trans hell) (Nat.cast_nonneg _)
omit [DecidableEq Q₁] [DecidableEq Q₂] in
theorem selectedInformationRadius_le [Nonempty A₁] [Nonempty A₂]
(G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (positive : 0 < G.selectedSuccess strategy selected)
(ell : ℝ)
(hell : logTwo ((Fintype.card A₁ : ℝ) * (Fintype.card A₂ : ℝ)) ≤ ell) :
selectedInformationRadius G strategy selected ≤
Real.sqrt (((n : ℝ) - selected.card) *
((selected.card : ℝ) * ell + logTwo (1 / G.selectedSuccess strategy selected))) := by
have hprob : 1 ≤ 1 / G.selectedSuccess strategy selected := by
apply (le_div_iff₀ positive).2
simpa using G.selectedSuccess_le_one strategy selected
have hbudget := add_le_add (selectedLabels_log_le (A₁ := A₁) (A₂ := A₂) selected ell hell)
(log_le_logTwo hprob)
unfold selectedInformationRadius
rw [← unusedCoordinates_card_real selected]
apply Real.sqrt_le_sqrt
exact mul_le_mul_of_nonneg_left hbudget (Nat.cast_nonneg _)
theorem sqrt_budget_factor (a b : ℝ) (ha : 0 < a) :
Real.sqrt (a * b) = a * Real.sqrt (b / a) := by
have he : a * b = a ^ 2 * (b / a) := by
field_simp
rw [he, Real.sqrt_mul (sq_nonneg a), Real.sqrt_sq (le_of_lt ha)]
omit [DecidableEq Q₁] [DecidableEq Q₂] in
theorem exists_coordinate_le_information_budget [Nonempty A₁] [Nonempty A₂]
(G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (positive : 0 < G.selectedSuccess strategy selected)
(ell : ℝ)
(hell : logTwo ((Fintype.card A₁ : ℝ) * (Fintype.card A₂ : ℝ)) ≤ ell)
(hselected : selected.card < n)
(error : {i : Fin n // i ∉ selected} → ℝ)
(hsum : (∑ j, error j) ≤ 15 * selectedInformationRadius G strategy selected) :
∃ j : {i : Fin n // i ∉ selected}, error j ≤ 15 * Real.sqrt
(((selected.card : ℝ) * ell + logTwo (1 / G.selectedSuccess strategy selected)) /
((n : ℝ) - selected.card)) := by
classical
have hcard : 0 < Fintype.card {i : Fin n // i ∉ selected} := by
rw [unusedCoordinates_card]
exact Nat.sub_pos_of_lt hselected
let : Nonempty {i : Fin n // i ∉ selected} := Fintype.card_pos_iff.mp hcard
have hden : 0 < (n : ℝ) - selected.card := by
rw [← unusedCoordinates_card_real selected]
exact_mod_cast hcard
have htotal := hsum.trans (mul_le_mul_of_nonneg_left
(selectedInformationRadius_le G strategy selected positive ell hell) (by norm_num : (0 : ℝ) ≤ 15))
rw [sqrt_budget_factor _ _ hden] at htotal
have havg : (∑ j, error j) ≤ ∑ _j : {i : Fin n // i ∉ selected},
15 * Real.sqrt
(((selected.card : ℝ) * ell + logTwo (1 / G.selectedSuccess strategy selected)) /
((n : ℝ) - selected.card)) := by
simpa only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul,
unusedCoordinates_card_real, mul_assoc, mul_left_comm] using htotal
obtain ⟨j, _, hj⟩ := Finset.exists_le_of_sum_le Finset.univ_nonempty havg
exact ⟨j, hj⟩
end IndependentSetsGames.Foundations.Repetition
end
end OAI