math / data /lean /OAI /Probability /CriticalPercolation /Exploration /ClosedPivotWeight.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.36 kB
import Mathlib
import OAI.Probability.CriticalPercolation.Exploration.QueryDelta
import OAI.Probability.CriticalPercolation.ProductMeasure.ExpectClosedFlip
namespace OAI
section
section
open Set MeasureTheory ProbabilityTheory
open Set
open scoped BigOperators
open scoped Classical
namespace CriticalPercolation.SearchTree
open scoped Classical
open FiniteProduct LazyDFS
variable {E R : Type*} [Fintype E] [DecidableEq E]
noncomputable def closedPivotWeight (T : SearchTree E R) (p : ℝ) (F : Set E β†’ Prop)
(w : E β†’ Prop β†’ ℝ) (Ο‰ : Set E) (e : E) : ℝ :=
if ¬ω e ∧ openPivot F e (Function.update Ο‰ e True) then p*T.queryDelta F w Ο‰ e else 0
theorem contact_flip_identity (T : SearchTree E R) (used : Finset E) (hT : T.Valid used)
{p : ℝ} (hp : p ∈ Set.Ioo 0 1) (F : Set E β†’ Prop) (w : E β†’ Prop β†’ ℝ)
(hw : βˆ€ e, βˆ‘ b, w e b = 1) (h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p)
(ψ : ℝ β†’ ℝ) :
expect w (fun Ο‰ => βˆ‘ e, T.closedPivotWeight p F w Ο‰ e *
ψ (T.score p F w (Function.update Ο‰ e True))) =
expect w (fun Ο‰ => T.score p F w Ο‰ * ψ (T.score p F w Ο‰)) := by
have hsingle (e : E) :
expect w (fun Ο‰ => T.closedPivotWeight p F w Ο‰ e *
ψ (T.score p F w (Function.update Ο‰ e True))) =
expect w (fun Ο‰ => (if openPivot F e Ο‰ then (1-p)*T.queryDelta F w Ο‰ e else 0) *
ψ (T.score p F w Ο‰)) := by
have h := expect_closed_flip_decidable w hw e hp (h0 e) (h1 e)
(fun Ο‰ => (if openPivot F e Ο‰ then T.queryDelta F w Ο‰ e else 0) * ψ (T.score p F w Ο‰))
convert h using 1
Β· congr 1
funext Ο‰
let Οƒ : Set E := Ο‰
change T.closedPivotWeight p F w Οƒ e * ψ (T.score p F w (Function.update Οƒ e True)) =
if ¬σ e then p*((if openPivot F e (Function.update Οƒ e True) then
T.queryDelta F w (Function.update Οƒ e True) e else 0) *
ψ (T.score p F w (Function.update Οƒ e True))) else 0
rw [queryDelta_update T F w Οƒ e True]
simp only [closedPivotWeight]
by_cases hc : Οƒ e <;>
by_cases hpiv : openPivot F e (Function.update Οƒ e True) <;> simp [hc,hpiv,mul_assoc]
Β· congr 1
funext Ο‰
by_cases hpiv : openPivot F e Ο‰
Β· simp only [ite_eq_left hpiv,ite_eq_left hpiv.1]; ring
Β· simp only [ite_eq_right hpiv,mul_zero,zero_mul,ite_self]
rw [expect_sum]
simp_rw [hsingle]
rw [← expect_sum]
congr 1
funext Ο‰
rw [← Finset.sum_mul]
exact congrArg (fun x => x * ψ (T.score p F w Ο‰))
(score_eq_queryDelta_sum T used hT p F w Ο‰).symm
end CriticalPercolation.SearchTree
namespace CriticalPercolation.SearchTree
open scoped Classical
open FiniteProduct LazyDFS
variable {E R : Type*} [Fintype E] [DecidableEq E]
noncomputable def prefixScore (T : SearchTree E R) (p : ℝ) (F : Set E β†’ Prop)
(w : E β†’ Prop β†’ ℝ) (Ο‰ : Set E) (e : E) : ℝ :=
match T with
| .done _ => 0
| .ask f l r => (if openPivot F f Ο‰ then (1-p)*delta w F f else 0) +
if e = f then 0 else
if Ο‰ f then r.prefixScore p F (pin w f True) Ο‰ e
else l.prefixScore p F (pin w f False) Ο‰ e
lemma prefixScore_le (T : SearchTree E R) (used : Finset E) (hT : T.Valid used)
{p : ℝ} (hp : p ∈ Set.Ioo 0 1) (F : Set E β†’ Prop)
(hF : βˆ€ s t, s βŠ† t β†’ F s β†’ F t) (w : E β†’ Prop β†’ ℝ)
(hw : βˆ€ e, βˆ‘ b, w e b = 1) (hn : βˆ€ e b, 0 ≀ w e b)
(hf : Fresh w p used) (Ο‰ : Set E) (e : E) :
T.prefixScore p F w Ο‰ e ≀ T.score p F w Ο‰ := by
induction T generalizing used w with
| done _ => exact le_rfl
| ask f l r hl hr =>
simp only [prefixScore,score]
apply add_le_add_right
by_cases he : e = f
Β· rw [ite_eq_left he]
by_cases ho : Ο‰ f
Β· rw [ite_eq_left ho]
exact score_nonneg r _ hT.2.2 hp F hF _ (pin_normalized w hw f True)
(pin_nonneg w hn f True) (fresh_pin w p used hf f True) Ο‰
Β· rw [ite_eq_right ho]
exact score_nonneg l _ hT.2.1 hp F hF _ (pin_normalized w hw f False)
(pin_nonneg w hn f False) (fresh_pin w p used hf f False) Ο‰
Β· rw [ite_eq_right he]
by_cases ho : Ο‰ f
Β· rw [ite_eq_left ho,ite_eq_left ho]
exact hr _ hT.2.2 _ (pin_normalized w hw f True) (pin_nonneg w hn f True)
(fresh_pin w p used hf f True)
Β· rw [ite_eq_right ho,ite_eq_right ho]
exact hl _ hT.2.1 _ (pin_normalized w hw f False) (pin_nonneg w hn f False)
(fresh_pin w p used hf f False)
lemma closedPivotWeight_nonneg (T : SearchTree E R) (used : Finset E) (hT : T.Valid used)
{p : ℝ} (hp : p ∈ Set.Ioo 0 1) (F : Set E β†’ Prop)
(hF : βˆ€ s t, s βŠ† t β†’ F s β†’ F t) (w : E β†’ Prop β†’ ℝ)
(hw : βˆ€ e, βˆ‘ b, w e b = 1) (hn : βˆ€ e b, 0 ≀ w e b)
(hf : Fresh w p used) (Ο‰ : Set E) (e : E) : 0 ≀ T.closedPivotWeight p F w Ο‰ e := by
unfold closedPivotWeight
split_ifs
Β· exact mul_nonneg hp.1.le (queryDelta_nonneg T used hT hp F hF w hw hn hf Ο‰ e)
Β· exact le_rfl
theorem marked_prefix_bound (T : SearchTree E R) (used : Finset E) (hT : T.Valid used)
{p : ℝ} (hp : p ∈ Set.Ioo 0 1) (F : Set E β†’ Prop)
(hF : βˆ€ s t, s βŠ† t β†’ F s β†’ F t) (w : E β†’ Prop β†’ ℝ)
(hw : βˆ€ e, βˆ‘ b, w e b = 1) (hn : βˆ€ e b, 0 ≀ w e b)
(hf : Fresh w p used) (h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p) :
expect w (fun Ο‰ => βˆ‘ e, T.closedPivotWeight p F w Ο‰ e *
(1 + T.prefixScore p F w (Function.update Ο‰ e True) e)) ≀
expect w (T.score p F w) + expect w (fun Ο‰ => (T.score p F w Ο‰)^2) := by
calc
_ ≀ expect w (fun Ο‰ => βˆ‘ e, T.closedPivotWeight p F w Ο‰ e *
(1 + T.score p F w (Function.update Ο‰ e True))) := by
apply expect_mono hn
intro Ο‰
apply Finset.sum_le_sum
intro e _
exact mul_le_mul_of_nonneg_left
(add_le_add_right (prefixScore_le T used hT hp F hF w hw hn hf _ e) 1)
(closedPivotWeight_nonneg T used hT hp F hF w hw hn hf Ο‰ e)
_ = expect w (fun Ο‰ => T.score p F w Ο‰ * (1 + T.score p F w Ο‰)) :=
contact_flip_identity T used hT hp F w hw h0 h1 (fun x => 1+x)
_ = expect w (fun Ο‰ => T.score p F w Ο‰ + (T.score p F w Ο‰)^2) := by
congr 1
funext Ο‰
ring
_ = _ := expect_add w _ _
end CriticalPercolation.SearchTree
end
end
end OAI