Speckle from fractal vasculature: power-law radii, echo maps, Burr, Lomax, log-amplitude and Pearson densities, speckle SNR
DefinitionArxiv2005_04287_BasicObjects of the Theory section and the Discussion of Parker and Poul (2020). Every density below is a function on . A density the paper states only for positive arguments is elsewhere, and a density defines the measure on .
- Vessel radii (eq. 7). For and , the power-law density for , and otherwise.
- Radius-to-echo maps (p. 7). Amplitude and intensity for , both otherwise.
- Amplitude densities. Eq. (9): . Eq. (10): . Both are for . The standard Burr XII density with shapes and scale is for .
- Intensity densities. Eq. (13): . Eq. (14): . Both are for . The standard Lomax density with shape and scale is for .
- Log-amplitude density (eq. 15). for every real .
- Phase and in-phase component. A uniform phase has law on . Eq. (17) is the density for every real .
- Speckle SNR (p. 19). For a law of the echo amplitude, with . The Rayleigh value is , printed as .
Formalization Note The paper's parameter is written lam and is written lam2. Eq. (15) is defined for every real , although the paper prints the range (see the statement for eq. (15)).
import Mathlib
/-!
K. J. Parker and S. S. Poul, *Burr, Lomax, Pareto, and Logistic Distributions from Ultrasound
Speckle*, arXiv:2005.04287v1 (2020): the power-law law of vessel radii (eq. (7)), the radius-to-echo
maps (Theory, "Spatial Convolutions and Transforms", p. 7), and the probability densities of the
echo amplitude (eqs. (9), (10)), intensity (eqs. (13), (14)), log amplitude (eq. (15)) and in-phase
component (eq. (17)), with the standard Burr XII and Lomax densities the paper identifies them
with and the speckle signal-to-noise ratio of the Discussion (p. 19).
Every density is a function `ℝ → ℝ`; a density stated by the paper only on a half-line is `0` off
it. A density `f` is turned into a measure on `ℝ` as `volume.withDensity (ENNReal.ofReal ∘ f)`.
-/
open MeasureTheory
noncomputable section
namespace Arxiv2005_04287
/-- Eq. (7), p. 7: the power-law density of vessel radii,
`p(a) = ((b - 1)/a_min) (a/a_min)^(-b)` for `a > a_min`, and `0` otherwise. -/
def powerLawDensity (b amin : ℝ) (a : ℝ) : ℝ :=
if amin < a then ((b - 1) / amin) * (a / amin) ^ (-b) else 0
/-- Eq. (7), p. 7: the law of the radius `a` of the vessel met by the pulse, the measure on `ℝ`
with density `powerLawDensity b amin`. -/
def powerLawMeasure (b amin : ℝ) : Measure ℝ :=
volume.withDensity (fun a => ENNReal.ofReal (powerLawDensity b amin a))
/-- P. 7 ("Spatial Convolutions and Transforms"): the echo amplitude of a cylinder of radius `a`,
`A[a] = A0 sqrt(a - a_min)` for `a > a_min`, and `0` otherwise. -/
def ampMap (A0 amin : ℝ) (a : ℝ) : ℝ :=
if amin < a then A0 * Real.sqrt (a - amin) else 0
/-- P. 7 and p. 8 ("Probability of Intensity"): the average echo intensity of a cylinder of
radius `a`, `I(a) = I0 (a - a_min)` for `a > a_min`, and `0` otherwise. -/
def intensityMap (I0 amin : ℝ) (a : ℝ) : ℝ :=
if amin < a then I0 * (a - amin) else 0
/-- Eq. (9), p. 8: the amplitude density
`p[A] = 2 A a_min^(b-1) (b - 1) / (A0^2 ((A/A0)^2 + a_min)^b)` for `A > 0`, and `0` otherwise. -/
def ampDensity9 (b amin A0 : ℝ) (A : ℝ) : ℝ :=
if 0 < A then 2 * A * amin ^ (b - 1) * (b - 1) / (A0 ^ 2 * ((A / A0) ^ 2 + amin) ^ b) else 0
/-- Eq. (10), p. 8 (and Table 1, p. 13): the two-parameter amplitude density
`p[A] = 2 A (b - 1) / (lam^2 ((A/lam)^2 + 1)^b)` for `A > 0`, and `0` otherwise. -/
def burrDensity (b lam : ℝ) (A : ℝ) : ℝ :=
if 0 < A then 2 * A * (b - 1) / (lam ^ 2 * ((A / lam) ^ 2 + 1) ^ b) else 0
/-- Eq. (10), p. 8: the law of the echo amplitude, the measure on `ℝ` with density
`burrDensity b lam`. -/
def burrMeasure (b lam : ℝ) : Measure ℝ :=
volume.withDensity (fun A => ENNReal.ofReal (burrDensity b lam A))
/-- P. 8, refs. 45, 46: the standard Burr Type XII density with shape parameters `c`, `k` and
scale `s`, `f(x) = (c k / s) (x/s)^(c-1) (1 + (x/s)^c)^(-(k+1))` for `x > 0`, and `0` otherwise. -/
def burrXIIDensity (c k s : ℝ) (x : ℝ) : ℝ :=
if 0 < x then (c * k / s) * (x / s) ^ (c - 1) * (1 + (x / s) ^ c) ^ (-(k + 1)) else 0
/-- Eq. (13), p. 9: the intensity density
`p_I(I) = (b - 1) / (a_min^(1-b) I0 (I/I0 + a_min)^b)` for `I > 0`, and `0` otherwise. -/
def intensityDensity13 (b amin I0 : ℝ) (I : ℝ) : ℝ :=
if 0 < I then (b - 1) / (amin ^ (1 - b) * I0 * (I / I0 + amin) ^ b) else 0
/-- Eq. (14), p. 9 (and Table 1, p. 13): the intensity density
`p_I(I) = (b - 1) lam2^(b-1) / (I + lam2)^b` for `I > 0`, and `0` otherwise. -/
def intensityDensity14 (b lam2 : ℝ) (I : ℝ) : ℝ :=
if 0 < I then (b - 1) * lam2 ^ (b - 1) / (I + lam2) ^ b else 0
/-- Eq. (14), p. 9: the law of the echo intensity, the measure on `ℝ` with density
`intensityDensity14 b lam2`. -/
def intensityMeasure (b lam2 : ℝ) : Measure ℝ :=
volume.withDensity (fun I => ENNReal.ofReal (intensityDensity14 b lam2 I))
/-- P. 9, ref. 47: the standard Lomax (Pareto type II) density with shape `alpha` and scale `s`,
`f(x) = (alpha / s) (1 + x/s)^(-(alpha+1))` for `x > 0`, and `0` otherwise. -/
def lomaxDensity (alpha s : ℝ) (x : ℝ) : ℝ :=
if 0 < x then (alpha / s) * (1 + x / s) ^ (-(alpha + 1)) else 0
/-- Eq. (15), p. 10 (and Table 1, p. 13): the log-amplitude density
`p_y(y) = 2 (b - 1) exp(2y) / (lam^2 (exp(2y)/lam^2 + 1)^b)`, as a function of every real `y`
(the paper prints the range `y > 0`; see the statement `logAmplitude_pdf`). -/
def logAmpDensity (b lam : ℝ) (y : ℝ) : ℝ :=
2 * (b - 1) * Real.exp (2 * y) / (lam ^ 2 * (Real.exp (2 * y) / lam ^ 2 + 1) ^ b)
/-- Eq. (15), p. 10: the law of the log amplitude `y = ln A`, the measure on `ℝ` with density
`logAmpDensity b lam`. -/
def logAmpMeasure (b lam : ℝ) : Measure ℝ :=
volume.withDensity (fun y => ENNReal.ofReal (logAmpDensity b lam y))
/-- P. 11 (text before eq. (17)): the law of a phase `theta` uniform on `[0, 2 pi)`, the measure
`(1/(2 pi)) * Lebesgue` restricted to `[0, 2 pi)`. -/
def uniformPhase : Measure ℝ :=
ENNReal.ofReal (1 / (2 * Real.pi)) • volume.restrict (Set.Ico 0 (2 * Real.pi))
/-- Eq. (17), p. 12 (and Table 1, p. 13): the density of the in-phase component `|A| cos theta_A`,
`p(x) = (b - 1) Gamma(b - 1/2) / (sqrt(pi) Gamma(b) (1 + x^2)^(b - 1/2))` for every real `x`. -/
def pearsonDensity (b : ℝ) (x : ℝ) : ℝ :=
(b - 1) * Real.Gamma (b - 1 / 2) /
(Real.sqrt Real.pi * Real.Gamma b * (1 + x ^ 2) ^ (b - 1 / 2))
/-- Eq. (17), p. 12: the law of the in-phase component, the measure on `ℝ` with density
`pearsonDensity b`. -/
def pearsonMeasure (b : ℝ) : Measure ℝ :=
volume.withDensity (fun x => ENNReal.ofReal (pearsonDensity b x))
/-- P. 19 (Discussion, ref. 9): the speckle signal-to-noise ratio of a law `mu` of the echo
amplitude, its mean divided by its standard deviation. -/
def speckleSNR (mu : Measure ℝ) : ℝ :=
(∫ x, x ∂mu) / Real.sqrt (∫ x, (x - ∫ x', x' ∂mu) ^ 2 ∂mu)
/-- P. 19 (ref. 9, Burckhardt 1978): the speckle signal-to-noise ratio of the Rayleigh amplitude
law, `sqrt(pi / (4 - pi)) = 1.913...`, printed in the paper as `1.91`. -/
def rayleighSNR : ℝ := Real.sqrt (Real.pi / (4 - Real.pi))
end Arxiv2005_04287
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Conventions used throughout this bundle. All of the following are fixed rules of the definitions below, not assumptions.
- Real parameters. Every parameter is an arbitrary real number. No positivity, ordering or normalisation condition is imposed on any of them.
- Division by zero. Division by yields .
- Square roots. of a negative is .
- Integer squares. Exponents written are ordinary squaring.
- Real powers. All other exponents are real powers , with these conventions:
- for , ;
- , and for ;
- for , , which is generally neither the "real root" nor undefined.
- Gamma function. is the real Gamma function, with .
- Measures from densities. "The measure with density " means the measure on , with respect to Lebesgue measure. Negative values of are clipped to . No statement is made that the total mass is .
- Integrals. of a function that is not -integrable is .
powerLawDensity. For reals , and ,
The edge cases are as follows:
- If , the prefactor is , so the function is identically .
- If and , the base is positive. However, for the base is negative and the negative-base power convention applies; at the base is .
- The value can be negative, for example when and .
powerLawMeasure. For reals and , this is the measure on with density above (negative values clipped to ). It is not asserted to be a probability measure. Its total mass is only for suitable parameters (e.g. , ) and may be , finite , or otherwise.
ampMap. For reals , and ,
may be zero or negative, in which case the values are or negative.
intensityMap. For reals , and ,
may be any real.
ampDensity9. For reals , , and ,
The edge cases are as follows:
- If , the denominator is and the value is for every .
- If , the factor follows the zero and negative-base power conventions.
- If , the base can be zero or negative. Where it is zero (and ) the value is .
burrDensity. For reals , and ,
The value depends on only through .
- If , the function is identically .
- For the base is at least .
- The value is negative for when .
burrMeasure. For reals and , this is the measure on with density (burrDensity above, negative values clipped to ). No normalisation is asserted. For example:
- for or it is the zero measure;
- for its total mass is exactly when .
burrXIIDensity. For reals , , and ,
The edge cases are as follows:
- If , the function is identically .
- If , the base is negative and the negative-base power convention applies, including inside .
- No sign condition is placed on or .
intensityDensity13. For reals , , and ,
The edge cases are as follows:
- If , the denominator is and the value is .
- If and , the factor is and the value is .
- For or the bases may be negative or zero, and the stated power and division conventions apply.
intensityDensity14. For reals , and ,
If , the factor and the base may be zero or negative and follow the stated conventions. In particular, at the denominator is .
intensityMeasure. For reals and , this is the measure on with density (intensityDensity14, negative values clipped to ). No normalisation is asserted.
lomaxDensity. For reals , and ,
If , the function is identically . If , the base can be zero or negative. No sign condition is placed on .
logAmpDensity. For reals and , this is a function of every real with no restriction to or any other half-line:
- If , the function is identically .
- For the base exceeds .
- The sign of the value is the sign of .
logAmpMeasure. For reals and , this is the measure on all of with density (logAmpDensity, negative values clipped to ). No normalisation is asserted.
uniformPhase. This is the measure on given by
It gives mass to a set , so its total mass is .
pearsonDensity. For reals and ,
This is defined for every real . The edge cases are as follows:
- If , then , so the denominator is and the value is .
- If , the numerator is .
- The value can be negative for some , for example with .
pearsonMeasure. For real , this is the measure on with density (pearsonDensity, negative values clipped to ). No normalisation is asserted.
speckleSNR. For an arbitrary measure on , let
Then
is not required to be a probability measure, finite, or to have finite moments. The edge cases are as follows:
- Mean not integrable. If is not -integrable, then and the whole value is .
- Second moment not integrable. If is not -integrable, the inner integral is . The denominator is then and the value is .
- Zero spread. If , the value is .
- Non-probability measures. For a measure of total mass , the inner integral is not divided by the total mass. It is therefore not the variance in the usual sense.
rayleighSNR. This is the specific real number
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.