ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
LogNormal.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 class LogNormal
9 {
22  public static function cumulative($value, $mean, $stdDev)
23  {
24  $value = Functions::flattenSingleValue($value);
25  $mean = Functions::flattenSingleValue($mean);
26  $stdDev = Functions::flattenSingleValue($stdDev);
27 
28  try {
31  $stdDev = DistributionValidations::validateFloat($stdDev);
32  } catch (Exception $e) {
33  return $e->getMessage();
34  }
35 
36  if (($value <= 0) || ($stdDev <= 0)) {
37  return Functions::NAN();
38  }
39 
40  return StandardNormal::cumulative((log($value) - $mean) / $stdDev);
41  }
42 
56  public static function distribution($value, $mean, $stdDev, $cumulative = false)
57  {
58  $value = Functions::flattenSingleValue($value);
59  $mean = Functions::flattenSingleValue($mean);
60  $stdDev = Functions::flattenSingleValue($stdDev);
61  $cumulative = Functions::flattenSingleValue($cumulative);
62 
63  try {
66  $stdDev = DistributionValidations::validateFloat($stdDev);
67  $cumulative = DistributionValidations::validateBool($cumulative);
68  } catch (Exception $e) {
69  return $e->getMessage();
70  }
71 
72  if (($value <= 0) || ($stdDev <= 0)) {
73  return Functions::NAN();
74  }
75 
76  if ($cumulative === true) {
77  return StandardNormal::distribution((log($value) - $mean) / $stdDev, true);
78  }
79 
80  return (1 / (sqrt(2 * M_PI) * $stdDev * $value)) *
81  exp(0 - ((log($value) - $mean) ** 2 / (2 * $stdDev ** 2)));
82  }
83 
99  public static function inverse($probability, $mean, $stdDev)
100  {
101  $probability = Functions::flattenSingleValue($probability);
102  $mean = Functions::flattenSingleValue($mean);
103  $stdDev = Functions::flattenSingleValue($stdDev);
104 
105  try {
106  $probability = DistributionValidations::validateProbability($probability);
108  $stdDev = DistributionValidations::validateFloat($stdDev);
109  } catch (Exception $e) {
110  return $e->getMessage();
111  }
112 
113  if ($stdDev <= 0) {
114  return Functions::NAN();
115  }
116 
117  return exp($mean + $stdDev * StandardNormal::inverse($probability));
118  }
119 }
static distribution($value, $mean, $stdDev, $cumulative=false)
LOGNORM.DIST.
Definition: LogNormal.php:56
static inverse($probability, $mean, $stdDev)
LOGINV.
Definition: LogNormal.php:99
static cumulative($value, $mean, $stdDev)
LOGNORMDIST.
Definition: LogNormal.php:22
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649