Offline · exact source
Exact Lean source

TensorLANEmbeddingWhitening

formalization/Cloning/TensorLANEmbeddingWhitening.lean

Source hash: 4213647e427a273f8fc575beb387391cee657e70e9596765f47699bf306d73bc

Full source copied without mathematical changes from the snapshot whose input hash matches the passing audit. Select a line number for a stable source pointer.

The declarations belong to the compiled inventory covered by the project’s shared axiom audit. That audit records an aggregate union, without attributing axioms to individual declarations.

Declarations in this module
1import Cloning.TensorLANEmbeddingClassicalCenter
2import Cloning.PCTJointGaussianChart
3import Mathlib.MeasureTheory.Measure.Haar.Unique
4 
5/-! Actual whitening of the physical root-space density, with the Jacobian
6derived from Haar measure and Gaussian normalization. -/
7noncomputable section
8open scoped BigOperators Topology Classical InnerProductSpace NNReal ENNReal
9open MeasureTheory Filter
10namespace Cloning.TensorLAN
11open Cloning.YoungHyperplane Cloning.PCTJointGaussianWhitening
12set_option backward.isDefEq.respectTransparency false
13set_option maxHeartbeats 1200000
14variable {d : ℕ}
15 
16/-- The existing PCT whitening coordinates applied to the literal Euclidean
17root hyperplane. -/
18def rootWhitening (p : Fin (d+1) → ℝ) (hp : ∀ a, 0 < p a)
19    (b : OrthonormalBasis (Fin (d+1)) ℝ (EuclideanSpace ℝ (Fin (d+1))))
20    (hb : b 0 = sqrtSpectrum p) : rootSpace d ≃L[ℝ] (Fin d → ℝ) :=
21  LinearEquiv.toContinuousLinearEquiv
22  { toFun := fun x => whiten p b x.1.ofLp
23    invFun := fun y => ⟨WithLp.toLp 2 (unwhiten p b y), unwhiten_sum_zero p b hb y⟩
24    left_inv := fun x => by
25      apply Subtype.ext
26      exact congrArg (WithLp.toLp 2) (unwhiten_whiten p hp b hb x.1.ofLp x.2)
27    right_inv := whiten_unwhiten p hp b
28    map_add' := by
29      intro x y
30      funext i
31      simp [whiten, mul_add, add_div, Finset.sum_add_distrib]
32    map_smul' := by
33      intro c x
34      funext i
35      simp [whiten, Finset.mul_sum, mul_div_assoc, mul_assoc, mul_left_comm] }
36 
37@[simp] theorem rootWhitening_apply (p : Fin (d+1) → ℝ) (hp : ∀ a, 0 < p a)
38    (b : OrthonormalBasis (Fin (d+1)) ℝ (EuclideanSpace ℝ (Fin (d+1))))
39    (hb : b 0 = sqrtSpectrum p) (x : rootSpace d) :
40    rootWhitening p hp b hb x = whiten p b x.1.ofLp := rfl
41 
42/-- The whitening chart has precisely the reciprocal-covariance quadratic
43form, including its normalization and its trace-zero restriction. -/
44theorem rootWhitening_norm_sq (p : Fin (d+1) → ℝ) (hp : ∀ a, 0 < p a)
45    (b : OrthonormalBasis (Fin (d+1)) ℝ (EuclideanSpace ℝ (Fin (d+1))))
46    (hb : b 0 = sqrtSpectrum p) (x : rootSpace d) :
47    (∑ i, (rootWhitening p hp b hb x i)^2) = ∑ a, (x.1 a)^2 / p a := by
48  rw [rootWhitening_apply, ← whiteningVector_norm_sq b (whiten p b x.1.ofLp),
49    whiteningVector_whiten p hp b hb x.1.ofLp x.2, EuclideanSpace.real_norm_sq_eq]
50  apply Finset.sum_congr rfl
51  intro a _
52  simp only [normalizedScore, WithLp.ofLp_toLp, div_pow, Real.sq_sqrt (hp a).le]
53 
54section DensityTransport
55variable (W : rootSpace d ≃L[ℝ] (Fin d → ℝ))
56 
57def whiteningJacobian : ℝ≥0 :=
58  Measure.addHaarScalarFactor ((volume : Measure (rootSpace d)).map W) (volume : Measure (Fin d → ℝ))
59 
60theorem whiteningJacobian_pos : 0 < whiteningJacobian W :=
61  Measure.addHaarScalarFactor_pos_of_isAddHaarMeasure _ _
62 
63theorem rootWhitening_map_volume :
64    (volume : Measure (rootSpace d)).map W = whiteningJacobian W • volume :=
65  Measure.isAddLeftInvariant_eq_smul _ _
66 
67/-- Push a density to coordinate Lebesgue measure, including its actual
68positive Jacobian. -/
69def whiteningDensity (f : rootSpace d → ℝ) (y : Fin d → ℝ) : ℝ :=
70  (whiteningJacobian W : ℝ) * f (W.symm y)
71 
72theorem whiteningDensity_integral (f : rootSpace d → ℝ) :
73    (∫ y, whiteningDensity W f y) = ∫ x, f x := by
74  have h := integral_map_equiv (μ := (volume : Measure (rootSpace d)))
75    W.toHomeomorph.toMeasurableEquiv (fun y => f (W.symm y))
76  change (∫ y, f (W.symm y) ∂((volume : Measure (rootSpace d)).map W)) =
77    (∫ x, f (W.symm (W x))) at h
78  rw [rootWhitening_map_volume, integral_smul_nnreal_measure] at h
79  simpa only [whiteningDensity, integral_const_mul, NNReal.smul_def,
80    ContinuousLinearEquiv.symm_apply_apply] using h
81 
82theorem whiteningDensity_integrable (f : rootSpace d → ℝ) (hf : Integrable f) :
83    Integrable (whiteningDensity W f) := by
84  have hi : Integrable (fun y => f (W.symm y))
85      ((volume : Measure (rootSpace d)).map W) := by
86    apply (integrable_map_equiv W.toHomeomorph.toMeasurableEquiv _).mpr
87    change Integrable (fun x => f (W.symm (W x)))
88    simpa only [ContinuousLinearEquiv.symm_apply_apply] using hf
89  rw [rootWhitening_map_volume] at hi
90  change Integrable (fun y => f (W.symm y))
91    ((whiteningJacobian W : ℝ≥0∞) • volume) at hi
92  have hj := (whiteningJacobian_pos W).ne'
93  have hi' := (integrable_smul_measure (ENNReal.coe_ne_zero.mpr hj)
94    ENNReal.coe_ne_top).mp hi
95  exact hi'.const_mul _
96 
97theorem whiteningDensity_l1 (f g : rootSpace d → ℝ) :
98    (∫ y, |whiteningDensity W f y - whiteningDensity W g y|) =
99      ∫ x, |f x - g x| := by
100  have h := whiteningDensity_integral W (fun x => |f x - g x|)
101  simpa only [whiteningDensity, ← mul_sub, abs_mul,
102    abs_of_nonneg (NNReal.coe_nonneg (whiteningJacobian W))] using h
103 
104end DensityTransport
105 
106end Cloning.TensorLAN