"""
Script to the video at
https://youtu.be/8w4jHN1LsnY
"""
===== Moving quantile series =====
=== Preliminary - Exponential distribution example ===
Density:
$p_\mu(x) := F'(x) = \frac{1}{\mu} {\mathrm e}^{-\frac{x}{\mu}}$
CDF:
$F_\mu(x) := 1 - {\mathrm e}^{-\frac{x}{\mu}}$
Plot[Table[Exp[-x/m]/m, {m, .1, 2, .2}], {x, 0, 3}]
The parameter actually equals the mean: ${\mathbb E}[X] = \mu$
Plot[{Exp[-x/0.1]/0.1, UnitStep[x - 0.1], Exp[-x/0.4]/0.4, UnitStep[x - 0.4]}, {x, 0, 0.6}]
My motivation (from Partial Differential Equations, 3rd Ed, by Jost),
$T_1(s) := {\mathrm e}^{s G}$
(which has $\lim_{s\to 0} T_1(s) = 1$.)
$I_1(\mu) = \int_0^\infty \left( T_1(s) - 1 \right)\cdot {\mathrm d}F_\mu(s)
= \int_0^\infty \left( {\mathrm e}^{s G} - 1 \right) \dfrac{{\mathrm e}^{-s/\mu} ,{\mathrm d}s}{\mu}$
$= \dfrac{1}{1 - \mu G} - 1
= \sum_{n=1}^{\infty} (\mu G)^n
= \mu G + {\mathcal O}(\mu^2)$
So, clearly,
$\lim_{\mu\to 0} I_1(s) = 0$.
Now for more a bit more general $T_2(s)$ (see PDF book for more contest),
$I_2(v, \mu) = \int_0^\infty \left( T_2(s)v - v \right)\cdot {\mathrm d}F_\mu(s)$
also has $\lim_{\mu\to 0} I_2(v, \mu) = 0$.
Approach (see book) is to do $\int_0^\infty = \int_0^\delta + \int_\delta^\infty$ and argue both parts are zero individually.
(Note that somehting like $\lim_{s\to 0} T_2(s)v = v$ helps.)
CDF:
$F\colon {\mathbb R}_{\ge 0}\to [0,1]$
$F(0) = 0, F(\infty) = 1$
$p(x) := F'(x)$
For a quantile level $q$, call the $q$-th quantile $x_{F,,q}$ the $x$-value with $F(x_{F,,q}) = q$.
$\int_0^{x_{F,,q}} p(x) , {\mathrm d}x = F(F^{-1}(q)) - F(0) = q$
Obtain a $d$-indexed family via $x$-axis rescaling,
$F_d(x) := F(\frac{x}{d})$ with $d > 0$
(Note that $F_d$ is just as valid a CDF as $F$.)
so that
$p_d(x) = F_d'(x) = \frac{1}{d} p(\frac{x}{d})$
(Note: Also ${\mathbb E}{p_d}[X] = d\cdot {\mathbb E}p[X]$.)
and with
$x{F_d,,q} := F_d^{-1}(q) = d\cdot F^{-1}(q)$
We still have a $d$-independent integral,
$\int_0^{x{F_d,,q}} p_d(x) , {\mathrm d}x = F(\frac{d\cdot F^{-1}(q)}{d}) = q$
Note that this is now despite the shrinked interval size.
As it's constant, it also holds while $\lim_{d\to 0} x_{F_d,,q} = 0$
In the shrinked setup with $d<1$, the mass is moved closer to $0$ and so the point where the CDF is $q$ comes earlier.
Example:
$F(x) := 1 - {\mathrm e}^{-x}$ with ${\mathbb E}[X] = 1$
Intorduce $d=\mu$, so as to get to
$F_\mu(x) := 1 - {\mathrm e}^{-\frac{x}{\mu}}$
With
$p_\mu(x) = \frac{1}{\mu} {\mathrm e}^{-\frac{x}{\mu}}$
We have that $x_{F_\mu,,q} = −\mu\log(1−q) > 0$
and it ofc gives $\int_0^{−\mu\log(1−q)} \left(\frac{1}{\mu} {\mathrm e}^{-\frac{x}{\mu}}\right) , {\mathrm d}x = q$
Now, instead, set a value $x_{F_d,,q_d}$ and let $q_d := F(x_{F_d,,q_d})$ be its quantile value.
In particular, we study $x_{F_d,,q_d} = d^r$.
Then if $r>0$ still $\lim_{d\to 0} x_{F_d,,q_d} = 0$, while
$\lim_{d\to 0} \int_0^{x_{F_d,,q_d}} p_d(x) , {\mathrm d}x = \lim_{d\to 0} F(d^{r-1})$
will now converge towards either of the extremes of ${\mathbb R}{\ge 0}$, depending on $r$.
I.e. we can either squeeze in all the mass inside of $[0, x{F_d,,q_d}]$ or be too fast and lose all the mass.
And for the more manual $x_{F_d,,q_d}=\mu^r$,
$I=\int_0^{\mu^r} \left(\frac{1}{\mu} {\mathrm e}^{-\frac{x}{\mu}}\right) , {\mathrm d}x = 1 - {\mathrm e}^{-\mu^{r-1}}$
$\mu^{r-1}\to 0\implies I=0$
For $r<1$ this actually takes the bulk of the density inside the shrinking early interval.
For $r=1$ it's constant and for for $r>1$ the mass in the interval goes to zero.