mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
No more use of $_ to mark private members.
This commit is contained in:
@ -4,13 +4,13 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class KeyedVariable extends Variable
|
||||
{
|
||||
public function __construct(private mixed $_key, string $name, mixed $prior)
|
||||
public function __construct(private mixed $key, string $name, mixed $prior)
|
||||
{
|
||||
parent::__construct($name, $prior);
|
||||
}
|
||||
|
||||
public function getKey(): mixed
|
||||
{
|
||||
return $this->_key;
|
||||
return $this->key;
|
||||
}
|
||||
}
|
||||
|
@ -4,22 +4,22 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class Message implements \Stringable
|
||||
{
|
||||
public function __construct(private $_value = null, private $_name = null)
|
||||
public function __construct(private $value = null, private $name = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string) $this->_name;
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleLoop extends Schedule
|
||||
{
|
||||
public function __construct($name, private readonly Schedule $_scheduleToLoop, private $_maxDelta)
|
||||
public function __construct($name, private readonly Schedule $scheduleToLoop, private $maxDelta)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
@ -12,9 +12,9 @@ class ScheduleLoop extends Schedule
|
||||
public function visit(int $depth = -1, int $maxDepth = 0)
|
||||
{
|
||||
$totalIterations = 1;
|
||||
$delta = $this->_scheduleToLoop->visit($depth + 1, $maxDepth);
|
||||
while ($delta > $this->_maxDelta) {
|
||||
$delta = $this->_scheduleToLoop->visit($depth + 1, $maxDepth);
|
||||
$delta = $this->scheduleToLoop->visit($depth + 1, $maxDepth);
|
||||
while ($delta > $this->maxDelta) {
|
||||
$delta = $this->scheduleToLoop->visit($depth + 1, $maxDepth);
|
||||
$totalIterations++;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleSequence extends Schedule
|
||||
{
|
||||
public function __construct($name, private readonly array $_schedules)
|
||||
public function __construct($name, private readonly array $schedules)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
@ -13,7 +13,7 @@ class ScheduleSequence extends Schedule
|
||||
{
|
||||
$maxDelta = 0;
|
||||
|
||||
$schedules = $this->_schedules;
|
||||
$schedules = $this->schedules;
|
||||
foreach ($schedules as $currentSchedule) {
|
||||
$currentVisit = $currentSchedule->visit($depth + 1, $maxDepth);
|
||||
$maxDelta = max($currentVisit, $maxDelta);
|
||||
|
@ -4,15 +4,15 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleStep extends Schedule
|
||||
{
|
||||
public function __construct($name, private readonly Factor $_factor, private $_index)
|
||||
public function __construct($name, private readonly Factor $factor, private $index)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function visit(int $depth = -1, int $maxDepth = 0)
|
||||
{
|
||||
$currentFactor = $this->_factor;
|
||||
$currentFactor = $this->factor;
|
||||
|
||||
return $currentFactor->updateMessageIndex($this->_index);
|
||||
return $currentFactor->updateMessageIndex($this->index);
|
||||
}
|
||||
}
|
||||
|
@ -4,20 +4,20 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class VariableFactory
|
||||
{
|
||||
public function __construct(private $_variablePriorInitializer)
|
||||
public function __construct(private $variablePriorInitializer)
|
||||
{
|
||||
}
|
||||
|
||||
public function createBasicVariable(string $name): Variable
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$initializer = $this->variablePriorInitializer;
|
||||
|
||||
return new Variable($name, $initializer());
|
||||
}
|
||||
|
||||
public function createKeyedVariable(mixed $key, string $name): KeyedVariable
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$initializer = $this->variablePriorInitializer;
|
||||
|
||||
return new KeyedVariable($key, $name, $initializer());
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class Matrix
|
||||
{
|
||||
public const ERROR_TOLERANCE = 0.0000000001;
|
||||
|
||||
public function __construct(private int $_rowCount = 0, private int $_columnCount = 0, private $_matrixRowData = null)
|
||||
public function __construct(private int $rowCount = 0, private int $columnCount = 0, private $matrixRowData = null)
|
||||
{
|
||||
}
|
||||
|
||||
@ -46,22 +46,22 @@ class Matrix
|
||||
|
||||
public function getRowCount(): int
|
||||
{
|
||||
return $this->_rowCount;
|
||||
return $this->rowCount;
|
||||
}
|
||||
|
||||
public function getColumnCount(): int
|
||||
{
|
||||
return $this->_columnCount;
|
||||
return $this->columnCount;
|
||||
}
|
||||
|
||||
public function getValue(int $row, int $col): float|int
|
||||
{
|
||||
return $this->_matrixRowData[$row][$col];
|
||||
return $this->matrixRowData[$row][$col];
|
||||
}
|
||||
|
||||
public function setValue(int $row, int $col, float|int $value)
|
||||
{
|
||||
$this->_matrixRowData[$row][$col] = $value;
|
||||
$this->matrixRowData[$row][$col] = $value;
|
||||
}
|
||||
|
||||
public function getTranspose(): self
|
||||
@ -69,15 +69,15 @@ class Matrix
|
||||
// Just flip everything
|
||||
$transposeMatrix = [];
|
||||
|
||||
$rowMatrixData = $this->_matrixRowData;
|
||||
$rowMatrixData = $this->matrixRowData;
|
||||
for (
|
||||
$currentRowTransposeMatrix = 0;
|
||||
$currentRowTransposeMatrix < $this->_columnCount;
|
||||
$currentRowTransposeMatrix < $this->columnCount;
|
||||
$currentRowTransposeMatrix++
|
||||
) {
|
||||
for (
|
||||
$currentColumnTransposeMatrix = 0;
|
||||
$currentColumnTransposeMatrix < $this->_rowCount;
|
||||
$currentColumnTransposeMatrix < $this->rowCount;
|
||||
$currentColumnTransposeMatrix++
|
||||
) {
|
||||
$transposeMatrix[$currentRowTransposeMatrix][$currentColumnTransposeMatrix] =
|
||||
@ -85,12 +85,12 @@ class Matrix
|
||||
}
|
||||
}
|
||||
|
||||
return new Matrix($this->_columnCount, $this->_rowCount, $transposeMatrix);
|
||||
return new Matrix($this->columnCount, $this->rowCount, $transposeMatrix);
|
||||
}
|
||||
|
||||
private function isSquare(): bool
|
||||
{
|
||||
return ($this->_rowCount == $this->_columnCount) && ($this->_rowCount > 0);
|
||||
return ($this->rowCount == $this->columnCount) && ($this->rowCount > 0);
|
||||
}
|
||||
|
||||
public function getDeterminant(): float
|
||||
@ -100,21 +100,21 @@ class Matrix
|
||||
throw new Exception('Matrix must be square!');
|
||||
}
|
||||
|
||||
if ($this->_rowCount == 1) {
|
||||
if ($this->rowCount == 1) {
|
||||
// Really happy path :)
|
||||
return $this->_matrixRowData[0][0];
|
||||
return $this->matrixRowData[0][0];
|
||||
}
|
||||
|
||||
if ($this->_rowCount == 2) {
|
||||
if ($this->rowCount == 2) {
|
||||
// Happy path!
|
||||
// Given:
|
||||
// | a b |
|
||||
// | c d |
|
||||
// The determinant is ad - bc
|
||||
$a = $this->_matrixRowData[0][0];
|
||||
$b = $this->_matrixRowData[0][1];
|
||||
$c = $this->_matrixRowData[1][0];
|
||||
$d = $this->_matrixRowData[1][1];
|
||||
$a = $this->matrixRowData[0][0];
|
||||
$b = $this->matrixRowData[0][1];
|
||||
$c = $this->matrixRowData[1][0];
|
||||
$d = $this->matrixRowData[1][1];
|
||||
|
||||
return $a * $d - $b * $c;
|
||||
}
|
||||
@ -128,8 +128,8 @@ class Matrix
|
||||
$result = 0.0;
|
||||
|
||||
// I expand along the first row
|
||||
for ($currentColumn = 0; $currentColumn < $this->_columnCount; $currentColumn++) {
|
||||
$firstRowColValue = $this->_matrixRowData[0][$currentColumn];
|
||||
for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) {
|
||||
$firstRowColValue = $this->matrixRowData[0][$currentColumn];
|
||||
$cofactor = $this->getCofactor(0, $currentColumn);
|
||||
$itemToAdd = $firstRowColValue * $cofactor;
|
||||
$result += $itemToAdd;
|
||||
@ -145,7 +145,7 @@ class Matrix
|
||||
}
|
||||
|
||||
// See http://en.wikipedia.org/wiki/Adjugate_matrix
|
||||
if ($this->_rowCount == 2) {
|
||||
if ($this->rowCount == 2) {
|
||||
// Happy path!
|
||||
// Adjugate of:
|
||||
// | a b |
|
||||
@ -154,10 +154,10 @@ class Matrix
|
||||
// | d -b |
|
||||
// | -c a |
|
||||
|
||||
$a = $this->_matrixRowData[0][0];
|
||||
$b = $this->_matrixRowData[0][1];
|
||||
$c = $this->_matrixRowData[1][0];
|
||||
$d = $this->_matrixRowData[1][1];
|
||||
$a = $this->matrixRowData[0][0];
|
||||
$b = $this->matrixRowData[0][1];
|
||||
$c = $this->matrixRowData[1][0];
|
||||
$d = $this->matrixRowData[1][1];
|
||||
|
||||
return new SquareMatrix(
|
||||
$d,
|
||||
@ -170,19 +170,19 @@ class Matrix
|
||||
// The idea is that it's the transpose of the cofactors
|
||||
$result = [];
|
||||
|
||||
for ($currentColumn = 0; $currentColumn < $this->_columnCount; $currentColumn++) {
|
||||
for ($currentRow = 0; $currentRow < $this->_rowCount; $currentRow++) {
|
||||
for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) {
|
||||
for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) {
|
||||
$result[$currentColumn][$currentRow] = $this->getCofactor($currentRow, $currentColumn);
|
||||
}
|
||||
}
|
||||
|
||||
return new Matrix($this->_columnCount, $this->_rowCount, $result);
|
||||
return new Matrix($this->columnCount, $this->rowCount, $result);
|
||||
}
|
||||
|
||||
public function getInverse(): Matrix|SquareMatrix
|
||||
{
|
||||
if (($this->_rowCount == 1) && ($this->_columnCount == 1)) {
|
||||
return new SquareMatrix(1.0 / $this->_matrixRowData[0][0]);
|
||||
if (($this->rowCount == 1) && ($this->columnCount == 1)) {
|
||||
return new SquareMatrix(1.0 / $this->matrixRowData[0][0]);
|
||||
}
|
||||
|
||||
// Take the simple approach:
|
||||
@ -275,19 +275,19 @@ class Matrix
|
||||
|
||||
$actualRow = 0;
|
||||
|
||||
for ($currentRow = 0; $currentRow < $this->_rowCount; $currentRow++) {
|
||||
for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) {
|
||||
if ($currentRow == $rowToRemove) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$actualCol = 0;
|
||||
|
||||
for ($currentColumn = 0; $currentColumn < $this->_columnCount; $currentColumn++) {
|
||||
for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) {
|
||||
if ($currentColumn == $columnToRemove) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$actualRow][$actualCol] = $this->_matrixRowData[$currentRow][$currentColumn];
|
||||
$result[$actualRow][$actualCol] = $this->matrixRowData[$currentRow][$currentColumn];
|
||||
|
||||
$actualCol++;
|
||||
}
|
||||
@ -295,7 +295,7 @@ class Matrix
|
||||
$actualRow++;
|
||||
}
|
||||
|
||||
return new Matrix($this->_rowCount - 1, $this->_columnCount - 1, $result);
|
||||
return new Matrix($this->rowCount - 1, $this->columnCount - 1, $result);
|
||||
}
|
||||
|
||||
public function getCofactor($rowToRemove, $columnToRemove)
|
||||
@ -319,15 +319,15 @@ class Matrix
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($this->_rowCount != $otherMatrix->getRowCount()) || ($this->_columnCount != $otherMatrix->getColumnCount())) {
|
||||
if (($this->rowCount != $otherMatrix->getRowCount()) || ($this->columnCount != $otherMatrix->getColumnCount())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($currentRow = 0; $currentRow < $this->_rowCount; $currentRow++) {
|
||||
for ($currentColumn = 0; $currentColumn < $this->_columnCount; $currentColumn++) {
|
||||
for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) {
|
||||
for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) {
|
||||
$delta =
|
||||
abs(
|
||||
$this->_matrixRowData[$currentRow][$currentColumn] -
|
||||
$this->matrixRowData[$currentRow][$currentColumn] -
|
||||
$otherMatrix->getValue($currentRow, $currentColumn)
|
||||
);
|
||||
|
||||
|
@ -12,11 +12,11 @@ class Rating implements \Stringable
|
||||
/**
|
||||
* Constructs a rating.
|
||||
*
|
||||
* @param float $_mean The statistical mean value of the rating (also known as mu).
|
||||
* @param float $_standardDeviation The standard deviation of the rating (also known as s).
|
||||
* @param float|int $_conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating.
|
||||
* @param float $mean The statistical mean value of the rating (also known as mu).
|
||||
* @param float $standardDeviation The standard deviation of the rating (also known as s).
|
||||
* @param float|int $conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating.
|
||||
*/
|
||||
public function __construct(private float $_mean, private float $_standardDeviation, private float|int $_conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER)
|
||||
public function __construct(private float $mean, private float $standardDeviation, private float|int $conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER)
|
||||
{
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ class Rating implements \Stringable
|
||||
*/
|
||||
public function getMean(): float
|
||||
{
|
||||
return $this->_mean;
|
||||
return $this->mean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,7 +33,7 @@ class Rating implements \Stringable
|
||||
*/
|
||||
public function getStandardDeviation(): float
|
||||
{
|
||||
return $this->_standardDeviation;
|
||||
return $this->standardDeviation;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,7 +41,7 @@ class Rating implements \Stringable
|
||||
*/
|
||||
public function getConservativeRating(): float
|
||||
{
|
||||
return $this->_mean - $this->_conservativeStandardDeviationMultiplier * $this->_standardDeviation;
|
||||
return $this->mean - $this->conservativeStandardDeviationMultiplier * $this->standardDeviation;
|
||||
}
|
||||
|
||||
public function getPartialUpdate(Rating $prior, Rating $fullPosterior, $updatePercentage): Rating
|
||||
@ -64,11 +64,11 @@ class Rating implements \Stringable
|
||||
$priorGaussian->getPrecision() + $partialPrecisionDifference
|
||||
);
|
||||
|
||||
return new Rating($partialPosteriorGaussion->getMean(), $partialPosteriorGaussion->getStandardDeviation(), $prior->_conservativeStandardDeviationMultiplier);
|
||||
return new Rating($partialPosteriorGaussion->getMean(), $partialPosteriorGaussion->getStandardDeviation(), $prior->conservativeStandardDeviationMultiplier);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('mean=%.4f, standardDeviation=%.4f', $this->_mean, $this->_standardDeviation);
|
||||
return sprintf('mean=%.4f, standardDeviation=%.4f', $this->mean, $this->standardDeviation);
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ use Exception;
|
||||
abstract class SkillCalculator
|
||||
{
|
||||
protected function __construct(
|
||||
private $_supportedOptions,
|
||||
private readonly TeamsRange $_totalTeamsAllowed,
|
||||
private readonly PlayersRange $_playersPerTeamAllowed
|
||||
private $supportedOptions,
|
||||
private readonly TeamsRange $totalTeamsAllowed,
|
||||
private readonly PlayersRange $playersPerTeamAllowed
|
||||
) {
|
||||
}
|
||||
|
||||
@ -41,12 +41,12 @@ abstract class SkillCalculator
|
||||
|
||||
public function isSupported($option): bool
|
||||
{
|
||||
return ($this->_supportedOptions & $option) == $option;
|
||||
return ($this->supportedOptions & $option) == $option;
|
||||
}
|
||||
|
||||
protected function validateTeamCountAndPlayersCountPerTeam(array $teamsOfPlayerToRatings)
|
||||
{
|
||||
self::validateTeamCountAndPlayersCountPerTeamWithRanges($teamsOfPlayerToRatings, $this->_totalTeamsAllowed, $this->_playersPerTeamAllowed);
|
||||
self::validateTeamCountAndPlayersCountPerTeamWithRanges($teamsOfPlayerToRatings, $this->totalTeamsAllowed, $this->playersPerTeamAllowed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,14 +13,14 @@ use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
|
||||
// start the process.
|
||||
class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
{
|
||||
public function __construct(TrueSkillFactorGraph $parentGraph, private readonly array $_teams)
|
||||
public function __construct(TrueSkillFactorGraph $parentGraph, private readonly array $teams)
|
||||
{
|
||||
parent::__construct($parentGraph);
|
||||
}
|
||||
|
||||
public function buildLayer()
|
||||
{
|
||||
$teams = $this->_teams;
|
||||
$teams = $this->teams;
|
||||
foreach ($teams as $currentTeam) {
|
||||
$localCurrentTeam = $currentTeam;
|
||||
$currentTeamSkills = [];
|
||||
|
Reference in New Issue
Block a user