cfahlgren1's picture
download
raw
15.7 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Encoding.Completion
import OAI.Combinatorics.IndependentSets.Repetition.SelectedProfileBudget
namespace OAI
noncomputable section
namespace IndependentSetsGames.Foundations.Repetition
section
open scoped BigOperators
open Games
variable {I X Y : Type*} [Fintype I] [DecidableEq I]
[Fintype X] [Fintype Y] [DecidableEq X] [DecidableEq Y]
def revealLeftFactor (μ : FiniteDistribution (X × Y)) (r : X ⊕ Y) (x : X) : ℝ :=
match r with
| Sum.inl u => if x = u then 1 else 0
| Sum.inr v => μ.weight (x,v) / 2
def revealRightFactor (μ : FiniteDistribution (X × Y)) (r : X ⊕ Y) (y : Y) : ℝ :=
match r with
| Sum.inl u => μ.weight (u,y) / 2
| Sum.inr v => if y = v then 1 else 0
omit [DecidableEq Y] in
theorem revealLeftFactor_nonnegative (μ : FiniteDistribution (X × Y))
(r : X ⊕ Y) (x : X) : 0 ≤ revealLeftFactor μ r x := by
cases r with
| inl u => simp only [revealLeftFactor]; split <;> norm_num
| inr v => exact div_nonneg (μ.nonnegative _) (by norm_num)
omit [DecidableEq X] in
theorem revealRightFactor_nonnegative (μ : FiniteDistribution (X × Y))
(r : X ⊕ Y) (y : Y) : 0 ≤ revealRightFactor μ r y := by
cases r with
| inl u => exact div_nonneg (μ.nonnegative _) (by norm_num)
| inr v => simp only [revealRightFactor]; split <;> norm_num
theorem revealLaw_factorization (μ : FiniteDistribution (X × Y))
(r : X ⊕ Y) (x : X) (y : Y) :
(revealLaw μ).weight ((x,y),r) =
revealLeftFactor μ r x * revealRightFactor μ r y := by
rw [revealLaw_weight]
cases r with
| inl u =>
by_cases h : x = u
· subst x; simp [revealLeftFactor, revealRightFactor]
· simp [revealLeftFactor, revealRightFactor, h, Ne.symm h]
| inr v =>
by_cases h : y = v
· subst y; simp [revealLeftFactor, revealRightFactor]
· simp [revealLeftFactor, revealRightFactor, h, Ne.symm h]
def partialLeftFactor (μ : FiniteDistribution (X × Y)) (j : I)
(rest : {i : I // i ≠ j} → X ⊕ Y) (x : I → X) : ℝ :=
∏ i, revealLeftFactor μ (rest i) (x i.1)
def partialRightFactor (μ : FiniteDistribution (X × Y)) (j : I)
(rest : {i : I // i ≠ j} → X ⊕ Y) (y : I → Y) : ℝ :=
∏ i, revealRightFactor μ (rest i) (y i.1)
theorem partialRevealWeight_factorization (μ : FiniteDistribution (X × Y)) (j : I)
(rest : {i : I // i ≠ j} → X ⊕ Y) (u : I → X × Y) :
partialRevealWeight μ j rest u =
μ.weight (u j) * partialLeftFactor μ j rest (fun i => (u i).1) *
partialRightFactor μ j rest (fun i => (u i).2) := by
have hpoint (i : {i : I // i ≠ j}) :
(revealLaw μ).weight (u i.1,rest i) =
revealLeftFactor μ (rest i) (u i.1).1 * revealRightFactor μ (rest i) (u i.1).2 :=
revealLaw_factorization μ (rest i) (u i.1).1 (u i.1).2
simp only [partialRevealWeight, partialLeftFactor, partialRightFactor,
hpoint, Finset.prod_mul_distrib]
ring
end
open scoped BigOperators
open Games
section LocalNormalization
variable {I X Y : Type*} [Fintype I] [DecidableEq I]
[Fintype X] [Fintype Y]
def completionTupleEquiv : (I → X × Y) ≃ ((I → X) × (I → Y)) where
toFun u := (fun i => (u i).1, fun i => (u i).2)
invFun z := fun i => (z.1 i, z.2 i)
left_inv u := by funext i; rfl
right_inv z := by cases z; rfl
def updatedTableFallback (μ : FiniteDistribution X) (j : I) (x : X) :
FiniteDistribution (I → X) :=
(FiniteDistribution.table (fun _ : I => μ)).pushforward
(fun l => Function.update l j x)
theorem updatedTableFallback_zero (μ : FiniteDistribution X) (j : I) (x : X)
(l : I → X) (hne : l j ≠ x) :
(updatedTableFallback μ j x).weight l = 0 := by
classical
simp only [updatedTableFallback, FiniteDistribution.pushforward]
apply Finset.sum_eq_zero
intro t _
apply ite_eq_right
intro h
have he := congrFun h j
exact hne (by simpa only [Function.update_self] using he.symm)
theorem normalizeOr_weight_eq_zero_of_zero
(w : X → ℝ) (hw : ∀ x, 0 ≤ w x) (fallback : FiniteDistribution X)
(x : X) (hraw : w x = 0) (hdefault : fallback.weight x = 0) :
(normalizeOr w hw fallback).weight x = 0 := by
classical
unfold normalizeOr
split
· change normalizedWeight w x = 0
simp only [normalizedWeight, hraw, zero_div]
· exact hdefault
end LocalNormalization
variable {Q₁ Q₂ A₁ A₂ : Type*}
[Fintype Q₁] [Fintype Q₂] [Fintype A₁] [Fintype A₂]
[DecidableEq Q₁] [DecidableEq Q₂] {n : Nat}
def selectedLeftRaw (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(x : Q₁) (l : {i : Fin n // i ∉ selected} → Q₁) : ℝ :=
(if l j = x then 1 else 0) * partialLeftFactor G.questions j s.2 l *
selectedLocalTest strategy.1 selected (fun i => (s.1.1 i).1) s.1.2.1 l
def selectedRightRaw (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(y : Q₂) (r : {i : Fin n // i ∉ selected} → Q₂) : ℝ :=
(if r j = y then 1 else 0) * partialRightFactor G.questions j s.2 r *
selectedLocalTest strategy.2 selected (fun i => (s.1.1 i).2) s.1.2.2 r
omit [DecidableEq Q₂] in
theorem selectedLeftRaw_nonnegative (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(x : Q₁) (l : {i : Fin n // i ∉ selected} → Q₁) :
0 ≤ selectedLeftRaw G strategy selected j s x l := by
apply mul_nonneg
· apply mul_nonneg
· split <;> norm_num
· exact Finset.prod_nonneg (fun i _ => revealLeftFactor_nonnegative G.questions (s.2 i) (l i.1))
· exact selectedLocalTest_nonnegative _ _ _ _ _
omit [DecidableEq Q₁] in
theorem selectedRightRaw_nonnegative (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(y : Q₂) (r : {i : Fin n // i ∉ selected} → Q₂) :
0 ≤ selectedRightRaw G strategy selected j s y r := by
apply mul_nonneg
· apply mul_nonneg
· split <;> norm_num
· exact Finset.prod_nonneg (fun i _ => revealRightFactor_nonnegative G.questions (s.2 i) (r i.1))
· exact selectedLocalTest_nonnegative _ _ _ _ _
def selectedLeftCompletion (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(x : Q₁) : FiniteDistribution ({i : Fin n // i ∉ selected} → Q₁) :=
normalizeOr (selectedLeftRaw G strategy selected j s x)
(selectedLeftRaw_nonnegative G strategy selected j s x)
(updatedTableFallback (G.questions.pushforward Prod.fst) j x)
def selectedRightCompletion (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(y : Q₂) : FiniteDistribution ({i : Fin n // i ∉ selected} → Q₂) :=
normalizeOr (selectedRightRaw G strategy selected j s y)
(selectedRightRaw_nonnegative G strategy selected j s y)
(updatedTableFallback (G.questions.pushforward Prod.snd) j y)
omit [DecidableEq Q₂] in
theorem selectedLeftCompletion_zero (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(x : Q₁) (l : {i : Fin n // i ∉ selected} → Q₁) (hne : l j ≠ x) :
(selectedLeftCompletion G strategy selected j s x).weight l = 0 := by
apply normalizeOr_weight_eq_zero_of_zero
· simp only [selectedLeftRaw, ite_eq_right hne, zero_mul]
· exact updatedTableFallback_zero _ j x l hne
omit [DecidableEq Q₁] in
theorem selectedRightCompletion_zero (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(y : Q₂) (r : {i : Fin n // i ∉ selected} → Q₂) (hne : r j ≠ y) :
(selectedRightCompletion G strategy selected j s y).weight r = 0 := by
apply normalizeOr_weight_eq_zero_of_zero
· simp only [selectedRightRaw, ite_eq_right hne, zero_mul]
· exact updatedTableFallback_zero _ j y r hne
omit [DecidableEq Q₂] in
theorem selectedLeftCompletion_support (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(x : Q₁) (l : {i : Fin n // i ∉ selected} → Q₁)
(h : (selectedLeftCompletion G strategy selected j s x).weight l ≠ 0) : l j = x := by
by_contra hne
exact h (selectedLeftCompletion_zero G strategy selected j s x l hne)
omit [DecidableEq Q₁] in
theorem selectedRightCompletion_support (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(y : Q₂) (r : {i : Fin n // i ∉ selected} → Q₂)
(h : (selectedRightCompletion G strategy selected j s y).weight r ≠ 0) : r j = y := by
by_contra hne
exact h (selectedRightCompletion_zero G strategy selected j s y r hne)
def selectedCompletionScale (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(xy : Q₁ × Q₂) : ℝ :=
G.questions.weight xy * (∏ i : selected, G.questions.weight (s.1.1 i)) *
(if selectedLabelAccepts G selected s.1.1 s.1.2 then 1 else 0) /
G.selectedSuccess strategy selected
theorem selected_completion_factorization (G : Game Q₁ Q₂ A₁ A₂)
(strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂))
(selected : Finset (Fin n)) (j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(xy : Q₁ × Q₂)
(l : {i : Fin n // i ∉ selected} → Q₁)
(r : {i : Fin n // i ∉ selected} → Q₂) :
selectedCompletionScale G strategy selected j s xy *
selectedLeftRaw G strategy selected j s xy.1 l *
selectedRightRaw G strategy selected j s xy.2 r =
if (l j, r j) = xy then
partialRevealWeight G.questions j s.2 (fun i => (l i,r i)) *
selectedOutsideLikelihood G strategy selected s.1 (fun i => (l i,r i))
else 0 := by
rcases xy with ⟨x,y⟩
by_cases hl : l j = x <;> by_cases hr : r j = y
· rw [ite_eq_left (Prod.ext hl hr), partialRevealWeight_factorization]
cases hacc : selectedLabelAccepts G selected s.1.1 s.1.2 <;>
simp [selectedOutsideLikelihood, selectedLikelihood_factorization,
selectedCompletionScale, selectedLeftRaw, selectedRightRaw, hl, hr, hacc]
ring
· simp [selectedLeftRaw, selectedRightRaw, hl, hr, Prod.mk.injEq]
· simp [selectedLeftRaw, selectedRightRaw, hl, hr, Prod.mk.injEq]
· simp [selectedLeftRaw, selectedRightRaw, hl, hr, Prod.mk.injEq]
theorem selectedCommonLaw_completion_row_mass (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)
(j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(xy : Q₁ × Q₂) :
(selectedCommonLaw G strategy selected positive j).weight (s,xy) =
∑ lr : ({i : Fin n // i ∉ selected} → Q₁) ×
({i : Fin n // i ∉ selected} → Q₂),
selectedCompletionScale G strategy selected j s xy *
selectedLeftRaw G strategy selected j s xy.1 lr.1 *
selectedRightRaw G strategy selected j s xy.2 lr.2 := by
classical
change (∑ u, if u j = xy then partialRevealWeight G.questions j s.2 u *
selectedOutsideLikelihood G strategy selected s.1 u else 0) = _
rw [← (completionTupleEquiv (I := {i : Fin n // i ∉ selected})
(X := Q₁) (Y := Q₂)).sum_comp]
apply Finset.sum_congr rfl
intro u _
exact (selected_completion_factorization G strategy selected j s xy
(fun i => (u i).1) (fun i => (u i).2)).symm
theorem selected_completion_row_recombine (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)
(j : {i : Fin n // i ∉ selected})
(s : SelectedCommonData (Q₁ := Q₁) (Q₂ := Q₂) (A₁ := A₁) (A₂ := A₂) selected j)
(xy : Q₁ × Q₂)
(l : {i : Fin n // i ∉ selected} → Q₁)
(r : {i : Fin n // i ∉ selected} → Q₂) :
(selectedCommonLaw G strategy selected positive j).weight (s,xy) *
((selectedLeftCompletion G strategy selected j s xy.1).product
(selectedRightCompletion G strategy selected j s xy.2)).weight (l,r) =
if (l j,r j) = xy then
partialRevealWeight G.questions j s.2 (fun i => (l i,r i)) *
selectedOutsideLikelihood G strategy selected s.1 (fun i => (l i,r i))
else 0 := by
rw [selectedCommonLaw_completion_row_mass]
calc
_ = selectedCompletionScale G strategy selected j s xy *
selectedLeftRaw G strategy selected j s xy.1 l *
selectedRightRaw G strategy selected j s xy.2 r :=
factorized_completion_row
(selectedLeftRaw G strategy selected j s xy.1)
(selectedRightRaw G strategy selected j s xy.2)
(selectedLeftRaw_nonnegative G strategy selected j s xy.1)
(selectedRightRaw_nonnegative G strategy selected j s xy.2)
(updatedTableFallback (G.questions.pushforward Prod.fst) j xy.1)
(updatedTableFallback (G.questions.pushforward Prod.snd) j xy.2)
(selectedCompletionScale G strategy selected j s xy) (l,r)
_ = _ := selected_completion_factorization G strategy selected j s xy l r
end IndependentSetsGames.Foundations.Repetition
end
end OAI

Xet Storage Details

Size:
15.7 kB
·
Xet hash:
75401973c8929d34e4a6235c11aad2db25386a054fcea9455f40940156814147

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.