PHPMD reintroduced.

This commit is contained in:
2024-07-04 09:38:03 +00:00
parent 5dc0c7058d
commit cf588f3fc2
28 changed files with 56692 additions and 165 deletions

View File

@ -13,15 +13,15 @@ namespace DNW\Skills\Numerics;
class BasicMath
{
/**
* Squares the input (x^2 = x * x)
* Squares the input (input^2 = input * input)
*
* @param $x Value to square (x)
* @param $input Value to square (input)
*
* @return float The squared value (x^2)
* @return float The squared value (input^2)
*/
public static function square(float $x): float
public static function square(float $input): float
{
return $x * $x;
return $input * $input;
}
/**

View File

@ -55,7 +55,6 @@ class GaussianDistribution
$this->precisionMean = $this->precision * $this->mean;
} else {
$this->precision = \INF;
$this->precisionMean = $this->mean == 0 ? 0 : \INF;
}
}
@ -175,7 +174,7 @@ class GaussianDistribution
BasicMath::square($meanDifference) / (2 * $varianceDifference);
}
public static function at(float $x, float $mean = 0.0, float $standardDeviation = 1.0): float
public static function at(float $var, float $mean = 0.0, float $standardDeviation = 1.0): float
{
// See http://mathworld.wolfram.com/NormalDistribution.html
// 1 -(x-mean)^2 / (2*stdDev^2)
@ -183,22 +182,22 @@ class GaussianDistribution
// stdDev * sqrt(2*pi)
$multiplier = 1.0 / ($standardDeviation * self::M_SQRT_2_PI);
$expPart = exp((-1.0 * BasicMath::square($x - $mean)) / (2 * BasicMath::square($standardDeviation)));
$expPart = exp((-1.0 * BasicMath::square($var - $mean)) / (2 * BasicMath::square($standardDeviation)));
return $multiplier * $expPart;
}
public static function cumulativeTo(float $x): float
public static function cumulativeTo(float $var): float
{
$result = GaussianDistribution::errorFunctionCumulativeTo(-M_SQRT1_2 * $x);
$result = GaussianDistribution::errorFunctionCumulativeTo(-M_SQRT1_2 * $var);
return 0.5 * $result;
}
private static function errorFunctionCumulativeTo(float $x): float
private static function errorFunctionCumulativeTo(float $var): float
{
// Derived from page 265 of Numerical Recipes 3rd Edition
$z = abs($x);
$z = abs($var);
$t = 2.0 / (2.0 + $z);
$ty = 4 * $t - 2;
@ -246,7 +245,7 @@ class GaussianDistribution
$ans = $t * exp(-$z * $z + 0.5 * ($coefficients[0] + $ty * $d) - $dd);
return ($x >= 0.0) ? $ans : (2.0 - $ans);
return ($var >= 0.0) ? $ans : (2.0 - $ans);
}
private static function inverseErrorFunctionCumulativeTo(float $p): float
@ -272,9 +271,9 @@ class GaussianDistribution
return ($p < 1.0) ? $x : -$x;
}
public static function inverseCumulativeTo(float $x, float $mean = 0.0, float $standardDeviation = 1.0): float
public static function inverseCumulativeTo(float $var, float $mean = 0.0, float $standardDeviation = 1.0): float
{
// From numerical recipes, page 320
return $mean - M_SQRT2 * $standardDeviation * GaussianDistribution::inverseErrorFunctionCumulativeTo(2 * $x);
return $mean - M_SQRT2 * $standardDeviation * GaussianDistribution::inverseErrorFunctionCumulativeTo(2 * $var);
}
}

View File

@ -76,10 +76,10 @@ class Matrix
$transposeMatrix = [];
$rowMatrixData = $this->matrixRowData;
for ($currentRowTransposeMatrix = 0; $currentRowTransposeMatrix < $this->columnCount; ++$currentRowTransposeMatrix) {
for ($currentColumnTransposeMatrix = 0; $currentColumnTransposeMatrix < $this->rowCount; ++$currentColumnTransposeMatrix) {
$transposeMatrix[$currentRowTransposeMatrix][$currentColumnTransposeMatrix] =
$rowMatrixData[$currentColumnTransposeMatrix][$currentRowTransposeMatrix];
for ($curRowTransposeMx = 0; $curRowTransposeMx < $this->columnCount; ++$curRowTransposeMx) {
for ($curColTransposeMx = 0; $curColTransposeMx < $this->rowCount; ++$curColTransposeMx) {
$transposeMatrix[$curRowTransposeMx][$curColTransposeMx] =
$rowMatrixData[$curColTransposeMx][$curRowTransposeMx];
}
}