Stat.Quantile.AtomicApproximation
Equally weighted atomic approximations of compactly supported finite real measures.
Basic 3 core · 2 supporting This module fixes the metric and atomic-measure conventions used by the synchronized rational approximation theorem. ★ cdfDistance_equalAtomMeasure_weight_le
Integrated CDF distance and equally weighted atomic measures
This module fixes the metric and atomic-measure conventions used by the synchronized rational approximation theorem. Measures are finite Borel measures on the real line.
The integrated-CDF distance between a measure μ and a measure ν on the real line, over the interval from a to b, is the absolute gap between their total masses plus the integral from a to b of the absolute gap between their cumulative distribution functions.
The equally weighted atomic measure with N atoms of total weight w at locations x_1, …, x_N is the sum of the point masses at the locations, each with weight w/N (read as zero when w is negative).
Over an interval with a ≤ b, with a positive number of atoms N and two nonnegative total weights m and q, the integrated-CDF distance between the two equally weighted atomic measures at the same locations is at most (1 + (b − a))·|m − q|.
Formal statement
Proof (Lean source)
2 supporting declarations (lemmas, instances)
-
equalAtomMeasure_masstheorem — If the number of atoms N is positive and the total weight w is nonnegative, then the equally weighted atomic measure at any locations has total mass exactly w.hypothesesconclusionProof (Lean source)
theorem equalAtomMeasure_mass (N : ℕ) (hN : 0 < N) (w : ℝ) (hw : 0 ≤ w) (x : Fin N → ℝ) : (equalAtomMeasure N w x).real univ = w := by /- Expand the finite measure sum. Each Dirac mass of `univ` is one; convert `ofReal (w / N)` to a real and sum `N` equal terms. -/ simp [equalAtomMeasure, Measure.real, Measure.finsetSum_apply, hw, div_nonneg, Nat.cast_nonneg] have hN' : (N : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hN) field_simp -
cdfDistance_triangletheorem — Over an interval whose endpoints satisfy a ≤ b, the integrated-CDF distance between finite measures on the real line satisfies the triangle inequality.hypothesesconclusionProof (Lean source)
theorem cdfDistance_triangle (a b : ℝ) (hab : a ≤ b) (μ ν ξ : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] [IsFiniteMeasure ξ] : cdfDistance a b μ ξ ≤ cdfDistance a b μ ν + cdfDistance a b ν ξ := by /- Use the real absolute-value triangle inequality pointwise, then monotonicity of the interval integral. The CDFs are interval integrable by `FiniteMassTransport.intervalIntegrable_abs_raw_cdf_sub`. -/ let μf : FiniteMeasure ℝ := ⟨μ, inferInstance⟩ let νf : FiniteMeasure ℝ := ⟨ν, inferInstance⟩ let ξf : FiniteMeasure ℝ := ⟨ξ, inferInstance⟩ have hμξ := intervalIntegrable_abs_raw_cdf_sub μf ξf a b have hμν := intervalIntegrable_abs_raw_cdf_sub μf νf a b have hνξ := intervalIntegrable_abs_raw_cdf_sub νf ξf a b change IntervalIntegrable (fun t : ℝ => |μ.real (Iic t) - ξ.real (Iic t)|) volume a b at hμξ change IntervalIntegrable (fun t : ℝ => |μ.real (Iic t) - ν.real (Iic t)|) volume a b at hμν change IntervalIntegrable (fun t : ℝ => |ν.real (Iic t) - ξ.real (Iic t)|) volume a b at hνξ have hsum := hμν.add hνξ have hint : (∫ t in a..b, |μ.real (Iic t) - ξ.real (Iic t)|) ≤ (∫ t in a..b, |μ.real (Iic t) - ν.real (Iic t)|) + (∫ t in a..b, |ν.real (Iic t) - ξ.real (Iic t)|) := by rw [← intervalIntegral.integral_add hμν hνξ] apply intervalIntegral.integral_mono_on hab hμξ hsum intro t _ exact abs_sub_le _ _ _ unfold cdfDistance have hmass := abs_sub_le (μ.real univ) (ν.real univ) (ξ.real univ) linarith
DenseLocations 1 core · 1 supporting A measure with N equally weighted atoms in an interval [a, b] can be approximated, in the integrated-CDF distance, by one whose atoms lie in any prescribed dense subset of the interval, keeping the number of atoms and th ★ equalAtomMeasure_dense_locations
Moving the atoms of a finite atomic measure into a dense set
A measure with N equally weighted atoms in an interval [a, b] can be approximated, in the
integrated-CDF distance, by one whose atoms lie in any prescribed dense subset of the interval,
keeping the number of atoms and the weights fixed. The integrated-CDF distance between two such
measures with total weight w and atom locations x, y is at most (w/N) ∑ᵢ |xᵢ − yᵢ|, so
small displacements of the locations give a small distance.
Main results
* cdfDistance_equalAtomMeasure_locations_le — the displacement bound
cdfDistance ≤ (w/N) ∑ᵢ |xᵢ − yᵢ| for two equalAtomMeasures with atoms in [a, b].
* equalAtomMeasure_dense_locations — for every ε > 0 and every set D dense within [a, b],
there are locations in D whose equal-atom measure is within ε of the original.
An ordered interval, a location set, density of that set inside the interval, an atom count that is positive, a nonnegative total weight, interval-valued source atoms, and a positive tolerance give equally weighted atoms in the dense set within that integrated-CDF tolerance.
Formal statement
Proof (Lean source)
1 supporting declaration (lemmas, instances)
-
cdfDistance_equalAtomMeasure_locations_letheorem — An ordered interval, a positive atom count, a nonnegative total weight, and two lists of interval-valued atom locations give a displacement bound for their integrated-CDF discrepancy.hypothesesconclusioncdfDistance a b (equalAtomMeasure N w (fun i => (x i : ℝ))) (equalAtomMeasure N w (fun i => (y i : ℝ)))≤ (w / N) * ∑ i, |(x i : ℝ) - (y i : ℝ)|Proof (Lean source)
theorem cdfDistance_equalAtomMeasure_locations_le (a b : ℝ) (hab : a ≤ b) (N : ℕ) (hN : 0 < N) (w : ℝ) (hw : 0 ≤ w) (x y : Fin N → Icc a b) : cdfDistance a b (equalAtomMeasure N w (fun i => (x i : ℝ))) (equalAtomMeasure N w (fun i => (y i : ℝ))) ≤ (w / N) * ∑ i, |(x i : ℝ) - (y i : ℝ)| := by let c : ℝ := w / N have hc : 0 ≤ c := div_nonneg hw (Nat.cast_nonneg _) let f (i : Fin N) (t : ℝ) : ℝ := |(Measure.dirac (x i : ℝ)).real (Iic t) - (Measure.dirac (y i : ℝ)).real (Iic t)| have hformula (z : Fin N → ℝ) (t : ℝ) : (equalAtomMeasure N w z).real (Iic t) = c * ∑ i, (Measure.dirac (z i)).real (Iic t) := by simp only [equalAtomMeasure, Measure.real, Measure.finsetSum_apply, Measure.smul_apply] rw [ENNReal.toReal_sum (by intro i hi by_cases hz : z i ∈ Iic t <;> simp [hz])] simp [ENNReal.toReal_mul, ENNReal.toReal_ofReal hc, ← Finset.mul_sum, c] have hfinite (z : Fin N → ℝ) : IsFiniteMeasure (equalAtomMeasure N w z) := by have : ∀ i : Fin N, IsFiniteMeasure (ofReal c • Measure.dirac (z i)) := fun i => Measure.smul_finite _ (by simp) unfold equalAtomMeasure infer_instance let μf : FiniteMeasure ℝ := ⟨equalAtomMeasure N w (fun i => (x i : ℝ)), hfinite _⟩ let νf : FiniteMeasure ℝ := ⟨equalAtomMeasure N w (fun i => (y i : ℝ)), hfinite _⟩ have hmain := Causalean.Stat.Quantile.FiniteMassTransport.intervalIntegrable_abs_raw_cdf_sub μf νf a b change IntervalIntegrable (fun t : ℝ => |(equalAtomMeasure N w (fun i => (x i : ℝ))).real (Iic t) - (equalAtomMeasure N w (fun i => (y i : ℝ))).real (Iic t)|) volume a b at hmain have hfi (i : Fin N) : IntervalIntegrable (f i) volume a b := by let μi : FiniteMeasure ℝ := ⟨Measure.dirac (x i : ℝ), inferInstance⟩ let νi : FiniteMeasure ℝ := ⟨Measure.dirac (y i : ℝ), inferInstance⟩ have hi := Causalean.Stat.Quantile.FiniteMassTransport.intervalIntegrable_abs_raw_cdf_sub μi νi a b exact hi have hsum : IntervalIntegrable (fun t => c * ∑ i, f i t) volume a b := by apply IntervalIntegrable.const_mul have heq : (fun t => ∑ i, f i t) = ∑ i, f i := by funext t simp rw [heq] exact IntervalIntegrable.sum univ (fun i _ => hfi i) have hpoint (t : ℝ) : |(equalAtomMeasure N w (fun i => (x i : ℝ))).real (Iic t) - (equalAtomMeasure N w (fun i => (y i : ℝ))).real (Iic t)| ≤ c * ∑ i, f i t := by rw [hformula (fun i => (x i : ℝ)) t, hformula (fun i => (y i : ℝ)) t, ← mul_sub, abs_mul, abs_of_nonneg hc, ← Finset.sum_sub_distrib] exact mul_le_mul_of_nonneg_left (Finset.abs_sum_le_sum_abs _ _) hc have hint := intervalIntegral.integral_mono_on hab hmain hsum (fun t _ => hpoint t) rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_finsetSum (fun i _ => hfi i)] at hint have hident (i : Fin N) : (∫ t in a..b, f i t) = |(x i : ℝ) - (y i : ℝ)| := by rw [abs_sub_eq_integral_Icc_indicator (x i).property (y i).property] congr 1 funext t by_cases hx : (x i : ℝ) ≤ t <;> by_cases hy : (y i : ℝ) ≤ t <;> simp [f, Measure.real, indicator, hx, hy] simp_rw [hident] at hint rw [cdfDistance, equalAtomMeasure_mass N hN w hw (fun i => (x i : ℝ)), equalAtomMeasure_mass N hN w hw (fun i => (y i : ℝ))] simpa [c] using hint
Empirical 1 core · 0 supporting The empirical approximation has a positive number of equally weighted atoms for every sufficiently large sample size. ★ eventually_equalAtomMeasure_approx
Equal-mass empirical approximation on a compact real interval
The empirical approximation has a positive number of equally weighted atoms for every sufficiently large sample size. Their locations lie in any dense subset of the support interval, including when the original law has atoms or zero mass.
A finite real measure, an ordered closed interval, concentration on that interval, a location set, density of that set inside the interval, and a tolerance that is positive give a threshold after which every positive grid size has an equally weighted approximation located in that dense set within the tolerance.
Formal statement
Proof (Lean source)
Main 1 core · 0 supporting Two compactly supported finite real measures of equal mass can be approximated simultaneously with one rational total mass and one positive atom count. ★ exists_synchronized_rational_equalAtom_approx
Synchronized rational atomic density for paired finite measures
Two compactly supported finite real measures of equal mass can be approximated simultaneously with one rational total mass and one positive atom count.
Two finite real measures, two ordered closed intervals, the first interval is ordered, the second interval is ordered, concentration of the first measure on its interval and concentration of the second measure on its interval, equality of their total real masses, two location sets, density of each location set in its interval, and a positive tolerance give a common positive atom count, nonnegative rational mass, and two equally weighted dense-location atomic approximations with exact mass and total error below the tolerance.
Formal statement
Proof (Lean source)
ProbabilityGrid 1 core · 0 supporting This module isolates the quantile-selection step for an equally weighted empirical approximation. ★ exists_probability_equalAtom_interval_cdf_error_le
Uniform cumulative-mass grids for compactly supported probability measures
This module isolates the quantile-selection step for an equally weighted empirical approximation. The finite-mass result follows by normalization and a separate zero-mass case.
A probability measure, a closed interval, concentration of that measure on the interval, and a positive grid size give interval-valued equally weighted atoms whose CDF error is at most one grid share at every threshold.
Formal statement
Proof (Lean source)
QuantileGrid 1 core · 2 supporting This module isolates the measure-theoretic approximation before atom locations are moved into a prescribed dense subset. ★ eventually_equalAtomMeasure_interval_approx
Equal-weight quantile grids on compact intervals
This module isolates the measure-theoretic approximation before atom locations are moved into a prescribed dense subset.
A finite real measure, an ordered closed interval, concentration on that interval, and a positive tolerance give a threshold after which every positive grid size admits an equally weighted interval-atomic approximation within that tolerance.
Formal statement
Proof (Lean source)
2 supporting declarations (lemmas, instances)
-
exists_equalAtomMeasure_interval_cdf_error_letheorem — A finite real measure, an ordered closed interval, concentration on that interval, and a positive grid size give interval-valued equally weighted atoms whose CDF error is at most one atom's share of the total mass at every threshold.hypothesesProof (Lean source)
theorem exists_equalAtomMeasure_interval_cdf_error_le (μ : Measure ℝ) [IsFiniteMeasure μ] (a b : ℝ) (hab : a ≤ b) (hμ : μ (Icc a b)ᶜ = 0) (N : ℕ) (hN : 0 < N) : ∃ x : Fin N → Icc a b, ∀ t : ℝ, |μ.real (Iic t) - (equalAtomMeasure N (μ.real univ) (fun i => (x i : ℝ))).real (Iic t)| ≤ μ.real univ / N := by /- Let `μf : FiniteMeasure ℝ := ⟨μ, inferInstance⟩` and set `m := μ.real univ`. If `m > 0`, use `FiniteMassTransport.normalize_support_Icc` and apply `exists_probability_equalAtom_interval_cdf_error_le` to `μf.normalize`. `FiniteMassTransport.cdf_normalize_eq_div` identifies its CDF with `μ.real (Iic t) / m`. Expand the finite Dirac sum to show that the `m`-weight grid has CDF `m` times the unit-weight grid's CDF; multiply the probability bound by `m` and simplify. If `m = 0`, finite-measure monotonicity makes every CDF value zero. Put every grid point at `a`; its weight `m / N` is zero. -/ let m : ℝ := μ.real univ have hm0 : 0 ≤ m := measureReal_nonneg have hNreal : (0 : ℝ) < N := by exact_mod_cast hN have hformula (w : ℝ) (hw : 0 ≤ w) (x : Fin N → ℝ) (t : ℝ) : (equalAtomMeasure N w x).real (Iic t) = (w / N) * ∑ i, (Measure.dirac (x i)).real (Iic t) := by simp only [equalAtomMeasure, Measure.real, Measure.finsetSum_apply, Measure.smul_apply] rw [ENNReal.toReal_sum (by intro i hi by_cases hx : x i ∈ Iic t <;> simp [hx])] simp [ENNReal.toReal_mul, ENNReal.toReal_ofReal (div_nonneg hw (Nat.cast_nonneg _)), ← Finset.mul_sum] by_cases hm : m = 0 · let x : Fin N → Icc a b := fun _ => ⟨a, ⟨le_refl a, hab⟩⟩ refine ⟨x, ?_⟩ intro t have hzero : μ.real (Iic t) = 0 := by have hle : μ.real (Iic t) ≤ m := measureReal_mono (subset_univ _) have hnonneg : 0 ≤ μ.real (Iic t) := measureReal_nonneg linarith rw [hzero, show μ.real univ = 0 from hm] rw [hformula 0 (le_refl 0) (fun i => (x i : ℝ)) t] norm_num · have hmp : 0 < m := lt_of_le_of_ne hm0 (Ne.symm hm) let μf : FiniteMeasure ℝ := ⟨μ, inferInstance⟩ have hmass : (μf.mass : ℝ) = m := rfl have hpos : 0 < (μf.mass : ℝ) := by simpa [hmass] using hmp have hsupport : (μf.normalize : Measure ℝ) (Icc a b)ᶜ = 0 := normalize_support_Icc μf hpos hμ obtain ⟨x, hx⟩ := exists_probability_equalAtom_interval_cdf_error_le (μf.normalize : Measure ℝ) a b hsupport N hN refine ⟨x, ?_⟩ intro t have hnorm := hx t have hcdf : (μf.normalize : Measure ℝ).real (Iic t) = μ.real (Iic t) / m := by rw [← ProbabilityTheory.cdf_eq_real, cdf_normalize_eq_div μf hpos] rfl rw [hcdf] at hnorm have hscale : (equalAtomMeasure N m (fun i => (x i : ℝ))).real (Iic t) = m * (equalAtomMeasure N 1 (fun i => (x i : ℝ))).real (Iic t) := by rw [hformula m hm0, hformula 1 (by norm_num)] ring change |μ.real (Iic t) - (equalAtomMeasure N m (fun i => (x i : ℝ))).real (Iic t)| ≤ m / N rw [hscale] have hident : μ.real (Iic t) - m * (equalAtomMeasure N 1 (fun i => (x i : ℝ))).real (Iic t) = m * (μ.real (Iic t) / m - (equalAtomMeasure N 1 (fun i => (x i : ℝ))).real (Iic t)) := by field_simp rw [hident, abs_mul, abs_of_nonneg hm0] have hbound := mul_le_mul_of_nonneg_left hnorm hm0 simpa [div_eq_mul_inv] using hbound -
cdfDistance_le_of_pointwise_cdf_letheorem — Two finite real measures, an interval and error level, the interval endpoints ordered, equal total real masses, and a uniform CDF-error bound on the interval give an integrated-CDF discrepancy bound by interval length times that error level.Proof (Lean source)
theorem cdfDistance_le_of_pointwise_cdf_le (μ ν : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] (a b c : ℝ) (hab : a ≤ b) (hmass : μ.real univ = ν.real univ) (hpoint : ∀ t ∈ Icc a b, |μ.real (Iic t) - ν.real (Iic t)| ≤ c) : cdfDistance a b μ ν ≤ (b - a) * c := by /- Use `FiniteMassTransport.intervalIntegrable_abs_raw_cdf_sub` for the integrand and `intervalIntegral.integral_mono_on` against the constant function `c`. Rewrite `intervalIntegral.integral_const`, then eliminate the mass term with `hmass`. No positivity of the original mass is needed. -/ let μf : FiniteMeasure ℝ := ⟨μ, inferInstance⟩ let νf : FiniteMeasure ℝ := ⟨ν, inferInstance⟩ have hint := intervalIntegrable_abs_raw_cdf_sub μf νf a b change IntervalIntegrable (fun t : ℝ => |μ.real (Iic t) - ν.real (Iic t)|) volume a b at hint have hbound := intervalIntegral.integral_mono_on hab hint (intervalIntegrable_const : IntervalIntegrable (fun _ : ℝ => c) volume a b) hpoint rw [intervalIntegral.integral_const] at hbound simpa [cdfDistance, hmass, smul_eq_mul, mul_comm] using hbound