Peter Johnson
Peter Johnson
Weighted arithmetic mean  Source: [Wikipedia](https://en.m.wikipedia.org/wiki/Weighted_arithmetic_mean)
Useful helper functions for checking arrays for zero & negative entries: ```pascal // Check if all elements of a non-empty array are zero function ArrayIsZero(const A: array of Extended): Boolean;...
A related (helper) function is LogSumExp or LSE for a sequence x1,...,xn is is defined as the [logarithm](https://en.m.wikipedia.org/wiki/Logarithm) of the sum of the [exponentials](https://en.m.wikipedia.org/wiki/Exponential_function) of the arguments: LSE(x1,...,xn) = log(exp(x1)...
Strictly convex LogSumExp  Source: [Wikipedia](https://en.m.wikipedia.org/wiki/LogSumExp) Since exp(0) = e^0 = 1, we have LSE(0, x1,...,xn) = log(exp(0) + exp(x1) + ... + exp(xn)) = log(1 + exp(x1) + ......
Quasi-arithmetic mean  Source: [Wikipedia](https://en.m.wikipedia.org/wiki/Quasi-arithmetic_mean) Note that certain functions f may be restricted to certain intervals of the real numbers, so if would be wise to pass a closure to...
Harmonic mean  Source: [Wikipedia](https://en.m.wikipedia.org/wiki/Harmonic_mean)
Median Two overloads suggested, one real & one integer: ```pascal function Median(const A: array of Extended): Extended; overload; begin Assert(Length(A) > 0); // optimisations for array lengths 1 & 2...
Mode for countable sets: `ModeN` Obeys [rule](https://www.investopedia.com/terms/m/mode.asp) that if all items in a sequence of values are unique then there is no mode. The following function returns an empty array...
Mode for real numbers. Numbers are considered equal if they are within `Epsilon` of each other. If `Epsilon` is zero then Delphi chooses a suitable default. ```pascal function ModeR(const A:...
Mode with [probability function p(x)](https://www.radfordmathematics.com/probabilities-and-statistics/discrete-probability-distributions-discrete-random-variables/parameters-discrete-random-variables.html#:~:text=the%20Poisson%20Distribution.-,Mode,x%3F%2C%20reaches%20a%20maximum.) that gives weighted values for, say, integer x. We define probability function as a closure: ```pascal P: TFunc; ```