Spline Statistics
How to obtain the mean, the variance, and the image of a periodic one-dimensional spline.
Average vs Mean
We take the average value of the function \(f:{\mathbb{R}}\rightarrow{\mathbb{R}},x\mapsto f(x)\) over some set \(\Omega\) to be the quantity \(\mu=\int_{\Omega}\,f(x)\,\frac{{\mathrm{d}}x}{\left|\Omega\right|},\) where \(\left|\Omega\right|\) is some measure of the size of \(\Omega.\) To be sure, the precise definition of this measure would take us on a journey that would lead us far away from the familiar territory of calculus, so we shall assume for simplicity that \(\Omega\) is but just one bounded and non-degenerate interval, and that \(f\) is such that it can be integrated in the simplest of all ways, for instance as the limit of a Riemann sum.
There are cases where \(f\) admits a favorable expression such that \(\mu\) can be found explicitly, but these cases are few and far apart. Most functions show hostility to the treatment, and \(\mu\) cannot be accessed through the tools of analysis. Even in such adverse cases, however, the Riemann sum still gives us an estimate of \(\mu\) that is easily computed as \(\tilde{\mu}=\sum_{k'=0}^{N-1}\,f(k')\,\frac{1}{N},\) with \(N\) a positive integer. This surrogate computation demands that the interval \(\Omega=[0,N]\) be partitioned into \(N\) subintervals of unit length. (A linear change of variable over \(f\) is all it takes to estimate the average over any arbitrary interval, with arbitrary rational length of the subintervals.)
An average is the name given to \(\mu\) and a mean is the name given to \(\tilde{\mu}.\) For finite \(N,\) they differ for nearly every function one can think of; yet, remarkably, they do coincide in the cases where \(f\) is a periodic polynomial spline of period \(K,\) with
whenever \(f(x)=\sum_{k\in{\mathbb{Z}}}\,c[{k\bmod K}]\,\beta^{n}(x-\delta x-k),\) where \(\left(c[k]\right)_{k=0}^{K-1}\in{\mathbb{R}}^{K}\) is a \(K\)-dimensional vector of spline coefficients and \(\beta^{n}\) is a polynomial B-spline of nonnegative degree \(n\in{\mathbb{N}}.\) Moreover, the equality between average and mean holds for any delay \(\delta x.\)
Variance
We take the variance of \(f\) over \(\Omega\) to be the quantity \(\sigma^{2}=\int_{\Omega}\,\left(f(x)-\mu\right)^{2}\,\frac{{\mathrm{d}}x}{\left|\Omega\right|}.\) Whenever \(f\) is a periodic spline, this variance can be computed exactly over one period. Even for splines, however, both the biased sample variance \(\sum_{k'=0}^{K-1}\,\left(f(k')-\tilde{\mu}\right)^{2}\,\frac{1}{K}\) and the unbiased sample variance \(\sum_{k'=0}^{K-1}\,\left(f(k')-\tilde{\mu}\right)^{2}\,\frac{1}{K-1}\) return only estimates of \(\sigma^{2}.\)
Bounds
Consider the periodic spline \(f:{\mathbb{R}}\rightarrow{\mathbb{R}},x\mapsto f(x)=\sum_{k\in{\mathbb{Z}}}\,c[{k\bmod K}]\,\beta^{n}(x-\delta x -k),\) along with its vector of samples at the integers \(\left(f(k')\right)_{k'=0}^{K-1}\in{\mathbb{R}}^{K}.\) While it is easy enough to compute \(\tilde{f}_{\min}=\min_{k'=0}^{K-1}\,f(k')\) and \(\tilde{f}_{\max}=\max_{k'=0}^{K-1}\,f(k'),\) there is no guarantee that the spline does not undershoot \(\tilde{f}_{\min}\) or overshoot \(\tilde{f}_{\max}\) for spline degrees above \(1.\) Even for linear splines, a guarantee would exist only for integer delays \(\delta x\in{\mathbb{Z}};\) for non-integer delays, the guarantee disappears.
The splinekit library offers an image function that returns as an interval the enclosure of the image of the spline over the domain \({\mathbb{R}}.\) The infimum and the supremum of this interval are \(f_{\min}\) and \(f_{\max},\) respectively. While the computations are performed numerically and rely on the determination of the roots of polynomials of degree \(\left(n-1\right),\) they nevertheless provide much more accurate and reliable estimates than \(\tilde{f}_{\min}\) and \(\tilde{f}_{\max}\) do.
Illustration
We provide now a notebook where one can explore visually the notions we touched above. It allows for the creation of random splines, in the sense that their samples are independent identically distributed realizations of a random variable that follows some specified probability density function. We consider three of them.
Uniform The samples of the spline are drawn over some interval of values, without preference for any one value. The interval is chosen to ensure that the mean of the samples would be \(0\) and that the sampled variance would be \(1\) if there would be infinitely many samples.
Gaussian The samples of the spline are made to follow a Gaussian normal distribution. They show a tendency to cluster around \(0,\) but large values can also be observed, albeit rarely.
Cauchy The samples of the spline take erratic values, so much so that it is known that neither their mean nor their variance converges to any definite value when the number of samples grows.
Jupyter Lab notebook