mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 02:02:29 +01:00 
			
		
		
		
	rector: codingStyle
This commit is contained in:
		@@ -18,6 +18,7 @@ abstract class FactorGraphLayer
 | 
			
		||||
     * @var array<int,array<int,object>>
 | 
			
		||||
     */
 | 
			
		||||
    private array $outputVariablesGroups = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var array<int,array<int,object>>
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -25,12 +25,12 @@ class FactorList
 | 
			
		||||
 | 
			
		||||
        $listCount = count($this->list);
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $listCount; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $listCount; ++$i) {
 | 
			
		||||
            $f = $this->list[$i];
 | 
			
		||||
 | 
			
		||||
            $numberOfMessages = $f->getNumberOfMessages();
 | 
			
		||||
 | 
			
		||||
            for ($j = 0; $j < $numberOfMessages; $j++) {
 | 
			
		||||
            for ($j = 0; $j < $numberOfMessages; ++$j) {
 | 
			
		||||
                $sumLogZ += $f->sendMessageIndex($j);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,8 +15,8 @@ class DiagonalMatrix extends Matrix
 | 
			
		||||
 | 
			
		||||
        parent::__construct($diagonalCount, $diagonalCount);
 | 
			
		||||
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $diagonalCount; $currentRow++) {
 | 
			
		||||
            for ($currentCol = 0; $currentCol < $diagonalCount; $currentCol++) {
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $diagonalCount; ++$currentRow) {
 | 
			
		||||
            for ($currentCol = 0; $currentCol < $diagonalCount; ++$currentCol) {
 | 
			
		||||
                if ($currentRow === $currentCol) {
 | 
			
		||||
                    $this->setValue($currentRow, $currentCol, $diagonalValues[$currentRow]);
 | 
			
		||||
                } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,10 +15,11 @@ class GaussianDistribution implements \Stringable
 | 
			
		||||
    //sqrt(2*pi)
 | 
			
		||||
    //from https://www.wolframalpha.com/input?i=sqrt%282*pi%29
 | 
			
		||||
    private const M_SQRT_2_PI = 2.5066282746310005024157652848110452530069867406099383166299235763;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    //log(sqrt(2*pi))
 | 
			
		||||
    //From https://www.wolframalpha.com/input?i=log%28sqrt%282*pi%29%29
 | 
			
		||||
    private const M_LOG_SQRT_2_PI = 0.9189385332046727417803297364056176398613974736377834128171515404;
 | 
			
		||||
 | 
			
		||||
    // precision and precisionMean are used because they make multiplying and dividing simpler
 | 
			
		||||
    // (the the accompanying math paper for more details)
 | 
			
		||||
    private float $precision;
 | 
			
		||||
@@ -209,7 +210,7 @@ class GaussianDistribution implements \Stringable
 | 
			
		||||
        $d = 0.0;
 | 
			
		||||
        $dd = 0.0;
 | 
			
		||||
 | 
			
		||||
        for ($j = $ncof - 1; $j > 0; $j--) {
 | 
			
		||||
        for ($j = $ncof - 1; $j > 0; --$j) {
 | 
			
		||||
            $tmp = $d;
 | 
			
		||||
            $d = $ty * $d - $dd + $coefficients[$j];
 | 
			
		||||
            $dd = $tmp;
 | 
			
		||||
@@ -227,6 +228,7 @@ class GaussianDistribution implements \Stringable
 | 
			
		||||
        if ($p >= 2.0) {
 | 
			
		||||
            return -100;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($p <= 0.0) {
 | 
			
		||||
            return 100;
 | 
			
		||||
        }
 | 
			
		||||
@@ -235,7 +237,7 @@ class GaussianDistribution implements \Stringable
 | 
			
		||||
        $t = sqrt(-2 * 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++) {
 | 
			
		||||
        for ($j = 0; $j < 2; ++$j) {
 | 
			
		||||
            $err = GaussianDistribution::errorFunctionCumulativeTo($x) - $pp;
 | 
			
		||||
            $x += $err / (M_2_SQRTPI * exp(-BasicMath::square($x)) - $x * $err); // Halley
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -25,10 +25,10 @@ class Matrix
 | 
			
		||||
        $data = [];
 | 
			
		||||
        $result = new Matrix($rows, $columns, $data);
 | 
			
		||||
 | 
			
		||||
        for ($currentColumn = 0; $currentColumn < $columns; $currentColumn++) {
 | 
			
		||||
        for ($currentColumn = 0; $currentColumn < $columns; ++$currentColumn) {
 | 
			
		||||
            $currentColumnData = $columnValues[$currentColumn];
 | 
			
		||||
 | 
			
		||||
            for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
 | 
			
		||||
            for ($currentRow = 0; $currentRow < $rows; ++$currentRow) {
 | 
			
		||||
                $result->setValue($currentRow, $currentColumn, $currentColumnData[$currentRow]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -41,8 +41,8 @@ class Matrix
 | 
			
		||||
        $result = new Matrix($rows, $cols);
 | 
			
		||||
        $currentIndex = 0;
 | 
			
		||||
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
 | 
			
		||||
            for ($currentCol = 0; $currentCol < $cols; $currentCol++) {
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $rows; ++$currentRow) {
 | 
			
		||||
            for ($currentCol = 0; $currentCol < $cols; ++$currentCol) {
 | 
			
		||||
                $result->setValue($currentRow, $currentCol, $args[$currentIndex++]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -76,8 +76,8 @@ class Matrix
 | 
			
		||||
        $transposeMatrix = [];
 | 
			
		||||
 | 
			
		||||
        $rowMatrixData = $this->matrixRowData;
 | 
			
		||||
        for ($currentRowTransposeMatrix = 0; $currentRowTransposeMatrix < $this->columnCount; $currentRowTransposeMatrix++) {
 | 
			
		||||
            for ($currentColumnTransposeMatrix = 0; $currentColumnTransposeMatrix < $this->rowCount; $currentColumnTransposeMatrix++) {
 | 
			
		||||
        for ($currentRowTransposeMatrix = 0; $currentRowTransposeMatrix < $this->columnCount; ++$currentRowTransposeMatrix) {
 | 
			
		||||
            for ($currentColumnTransposeMatrix = 0; $currentColumnTransposeMatrix < $this->rowCount; ++$currentColumnTransposeMatrix) {
 | 
			
		||||
                $transposeMatrix[$currentRowTransposeMatrix][$currentColumnTransposeMatrix] =
 | 
			
		||||
                    $rowMatrixData[$currentColumnTransposeMatrix][$currentRowTransposeMatrix];
 | 
			
		||||
            }
 | 
			
		||||
@@ -126,7 +126,7 @@ class Matrix
 | 
			
		||||
        $result = 0.0;
 | 
			
		||||
 | 
			
		||||
        // I expand along the first row
 | 
			
		||||
        for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) {
 | 
			
		||||
        for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) {
 | 
			
		||||
            $firstRowColValue = $this->matrixRowData[0][$currentColumn];
 | 
			
		||||
            $cofactor = $this->getCofactor(0, $currentColumn);
 | 
			
		||||
            $itemToAdd = $firstRowColValue * $cofactor;
 | 
			
		||||
@@ -168,8 +168,8 @@ 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);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -197,8 +197,8 @@ class Matrix
 | 
			
		||||
        $columns = $matrix->getColumnCount();
 | 
			
		||||
        $newValues = [];
 | 
			
		||||
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $columns; $currentColumn++) {
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $rows; ++$currentRow) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $columns; ++$currentColumn) {
 | 
			
		||||
                $newValues[$currentRow][$currentColumn] = $scalarValue * $matrix->getValue($currentRow, $currentColumn);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -216,8 +216,8 @@ class Matrix
 | 
			
		||||
 | 
			
		||||
        $resultMatrix = [];
 | 
			
		||||
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $left->getRowCount(); $currentRow++) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); $currentColumn++) {
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $left->getRowCount(); ++$currentRow) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); ++$currentColumn) {
 | 
			
		||||
                $resultMatrix[$currentRow][$currentColumn] =
 | 
			
		||||
                    $left->getValue($currentRow, $currentColumn)
 | 
			
		||||
                    +
 | 
			
		||||
@@ -242,11 +242,11 @@ class Matrix
 | 
			
		||||
 | 
			
		||||
        $resultMatrix = [];
 | 
			
		||||
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $resultRows; $currentRow++) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $resultColumns; $currentColumn++) {
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $resultRows; ++$currentRow) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $resultColumns; ++$currentColumn) {
 | 
			
		||||
                $productValue = 0;
 | 
			
		||||
 | 
			
		||||
                for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); $vectorIndex++) {
 | 
			
		||||
                for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); ++$vectorIndex) {
 | 
			
		||||
                    $leftValue = $left->getValue($currentRow, $vectorIndex);
 | 
			
		||||
                    $rightValue = $right->getValue($vectorIndex, $currentColumn);
 | 
			
		||||
                    $vectorIndexProduct = $leftValue * $rightValue;
 | 
			
		||||
@@ -269,24 +269,24 @@ 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];
 | 
			
		||||
 | 
			
		||||
                $actualCol++;
 | 
			
		||||
                ++$actualCol;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $actualRow++;
 | 
			
		||||
            ++$actualRow;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Matrix($this->rowCount - 1, $this->columnCount - 1, $result);
 | 
			
		||||
@@ -312,8 +312,8 @@ class Matrix
 | 
			
		||||
            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] -
 | 
			
		||||
 
 | 
			
		||||
@@ -13,8 +13,8 @@ class SquareMatrix extends Matrix
 | 
			
		||||
        $matrixData = [];
 | 
			
		||||
        $allValuesIndex = 0;
 | 
			
		||||
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $size; $currentRow++) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $size; $currentColumn++) {
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $size; ++$currentRow) {
 | 
			
		||||
            for ($currentColumn = 0; $currentColumn < $size; ++$currentColumn) {
 | 
			
		||||
                $matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ class Vector extends Matrix
 | 
			
		||||
        foreach ($vectorValues as $currentVectorValue) {
 | 
			
		||||
            $columnValues[] = [$currentVectorValue];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        parent::__construct(count($vectorValues), 1, $columnValues);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -70,7 +70,8 @@ abstract class SkillCalculator
 | 
			
		||||
            if (! $playersPerTeam->isInRange($currentTeam->count())) {
 | 
			
		||||
                throw new Exception('Player count is not in range');
 | 
			
		||||
            }
 | 
			
		||||
            $countOfTeams++;
 | 
			
		||||
 | 
			
		||||
            ++$countOfTeams;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (! $totalTeams->isInRange($countOfTeams)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
@@ -51,6 +52,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
 | 
			
		||||
        return $factorGraph->getUpdatedRatings();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
@@ -104,7 +106,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
        return new Vector(
 | 
			
		||||
            self::getPlayerRatingValues(
 | 
			
		||||
                $teamAssignmentsList,
 | 
			
		||||
                fn (Rating $rating): float => $rating->getMean()
 | 
			
		||||
                static fn(Rating $rating): float => $rating->getMean()
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
@@ -119,7 +121,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
        return new DiagonalMatrix(
 | 
			
		||||
            self::getPlayerRatingValues(
 | 
			
		||||
                $teamAssignmentsList,
 | 
			
		||||
                fn (Rating $rating): float => BasicMath::square($rating->getStandardDeviation())
 | 
			
		||||
                static fn(Rating $rating): float => BasicMath::square($rating->getStandardDeviation())
 | 
			
		||||
            )
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
@@ -171,7 +173,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
 | 
			
		||||
        $currentColumn = 0;
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < count($teamAssignmentsList) - 1; $i++) {
 | 
			
		||||
        for ($i = 0; $i < count($teamAssignmentsList) - 1; ++$i) {
 | 
			
		||||
            $currentTeam = $teamAssignmentsList[$i];
 | 
			
		||||
 | 
			
		||||
            // Need to add in 0's for all the previous players, since they're not
 | 
			
		||||
@@ -181,7 +183,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
            foreach ($currentTeam->getAllPlayers() as $currentPlayer) {
 | 
			
		||||
                $playerAssignments[$currentColumn][] = PartialPlay::getPartialPlayPercentage($currentPlayer);
 | 
			
		||||
                // indicates the player is on the team
 | 
			
		||||
                $totalPreviousPlayers++;
 | 
			
		||||
                ++$totalPreviousPlayers;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $rowsRemaining = $totalPlayers - $totalPreviousPlayers;
 | 
			
		||||
@@ -190,15 +192,15 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
            foreach ($nextTeam->getAllPlayers() as $nextTeamPlayer) {
 | 
			
		||||
                // Add a -1 * playing time to represent the difference
 | 
			
		||||
                $playerAssignments[$currentColumn][] = -1 * PartialPlay::getPartialPlayPercentage($nextTeamPlayer);
 | 
			
		||||
                $rowsRemaining--;
 | 
			
		||||
                --$rowsRemaining;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            for ($ixAdditionalRow = 0; $ixAdditionalRow < $rowsRemaining; $ixAdditionalRow++) {
 | 
			
		||||
            for ($ixAdditionalRow = 0; $ixAdditionalRow < $rowsRemaining; ++$ixAdditionalRow) {
 | 
			
		||||
                // Pad with zeros
 | 
			
		||||
                $playerAssignments[$currentColumn][] = 0;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $currentColumn++;
 | 
			
		||||
            ++$currentColumn;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return Matrix::fromColumnValues($totalPlayers, count($teamAssignmentsList) - 1, $playerAssignments);
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
     * @var array<float[]> $weights
 | 
			
		||||
     */
 | 
			
		||||
    private array $weights = [];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var array<float[]> $weightsSquared
 | 
			
		||||
     */
 | 
			
		||||
@@ -48,7 +49,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
        $variableWeightsLength = count($variableWeights);
 | 
			
		||||
        $this->weights[0] = array_fill(0, count($variableWeights), 0);
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $variableWeightsLength; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $variableWeightsLength; ++$i) {
 | 
			
		||||
            $weight = &$variableWeights[$i];
 | 
			
		||||
            $this->weights[0][$i] = $weight;
 | 
			
		||||
            $this->weightsSquared[0][$i] = BasicMath::square($weight);
 | 
			
		||||
@@ -58,7 +59,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
 | 
			
		||||
        // 0..n-1
 | 
			
		||||
        $this->variableIndexOrdersForWeights[0] = [];
 | 
			
		||||
        for ($i = 0; $i < ($variablesToSumLength + 1); $i++) {
 | 
			
		||||
        for ($i = 0; $i < ($variablesToSumLength + 1); ++$i) {
 | 
			
		||||
            $this->variableIndexOrdersForWeights[0][] = $i;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -70,7 +71,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
        // By convention, we'll put the v_0 term at the end
 | 
			
		||||
 | 
			
		||||
        $weightsLength = $variableWeightsLength + 1;
 | 
			
		||||
        for ($weightsIndex = 1; $weightsIndex < $weightsLength; $weightsIndex++) {
 | 
			
		||||
        for ($weightsIndex = 1; $weightsIndex < $weightsLength; ++$weightsIndex) {
 | 
			
		||||
            $currentWeights = \array_fill(0, $variableWeightsLength, 0);
 | 
			
		||||
 | 
			
		||||
            $variableIndices = \array_fill(0, $variableWeightsLength + 1, 0);
 | 
			
		||||
@@ -82,7 +83,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
            // This is helpful since we skip over one of the spots
 | 
			
		||||
            $currentDestinationWeightIndex = 0;
 | 
			
		||||
 | 
			
		||||
            for ($currentWeightSourceIndex = 0; $currentWeightSourceIndex < $variableWeightsLength; $currentWeightSourceIndex++) {
 | 
			
		||||
            for ($currentWeightSourceIndex = 0; $currentWeightSourceIndex < $variableWeightsLength; ++$currentWeightSourceIndex) {
 | 
			
		||||
                if ($currentWeightSourceIndex === $weightsIndex - 1) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
@@ -98,7 +99,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
                $currentWeightsSquared[$currentDestinationWeightIndex] = $currentWeight * $currentWeight;
 | 
			
		||||
 | 
			
		||||
                $variableIndices[$currentDestinationWeightIndex + 1] = $currentWeightSourceIndex + 1;
 | 
			
		||||
                $currentDestinationWeightIndex++;
 | 
			
		||||
                ++$currentDestinationWeightIndex;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // And the final one
 | 
			
		||||
@@ -108,6 +109,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
                // HACK: Getting around division by zero
 | 
			
		||||
                $finalWeight = 0;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $currentWeights[$currentDestinationWeightIndex] = $finalWeight;
 | 
			
		||||
            $currentWeightsSquared[$currentDestinationWeightIndex] = BasicMath::square($finalWeight);
 | 
			
		||||
            $variableIndices[count($variableWeights)] = 0;
 | 
			
		||||
@@ -135,7 +137,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
        $counter = count($vars);
 | 
			
		||||
 | 
			
		||||
        // We start at 1 since offset 0 has the sum
 | 
			
		||||
        for ($i = 1; $i < $counter; $i++) {
 | 
			
		||||
        for ($i = 1; $i < $counter; ++$i) {
 | 
			
		||||
            $result += GaussianDistribution::logRatioNormalization($vars[$i]->getValue(), $messages[$i]->getValue());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -164,7 +166,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
 | 
			
		||||
        $weightsSquaredLength = count($weightsSquared);
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $weightsSquaredLength; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $weightsSquaredLength; ++$i) {
 | 
			
		||||
            // These flow directly from the paper
 | 
			
		||||
 | 
			
		||||
            $inverseOfNewPrecisionSum += $weightsSquared[$i] /
 | 
			
		||||
@@ -221,7 +223,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
        // The tricky part here is that we have to put the messages and variables in the same
 | 
			
		||||
        // order as the weights. Thankfully, the weights and messages share the same index numbers,
 | 
			
		||||
        // so we just need to make sure they're consistent
 | 
			
		||||
        for ($i = 0; $i < $counter; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $counter; ++$i) {
 | 
			
		||||
            $updatedMessages[] = $allMessages[$indicesToUse[$i]];
 | 
			
		||||
            $updatedVariables[] = $allVariables[$indicesToUse[$i]];
 | 
			
		||||
        }
 | 
			
		||||
@@ -245,7 +247,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
 | 
			
		||||
        $result .= ' = ';
 | 
			
		||||
 | 
			
		||||
        $totalVars = count($variablesToSum);
 | 
			
		||||
        for ($i = 0; $i < $totalVars; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $totalVars; ++$i) {
 | 
			
		||||
            $isFirst = ($i == 0);
 | 
			
		||||
 | 
			
		||||
            if ($isFirst && ($weights[$i] < 0)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -113,7 +113,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
 | 
			
		||||
        $forwardScheduleList = [];
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $totalTeamDifferences - 1; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $totalTeamDifferences - 1; ++$i) {
 | 
			
		||||
            $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
 | 
			
		||||
            $teamDifferencesComparisonLayerLocalFactors = $this->TeamDifferencesComparisonLayer->getLocalFactors();
 | 
			
		||||
 | 
			
		||||
@@ -149,7 +149,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
 | 
			
		||||
        $backwardScheduleList = [];
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $totalTeamDifferences - 1; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $totalTeamDifferences - 1; ++$i) {
 | 
			
		||||
            $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();
 | 
			
		||||
            $teamDifferencesComparisonLayerLocalFactors = $this->TeamDifferencesComparisonLayer->getLocalFactors();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
 | 
			
		||||
        return $this->scheduleSequence(
 | 
			
		||||
            array_map(
 | 
			
		||||
                fn ($weightedSumFactor): ScheduleStep => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0),
 | 
			
		||||
                static fn($weightedSumFactor): ScheduleStep => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0),
 | 
			
		||||
                $localFactors
 | 
			
		||||
            ),
 | 
			
		||||
            'all player perf to team perf schedule'
 | 
			
		||||
@@ -50,9 +50,8 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
    protected function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor
 | 
			
		||||
    {
 | 
			
		||||
        $weights = array_map(
 | 
			
		||||
            function ($v): float {
 | 
			
		||||
            static function ($v): float {
 | 
			
		||||
                $player = $v->getKey();
 | 
			
		||||
 | 
			
		||||
                return PartialPlay::getPartialPlayPercentage($player);
 | 
			
		||||
            },
 | 
			
		||||
            $teamMembers
 | 
			
		||||
@@ -72,7 +71,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
        foreach ($localFactors as $currentFactor) {
 | 
			
		||||
            $localCurrentFactor = $currentFactor;
 | 
			
		||||
            $numberOfMessages = $localCurrentFactor->getNumberOfMessages();
 | 
			
		||||
            for ($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++) {
 | 
			
		||||
            for ($currentIteration = 1; $currentIteration < $numberOfMessages; ++$currentIteration) {
 | 
			
		||||
                $allFactors[] = new ScheduleStep(
 | 
			
		||||
                    'team sum perf @' . $currentIteration,
 | 
			
		||||
                    $localCurrentFactor,
 | 
			
		||||
@@ -89,7 +88,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
     */
 | 
			
		||||
    private function createOutputVariable(array $team): Variable
 | 
			
		||||
    {
 | 
			
		||||
        $memberNames = array_map(fn ($currentPlayer): string => (string)($currentPlayer->getKey()), $team);
 | 
			
		||||
        $memberNames = array_map(static fn($currentPlayer): string => (string)($currentPlayer->getKey()), $team);
 | 
			
		||||
 | 
			
		||||
        $teamMemberNames = \implode(', ', $memberNames);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
 | 
			
		||||
        return $this->scheduleSequence(
 | 
			
		||||
            array_map(
 | 
			
		||||
                fn ($prior): ScheduleStep => new ScheduleStep('Prior to Skill Step', $prior, 0),
 | 
			
		||||
                static fn($prior): ScheduleStep => new ScheduleStep('Prior to Skill Step', $prior, 0),
 | 
			
		||||
                $localFactors
 | 
			
		||||
            ),
 | 
			
		||||
            'All priors'
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
 | 
			
		||||
        return $this->scheduleSequence(
 | 
			
		||||
            array_map(
 | 
			
		||||
                fn ($likelihood): ScheduleStep => new ScheduleStep('Skill to Perf step', $likelihood, 0),
 | 
			
		||||
                static fn($likelihood): ScheduleStep => new ScheduleStep('Skill to Perf step', $likelihood, 0),
 | 
			
		||||
                $localFactors
 | 
			
		||||
            ),
 | 
			
		||||
            'All skill to performance sending'
 | 
			
		||||
@@ -66,7 +66,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
 | 
			
		||||
        return $this->scheduleSequence(
 | 
			
		||||
            array_map(
 | 
			
		||||
                fn ($likelihood): ScheduleStep => new ScheduleStep('name', $likelihood, 1),
 | 
			
		||||
                static fn($likelihood): ScheduleStep => new ScheduleStep('name', $likelihood, 1),
 | 
			
		||||
                $localFactors
 | 
			
		||||
            ),
 | 
			
		||||
            'All skill to performance sending'
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
        $inputVarGroups = $this->getInputVariablesGroups();
 | 
			
		||||
        $inputVarGroupsCount = count($inputVarGroups);
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $inputVarGroupsCount; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $inputVarGroupsCount; ++$i) {
 | 
			
		||||
            $isDraw = ($this->teamRanks[$i] == $this->teamRanks[$i + 1]);
 | 
			
		||||
            $teamDifference = $inputVarGroups[$i][0];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
 | 
			
		||||
        $inputVariablesGroupsCount = count($inputVariablesGroups);
 | 
			
		||||
        $outputVariablesGroup = &$this->getOutputVariablesGroups();
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) {
 | 
			
		||||
        for ($i = 0; $i < $inputVariablesGroupsCount - 1; ++$i) {
 | 
			
		||||
            $strongerTeam = $inputVariablesGroups[$i][0];
 | 
			
		||||
            $weakerTeam = $inputVariablesGroups[$i + 1][0];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ class TrueSkillFactorGraph extends FactorGraph
 | 
			
		||||
    {
 | 
			
		||||
        $this->priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams);
 | 
			
		||||
        $newFactory = new VariableFactory(
 | 
			
		||||
            fn (): GaussianDistribution => GaussianDistribution::fromPrecisionMean(0, 0)
 | 
			
		||||
            static fn(): GaussianDistribution => GaussianDistribution::fromPrecisionMean(0, 0)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->setVariableFactory($newFactory);
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     */
 | 
			
		||||
@@ -82,12 +83,12 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
 | 
			
		||||
        $totalPlayers = $selfTeam->count() + $otherTeam->count();
 | 
			
		||||
 | 
			
		||||
        $meanGetter = fn (Rating $currentRating): float => $currentRating->getMean();
 | 
			
		||||
        $meanGetter = static fn(Rating $currentRating): float => $currentRating->getMean();
 | 
			
		||||
 | 
			
		||||
        $selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter);
 | 
			
		||||
        $otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter);
 | 
			
		||||
 | 
			
		||||
        $varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
        $varianceGetter = static fn(Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
 | 
			
		||||
        $c = sqrt(
 | 
			
		||||
            BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter)
 | 
			
		||||
@@ -163,9 +164,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
 | 
			
		||||
        $betaSquared = BasicMath::square($gameInfo->getBeta());
 | 
			
		||||
 | 
			
		||||
        $meanGetter = fn (Rating $currentRating): float => $currentRating->getMean();
 | 
			
		||||
        $meanGetter = static fn(Rating $currentRating): float => $currentRating->getMean();
 | 
			
		||||
 | 
			
		||||
        $varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
        $varianceGetter = static fn(Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
 | 
			
		||||
 | 
			
		||||
        $team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter);
 | 
			
		||||
        $team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user