MathPHP\Statistics\Average::lehmerMean PHP Method

lehmerMean() public static method

∑xᵢᵖ Lp(x) = ------ ∑xᵢᵖ⁻¹ Special cases: L-∞(x) is the min(x) L₀(x) is the harmonic mean L½(x₀, x₁) is the geometric mean if computed against two numbers L₁(x) is the arithmetic mean L₂(x) is the contraharmonic mean L∞(x) is the max(x)
public static lehmerMean ( array $numbers, number $p ) : number
$numbers array
$p number
return number
    public static function lehmerMean(array $numbers, $p)
    {
        // Special cases for infinite p
        if ($p == -\INF) {
            return min($numbers);
        }
        if ($p == \INF) {
            return max($numbers);
        }
        // Standard case for non-infinite p
        $∑xᵢᵖ = array_sum(array_map(function ($x) use($p) {
            return $x ** $p;
        }, $numbers));
        $∑xᵢᵖ⁻¹ = array_sum(array_map(function ($x) use($p) {
            return $x ** ($p - 1);
        }, $numbers));
        return $∑xᵢᵖ / $∑xᵢᵖ⁻¹;
    }