tablepress
/
libraries
/
vendor
/
PhpSpreadsheet
/
Calculation
/
Statistical
/
Distributions
/
Weibull.php
Weibull.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.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 Weibull |
| 10 | { |
| 11 | use ArrayEnabled; |
| 12 | |
| 13 | /** |
| 14 | * WEIBULL. |
| 15 | * |
| 16 | * Returns the Weibull distribution. Use this distribution in reliability |
| 17 | * analysis, such as calculating a device's mean time to failure. |
| 18 | * |
| 19 | * @param mixed $value Float value for the distribution |
| 20 | * Or can be an array of values |
| 21 | * @param mixed $alpha Float alpha Parameter |
| 22 | * Or can be an array of values |
| 23 | * @param mixed $beta Float beta Parameter |
| 24 | * Or can be an array of values |
| 25 | * @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false) |
| 26 | * Or can be an array of values |
| 27 | * |
| 28 | * @return array<mixed>|float|string (string if result is an error) |
| 29 | * If an array of numbers is passed as an argument, then the returned result will also be an array |
| 30 | * with the same dimensions |
| 31 | */ |
| 32 | public static function distribution($value, $alpha, $beta, $cumulative) |
| 33 | { |
| 34 | if (is_array($value) || is_array($alpha) || is_array($beta) || is_array($cumulative)) { |
| 35 | return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $alpha, $beta, $cumulative); |
| 36 | } |
| 37 | |
| 38 | try { |
| 39 | $value = DistributionValidations::validateFloat($value); |
| 40 | $alpha = DistributionValidations::validateFloat($alpha); |
| 41 | $beta = DistributionValidations::validateFloat($beta); |
| 42 | $cumulative = DistributionValidations::validateBool($cumulative); |
| 43 | } catch (Exception $e) { |
| 44 | return $e->getMessage(); |
| 45 | } |
| 46 | |
| 47 | if (($value < 0) || ($alpha <= 0) || ($beta <= 0)) { |
| 48 | return ExcelError::NAN(); |
| 49 | } |
| 50 | |
| 51 | if ($cumulative) { |
| 52 | return 1 - exp(0 - ($value / $beta) ** $alpha); |
| 53 | } |
| 54 | |
| 55 | return ($alpha / $beta ** $alpha) * $value ** ($alpha - 1) * exp(0 - ($value / $beta) ** $alpha); |
| 56 | } |
| 57 | } |
| 58 |