math / data /lean /OAI /Probability /CriticalPercolation /Entropy /BinaryDescriptor.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
7.23 kB
import Mathlib
import OAI.Probability.CriticalPercolation.Exploration.PrefixScoreNonneg
import OAI.Probability.CriticalPercolation.Entropy.BinaryWords
import OAI.Probability.CriticalPercolation.Entropy.BinaryMarks
namespace OAI
section
section
namespace CriticalPercolation.BinaryLaw
open scoped Classical
open FiniteProduct BondGraph BinaryInterpolation InterpolationForest FiniteEntropy ExactExposure
variable {V E : Type*}
abbrev FixedDescriptor (n : β„•) := Fin n β†’ Bool Γ— Bool Γ— Bool
lemma fixedDescriptor_card (n : β„•) : Fintype.card (FixedDescriptor n) = 8^n := by
simp only [FixedDescriptor,Fintype.card_fun,Fintype.card_prod,Fintype.card_bool,Fintype.card_fin]
noncomputable def descriptor (G : BondGraph V E) (d : β„•) (x : β„• β†’ V)
(n : β„•) (h : History E n) (Ο‰ : Set E) : FixedDescriptor n := fun i =>
(sides n h i, decide (marks n h i β‰  none), decide (i.val+2 ∈ activeNodes G d x n h Ο‰))
lemma descriptor_sides (G : BondGraph V E) (d : β„•) (x : β„• β†’ V)
(n : β„•) (h : History E n) (Ο‰ : Set E) (D : FixedDescriptor n)
(hD : descriptor G d x n h Ο‰ = D) : sides n h = fun i => (D i).1 := by
funext i
exact congrArg (fun D : FixedDescriptor n => (D i).1) hD
lemma sum_history_words [Fintype E] (n : β„•) (f : History E n β†’ ℝ) :
(βˆ‘ h, f h) = βˆ‘ b : Fin n β†’ Bool, βˆ‘ m : Fin n β†’ Option E, f (fromWords n b m) := by
rw [← (wordsEquiv (E := E) n).symm.sum_comp f,Fintype.sum_prod_type]
rfl
section Finite
variable [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]
variable (G : BondGraph V E) (order : List (LazyDFS.Dart V E)) (d : β„•) (x : β„• β†’ V)
variable (p : ℝ) (w : E β†’ Prop β†’ ℝ) (s n : β„•)
noncomputable def jointMass (z : (E β†’ Bool) Γ— History E n) : ℝ :=
FiniteProduct.density (QueryTree.bitWeight p) z.1 *
density G order d x p w (seed G w (x 0) (x d) s) n z.2 (configuration z.1)
lemma jointMass_nonneg (hp : p ∈ Set.Ioo 0 1) (h0 : βˆ€ e, w e False = 1-p)
(h1 : βˆ€ e, w e True = p) (hΞ΄ : 0 < prob w (endpointEvent G (x 0) (x d) s))
(z : (E β†’ Bool) Γ— History E n) : 0 ≀ jointMass G order d x p w s n z := by
exact mul_nonneg (FiniteProduct.density_nonneg (fun e b => (QueryTree.bitWeight_pos hp e b).le) _)
(density_nonneg G order d x p w _ hp h0 h1 (seed_nonneg G w _ _ s hΞ΄) n z.2 _)
lemma jointMass_normalized (ho : LazyDFS.Exhaustive G order) (hd : 2 ≀ d)
(hp : p ∈ Set.Ioo 0 1) (h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p)
{c : ℝ} (hc : 0<c)
(hconn : βˆ€ j k, j<k β†’ k≀d β†’ k-j<d β†’
c ≀ prob w (fun Ο‰ => (G.openGraph Ο‰).Reachable (x j) (x k)))
(hΞ΄ : 0 < prob w (endpointEvent G (x 0) (x d) s)) :
βˆ‘ z, jointMass G order d x p w s n z = 1 := by
have hw : QueryTree.bitWeight p = fun e (b : Bool) => w e (b = true) := by
funext e b
cases b <;> simp [QueryTree.bitWeight,h0,h1]
rw [Fintype.sum_prod_type,Finset.sum_comm]
simp only [jointMass]
have ht := endpoint_density_normalized G order ho hd x hp w h0 h1 hc hconn s hΞ΄ n
rw [← ht]
apply Finset.sum_congr rfl
intro h _
have he := expect_configuration w
(fun Ξ· : Set E => density G order d x p w (seed G w (x 0) (x d) s) n h Ξ·)
rw [← hw] at he
refine Eq.trans ?_ he
unfold expect
apply Finset.sum_congr
Β· ext f; simp only [Finset.mem_univ]
Β· intro f _; rfl
noncomputable def descriptorMass (D : FixedDescriptor n) : ℝ :=
pushMass (fun z : (E β†’ Bool) Γ— History E n => descriptor G d x n z.2 (configuration z.1))
(jointMass G order d x p w s n) D
lemma descriptorMass_sum :
(βˆ‘ D, descriptorMass G order d x p w s n D) = βˆ‘ z, jointMass G order d x p w s n z :=
pushMass_sum _ _
theorem exists_descriptor (hZ : βˆ‘ z, jointMass G order d x p w s n z = 1) :
βˆƒ D : FixedDescriptor n, (8:ℝ)^(- (n:β„€)) ≀ descriptorMass G order d x p w s n D := by
obtain ⟨D,hD,hmax⟩ := Finset.exists_max_image (Finset.univ : Finset (FixedDescriptor n))
(descriptorMass G order d x p w s n) Finset.univ_nonempty
have hs : 1 ≀ (8:ℝ)^n * descriptorMass G order d x p w s n D := by
calc
1 = βˆ‘ D', descriptorMass G order d x p w s n D' := (descriptorMass_sum G order d x p w s n).trans hZ |>.symm
_ ≀ βˆ‘ _D' : FixedDescriptor n, descriptorMass G order d x p w s n D :=
Finset.sum_le_sum (fun D' hD' => hmax D' hD')
_ = _ := by simp only [Finset.sum_const,Finset.card_univ,fixedDescriptor_card,nsmul_eq_mul,Nat.cast_pow,Nat.cast_ofNat]
refine ⟨D,?_⟩
rw [zpow_neg, zpow_natCast]
rw [← one_div]
exact (div_le_iffβ‚€ (pow_pos (by norm_num : (0:ℝ)<8) n)).mpr (by simpa only [mul_comm] using hs)
noncomputable def fixedMass (D : FixedDescriptor n) (z : (E β†’ Bool) Γ— (Fin n β†’ Option E)) : ℝ :=
let h := fromWords n (fun i => (D i).1) z.2
if descriptor G d x n h (configuration z.1) = D then
jointMass G order d x p w s n (z.1,h) else 0
lemma fixedMass_sum (D : FixedDescriptor n) :
(βˆ‘ z, fixedMass G order d x p w s n D z) = descriptorMass G order d x p w s n D := by
unfold descriptorMass pushMass
conv_rhs => rw [Fintype.sum_prod_type]
simp_rw [sum_history_words]
rw [Fintype.sum_prod_type]
apply Finset.sum_congr rfl
intro Ο‰ _
symm
apply (Finset.sum_eq_single (fun i => (D i).1) ?_ ?_).trans
Β· apply Finset.sum_congr rfl
intro m _
unfold fixedMass
dsimp only
split_ifs <;> rfl
Β· intro b _ hb
apply Finset.sum_eq_zero
intro m _
have hne : descriptor G d x n (fromWords n b m) (configuration Ο‰) β‰  D := by
intro he
have hs := descriptor_sides G d x n _ _ D he
rw [sides_fromWords] at hs
exact hb hs
rw [ite_eq_right hne]
Β· simp
noncomputable def conditionedMass (D : FixedDescriptor n)
(z : (E β†’ Bool) Γ— (Fin n β†’ Option E)) : ℝ :=
fixedMass G order d x p w s n D z / descriptorMass G order d x p w s n D
lemma conditionedMass_normalized (D : FixedDescriptor n)
(hD : 0 < descriptorMass G order d x p w s n D) :
βˆ‘ z, conditionedMass G order d x p w s n D z = 1 := by
simp only [conditionedMass,← Finset.sum_div,fixedMass_sum,div_self hD.ne']
lemma conditionedMass_nonneg (hp : p ∈ Set.Ioo 0 1) (h0 : βˆ€ e, w e False = 1-p)
(h1 : βˆ€ e, w e True = p) (hΞ΄ : 0 < prob w (endpointEvent G (x 0) (x d) s))
(D : FixedDescriptor n) (hD : 0 < descriptorMass G order d x p w s n D)
(z : (E β†’ Bool) Γ— (Fin n β†’ Option E)) : 0 ≀ conditionedMass G order d x p w s n D z := by
apply div_nonneg _ hD.le
unfold fixedMass
dsimp only
split_ifs
Β· exact jointMass_nonneg G order d x p w s n hp h0 h1 hΞ΄ _
Β· rfl
lemma conditionedMass_support (D : FixedDescriptor n)
(z : (E β†’ Bool) Γ— (Fin n β†’ Option E))
(hz : conditionedMass G order d x p w s n D z β‰  0) :
let h := fromWords n (fun i => (D i).1) z.2
descriptor G d x n h (configuration z.1) = D ∧
density G order d x p w (seed G w (x 0) (x d) s) n h (configuration z.1) β‰  0 := by
have hf := (div_ne_zero_iff.mp hz).1
unfold fixedMass at hf
dsimp only at hf ⊒
split_ifs at hf with ht
· exact ⟨ht,(mul_ne_zero_iff.mp hf).2⟩
Β· exact (hf rfl).elim
end Finite
end CriticalPercolation.BinaryLaw
end
end
end OAI