tablepress
/
libraries
/
vendor
/
PhpSpreadsheet
/
Calculation
/
Statistical
/
Distributions
/
Exponential.php
Exponential.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php
| 1 | <?php |
| 2 | |
| 3 | namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions; |
| 4 | |
| 5 | use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; |
| 6 | use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception; |
| 7 | use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; |
| 8 | |
| 9 | class Exponential |
| 10 | { |
| 11 | use ArrayEnabled; |
| 12 | |
| 13 | /** |
| 14 | * EXPONDIST. |
| 15 | * |
| 16 | * Returns the exponential distribution. Use EXPONDIST to model the time between events, |
| 17 | * such as how long an automated bank teller takes to deliver cash. For example, you can |
| 18 | * use EXPONDIST to determine the probability that the process takes at most 1 minute. |
| 19 | * |
| 20 | * @param mixed $value Float value for which we want the probability |
| 21 | * Or can be an array of values |
| 22 | * @param mixed $lambda The parameter value as a float |
| 23 | * Or can be an array of values |
| 24 | * @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false) |
| 25 | * Or can be an array of values |
| 26 | * |
| 27 | * @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array |
| 28 | * with the same dimensions |
| 29 | */ |
| 30 | public static function distribution($value, $lambda, $cumulative) |
| 31 | { |
| 32 | if (is_array($value) || is_array($lambda) || is_array($cumulative)) { |
| 33 | return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $lambda, $cumulative); |
| 34 | } |
| 35 | |
| 36 | try { |
| 37 | $value = DistributionValidations::validateFloat($value); |
| 38 | $lambda = DistributionValidations::validateFloat($lambda); |
| 39 | $cumulative = DistributionValidations::validateBool($cumulative); |
| 40 | } catch (Exception $e) { |
| 41 | return $e->getMessage(); |
| 42 | } |
| 43 | |
| 44 | if (($value < 0) || ($lambda < 0)) { |
| 45 | return ExcelError::NAN(); |
| 46 | } |
| 47 | |
| 48 | if ($cumulative === true) { |
| 49 | return 1 - exp(0 - $value * $lambda); |
| 50 | } |
| 51 | |
| 52 | return $lambda * exp(0 - $value * $lambda); |
| 53 | } |
| 54 | } |
| 55 |