File size: 14,095 Bytes
b317718 | 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | import OAI.Probability.InvariantIsing.Arrays.NSpinTensorAncestorInput
namespace OAI
/-! Conditional independent spin residuals at two sampled cascade leaves. -/
noncomputable section
open MeasureTheory ProbabilityTheory IsingPerceptron
open scoped BigOperators ENNReal NNReal
namespace InvariantIsing
def spinLeafTerminal {N n : ℕ} (H : Spin N × LabeledLeaf n → ℝ) (α : LabeledLeaf n) : ℝ :=
finiteLogIntegral (uniformSpinPrior N : Measure (Spin N)) (fun σ => H (σ, α))
lemma exp_spinLeafTerminal {N n : ℕ} (H : Spin N × LabeledLeaf n → ℝ) (α : LabeledLeaf n) :
Real.exp (spinLeafTerminal H α) =
referencePartition (uniformSpinPrior N : Measure (Spin N)) (fun σ => H (σ, α)) := by
exact Real.exp_log (integral_exp_pos (Integrable.of_finite))
lemma spinLeafPartition_eq {N n : ℕ} (ν : Measure (LabeledLeaf n)) [IsProbabilityMeasure ν]
(H : Spin N × LabeledLeaf n → ℝ)
(he : Integrable (fun x => Real.exp (H x)) ((uniformSpinPrior N : Measure (Spin N)).prod ν)) :
referencePartition ((uniformSpinPrior N : Measure (Spin N)).prod ν) H =
referencePartition ν (spinLeafTerminal H) := by
unfold referencePartition
rw [integral_prod_symm _ he]
apply integral_congr_ae
exact ae_of_all _ fun α => (exp_spinLeafTerminal H α).symm
lemma spinLeafTerminal_exp_integrable {N n : ℕ} (ν : Measure (LabeledLeaf n)) [IsProbabilityMeasure ν]
(H : Spin N × LabeledLeaf n → ℝ)
(he : Integrable (fun x => Real.exp (H x)) ((uniformSpinPrior N : Measure (Spin N)).prod ν)) :
Integrable (fun α => Real.exp (spinLeafTerminal H α)) ν := by
convert he.integral_prod_right using 1
ext α
exact exp_spinLeafTerminal H α
lemma spinLeafGibbs_singleton {N n : ℕ} (ν : Measure (LabeledLeaf n)) [IsProbabilityMeasure ν]
(H : Spin N × LabeledLeaf n → ℝ)
(he : Integrable (fun x => Real.exp (H x)) ((uniformSpinPrior N : Measure (Spin N)).prod ν))
(σ : Spin N) (α : LabeledLeaf n) :
gibbsProbability ((uniformSpinPrior N : Measure (Spin N)).prod ν) H {(σ, α)} =
gibbsProbability ν (spinLeafTerminal H) {α} *
gibbsProbability (uniformSpinPrior N : Measure (Spin N)) (fun τ => H (τ, α)) {σ} := by
have hi := spinLeafTerminal_exp_integrable ν H he
have hs : Integrable (fun τ : Spin N => Real.exp (H (τ, α)))
(uniformSpinPrior N : Measure (Spin N)) := Integrable.of_finite
have hZ : 0 < referencePartition ν (spinLeafTerminal H) := integral_exp_pos hi
have hS : 0 < referencePartition (uniformSpinPrior N : Measure (Spin N)) (fun τ => H (τ, α)) :=
integral_exp_pos hs
rw [gibbsProbability_eq_tilted _ _ he, gibbsProbability_eq_tilted _ _ hi,
gibbsProbability_eq_tilted _ _ hs, tilted_singleton, tilted_singleton, tilted_singleton,
← Set.singleton_prod_singleton, Measure.prod_prod,
spinLeafPartition_eq ν H he, exp_spinLeafTerminal]
have hc :
ENNReal.ofReal (Real.exp (H (σ, α)) / referencePartition ν (spinLeafTerminal H)) =
ENNReal.ofReal
(referencePartition (uniformSpinPrior N : Measure (Spin N)) (fun τ => H (τ, α)) /
referencePartition ν (spinLeafTerminal H)) *
ENNReal.ofReal
(Real.exp (H (σ, α)) /
referencePartition (uniformSpinPrior N : Measure (Spin N)) (fun τ => H (τ, α))) := by
rw [← ENNReal.ofReal_mul (div_nonneg hS.le hZ.le)]
congr 1
field_simp
rw [hc]
ac_rfl
def spinLeafPairResidualKernel {N n : ℕ} (H : Spin N × LabeledLeaf n → ℝ) :
Kernel (Fin 2 → LabeledLeaf n) (Fin 2 → Spin N) :=
⟨fun α => Measure.pi (fun i : Fin 2 =>
gibbsProbability (uniformSpinPrior N : Measure (Spin N)) (fun σ => H (σ, α i))),
measurable_of_countable _⟩
instance spinLeafPairResidualKernel_markov {N n : ℕ} (H : Spin N × LabeledLeaf n → ℝ) :
IsMarkovKernel (spinLeafPairResidualKernel H) :=
⟨fun _ => inferInstanceAs (IsProbabilityMeasure (Measure.pi _))⟩
def spinLeafPairJoin {N n : ℕ}
(p : (Fin 2 → LabeledLeaf n) × (Fin 2 → Spin N)) : Fin 2 → Spin N × LabeledLeaf n :=
fun i => (p.2 i, p.1 i)
lemma measurable_spinLeafPairJoin {N n : ℕ} :
Measurable (spinLeafPairJoin (N := N) (n := n)) := by
unfold spinLeafPairJoin
fun_prop
/-- Conditional on the two leaf labels, the spin residual draws are
independent, including when the leaf labels coincide. -/
theorem spinLeafPairLaw {N n : ℕ} (ν : Measure (LabeledLeaf n)) [IsProbabilityMeasure ν]
(H : Spin N × LabeledLeaf n → ℝ)
(he : Integrable (fun x => Real.exp (H x)) ((uniformSpinPrior N : Measure (Spin N)).prod ν)) :
((Measure.pi (fun _ : Fin 2 => gibbsProbability ν (spinLeafTerminal H))) ⊗ₘ
spinLeafPairResidualKernel H).map spinLeafPairJoin =
Measure.pi (fun _ : Fin 2 => gibbsProbability ((uniformSpinPrior N : Measure (Spin N)).prod ν) H) := by
apply Measure.ext_of_singleton
intro x
rw [Measure.map_apply measurable_spinLeafPairJoin (measurableSet_singleton _)]
have hp : spinLeafPairJoin ⁻¹' {x} =
{(fun i => (x i).2, fun i => (x i).1)} := by
ext p
simp only [Set.mem_preimage, Set.mem_singleton_iff]
constructor
· intro h
apply Prod.ext
· funext i
exact congrArg Prod.snd (congrFun h i)
· funext i
exact congrArg Prod.fst (congrFun h i)
· intro h
subst p
rfl
rw [hp, ← Set.singleton_prod_singleton, Measure.compProd_apply_prod
(measurableSet_singleton _) (measurableSet_singleton _), lintegral_singleton]
change (Measure.pi (fun i : Fin 2 =>
gibbsProbability (uniformSpinPrior N : Measure (Spin N)) (fun σ => H (σ, (x i).2))))
{fun i => (x i).1} *
(Measure.pi (fun _ : Fin 2 => gibbsProbability ν (spinLeafTerminal H)))
{fun i => (x i).2} = _
simp only [Measure.pi_singleton]
rw [← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro i _
rw [mul_comm]
exact (spinLeafGibbs_singleton ν H he (x i).1 (x i).2).symm
theorem spinLeafPair_conditioning {N n : ℕ} (ν : Measure (LabeledLeaf n)) [IsProbabilityMeasure ν]
(H : Spin N × LabeledLeaf n → ℝ)
(he : Integrable (fun x => Real.exp (H x)) ((uniformSpinPrior N : Measure (Spin N)).prod ν))
(D : (Fin 2 → Spin N × LabeledLeaf n) → ℝ)
(hD : ∃ C : ℝ, ∀ x, |D x| ≤ C) :
referenceReplicaMean ((uniformSpinPrior N : Measure (Spin N)).prod ν) H D =
referenceReplicaMean ν (spinLeafTerminal H)
(fun α => ∫ σ, D (spinLeafPairJoin (α, σ)) ∂spinLeafPairResidualKernel H α) := by
have hmD : Measurable D := measurable_of_countable _
have hiD : Integrable D
(Measure.pi (fun _ : Fin 2 =>
gibbsProbability ((uniformSpinPrior N : Measure (Spin N)).prod ν) H)) := by
obtain ⟨C, hC⟩ := hD
exact integrable_of_measurable_abs_le hmD hC
have hp : MeasurePreserving spinLeafPairJoin
((Measure.pi (fun _ : Fin 2 => gibbsProbability ν (spinLeafTerminal H))) ⊗ₘ
spinLeafPairResidualKernel H)
(Measure.pi (fun _ : Fin 2 =>
gibbsProbability ((uniformSpinPrior N : Measure (Spin N)).prod ν) H)) :=
⟨measurable_spinLeafPairJoin, spinLeafPairLaw ν H he⟩
have hcomp := hp.hasLaw.integrable_comp hiD
rw [referenceReplicaMean_eq_tilted _ _ he, ← gibbsProbability_eq_tilted _ _ he,
referenceReplicaMean_eq_tilted _ _ (spinLeafTerminal_exp_integrable ν H he),
← gibbsProbability_eq_tilted _ _ (spinLeafTerminal_exp_integrable ν H he)]
rw [← hp.hasLaw.integral_comp hmD.aestronglyMeasurable]
exact integral_compProd hcomp
def tensorLeafSpinHamiltonian {N m k : ℕ}
(eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
(I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
(n : ℕ) (z : SpinTensorIndex I degree → ℝ) (p : TensorCoordinateData I degree n)
(s : Spin N × LabeledLeaf n) : ℝ :=
tensorSpinBaseEnergy eig U c I degree amplitude
(labeledEnergy n (markForestOfCoords (SpinTensorIndex I degree → ℝ) n p.2) s.2 z) s.1
lemma tensorLeafSpinHamiltonian_eq_coordinates {N m k : ℕ}
(eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
(I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
(n : ℕ) (z : SpinTensorIndex I degree → ℝ) (p : TensorCoordinateData I degree n)
(s : Spin N × LabeledLeaf n) :
tensorLeafSpinHamiltonian eig U c I degree amplitude n z p s =
tensorLabeledEnergy eig U c I degree amplitude n z
(tensorEnergyCoordinates U I degree amplitude n p) s := by
have hmarks : spinTensorEnergy U I degree amplitude
(labeledEnergy n (markForestOfCoords (SpinTensorIndex I degree → ℝ) n p.2) s.2 z) s.1 =
spinTensorEnergy U I degree amplitude z s.1 +
∑ i : Fin n, spinTensorEnergy U I degree amplitude (p.2 (edgeAt n s.2 i)) s.1 := by
unfold spinTensorEnergy
simp only [labeledEnergy_edge_sum, add_mul, Finset.sum_add_distrib]
congr 1
simp_rw [Finset.sum_mul]
rw [Finset.sum_comm]
change rotatedEnergy eig U s.1 + fieldEnergy c s.1 + _ =
rotatedEnergy eig U s.1 + fieldEnergy c s.1 + _ + _
rw [hmarks]
dsimp only [tensorEnergyCoordinates]
ring
theorem tensorLeafSpin_exp_integrable_ae {N m k : ℕ} (hN : 0 < N)
(eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
(I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
(n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
(hb : CascadeExponents n b) (z : SpinTensorIndex I degree → ℝ) :
∀ᵐ p ∂tensorCoordinateLaw I degree n b v,
Integrable (fun s => Real.exp (tensorLeafSpinHamiltonian eig U c I degree amplitude n z p s))
((uniformSpinPrior N : Measure (Spin N)).prod (labeledLeafLaw n p.1)) := by
have h := (tensorEnergyCoordinates_measurePreserving U I degree amplitude n b v).quasiMeasurePreserving.ae
(tensorLabeled_exp_integrable hN eig U c I degree amplitude n b v hb z)
filter_upwards [h] with p hp
simpa only [tensorLeafSpinHamiltonian_eq_coordinates, tensorLabeledReference,
tensorEnergyCoordinates, labeledSpinReference] using hp
lemma spinLeafTerminal_tensorLeafSpinHamiltonian {N m k : ℕ}
(eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
(I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
(n : ℕ) (z : SpinTensorIndex I degree → ℝ) (p : TensorCoordinateData I degree n)
(α : LabeledLeaf n) :
spinLeafTerminal (tensorLeafSpinHamiltonian eig U c I degree amplitude n z p) α =
spinTensorTerminal eig U c I degree amplitude
(labeledEnergy n (markForestOfCoords (SpinTensorIndex I degree → ℝ) n p.2) α z) := by
exact finiteLogIntegral_uniformSpinPrior _
/-- Actual finite tensor Hamiltonian version of conditional spin sampling. -/
theorem tensorLeafSpinPair_conditioning {N m k : ℕ}
(eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
(I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
(n : ℕ) (z : SpinTensorIndex I degree → ℝ) (p : TensorCoordinateData I degree n)
(he : Integrable (fun s => Real.exp (tensorLeafSpinHamiltonian eig U c I degree amplitude n z p s))
((uniformSpinPrior N : Measure (Spin N)).prod (labeledLeafLaw n p.1)))
(D : (Fin 2 → Spin N × LabeledLeaf n) → ℝ)
(hD : ∃ C : ℝ, ∀ x, |D x| ≤ C) :
referenceReplicaMean ((uniformSpinPrior N : Measure (Spin N)).prod (labeledLeafLaw n p.1))
(tensorLeafSpinHamiltonian eig U c I degree amplitude n z p) D =
referenceReplicaMean (labeledLeafLaw n p.1)
(fun α => spinTensorTerminal eig U c I degree amplitude
(labeledEnergy n (markForestOfCoords (SpinTensorIndex I degree → ℝ) n p.2) α z))
(fun α => ∫ σ, D (spinLeafPairJoin (α, σ))
∂spinLeafPairResidualKernel (tensorLeafSpinHamiltonian eig U c I degree amplitude n z p) α) := by
have ht : spinLeafTerminal (tensorLeafSpinHamiltonian eig U c I degree amplitude n z p) =
(fun α => spinTensorTerminal eig U c I degree amplitude
(labeledEnergy n (markForestOfCoords (SpinTensorIndex I degree → ℝ) n p.2) α z)) := by
funext α
exact spinLeafTerminal_tensorLeafSpinHamiltonian eig U c I degree amplitude n z p α
simpa only [ht] using spinLeafPair_conditioning (labeledLeafLaw n p.1)
(tensorLeafSpinHamiltonian eig U c I degree amplitude n z p) he D hD
/-- The actual Gaussian/cascade disorder satisfies the conditional pair
factorization almost surely, on one event for every bounded pair test. -/
theorem tensorLeafSpinPair_conditioning_ae {N m k : ℕ} (hN : 0 < N)
(eig : Fin N → ℝ) (U : Rotation N) (c : Fin N → ℝ)
(I : Fin m → Finset (Fin N)) (degree : Fin k → Fin m → ℕ) (amplitude : Fin k → ℝ)
(n : ℕ) (b : ℕ → ℝ) (v : ℕ → SpinTensorIndex I degree → ℝ≥0)
(hb : CascadeExponents n b) (z : SpinTensorIndex I degree → ℝ) :
∀ᵐ p ∂tensorCoordinateLaw I degree n b v,
∀ D : (Fin 2 → Spin N × LabeledLeaf n) → ℝ,
(∃ C : ℝ, ∀ x, |D x| ≤ C) →
referenceReplicaMean ((uniformSpinPrior N : Measure (Spin N)).prod (labeledLeafLaw n p.1))
(tensorLeafSpinHamiltonian eig U c I degree amplitude n z p) D =
referenceReplicaMean (labeledLeafLaw n p.1)
(fun α => spinTensorTerminal eig U c I degree amplitude
(labeledEnergy n (markForestOfCoords (SpinTensorIndex I degree → ℝ) n p.2) α z))
(fun α => ∫ σ, D (spinLeafPairJoin (α, σ))
∂spinLeafPairResidualKernel (tensorLeafSpinHamiltonian eig U c I degree amplitude n z p) α) := by
filter_upwards [tensorLeafSpin_exp_integrable_ae hN eig U c I degree amplitude n b v hb z] with p hp
intro D hD
exact tensorLeafSpinPair_conditioning eig U c I degree amplitude n z p hp D hD
end InvariantIsing
end
end OAI
|