public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks)
 {
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     RankSorter::sort($teams, $teamRanks);
     $factorGraph = new TrueSkillFactorGraph($gameInfo, $teams, $teamRanks);
     $factorGraph->buildGraph();
     $factorGraph->runSchedule();
     $probabilityOfOutcome = $factorGraph->getProbabilityOfRanking();
     return $factorGraph->getUpdatedRatings();
 }
 /**
  * {@inheritdoc }
  */
 public function calculateMatchQuality(GameInfo $gameInfo, array $teams)
 {
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     $team1 = $teams[0];
     $team2 = $teams[1];
     $team1Ratings = $team1->getAllRatings();
     $team2Ratings = $team2->getAllRatings();
     $player1Rating = $team1Ratings[0];
     $player2Rating = $team2Ratings[0];
     // We just use equation 4.1 found on page 8 of the TrueSkill 2006 paper:
     $betaSquared = square($gameInfo->getBeta());
     $player1SigmaSquared = square($player1Rating->getStandardDeviation());
     $player2SigmaSquared = square($player2Rating->getStandardDeviation());
     // This is the square root part of the equation:
     $sqrtPart = sqrt(2 * $betaSquared / (2 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared));
     // This is the exponent part of the equation:
     $expPart = exp(-1 * square($player1Rating->getMean() - $player2Rating->getMean()) / (2 * (2 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared)));
     return $sqrtPart * $expPart;
 }
예제 #3
0
 /**
  * {@inheritdoc }
  */
 public function calculateMatchQuality(GameInfo &$gameInfo, array &$teams)
 {
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     // We've verified that there's just two teams
     $team1Ratings = $teams[0]->getAllRatings();
     $team1Count = count($team1Ratings);
     $team2Ratings = $teams[1]->getAllRatings();
     $team2Count = count($team2Ratings);
     $totalPlayers = $team1Count + $team2Count;
     $betaSquared = square($gameInfo->getBeta());
     $meanGetter = function ($currentRating) {
         return $currentRating->getMean();
     };
     $varianceGetter = function ($currentRating) {
         return square($currentRating->getStandardDeviation());
     };
     $team1MeanSum = sum($team1Ratings, $meanGetter);
     $team1StdDevSquared = sum($team1Ratings, $varianceGetter);
     $team2MeanSum = sum($team2Ratings, $meanGetter);
     $team2SigmaSquared = sum($team2Ratings, $varianceGetter);
     // This comes from equation 4.1 in the TrueSkill paper on page 8
     // The equation was broken up into the part under the square root sign and
     // the exponential part to make the code easier to read.
     $sqrtPart = sqrt($totalPlayers * $betaSquared / ($totalPlayers * $betaSquared + $team1StdDevSquared + $team2SigmaSquared));
     $expPart = exp(-1 * square($team1MeanSum - $team2MeanSum) / (2 * ($totalPlayers * $betaSquared + $team1StdDevSquared + $team2SigmaSquared)));
     return $expPart * $sqrtPart;
 }