Skip to content

Commit b375a6d

Browse files
committed
feat: covariance of a measure in a Banach space (#24930)
Define the covariance of a measure `μ` with `∫ x, ‖x‖^2 ∂μ < ∞` on a Banach space, as a continuous bilinear form `Dual ℝ E →L[ℝ] Dual ℝ E →L[ℝ] ℝ`.
1 parent 7050e9f commit b375a6d

File tree

5 files changed

+273
-1
lines changed

5 files changed

+273
-1
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4928,6 +4928,7 @@ import Mathlib.Probability.Martingale.Upcrossing
49284928
import Mathlib.Probability.Moments.Basic
49294929
import Mathlib.Probability.Moments.ComplexMGF
49304930
import Mathlib.Probability.Moments.Covariance
4931+
import Mathlib.Probability.Moments.CovarianceBilin
49314932
import Mathlib.Probability.Moments.IntegrableExpMul
49324933
import Mathlib.Probability.Moments.MGFAnalytic
49334934
import Mathlib.Probability.Moments.SubGaussian

Mathlib/Analysis/NormedSpace/OperatorNorm/Basic.lean

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ variable [RingHomIsometric σ₁₂] [RingHomIsometric σ₂₃] (f g : E →SL[
189189
/-- The fundamental property of the operator norm: `‖f x‖ ≤ ‖f‖ * ‖x‖`. -/
190190
theorem le_opNorm : ‖f x‖ ≤ ‖f‖ * ‖x‖ := (isLeast_opNorm f).1.2 x
191191

192-
193192
theorem dist_le_opNorm (x y : E) : dist (f x) (f y) ≤ ‖f‖ * dist x y := by
194193
simp_rw [dist_eq_norm, ← map_sub, f.le_opNorm]
195194

@@ -347,6 +346,13 @@ theorem opNorm_subsingleton [Subsingleton E] : ‖f‖ = 0 := by
347346
intro x
348347
simp [Subsingleton.elim x 0]
349348

349+
/-- The fundamental property of the operator norm, expressed with extended norms:
350+
`‖f x‖ₑ ≤ ‖f‖ₑ * ‖x‖ₑ`. -/
351+
lemma le_opNorm_enorm (x : E) : ‖f x‖ₑ ≤ ‖f‖ₑ * ‖x‖ₑ := by
352+
simp_rw [← ofReal_norm]
353+
rw [← ENNReal.ofReal_mul (by positivity)]
354+
gcongr
355+
exact f.le_opNorm x
350356

351357
end OpNorm
352358

Mathlib/MeasureTheory/Function/LpSpace/Basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,12 @@ theorem MeasureTheory.MemLp.of_comp_antilipschitzWith {α E F} {K'} [MeasurableS
654654
@[deprecated (since := "2025-02-21")]
655655
alias MeasureTheory.Memℒp.of_comp_antilipschitzWith := MeasureTheory.MemLp.of_comp_antilipschitzWith
656656

657+
lemma MeasureTheory.MemLp.continuousLinearMap_comp [NontriviallyNormedField 𝕜]
658+
[NormedSpace 𝕜 E] [NormedSpace 𝕜 F] {f : α → E}
659+
(h_Lp : MemLp f p μ) (L : E →L[𝕜] F) :
660+
MemLp (fun x ↦ L (f x)) p μ :=
661+
LipschitzWith.comp_memLp L.lipschitz (by simp) h_Lp
662+
657663
namespace LipschitzWith
658664

659665
theorem memLp_comp_iff_of_antilipschitz {α E F} {K K'} [MeasurableSpace α] {μ : Measure α}

Mathlib/MeasureTheory/Group/MeasurableEquiv.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,23 @@ def divRight [MeasurableMul G] (g : G) : G ≃ᵐ G where
197197
measurable_toFun := measurable_div_const' g
198198
measurable_invFun := measurable_mul_const g
199199

200+
@[to_additive]
201+
lemma _root_.measurableEmbedding_divRight [MeasurableMul G] (g : G) :
202+
MeasurableEmbedding fun x ↦ x / g :=
203+
(divRight g).measurableEmbedding
204+
200205
/-- `equiv.divLeft` as a `MeasurableEquiv` -/
201206
@[to_additive "`equiv.subLeft` as a `MeasurableEquiv`"]
202207
def divLeft [MeasurableMul G] [MeasurableInv G] (g : G) : G ≃ᵐ G where
203208
toEquiv := Equiv.divLeft g
204209
measurable_toFun := measurable_id.const_div g
205210
measurable_invFun := measurable_inv.mul_const g
206211

212+
@[to_additive]
213+
lemma _root_.measurableEmbedding_divLeft [MeasurableMul G] [MeasurableInv G] (g : G) :
214+
MeasurableEmbedding fun x ↦ g / x :=
215+
(divLeft g).measurableEmbedding
216+
207217
end MeasurableEquiv
208218

209219
namespace MeasureTheory.Measure
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/-
2+
Copyright (c) 2025 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
import Mathlib.Analysis.LocallyConvex.ContinuousOfBounded
7+
import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap
8+
import Mathlib.Probability.Variance
9+
10+
/-!
11+
# Covariance in Banach spaces
12+
13+
We define the covariance of a finite measure in a Banach space `E`,
14+
as a continous bilinear form on `Dual ℝ E`.
15+
16+
## Main definitions
17+
18+
Let `μ` be a finite measure on a normed space `E` with the Borel σ-algebra. We then define
19+
20+
* `Dual.toLp`: the function `MemLp.toLp` as a continuous linear map from `Dual 𝕜 E` (for `RCLike 𝕜`)
21+
into the space `Lp 𝕜 p μ` for `p ≥ 1`. This needs a hypothesis `MemLp id p μ` (we set it to the
22+
junk value 0 if that's not the case).
23+
* `covarianceBilin` : covariance of a measure `μ` with `∫ x, ‖x‖^2 ∂μ < ∞` on a Banach space,
24+
as a continuous bilinear form `Dual ℝ E →L[ℝ] Dual ℝ E →L[ℝ] ℝ`.
25+
If the second moment of `μ` is not finite, we set `covarianceBilin μ = 0`.
26+
27+
## Main statements
28+
29+
* `covarianceBilin_apply` : the covariance of `μ` on `L₁, L₂ : Dual ℝ E` is equal to
30+
`∫ x, (L₁ x - μ[L₁]) * (L₂ x - μ[L₂]) ∂μ`.
31+
* `covarianceBilin_same_eq_variance`: `covarianceBilin μ L L = Var[L; μ]`.
32+
33+
## Implementation notes
34+
35+
The hypothesis that `μ` has a second moment is written as `MemLp id 2 μ` in the code.
36+
37+
-/
38+
39+
40+
open MeasureTheory ProbabilityTheory Complex NormedSpace
41+
open scoped ENNReal NNReal Real Topology
42+
43+
variable {E : Type*} [NormedAddCommGroup E] {mE : MeasurableSpace E} {μ : Measure E} {p : ℝ≥0∞}
44+
45+
namespace NormedSpace.Dual
46+
47+
section LinearMap
48+
49+
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E]
50+
51+
open Classical in
52+
/-- Linear map from the dual to `Lp` equal to `MemLp.toLp` if `MemLp id p μ` and to 0 otherwise. -/
53+
noncomputable
54+
def toLpₗ (μ : Measure E) (p : ℝ≥0∞) :
55+
Dual 𝕜 E →ₗ[𝕜] Lp 𝕜 p μ :=
56+
if h_Lp : MemLp id p μ then
57+
{ toFun := fun L ↦ MemLp.toLp L (h_Lp.continuousLinearMap_comp L)
58+
map_add' u v := by push_cast; rw [MemLp.toLp_add]
59+
map_smul' c L := by push_cast; rw [MemLp.toLp_const_smul]; rfl }
60+
else 0
61+
62+
@[simp]
63+
lemma toLpₗ_apply (h_Lp : MemLp id p μ) (L : Dual 𝕜 E) :
64+
L.toLpₗ μ p = MemLp.toLp L (h_Lp.continuousLinearMap_comp L) := by
65+
simp [toLpₗ, dif_pos h_Lp]
66+
67+
@[simp]
68+
lemma toLpₗ_of_not_memLp (h_Lp : ¬ MemLp id p μ) (L : Dual 𝕜 E) :
69+
L.toLpₗ μ p = 0 := by
70+
simp [toLpₗ, dif_neg h_Lp]
71+
72+
lemma norm_toLpₗ_le [OpensMeasurableSpace E] (L : Dual 𝕜 E) :
73+
‖L.toLpₗ μ p‖ ≤ ‖L‖ * (eLpNorm id p μ).toReal := by
74+
by_cases h_Lp : MemLp id p μ
75+
swap
76+
· simp only [h_Lp, not_false_eq_true, toLpₗ_of_not_memLp, Lp.norm_zero]
77+
positivity
78+
by_cases hp : p = 0
79+
· simp only [h_Lp, toLpₗ_apply, Lp.norm_toLp]
80+
simp [hp]
81+
by_cases hp_top : p = ∞
82+
· simp only [hp_top, Dual.toLpₗ_apply h_Lp, Lp.norm_toLp, eLpNorm_exponent_top] at h_Lp ⊢
83+
simp only [eLpNormEssSup, id_eq]
84+
suffices (essSup (fun x ↦ ‖L x‖ₑ) μ).toReal ≤ (essSup (fun x ↦ ‖L‖ₑ *‖x‖ₑ) μ).toReal by
85+
rwa [ENNReal.essSup_const_mul, ENNReal.toReal_mul, toReal_enorm] at this
86+
gcongr
87+
· rw [ENNReal.essSup_const_mul]
88+
exact ENNReal.mul_ne_top (by simp) h_Lp.eLpNorm_ne_top
89+
· exact essSup_mono_ae <| ae_of_all _ L.le_opNorm_enorm
90+
have h0 : 0 < p.toReal := by simp [ENNReal.toReal_pos_iff, pos_iff_ne_zero, hp, Ne.lt_top hp_top]
91+
suffices ‖L.toLpₗ μ p‖
92+
≤ (‖L‖ₑ ^ p.toReal * ∫⁻ x, ‖x‖ₑ ^ p.toReal ∂μ).toReal ^ p.toReal⁻¹ by
93+
refine this.trans_eq ?_
94+
simp only [ENNReal.toReal_mul]
95+
rw [← ENNReal.toReal_rpow, Real.mul_rpow (by positivity) (by positivity),
96+
← Real.rpow_mul (by positivity), mul_inv_cancel₀ h0.ne', Real.rpow_one, toReal_enorm]
97+
rw [eLpNorm_eq_lintegral_rpow_enorm (by simp [hp]) hp_top, ENNReal.toReal_rpow]
98+
simp
99+
rw [Dual.toLpₗ_apply h_Lp, Lp.norm_toLp, eLpNorm_eq_lintegral_rpow_enorm (by simp [hp]) hp_top]
100+
simp only [ENNReal.toReal_ofNat, ENNReal.rpow_ofNat, one_div]
101+
refine ENNReal.toReal_le_of_le_ofReal (by positivity) ?_
102+
suffices ∫⁻ x, ‖L x‖ₑ ^ p.toReal ∂μ ≤ ‖L‖ₑ ^ p.toReal * ∫⁻ x, ‖x‖ₑ ^ p.toReal ∂μ by
103+
rw [← ENNReal.ofReal_rpow_of_nonneg (by positivity) (by positivity)]
104+
gcongr
105+
rwa [ENNReal.ofReal_toReal]
106+
refine ENNReal.mul_ne_top (by simp) ?_
107+
have h := h_Lp.eLpNorm_ne_top
108+
rw [eLpNorm_eq_lintegral_rpow_enorm (by simp [hp]) hp_top] at h
109+
simpa [h0] using h
110+
calc ∫⁻ x, ‖L x‖ₑ ^ p.toReal ∂μ
111+
_ ≤ ∫⁻ x, ‖L‖ₑ ^ p.toReal * ‖x‖ₑ ^ p.toReal ∂μ := by
112+
refine lintegral_mono fun x ↦ ?_
113+
rw [← ENNReal.mul_rpow_of_nonneg]
114+
swap; · positivity
115+
gcongr
116+
exact L.le_opNorm_enorm x
117+
_ = ‖L‖ₑ ^ p.toReal * ∫⁻ x, ‖x‖ₑ ^ p.toReal ∂μ := by rw [lintegral_const_mul]; fun_prop
118+
119+
end LinearMap
120+
121+
section ContinuousLinearMap
122+
123+
variable {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [OpensMeasurableSpace E]
124+
125+
/-- Continuous linear map from the dual to `Lp` equal to `MemLp.toLp` if `MemLp id p μ`
126+
and to 0 otherwise. -/
127+
noncomputable
128+
def toLp (μ : Measure E) (p : ℝ≥0∞) [Fact (1 ≤ p)] :
129+
Dual 𝕜 E →L[𝕜] Lp 𝕜 p μ where
130+
toLinearMap := Dual.toLpₗ μ p
131+
cont := by
132+
refine LinearMap.continuous_of_locally_bounded _ fun s hs ↦ ?_
133+
rw [image_isVonNBounded_iff]
134+
simp_rw [isVonNBounded_iff'] at hs
135+
obtain ⟨r, hxr⟩ := hs
136+
refine ⟨r * (eLpNorm id p μ).toReal, fun L hLs ↦ ?_⟩
137+
specialize hxr L hLs
138+
refine (Dual.norm_toLpₗ_le L).trans ?_
139+
gcongr
140+
141+
@[simp]
142+
lemma toLp_apply [Fact (1 ≤ p)] (h_Lp : MemLp id p μ) (L : Dual 𝕜 E) :
143+
L.toLp μ p = MemLp.toLp L (h_Lp.continuousLinearMap_comp L) := by
144+
simp [toLp, h_Lp]
145+
146+
@[simp]
147+
lemma toLp_of_not_memLp [Fact (1 ≤ p)] (h_Lp : ¬ MemLp id p μ) (L : Dual 𝕜 E) :
148+
L.toLp μ p = 0 := by
149+
simp [toLp, h_Lp]
150+
151+
end ContinuousLinearMap
152+
153+
end NormedSpace.Dual
154+
155+
namespace ProbabilityTheory
156+
157+
section Centered
158+
159+
variable [NormedSpace ℝ E] [OpensMeasurableSpace E]
160+
161+
/-- Continuous bilinear form with value `∫ x, L₁ x * L₂ x ∂μ` on `(L₁, L₂)`.
162+
This is equal to the covariance only if `μ` is centered. -/
163+
noncomputable
164+
def uncenteredCovarianceBilin (μ : Measure E) : Dual ℝ E →L[ℝ] Dual ℝ E →L[ℝ] ℝ :=
165+
ContinuousLinearMap.bilinearComp (isBoundedBilinearMap_inner (𝕜 := ℝ)).toContinuousLinearMap
166+
(Dual.toLp μ 2) (Dual.toLp μ 2)
167+
168+
lemma uncenteredCovarianceBilin_apply (h : MemLp id 2 μ) (L₁ L₂ : Dual ℝ E) :
169+
uncenteredCovarianceBilin μ L₁ L₂ = ∫ x, L₁ x * L₂ x ∂μ := by
170+
simp only [uncenteredCovarianceBilin, ContinuousLinearMap.bilinearComp_apply,
171+
Dual.toLp_apply h, L2.inner_def, RCLike.inner_apply, conj_trivial]
172+
refine integral_congr_ae ?_
173+
filter_upwards [MemLp.coeFn_toLp (h.continuousLinearMap_comp L₁),
174+
MemLp.coeFn_toLp (h.continuousLinearMap_comp L₂)] with x hxL₁ hxL₂
175+
simp only [id_eq] at hxL₁ hxL₂
176+
rw [hxL₁, hxL₂, mul_comm]
177+
178+
lemma uncenteredCovarianceBilin_of_not_memLp (h : ¬ MemLp id 2 μ) (L₁ L₂ : Dual ℝ E) :
179+
uncenteredCovarianceBilin μ L₁ L₂ = 0 := by
180+
simp [uncenteredCovarianceBilin, Dual.toLp_of_not_memLp h]
181+
182+
lemma norm_uncenteredCovarianceBilin_le (L₁ L₂ : Dual ℝ E) :
183+
‖uncenteredCovarianceBilin μ L₁ L₂‖ ≤ ‖L₁‖ * ‖L₂‖ * ∫ x, ‖x‖ ^ 2 ∂μ := by
184+
by_cases h : MemLp id 2 μ
185+
swap; · simp only [uncenteredCovarianceBilin_of_not_memLp h, norm_zero]; positivity
186+
calc ‖uncenteredCovarianceBilin μ L₁ L₂‖
187+
_ = ‖∫ x, L₁ x * L₂ x ∂μ‖ := by rw [uncenteredCovarianceBilin_apply h]
188+
_ ≤ ∫ x, ‖L₁ x‖ * ‖L₂ x‖ ∂μ := (norm_integral_le_integral_norm _).trans (by simp)
189+
_ ≤ ∫ x, ‖L₁‖ * ‖x‖ * ‖L₂‖ * ‖x‖ ∂μ := by
190+
refine integral_mono_ae ?_ ?_ (ae_of_all _ fun x ↦ ?_)
191+
· simp_rw [← norm_mul]
192+
exact (MemLp.integrable_mul (h.continuousLinearMap_comp L₁)
193+
(h.continuousLinearMap_comp L₂)).norm
194+
· simp_rw [mul_assoc]
195+
refine Integrable.const_mul ?_ _
196+
simp_rw [← mul_assoc, mul_comm _ (‖L₂‖), mul_assoc, ← pow_two]
197+
refine Integrable.const_mul ?_ _
198+
exact h.integrable_norm_pow (by simp)
199+
· simp only
200+
rw [mul_assoc]
201+
gcongr
202+
· exact ContinuousLinearMap.le_opNorm L₁ x
203+
· exact ContinuousLinearMap.le_opNorm L₂ x
204+
_ = ‖L₁‖ * ‖L₂‖ * ∫ x, ‖x‖ ^ 2 ∂μ := by
205+
rw [← integral_const_mul]
206+
congr with x
207+
ring
208+
209+
end Centered
210+
211+
section Covariance
212+
213+
variable [NormedSpace ℝ E] [BorelSpace E] [IsFiniteMeasure μ]
214+
215+
open Classical in
216+
/-- Continuous bilinear form with value `∫ x, (L₁ x - μ[L₁]) * (L₂ x - μ[L₂]) ∂μ` on `(L₁, L₂)`
217+
if `MemLp id 2 μ`. If not, we set it to zero. -/
218+
noncomputable
219+
def covarianceBilin (μ : Measure E) : Dual ℝ E →L[ℝ] Dual ℝ E →L[ℝ] ℝ :=
220+
uncenteredCovarianceBilin (μ.map (fun x ↦ x - ∫ x, x ∂μ))
221+
222+
@[simp]
223+
lemma covarianceBilin_of_not_memLp (h : ¬ MemLp id 2 μ) (L₁ L₂ : Dual ℝ E) :
224+
covarianceBilin μ L₁ L₂ = 0 := by
225+
rw [covarianceBilin, uncenteredCovarianceBilin_of_not_memLp]
226+
rw [(measurableEmbedding_subRight _).memLp_map_measure_iff]
227+
refine fun h_Lp ↦ h ?_
228+
have : (id : E → E) = fun x ↦ x - ∫ x, x ∂μ + ∫ x, x ∂μ := by ext; simp
229+
rw [this]
230+
exact h_Lp.add (memLp_const _)
231+
232+
variable [CompleteSpace E]
233+
234+
lemma covarianceBilin_apply (h : MemLp id 2 μ) (L₁ L₂ : Dual ℝ E) :
235+
covarianceBilin μ L₁ L₂ = ∫ x, (L₁ x - μ[L₁]) * (L₂ x - μ[L₂]) ∂μ := by
236+
rw [covarianceBilin, uncenteredCovarianceBilin_apply,
237+
integral_map (by fun_prop) (by fun_prop)]
238+
· have hL (L : Dual ℝ E) : μ[L] = L (∫ x, x ∂μ) := L.integral_comp_comm (h.integrable (by simp))
239+
simp [← hL]
240+
· exact (measurableEmbedding_subRight _).memLp_map_measure_iff.mpr <| h.sub (memLp_const _)
241+
242+
lemma covarianceBilin_same_eq_variance (h : MemLp id 2 μ) (L : Dual ℝ E) :
243+
covarianceBilin μ L L = Var[L; μ] := by
244+
rw [covarianceBilin_apply h, variance_eq_integral (by fun_prop)]
245+
simp_rw [pow_two]
246+
247+
end Covariance
248+
249+
end ProbabilityTheory

0 commit comments

Comments
 (0)