コード例 #1
0
 public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks)
 {
     // Basic argument checking
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     // Make sure things are in order
     $teams = RankSorter::sort($teams, $teamRanks);
     // Since we verified that each team has one player, we know the player is the first one
     $winningTeamPlayers = $teams[0]->getAllPlayers();
     $winner = $winningTeamPlayers[0];
     $winnerPreviousRating = $teams[0]->getRating($winner);
     $losingTeamPlayers = $teams[1]->getAllPlayers();
     $loser = $losingTeamPlayers[0];
     $loserPreviousRating = $teams[1]->getRating($loser);
     $wasDraw = $teamRanks[0] == $teamRanks[1];
     $results = new RatingContainer();
     $results->setRating($winner, self::calculateNewRating($gameInfo, $winnerPreviousRating, $loserPreviousRating, $wasDraw ? PairwiseComparison::DRAW : PairwiseComparison::WIN));
     $results->setRating($loser, self::calculateNewRating($gameInfo, $loserPreviousRating, $winnerPreviousRating, $wasDraw ? PairwiseComparison::DRAW : PairwiseComparison::LOSE));
     // And we're done!
     return $results;
 }
コード例 #2
0
 private static function updatePlayerRatings(GameInfo $gameInfo, RatingContainer &$newPlayerRatings, Team $selfTeam, Team $otherTeam, $selfToOtherTeamComparison)
 {
     $drawMargin = DrawMargin::getDrawMarginFromDrawProbability($gameInfo->getDrawProbability(), $gameInfo->getBeta());
     $betaSquared = square($gameInfo->getBeta());
     $tauSquared = square($gameInfo->getDynamicsFactor());
     $totalPlayers = $selfTeam->count() + $otherTeam->count();
     $meanGetter = function ($currentRating) {
         return $currentRating->getMean();
     };
     $selfMeanSum = sum($selfTeam->getAllRatings(), $meanGetter);
     $otherTeamMeanSum = sum($otherTeam->getAllRatings(), $meanGetter);
     $varianceGetter = function ($currentRating) {
         return square($currentRating->getStandardDeviation());
     };
     $c = sqrt(sum($selfTeam->getAllRatings(), $varianceGetter) + sum($otherTeam->getAllRatings(), $varianceGetter) + $totalPlayers * $betaSquared);
     $winningMean = $selfMeanSum;
     $losingMean = $otherTeamMeanSum;
     switch ($selfToOtherTeamComparison) {
         case PairwiseComparison::WIN:
         case PairwiseComparison::DRAW:
             // NOP
             break;
         case PairwiseComparison::LOSE:
             $winningMean = $otherTeamMeanSum;
             $losingMean = $selfMeanSum;
             break;
     }
     $meanDelta = $winningMean - $losingMean;
     if ($selfToOtherTeamComparison != PairwiseComparison::DRAW) {
         // non-draw case
         $v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c);
         $w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c);
         $rankMultiplier = (int) $selfToOtherTeamComparison;
     } else {
         // assume draw
         $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c);
         $w = TruncatedGaussianCorrectionFunctions::wWithinMarginScaled($meanDelta, $drawMargin, $c);
         $rankMultiplier = 1;
     }
     $selfTeamAllPlayers =& $selfTeam->getAllPlayers();
     foreach ($selfTeamAllPlayers as &$selfTeamCurrentPlayer) {
         $localSelfTeamCurrentPlayer =& $selfTeamCurrentPlayer;
         $previousPlayerRating = $selfTeam->getRating($localSelfTeamCurrentPlayer);
         $meanMultiplier = (square($previousPlayerRating->getStandardDeviation()) + $tauSquared) / $c;
         $stdDevMultiplier = (square($previousPlayerRating->getStandardDeviation()) + $tauSquared) / square($c);
         $playerMeanDelta = $rankMultiplier * $meanMultiplier * $v;
         $newMean = $previousPlayerRating->getMean() + $playerMeanDelta;
         $newStdDev = sqrt((square($previousPlayerRating->getStandardDeviation()) + $tauSquared) * (1 - $w * $stdDevMultiplier));
         $newPlayerRatings->setRating($localSelfTeamCurrentPlayer, new Rating($newMean, $newStdDev));
     }
 }
コード例 #3
0
 public function getUpdatedRatings()
 {
     $result = new RatingContainer();
     $priorLayerOutputVariablesGroups =& $this->_priorLayer->getOutputVariablesGroups();
     foreach ($priorLayerOutputVariablesGroups as &$currentTeam) {
         foreach ($currentTeam as &$currentPlayer) {
             $localCurrentPlayer =& $currentPlayer->getKey();
             $newRating = new Rating($currentPlayer->getValue()->getMean(), $currentPlayer->getValue()->getStandardDeviation());
             $result->setRating($localCurrentPlayer, $newRating);
         }
     }
     return $result;
 }