math / data /lean /OAI /Probability /InvariantIsing /Arrays /NSpinTensorLabeled.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
17.9 kB
import OAI.Probability.InvariantIsing.Arrays.NSpinTensorFluctuation
import OAI.Probability.IsingPerceptron.TiltedLabelLaw
namespace OAI
/-!
The finite spectral tensor model on the countable spin/leaf state space.
The Gaussian energy marks are the actual pushforward of the coordinate
marks, and the tilted ancestor-prefix marginal has its cascade value.
-/
noncomputable section
open MeasureTheory ProbabilityTheory
open scoped BigOperators NNReal
namespace InvariantIsing
def uniformSpinPrior (N : β„•) : ProbabilityMeasure (Spin N) :=
⟨(PMF.uniformOfFintype (Spin N)).toMeasure, inferInstance⟩
lemma finiteLogIntegral_uniformSpinPrior {N : β„•} (H : Spin N β†’ ℝ) :
IsingPerceptron.finiteLogIntegral (uniformSpinPrior N : Measure (Spin N)) H = logPartition H := by
unfold IsingPerceptron.finiteLogIntegral logPartition
congr 1
change (∫ Οƒ, Real.exp (H Οƒ) βˆ‚(PMF.uniformOfFintype (Spin N)).toMeasure) = _
rw [integral_fintype (Integrable.of_finite)]
simp only [measureReal_def,
PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton _),
PMF.uniformOfFintype_apply, ENNReal.toReal_inv, ENNReal.toReal_natCast, smul_eq_mul]
rw [← Finset.mul_sum]
lemma measurable_spinTensorEnergyMark {N m k : β„•} (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ) :
Measurable (fun z : SpinTensorIndex I degree β†’ ℝ =>
spinTensorEnergy U I degree amplitude z) := by
unfold spinTensorEnergy
fun_prop
def tensorEnergyMarkLaw {N m k : β„•} (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(v : SpinTensorIndex I degree β†’ ℝβ‰₯0) : ProbabilityMeasure (Spin N β†’ ℝ) :=
(tensorGaussianLaw I degree v).map (fun z => spinTensorEnergy U I degree amplitude z)
lemma spinTensorEnergyMark_norm_le {N m k : β„•} (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(z : SpinTensorIndex I degree β†’ ℝ) :
β€–spinTensorEnergy U I degree amplitude zβ€– ≀
(βˆ‘ Οƒ : Spin N, βˆ‘ i : SpinTensorIndex I degree,
|spinTensorFeature U I degree amplitude Οƒ i|) * β€–zβ€– := by
classical
let L : ℝ := βˆ‘ Οƒ : Spin N, βˆ‘ i : SpinTensorIndex I degree,
|spinTensorFeature U I degree amplitude Οƒ i|
have hL : 0 ≀ L := Finset.sum_nonneg fun _ _ => Finset.sum_nonneg fun _ _ => abs_nonneg _
apply (pi_norm_le_iff_of_nonneg (mul_nonneg hL (norm_nonneg z))).mpr
intro Οƒ
rw [Real.norm_eq_abs]
have hΟƒ : (βˆ‘ i : SpinTensorIndex I degree, |spinTensorFeature U I degree amplitude Οƒ i|) ≀ L := by
apply Finset.single_le_sum (f := fun Ο„ : Spin N =>
βˆ‘ i : SpinTensorIndex I degree, |spinTensorFeature U I degree amplitude Ο„ i|)
Β· exact fun _ _ => Finset.sum_nonneg fun _ _ => abs_nonneg _
Β· exact Finset.mem_univ Οƒ
calc
_ ≀ βˆ‘ i, |z i * spinTensorFeature U I degree amplitude Οƒ i| := Finset.abs_sum_le_sum_abs _ _
_ ≀ βˆ‘ i, β€–zβ€– * |spinTensorFeature U I degree amplitude Οƒ i| :=
Finset.sum_le_sum fun i _ => by
rw [abs_mul]
exact mul_le_mul_of_nonneg_right (by simpa only [Real.norm_eq_abs] using norm_le_pi_norm z i)
(abs_nonneg _)
_ = β€–zβ€– * βˆ‘ i, |spinTensorFeature U I degree amplitude Οƒ i| := (Finset.mul_sum _ _ _).symm
_ ≀ β€–zβ€– * L := mul_le_mul_of_nonneg_left hΟƒ (norm_nonneg _)
_ = _ := mul_comm _ _
lemma tensorEnergyMarkLaw_moments {N m k : β„•} (hN : 0 < N) (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(v : SpinTensorIndex I degree β†’ ℝβ‰₯0) :
IsingPerceptron.ExponentialNormMoments (tensorEnergyMarkLaw U I degree amplitude v :
Measure (Spin N β†’ ℝ)) := by
intro a
apply (integrable_map_measure (by fun_prop)
(measurable_spinTensorEnergyMark U I degree amplitude).aemeasurable).mpr
let L : ℝ := βˆ‘ Οƒ : Spin N, βˆ‘ i : SpinTensorIndex I degree,
|spinTensorFeature U I degree amplitude Οƒ i|
have hi := tensorGaussianLaw_moments hN I degree v (|a| * L)
apply hi.mono' (((measurable_spinTensorEnergyMark U I degree amplitude).norm.const_mul a).exp.aestronglyMeasurable)
exact ae_of_all _ fun z => by
rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)]
apply Real.exp_le_exp.mpr
calc
a * β€–spinTensorEnergy U I degree amplitude zβ€– ≀ |a| * β€–spinTensorEnergy U I degree amplitude zβ€– :=
mul_le_mul_of_nonneg_right (le_abs_self _) (norm_nonneg _)
_ ≀ |a| * (L * β€–zβ€–) := mul_le_mul_of_nonneg_left
(spinTensorEnergyMark_norm_le U I degree amplitude z) (abs_nonneg _)
_ = _ := by ring
def tensorSpinBaseEnergy {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 β†’ ℝ)
(z : SpinTensorIndex I degree β†’ ℝ) : Spin N β†’ ℝ :=
fun Οƒ => rotatedEnergy eig U Οƒ + fieldEnergy c Οƒ + spinTensorEnergy U I degree amplitude z Οƒ
lemma tensorSpinBaseEnergy_add {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 β†’ ℝ)
(z a : SpinTensorIndex I degree β†’ ℝ) :
tensorSpinBaseEnergy eig U c I degree amplitude (z + a) =
tensorSpinBaseEnergy eig U c I degree amplitude z + spinTensorEnergy U I degree amplitude a := by
ext Οƒ
simp only [tensorSpinBaseEnergy, Pi.add_apply, spinTensorEnergy_add]
ring
/-- Pushforward of the Gaussian energy marks commutes with the actual
backward recursion. The terminal keeps the uniform probability Ising prior. -/
theorem tensorCascadeValue_eq_energyRecursion {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 : β„•) (b : β„• β†’ ℝ) (v : β„• β†’ SpinTensorIndex I degree β†’ ℝβ‰₯0)
(z : SpinTensorIndex I degree β†’ ℝ) :
tensorCascadeValue eig U c I degree amplitude n b v z =
IsingPerceptron.energyRecursion n b (fun i => tensorEnergyMarkLaw U I degree amplitude (v i))
(uniformSpinPrior N : Measure (Spin N)) (tensorSpinBaseEnergy eig U c I degree amplitude z) := by
induction n generalizing b v z with
| zero => exact (finiteLogIntegral_uniformSpinPrior _).symm
| succ n ih =>
let bs := fun i => b (i + 1)
let vs := fun i => v (i + 1)
let G := IsingPerceptron.energyRecursion n bs
(fun i => tensorEnergyMarkLaw U I degree amplitude (vs i)) (uniformSpinPrior N : Measure (Spin N))
have hmG : Measurable G := IsingPerceptron.measurable_energyRecursion _ _ _ _
change Real.log (∫ a, Real.exp (b 0 * tensorCascadeValue eig U c I degree amplitude n bs vs (z + a))
βˆ‚(tensorGaussianLaw I degree (v 0) : Measure (SpinTensorIndex I degree β†’ ℝ))) / b 0 =
Real.log (∫ a, Real.exp (b 0 * G (tensorSpinBaseEnergy eig U c I degree amplitude z + a))
βˆ‚(tensorEnergyMarkLaw U I degree amplitude (v 0) : Measure (Spin N β†’ ℝ))) / b 0
congr 2
have hme : Measurable (fun a : Spin N β†’ ℝ =>
Real.exp (b 0 * G (tensorSpinBaseEnergy eig U c I degree amplitude z + a))) :=
((hmG.comp (measurable_const.add measurable_id)).const_mul (b 0)).exp
have hmap := integral_map (ΞΌ := (tensorGaussianLaw I degree (v 0) : Measure (SpinTensorIndex I degree β†’ ℝ)))
(measurable_spinTensorEnergyMark U I degree amplitude).aemeasurable hme.aestronglyMeasurable
change (∫ a, Real.exp (b 0 * G (tensorSpinBaseEnergy eig U c I degree amplitude z + a))
βˆ‚(tensorEnergyMarkLaw U I degree amplitude (v 0) : Measure (Spin N β†’ ℝ))) = _ at hmap
rw [hmap]
apply integral_congr_ae
refine ae_of_all _ fun a => ?_
dsimp only
rw [ih bs vs (z + a), tensorSpinBaseEnergy_add]
abbrev TensorLabeledData (N n : β„•) :=
IsingPerceptron.LabeledTree n Γ— (IsingPerceptron.ForestVertex n β†’ Spin N β†’ ℝ)
abbrev TensorLabeledState (N n : β„•) := Spin N Γ— IsingPerceptron.LabeledLeaf n
def tensorLabeledLaw {N m k : β„•} (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(n : β„•) (b : β„• β†’ ℝ) (v : β„• β†’ SpinTensorIndex I degree β†’ ℝβ‰₯0) : Measure (TensorLabeledData N n) :=
IsingPerceptron.cascadeCoordinateLaw n b (fun i => tensorEnergyMarkLaw U I degree amplitude (v i))
abbrev TensorCoordinateData {N m k : β„•} (I : Fin m β†’ Finset (Fin N))
(degree : Fin k β†’ Fin m β†’ β„•) (n : β„•) :=
IsingPerceptron.LabeledTree n Γ— (IsingPerceptron.ForestVertex n β†’ SpinTensorIndex I degree β†’ ℝ)
def tensorCoordinateLaw {N m k : β„•} (I : Fin m β†’ Finset (Fin N))
(degree : Fin k β†’ Fin m β†’ β„•) (n : β„•) (b : β„• β†’ ℝ)
(v : β„• β†’ SpinTensorIndex I degree β†’ ℝβ‰₯0) : Measure (TensorCoordinateData I degree n) :=
(IsingPerceptron.labeledCascadeLaw n b : Measure (IsingPerceptron.LabeledTree n)).prod
(Measure.infinitePi (fun w : IsingPerceptron.ForestVertex n =>
(tensorGaussianLaw I degree (v (IsingPerceptron.forestVertexDepth n w)) :
Measure (SpinTensorIndex I degree β†’ ℝ))))
instance tensorCoordinateLaw_probability {N m k : β„•} (I : Fin m β†’ Finset (Fin N))
(degree : Fin k β†’ Fin m β†’ β„•) (n : β„•) (b : β„• β†’ ℝ)
(v : β„• β†’ SpinTensorIndex I degree β†’ ℝβ‰₯0) :
IsProbabilityMeasure (tensorCoordinateLaw I degree n b v) := by
unfold tensorCoordinateLaw
infer_instance
def tensorEnergyCoordinates {N m k : β„•} (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(n : β„•) (p : TensorCoordinateData I degree n) : TensorLabeledData N n :=
(p.1, fun w => spinTensorEnergy U I degree amplitude (p.2 w))
lemma measurable_tensorEnergyCoordinates_joint {N m k : β„•}
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(n : β„•) :
Measurable (fun p : SpecialOrthogonal N Γ— TensorCoordinateData I degree n =>
tensorEnergyCoordinates (specialRotation p.1) I degree amplitude n p.2) := by
refine measurable_snd.fst.prodMk (Measurable.of_eval fun w => Measurable.of_eval fun Οƒ => ?_)
apply Finset.measurable_sum
intro i _
have hc : Measurable (fun p : SpecialOrthogonal N Γ— TensorCoordinateData I degree n => p.2.2 w i) := by
fun_prop
exact hc.mul ((measurable_spinTensorFeature I degree amplitude Οƒ i).comp measurable_fst)
theorem tensorEnergyCoordinates_measurePreserving {N m k : β„•} (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(n : β„•) (b : β„• β†’ ℝ) (v : β„• β†’ SpinTensorIndex I degree β†’ ℝβ‰₯0) :
MeasurePreserving (tensorEnergyCoordinates U I degree amplitude n)
(tensorCoordinateLaw I degree n b v) (tensorLabeledLaw U I degree amplitude n b v) := by
have hmark : MeasurePreserving
(fun z : IsingPerceptron.ForestVertex n β†’ SpinTensorIndex I degree β†’ ℝ =>
fun w => spinTensorEnergy U I degree amplitude (z w))
(Measure.infinitePi (fun w : IsingPerceptron.ForestVertex n =>
(tensorGaussianLaw I degree (v (IsingPerceptron.forestVertexDepth n w)) :
Measure (SpinTensorIndex I degree β†’ ℝ))))
(Measure.infinitePi (fun w : IsingPerceptron.ForestVertex n =>
(tensorEnergyMarkLaw U I degree amplitude (v (IsingPerceptron.forestVertexDepth n w)) :
Measure (Spin N β†’ ℝ)))) := by
refine ⟨Measurable.of_eval (fun w =>
(measurable_spinTensorEnergyMark U I degree amplitude).comp (measurable_pi_apply w)), ?_⟩
rw [Measure.infinitePi_map_pi _ (fun _ => measurable_spinTensorEnergyMark U I degree amplitude)]
rfl
convert (MeasurePreserving.id (IsingPerceptron.labeledCascadeLaw n b :
Measure (IsingPerceptron.LabeledTree n))).prod hmark using 1
all_goals rfl
instance tensorLabeledLaw_probability {N m k : β„•} (U : Rotation N)
(I : Fin m β†’ Finset (Fin N)) (degree : Fin k β†’ Fin m β†’ β„•) (amplitude : Fin k β†’ ℝ)
(n : β„•) (b : β„• β†’ ℝ) (v : β„• β†’ SpinTensorIndex I degree β†’ ℝβ‰₯0) :
IsProbabilityMeasure (tensorLabeledLaw U I degree amplitude n b v) := by
unfold tensorLabeledLaw
infer_instance
def tensorLabeledReference (N n : β„•) (p : TensorLabeledData N n) : Measure (TensorLabeledState N n) :=
IsingPerceptron.labeledSpinReference n (uniformSpinPrior N : Measure (Spin N)) p.1
instance tensorLabeledReference_probability (N n : β„•) (p : TensorLabeledData N n) :
IsProbabilityMeasure (tensorLabeledReference N n p) := by
unfold tensorLabeledReference
infer_instance
lemma measurable_tensorLabeledReference (N n : β„•) : Measurable (tensorLabeledReference N n) :=
(IsingPerceptron.measurable_labeledSpinReference_general n (uniformSpinPrior N : Measure (Spin N))).comp measurable_fst
def tensorLabeledEnergy {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 : TensorLabeledData N n) : TensorLabeledState N n β†’ ℝ :=
IsingPerceptron.cascadeCoordinateEnergy n (tensorSpinBaseEnergy eig U c I degree amplitude z) p
lemma measurable_tensorLabeledEnergy {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 β†’ ℝ) :
Measurable (fun p : TensorLabeledData N n Γ— TensorLabeledState N n =>
tensorLabeledEnergy eig U c I degree amplitude n z p.1 p.2) :=
IsingPerceptron.measurable_cascadeCoordinateEnergy n _
lemma measurable_tensorLabeledEnergy_root {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 : β„•) :
Measurable (fun p : ((SpinTensorIndex I degree β†’ ℝ) Γ— TensorLabeledData N n) Γ—
TensorLabeledState N n => tensorLabeledEnergy eig U c I degree amplitude n p.1.1 p.1.2 p.2) := by
apply measurable_from_prod_countable_left
intro s
change Measurable (fun p : (SpinTensorIndex I degree β†’ ℝ) Γ— TensorLabeledData N n =>
tensorSpinBaseEnergy eig U c I degree amplitude p.1 s.1 +
βˆ‘ i : Fin n, p.2.2 (IsingPerceptron.edgeAt n s.2 i) s.1)
unfold tensorSpinBaseEnergy spinTensorEnergy
fun_prop
theorem tensorLabeled_exp_integrable {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 : IsingPerceptron.CascadeExponents n b) (z : SpinTensorIndex I degree β†’ ℝ) :
βˆ€α΅ p βˆ‚tensorLabeledLaw U I degree amplitude n b v,
Integrable (fun s => Real.exp (tensorLabeledEnergy eig U c I degree amplitude n z p s))
(tensorLabeledReference N n p) :=
IsingPerceptron.cascadeCoordinate_exp_integrable n b hb
(fun i => tensorEnergyMarkLaw U I degree amplitude (v i))
(uniformSpinPrior N : Measure (Spin N))
(fun i _ => tensorEnergyMarkLaw_moments hN U I degree amplitude (v i)) _
theorem tensorLabeledLog_mean {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 : IsingPerceptron.CascadeExponents n b) (z : SpinTensorIndex I degree β†’ ℝ) :
let F := fun p => Real.log (∫ s, Real.exp (tensorLabeledEnergy eig U c I degree amplitude n z p s)
βˆ‚tensorLabeledReference N n p)
Integrable F (tensorLabeledLaw U I degree amplitude n b v) ∧
(∫ p, F p βˆ‚tensorLabeledLaw U I degree amplitude n b v) =
tensorCascadeValue eig U c I degree amplitude n b v z := by
have h := IsingPerceptron.cascadeCoordinate_log_integral n b hb
(fun i => tensorEnergyMarkLaw U I degree amplitude (v i))
(uniformSpinPrior N : Measure (Spin N))
(fun i _ => tensorEnergyMarkLaw_moments hN U I degree amplitude (v i))
(tensorSpinBaseEnergy eig U c I degree amplitude z)
exact ⟨h.1, h.2.trans (tensorCascadeValue_eq_energyRecursion eig U c I degree amplitude n b v z).symm⟩
/-- The exact parent-prefix probability of two tilted replicas is the
original cascade marginal, for the concrete tensor-enriched Ising model. -/
theorem tensorLabeled_tilted_parent_tail {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 : IsingPerceptron.CascadeExponents n b) (z : SpinTensorIndex I degree β†’ ℝ) (d : Fin n) :
(∫ p, IsingPerceptron.referenceReplicaMean (tensorLabeledReference N n p)
(tensorLabeledEnergy eig U c I degree amplitude n z p)
(fun Οƒ : Fin 2 β†’ TensorLabeledState N n =>
if (IsingPerceptron.labeledAddress n (Οƒ 1).2).take (d + 1) =
(IsingPerceptron.labeledAddress n (Οƒ 0).2).take (d + 1) then 1 else 0)
βˆ‚tensorLabeledLaw U I degree amplitude n b v) = 1 - b d :=
IsingPerceptron.cascadeCoordinate_tilted_label_tail n b hb
(fun i => tensorEnergyMarkLaw U I degree amplitude (v i))
(uniformSpinPrior N : Measure (Spin N))
(fun i _ => tensorEnergyMarkLaw_moments hN U I degree amplitude (v i)) _ d
end InvariantIsing
end
end OAI