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

Without repetition: (n) n! nCk = ( ) = ---------- (k) (n - k)!k! With repetition: (n) (n + k - 1)! nC'k = ( ) = ------------ (k) (n - 1)!k! http://mathworld.wolfram.com/BinomialCoefficient.html
public static combinations ( integer $n, integer $k, boolean $repetition = false ) : integer
$n integer
$k integer
$repetition boolean Whether to do n choose k with or without repetitions
Результат integer number of possible combinations of n objects taken k at a time
Пример #1
0
 /**
  * Binomial distribution - probability mass function
  * https://en.wikipedia.org/wiki/Binomial_distribution
  *
  * P(X = r) = nCr pʳ (1 - p)ⁿ⁻ʳ
  *
  * @param  int   $n number of events
  * @param  int   $r number of successful events
  * @param  float $p probability of success
  *
  * @return float
  */
 public static function PMF(int $n, int $r, float $p) : float
 {
     Support::checkLimits(self::LIMITS, ['n' => $n, 'r' => $r, 'p' => $p]);
     $nCr = Combinatorics::combinations($n, $r);
     $pʳ = pow($p, $r);
     $⟮1 − p⟯ⁿ⁻ʳ = pow(1 - $p, $n - $r);
     return $nCr * $pʳ * $⟮1 − p⟯ⁿ⁻ʳ;
 }
Пример #2
0
 /**
  * Probability mass function
  *
  * b(x; r, p) = ₓ₋₁Cᵣ₋₁ pʳ * (1 - p)ˣ⁻ʳ
  *
  * @param  int   $x number of trials required to produce r successes
  * @param  int   $r number of successful events
  * @param  float $p probability of success on an individual trial
  *
  * @return float
  */
 public static function PMF(int $x, int $r, float $p) : float
 {
     Support::checkLimits(self::LIMITS, ['x' => $x, 'r' => $r, 'p' => $p]);
     $ₓ₋₁Cᵣ₋₁ = Combinatorics::combinations($x - 1, $r - 1);
     $pʳ = pow($p, $r);
     $⟮1 − p⟯ˣ⁻ʳ = pow(1 - $p, $x - $r);
     return $ₓ₋₁Cᵣ₋₁ * $pʳ * $⟮1 − p⟯ˣ⁻ʳ;
 }