File size: 5,376 Bytes
f61e547 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | import OAI.Probability.DirectionalWalk.MarkedSums
namespace OAI
open MeasureTheory ProbabilityTheory Filter Preorder
open scoped ENNReal BigOperators Topology
namespace DirectionalZeroOne
open scoped Classical
noncomputable def countWindowLaw (k n : ℕ) : Measure ℕ :=
(n : ℝ≥0∞)⁻¹ • ∑ i : Fin n, Measure.dirac (k+i)
instance countWindowLaw_probability (k n : ℕ) [NeZero n] : IsProbabilityMeasure (countWindowLaw k n) := by
constructor
simp only [countWindowLaw,Measure.smul_apply,smul_eq_mul,Measure.finsetSum_apply,measure_univ,
Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one]
exact ENNReal.inv_mul_cancel (by exact_mod_cast NeZero.ne n) (by finiteness)
lemma countWindowLaw_atom (k n r : ℕ) : countWindowLaw k n {r} =
(if k ≤ r ∧ r < k+n then (n : ℝ≥0∞)⁻¹ else 0) := by
classical
simp only [countWindowLaw,Measure.smul_apply,smul_eq_mul,Measure.finsetSum_apply,
Measure.dirac_apply' _ (measurableSet_singleton _),Set.indicator_apply,Set.mem_singleton_iff,Pi.one_apply]
by_cases h : k ≤ r ∧ r < k+n
· rw [ite_eq_left h]
let i : Fin n := ⟨r-k,by omega⟩
rw [Finset.sum_eq_single i]
· simp only [show k+(i : ℕ) = r by dsimp [i];omega,ite_eq_left,mul_one]
· intro j _ hji
apply ite_eq_right
intro hj
apply hji
apply Fin.ext
change (j : ℕ) = r-k
omega
· simp
· rw [ite_eq_right h]
have hz : ∑ i : Fin n, (if k+(i : ℕ) = r then (1 : ℝ≥0∞) else 0) = 0 := by
apply Finset.sum_eq_zero
intro i _
apply ite_eq_right
intro hi
exact h ⟨by omega,by omega⟩
rw [hz,mul_zero]
lemma countWindowLaw_ae (k n : ℕ) : ∀ᵐ r ∂countWindowLaw k n, k ≤ r ∧ r < k+n := by
filter_upwards [ae_atom_pos (countWindowLaw k n)] with r hr
by_contra hn
rw [countWindowLaw_atom,ite_eq_right hn] at hr
exact hr rfl
lemma countWindowLaw_info (k n : ℕ) : atomInfo (countWindowLaw k n) =ᵐ[countWindowLaw k n]
fun _ => Real.log n := by
filter_upwards [countWindowLaw_ae k n] with r hr
simp only [atomInfo,measureReal_def,countWindowLaw_atom,ite_eq_left hr,ENNReal.toReal_inv,
ENNReal.toReal_natCast,Real.log_inv,neg_neg]
lemma countWindowLaw_entropy (k n : ℕ) [NeZero n] :
Integrable (atomInfo (countWindowLaw k n)) (countWindowLaw k n) ∧
discreteEntropy (countWindowLaw k n) = Real.log n := by
constructor
· exact (integrable_const _).congr (countWindowLaw_info k n).symm
· change (∫ r, atomInfo (countWindowLaw k n) r ∂countWindowLaw k n) = _
rw [integral_congr_ae (countWindowLaw_info k n)]
simp
lemma convolution_ae_bounds (μ ν : Measure ℕ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]
(a b c d : ℕ) (hμ : ∀ᵐ x ∂μ, a ≤ x ∧ x ≤ b) (hν : ∀ᵐ y ∂ν, c ≤ y ∧ y ≤ d) :
∀ᵐ z ∂μ.conv ν, a+c ≤ z ∧ z ≤ b+d := by
rw [Measure.conv,ae_map_iff (measurable_of_countable _).aemeasurable (Set.to_countable _).measurableSet]
apply (Measure.ae_prod_iff_ae_ae (Set.to_countable _).measurableSet).mpr
filter_upwards [hμ] with x hx
filter_upwards [hν] with y hy
exact ⟨Nat.add_le_add hx.1 hy.1,Nat.add_le_add hx.2 hy.2⟩
section MarkedWindows
variable {G : Type*} [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup G]
{α : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α]
lemma nthCommonLaw_marked (ν : Bool → Measure α) [∀ b, IsProbabilityMeasure (ν b)]
(L : Bool → α → ℕ) (hL : ∀ b, ∀ᵐ a ∂ν b, 0 < L b a)
(he : ∀ᵐ Z ∂twoTapeLaw ν, ∃ H, 0 < H ∧ Z ∈ commonCut L H)
(D : Bool → α → G) (r : ℕ) :
(nthCommonLaw ν L r).map (fun a => (listCommonCount L a,pairTotal D a)) =
(sumLaw (commonGapLaw ν L D) r).map (fun x => (r,x)) := by
have hc : ∀ᵐ a ∂nthCommonLaw ν L r, listCommonCount L a = r := by
classical
filter_upwards [ae_atom_pos (nthCommonLaw ν L r)] with a ha
by_contra hn
rw [nthCommonLaw_atom ν L hL he,ite_eq_right (fun h => hn h.2)] at ha
exact ha rfl
rw [← nthCommonLaw_pairTotal ν L hL he D r,Measure.map_map (measurable_of_countable _)
(measurable_of_countable _)]
apply Measure.map_congr
filter_upwards [hc] with a ha
exact Prod.ext ha rfl
lemma windowCommonLaw_marked (ν : Bool → Measure α) [∀ b, IsProbabilityMeasure (ν b)]
(L : Bool → α → ℕ) (hL : ∀ b, ∀ᵐ a ∂ν b, 0 < L b a)
(he : ∀ᵐ Z ∂twoTapeLaw ν, ∃ H, 0 < H ∧ Z ∈ commonCut L H)
(D : Bool → α → G) (k n : ℕ) :
(windowCommonLaw ν L k n).map (fun a => (listCommonCount L a,pairTotal D a)) =
markedSumLaw (commonGapLaw ν L D) (countWindowLaw k n) := by
simp only [windowCommonLaw,Measure.map_smul _ (measurable_of_countable _).aemeasurable]
rw [Measure.map_finset_sum' (measurable_of_countable _).aemeasurable]
simp_rw [nthCommonLaw_marked ν L hL he D]
conv_rhs => unfold markedSumLaw countWindowLaw
rw [Measure.compProd_smul_left]
congr 1
conv_rhs => rw [← Measure.sum_fintype,Measure.compProd_sum_left,Measure.sum_fintype]
apply Finset.sum_congr rfl
intro i _
apply Measure.ext
intro s hs
rw [Measure.dirac_compProd_apply hs,Measure.map_apply (measurable_of_countable _) hs]
rfl
end MarkedWindows
end DirectionalZeroOne
end OAI
|