Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| LogLevelRegression | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| getRegression | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getSlope | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getElasticity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Math\Statistic\Forecast\Regression |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Math\Statistic\Forecast\Regression; |
| 16 | |
| 17 | use phpOMS\Math\Matrix\Exception\InvalidDimensionException; |
| 18 | |
| 19 | /** |
| 20 | * Regression class. |
| 21 | * |
| 22 | * @package phpOMS\Math\Statistic\Forecast\Regression |
| 23 | * @license OMS License 2.0 |
| 24 | * @link https://jingga.app |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | final class LogLevelRegression extends RegressionAbstract |
| 28 | { |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | * |
| 32 | * @throws InvalidDimensionException |
| 33 | */ |
| 34 | public static function getRegression(array $x, array $y) : array |
| 35 | { |
| 36 | if (($c = \count($x)) !== \count($y)) { |
| 37 | throw new InvalidDimensionException($c . 'x' . \count($y)); |
| 38 | } |
| 39 | |
| 40 | for ($i = 0; $i < $c; ++$i) { |
| 41 | $y[$i] = \log($y[$i]); |
| 42 | } |
| 43 | |
| 44 | return parent::getRegression($x, $y); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * {@inheritdoc} |
| 49 | */ |
| 50 | public static function getSlope(float $b1, float $y, float $x) : float |
| 51 | { |
| 52 | return $b1 * $y; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * {@inheritdoc} |
| 57 | */ |
| 58 | public static function getElasticity(float $b1, float $y, float $x) : float |
| 59 | { |
| 60 | return $b1 * $x; |
| 61 | } |
| 62 | } |