MathPHP\Statistics\Average::generalizedMean PHP Метод

generalizedMean() публичный статический Метод

1 n \ 1/p Mp(x) = | - ∑ xᵢᵖ| \ n ⁱ⁼¹ / Special cases: M-∞(x) is min(x) M₋₁(x) is the harmonic mean M₀(x) is the geometric mean M₁(x) is the arithmetic mean M₂(x) is the quadratic mean M₃(x) is the cubic mean M∞(x) is max(X)
public static generalizedMean ( array $numbers, number $p ) : number
$numbers array
$p number
Результат number
    public static function generalizedMean(array $numbers, $p)
    {
        // Special cases for infinite p
        if ($p == -\INF) {
            return min($numbers);
        }
        if ($p == \INF) {
            return max($numbers);
        }
        // Special case for p = 0 (geometric mean)
        if ($p == 0) {
            return self::geometricMean($numbers);
        }
        // Standard case for non-infinite p
        $n = count($numbers);
        $∑xᵢᵖ = array_sum(array_map(function ($x) use($p) {
            return $x ** $p;
        }, $numbers));
        return pow(1 / $n * $∑xᵢᵖ, 1 / $p);
    }