mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 10:12:28 +01:00 
			
		
		
		
	Much stricter coding standards for phpstan, phpstan and psalm.
This commit is contained in:
		@@ -10,7 +10,7 @@ namespace DNW\Skills\Numerics;
 | 
			
		||||
 * @author    Jeff Moser <jeff@moserware.com>
 | 
			
		||||
 * @copyright 2010 Jeff Moser
 | 
			
		||||
 */
 | 
			
		||||
class BasicMath
 | 
			
		||||
final class BasicMath
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Squares the input (input^2 = input * input)
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ namespace DNW\Skills\Numerics;
 | 
			
		||||
 * @author    Jeff Moser <jeff@moserware.com>
 | 
			
		||||
 * @copyright 2010 Jeff Moser
 | 
			
		||||
 */
 | 
			
		||||
class GaussianDistribution
 | 
			
		||||
final class GaussianDistribution
 | 
			
		||||
{
 | 
			
		||||
    private const float DEFAULT_STANDARD_DEVIATION = 1.0;
 | 
			
		||||
 | 
			
		||||
@@ -171,7 +171,7 @@ class GaussianDistribution
 | 
			
		||||
        $meanDifference = $numerator->mean - $denominator->mean;
 | 
			
		||||
 | 
			
		||||
        return log($denominator->variance) + self::M_LOG_SQRT_2_PI - log($varianceDifference) / 2.0 +
 | 
			
		||||
        BasicMath::square($meanDifference) / (2 * $varianceDifference);
 | 
			
		||||
        BasicMath::square($meanDifference) / (2.0 * $varianceDifference);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function at(float $var, float $mean = 0.0, float $standardDeviation = 1.0): float
 | 
			
		||||
@@ -182,7 +182,7 @@ class GaussianDistribution
 | 
			
		||||
        //        stdDev * sqrt(2*pi)
 | 
			
		||||
 | 
			
		||||
        $multiplier = 1.0 / ($standardDeviation * self::M_SQRT_2_PI);
 | 
			
		||||
        $expPart = exp((-1.0 * BasicMath::square($var - $mean)) / (2 * BasicMath::square($standardDeviation)));
 | 
			
		||||
        $expPart = exp((-1.0 * BasicMath::square($var - $mean)) / (2.0 * BasicMath::square($standardDeviation)));
 | 
			
		||||
 | 
			
		||||
        return $multiplier * $expPart;
 | 
			
		||||
    }
 | 
			
		||||
@@ -200,7 +200,7 @@ class GaussianDistribution
 | 
			
		||||
        $z = abs($var);
 | 
			
		||||
 | 
			
		||||
        $t = 2.0 / (2.0 + $z);
 | 
			
		||||
        $ty = 4 * $t - 2;
 | 
			
		||||
        $ty = 4.0 * $t - 2.0;
 | 
			
		||||
 | 
			
		||||
        $coefficients = [
 | 
			
		||||
            -1.3026537197817094,
 | 
			
		||||
@@ -259,8 +259,8 @@ class GaussianDistribution
 | 
			
		||||
            return 100;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $pp = ($p < 1.0) ? $p : 2 - $p;
 | 
			
		||||
        $t = sqrt(-2 * log($pp / 2.0)); // Initial guess
 | 
			
		||||
        $pp = ($p < 1.0) ? $p : 2.0 - $p;
 | 
			
		||||
        $t = sqrt(-2.0 * log($pp / 2.0)); // Initial guess
 | 
			
		||||
        $x = -M_SQRT1_2 * ((2.30753 + $t * 0.27061) / (1.0 + $t * (0.99229 + $t * 0.04481)) - $t);
 | 
			
		||||
 | 
			
		||||
        for ($j = 0; $j < 2; ++$j) {
 | 
			
		||||
@@ -274,6 +274,6 @@ class GaussianDistribution
 | 
			
		||||
    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 * $var);
 | 
			
		||||
        return $mean - M_SQRT2 * $standardDeviation * GaussianDistribution::inverseErrorFunctionCumulativeTo(2.0 * $var);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\Numerics;
 | 
			
		||||
 | 
			
		||||
class IdentityMatrix extends DiagonalMatrix
 | 
			
		||||
final class IdentityMatrix extends DiagonalMatrix
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(int $rows)
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -130,10 +130,10 @@ class Matrix
 | 
			
		||||
            // | a b |
 | 
			
		||||
            // | c d |
 | 
			
		||||
            // The determinant is ad - bc
 | 
			
		||||
            $a = $this->getValue(0, 0);
 | 
			
		||||
            $b = $this->getValue(0, 1);
 | 
			
		||||
            $c = $this->getValue(1, 0);
 | 
			
		||||
            $d = $this->getValue(1, 1);
 | 
			
		||||
            $a = (float)$this->getValue(0, 0);
 | 
			
		||||
            $b = (float)$this->getValue(0, 1);
 | 
			
		||||
            $c = (float)$this->getValue(1, 0);
 | 
			
		||||
            $d = (float)$this->getValue(1, 1);
 | 
			
		||||
 | 
			
		||||
            return $a * $d - $b * $c;
 | 
			
		||||
        }
 | 
			
		||||
@@ -148,7 +148,7 @@ class Matrix
 | 
			
		||||
 | 
			
		||||
        // I expand along the first row
 | 
			
		||||
        for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) {
 | 
			
		||||
            $firstRowColValue = $this->getValue(0, $currentColumn);
 | 
			
		||||
            $firstRowColValue = (float)$this->getValue(0, $currentColumn);
 | 
			
		||||
            $cofactor = $this->getCofactor(0, $currentColumn);
 | 
			
		||||
            $itemToAdd = $firstRowColValue * $cofactor;
 | 
			
		||||
            $result += $itemToAdd;
 | 
			
		||||
@@ -201,7 +201,7 @@ class Matrix
 | 
			
		||||
    public function getInverse(): Matrix|SquareMatrix
 | 
			
		||||
    {
 | 
			
		||||
        if (($this->rowCount == 1) && ($this->columnCount == 1)) {
 | 
			
		||||
            return new SquareMatrix(1.0 / $this->getValue(0, 0));
 | 
			
		||||
            return new SquareMatrix(1.0 / (float)$this->getValue(0, 0));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Take the simple approach:
 | 
			
		||||
@@ -240,9 +240,9 @@ class Matrix
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $left->getRowCount(); ++$currentRow) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); ++$currentColumn) {
 | 
			
		||||
                $resultMatrix[$currentRow][$currentColumn] =
 | 
			
		||||
                    $left->getValue($currentRow, $currentColumn)
 | 
			
		||||
                    (float)$left->getValue($currentRow, $currentColumn)
 | 
			
		||||
                    +
 | 
			
		||||
                    $right->getValue($currentRow, $currentColumn);
 | 
			
		||||
                    (float)$right->getValue($currentRow, $currentColumn);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -268,8 +268,8 @@ class Matrix
 | 
			
		||||
                $productValue = 0;
 | 
			
		||||
 | 
			
		||||
                for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); ++$vectorIndex) {
 | 
			
		||||
                    $leftValue = $left->getValue($currentRow, $vectorIndex);
 | 
			
		||||
                    $rightValue = $right->getValue($vectorIndex, $currentColumn);
 | 
			
		||||
                    $leftValue = (float)$left->getValue($currentRow, $vectorIndex);
 | 
			
		||||
                    $rightValue = (float)$right->getValue($vectorIndex, $currentColumn);
 | 
			
		||||
                    $vectorIndexProduct = $leftValue * $rightValue;
 | 
			
		||||
                    $productValue += $vectorIndexProduct;
 | 
			
		||||
                }
 | 
			
		||||
@@ -339,8 +339,8 @@ class Matrix
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) {
 | 
			
		||||
                $delta =
 | 
			
		||||
                    abs(
 | 
			
		||||
                        $this->getValue($currentRow, $currentColumn) -
 | 
			
		||||
                        $otherMatrix->getValue($currentRow, $currentColumn)
 | 
			
		||||
                        (float)$this->getValue($currentRow, $currentColumn) -
 | 
			
		||||
                        (float)$otherMatrix->getValue($currentRow, $currentColumn)
 | 
			
		||||
                    );
 | 
			
		||||
 | 
			
		||||
                if ($delta > self::ERROR_TOLERANCE) {
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\Numerics;
 | 
			
		||||
 | 
			
		||||
class SquareMatrix extends Matrix
 | 
			
		||||
final class SquareMatrix extends Matrix
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(float|int ...$allValues)
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\Numerics;
 | 
			
		||||
 | 
			
		||||
class Vector extends Matrix
 | 
			
		||||
final class Vector extends Matrix
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @param float[] $vectorValues
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user