MathPHP\Probability\Combinatorics::factorial PHP Метод

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

Factorial (iterative) Represents the number of ways to arrange n things (permutations) n! = n(n - 1)(n - 2) ・・・ (n - (n - 1))
public static factorial ( integer $n ) : integer
$n integer
Результат integer number of permutations of n
    public static function factorial(int $n)
    {
        if ($n < 0) {
            throw new Exception\OutOfBoundsException('Cannot compute factorial of a negative number.');
        }
        $factorial = 1;
        while ($n > 0) {
            $factorial *= $n;
            $n--;
        }
        return $factorial;
    }

Usage Example

Пример #1
0
 /**
  * Poisson distribution - probability mass function
  * A discrete probability distribution that expresses the probability of a given number of events
  * occurring in a fixed interval of time and/or space if these events occur with a known average
  * rate and independently of the time since the last event.
  * https://en.wikipedia.org/wiki/Poisson_distribution
  *
  *                              λᵏℯ^⁻λ
  * P(k events in an interval) = ------
  *                                k!
  *
  * @param  int   $k events in the interval
  * @param  float $λ average number of successful events per interval
  *
  * @return float The Poisson probability of observing k successful events in an interval
  */
 public static function PMF(int $k, float $λ) : float
 {
     Support::checkLimits(self::LIMITS, ['k' => $k, 'λ' => $λ]);
     $λᵏℯ^−λ = pow($λ, $k) * exp(-$λ);
     $k! = Combinatorics::factorial($k);
     return $λᵏℯ^−λ / $k!;
 }
All Usage Examples Of MathPHP\Probability\Combinatorics::factorial