ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Poisson.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 class Poisson
10 {
24  public static function distribution($value, $mean, $cumulative)
25  {
26  $value = Functions::flattenSingleValue($value);
27  $mean = Functions::flattenSingleValue($mean);
28 
29  try {
32  $cumulative = DistributionValidations::validateBool($cumulative);
33  } catch (Exception $e) {
34  return $e->getMessage();
35  }
36 
37  if (($value < 0) || ($mean < 0)) {
38  return Functions::NAN();
39  }
40 
41  if ($cumulative) {
42  $summer = 0;
43  $floor = floor($value);
44  for ($i = 0; $i <= $floor; ++$i) {
45  $summer += $mean ** $i / MathTrig\Factorial::fact($i);
46  }
47 
48  return exp(0 - $mean) * $summer;
49  }
50 
51  return (exp(0 - $mean) * $mean ** $value) / MathTrig\Factorial::fact($value);
52  }
53 }
$i
Definition: disco.tpl.php:19
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
static distribution($value, $mean, $cumulative)
POISSON.
Definition: Poisson.php:24