cfahlgren1/math / lean /ComparatorChallenges /ThreeStateTreeClauses.lean
cfahlgren1's picture
download
raw
3.79 kB
import Mathlib
namespace OAI
noncomputable section
open scoped BigOperators ENNReal NNReal
open Filter
namespace ThreeState.TreeClauses
abbrev Spin := Fin 3
def Admissible (lam : ℝ) : Prop := -(1 / 2 : ℝ) ≤ lam ∧ lam ≤ 1
def channelWeight (lam : ℝ) (i j : Spin) : ℝ :=
if i = j then (1 + 2 * lam) / 3 else (1 - lam) / 3
lemma channelWeight_nonneg {lam : ℝ} (hlam : Admissible lam) (i j : Spin) :
0 ≤ channelWeight lam i j := by
unfold channelWeight
split_ifs <;> dsimp [Admissible] at hlam <;> linarith [hlam.1, hlam.2]
lemma channelWeight_sum (lam : ℝ) (i : Spin) : ∑ j, channelWeight lam i j = 1 := by
fin_cases i <;> simp [channelWeight, Fin.sum_univ_three] <;> ring
def channel (lam : ℝ) (hlam : Admissible lam) (i : Spin) : PMF Spin :=
PMF.ofFintype (fun j ↦ ENNReal.ofReal (channelWeight lam i j)) (by
rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ ↦ channelWeight_nonneg hlam i j),
channelWeight_sum]
norm_num)
def Observation : ℕ → Type
| 0 => Spin
| n + 1 => Multiset (Observation n)
def iidList {α : Type} (p : PMF α) : ℕ → PMF (List α)
| 0 => PMF.pure []
| n + 1 => p.bind fun x ↦ (iidList p n).map (List.cons x)
def observationLaw (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) :
(ℓ : ℕ) → Spin → PMF (Observation ℓ)
| 0, i => PMF.pure i
| ℓ + 1, i => offspring.bind fun n ↦
(iidList ((channel lam hlam i).bind (observationLaw lam hlam offspring ℓ)) n).map
(fun xs ↦ (xs : Multiset (Observation ℓ)))
def jointWeight (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ)
(ℓ : ℕ) (i : Spin) (o : Observation ℓ) : ℝ≥0∞ :=
(1 / 3 : ℝ≥0∞) * observationLaw lam hlam offspring ℓ i o
def marginalWeight (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ)
(ℓ : ℕ) (o : Observation ℓ) : ℝ≥0∞ :=
∑ i, jointWeight lam hlam offspring ℓ i o
def posterior (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ)
(ℓ : ℕ) (o : Observation ℓ) (i : Spin) : ℝ :=
(jointWeight lam hlam offspring ℓ i o / marginalWeight lam hlam offspring ℓ o).toReal
def advantage (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : ℝ :=
∑' o : Observation ℓ, (marginalWeight lam hlam offspring ℓ o).toReal *
((∑ i : Spin, |posterior lam hlam offspring ℓ o i - (1 / 3 : ℝ)|) / 2)
def Reconstructs (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : Prop :=
∃ a : ℝ, 0 < a ∧ Tendsto (advantage lam hlam offspring) atTop (nhds a)
namespace Probability
def poissonWeight (rate : ℝ) (count : ℕ) : ℝ :=
Real.exp (-rate) * rate ^ count / (count.factorial : ℝ)
lemma poissonWeight_nonneg {rate : ℝ} (hrate : 0 ≤ rate) (count : ℕ) :
0 ≤ poissonWeight rate count := by
unfold poissonWeight
positivity
lemma poissonWeight_mass (rate : ℝ≥0) : HasSum (poissonWeight rate) 1 :=
ProbabilityTheory.hasSum_one_poissonMeasure rate
def _root_.OAI.ThreeState.TreeClauses.poissonPMF (rate : ℝ≥0) : PMF ℕ := by
refine ⟨fun count ↦ ENNReal.ofReal (poissonWeight rate count), ?_⟩
apply ENNReal.hasSum_coe.mpr
rw [← Real.toNNReal_one]
exact (poissonWeight_mass rate).toNNReal (poissonWeight_nonneg rate.coe_nonneg)
end Probability
end ThreeState.TreeClauses
open scoped Topology
namespace ThreeState.TreeClauses.Tree
theorem regular_reconstructs_above_KS (b : ℕ) (lam : ℝ) (hlam : Admissible lam)
(hKS : 1 < (b:ℝ)*lam^2) : Reconstructs lam hlam (PMF.pure b) := by
sorry
theorem poisson_reconstructs_above_KS (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam)
(hKS : 1 < (d:ℝ)*lam^2) : Reconstructs lam hlam (poissonPMF d) := by
sorry
end ThreeState.TreeClauses.Tree
end
end OAI

Xet Storage Details

Size:
3.79 kB
·
Xet hash:
b9e125e654564e83682165ad1000dddbcce953816f52e1ea19913d8932e0bee6

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