Stat.Nonparametric.Histogram­Regression

This roll-up exports totalized finite-partition regression histograms, their integrated iid squared-risk bound, and the Hölder cubical specialization with an optimized ceiling-mesh rate.

Basic 10 core · 3 supporting A finite measurable label map represents a partition: its fibers are disjoint and cover the covariate space. ★ cellEstimate_mem_Icc

Totalized finite-partition regression histograms

A finite measurable label map represents a partition: its fibers are disjoint and cover the covariate space. Empty and zero-mass fibers are allowed. Samples are tuples of observations, whose covariates and responses are supplied by maps. The estimator clips the empirical response average to [0,1] and uses a fixed default when the observed cell count is zero, including sample size zero.

Reference for the estimator and integrated marginal loss: A. Nobel, Histogram Regression Estimation Using Data-dependent Partitions, Ann. Statist. 24 (1996), 1084–1105, equations (1)–(2), https://nobel.web.unc.edu/wp-content/uploads/sites/13591/2017/01/histreg.pdf. Here partitions are deterministic, and the empty-cell default is arbitrary.

def cell reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The cell with label is the inverse image under the partition map of that label after applying the covariate map.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
label :
A → κ
X :
Ω → A
k :
κ
cell label X k :
Set Ω
{ω | label (X ω) = k}
Causalean.Stat.Nonparametric.HistogramRegression.cell · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:33
def cellMass reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The cell probability is the real mass under the observation law of the cell specified by the partition, covariate map, and label.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
μ :
label :
A → κ
X :
Ω → A
k :
κ
cellMass μ label X k :
ℝ
(μ (cell label X k)).toReal
Causalean.Stat.Nonparametric.HistogramRegression.cellMass · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:38
def cellCount reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The sample cell count counts entries of the sample whose covariates have the specified partition label.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
k :
κ
z :
Fin m → Ω
cellCount label X k z :
ℕ
(Finset.univ.filter fun r => label (X (z r)) = k).card
Causalean.Stat.Nonparametric.HistogramRegression.cellCount · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:43
def cellSum reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The cell response sum sums responses in the sample over the cell specified by the partition, covariate map, and label.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
k :
κ
z :
Fin m → Ω
cellSum label X Y k z :
ℝ
∑ r : Fin m, if label (X (z r)) = k then Y (z r) else 0
Causalean.Stat.Nonparametric.HistogramRegression.cellSum · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:49
def clip reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Clipping maps a real input to its nearest point in [0,1].

Definition (Lean source)
t :
ℝ
clip t :
ℝ
max 0 (min 1 t)
Causalean.Stat.Nonparametric.HistogramRegression.clip · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:55
def cellEstimate reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The cell estimate clips the empirical average of responses in a sample within the specified covariate partition cell, and returns the fixed default when the cell is empty.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
a :
ℝ
k :
κ
z :
Fin m → Ω
cellEstimate label X Y a k z :
ℝ
if cellCount label X k z
= 0 then a else clip (cellSum label X Y k z / (cellCount label X k z : ℝ))
Causalean.Stat.Nonparametric.HistogramRegression.cellEstimate · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:58
def histogram reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The histogram prediction at a query covariate is the cell estimate using the partition, covariates, responses, default, and sample.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
a :
ℝ
z :
Fin m → Ω
x :
A
histogram label X Y a z x :
ℝ
cellEstimate label X Y a (label x) z
Causalean.Stat.Nonparametric.HistogramRegression.histogram · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:66
def risk reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The expected integrated squared risk averages squared prediction error against the target, integrating a fresh covariate drawn from the observation law and training samples drawn from the sample law, using the partition, covariates, responses, and default.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
μ :
ν :
Measure (Fin m → Ω)
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
a :
ℝ
g :
A → ℝ
risk μ ν label X Y a g :
ℝ
∫ z, (∫ ω, (histogram label X Y a z (X ω) - g (X ω)) ^ 2 ∂μ) ∂ν
Causalean.Stat.Nonparametric.HistogramRegression.risk · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:72
def positiveCells reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The positive-mass labels retain precisely those cells of the partition and covariate map with positive mass under the law.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
μ :
label :
A → κ
X :
Ω → A
positiveCells μ label X :
Finset.univ.filter fun k => 0 < cellMass μ label X k
Causalean.Stat.Nonparametric.HistogramRegression.positiveCells · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:80
theorem cellEstimate_mem_Icc reviewed
Causalean.Stat.Nonparametric.HistogramRegression

A default value in the unit interval ensures that every cell estimate belongs to the unit interval.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
a :
ℝ
k :
κ
z :
Fin m → Ω
ha :
a ∈ Icc (0 : ℝ) 1
cellEstimate label X Y a k z ∈ Icc (0 : ℝ) 1
Proof (Lean source)
theorem cellEstimate_mem_Icc {m : ℕ} (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (a : ℝ) (k : κ) (z : Fin m → Ω) (ha : a ∈ Icc (0 : ℝ) 1) : cellEstimate label X Y a k z ∈ Icc (0 : ℝ) 1 := by unfold cellEstimate split_ifs with hzero · exact ha · exact ⟨le_max_left _ _, max_le (by norm_num) (min_le_left _ _)⟩
Causalean.Stat.Nonparametric.HistogramRegression.cellEstimate_mem_Icc · Causalean/Stat/Nonparametric/HistogramRegression/Basic.lean:143 · uses cellEstimate
3 supporting declarations (lemmas, instances)
Population 3 core · 4 supporting The conditional-mean premise is the defining set-integral characterization of E[Y | X] = g(X), together with integrability. ★ cell_bias_le

Regression cell means and oscillation bias

The conditional-mean premise is the defining set-integral characterization of E[Y | X] = g(X), together with integrability. It asks only for a population regression identity, never for any sample-risk or rate estimate. A separate bridge accepts Mathlib's conditional expectation on the sigma algebra generated by X. Boundedness of the regression representative is derived almost surely.

def ConditionalMean reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The conditional-mean relation for the observation law, covariates, responses, and regression function says both responses and fitted population values are integrable and have equal integrals on every covariate-measurable event.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
μ :
X :
Ω → A
Y :
Ω → ℝ
g :
A → ℝ
ConditionalMean μ X Y g :
Prop
clause 1
clause 2
Integrable (fun ω => g (X ω)) μ
clause 3
s :
Set A
(∫ ω in X ⁻¹' s, Y ω ∂μ) = ∫ ω in X ⁻¹' s, g (X ω) ∂μ
Causalean.Stat.Nonparametric.HistogramRegression.ConditionalMean · Causalean/Stat/Nonparametric/HistogramRegression/Population.lean:26
def cellMean reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The population cell mean averages responses under the observation law within the specified partition cell, totalizing to zero at zero cell mass.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
μ :
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
k :
κ
cellMean μ label X Y k :
ℝ
(∫ ω in cell label X k, Y ω ∂μ) / cellMass μ label X k
Causalean.Stat.Nonparametric.HistogramRegression.cellMean · Causalean/Stat/Nonparametric/HistogramRegression/Population.lean:34
theorem cell_bias_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Measurable inputs, bounded responses, the conditional-mean relation, and a nonnegative within-cell oscillation envelope imply the integrated squared cell bias is at most cell mass times the squared envelope.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
g :
A → ℝ
k :
κ
δ :
ℝ
hlabel :
hX :
hg :
hY :
∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
hmean :
hδ :
0 ≤ δ
hosc :
∀ x x'
if
label x = k
and
label x' = k
then
|g x - g x'| ≤ δ
(∫ ω in cell label X k, (cellMean μ label X Y k - g (X ω)) ^ 2 ∂μ)
≤ cellMass μ label X k * δ ^ 2
Proof (Lean source)
theorem cell_bias_le (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (g : A → ℝ) (k : κ) (δ : ℝ) (hlabel : Measurable label) (hX : Measurable X) (hg : Measurable g) (hY : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (hmean : ConditionalMean μ X Y g) (hδ : 0 ≤ δ) (hosc : ∀ x x', label x = k → label x' = k → |g x - g x'| ≤ δ) : (∫ ω in cell label X k, (cellMean μ label X Y k - g (X ω)) ^ 2 ∂μ) ≤ cellMass μ label X k * δ ^ 2 := by have hs : MeasurableSet (cell label X k) := (measurableSet_singleton k).preimage (hlabel.comp hX) have hm : 0 ≤ cellMass μ label X k := ENNReal.toReal_nonneg by_cases hz : cellMass μ label X k = 0 · have hzμ : μ (cell label X k) = 0 := by exact ((ENNReal.toReal_eq_zero_iff _).mp hz).resolve_right (measure_ne_top μ _) simp [Measure.restrict_eq_zero.mpr hzμ, hz] · have hp : 0 < cellMass μ label X k := lt_of_le_of_ne hm (Ne.symm hz) have he := cellMean_eq_regression μ label X Y g k hlabel hmean have hpoint : ∀ ω ∈ cell label X k, |cellMean μ label X Y k - g (X ω)| ≤ δ := by intro ω hω have hlo : (cellMass μ label X k) * (g (X ω) - δ) ≤ ∫ ω' in cell label X k, g (X ω') ∂μ := by have hi := integral_mono_ae (μ := μ.restrict (cell label X k)) (integrable_const (g (X ω) - δ)) hmean.2.1.integrableOn (ae_restrict_of_forall_mem hs fun ω' hω' => by have hh := (abs_le.mp (hosc (X ω') (X ω) hω' hω)).1 linarith) simpa [setIntegral_const, cellMass, Measure.real] using hi have hhi : (∫ ω' in cell label X k, g (X ω') ∂μ) ≤ (cellMass μ label X k) * (g (X ω) + δ) := by have hi := integral_mono_ae (μ := μ.restrict (cell label X k)) hmean.2.1.integrableOn (integrable_const (g (X ω) + δ)) (ae_restrict_of_forall_mem hs fun ω' hω' => by have hh := (abs_le.mp (hosc (X ω') (X ω) hω' hω)).2 linarith) simpa [setIntegral_const, cellMass, Measure.real] using hi rw [he, cellMean] apply abs_le.mpr have hl := (le_div_iff₀ hp).mpr (by simpa [mul_comm] using hlo) have hu := (div_le_iff₀ hp).mpr (by simpa [mul_comm] using hhi) constructor <;> linarith have hb := regression_mem_Icc_ae μ X Y g hX hg hY hmean have hc : cellMean μ label X Y k ∈ Icc (0 : ℝ) 1 := by rw [he] exact cellMean_mem_Icc μ label X (fun ω => g (X ω)) k (hg.comp hX) hb have hi : Integrable (fun ω => (cellMean μ label X Y k - g (X ω)) ^ 2) μ := by apply (integrable_const (1 : ℝ)).mono' ((measurable_const.sub (hg.comp hX)).pow_const 2).aestronglyMeasurable filter_upwards [hb] with ω hω rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] have hl : -1 ≤ cellMean μ label X Y k - g (X ω) := by linarith [hc.1, hω.2] have hu : cellMean μ label X Y k - g (X ω) ≤ 1 := by linarith [hc.2, hω.1] simpa using sq_le_sq' hl hu have hle := integral_mono_ae (μ := μ.restrict (cell label X k)) hi.integrableOn (integrable_const (δ ^ 2)) (ae_restrict_of_forall_mem hs fun ω hω => by exact sq_le_sq.mpr (by simpa [abs_of_nonneg hδ] using hpoint ω hω)) simpa [setIntegral_const, cellMass, Measure.real] using hle
4 supporting declarations (lemmas, instances)
  • conditionalMean_of_condExp theorem — A conditional-expectation equality for measurable covariates and integrable responses implies the conditional-mean relation.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    X :
    Ω → A
    Y :
    Ω → ℝ
    g :
    A → ℝ
    hX :
    hY :
    hcond :
    μ[Y | comap X inferInstance] =ᵐ[μ] fun ω => g (X ω)
    Proof (Lean source)
    theorem conditionalMean_of_condExp (μ : Measure Ω) [IsProbabilityMeasure μ] (X : Ω → A) (Y : Ω → ℝ) (g : A → ℝ) (hX : Measurable X) (hY : Integrable Y μ) (hcond : μ[Y | comap X inferInstance] =ᵐ[μ] fun ω => g (X ω)) : ConditionalMean μ X Y g := by have hm : comap X inferInstance ≤ (inferInstance : MeasurableSpace Ω) := hX.comap_le refine ⟨hY, integrable_condExp.congr hcond, ?_⟩ intro s hs have hs' : MeasurableSet[comap X inferInstance] (X ⁻¹' s) := ⟨s, hs, rfl⟩ calc (∫ ω in X ⁻¹' s, Y ω ∂μ) = ∫ ω in X ⁻¹' s, (μ[Y | comap X inferInstance]) ω ∂μ := (setIntegral_condExp hm hY hs').symm _ = ∫ ω in X ⁻¹' s, g (X ω) ∂μ := integral_congr_ae (ae_restrict_of_ae hcond)
    Causalean.Stat.Nonparametric.HistogramRegression.conditionalMean_of_condExp · Causalean/Stat/Nonparametric/HistogramRegression/Population.lean:41
  • regression_mem_Icc_ae theorem — Measurable covariates and regression function, unit-interval responses, and the conditional-mean relation imply that the regression function is almost surely in the unit interval.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    X :
    Ω → A
    Y :
    Ω → ℝ
    g :
    A → ℝ
    hX :
    hg :
    hY :
    ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
    hmean :
    ∀ᵐ ω ∂μ, g (X ω) ∈ Icc (0 : ℝ) 1
    Proof (Lean source)
    theorem regression_mem_Icc_ae (μ : Measure Ω) [IsProbabilityMeasure μ] (X : Ω → A) (Y : Ω → ℝ) (g : A → ℝ) (hX : Measurable X) (hg : Measurable g) (hY : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (hmean : ConditionalMean μ X Y g) : ∀ᵐ ω ∂μ, g (X ω) ∈ Icc (0 : ℝ) 1 := by have nonneg_of_test (f : A → ℝ) (hf : Measurable f) (hfi : Integrable (fun ω => f (X ω)) μ) (htest : 0 ≤ ∫ ω in X ⁻¹' {x | f x < 0}, f (X ω) ∂μ) : ∀ᵐ ω ∂μ, 0 ≤ f (X ω) := by have hs : MeasurableSet (X ⁻¹' {x | f x < 0}) := (measurableSet_lt hf measurable_const).preimage hX have hn : ∀ᵐ ω ∂μ.restrict (X ⁻¹' {x | f x < 0}), 0 ≤ -f (X ω) := by filter_upwards [ae_restrict_mem hs] with ω hω exact neg_nonneg.mpr (le_of_lt hω) have hz : (∫ ω in X ⁻¹' {x | f x < 0}, -f (X ω) ∂μ) = 0 := by rw [integral_neg] have hp := integral_nonneg_of_ae hn rw [integral_neg] at hp linarith have he := (integral_eq_zero_iff_of_nonneg_ae hn hfi.integrableOn.neg).mp hz have he' := (ae_restrict_iff' hs).mp he filter_upwards [he'] with ω hω by_contra h have hh := hω (lt_of_not_ge h) change -f (X ω) = 0 at hh linarith have hlo : ∀ᵐ ω ∂μ, 0 ≤ g (X ω) := by apply nonneg_of_test g hg hmean.2.1 rw [← hmean.2.2 _ (measurableSet_lt hg measurable_const)] exact setIntegral_nonneg_of_ae (hY.mono fun ω hω => hω.1) have hhi : ∀ᵐ ω ∂μ, 0 ≤ 1 - g (X ω) := by apply nonneg_of_test (fun x => 1 - g x) (measurable_const.sub hg) ((integrable_const 1).sub hmean.2.1) rw [integral_sub (integrable_const 1) hmean.2.1.integrableOn, ← hmean.2.2 {x | 1 - g x < 0} (measurableSet_lt (show Measurable (fun x : A => (1 : ℝ) - g x) from measurable_const.sub hg) measurable_const)] exact sub_nonneg.mpr (integral_mono_ae hmean.1.integrableOn (integrable_const 1) (ae_restrict_of_ae (hY.mono fun ω hω => hω.2))) filter_upwards [hlo, hhi] with ω hlo hhi exact ⟨hlo, by linarith⟩
    Causalean.Stat.Nonparametric.HistogramRegression.regression_mem_Icc_ae · Causalean/Stat/Nonparametric/HistogramRegression/Population.lean:62
  • cellMean_eq_regression theorem — Measurable partition labels and the conditional-mean relation imply that the response cell mean equals the regression cell mean.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    μ :
    label :
    A → κ
    X :
    Ω → A
    Y :
    Ω → ℝ
    g :
    A → ℝ
    k :
    κ
    hlabel :
    hmean :
    cellMean μ label X Y k = cellMean μ label X (fun ω => g (X ω)) k
    Proof (Lean source)
    theorem cellMean_eq_regression (μ : Measure Ω) (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (g : A → ℝ) (k : κ) (hlabel : Measurable label) (hmean : ConditionalMean μ X Y g) : cellMean μ label X Y k = cellMean μ label X (fun ω => g (X ω)) k := by unfold cellMean congr 1 exact hmean.2.2 (label ⁻¹' {k}) ((measurableSet_singleton k).preimage hlabel)
    Causalean.Stat.Nonparametric.HistogramRegression.cellMean_eq_regression · Causalean/Stat/Nonparametric/HistogramRegression/Population.lean:108
  • cellMean_mem_Icc theorem — Measurable responses and bounded responses ensure the totalized population cell mean belongs to the unit interval.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    label :
    A → κ
    X :
    Ω → A
    Y :
    Ω → ℝ
    k :
    κ
    hYm :
    hY :
    ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
    cellMean μ label X Y k ∈ Icc (0 : ℝ) 1
    Proof (Lean source)
    theorem cellMean_mem_Icc (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (k : κ) (hYm : Measurable Y) (hY : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) : cellMean μ label X Y k ∈ Icc (0 : ℝ) 1 := by have hi : Integrable Y μ := (integrable_const (1 : ℝ)).mono' hYm.aestronglyMeasurable (hY.mono fun ω hω => by simpa [Real.norm_eq_abs, abs_of_nonneg hω.1] using hω.2) have hm : 0 ≤ cellMass μ label X k := ENNReal.toReal_nonneg by_cases hz : cellMass μ label X k = 0 · simp [cellMean, hz] · have hp : 0 < cellMass μ label X k := lt_of_le_of_ne hm (Ne.symm hz) refine ⟨div_nonneg (setIntegral_nonneg_of_ae (hY.mono fun ω hω => hω.1)) hm, ?_⟩ change (∫ ω in cell label X k, Y ω ∂μ) / cellMass μ label X k ≤ 1 apply (div_le_iff₀ hp).mpr have hle := integral_mono_ae (μ := μ.restrict (cell label X k)) hi.integrableOn (integrable_const (1 : ℝ)) (ae_restrict_of_ae (hY.mono fun ω hω => hω.2)) simpa [setIntegral_const, cellMass, Measure.real] using hle
    Causalean.Stat.Nonparametric.HistogramRegression.cellMean_mem_Icc · Causalean/Stat/Nonparametric/HistogramRegression/Population.lean:118
Mesh 3 core · 5 supporting Use max 1 (ceil (1/b)) bins along each axis. ★ optimized_mesh_variance_le

Ceiling meshes and optimized regression bandwidth algebra

Use max 1 (ceil (1/b)) bins along each axis. For 0<b≤1 its reciprocal lies between b/2 and b, and its d-dimensional cell count is at most (2/b)^d. The optimized positive-sample bandwidth is m^(-1/(2β+d)). All the real-power and ceiling comparisons needed by the statistical theorem are isolated here and make no probabilistic assumptions.

def meshCount reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The number of bins per coordinate for bandwidth is the ceiling of its reciprocal, with at least one bin for every real input.

Definition (Lean source)
b :
ℝ
meshCount b :
ℕ
max 1 ⌈b⁻¹⌉₊
Causalean.Stat.Nonparametric.HistogramRegression.meshCount · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:21
def optimizedBandwidth reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The optimized bandwidth for dimension, smoothness exponent, and sample size is the sample size raised to -1/(2β+d).

Definition (Lean source)
d :
ℕ
β :
ℝ
m :
ℕ
optimizedBandwidth d β m :
ℝ
(m : ℝ) ^ (-(1 / (2 * β + d)))
Causalean.Stat.Nonparametric.HistogramRegression.optimizedBandwidth · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:60
theorem optimized_mesh_variance_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Positive smoothness and sample size give the bound 2^d · m^(-2β/(2β+d)) on the variance term: the number of cubical cells at the optimized bandwidth divided by the sample size plus one.

Formal statement
d :
ℕ
β :
ℝ
m :
ℕ
hβ :
0 < β
hm :
1 ≤ m
(meshCount (optimizedBandwidth d β m) : ℝ) ^ d / (m + 1 : ℝ)
≤ (2 : ℝ) ^ d * (m : ℝ) ^ (-(2 * β / (2 * β + d)))
Proof (Lean source)
theorem optimized_mesh_variance_le (d : ℕ) (β : ℝ) (m : ℕ) (hβ : 0 < β) (hm : 1 ≤ m) : (meshCount (optimizedBandwidth d β m) : ℝ) ^ d / (m + 1 : ℝ) ≤ (2 : ℝ) ^ d * (m : ℝ) ^ (-(2 * β / (2 * β + d))) := by obtain ⟨hb, hb1⟩ := optimizedBandwidth_mem d β m hβ hm have hmpos : 0 < (m : ℝ) := by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one hm) have hcount := mesh_count_pow_le d (optimizedBandwidth d β m) hb hb1 calc (meshCount (optimizedBandwidth d β m) : ℝ) ^ d / (m + 1 : ℝ) ≤ ((2 : ℝ) ^ d / (optimizedBandwidth d β m) ^ d) / (m + 1 : ℝ) := div_le_div_of_nonneg_right hcount (by positivity) _ ≤ ((2 : ℝ) ^ d / (optimizedBandwidth d β m) ^ d) / (m : ℝ) := div_le_div_of_nonneg_left (by positivity) hmpos (by linarith) _ = (2 : ℝ) ^ d * (1 / ((m : ℝ) * (optimizedBandwidth d β m) ^ d)) := by ring _ = _ := by rw [(optimized_power_identities d β m hβ hm).2]
Causalean.Stat.Nonparametric.HistogramRegression.optimized_mesh_variance_le · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:104 · uses meshCount , optimizedBandwidth
5 supporting declarations (lemmas, instances)
  • meshCount_pos theorem — The ceiling mesh count is positive for every bandwidth.
    b :
    ℝ
    0 < meshCount b
    Proof (Lean source)
    theorem meshCount_pos (b : ℝ) : 0 < meshCount b := by exact lt_of_lt_of_le Nat.zero_lt_one (le_max_left _ _)
    Causalean.Stat.Nonparametric.HistogramRegression.meshCount_pos · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:25
  • mesh_bounds theorem — A bandwidth in (0,1] gives the reciprocal mesh-width comparison and ceiling cell-count bound.
    b :
    ℝ
    hb :
    0 < b
    hb1 :
    b ≤ 1
    conclusion 1
    b / 2 ≤ (meshCount b : ℝ)⁻¹
    conclusion 2
    (meshCount b : ℝ)⁻¹ ≤ b
    conclusion 3
    (meshCount b : ℝ) ≤ 2 / b
    Proof (Lean source)
    theorem mesh_bounds (b : ℝ) (hb : 0 < b) (hb1 : b ≤ 1) : b / 2 ≤ (meshCount b : ℝ)⁻¹ ∧ (meshCount b : ℝ)⁻¹ ≤ b ∧ (meshCount b : ℝ) ≤ 2 / b := by have hi : 0 < b⁻¹ := inv_pos.mpr hb have hcount : meshCount b = ⌈b⁻¹⌉₊ := max_eq_right (Nat.one_le_ceil_iff.mpr hi) have hpos : 0 < (meshCount b : ℝ) := by exact_mod_cast meshCount_pos b have hlo : b⁻¹ ≤ (meshCount b : ℝ) := by rw [hcount] exact Nat.le_ceil _ have hup : (meshCount b : ℝ) ≤ 2 / b := by have hceil := (Nat.ceil_lt_add_one hi.le).le have hone : 1 ≤ b⁻¹ := (one_le_inv₀ hb).mpr hb1 rw [hcount, div_eq_mul_inv] linarith refine ⟨?_, ?_, hup⟩ · have h := (inv_le_inv₀ (by positivity : 0 < 2 / b) hpos).mpr hup simpa using h · have h := (inv_le_inv₀ hpos hi).mpr hlo simpa using h
    Causalean.Stat.Nonparametric.HistogramRegression.mesh_bounds · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:29
  • mesh_count_pow_le theorem — A bandwidth in (0,1] gives the dimension-dependent ceiling cell-count bound.
    d :
    ℕ
    b :
    ℝ
    hb :
    0 < b
    hb1 :
    b ≤ 1
    (meshCount b : ℝ) ^ d ≤ (2 : ℝ) ^ d / b ^ d
    Proof (Lean source)
    theorem mesh_count_pow_le (d : ℕ) (b : ℝ) (hb : 0 < b) (hb1 : b ≤ 1) : (meshCount b : ℝ) ^ d ≤ (2 : ℝ) ^ d / b ^ d := by have h := pow_le_pow_left₀ (by positivity : 0 ≤ (meshCount b : ℝ)) (mesh_bounds b hb hb1).2.2 d simpa only [div_pow] using h
    Causalean.Stat.Nonparametric.HistogramRegression.mesh_count_pow_le · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:52
  • optimizedBandwidth_mem theorem — Positive smoothness and at least one observation imply the optimized bandwidth is in (0,1].
    d :
    ℕ
    β :
    ℝ
    m :
    ℕ
    hβ :
    0 < β
    hm :
    1 ≤ m
    conclusion 1
    conclusion 2
    optimizedBandwidth d β m ≤ 1
    Proof (Lean source)
    theorem optimizedBandwidth_mem (d : ℕ) (β : ℝ) (m : ℕ) (hβ : 0 < β) (hm : 1 ≤ m) : 0 < optimizedBandwidth d β m ∧ optimizedBandwidth d β m ≤ 1 := by have hm1 : (1 : ℝ) ≤ m := by exact_mod_cast hm have hmpos : 0 < (m : ℝ) := lt_of_lt_of_le zero_lt_one hm1 have hden : 0 < 2 * β + (d : ℝ) := by positivity unfold optimizedBandwidth exact ⟨Real.rpow_pos_of_pos hmpos _, Real.rpow_le_one_of_one_le_of_nonpos hm1 (neg_nonpos.mpr (one_div_pos.mpr hden).le)⟩
    Causalean.Stat.Nonparametric.HistogramRegression.optimizedBandwidth_mem · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:65
  • optimized_power_identities theorem — Positive smoothness and sample size give the exact balanced bias and reciprocal effective-sample-size powers at the optimized bandwidth.
    d :
    ℕ
    β :
    ℝ
    m :
    ℕ
    hβ :
    0 < β
    hm :
    1 ≤ m
    conclusion 1
    (optimizedBandwidth d β m) ^ (2 * β) = (m : ℝ) ^ (-(2 * β / (2 * β + d)))
    conclusion 2
    1 / ((m : ℝ) * (optimizedBandwidth d β m) ^ d) = (m : ℝ) ^ (-(2 * β / (2 * β + d)))
    Proof (Lean source)
    theorem optimized_power_identities (d : ℕ) (β : ℝ) (m : ℕ) (hβ : 0 < β) (hm : 1 ≤ m) : (optimizedBandwidth d β m) ^ (2 * β) = (m : ℝ) ^ (-(2 * β / (2 * β + d))) ∧ 1 / ((m : ℝ) * (optimizedBandwidth d β m) ^ d) = (m : ℝ) ^ (-(2 * β / (2 * β + d))) := by -- Prove using rpow_mul, rpow_natCast, rpow_add, and positivity of m -- and 2β+d. The second exponent is -1+d/(2β+d)=-2β/(2β+d). have hmpos : 0 < (m : ℝ) := by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one hm) have hden : 2 * β + (d : ℝ) ≠ 0 := ne_of_gt (by positivity) unfold optimizedBandwidth constructor · rw [← Real.rpow_mul hmpos.le] congr 1 ring · have hprod : (m : ℝ) * (m : ℝ) ^ (-(1 / (2 * β + d)) * d) = (m : ℝ) ^ (1 + -(1 / (2 * β + d)) * d) := by rw [Real.rpow_add hmpos, Real.rpow_one] rw [← Real.rpow_natCast, ← Real.rpow_mul hmpos.le, hprod, one_div, ← Real.rpow_neg hmpos.le] congr 1 field_simp [hden] ring
    Causalean.Stat.Nonparametric.HistogramRegression.optimized_power_identities · Causalean/Stat/Nonparametric/HistogramRegression/Mesh.lean:78
Geometry 3 core · 4 supporting The covariate domain is the closed unit cube in Euclidean space, with the Euclidean (L², not sup) metric. ★ cube_holder_oscillation

Euclidean unit-cube partition geometry

The covariate domain is the closed unit cube in Euclidean space, with the Euclidean (L², not sup) metric. Floors at interior grid points choose the cell to their right, and the coordinate value one is assigned to the final cell by clamping the index. This keeps exactly meshCount b ^ d labels, covers the boundary, and gives diameter at most sqrt(d)*b for positive bandwidths at most one. Arbitrary probability distributions on the cube are permitted.

abbrev Cube reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The closed unit cube in dimension consists of Euclidean vectors with every coordinate in the unit interval.

Definition (Lean source)
d :
ℕ
Cube d :
Type
{x : EuclideanSpace ℝ (Fin d) // ∀ i, x i ∈ Icc (0 : ℝ) 1}
Causalean.Stat.Nonparametric.HistogramRegression.Cube · Causalean/Stat/Nonparametric/HistogramRegression/Geometry.lean:26
def cubeLabel reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The cubical cell label for a bandwidth and cube point floors each scaled coordinate and clamps the endpoint to the final bin.

Definition (Lean source)
d :
ℕ
b :
ℝ
x :
cubeLabel b x :
Fin d → Fin (meshCount b)
fun i
=> ⟨min ⌊(meshCount b : ℝ) * x.val i⌋₊ (meshCount b - 1), by have hn := meshCount_pos b have hle := Nat.min_le_right ⌊(meshCount b : ℝ) * x.val i⌋₊ (meshCount b - 1) omega⟩
Causalean.Stat.Nonparametric.HistogramRegression.cubeLabel · Causalean/Stat/Nonparametric/HistogramRegression/Geometry.lean:31 · uses Cube , meshCount
theorem cube_holder_oscillation reviewed
Causalean.Stat.Nonparametric.HistogramRegression

A positive Hölder exponent and nonnegative constant, a Hölder regression function, a bandwidth in (0,1], and equal cell labels give the oscillation bound |g x − g y| ≤ C (√d)^β b^β for two cube points in the same cell.

Formal statement
d :
ℕ
g :
Cube d → ℝ
β C b :
ℝ
hβ :
0 < β
hC :
0 ≤ C
hb :
0 < b
hb1 :
b ≤ 1
hholder :
∀ x y, |g x - g y| ≤ C * (dist x y) ^ β
x y :
hlabel :
|g x - g y| ≤ C * (sqrt (d : ℝ)) ^ β * b ^ β
Proof (Lean source)
theorem cube_holder_oscillation {d : ℕ} (g : Cube d → ℝ) (β C b : ℝ) (hβ : 0 < β) (hC : 0 ≤ C) (hb : 0 < b) (hb1 : b ≤ 1) (hholder : ∀ x y, |g x - g y| ≤ C * (dist x y) ^ β) (x y : Cube d) (hlabel : cubeLabel b x = cubeLabel b y) : |g x - g y| ≤ C * (sqrt (d : ℝ)) ^ β * b ^ β := by calc |g x - g y| ≤ C * (dist x y) ^ β := hholder x y _ ≤ C * (sqrt (d : ℝ) * b) ^ β := mul_le_mul_of_nonneg_left (Real.rpow_le_rpow dist_nonneg (same_cell_diameter_le b hb hb1 x y hlabel) hβ.le) hC _ = _ := by rw [Real.mul_rpow (Real.sqrt_nonneg _) hb.le]; ring
Causalean.Stat.Nonparametric.HistogramRegression.cube_holder_oscillation · Causalean/Stat/Nonparametric/HistogramRegression/Geometry.lean:117 · uses Cube , cubeLabel , meshCount
4 supporting declarations (lemmas, instances)
  • measurable_cubeLabel theorem — Cubical labels are measurable for every bandwidth.
    d :
    ℕ
    b :
    ℝ
    Measurable (cubeLabel (d := d) b)
    Proof (Lean source)
    @[fun_prop] theorem measurable_cubeLabel (d : ℕ) (b : ℝ) : Measurable (cubeLabel (d := d) b) := by apply measurable_pi_iff.mpr intro i let clamp : ℕ → Fin (meshCount b) := fun k => ⟨min k (meshCount b - 1), by have hn := meshCount_pos b have hle := Nat.min_le_right k (meshCount b - 1) omega⟩ have hf : Measurable (fun x : Cube d => ⌊(meshCount b : ℝ) * x.val i⌋₊) := (measurable_const.mul ((measurable_pi_apply i).comp ((WithLp.measurable_ofLp 2 _).comp measurable_subtype_coe))).nat_floor exact (measurable_of_countable clamp).comp hf
    Causalean.Stat.Nonparametric.HistogramRegression.measurable_cubeLabel · Causalean/Stat/Nonparametric/HistogramRegression/Geometry.lean:39
  • same_cell_coordinate_le theorem — Equal cubical labels imply coordinate distance at most the reciprocal number of bins, including the upper cube boundary.
    d :
    ℕ
    b :
    ℝ
    x y :
    hlabel :
    i :
    Fin d
    |x.val i - y.val i| ≤ (meshCount b : ℝ)⁻¹
    Proof (Lean source)
    theorem same_cell_coordinate_le {d : ℕ} (b : ℝ) (x y : Cube d) (hlabel : cubeLabel b x = cubeLabel b y) (i : Fin d) : |x.val i - y.val i| ≤ (meshCount b : ℝ)⁻¹ := by -- Prove separately for a final-bin index and an interior index. The final -- bin uses x_i≤1, whereas interior bins use the floor interval bounds. have hn := meshCount_pos b have hnR : 0 < (meshCount b : ℝ) := by exact_mod_cast hn have hinterval (z : Cube d) : ((min ⌊(meshCount b : ℝ) * z.val i⌋₊ (meshCount b - 1) : ℕ) : ℝ) ≤ (meshCount b : ℝ) * z.val i ∧ (meshCount b : ℝ) * z.val i ≤ ((min ⌊(meshCount b : ℝ) * z.val i⌋₊ (meshCount b - 1) : ℕ) : ℝ) + 1 := by constructor · exact (Nat.cast_le.mpr (Nat.min_le_left _ _)).trans (Nat.floor_le (mul_nonneg hnR.le (z.property i).1)) · by_cases hf : ⌊(meshCount b : ℝ) * z.val i⌋₊ ≤ meshCount b - 1 · rw [min_eq_left hf] exact (Nat.lt_floor_add_one _).le · rw [min_eq_right (by omega)] have hcast : ((meshCount b - 1 : ℕ) : ℝ) + 1 = (meshCount b : ℝ) := by exact_mod_cast (show meshCount b - 1 + 1 = meshCount b by omega) rw [hcast] exact mul_le_of_le_one_right hnR.le (z.property i).2 have heq : min ⌊(meshCount b : ℝ) * x.val i⌋₊ (meshCount b - 1) = min ⌊(meshCount b : ℝ) * y.val i⌋₊ (meshCount b - 1) := congrArg (fun f => (f i).val) hlabel obtain ⟨hxl, hxu⟩ := hinterval x obtain ⟨hyl, hyu⟩ := hinterval y rw [← heq] at hyl hyu apply (abs_le).mpr have hinv : (meshCount b : ℝ) * (meshCount b : ℝ)⁻¹ = 1 := mul_inv_cancel₀ hnR.ne' constructor <;> nlinarith
    Causalean.Stat.Nonparametric.HistogramRegression.same_cell_coordinate_le · Causalean/Stat/Nonparametric/HistogramRegression/Geometry.lean:55
  • same_cell_diameter_le theorem — A bandwidth in (0,1] and equal cubical labels imply Euclidean point distance at most square-root dimension times bandwidth.
    d :
    ℕ
    b :
    ℝ
    hb :
    0 < b
    hb1 :
    b ≤ 1
    x y :
    hlabel :
    dist x y ≤ sqrt (d : ℝ) * b
    Proof (Lean source)
    theorem same_cell_diameter_le {d : ℕ} (b : ℝ) (hb : 0 < b) (hb1 : b ≤ 1) (x y : Cube d) (hlabel : cubeLabel b x = cubeLabel b y) : dist x y ≤ sqrt (d : ℝ) * b := by -- Sum squared coordinate differences in EuclideanSpace.norm_eq, use -- same_cell_coordinate_le and mesh_bounds, then compare square roots. have hcoord (i : Fin d) : dist (x.val i) (y.val i) ≤ b := by rw [Real.dist_eq] exact (same_cell_coordinate_le b x y hlabel i).trans (mesh_bounds b hb hb1).2.1 have hsum : ∑ i : Fin d, dist (x.val i) (y.val i) ^ 2 ≤ (d : ℝ) * b ^ 2 := by calc _ ≤ ∑ _i : Fin d, b ^ 2 := Finset.sum_le_sum fun i _ => pow_le_pow_left₀ dist_nonneg (hcoord i) 2 _ = _ := by simp change dist x.val y.val ≤ _ rw [EuclideanSpace.dist_eq] calc _ ≤ sqrt ((d : ℝ) * b ^ 2) := Real.sqrt_le_sqrt hsum _ = _ := by rw [Real.sqrt_mul (Nat.cast_nonneg d), Real.sqrt_sq hb.le]
    Causalean.Stat.Nonparametric.HistogramRegression.same_cell_diameter_le · Causalean/Stat/Nonparametric/HistogramRegression/Geometry.lean:91
  • cube_label_card theorem — Cubical labels have exactly the ceiling mesh count to the dimension.
    d :
    ℕ
    b :
    ℝ
    card (Fin d → Fin (meshCount b)) = meshCount b ^ d
    Proof (Lean source)
    theorem cube_label_card (d : ℕ) (b : ℝ) : card (Fin d → Fin (meshCount b)) = meshCount b ^ d := by simp
    Causalean.Stat.Nonparametric.HistogramRegression.cube_label_card · Causalean/Stat/Nonparametric/HistogramRegression/Geometry.lean:112
Pattern­Moments 2 core · 7 supporting A fixed subset of sample indices defines a measurable rectangle: selected coordinates lie in a given cell, and other coordinates lie in its complement. ★ integral_centered_sum_sq_on_pattern

Membership-pattern product moments

A fixed subset of sample indices defines a measurable rectangle: selected coordinates lie in a given cell, and other coordinates lie in its complement. Mathlib's restricted product measure and coordinate-product integral formulas give the factorization directly. The diagonal and centered cross-coordinate moments are isolated before the squared-sum identity. This layer depends only on the estimator definitions, not on binomial counts or regression hypotheses.

def cellPattern reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The membership pattern event specifies exactly which positions of a sample are in the cell determined by the partition, covariates, and label, using the prescribed index set.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
k :
κ
T :
cellPattern label X k T :
Set (Fin m → Ω)
{z | ∀ r, label (X (z r)) = k ↔ r ∈ T}
Causalean.Stat.Nonparametric.HistogramRegression.cellPattern · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:28
theorem integral_centered_sum_sq_on_pattern reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Measurable inputs and integrable first and second response moments, with zero cell residual mean, imply that the iid-sample integral, over the event that exactly the selected positions fall in the cell, of the squared sum of the selected centered responses equals the number of selected positions, times the integral of the squared centered response over the cell, times the cell mass to the power of that number minus one, times the complementary mass to the power of the number of unselected positions.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
c :
ℝ
k :
κ
T :
hlabel :
hX :
hint :
hsq :
Integrable (fun ω => Y ω ^ 2) μ
hcenter :
(∫ ω in cell label X k, (Y ω - c) ∂μ) = 0
(∫ z in cellPattern label X k T, (∑ r ∈ T, (Y (z r) - c)) ^ 2 ∂Measure.pi (fun _ : Fin m => μ))
= (T.card : ℝ) * (∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) * cellMass μ label X k ^ (T.card - 1) * (1 - cellMass μ label X k) ^ (m - T.card)
Proof (Lean source)
theorem integral_centered_sum_sq_on_pattern {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (c : ℝ) (k : κ) (T : Finset (Fin m)) (hlabel : Measurable label) (hX : Measurable X) (hint : Integrable Y μ) (hsq : Integrable (fun ω => Y ω ^ 2) μ) (hcenter : (∫ ω in cell label X k, (Y ω - c) ∂μ) = 0) : (∫ z in cellPattern label X k T, (∑ r ∈ T, (Y (z r) - c)) ^ 2 ∂Measure.pi (fun _ : Fin m => μ)) = (T.card : ℝ) * (∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) * cellMass μ label X k ^ (T.card - 1) * (1 - cellMass μ label X k) ^ (m - T.card) := by classical have hres : Integrable (fun ω => Y ω - c) μ := hint.sub (integrable_const c) have hres2 : Integrable (fun ω => (Y ω - c) ^ 2) μ := by have h := (hsq.sub (hint.const_mul (2 * c))).add (integrable_const (c ^ 2)) refine h.congr (Filter.Eventually.of_forall ?_) intro ω change Y ω ^ 2 - (2 * c) * Y ω + c ^ 2 = (Y ω - c) ^ 2 ring have hterm (i j : Fin m) : IntegrableOn (fun z : Fin m → Ω => (Y (z i) - c) * (Y (z j) - c)) (cellPattern label X k T) (Measure.pi (fun _ : Fin m => μ)) := by by_cases hij : i = j · subst j simpa only [pow_two] using (integrable_comp_eval (μ := fun _ : Fin m => μ) (i := i) hres2).integrableOn · let f : Fin m → Ω → ℝ := fun r ω => (if r = i then Y ω - c else 1) * (if r = j then Y ω - c else 1) have hf : ∀ r, Integrable (f r) μ := by intro r by_cases hri : r = i · subst r simpa [f, hij] using hres · by_cases hrj : r = j · subst r simpa [f, hri] using hres · simpa [f, hri, hrj] using (integrable_const (1 : ℝ) : Integrable _ μ) have hp (z : Fin m → Ω) : (∏ r, f r (z r)) = (Y (z i) - c) * (Y (z j) - c) := by simp only [f, Finset.prod_mul_distrib] simp exact (integrableOn_pattern_prod μ label X k T f hf).congr (Filter.Eventually.of_forall hp) have hexpand (z : Fin m → Ω) : (∑ r ∈ T, (Y (z r) - c)) ^ 2 = ∑ i ∈ T, ∑ j ∈ T, (Y (z i) - c) * (Y (z j) - c) := by rw [pow_two, Finset.sum_mul_sum] rw [integral_congr_ae (Filter.Eventually.of_forall hexpand)] rw [integral_finsetSum T (fun i _ => integrable_finsetSum T (fun j _ => hterm i j))] simp_rw [integral_finsetSum T (fun j _ => hterm _ j)] have hmom (i : Fin m) (hi : i ∈ T) (j : Fin m) (hj : j ∈ T) : (∫ z in cellPattern label X k T, (Y (z i) - c) * (Y (z j) - c) ∂Measure.pi (fun _ : Fin m => μ)) = if j = i then (∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) * cellMass μ label X k ^ (T.card - 1) * (1 - cellMass μ label X k) ^ (m - T.card) else 0 := by by_cases hji : j = i · subst j simpa only [ite_true, ← pow_two] using integral_pattern_coordinate_sq μ label X Y c k T hlabel hX i hi · simpa only [if_neg hji] using integral_pattern_cross_eq_zero μ label X Y c k T i j hi (Ne.symm hji) hcenter calc _ = ∑ i ∈ T, (∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) * cellMass μ label X k ^ (T.card - 1) * (1 - cellMass μ label X k) ^ (m - T.card) := by apply Finset.sum_congr rfl intro i hi rw [Finset.sum_congr rfl (fun j hj => hmom i hi j hj)] simp [hi] _ = _ := by rw [Finset.sum_const, nsmul_eq_mul]; ring
Causalean.Stat.Nonparametric.HistogramRegression.integral_centered_sum_sq_on_pattern · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:169 · uses cell , cellMass , cellPattern
7 supporting declarations (lemmas, instances)
  • cellPattern_eq_pi theorem — The membership pattern is the rectangle with the cell in selected coordinates and its complement elsewhere.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    k :
    κ
    T :
    cellPattern label X k T
    = Set.univ.pi (fun r => if r ∈ T then cell label X k else (cell label X k)ᶜ)
    Proof (Lean source)
    theorem cellPattern_eq_pi {m : ℕ} (label : A → κ) (X : Ω → A) (k : κ) (T : Finset (Fin m)) : cellPattern label X k T = Set.univ.pi (fun r => if r ∈ T then cell label X k else (cell label X k)ᶜ) := by ext z simp only [cellPattern, Set.mem_ofPred_eq, Set.mem_pi, Set.mem_univ, forall_true_left] constructor · intro hz r by_cases hr : r ∈ T · simpa [hr, cell] using (hz r).mpr hr · simpa [hr, cell] using (fun h => hr ((hz r).mp h)) · intro hz r by_cases hr : r ∈ T · simpa [hr, cell] using hz r · simpa [hr, cell] using hz r
    Causalean.Stat.Nonparametric.HistogramRegression.cellPattern_eq_pi · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:35
  • measurableSet_cellPattern theorem — Measurable labels and covariates give a measurable membership pattern for any selected subset.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    k :
    κ
    T :
    hlabel :
    hX :
    Proof (Lean source)
    theorem measurableSet_cellPattern {m : ℕ} (label : A → κ) (X : Ω → A) (k : κ) (T : Finset (Fin m)) (hlabel : Measurable label) (hX : Measurable X) : MeasurableSet (cellPattern label X k T) := by have hc : MeasurableSet (cell label X k) := (measurableSet_singleton k).preimage (hlabel.comp hX) rw [cellPattern_eq_pi] apply MeasurableSet.univ_pi intro r split_ifs <;> first | exact hc | exact hc.compl
    Causalean.Stat.Nonparametric.HistogramRegression.measurableSet_cellPattern · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:53
  • cellCount_on_pattern theorem — A sample in the specified membership pattern has cell count equal to the size of the selected index set.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    k :
    κ
    T :
    z :
    Fin m → Ω
    hz :
    z ∈ cellPattern label X k T
    cellCount label X k z = T.card
    Proof (Lean source)
    theorem cellCount_on_pattern {m : ℕ} (label : A → κ) (X : Ω → A) (k : κ) (T : Finset (Fin m)) (z : Fin m → Ω) (hz : z ∈ cellPattern label X k T) : cellCount label X k z = T.card := by unfold cellCount congr 1 ext r simpa only [mem_filter, Finset.mem_univ, true_and] using hz r
    Causalean.Stat.Nonparametric.HistogramRegression.cellCount_on_pattern · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:65
  • integrableOn_pattern_prod theorem — Integrable coordinate factors have an integrable product on every membership pattern under the iid law.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    k :
    κ
    T :
    f :
    Fin m → Ω → ℝ
    hf :
    ∀ r, Integrable (f r) μ
    IntegrableOn (fun z : Fin m → Ω => ∏ r, f r (z r)) (cellPattern label X k T) (Measure.pi (fun _ : Fin m => μ))
    Proof (Lean source)
    theorem integrableOn_pattern_prod {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (k : κ) (T : Finset (Fin m)) (f : Fin m → Ω → ℝ) (hf : ∀ r, Integrable (f r) μ) : IntegrableOn (fun z : Fin m → Ω => ∏ r, f r (z r)) (cellPattern label X k T) (Measure.pi (fun _ : Fin m => μ)) := by exact (Integrable.fintype_prod hf).integrableOn
    Causalean.Stat.Nonparametric.HistogramRegression.integrableOn_pattern_prod · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:75
  • integral_pattern_prod theorem — The coordinate product on a fixed membership pattern has integral equal to the product of the corresponding cell or complement set integrals under the iid probability law.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    k :
    κ
    T :
    f :
    Fin m → Ω → ℝ
    (∫ z in cellPattern label X k T, (∏ r, f r (z r)) ∂Measure.pi (fun _ : Fin m => μ))
    = ∏ r, ∫ ω in (if r ∈ T then cell label X k else (cell label X k)ᶜ), f r ω ∂μ
    Proof (Lean source)
    theorem integral_pattern_prod {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (k : κ) (T : Finset (Fin m)) (f : Fin m → Ω → ℝ) : (∫ z in cellPattern label X k T, (∏ r, f r (z r)) ∂Measure.pi (fun _ : Fin m => μ)) = ∏ r, ∫ ω in (if r ∈ T then cell label X k else (cell label X k)ᶜ), f r ω ∂μ := by rw [cellPattern_eq_pi, Measure.restrict_pi_pi] exact integral_fintype_prod_eq_prod f
    Causalean.Stat.Nonparametric.HistogramRegression.integral_pattern_prod · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:84
  • integral_pattern_coordinate_sq theorem — Measurable partition inputs and a selected coordinate give a pattern-restricted squared residual integral equal to its cell second moment times the masses of all other coordinates.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    Y :
    Ω → ℝ
    c :
    ℝ
    k :
    κ
    T :
    hlabel :
    hX :
    i :
    Fin m
    hi :
    i ∈ T
    (∫ z in cellPattern label X k T, (Y (z i) - c) ^ 2 ∂Measure.pi (fun _ : Fin m => μ))
    = (∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) * cellMass μ label X k ^ (T.card - 1) * (1 - cellMass μ label X k) ^ (m - T.card)
    Proof (Lean source)
    theorem integral_pattern_coordinate_sq {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (c : ℝ) (k : κ) (T : Finset (Fin m)) (hlabel : Measurable label) (hX : Measurable X) (i : Fin m) (hi : i ∈ T) : (∫ z in cellPattern label X k T, (Y (z i) - c) ^ 2 ∂Measure.pi (fun _ : Fin m => μ)) = (∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) * cellMass μ label X k ^ (T.card - 1) * (1 - cellMass μ label X k) ^ (m - T.card) := by classical let f : Fin m → Ω → ℝ := fun r ω => if r = i then (Y ω - c) ^ 2 else 1 have hp (z : Fin m → Ω) : (∏ r, f r (z r)) = (Y (z i) - c) ^ 2 := by simp [f] rw [← integral_congr_ae (Filter.Eventually.of_forall hp)] rw [integral_pattern_prod] let g : Fin m → ℝ := fun r => ∫ ω in (if r ∈ T then cell label X k else (cell label X k)ᶜ), f r ω ∂μ change (∏ r, g r) = _ have hc : MeasurableSet (cell label X k) := (measurableSet_singleton k).preimage (hlabel.comp hX) have hcompl : μ.real (cell label X k)ᶜ = 1 - cellMass μ label X k := by simpa [cellMass, measureReal_def] using measureReal_compl (μ := μ) hc rw [← Finset.prod_mul_prod_compl T g, ← Finset.mul_prod_erase T g hi] have hgi : g i = ∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ := by simp [g, f, hi] have hT : (∏ r ∈ T.erase i, g r) = cellMass μ label X k ^ (T.card - 1) := by calc _ = ∏ _r ∈ T.erase i, cellMass μ label X k := by apply Finset.prod_congr rfl intro r hr rcases Finset.mem_erase.mp hr with ⟨hri, hrT⟩ simp [g, f, hri, hrT, cellMass, measureReal_def] _ = _ := by simp [Finset.card_erase_of_mem hi] have hTc : (∏ r ∈ Tᶜ, g r) = (1 - cellMass μ label X k) ^ (m - T.card) := by calc _ = ∏ _r ∈ Tᶜ, (1 - cellMass μ label X k) := by apply Finset.prod_congr rfl intro r hr have hrT : r ∉ T := Finset.mem_compl.mp hr have hri : r ≠ i := fun h => hrT (h ▸ hi) simp [g, f, hri, hrT, hcompl] _ = _ := by simp [Finset.card_compl] rw [hgi, hT, hTc]
    Causalean.Stat.Nonparametric.HistogramRegression.integral_pattern_coordinate_sq · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:98
  • integral_pattern_cross_eq_zero theorem — Two distinct coordinates, the first of them selected, with centered cell residuals have zero cross moment on the fixed pattern.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    Y :
    Ω → ℝ
    c :
    ℝ
    k :
    κ
    T :
    i j :
    Fin m
    hi :
    i ∈ T
    hij :
    i ≠ j
    hcenter :
    (∫ ω in cell label X k, (Y ω - c) ∂μ) = 0
    (∫ z in cellPattern label X k T, (Y (z i) - c) * (Y (z j) - c) ∂Measure.pi (fun _ : Fin m => μ))
    = 0
    Proof (Lean source)
    theorem integral_pattern_cross_eq_zero {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (c : ℝ) (k : κ) (T : Finset (Fin m)) (i j : Fin m) (hi : i ∈ T) (hij : i ≠ j) (hcenter : (∫ ω in cell label X k, (Y ω - c) ∂μ) = 0) : (∫ z in cellPattern label X k T, (Y (z i) - c) * (Y (z j) - c) ∂Measure.pi (fun _ : Fin m => μ)) = 0 := by classical let f : Fin m → Ω → ℝ := fun r ω => (if r = i then Y ω - c else 1) * (if r = j then Y ω - c else 1) have hp (z : Fin m → Ω) : (∏ r, f r (z r)) = (Y (z i) - c) * (Y (z j) - c) := by simp only [f, Finset.prod_mul_distrib] simp rw [← integral_congr_ae (Filter.Eventually.of_forall hp), integral_pattern_prod] apply Finset.prod_eq_zero (Finset.mem_univ i) simpa [f, hi, hij] using hcenter
    Causalean.Stat.Nonparametric.HistogramRegression.integral_pattern_cross_eq_zero · Causalean/Stat/Nonparametric/HistogramRegression/PatternMoments.lean:148
Pattern­Means 2 core · 1 supporting This layer turns the closed rectangle moments into a reciprocal-count identity on each membership pattern. ★ integral_centeredCellMean_sq_on_pattern

Totalized centered means on membership patterns

This layer turns the closed rectangle moments into a reciprocal-count identity on each membership pattern. It also isolates square integrability of the zero-totalized empirical mean, including sample size zero. The global variance formula in Centered can then sum over patterns and invoke the count law, without another combinatorial grouping by cardinality.

def centeredCellMean reviewed
Causalean.Stat.Nonparametric.HistogramRegression

The zero-totalized empirical centered cell mean divides the cell sum of responses centered at the specified value by the cell count for the given partition, covariates, label, and sample, and equals zero when the sample has no observation in the cell.

Definition (Lean source)
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
c :
ℝ
k :
κ
z :
Fin m → Ω
centeredCellMean label X Y c k z :
ℝ
cellSum label X (fun ω => Y ω - c) k z / (cellCount label X k z : ℝ)
Causalean.Stat.Nonparametric.HistogramRegression.centeredCellMean · Causalean/Stat/Nonparametric/HistogramRegression/PatternMeans.lean:26
theorem integral_centeredCellMean_sq_on_pattern reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Measurable inputs and integrable response moments, zero cell residual mean, and positive cell mass give a patternwise squared centered-mean integral equal to the within-cell second moment times the patternwise totalized reciprocal-count integral.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
c :
ℝ
k :
κ
T :
hlabel :
hX :
hint :
hsq :
Integrable (fun ω => Y ω ^ 2) μ
hcenter :
(∫ ω in cell label X k, (Y ω - c) ∂μ) = 0
hp :
0 < cellMass μ label X k
(∫ z in cellPattern label X k T, (centeredCellMean label X Y c k z) ^ 2 ∂Measure.pi (fun _ : Fin m => μ))
= ((∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) / cellMass μ label X k) * (∫ z in cellPattern label X k T, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ))
Proof (Lean source)
theorem integral_centeredCellMean_sq_on_pattern {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (c : ℝ) (k : κ) (T : Finset (Fin m)) (hlabel : Measurable label) (hX : Measurable X) (hint : Integrable Y μ) (hsq : Integrable (fun ω => Y ω ^ 2) μ) (hcenter : (∫ ω in cell label X k, (Y ω - c) ∂μ) = 0) (hp : 0 < cellMass μ label X k) : (∫ z in cellPattern label X k T, (centeredCellMean label X Y c k z) ^ 2 ∂Measure.pi (fun _ : Fin m => μ)) = ((∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) / cellMass μ label X k) * (∫ z in cellPattern label X k T, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ)) := by -- On the pattern, cellCount=T.card and cellSum is the residual sum over T. -- Empty T gives zero on both sides. Otherwise apply the closed -- integral_centered_sum_sq_on_pattern and pull out the squared denominator. -- Obtain pattern mass via integral_pattern_prod with all factors equal to 1: -- p^T.card * (1-p)^(m-T.card). Cancel p>0 and T.card>0; handle p=1 without -- cancelling the complement mass. No choose/cardinality regrouping is needed. classical have hpat := measurableSet_cellPattern label X k T hlabel hX have hsum (z : Fin m → Ω) (hz : z ∈ cellPattern label X k T) : cellSum label X (fun ω => Y ω - c) k z = ∑ r ∈ T, (Y (z r) - c) := by have hfilter : (Finset.univ.filter fun r => label (X (z r)) = k) = T := by ext r simpa only [mem_filter, Finset.mem_univ, true_and] using hz r rw [cellSum, ← Finset.sum_filter, hfilter] have hmean : (∫ z in cellPattern label X k T, (centeredCellMean label X Y c k z) ^ 2 ∂Measure.pi (fun _ : Fin m => μ)) = ((T.card : ℝ) * (∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) * cellMass μ label X k ^ (T.card - 1) * (1 - cellMass μ label X k) ^ (m - T.card)) / (T.card : ℝ) ^ 2 := by calc _ = ∫ z in cellPattern label X k T, (∑ r ∈ T, (Y (z r) - c)) ^ 2 / (T.card : ℝ) ^ 2 ∂Measure.pi (fun _ : Fin m => μ) := by apply setIntegral_congr_fun hpat intro z hz change (centeredCellMean label X Y c k z) ^ 2 = _ unfold centeredCellMean rw [cellCount_on_pattern label X k T z hz, hsum z hz, div_pow] _ = _ := by rw [integral_div, integral_centered_sum_sq_on_pattern μ label X Y c k T hlabel hX hint hsq hcenter] by_cases hT : T.card = 0 · rw [hmean] have hrec : (∫ z in cellPattern label X k T, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ)) = 0 := by calc _ = ∫ z in cellPattern label X k T, (0 : ℝ) ∂Measure.pi (fun _ : Fin m => μ) := by apply setIntegral_congr_fun hpat intro z hz simp [cellCount_on_pattern label X k T z hz, hT] _ = 0 := by simp simp [hT, hrec] · have hnpos : 0 < T.card := Nat.pos_of_ne_zero hT have hn : (T.card : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hT have hc : MeasurableSet (cell label X k) := (measurableSet_singleton k).preimage (hlabel.comp hX) have hcompl : μ.real (cell label X k)ᶜ = 1 - cellMass μ label X k := by simpa [cellMass, measureReal_def] using measureReal_compl (μ := μ) hc have hmass : (∫ z in cellPattern label X k T, (1 : ℝ) ∂Measure.pi (fun _ : Fin m => μ)) = cellMass μ label X k ^ T.card * (1 - cellMass μ label X k) ^ (m - T.card) := by calc _ = ∫ z in cellPattern label X k T, (∏ _r : Fin m, (1 : ℝ)) ∂Measure.pi (fun _ : Fin m => μ) := by simp _ = ∏ r : Fin m, ∫ ω in (if r ∈ T then cell label X k else (cell label X k)ᶜ), (1 : ℝ) ∂μ := integral_pattern_prod μ label X k T (fun _ _ => 1) _ = _ := by rw [← Finset.prod_mul_prod_compl T] have hsel : (∏ r ∈ T, ∫ ω in (if r ∈ T then cell label X k else (cell label X k)ᶜ), (1 : ℝ) ∂μ) = cellMass μ label X k ^ T.card := by calc _ = ∏ _r ∈ T, cellMass μ label X k := by apply Finset.prod_congr rfl intro r hr simp [hr, cellMass, measureReal_def] _ = _ := by simp have hunsel : (∏ r ∈ Tᶜ, ∫ ω in (if r ∈ T then cell label X k else (cell label X k)ᶜ), (1 : ℝ) ∂μ) = (1 - cellMass μ label X k) ^ (m - T.card) := by calc _ = ∏ _r ∈ Tᶜ, (1 - cellMass μ label X k) := by apply Finset.prod_congr rfl intro r hr simp [Finset.mem_compl.mp hr, hcompl] _ = _ := by simp [Finset.card_compl] rw [hsel, hunsel] have hrec : (∫ z in cellPattern label X k T, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ)) = (T.card : ℝ)⁻¹ * (cellMass μ label X k ^ T.card * (1 - cellMass μ label X k) ^ (m - T.card)) := by calc _ = ∫ z in cellPattern label X k T, (T.card : ℝ)⁻¹ * (1 : ℝ) ∂Measure.pi (fun _ : Fin m => μ) := by apply setIntegral_congr_fun hpat intro z hz simp [cellCount_on_pattern label X k T z hz, hnpos] _ = _ := by rw [integral_const_mul, hmass] rw [hmean, hrec] by_cases hpone : cellMass μ label X k = 1 · simp only [hpone, one_pow, div_one] field_simp [hn, ne_of_gt hp] · have hpow : cellMass μ label X k ^ T.card = cellMass μ label X k ^ (T.card - 1) * cellMass μ label X k := by rw [← pow_succ, Nat.sub_add_cancel hnpos] rw [hpow] field_simp [hn, ne_of_gt hp]
Causalean.Stat.Nonparametric.HistogramRegression.integral_centeredCellMean_sq_on_pattern · Causalean/Stat/Nonparametric/HistogramRegression/PatternMeans.lean:101 · uses cell , cellCount , cellMass , cellPattern , centeredCellMean
1 supporting declaration (lemmas, instances)
  • integrable_centeredCellMean_sq theorem — Measurable partition inputs and responses with integrable first and second response moments give an integrable squared totalized centered cell mean under iid sampling.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    Y :
    Ω → ℝ
    c :
    ℝ
    k :
    κ
    hlabel :
    hX :
    hY :
    hint :
    hsq :
    Integrable (fun ω => Y ω ^ 2) μ
    Integrable (fun z : Fin m → Ω => (centeredCellMean label X Y c k z) ^ 2) (Measure.pi (fun _ : Fin m => μ))
    Proof (Lean source)
    theorem integrable_centeredCellMean_sq {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (c : ℝ) (k : κ) (hlabel : Measurable label) (hX : Measurable X) (hY : Measurable Y) (hint : Integrable Y μ) (hsq : Integrable (fun ω => Y ω ^ 2) μ) : Integrable (fun z : Fin m → Ω => (centeredCellMean label X Y c k z) ^ 2) (Measure.pi (fun _ : Fin m => μ)) := by -- First derive integrability of (Y-c)^2 from the two response moments. -- Measurability follows by finite sums, measurable_cellCount, and division. -- At count zero the quotient is zero. Otherwise its squared value is bounded -- by m times the sum of coordinate residual squares (finite Cauchy-Schwarz -- and count >= 1). Each coordinate square is integrable_comp_eval. classical have hres2 : Integrable (fun ω => (Y ω - c) ^ 2) μ := by have h := (hsq.sub (hint.const_mul (2 * c))).add (integrable_const (c ^ 2)) refine h.congr (Filter.Eventually.of_forall ?_) intro ω change Y ω ^ 2 - (2 * c) * Y ω + c ^ 2 = (Y ω - c) ^ 2 ring have hsum : Measurable (cellSum (m := m) label X (fun ω => Y ω - c) k) := by unfold cellSum apply Finset.measurable_fun_sum intro r _ exact Measurable.ite ((measurableSet_singleton k).preimage (hlabel.comp (hX.comp (measurable_pi_apply r)))) ((hY.comp (measurable_pi_apply r)).sub measurable_const) measurable_const have hcast : Measurable (fun z : Fin m → Ω => (cellCount label X k z : ℝ)) := (measurable_of_countable (fun n : ℕ => (n : ℝ))).comp (measurable_cellCount label X k hlabel hX) have hmeas : Measurable (fun z : Fin m → Ω => (centeredCellMean label X Y c k z) ^ 2) := (hsum.div hcast).pow_const 2 have hdom : Integrable (fun z : Fin m → Ω => (m : ℝ) * ∑ r : Fin m, (Y (z r) - c) ^ 2) (Measure.pi (fun _ : Fin m => μ)) := (integrable_finsetSum univ (fun r _ => integrable_comp_eval (μ := fun _ : Fin m => μ) (i := r) hres2)).const_mul _ refine hdom.mono' hmeas.aestronglyMeasurable (Filter.Eventually.of_forall ?_) intro z rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] have hnonneg : 0 ≤ (m : ℝ) * ∑ r : Fin m, (Y (z r) - c) ^ 2 := mul_nonneg (Nat.cast_nonneg _) (Finset.sum_nonneg (fun r _ => sq_nonneg _)) by_cases hn : cellCount label X k z = 0 · simpa [centeredCellMean, hn] using hnonneg · have hn1 : (1 : ℝ) ≤ (cellCount label X k z : ℝ) := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hn have hn2 : (1 : ℝ) ≤ (cellCount label X k z : ℝ) ^ 2 := by nlinarith have hcs := Finset.sum_mul_sq_le_sq_mul_sq univ (fun _ : Fin m => (1 : ℝ)) (fun r => if label (X (z r)) = k then Y (z r) - c else 0) have hcs' : (cellSum label X (fun ω => Y ω - c) k z) ^ 2 ≤ (m : ℝ) * ∑ r : Fin m, (Y (z r) - c) ^ 2 := by have hcs0 : (cellSum label X (fun ω => Y ω - c) k z) ^ 2 ≤ (m : ℝ) * ∑ r : Fin m, (if label (X (z r)) = k then Y (z r) - c else 0) ^ 2 := by simpa [cellSum] using hcs refine hcs0.trans ?_ apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg m) apply Finset.sum_le_sum intro r _ split_ifs <;> simp [sq_nonneg] simpa only [centeredCellMean, div_pow] using (div_le_self (sq_nonneg (cellSum label X (fun ω => Y ω - c) k z)) hn2).trans hcs'
    Causalean.Stat.Nonparametric.HistogramRegression.integrable_centeredCellMean_sq · Causalean/Stat/Nonparametric/HistogramRegression/PatternMeans.lean:34
Cell­Variance 1 core · 1 supporting Condition on the full subset of observations falling in one cell. ★ nonempty_cell_mse_le

Global centered cell-sample variance

Condition on the full subset of observations falling in one cell. Centering annuls cross terms, leaving the cell variance times the reciprocal count. The finite-pattern moments are isolated in PatternMoments, and their totalized-mean consequences in PatternMeans, independently of the binomial identity in Counts; the bounded-response consequence controls the nonempty centered mean. Clipping and the arbitrary empty default are handled separately in Centered. Related infrastructure, without an import dependency on it, is in Causalean.Stat.Sample.Stratified.CenteredNoiseBound and Causalean.Stat.Sample.OccupancyWeightedMean.MomentBounds.

theorem nonempty_cell_mse_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

A measurable partition and responses, unit-interval responses, and positive cell mass imply that the cell mass times the iid-sample expectation of the squared empirical cell mean centered at the population cell mean (taken as zero on an empty cell) is at most two over the sample size plus one.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
k :
κ
hlabel :
hX :
hY :
hbound :
∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
hp :
0 < cellMass μ label X k
cellMass μ label X k * (∫ z : Fin m → Ω, (centeredCellMean label X Y (cellMean μ label X Y k) k z) ^ 2 ∂Measure.pi (fun _ : Fin m => μ))
≤ 2 / (m + 1 : ℝ)
Proof (Lean source)
theorem nonempty_cell_mse_le {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (k : κ) (hlabel : Measurable label) (hX : Measurable X) (hY : Measurable Y) (hbound : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (hp : 0 < cellMass μ label X k) : cellMass μ label X k * (∫ z : Fin m → Ω, (centeredCellMean label X Y (cellMean μ label X Y k) k z) ^ 2 ∂Measure.pi (fun _ : Fin m => μ)) ≤ 2 / (m + 1 : ℝ) := by -- Dominate Y and Y^2 by 1 to obtain both integrability hypotheses. -- cellMean_mem_Icc bounds c. integral_sub, setIntegral_const, and hp -- give the zero residual set integral. The squared residual is at most 1 -- ae on the cell, so its set integral divided by p is at most 1. -- Invoke integral_centeredCellMean_sq_eq and the closed -- mass_mul_integral_inverse_count_le (rewriting its integral by Counts). -- Multipliers are nonnegative; sample size zero and p=1 need no exceptions. have hint : Integrable Y μ := by apply (integrable_const (1 : ℝ)).mono' hY.aestronglyMeasurable filter_upwards [hbound] with ω hω simpa [Real.norm_eq_abs, abs_of_nonneg hω.1] using hω.2 have hsq : Integrable (fun ω => Y ω ^ 2) μ := by apply (integrable_const (1 : ℝ)).mono' (hY.pow_const 2).aestronglyMeasurable filter_upwards [hbound] with ω hω rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] nlinarith [hω.1, hω.2] have hc := cellMean_mem_Icc μ label X Y k hY hbound have hresbound : ∀ᵐ ω ∂μ, (Y ω - cellMean μ label X Y k) ^ 2 ≤ 1 := by filter_upwards [hbound] with ω hω have hl : -1 ≤ Y ω - cellMean μ label X Y k := by linarith [hω.1, hc.2] have hu : Y ω - cellMean μ label X Y k ≤ 1 := by linarith [hω.2, hc.1] simpa using sq_le_sq' hl hu have hres : Integrable (fun ω => (Y ω - cellMean μ label X Y k) ^ 2) μ := by apply (integrable_const (1 : ℝ)).mono' ((hY.sub measurable_const).pow_const 2).aestronglyMeasurable filter_upwards [hresbound] with ω hω change ‖(Y ω - cellMean μ label X Y k) ^ 2‖ ≤ 1 rwa [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] have hcenter : (∫ ω in cell label X k, (Y ω - cellMean μ label X Y k) ∂μ) = 0 := by rw [integral_sub hint.integrableOn (integrable_const _), setIntegral_const] simp only [smul_eq_mul] change (∫ ω in cell label X k, Y ω ∂μ) - cellMass μ label X k * cellMean μ label X Y k = 0 rw [cellMean, mul_div_cancel₀ _ (ne_of_gt hp), sub_self] have hvar : (∫ ω in cell label X k, (Y ω - cellMean μ label X Y k) ^ 2 ∂μ) / cellMass μ label X k ≤ 1 := by apply (div_le_iff₀ hp).mpr have hle := integral_mono_ae (μ := μ.restrict (cell label X k)) hres.integrableOn (integrable_const (1 : ℝ)) (ae_restrict_of_ae hresbound) simpa [setIntegral_const, cellMass, Measure.real] using hle have hrecnonneg : 0 ≤ (∫ z : Fin m → Ω, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ)) := by apply integral_nonneg intro z dsimp only split_ifs <;> positivity rw [integral_centeredCellMean_sq_eq μ label X Y (cellMean μ label X Y k) k hlabel hX hY hint hsq hcenter hp, ← integral_cellCount_eq_binomial μ label X k (fun j => if 0 < j then (j : ℝ)⁻¹ else 0) hlabel hX] calc _ ≤ cellMass μ label X k * (1 * (∫ z : Fin m → Ω, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ))) := mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right hvar hrecnonneg) hp.le _ ≤ 2 / (m + 1 : ℝ) := by simpa only [one_mul] using mass_mul_integral_inverse_count_le (m := m) μ label X k hlabel hX hp
Causalean.Stat.Nonparametric.HistogramRegression.nonempty_cell_mse_le · Causalean/Stat/Nonparametric/HistogramRegression/CellVariance.lean:102 · uses cellMass , cellMean , centeredCellMean
1 supporting declaration (lemmas, instances)
  • integral_centeredCellMean_sq_eq theorem — Measurable inputs and integrable response moments, zero cell residual mean, and positive cell mass give the exact reciprocal-binomial-count variance formula.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    Y :
    Ω → ℝ
    c :
    ℝ
    k :
    κ
    hlabel :
    hX :
    hY :
    hint :
    hsq :
    Integrable (fun ω => Y ω ^ 2) μ
    hcenter :
    (∫ ω in cell label X k, (Y ω - c) ∂μ) = 0
    hp :
    0 < cellMass μ label X k
    (∫ z : Fin m → Ω, (centeredCellMean label X Y c k z) ^ 2 ∂Measure.pi (fun _ : Fin m => μ))
    = ((∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) / cellMass μ label X k) * ∑ j ∈ range (m + 1), binomialWeight m (cellMass μ label X k) j * (if 0 < j then (j : ℝ)⁻¹ else 0)
    Proof (Lean source)
    theorem integral_centeredCellMean_sq_eq {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (c : ℝ) (k : κ) (hlabel : Measurable label) (hX : Measurable X) (hY : Measurable Y) (hint : Integrable Y μ) (hsq : Integrable (fun ω => Y ω ^ 2) μ) (hcenter : (∫ ω in cell label X k, (Y ω - c) ∂μ) = 0) (hp : 0 < cellMass μ label X k) : (∫ z : Fin m → Ω, (centeredCellMean label X Y c k z) ^ 2 ∂Measure.pi (fun _ : Fin m => μ)) = ((∫ ω in cell label X k, (Y ω - c) ^ 2 ∂μ) / cellMass μ label X k) * ∑ j ∈ range (m + 1), binomialWeight m (cellMass μ label X k) j * (if 0 < j then (j : ℝ)⁻¹ else 0) := by -- Use integrable_centeredCellMean_sq and split both integrals over all -- membership patterns T : Finset (Fin m), a measurable disjoint cover. -- Sum integral_centeredCellMean_sq_on_pattern. The bounded inverse-count -- integrand is integrable; apply integral_cellCount_eq_binomial to it. -- This route avoids summing powersetCard/binomial coefficients a second time. classical let ν := Measure.pi (fun _ : Fin m => μ) let R : (Fin m → Ω) → ℝ := fun z => if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0 have hRmeas : Measurable R := (measurable_of_countable (fun j : ℕ => if 0 < j then (j : ℝ)⁻¹ else 0)).comp (measurable_cellCount label X k hlabel hX) have hR : Integrable R ν := by refine (integrable_const (1 : ℝ)).mono' hRmeas.aestronglyMeasurable (Filter.Eventually.of_forall ?_) intro z dsimp [R] split_ifs with hn · rw [abs_of_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _))] apply inv_le_one_of_one_le₀ exact_mod_cast hn · simp have hmeas := fun T : Finset (Fin m) => measurableSet_cellPattern label X k T hlabel hX have hdisj : Pairwise (onFun Disjoint (fun T : Finset (Fin m) => cellPattern label X k T)) := by intro T U hTU apply Set.disjoint_left.mpr intro z hzT hzU apply hTU ext r exact (hzT r).symm.trans (hzU r) have hcover : (⋃ T : Finset (Fin m), cellPattern label X k T) = univ := by apply Set.eq_univ_of_forall intro z apply Set.mem_iUnion.mpr refine ⟨Finset.univ.filter (fun r => label (X (z r)) = k), ?_⟩ intro r simp have hmean := integrable_centeredCellMean_sq (m := m) μ label X Y c k hlabel hX hY hint hsq have hsum := integral_iUnion_fintype hmeas hdisj (fun T => hmean.integrableOn (s := cellPattern label X k T)) have hsumR := integral_iUnion_fintype hmeas hdisj (fun T => hR.integrableOn (s := cellPattern label X k T)) rw [hcover, setIntegral_univ] at hsum hsumR rw [hsum] simp_rw [integral_centeredCellMean_sq_on_pattern μ label X Y c k _ hlabel hX hint hsq hcenter hp] rw [← Finset.mul_sum, ← hsumR] rw [integral_cellCount_eq_binomial μ label X k (fun j => if 0 < j then (j : ℝ)⁻¹ else 0) hlabel hX]
    Causalean.Stat.Nonparametric.HistogramRegression.integral_centeredCellMean_sq_eq · Causalean/Stat/Nonparametric/HistogramRegression/CellVariance.lean:33
Centered 1 core · 0 supporting Combine the closed-form centered-mean variance and empty-cell probability with the deterministic clipping comparison. ★ cell_estimation_mse_le

Totalized clipped cell-estimation risk

Combine the closed-form centered-mean variance and empty-cell probability with the deterministic clipping comparison. The fixed default may be any point in the unit interval. No lower cell-mass bound is required.

theorem cell_estimation_mse_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Measurable inputs, unit-interval responses and default, and positive cell mass imply mass-weighted cell-estimation MSE at most three over the sample-size successor.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
a :
ℝ
k :
κ
hlabel :
hX :
hY :
hbound :
∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
ha :
a ∈ Icc (0 : ℝ) 1
hp :
0 < cellMass μ label X k
cellMass μ label X k * (∫ z : Fin m → Ω, (cellEstimate label X Y a k z - cellMean μ label X Y k) ^ 2 ∂Measure.pi (fun _ : Fin m => μ))
≤ 3 / (m + 1 : ℝ)
Proof (Lean source)
theorem cell_estimation_mse_le {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (a : ℝ) (k : κ) (hlabel : Measurable label) (hX : Measurable X) (hY : Measurable Y) (hbound : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (ha : a ∈ Icc (0 : ℝ) 1) (hp : 0 < cellMass μ label X k) : cellMass μ label X k * (∫ z : Fin m → Ω, (cellEstimate label X Y a k z - cellMean μ label X Y k) ^ 2 ∂Measure.pi (fun _ : Fin m => μ)) ≤ 3 / (m + 1 : ℝ) := by -- Set c=cellMean and use cellMean_mem_Icc. The pointwise -- cellEstimate_sq_error_le comparison avoids lifting ae response bounds -- to every training coordinate: clipping contracts distance to c even for -- unbounded inputs. Integrability of the left loss is provided by -- integrable_cellEstimate_sq_error; the centered square uses PatternMeans. -- Integrate the comparison, identify the indicator expectation with -- empty_cell_probability, multiply by p, and add the closed nonempty and -- mass_mul_empty_probability_le bounds to obtain 3/(m+1). let ν := Measure.pi (fun _ : Fin m => μ) let c := cellMean μ label X Y k let E : (Fin m → Ω) → ℝ := fun z => if cellCount label X k z = 0 then 1 else 0 have hc := cellMean_mem_Icc μ label X Y k hY hbound have hint : Integrable Y μ := by apply (integrable_const (1 : ℝ)).mono' hY.aestronglyMeasurable filter_upwards [hbound] with ω hω simpa [Real.norm_eq_abs, abs_of_nonneg hω.1] using hω.2 have hsq : Integrable (fun ω => Y ω ^ 2) μ := by apply (integrable_const (1 : ℝ)).mono' (hY.pow_const 2).aestronglyMeasurable filter_upwards [hbound] with ω hω rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] nlinarith [hω.1, hω.2] have hcenter := integrable_centeredCellMean_sq (m := m) μ label X Y c k hlabel hX hY hint hsq have hs : MeasurableSet {z : Fin m → Ω | cellCount label X k z = 0} := (measurableSet_singleton 0).preimage (measurable_cellCount label X k hlabel hX) have hE : Integrable E ν := by have hmeas : Measurable E := Measurable.ite hs measurable_const measurable_const refine (integrable_const (1 : ℝ)).mono' hmeas.aestronglyMeasurable (Filter.Eventually.of_forall ?_) intro z simp only [E] split_ifs <;> norm_num have hEeq : (∫ z, E z ∂ν) = (1 - cellMass μ label X k) ^ m := by have hi := integral_indicator_one (μ := ν) hs have hi' : (∫ z, E z ∂ν) = (ν {z | cellCount label X k z = 0}).toReal := by simpa only [E, indicator, Set.mem_ofPred_eq, Pi.one_apply, measureReal_def] using hi rw [hi'] exact empty_cell_probability μ label X k hlabel hX have hle := integral_mono_ae (integrable_cellEstimate_sq_error μ label X Y a c k hlabel hX hY ha hc) (hcenter.add hE) (Filter.Eventually.of_forall (fun z => cellEstimate_sq_error_le label X Y a c k z ha hc)) change (∫ z, (cellEstimate label X Y a k z - c) ^ 2 ∂ν) ≤ ∫ z, (centeredCellMean label X Y c k z) ^ 2 + E z ∂ν at hle rw [integral_add hcenter hE, hEeq] at hle have hmul := mul_le_mul_of_nonneg_left hle hp.le have hn := nonempty_cell_mse_le (m := m) μ label X Y k hlabel hX hY hbound hp have he := mass_mul_empty_probability_le m (cellMass μ label X k) ⟨hp.le, measureReal_le_one⟩ dsimp [ν, c] at hmul rw [mul_add] at hmul exact hmul.trans (by calc _ ≤ 2 / (m + 1 : ℝ) + 1 / (m + 1 : ℝ) := add_le_add hn he _ = 3 / (m + 1 : ℝ) := by ring)
Causalean.Stat.Nonparametric.HistogramRegression.cell_estimation_mse_le · Causalean/Stat/Nonparametric/HistogramRegression/Centered.lean:25 · uses cellEstimate , cellMass , cellMean
Counts 1 core · 3 supporting This layer transfers iid product sampling to the real binomial weights already provided by Causalean. ★ mass_mul_integral_inverse_count_le

Binomial cell counts and empty-cell control

This layer transfers iid product sampling to the real binomial weights already provided by Causalean. The empty-cell inequality includes both endpoints of the probability interval and sample size zero. No regression or risk assumption is used here.

theorem mass_mul_integral_inverse_count_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

A measurable partition and positive cell mass give mass-weighted expected reciprocal count at most twice the reciprocal sample-size successor.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
k :
κ
hlabel :
hX :
hp :
0 < cellMass μ label X k
cellMass μ label X k * (∫ z : Fin m → Ω, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ))
≤ 2 / (m + 1 : ℝ)
Proof (Lean source)
theorem mass_mul_integral_inverse_count_le {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (k : κ) (hlabel : Measurable label) (hX : Measurable X) (hp : 0 < cellMass μ label X k) : cellMass μ label X k * (∫ z : Fin m → Ω, (if 0 < cellCount label X k z then (cellCount label X k z : ℝ)⁻¹ else 0) ∂Measure.pi (fun _ : Fin m => μ)) ≤ 2 / (m + 1 : ℝ) := by rw [integral_cellCount_eq_binomial μ label X k (fun j => if 0 < j then (j : ℝ)⁻¹ else 0) hlabel hX] have hp1 : cellMass μ label X k ≤ 1 := measureReal_le_one have h := mul_le_mul_of_nonneg_left (binomial_totalized_inverse_count_le m (cellMass μ label X k) hp hp1) hp.le calc _ ≤ cellMass μ label X k * (2 / (((m + 1 : ℕ) : ℝ) * cellMass μ label X k)) := h _ = 2 / (m + 1 : ℝ) := by push_cast field_simp
Causalean.Stat.Nonparametric.HistogramRegression.mass_mul_integral_inverse_count_le · Causalean/Stat/Nonparametric/HistogramRegression/Counts.lean:146 · uses cellCount , cellMass
3 supporting declarations (lemmas, instances)
  • integral_cellCount_eq_binomial theorem — A measurable covariate partition implies that expectations of functions of a cell count equal the corresponding binomial sum.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    k :
    κ
    F :
    ℕ → ℝ
    hlabel :
    hX :
    (∫ z : Fin m → Ω, F (cellCount label X k z) ∂Measure.pi (fun _ : Fin m => μ))
    = ∑ j ∈ range (m + 1), binomialWeight m (cellMass μ label X k) j * F j
    Proof (Lean source)
    theorem integral_cellCount_eq_binomial {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (k : κ) (F : ℕ → ℝ) (hlabel : Measurable label) (hX : Measurable X) : (∫ z : Fin m → Ω, F (cellCount label X k z) ∂Measure.pi (fun _ : Fin m => μ)) = ∑ j ∈ range (m + 1), binomialWeight m (cellMass μ label X k) j * F j := by -- Push the sample through its Bool membership design, integrate the finite -- design law, and reuse sum_bernoulli_eq_binomial. Arbitrary F is harmless: -- the count has finite range, so its composition is integrable. classical let B : Ω → Bool := fun ω => if label (X ω) = k then true else false have hs : MeasurableSet (cell label X k) := (measurableSet_singleton k).preimage (hlabel.comp hX) have hB : Measurable B := Measurable.ite hs measurable_const measurable_const have hp0 : 0 ≤ cellMass μ label X k := ENNReal.toReal_nonneg have hp1 : cellMass μ label X k ≤ 1 := by exact measureReal_le_one have hmap : μ.map B = bernoulliBool (cellMass μ label X k) := by apply Measure.ext_of_singleton intro b rw [Measure.map_apply hB (measurableSet_singleton b)] cases b · have he : B ⁻¹' {false} = (cell label X k)ᶜ := by ext ω simp [B, cell] rw [he, measure_compl hs (measure_ne_top μ _)] simp [bernoulliBool, cellMass, ENNReal.ofReal_sub, ENNReal.ofReal_toReal (measure_ne_top μ _)] · have he : B ⁻¹' {true} = cell label X k := by ext ω simp [B, cell] rw [he] simp [bernoulliBool, cellMass, ENNReal.ofReal_toReal (measure_ne_top μ _)] let T : (Fin m → Ω) → (Fin m → Bool) := fun z r => B (z r) have hT : Measurable T := measurable_pi_lambda _ fun r => hB.comp (measurable_pi_apply r) have hpi : (Measure.pi (fun _ : Fin m => μ)).map T = Measure.pi (fun _ : Fin m => bernoulliBool (cellMass μ label X k)) := by rw [Measure.pi_map_pi (fun _ => hB.aemeasurable)] simp only [hmap] have : IsProbabilityMeasure (bernoulliBool (cellMass μ label X k)) := Causalean.Mathlib.Probability.bernoulliBool_isProbabilityMeasure hp0 hp1 let G : (Fin m → Bool) → ℝ := fun b => F (Finset.univ.filter fun r => b r = true).card have hcount (z : Fin m → Ω) : G (T z) = F (cellCount label X k z) := by simp [G, T, B, cellCount] rw [← show (fun z => G (T z)) = (fun z => F (cellCount label X k z)) from funext hcount, ← integral_map hT.aemeasurable (measurable_of_finite G).aestronglyMeasurable, hpi, integral_fintype Integrable.of_finite] calc _ = ∑ b : Fin m → Bool, (∏ r, if b r then cellMass μ label X k else 1 - cellMass μ label X k) * F (Finset.univ.filter fun r => b r = true).card := by apply Finset.sum_congr rfl intro b _ rw [measureReal_def, Measure.pi_singleton, ENNReal.toReal_prod] simp only [smul_eq_mul, G] congr 1 apply Finset.prod_congr rfl intro r _ cases b r <;> simp [bernoulliBool, hp0, sub_nonneg.mpr hp1] _ = _ := by simpa using sum_bernoulli_eq_binomial (ι := Fin m) (cellMass μ label X k) F
    Causalean.Stat.Nonparametric.HistogramRegression.integral_cellCount_eq_binomial · Causalean/Stat/Nonparametric/HistogramRegression/Counts.lean:27
  • empty_cell_probability theorem — A measurable covariate partition gives empty-cell probability equal to the failure probability raised to the sample size.
    Ω :
    Type u_1
    shared
    A :
    Type u_2
    shared
    κ :
    Type u_3
    shared
    m :
    ℕ
    label :
    A → κ
    X :
    Ω → A
    k :
    κ
    hlabel :
    hX :
    ((Measure.pi (fun _ : Fin m => μ)) {z | cellCount label X k z = 0}).toReal
    = (1 - cellMass μ label X k) ^ m
    Proof (Lean source)
    theorem empty_cell_probability {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (k : κ) (hlabel : Measurable label) (hX : Measurable X) : ((Measure.pi (fun _ : Fin m => μ)) {z | cellCount label X k z = 0}).toReal = (1 - cellMass μ label X k) ^ m := by classical have hs : MeasurableSet {z : Fin m → Ω | cellCount label X k z = 0} := (measurableSet_singleton 0).preimage (measurable_cellCount label X k hlabel hX) have h := integral_cellCount_eq_binomial (m := m) μ label X k (fun j => if j = 0 then 1 else 0) hlabel hX have hi : (∫ z : Fin m → Ω, (if cellCount label X k z = 0 then (1 : ℝ) else 0) ∂Measure.pi (fun _ : Fin m => μ)) = ((Measure.pi (fun _ : Fin m => μ)) {z | cellCount label X k z = 0}).toReal := by simpa only [indicator, Set.mem_ofPred_eq, Pi.one_apply, measureReal_def] using (integral_indicator_one (μ := Measure.pi (fun _ : Fin m => μ)) hs) rw [hi] at h simpa [binomialWeight] using h
    Causalean.Stat.Nonparametric.HistogramRegression.empty_cell_probability · Causalean/Stat/Nonparametric/HistogramRegression/Counts.lean:100
  • mass_mul_empty_probability_le theorem — A probability in the unit interval satisfies the mass-weighted empty-cell bound, including zero observations.
    m :
    ℕ
    p :
    ℝ
    hp :
    p ∈ Icc (0 : ℝ) 1
    p * (1 - p) ^ m ≤ 1 / (m + 1 : ℝ)
    Proof (Lean source)
    theorem mass_mul_empty_probability_le (m : ℕ) (p : ℝ) (hp : p ∈ Icc (0 : ℝ) 1) : p * (1 - p) ^ m ≤ 1 / (m + 1 : ℝ) := by -- The first m+1 terms of the geometric series are each at least (1-p)^m; -- multiply by p and use the telescoping sum 1-(1-p)^(m+1) ≤ 1. have hq0 : 0 ≤ 1 - p := sub_nonneg.mpr hp.2 have hq1 : 1 - p ≤ 1 := by linarith [hp.1] have hsum : (m + 1 : ℝ) * (1 - p) ^ m ≤ ∑ j ∈ range (m + 1), (1 - p) ^ j := by calc _ = ∑ j ∈ range (m + 1), (1 - p) ^ m := by simp _ ≤ _ := by apply Finset.sum_le_sum intro j hj exact pow_le_pow_of_le_one hq0 hq1 (by simpa using Finset.mem_range.mp hj) have hid := geom_sum_mul_neg (1 - p) (m + 1) have hbound : p * ((m + 1 : ℝ) * (1 - p) ^ m) ≤ 1 := by have hmul := mul_le_mul_of_nonneg_left hsum hp.1 have hpow := pow_nonneg hq0 (m + 1) simp only [sub_sub_cancel] at hid nlinarith apply (le_div_iff₀ (by positivity : (0 : ℝ) < m + 1)).2 nlinarith
    Causalean.Stat.Nonparametric.HistogramRegression.mass_mul_empty_probability_le · Causalean/Stat/Nonparametric/HistogramRegression/Counts.lean:121
Cubical­Risk 1 core · 2 supporting For any observation law with unit-cube covariates and bounded responses whose conditional mean is Hölder, the ceiling-mesh histogram has squared bias of order b^(2β) and variance of order 1/(m*b^d). ★ optimized_cubical_histogram_risk_le

Hölder cubical histogram risk and optimized rate

For any observation law with unit-cube covariates and bounded responses whose conditional mean is Hölder, the ceiling-mesh histogram has squared bias of order b^(2β) and variance of order 1/(m*b^d). The optimized bandwidth gives the explicit rate m^(-2β/(2β+d)). Constants depend only on dimension and the Hölder constant/exponent, and all cube boundary points and empty cells are kept.

The integrated marginal loss and zero-empty-cell convention are classical: Andrew Nobel, "Histogram Regression Estimation Using Data-dependent Partitions" (1995), introduction and equation (2), https://nobel.web.unc.edu/wp-content/uploads/sites/13591/2017/01/histreg.pdf. Here the default is generalized to any fixed point of the unit interval; the finite-sample rate is derived from the closed occupancy and mesh lemmas.

theorem optimized_cubical_histogram_risk_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Measurable regression inputs, bounded responses and default, the conditional mean identity, positive Hölder smoothness and nonnegative constant, a Hölder bound, and at least one observation give the bound (2 C² (√d)^(2β) + 6 · 2^d) · m^(-2β/(2β+d)) on the expected integrated squared risk, under iid sampling, of the cubical histogram with the optimized bandwidth m^(-1/(2β+d)).

Formal statement
Ω :
Type u_1
shared
d m :
ℕ
X :
Ω → Cube d
Y :
Ω → ℝ
g :
Cube d → ℝ
a β C :
ℝ
hX :
hY :
hg :
hbound :
∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
ha :
a ∈ Icc (0 : ℝ) 1
hmean :
hβ :
0 < β
hC :
0 ≤ C
hm :
1 ≤ m
hholder :
∀ x y, |g x - g y| ≤ C * (dist x y) ^ β
risk μ (Measure.pi (fun _ : Fin m => μ)) (cubeLabel (optimizedBandwidth d β m)) X Y a g
≤ (2 * C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) + 6 * (2 : ℝ) ^ d) * (m : ℝ) ^ (-(2 * β / (2 * β + d)))
Proof (Lean source)
theorem optimized_cubical_histogram_risk_le {d m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (X : Ω → Cube d) (Y : Ω → ℝ) (g : Cube d → ℝ) (a β C : ℝ) (hX : Measurable X) (hY : Measurable Y) (hg : Measurable g) (hbound : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (ha : a ∈ Icc (0 : ℝ) 1) (hmean : ConditionalMean μ X Y g) (hβ : 0 < β) (hC : 0 ≤ C) (hm : 1 ≤ m) (hholder : ∀ x y, |g x - g y| ≤ C * (dist x y) ^ β) : risk μ (Measure.pi (fun _ : Fin m => μ)) (cubeLabel (optimizedBandwidth d β m)) X Y a g ≤ (2 * C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) + 6 * (2 : ℝ) ^ d) * (m : ℝ) ^ (-(2 * β / (2 * β + d))) := by -- Use the closed balancing identity for bias and the optimized ceiling-count -- comparison for variance, then factor their common sample-size power. obtain ⟨hb, hb1⟩ := optimizedBandwidth_mem d β m hβ hm have hr := cubical_histogram_risk_le (m := m) μ X Y g a β C (optimizedBandwidth d β m) hX hY hg hbound ha hmean hβ hC hb hb1 hholder rw [(optimized_power_identities d β m hβ hm).1] at hr refine hr.trans ?_ have hv := mul_le_mul_of_nonneg_left (optimized_mesh_variance_le d β m hβ hm) (by norm_num : (0 : ℝ) ≤ 6) calc _ ≤ 2 * C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * (m : ℝ) ^ (-(2 * β / (2 * β + d))) + 6 * ((2 : ℝ) ^ d * (m : ℝ) ^ (-(2 * β / (2 * β + d)))) := by apply add_le_add le_rfl simpa only [mul_div_assoc] using hv _ = _ := by ring
Causalean.Stat.Nonparametric.HistogramRegression.optimized_cubical_histogram_risk_le · Causalean/Stat/Nonparametric/HistogramRegression/CubicalRisk.lean:124 · uses ConditionalMean , Cube , cubeLabel , meshCount , optimizedBandwidth , risk
2 supporting declarations (lemmas, instances)
  • cubical_histogram_risk_le theorem — Measurable cube covariates, responses, and regression function, bounded responses and default, the conditional mean identity, positive smoothness and a nonnegative Hölder constant, a Hölder bound, and a bandwidth in (0,1] imply the explicit bias-plus-cell-count histogram risk bound.
    Ω :
    Type u_1
    shared
    d m :
    ℕ
    X :
    Ω → Cube d
    Y :
    Ω → ℝ
    g :
    Cube d → ℝ
    a β C b :
    ℝ
    hX :
    hY :
    hg :
    hbound :
    ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
    ha :
    a ∈ Icc (0 : ℝ) 1
    hmean :
    hβ :
    0 < β
    hC :
    0 ≤ C
    hb :
    0 < b
    hb1 :
    b ≤ 1
    hholder :
    ∀ x y, |g x - g y| ≤ C * (dist x y) ^ β
    risk μ (Measure.pi (fun _ : Fin m => μ)) (cubeLabel b) X Y a g
    ≤ 2 * C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * b ^ (2 * β)
    + 6 * (meshCount b : ℝ) ^ d / (m + 1 : ℝ)
    Proof (Lean source)
    theorem cubical_histogram_risk_le {d m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (X : Ω → Cube d) (Y : Ω → ℝ) (g : Cube d → ℝ) (a β C b : ℝ) (hX : Measurable X) (hY : Measurable Y) (hg : Measurable g) (hbound : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (ha : a ∈ Icc (0 : ℝ) 1) (hmean : ConditionalMean μ X Y g) (hβ : 0 < β) (hC : 0 ≤ C) (hb : 0 < b) (hb1 : b ≤ 1) (hholder : ∀ x y, |g x - g y| ≤ C * (dist x y) ^ β) : risk μ (Measure.pi (fun _ : Fin m => μ)) (cubeLabel b) X Y a g ≤ 2 * C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * b ^ (2 * β) + 6 * (meshCount b : ℝ) ^ d / (m + 1 : ℝ) := by -- The constant oscillation envelope sums against cell masses totaling one. -- Count only positive-mass cells before comparing with the full label type. -- Nonnegative-base rpow identities retain the zero-dimensional cube case. let D : ℝ := C * (sqrt (d : ℝ)) ^ β * b ^ β have hD : 0 ≤ D := by dsimp [D]; positivity have hosc : ∀ k x y, cubeLabel b x = k → cubeLabel b y = k → |g x - g y| ≤ D := by intro k x y hx hy exact cube_holder_oscillation g β C b hβ hC hb hb1 hholder x y (hx.trans hy.symm) have hr := histogram_risk_le (m := m) μ (cubeLabel b) X Y g a (fun _ => D) (measurable_cubeLabel d b) hX hY hg hbound ha hmean (fun _ => hD) hosc have hmass := sum_positiveCells_mass μ (cubeLabel b) X (measurable_cubeLabel d b) hX have hsum : (∑ k ∈ positiveCells μ (cubeLabel b) X, cellMass μ (cubeLabel b) X k * D ^ 2) = D ^ 2 := by rw [← Finset.sum_mul, hmass, one_mul] have hcard : ((positiveCells μ (cubeLabel b) X).card : ℝ) ≤ (meshCount b : ℝ) ^ d := by have hn := Finset.card_le_univ (positiveCells μ (cubeLabel b) X) rw [cube_label_card d b] at hn exact_mod_cast hn have hsqrt : ((sqrt (d : ℝ)) ^ β) ^ (2 : ℕ) = (sqrt (d : ℝ)) ^ (2 * β) := by rw [← Real.rpow_two, ← Real.rpow_mul (Real.sqrt_nonneg _)] congr 1 ring have hbpow : (b ^ β) ^ (2 : ℕ) = b ^ (2 * β) := by rw [← Real.rpow_two, ← Real.rpow_mul hb.le] congr 1 ring have hDsquare : D ^ 2 = C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * b ^ (2 * β) := by dsimp [D] rw [mul_pow, mul_pow, hsqrt, hbpow] rw [hsum, hDsquare] at hr calc _ ≤ 2 * (C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * b ^ (2 * β)) + 6 * ((positiveCells μ (cubeLabel b) X).card : ℝ) / (m + 1 : ℝ) := hr _ ≤ 2 * (C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * b ^ (2 * β)) + 6 * (meshCount b : ℝ) ^ d / (m + 1 : ℝ) := by apply add_le_add le_rfl exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hcard (by norm_num)) (by positivity) _ = _ := by ring
    Causalean.Stat.Nonparametric.HistogramRegression.cubical_histogram_risk_le · Causalean/Stat/Nonparametric/HistogramRegression/CubicalRisk.lean:32
  • cubical_histogram_bandwidth_risk_le theorem — Measurable regression inputs, bounded responses and default, the conditional mean identity, positive Hölder smoothness and a nonnegative constant, a Hölder bound, a bandwidth in (0,1], and at least one observation imply the bias-plus-inverse-effective-sample-size risk bound.
    Ω :
    Type u_1
    shared
    d m :
    ℕ
    X :
    Ω → Cube d
    Y :
    Ω → ℝ
    g :
    Cube d → ℝ
    a β C b :
    ℝ
    hX :
    hY :
    hg :
    hbound :
    ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
    ha :
    a ∈ Icc (0 : ℝ) 1
    hmean :
    hβ :
    0 < β
    hC :
    0 ≤ C
    hb :
    0 < b
    hb1 :
    b ≤ 1
    hm :
    1 ≤ m
    hholder :
    ∀ x y, |g x - g y| ≤ C * (dist x y) ^ β
    risk μ (Measure.pi (fun _ : Fin m => μ)) (cubeLabel b) X Y a g
    ≤ 2 * C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * b ^ (2 * β)
    + (6 * (2 : ℝ) ^ d) / ((m : ℝ) * b ^ d)
    Proof (Lean source)
    theorem cubical_histogram_bandwidth_risk_le {d m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (X : Ω → Cube d) (Y : Ω → ℝ) (g : Cube d → ℝ) (a β C b : ℝ) (hX : Measurable X) (hY : Measurable Y) (hg : Measurable g) (hbound : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (ha : a ∈ Icc (0 : ℝ) 1) (hmean : ConditionalMean μ X Y g) (hβ : 0 < β) (hC : 0 ≤ C) (hb : 0 < b) (hb1 : b ≤ 1) (hm : 1 ≤ m) (hholder : ∀ x y, |g x - g y| ≤ C * (dist x y) ^ β) : risk μ (Measure.pi (fun _ : Fin m => μ)) (cubeLabel b) X Y a g ≤ 2 * C ^ 2 * (sqrt (d : ℝ)) ^ (2 * β) * b ^ (2 * β) + (6 * (2 : ℝ) ^ d) / ((m : ℝ) * b ^ d) := by -- First bound the ceiling cell count by (2/b)^d; then replace m+1 by m. have hmpos : 0 < (m : ℝ) := by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one hm) refine (cubical_histogram_risk_le μ X Y g a β C b hX hY hg hbound ha hmean hβ hC hb hb1 hholder).trans ?_ apply add_le_add le_rfl calc 6 * (meshCount b : ℝ) ^ d / (m + 1 : ℝ) ≤ 6 * ((2 : ℝ) ^ d / b ^ d) / (m + 1 : ℝ) := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (mesh_count_pow_le d b hb hb1) (by norm_num)) (by positivity) _ ≤ 6 * ((2 : ℝ) ^ d / b ^ d) / (m : ℝ) := div_le_div_of_nonneg_left (by positivity) hmpos (by linarith) _ = _ := by ring
    Causalean.Stat.Nonparametric.HistogramRegression.cubical_histogram_bandwidth_risk_le · Causalean/Stat/Nonparametric/HistogramRegression/CubicalRisk.lean:91
Estimator­Comparison 1 core · 1 supporting Clipping an empirical mean to the unit interval contracts squared distance to every unit-interval center. ★ cellEstimate_sq_error_le

Clipping and empty-default comparisons

Clipping an empirical mean to the unit interval contracts squared distance to every unit-interval center. An empty cell contributes at most one when the default lies in the same interval. These deterministic comparisons do not assume bounded responses; they separate estimator algebra from the iid variance analysis. The clipped squared error is integrable under every iid probability law with measurable inputs.

theorem cellEstimate_sq_error_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

A unit-interval default and center give a pointwise bound on squared cell-estimation error by the squared totalized centered empirical mean plus the empty-cell indicator.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
a c :
ℝ
k :
κ
z :
Fin m → Ω
ha :
a ∈ Icc (0 : ℝ) 1
hc :
c ∈ Icc (0 : ℝ) 1
(cellEstimate label X Y a k z - c) ^ 2
≤ (centeredCellMean label X Y c k z) ^ 2 + (if cellCount label X k z = 0 then 1 else 0)
Proof (Lean source)
theorem cellEstimate_sq_error_le {m : ℕ} (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (a c : ℝ) (k : κ) (z : Fin m → Ω) (ha : a ∈ Icc (0 : ℝ) 1) (hc : c ∈ Icc (0 : ℝ) 1) : (cellEstimate label X Y a k z - c) ^ 2 ≤ (centeredCellMean label X Y c k z) ^ 2 + (if cellCount label X k z = 0 then 1 else 0) := by -- Split on count zero. Then centeredCellMean=0 and |a-c|≤1. -- For positive count N, expand cellSum(Y-c)=cellSum(Y)-c*N -- using Finset.sum_sub_distrib and Finset.card_filter. Thus the centered -- mean equals cellSum(Y)/N-c. For any t and c∈[0,1], -- (clip t-c)^2≤(t-c)^2: split t≤0, 0≤t≤1, and 1≤t, and use -- sq_le_sq / nlinarith. No bounds on Y or probabilistic assumptions are needed. classical by_cases hn : cellCount label X k z = 0 · simp only [cellEstimate, hn, if_pos, centeredCellMean, Nat.cast_zero, div_zero] simpa using (sq_le_sq' (by linarith [ha.1, hc.2]) (by linarith [ha.2, hc.1]) : (a - c) ^ 2 ≤ (1 : ℝ) ^ 2) · have hsum : cellSum label X (fun ω => Y ω - c) k z = cellSum label X Y k z - c * (cellCount label X k z : ℝ) := by unfold cellSum cellCount rw [← Finset.sum_filter, ← Finset.sum_filter, Finset.sum_sub_distrib] simp [mul_comm] have hmean : centeredCellMean label X Y c k z = cellSum label X Y k z / (cellCount label X k z : ℝ) - c := by rw [centeredCellMean, hsum, sub_div, mul_div_cancel_right₀ c (Nat.cast_ne_zero.mpr hn)] simp only [cellEstimate, hn, if_false, hmean, add_zero] generalize cellSum label X Y k z / (cellCount label X k z : ℝ) = t by_cases ht0 : t ≤ 0 · rw [clip, min_eq_right (by linarith : t ≤ 1), max_eq_left ht0] nlinarith [mul_nonneg (neg_nonneg.mpr ht0) hc.1, sq_nonneg t] · have ht0' : 0 ≤ t := le_of_not_ge ht0 by_cases ht1 : t ≤ 1 · simp [clip, min_eq_right ht1, max_eq_right ht0'] · have ht1' : 1 ≤ t := le_of_not_ge ht1 rw [clip, min_eq_left ht1', max_eq_right (by norm_num : (0 : ℝ) ≤ 1)] nlinarith [mul_nonneg (sub_nonneg.mpr ht1') (sub_nonneg.mpr hc.2), sq_nonneg (t - 1)]
Causalean.Stat.Nonparametric.HistogramRegression.cellEstimate_sq_error_le · Causalean/Stat/Nonparametric/HistogramRegression/EstimatorComparison.lean:27 · uses cellCount , cellEstimate , centeredCellMean
1 supporting declaration (lemmas, instances)
IIDTransfer 1 core · 1 supporting The integrated squared histogram loss is a measurable function of the training tuple. ★ integral_histogram_loss_eq_risk_iid

Transferring histogram loss along an iid sample law

The integrated squared histogram loss is a measurable function of the training tuple. Independent observations with a common law therefore have exactly the same expected integrated loss as canonical product samples. This layer does not require bounded responses or a conditional mean, and is independent of the statistical risk inequality in Risk.

theorem integral_histogram_loss_eq_risk_iid reviewed
Causalean.Stat.Nonparametric.HistogramRegression

Measurable iid observation maps with a common law and measurable partition inputs, responses, and target give equality of expected integrated squared histogram loss on the original sample space and the canonical product sample space.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
S :
Z :
Fin m → S → Ω
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
g :
A → ℝ
a :
ℝ
hZ :
∀ r, Measurable (Z r)
hind :
iIndepFun Z ν
hident :
∀ r, IdentDistrib (Z r) id ν μ
hlabel :
hX :
hY :
hg :
(∫ s, (∫ ω, (histogram label X Y a (fun r => Z r s) (X ω) - g (X ω)) ^ 2 ∂μ) ∂ν)
= risk μ (Measure.pi (fun _ : Fin m => μ)) label X Y a g
Proof (Lean source)
theorem integral_histogram_loss_eq_risk_iid {m : ℕ} {S : Type*} [MeasurableSpace S] (μ : Measure Ω) [IsProbabilityMeasure μ] (ν : Measure S) [IsProbabilityMeasure ν] (Z : Fin m → S → Ω) (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (g : A → ℝ) (a : ℝ) (hZ : ∀ r, Measurable (Z r)) (hind : iIndepFun Z ν) (hident : ∀ r, IdentDistrib (Z r) id ν μ) (hlabel : Measurable label) (hX : Measurable X) (hY : Measurable Y) (hg : Measurable g) : (∫ s, (∫ ω, (histogram label X Y a (fun r => Z r s) (X ω) - g (X ω)) ^ 2 ∂μ) ∂ν) = risk μ (Measure.pi (fun _ : Fin m => μ)) label X Y a g := by -- Apply iIndepFun_iff_map_fun_eq_pi_map to the measurable tuple map, -- rewrite each marginal using (hident r).map_eq and Measure.map_id, -- and use integral_map with measurable_integrated_sq_loss. This includes -- m=0 and requires no standard-Borel structure on Ω or S. have hlaw : ν.map (fun s r => Z r s) = Measure.pi (fun _ : Fin m => μ) := by rw [(iIndepFun_iff_map_fun_eq_pi_map (fun r => (hZ r).aemeasurable)).mp hind] congr 1 funext r exact (hident r).map_eq.trans (Measure.map_id) have hloss := measurable_integrated_sq_loss (m := m) μ label X Y g a hlabel hX hY hg unfold risk rw [← hlaw] exact (integral_map (measurable_pi_lambda _ hZ).aemeasurable hloss.stronglyMeasurable.aestronglyMeasurable).symm
Causalean.Stat.Nonparametric.HistogramRegression.integral_histogram_loss_eq_risk_iid · Causalean/Stat/Nonparametric/HistogramRegression/IIDTransfer.lean:51 · uses histogram , risk
1 supporting declaration (lemmas, instances)
Partition­Totals 1 core · 1 supporting These label-API bridges reuse Mathlib's finite disjoint-union integral theorem, then remove zero-mass fibers. ★ integral_eq_sum_positive_cells

Integration over the positive-mass partition

These label-API bridges reuse Mathlib's finite disjoint-union integral theorem, then remove zero-mass fibers. They supply the partition sum for integrated risk and the mass-one simplification for a constant cubical oscillation envelope. Zero-mass cells are retained in the estimator and omitted only from integrals.

theorem integral_eq_sum_positive_cells reviewed
Causalean.Stat.Nonparametric.HistogramRegression

A measurable finite partition and covariates and an integrable observation function give its integral as the sum of set integrals over positive-mass cells.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
label :
A → κ
X :
Ω → A
f :
Ω → ℝ
hlabel :
hX :
hf :
(∫ ω, f ω ∂μ) = ∑ k ∈ positiveCells μ label X, ∫ ω in cell label X k, f ω ∂μ
Proof (Lean source)
theorem integral_eq_sum_positive_cells (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (f : Ω → ℝ) (hlabel : Measurable label) (hX : Measurable X) (hf : Integrable f μ) : (∫ ω, f ω ∂μ) = ∑ k ∈ positiveCells μ label X, ∫ ω in cell label X k, f ω ∂μ := by -- Apply integral_iUnion_fintype to the measurable label fibers: distinct -- fibers are disjoint and their union is univ. Use Finset.sum_subset to -- remove the labels outside positiveCells. For each omitted cell, nonnegative -- toReal mass and finite measure imply measure zero, hence restrict_eq_zero. have hmeas : ∀ k, MeasurableSet (cell label X k) := fun k => (measurableSet_singleton k).preimage (hlabel.comp hX) have hdisj : Pairwise (onFun Disjoint (cell label X)) := by intro i j hij change Disjoint (cell label X i) (cell label X j) rw [Set.disjoint_left] intro ω hi hj exact hij (hi.symm.trans hj) have hcover : (⋃ k, cell label X k) = univ := by ext ω simp only [Set.mem_iUnion, Set.mem_univ, iff_true] exact ⟨label (X ω), rfl⟩ calc (∫ ω, f ω ∂μ) = ∑ k : κ, ∫ ω in cell label X k, f ω ∂μ := by simpa only [hcover, Measure.restrict_univ] using (integral_iUnion_fintype hmeas hdisj (fun _ => hf.integrableOn)) _ = ∑ k ∈ positiveCells μ label X, ∫ ω in cell label X k, f ω ∂μ := by symm apply Finset.sum_subset (Finset.subset_univ _) intro k _ hk have hnpos : ¬ 0 < cellMass μ label X k := by simpa only [positiveCells, mem_filter, Finset.mem_univ, true_and] using hk have hz : (μ (cell label X k)).toReal = 0 := le_antisymm (le_of_not_gt hnpos) ENNReal.toReal_nonneg have hzero : μ (cell label X k) = 0 := ((ENNReal.toReal_eq_zero_iff _).mp hz).resolve_right (measure_ne_top μ _) rw [Measure.restrict_eq_zero.mpr hzero, integral_zero_measure]
Causalean.Stat.Nonparametric.HistogramRegression.integral_eq_sum_positive_cells · Causalean/Stat/Nonparametric/HistogramRegression/PartitionTotals.lean:25 · uses cell , positiveCells
1 supporting declaration (lemmas, instances)
Risk 1 core · 1 supporting The universal bound is twice the mass-weighted squared oscillation plus six times the number of positive-mass cells divided by m+1. ★ histogram_risk_le

Integrated finite-partition histogram risk

The universal bound is twice the mass-weighted squared oscillation plus six times the number of positive-mass cells divided by m+1. Sampling may be presented either as the canonical iid product law or as an independent family on an arbitrary probability space with a common observation law. No density, positive lower cell mass, or nonempty-sample premise is required.

theorem histogram_risk_le reviewed
Causalean.Stat.Nonparametric.HistogramRegression

A measurable finite partition and regression inputs, bounded responses and default, the population conditional mean identity, and within-cell oscillation bounds imply expected integrated squared histogram error is bounded by twice the mass-weighted squared oscillation plus six times the positive-cell count divided by the sample-size successor.

Formal statement
Ω :
Type u_1
shared
A :
Type u_2
shared
κ :
Type u_3
shared
m :
ℕ
label :
A → κ
X :
Ω → A
Y :
Ω → ℝ
g :
A → ℝ
a :
ℝ
δ :
κ → ℝ
hlabel :
hX :
hY :
hg :
hbound :
∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1
ha :
a ∈ Icc (0 : ℝ) 1
hmean :
hδ :
∀ k, 0 ≤ δ k
hosc :
∀ k x x'
if
label x = k
and
label x' = k
then
|g x - g x'| ≤ δ k
risk μ (Measure.pi (fun _ : Fin m => μ)) label X Y a g
≤ 2 * (∑ k ∈ positiveCells μ label X, cellMass μ label X k * δ k ^ 2)
+ 6 * ((positiveCells μ label X).card : ℝ) / (m + 1 : ℝ)
Proof (Lean source)
theorem histogram_risk_le {m : ℕ} (μ : Measure Ω) [IsProbabilityMeasure μ] (label : A → κ) (X : Ω → A) (Y : Ω → ℝ) (g : A → ℝ) (a : ℝ) (δ : κ → ℝ) (hlabel : Measurable label) (hX : Measurable X) (hY : Measurable Y) (hg : Measurable g) (hbound : ∀ᵐ ω ∂μ, Y ω ∈ Icc (0 : ℝ) 1) (ha : a ∈ Icc (0 : ℝ) 1) (hmean : ConditionalMean μ X Y g) (hδ : ∀ k, 0 ≤ δ k) (hosc : ∀ k x x', label x = k → label x' = k → |g x - g x'| ≤ δ k) : risk μ (Measure.pi (fun _ : Fin m => μ)) label X Y a g ≤ 2 * (∑ k ∈ positiveCells μ label X, cellMass μ label X k * δ k ^ 2) + 6 * ((positiveCells μ label X).card : ℝ) / (m + 1 : ℝ) := by let ν := Measure.pi (fun _ : Fin m => μ) let c := cellMean μ label X Y let p := cellMass μ label X let K := positiveCells μ label X let L := fun (z : Fin m → Ω) (ω : Ω) => (histogram label X Y a z (X ω) - g (X ω)) ^ 2 -- Regression is bounded almost surely; clipping bounds every training tuple. have hb := regression_mem_Icc_ae μ X Y g hX hg hbound hmean have hc (k : κ) : c k ∈ Icc (0 : ℝ) 1 := cellMean_mem_Icc μ label X Y k hY hbound have he (k : κ) (z : Fin m → Ω) : cellEstimate label X Y a k z ∈ Icc (0 : ℝ) 1 := by unfold cellEstimate split_ifs · exact ha · exact ⟨le_max_left _ _, max_le (by norm_num) (min_le_left _ _)⟩ have hsq (u v : ℝ) (hu : u ∈ Icc (0 : ℝ) 1) (hv : v ∈ Icc (0 : ℝ) 1) : (u - v) ^ 2 ≤ 1 := by simpa using (sq_le_sq' (by linarith [hu.1, hv.2]) (by linarith [hu.2, hv.1]) : (u - v) ^ 2 ≤ (1 : ℝ) ^ 2) have hLm : Measurable (uncurry L) := by exact (((measurable_histogram label X Y a hlabel hX hY).comp (measurable_fst.prodMk (hX.comp measurable_snd))).sub (hg.comp (hX.comp measurable_snd))).pow_const 2 have hLi (z : Fin m → Ω) : Integrable (L z) μ := by refine (integrable_const (1 : ℝ)).mono' (hLm.comp (measurable_const.prodMk measurable_id)).aestronglyMeasurable ?_ filter_upwards [hb] with ω hω rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] exact hsq _ _ (he (label (X ω)) z) hω have hBi (k : κ) : Integrable (fun ω => (c k - g (X ω)) ^ 2) μ := by refine (integrable_const (1 : ℝ)).mono' ((measurable_const.sub (hg.comp hX)).pow_const 2).aestronglyMeasurable ?_ filter_upwards [hb] with ω hω rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] exact hsq _ _ (hc k) hω have hRi : Integrable (fun z => ∫ ω, L z ω ∂μ) ν := by refine (integrable_const (1 : ℝ)).mono' (hLm.stronglyMeasurable.integral_prod_right').aestronglyMeasurable ?_ apply Filter.Eventually.of_forall intro z rw [Real.norm_eq_abs, abs_of_nonneg (integral_nonneg fun ω => sq_nonneg _)] have hh := integral_mono_ae (hLi z) (integrable_const (1 : ℝ)) (hb.mono fun ω hω => hsq _ _ (he (label (X ω)) z) hω) simpa using hh have hEi (k : κ) : Integrable (fun z : Fin m → Ω => (cellEstimate label X Y a k z - c k) ^ 2) ν := integrable_cellEstimate_sq_error μ label X Y a (c k) k hlabel hX hY ha (hc k) have hTi (k : κ) : Integrable (fun z : Fin m → Ω => 2 * p k * (cellEstimate label X Y a k z - c k) ^ 2 + 2 * (p k * δ k ^ 2)) ν := ((hEi k).const_mul _).add (integrable_const _) -- Split the fresh integral and bound each cell by estimation error plus bias. have hpoint (z : Fin m → Ω) : (∫ ω, L z ω ∂μ) ≤ ∑ k ∈ K, (2 * p k * (cellEstimate label X Y a k z - c k) ^ 2 + 2 * (p k * δ k ^ 2)) := by rw [integral_eq_sum_positive_cells μ label X (L z) hlabel hX (hLi z)] apply Finset.sum_le_sum intro k hk have hs : MeasurableSet (cell label X k) := (measurableSet_singleton k).preimage (hlabel.comp hX) have hh := integral_mono_ae (hLi z).integrableOn (((integrable_const ((cellEstimate label X Y a k z - c k) ^ 2)).add (hBi k).integrableOn).const_mul 2) (ae_restrict_of_forall_mem hs (fun ω hω => by change label (X ω) = k at hω dsimp [L, histogram] rw [hω] convert (add_sq_le (a := cellEstimate label X Y a k z - c k) (b := c k - g (X ω))) using 1; ring)) simp only [Pi.add_apply] at hh rw [integral_const_mul, integral_add (integrable_const _) (hBi k).integrableOn, integral_const] at hh have hbl := cell_bias_le μ label X Y g k (δ k) hlabel hX hg hbound hmean (hδ k) (hosc k) change (∫ ω in cell label X k, (c k - g (X ω)) ^ 2 ∂μ) ≤ p k * δ k ^ 2 at hbl calc _ ≤ 2 * (p k * (cellEstimate label X Y a k z - c k) ^ 2 + ∫ ω in cell label X k, (c k - g (X ω)) ^ 2 ∂μ) := by simpa [p, cellMass, Measure.real, smul_eq_mul] using hh _ ≤ 2 * (p k * (cellEstimate label X Y a k z - c k) ^ 2 + p k * δ k ^ 2) := mul_le_mul_of_nonneg_left (add_le_add_right hbl _) (by norm_num) _ = _ := by ring -- Integrate the finite sum and apply the mass-weighted cell MSE bound. have hi := integral_mono_ae hRi (integrable_finsetSum K (fun k _ => hTi k)) (Filter.Eventually.of_forall hpoint) rw [integral_finsetSum K (fun k _ => hTi k)] at hi have hcell (k : κ) (hk : k ∈ K) : (∫ z : Fin m → Ω, 2 * p k * (cellEstimate label X Y a k z - c k) ^ 2 + 2 * (p k * δ k ^ 2) ∂ν) ≤ 2 * (p k * δ k ^ 2) + 6 / (m + 1 : ℝ) := by rw [integral_add ((hEi k).const_mul _) (integrable_const _), integral_const_mul, integral_const] have hp : 0 < cellMass μ label X k := by simpa [K, positiveCells] using hk have hh := cell_estimation_mse_le (m := m) μ label X Y a k hlabel hX hY hbound ha hp change p k * (∫ z, (cellEstimate label X Y a k z - c k) ^ 2 ∂ν) ≤ 3 / (m + 1 : ℝ) at hh simp only [Measure.real, measure_univ, ENNReal.toReal_one, smul_eq_mul, one_mul] have hh2 := mul_le_mul_of_nonneg_left hh (by norm_num : (0 : ℝ) ≤ 2) calc _ = 2 * (p k * (∫ z, (cellEstimate label X Y a k z - c k) ^ 2 ∂ν)) + 2 * (p k * δ k ^ 2) := by ring _ ≤ 2 * (3 / (m + 1 : ℝ)) + 2 * (p k * δ k ^ 2) := add_le_add_left hh2 _ _ = _ := by ring change (∫ z, (∫ ω, L z ω ∂μ) ∂ν) ≤ _ calc _ ≤ ∑ k ∈ K, (∫ z : Fin m → Ω, 2 * p k * (cellEstimate label X Y a k z - c k) ^ 2 + 2 * (p k * δ k ^ 2) ∂ν) := hi _ ≤ ∑ k ∈ K, (2 * (p k * δ k ^ 2) + 6 / (m + 1 : ℝ)) := Finset.sum_le_sum hcell _ = _ := by simp only [Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_const, nsmul_eq_mul] dsimp [K, p] ring
Causalean.Stat.Nonparametric.HistogramRegression.histogram_risk_le · Causalean/Stat/Nonparametric/HistogramRegression/Risk.lean:30 · uses ConditionalMean , cellMass , positiveCells , risk
1 supporting declaration (lemmas, instances)