mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-19 04:14:28 +00:00
Upgrade with rector
This commit is contained in:
@ -14,7 +14,7 @@ class DiagonalMatrix extends Matrix
|
||||
|
||||
for ($currentRow = 0; $currentRow < $rowCount; $currentRow++) {
|
||||
for ($currentCol = 0; $currentCol < $colCount; $currentCol++) {
|
||||
if ($currentRow == $currentCol) {
|
||||
if ($currentRow === $currentCol) {
|
||||
$this->setValue($currentRow, $currentCol, $diagonalValues[$currentRow]);
|
||||
} else {
|
||||
$this->setValue($currentRow, $currentCol, 0);
|
||||
|
@ -8,12 +8,8 @@ namespace DNW\Skills\Numerics;
|
||||
* @author Jeff Moser <jeff@moserware.com>
|
||||
* @copyright 2010 Jeff Moser
|
||||
*/
|
||||
class GaussianDistribution
|
||||
class GaussianDistribution implements \Stringable
|
||||
{
|
||||
private $_mean;
|
||||
|
||||
private $_standardDeviation;
|
||||
|
||||
// precision and precisionMean are used because they make multiplying and dividing simpler
|
||||
// (the the accompanying math paper for more details)
|
||||
private $_precision;
|
||||
@ -22,11 +18,9 @@ class GaussianDistribution
|
||||
|
||||
private $_variance;
|
||||
|
||||
public function __construct($mean = 0.0, $standardDeviation = 1.0)
|
||||
public function __construct(private $_mean = 0.0, private $_standardDeviation = 1.0)
|
||||
{
|
||||
$this->_mean = $mean;
|
||||
$this->_standardDeviation = $standardDeviation;
|
||||
$this->_variance = BasicMath::square($standardDeviation);
|
||||
$this->_variance = BasicMath::square($_standardDeviation);
|
||||
|
||||
if ($this->_variance != 0) {
|
||||
$this->_precision = 1.0 / $this->_variance;
|
||||
@ -34,11 +28,7 @@ class GaussianDistribution
|
||||
} else {
|
||||
$this->_precision = \INF;
|
||||
|
||||
if ($this->_mean == 0) {
|
||||
$this->_precisionMean = 0;
|
||||
} else {
|
||||
$this->_precisionMean = \INF;
|
||||
}
|
||||
$this->_precisionMean = $this->_mean == 0 ? 0 : \INF;
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,9 +162,8 @@ class GaussianDistribution
|
||||
|
||||
$multiplier = 1.0 / ($standardDeviation * sqrt(2 * M_PI));
|
||||
$expPart = exp((-1.0 * BasicMath::square($x - $mean)) / (2 * BasicMath::square($standardDeviation)));
|
||||
$result = $multiplier * $expPart;
|
||||
|
||||
return $result;
|
||||
return $multiplier * $expPart;
|
||||
}
|
||||
|
||||
public static function cumulativeTo($x, $mean = 0.0, $standardDeviation = 1.0)
|
||||
@ -267,7 +256,7 @@ class GaussianDistribution
|
||||
return $mean - sqrt(2) * $standardDeviation * GaussianDistribution::inverseErrorFunctionCumulativeTo(2 * $x);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('mean=%.4f standardDeviation=%.4f', $this->_mean, $this->_standardDeviation);
|
||||
}
|
||||
|
@ -6,19 +6,10 @@ use Exception;
|
||||
|
||||
class Matrix
|
||||
{
|
||||
const ERROR_TOLERANCE = 0.0000000001;
|
||||
public const ERROR_TOLERANCE = 0.0000000001;
|
||||
|
||||
private $_matrixRowData;
|
||||
|
||||
private $_rowCount;
|
||||
|
||||
private $_columnCount;
|
||||
|
||||
public function __construct($rows = 0, $columns = 0, $matrixData = null)
|
||||
public function __construct(private $_rowCount = 0, private $_columnCount = 0, private $_matrixRowData = null)
|
||||
{
|
||||
$this->_rowCount = $rows;
|
||||
$this->_columnCount = $columns;
|
||||
$this->_matrixRowData = $matrixData;
|
||||
}
|
||||
|
||||
public static function fromColumnValues($rows, $columns, $columnValues)
|
||||
@ -37,9 +28,8 @@ class Matrix
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function fromRowsColumns()
|
||||
public static function fromRowsColumns(...$args)
|
||||
{
|
||||
$args = \func_get_args();
|
||||
$rows = $args[0];
|
||||
$cols = $args[1];
|
||||
$result = new Matrix($rows, $cols);
|
||||
@ -138,7 +128,7 @@ class Matrix
|
||||
$firstRowColValue = $this->_matrixRowData[0][$currentColumn];
|
||||
$cofactor = $this->getCofactor(0, $currentColumn);
|
||||
$itemToAdd = $firstRowColValue * $cofactor;
|
||||
$result = $result + $itemToAdd;
|
||||
$result += $itemToAdd;
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -258,7 +248,7 @@ class Matrix
|
||||
$leftValue = $left->getValue($currentRow, $vectorIndex);
|
||||
$rightValue = $right->getValue($vectorIndex, $currentColumn);
|
||||
$vectorIndexProduct = $leftValue * $rightValue;
|
||||
$productValue = $productValue + $vectorIndexProduct;
|
||||
$productValue += $vectorIndexProduct;
|
||||
}
|
||||
|
||||
$resultMatrix[$currentRow][$currentColumn] = $productValue;
|
||||
|
@ -4,9 +4,8 @@ namespace DNW\Skills\Numerics;
|
||||
|
||||
class SquareMatrix extends Matrix
|
||||
{
|
||||
public function __construct()
|
||||
public function __construct(...$allValues)
|
||||
{
|
||||
$allValues = func_get_args();
|
||||
$rows = (int) sqrt(count($allValues));
|
||||
$cols = $rows;
|
||||
|
||||
|
Reference in New Issue
Block a user