math / data /lean /OAI /Probability /CriticalPercolation /Entropy /BinaryReferenceLikelihood.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.72 kB
import Mathlib
import OAI.Probability.CriticalPercolation.Entropy.RecursiveLikelihood
import OAI.Probability.CriticalPercolation.Entropy.BinaryLikelihood
namespace OAI
section
section
noncomputable section
namespace CriticalPercolation.BinaryLaw
open scoped Classical
open FiniteProduct BondGraph BinaryInterpolation ExactExposure FiniteEntropy MarkedBits SearchTree
variable {V E : Type*} [Fintype V] [Fintype E]
local instance refLikelihoodFinDec (n : β„•) : DecidableEq (Fin n) := Classical.decEq _
noncomputable def recorded (n : β„•) (D : FixedDescriptor n) (z : (E β†’ Bool) Γ— (Fin n β†’ Option E)) :
(E β†’ Bool) Γ— (Fin n β†’ Option E) Γ— (Fin n β†’ Option E) :=
(stage n D z.1 z.2 n,masked (activeSteps n D) z.2,masked (activeSteps n D)ᢜ z.2)
variable (G : BondGraph V E) (order : List (LazyDFS.Dart V E)) (d : β„•) (x : β„• β†’ V)
variable (p : ℝ) (w : E β†’ Prop β†’ ℝ) (n : β„•) (D : FixedDescriptor n)
def inverseLog (Ο‰ : E β†’ Bool) (m : Fin n β†’ Option E) : ℝ :=
2*(βˆ‘ i ∈ activeSteps n D, Real.log (1+selectedCost G order d x p w n D i Ο‰ (m i))) +
logContactMass (scheduleWeight G order d x p w n (fun j => (D j).1)) (configuration Ο‰)
lemma inversePenalty_product (hp : p ∈ Set.Ioo 0 1)
(h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p)
(Ο‰ : E β†’ Bool) (m : Fin n β†’ Option E) :
(∏ i, inversePenalty G order d x p w n D i Ο‰ (m i)) =
Real.exp (inverseLog G order d x p w n D Ο‰ m) := by
have hc (i : Fin n) : 0 < 1+selectedCost G order d x p w n D i Ο‰ (m i) := by
have hn := (selected_nonneg G order d x p w n D hp h0 h1 i Ο‰ (m i)).2
linarith
have he (i : Fin n) : (if i ∈ activeSteps n D then
(1+selectedCost G order d x p w n D i Ο‰ (m i))^2 else 1) =
Real.exp (if i ∈ activeSteps n D then
2*Real.log (1+selectedCost G order d x p w n D i Ο‰ (m i)) else 0) := by
split_ifs
Β· rw [two_mul,Real.exp_add,Real.exp_log (hc i),pow_two]
Β· exact Real.exp_zero.symm
simp only [inversePenalty,Finset.prod_mul_distrib,he,← Real.exp_sum]
change _ * (∏ i, max 1 (βˆ‘ a, scheduleWeight G order d x p w n
(fun j => (D j).1) i (configuration Ο‰) a)) = _
rw [← exp_logContactMass (scheduleWeight G order d x p w n (fun j => (D j).1))
(configuration Ο‰),← Real.exp_add]
congr 1
simp only [inverseLog,logContactMass]
rw [← Finset.sum_filter,← Finset.mul_sum]
simp only [Finset.filter_mem_eq_inter,Finset.univ_inter]
lemma supported_reference_dominance (s : β„•) (hp : p ∈ Set.Ioo 0 1)
(h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p)
(Ο‰ : E β†’ Bool) (m : Fin n β†’ Option E)
(hz : conditionedMass G order d x p w s n D (Ο‰,m) β‰  0) :
FiniteProduct.density (QueryTree.bitWeight p) Ο‰ *
(∏ i, scheduleWeight G order d x p w n (fun j => (D j).1) i (configuration Ο‰) (m i)) ≀
inverseReference G order d x p w n D (recorded n D (Ο‰,m)) *
Real.exp (inverseLog G order d x p w n D Ο‰ m) := by
let m' : β„• β†’ Option E := fun j => if hj : j<n then masked (activeSteps n D) m ⟨j,hj⟩ else none
have hm : (fun i : Fin n => m' i.val) = masked (activeSteps n D) m := by
funext i
simp only [m',dite_eq_left i.isLt]
have hu : βˆ€ j<n, inverseUpdate (E := E) n D j (stage n D Ο‰ m (j+1)) (m' j) = stage n D Ο‰ m j := by
intro j hj
simpa only [m',dite_eq_left hj] using supported_inverse_update G order d x p w s n D Ο‰ m hz ⟨j,hj⟩
have hh := ReverseReference.joint_trajectory_dominance
(FiniteProduct.density (QueryTree.bitWeight p) : (E β†’ Bool) β†’ ℝ)
(inverseKernel G order d x p w n D) (inverseUpdate (E := E) n D) n
(inactiveKernel G order d x p w n D) (stage n D Ο‰ m) m' (masked (activeSteps n D)ᢜ m)
(fun i => scheduleWeight G order d x p w n (fun j => (D j).1) i (configuration Ο‰) (m i))
(fun i => inversePenalty G order d x p w n D i Ο‰ (m i)) hu
(fun i => scheduleWeight_nonneg G order d x p w hp h0 h1 n _ i _ _)
(fun i => mul_nonneg (mul_nonneg
(inverseKernel_nonneg G order d x p w n D hp h0 h1 _ _ _)
(inactiveKernel_nonneg G order d x p w n D hp h0 h1 _ _ _))
(inversePenalty_nonneg G order d x p w n D _ _ _))
(fun i => by
simpa only [stage_zero,m',dite_eq_left i.isLt] using
supported_step_likelihood G order d x p w n D s hp h0 h1 Ο‰ m hz i)
rw [hm,stage_zero,inversePenalty_product G order d x p w n D hp h0 h1 Ο‰ m] at hh
exact hh
lemma conditioned_reference_density_le (s : β„•) (hd : 0<d) (hp : p ∈ Set.Ioo 0 1)
(h0 : βˆ€ e, w e False = 1-p) (h1 : βˆ€ e, w e True = p)
{c : ℝ} (hc : 0<c) (hc1 : c≀1)
(hconn : βˆ€ j, 0<j β†’ j<d β†’ c ≀ prob w (fun Ο‰ => (G.openGraph Ο‰).Reachable (x 0) (x j)))
(hΞ΄ : 0 < prob w (endpointEvent G (x 0) (x d) s))
(hD : 0 < descriptorMass G order d x p w s n D)
(z : (E β†’ Bool) Γ— (Fin n β†’ Option E)) :
conditionedMass G order d x p w s n D z ≀
inverseReference G order d x p w n D (recorded n D z) *
Real.exp (constructionCost G order d x p w c s n D + inverseLog G order d x p w n D z.1 z.2) := by
by_cases hz : conditionedMass G order d x p w s n D z = 0
Β· rw [hz]
exact mul_nonneg (inverseReference_nonneg G order d x p w n D hp h0 h1 _) (Real.exp_pos _).le
Β· have hh := mul_le_mul_of_nonneg_left
(supported_reference_dominance G order d x p w n D s hp h0 h1 z.1 z.2 hz)
(Real.exp_pos (constructionCost G order d x p w c s n D)).le
calc
_ ≀ _ := conditionedMass_density_le G order d x p w hd hp h0 h1 hc hc1 hconn s n D hΞ΄ hD z
_ ≀ _ := by simpa only [Real.exp_add,mul_assoc,mul_left_comm,mul_comm] using hh
end CriticalPercolation.BinaryLaw
end
end
end
end OAI