mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
More code standards
This commit is contained in:
@ -15,6 +15,8 @@ use DNW\Skills\Teams;
|
|||||||
class BasicBench
|
class BasicBench
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
* To benchmark performance when using TwoPlayerTrueSkillCalculator
|
||||||
|
*
|
||||||
* @Revs(20)
|
* @Revs(20)
|
||||||
* @Iterations(20)
|
* @Iterations(20)
|
||||||
*/
|
*/
|
||||||
@ -44,6 +46,8 @@ class BasicBench
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* To benchmark performance when using TwoTeamTrueSkillCalculator for just two players in two teams
|
||||||
|
*
|
||||||
* @Revs(20)
|
* @Revs(20)
|
||||||
* @Iterations(20)
|
* @Iterations(20)
|
||||||
*/
|
*/
|
||||||
@ -73,6 +77,8 @@ class BasicBench
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* To benchmark performance when using FactorGraphTrueSkillCalculator for just two players in two teams
|
||||||
|
*
|
||||||
* @Revs(20)
|
* @Revs(20)
|
||||||
* @Iterations(20)
|
* @Iterations(20)
|
||||||
*/
|
*/
|
||||||
@ -102,6 +108,8 @@ class BasicBench
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* To benchmark performance when using FactorGraphTrueSkillCalculator with 3 players in 3 teams
|
||||||
|
*
|
||||||
* @Revs(20)
|
* @Revs(20)
|
||||||
* @Iterations(20)
|
* @Iterations(20)
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
use DNW\Skills\Guard;
|
use DNW\Skills\Guard;
|
||||||
@ -94,6 +96,7 @@ abstract class Factor implements \Stringable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the ith message to the marginal and returns the log-normalization constant
|
* Sends the ith message to the marginal and returns the log-normalization constant
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendMessageIndex(int $messageIndex): float|int
|
public function sendMessageIndex(int $messageIndex): float|int
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
||||||
@ -42,6 +44,7 @@ abstract class FactorGraphLayer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This reference is still needed
|
* This reference is still needed
|
||||||
|
*
|
||||||
* @return array<int,array<int,object>>
|
* @return array<int,array<int,object>>
|
||||||
*/
|
*/
|
||||||
public function &getOutputVariablesGroups(): array
|
public function &getOutputVariablesGroups(): array
|
||||||
@ -82,11 +85,11 @@ abstract class FactorGraphLayer
|
|||||||
|
|
||||||
public function createPriorSchedule(): ?ScheduleSequence
|
public function createPriorSchedule(): ?ScheduleSequence
|
||||||
{
|
{
|
||||||
return null;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPosteriorSchedule(): ?ScheduleSequence
|
public function createPosteriorSchedule(): ?ScheduleSequence
|
||||||
{
|
{
|
||||||
return null;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
class ScheduleLoop extends Schedule
|
class ScheduleLoop extends Schedule
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
class ScheduleSequence extends Schedule
|
class ScheduleSequence extends Schedule
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
class ScheduleStep extends Schedule
|
class ScheduleStep extends Schedule
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
use DNW\Skills\Numerics\GaussianDistribution;
|
use DNW\Skills\Numerics\GaussianDistribution;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\FactorGraphs;
|
namespace DNW\Skills\FactorGraphs;
|
||||||
|
|
||||||
class VariableFactory
|
class VariableFactory
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills;
|
namespace DNW\Skills;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +25,8 @@ class GameInfo
|
|||||||
private float $beta = self::DEFAULT_BETA,
|
private float $beta = self::DEFAULT_BETA,
|
||||||
private float $dynamicsFactor = self::DEFAULT_DYNAMICS_FACTOR,
|
private float $dynamicsFactor = self::DEFAULT_DYNAMICS_FACTOR,
|
||||||
private float $drawProbability = self::DEFAULT_DRAW_PROBABILITY
|
private float $drawProbability = self::DEFAULT_DRAW_PROBABILITY
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInitialMean(): float
|
public function getInitialMean(): float
|
||||||
|
@ -13,7 +13,7 @@ class Guard
|
|||||||
{
|
{
|
||||||
public static function argumentNotNull(mixed $value, string $parameterName): void
|
public static function argumentNotNull(mixed $value, string $parameterName): void
|
||||||
{
|
{
|
||||||
if ($value == null) {
|
if ($value == NULL) {
|
||||||
throw new Exception($parameterName . ' can not be null');
|
throw new Exception($parameterName . ' can not be null');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Numerics;
|
namespace DNW\Skills\Numerics;
|
||||||
|
|
||||||
class DiagonalMatrix extends Matrix
|
class DiagonalMatrix extends Matrix
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Numerics;
|
namespace DNW\Skills\Numerics;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
@ -11,7 +13,7 @@ class Matrix
|
|||||||
/**
|
/**
|
||||||
* @param array<int,array<int,float>> $matrixRowData
|
* @param array<int,array<int,float>> $matrixRowData
|
||||||
*/
|
*/
|
||||||
public function __construct(private int $rowCount = 0, private int $columnCount = 0, private array $matrixRowData = array())
|
public function __construct(private int $rowCount = 0, private int $columnCount = 0, private array $matrixRowData = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +309,7 @@ class Matrix
|
|||||||
public function equals(Matrix $otherMatrix): bool
|
public function equals(Matrix $otherMatrix): bool
|
||||||
{
|
{
|
||||||
if (($this->rowCount != $otherMatrix->getRowCount()) || ($this->columnCount != $otherMatrix->getColumnCount())) {
|
if (($this->rowCount != $otherMatrix->getRowCount()) || ($this->columnCount != $otherMatrix->getColumnCount())) {
|
||||||
return false;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) {
|
for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) {
|
||||||
@ -319,11 +321,11 @@ class Matrix
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($delta > self::ERROR_TOLERANCE) {
|
if ($delta > self::ERROR_TOLERANCE) {
|
||||||
return false;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills;
|
namespace DNW\Skills;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,8 +12,9 @@ class RankSorter
|
|||||||
/**
|
/**
|
||||||
* Performs an in-place sort of the items in according to the ranks in non-decreasing order.
|
* Performs an in-place sort of the items in according to the ranks in non-decreasing order.
|
||||||
*
|
*
|
||||||
* @param array<mixed> $teams The items to sort according to the order specified by ranks.
|
* @param array<mixed> $teams The items to sort according to the order specified by ranks.
|
||||||
* @param array<int> $teamRanks The ranks for each item where 1 is first place.
|
* @param array<int> $teamRanks The ranks for each item where 1 is first place.
|
||||||
|
*
|
||||||
* @return array<int>
|
* @return array<int>
|
||||||
*/
|
*/
|
||||||
public static function sort(array &$teams, array &$teamRanks): array
|
public static function sort(array &$teams, array &$teamRanks): array
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills;
|
namespace DNW\Skills;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
@ -13,15 +15,17 @@ abstract class SkillCalculator
|
|||||||
private int $supportedOptions,
|
private int $supportedOptions,
|
||||||
private readonly TeamsRange $totalTeamsAllowed,
|
private readonly TeamsRange $totalTeamsAllowed,
|
||||||
private readonly PlayersRange $playersPerTeamAllowed
|
private readonly PlayersRange $playersPerTeamAllowed
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates new ratings based on the prior ratings and team ranks.
|
* Calculates new ratings based on the prior ratings and team ranks.
|
||||||
*
|
*
|
||||||
* @param GameInfo $gameInfo Parameters for the game.
|
* @param GameInfo $gameInfo Parameters for the game.
|
||||||
* @param Team[] $teams A mapping of team players and their ratings.
|
* @param Team[] $teams A mapping of team players and their ratings.
|
||||||
* @param int[] $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
|
* @param int[] $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
|
||||||
|
*
|
||||||
* @return RatingContainer All the players and their new ratings.
|
* @return RatingContainer All the players and their new ratings.
|
||||||
*/
|
*/
|
||||||
abstract public function calculateNewRatings(
|
abstract public function calculateNewRatings(
|
||||||
@ -35,6 +39,7 @@ abstract class SkillCalculator
|
|||||||
*
|
*
|
||||||
* @param GameInfo $gameInfo Parameters for the game.
|
* @param GameInfo $gameInfo Parameters for the game.
|
||||||
* @param Team[] $teams A mapping of team players and their ratings.
|
* @param Team[] $teams A mapping of team players and their ratings.
|
||||||
|
*
|
||||||
* @return float The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).
|
* @return float The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).
|
||||||
*/
|
*/
|
||||||
abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float;
|
abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float;
|
||||||
|
@ -4,7 +4,7 @@ namespace DNW\Skills;
|
|||||||
|
|
||||||
class Team extends RatingContainer
|
class Team extends RatingContainer
|
||||||
{
|
{
|
||||||
public function __construct(Player $player = null, Rating $rating = null)
|
public function __construct(Player $player = NULL, Rating $rating = NULL)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills;
|
namespace DNW\Skills;
|
||||||
|
|
||||||
class Teams
|
class Teams
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills;
|
namespace DNW\Skills;
|
||||||
|
|
||||||
use DNW\Skills\Numerics\Range;
|
use DNW\Skills\Numerics\Range;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill;
|
namespace DNW\Skills\TrueSkill;
|
||||||
|
|
||||||
use DNW\Skills\Numerics\GaussianDistribution;
|
use DNW\Skills\Numerics\GaussianDistribution;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill\Factors;
|
namespace DNW\Skills\TrueSkill\Factors;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\Message;
|
use DNW\Skills\FactorGraphs\Message;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill\Layers;
|
namespace DNW\Skills\TrueSkill\Layers;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\ScheduleLoop;
|
use DNW\Skills\FactorGraphs\ScheduleLoop;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill\Layers;
|
namespace DNW\Skills\TrueSkill\Layers;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||||
@ -87,7 +89,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
|||||||
*/
|
*/
|
||||||
private function createOutputVariable(array $team): Variable
|
private function createOutputVariable(array $team): Variable
|
||||||
{
|
{
|
||||||
$memberNames = array_map(fn ($currentPlayer) => (string) ($currentPlayer->getKey()), $team);
|
$memberNames = array_map(fn ($currentPlayer) => (string)($currentPlayer->getKey()), $team);
|
||||||
|
|
||||||
$teamMemberNames = \implode(', ', $memberNames);
|
$teamMemberNames = \implode(', ', $memberNames);
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill\Layers;
|
namespace DNW\Skills\TrueSkill\Layers;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill\Layers;
|
namespace DNW\Skills\TrueSkill\Layers;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\KeyedVariable;
|
use DNW\Skills\FactorGraphs\KeyedVariable;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill\Layers;
|
namespace DNW\Skills\TrueSkill\Layers;
|
||||||
|
|
||||||
use DNW\Skills\TrueSkill\DrawMargin;
|
use DNW\Skills\TrueSkill\DrawMargin;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill\Layers;
|
namespace DNW\Skills\TrueSkill\Layers;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\Variable;
|
use DNW\Skills\FactorGraphs\Variable;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill;
|
namespace DNW\Skills\TrueSkill;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\FactorGraph;
|
use DNW\Skills\FactorGraphs\FactorGraph;
|
||||||
@ -60,11 +62,11 @@ class TrueSkillFactorGraph extends FactorGraph
|
|||||||
|
|
||||||
public function buildGraph(): void
|
public function buildGraph(): void
|
||||||
{
|
{
|
||||||
$lastOutput = null;
|
$lastOutput = NULL;
|
||||||
|
|
||||||
$layers = $this->layers;
|
$layers = $this->layers;
|
||||||
foreach ($layers as $currentLayer) {
|
foreach ($layers as $currentLayer) {
|
||||||
if ($lastOutput != null) {
|
if ($lastOutput != NULL) {
|
||||||
$currentLayer->setInputVariablesGroups($lastOutput);
|
$currentLayer->setInputVariablesGroups($lastOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +107,7 @@ class TrueSkillFactorGraph extends FactorGraph
|
|||||||
$layers = $this->layers;
|
$layers = $this->layers;
|
||||||
foreach ($layers as $currentLayer) {
|
foreach ($layers as $currentLayer) {
|
||||||
$currentPriorSchedule = $currentLayer->createPriorSchedule();
|
$currentPriorSchedule = $currentLayer->createPriorSchedule();
|
||||||
if ($currentPriorSchedule != null) {
|
if ($currentPriorSchedule != NULL) {
|
||||||
$fullSchedule[] = $currentPriorSchedule;
|
$fullSchedule[] = $currentPriorSchedule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +116,7 @@ class TrueSkillFactorGraph extends FactorGraph
|
|||||||
|
|
||||||
foreach ($allLayersReverse as $currentLayer) {
|
foreach ($allLayersReverse as $currentLayer) {
|
||||||
$currentPosteriorSchedule = $currentLayer->createPosteriorSchedule();
|
$currentPosteriorSchedule = $currentLayer->createPosteriorSchedule();
|
||||||
if ($currentPosteriorSchedule != null) {
|
if ($currentPosteriorSchedule != NULL) {
|
||||||
$fullSchedule[] = $currentPosteriorSchedule;
|
$fullSchedule[] = $currentPosteriorSchedule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill;
|
namespace DNW\Skills\TrueSkill;
|
||||||
|
|
||||||
use DNW\Skills\Numerics\GaussianDistribution;
|
use DNW\Skills\Numerics\GaussianDistribution;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill;
|
namespace DNW\Skills\TrueSkill;
|
||||||
|
|
||||||
use DNW\Skills\GameInfo;
|
use DNW\Skills\GameInfo;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\TrueSkill;
|
namespace DNW\Skills\TrueSkill;
|
||||||
|
|
||||||
use DNW\Skills\GameInfo;
|
use DNW\Skills\GameInfo;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\FactorGraphs;
|
namespace DNW\Skills\Tests\FactorGraphs;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\FactorGraphs;
|
namespace DNW\Skills\Tests\FactorGraphs;
|
||||||
|
|
||||||
use DNW\Skills\FactorGraphs\Variable;
|
use DNW\Skills\FactorGraphs\Variable;
|
||||||
@ -11,8 +13,9 @@ class VariableTest extends TestCase
|
|||||||
public function test(): void
|
public function test(): void
|
||||||
{
|
{
|
||||||
$gd_prior = new GaussianDistribution();
|
$gd_prior = new GaussianDistribution();
|
||||||
$var = new Variable('dummy', $gd_prior);
|
$var = new Variable('dummy', $gd_prior);
|
||||||
$this->assertEquals($gd_prior, $var->getValue());
|
$this->assertEquals($gd_prior, $var->getValue());
|
||||||
|
|
||||||
$gd_new = new GaussianDistribution();
|
$gd_new = new GaussianDistribution();
|
||||||
$this->assertEquals($gd_new, $var->getValue());
|
$this->assertEquals($gd_new, $var->getValue());
|
||||||
$var->resetToPrior();
|
$var->resetToPrior();
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests;
|
namespace DNW\Skills\Tests;
|
||||||
|
|
||||||
@ -12,7 +14,7 @@ class GuardTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException(Exception::class);
|
$this->expectException(Exception::class);
|
||||||
$this->expectExceptionMessage('dummy can not be null');
|
$this->expectExceptionMessage('dummy can not be null');
|
||||||
Guard::argumentNotNull(null, "dummy");
|
Guard::argumentNotNull(NULL, "dummy");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testargumentIsValidIndex(): void
|
public function testargumentIsValidIndex(): void
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\Numerics;
|
namespace DNW\Skills\Tests\Numerics;
|
||||||
|
|
||||||
use DNW\Skills\Numerics\BasicMath;
|
use DNW\Skills\Numerics\BasicMath;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\Numerics;
|
namespace DNW\Skills\Tests\Numerics;
|
||||||
|
|
||||||
use DNW\Skills\Numerics\BasicMath;
|
use DNW\Skills\Numerics\BasicMath;
|
||||||
@ -39,9 +41,9 @@ class GaussianDistributionTest extends TestCase
|
|||||||
public function testMultiplication(): void
|
public function testMultiplication(): void
|
||||||
{
|
{
|
||||||
// I verified this against the formula at http://www.tina-vision.net/tina-knoppix/tina-memo/2003-003.pdf
|
// I verified this against the formula at http://www.tina-vision.net/tina-knoppix/tina-memo/2003-003.pdf
|
||||||
$standardNormal = new GaussianDistribution(0, 1);
|
$standardNormal = new GaussianDistribution(0, 1);
|
||||||
$shiftedGaussian = new GaussianDistribution(2, 3);
|
$shiftedGaussian = new GaussianDistribution(2, 3);
|
||||||
$product = GaussianDistribution::multiply($standardNormal, $shiftedGaussian);
|
$product = GaussianDistribution::multiply($standardNormal, $shiftedGaussian);
|
||||||
|
|
||||||
$this->assertEqualsWithDelta(0.2, $product->getMean(), GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(0.2, $product->getMean(), GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
$this->assertEqualsWithDelta(3.0 / sqrt(10), $product->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(3.0 / sqrt(10), $product->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
@ -61,15 +63,15 @@ class GaussianDistributionTest extends TestCase
|
|||||||
public function testDivision(): void
|
public function testDivision(): void
|
||||||
{
|
{
|
||||||
// Since the multiplication was worked out by hand, we use the same numbers but work backwards
|
// Since the multiplication was worked out by hand, we use the same numbers but work backwards
|
||||||
$product = new GaussianDistribution(0.2, 3.0 / sqrt(10));
|
$product = new GaussianDistribution(0.2, 3.0 / sqrt(10));
|
||||||
$standardNormal = new GaussianDistribution(0, 1);
|
$standardNormal = new GaussianDistribution(0, 1);
|
||||||
|
|
||||||
$productDividedByStandardNormal = GaussianDistribution::divide($product, $standardNormal);
|
$productDividedByStandardNormal = GaussianDistribution::divide($product, $standardNormal);
|
||||||
$this->assertEqualsWithDelta(2.0, $productDividedByStandardNormal->getMean(), GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(2.0, $productDividedByStandardNormal->getMean(), GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
$this->assertEqualsWithDelta(3.0, $productDividedByStandardNormal->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(3.0, $productDividedByStandardNormal->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
|
|
||||||
$product2 = new GaussianDistribution((4 * BasicMath::square(7) + 6 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)), sqrt(((BasicMath::square(5) * BasicMath::square(7)) / (BasicMath::square(5) + BasicMath::square(7)))));
|
$product2 = new GaussianDistribution((4 * BasicMath::square(7) + 6 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)), sqrt(((BasicMath::square(5) * BasicMath::square(7)) / (BasicMath::square(5) + BasicMath::square(7)))));
|
||||||
$m4s5 = new GaussianDistribution(4, 5);
|
$m4s5 = new GaussianDistribution(4, 5);
|
||||||
$product2DividedByM4S5 = GaussianDistribution::divide($product2, $m4s5);
|
$product2DividedByM4S5 = GaussianDistribution::divide($product2, $m4s5);
|
||||||
$this->assertEqualsWithDelta(6.0, $product2DividedByM4S5->getMean(), GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(6.0, $product2DividedByM4S5->getMean(), GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
$this->assertEqualsWithDelta(7.0, $product2DividedByM4S5->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(7.0, $product2DividedByM4S5->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
@ -93,7 +95,7 @@ class GaussianDistributionTest extends TestCase
|
|||||||
// Verified with Ralf Herbrich's F# implementation
|
// Verified with Ralf Herbrich's F# implementation
|
||||||
$m1s2 = new GaussianDistribution(1, 2);
|
$m1s2 = new GaussianDistribution(1, 2);
|
||||||
$m3s4 = new GaussianDistribution(3, 4);
|
$m3s4 = new GaussianDistribution(3, 4);
|
||||||
$lrn = GaussianDistribution::logRatioNormalization($m1s2, $m3s4);
|
$lrn = GaussianDistribution::logRatioNormalization($m1s2, $m3s4);
|
||||||
$this->assertEqualsWithDelta(2.6157405972171204, $lrn, GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(2.6157405972171204, $lrn, GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ class GaussianDistributionTest extends TestCase
|
|||||||
{
|
{
|
||||||
// Verified with Ralf Herbrich's F# implementation
|
// Verified with Ralf Herbrich's F# implementation
|
||||||
$standardNormal = new GaussianDistribution(0, 1);
|
$standardNormal = new GaussianDistribution(0, 1);
|
||||||
$absDiff = GaussianDistribution::absoluteDifference($standardNormal, $standardNormal);
|
$absDiff = GaussianDistribution::absoluteDifference($standardNormal, $standardNormal);
|
||||||
$this->assertEqualsWithDelta(0.0, $absDiff, GaussianDistributionTest::ERROR_TOLERANCE);
|
$this->assertEqualsWithDelta(0.0, $absDiff, GaussianDistributionTest::ERROR_TOLERANCE);
|
||||||
|
|
||||||
$m1s2 = new GaussianDistribution(1, 2);
|
$m1s2 = new GaussianDistribution(1, 2);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\Numerics;
|
namespace DNW\Skills\Tests\Numerics;
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\Numerics;
|
namespace DNW\Skills\Tests\Numerics;
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests;
|
namespace DNW\Skills\Tests;
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests;
|
namespace DNW\Skills\Tests;
|
||||||
|
|
||||||
use DNW\Skills\RankSorter;
|
use DNW\Skills\RankSorter;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests;
|
namespace DNW\Skills\Tests;
|
||||||
|
|
||||||
use DNW\Skills\Rating;
|
use DNW\Skills\Rating;
|
||||||
@ -18,11 +20,11 @@ class RatingTest extends TestCase
|
|||||||
|
|
||||||
public function testPartialUpdate(): void
|
public function testPartialUpdate(): void
|
||||||
{
|
{
|
||||||
$rating = new Rating(100, 10, 5);
|
$rating = new Rating(100, 10, 5);
|
||||||
$rating_prior = new Rating(100, 10, 5);
|
$ratingOld = new Rating(100, 10, 5);
|
||||||
$rating_new = new Rating(200, 10, 5);
|
$ratingNew = new Rating(200, 10, 5);
|
||||||
|
|
||||||
$rating_partial = $rating ->getPartialUpdate($rating_prior, $rating_new, 0.5);
|
$rating_partial = $rating->getPartialUpdate($ratingOld, $ratingNew, 0.5);
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals(150, $rating_partial->getMean());
|
$this->assertEquals(150, $rating_partial->getMean());
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\TrueSkill;
|
namespace DNW\Skills\Tests\TrueSkill;
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\TrueSkill;
|
namespace DNW\Skills\Tests\TrueSkill;
|
||||||
|
|
||||||
@ -21,6 +23,6 @@ class FactorGraphTeamTrueSkillCalculatorTest extends TestCase
|
|||||||
public function testMethodisSupported(): void
|
public function testMethodisSupported(): void
|
||||||
{
|
{
|
||||||
$calculator = new FactorGraphTrueSkillCalculator();
|
$calculator = new FactorGraphTrueSkillCalculator();
|
||||||
$this->assertEquals(true, $calculator->isSupported(SkillCalculatorSupportedOptions::PARTIAL_PLAY));
|
$this->assertEquals(TRUE, $calculator->isSupported(SkillCalculatorSupportedOptions::PARTIAL_PLAY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\TrueSkill;
|
namespace DNW\Skills\Tests\TrueSkill;
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ class FactorGraphTrueSkillCalculatorTest extends TestCase
|
|||||||
new Player("hillary"),
|
new Player("hillary"),
|
||||||
];
|
];
|
||||||
|
|
||||||
$teams = array();
|
$teams = [];
|
||||||
foreach ($players as $player) {
|
foreach ($players as $player) {
|
||||||
$teams[] = new Team($player, $gameInfo->getDefaultRating());
|
$teams[] = new Team($player, $gameInfo->getDefaultRating());
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\TrueSkill;
|
namespace DNW\Skills\Tests\TrueSkill;
|
||||||
|
|
||||||
@ -78,8 +80,8 @@ class TrueSkillCalculatorTests
|
|||||||
|
|
||||||
private static function twoPlayerTestNotDrawn(TestCase $testClass, SkillCalculator $calculator): void
|
private static function twoPlayerTestNotDrawn(TestCase $testClass, SkillCalculator $calculator): void
|
||||||
{
|
{
|
||||||
$player1 = new Player(1);
|
$player1 = new Player(1);
|
||||||
$player2 = new Player(2);
|
$player2 = new Player(2);
|
||||||
$gameInfo = new GameInfo();
|
$gameInfo = new GameInfo();
|
||||||
|
|
||||||
$team1 = new Team($player1, $gameInfo->getDefaultRating());
|
$team1 = new Team($player1, $gameInfo->getDefaultRating());
|
||||||
@ -108,6 +110,7 @@ class TrueSkillCalculatorTests
|
|||||||
$team2 = new Team($player2, $gameInfo->getDefaultRating());
|
$team2 = new Team($player2, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
$teams = Teams::concat($team1, $team2);
|
$teams = Teams::concat($team1, $team2);
|
||||||
|
|
||||||
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]);
|
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 1]);
|
||||||
|
|
||||||
$player1NewRating = $newRatings->getRating($player1);
|
$player1NewRating = $newRatings->getRating($player1);
|
||||||
@ -122,8 +125,8 @@ class TrueSkillCalculatorTests
|
|||||||
private static function twoPlayerChessTestNotDrawn(TestCase $testClass, SkillCalculator $calculator): void
|
private static function twoPlayerChessTestNotDrawn(TestCase $testClass, SkillCalculator $calculator): void
|
||||||
{
|
{
|
||||||
// Inspired by a real bug :-)
|
// Inspired by a real bug :-)
|
||||||
$player1 = new Player(1);
|
$player1 = new Player(1);
|
||||||
$player2 = new Player(2);
|
$player2 = new Player(2);
|
||||||
$gameInfo = new GameInfo(1200.0, 1200.0 / 3.0, 200.0, 1200.0 / 300.0, 0.03);
|
$gameInfo = new GameInfo(1200.0, 1200.0 / 3.0, 200.0, 1200.0 / 300.0, 0.03);
|
||||||
|
|
||||||
$team1 = new Team($player1, new Rating(1301.0007, 42.9232));
|
$team1 = new Team($player1, new Rating(1301.0007, 42.9232));
|
||||||
@ -169,11 +172,9 @@ class TrueSkillCalculatorTests
|
|||||||
|
|
||||||
private static function oneOnTwoSimpleTest(TestCase $testClass, SkillCalculator $calculator): void
|
private static function oneOnTwoSimpleTest(TestCase $testClass, SkillCalculator $calculator): void
|
||||||
{
|
{
|
||||||
$player1 = new Player(1);
|
$player1 = new Player(1);
|
||||||
|
|
||||||
$gameInfo = new GameInfo();
|
$gameInfo = new GameInfo();
|
||||||
|
$team1 = new Team();
|
||||||
$team1 = new Team();
|
|
||||||
$team1->addPlayer($player1, $gameInfo->getDefaultRating());
|
$team1->addPlayer($player1, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
$player2 = new Player(2);
|
$player2 = new Player(2);
|
||||||
@ -975,7 +976,7 @@ class TrueSkillCalculatorTests
|
|||||||
{
|
{
|
||||||
$gameInfo = new GameInfo();
|
$gameInfo = new GameInfo();
|
||||||
|
|
||||||
$p1 = new Player(1);
|
$p1 = new Player(1);
|
||||||
$team1 = new Team($p1, $gameInfo->getDefaultRating());
|
$team1 = new Team($p1, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
$p2 = new Player(2, 0.0);
|
$p2 = new Player(2, 0.0);
|
||||||
@ -985,7 +986,7 @@ class TrueSkillCalculatorTests
|
|||||||
$team2->addPlayer($p2, $gameInfo->getDefaultRating());
|
$team2->addPlayer($p2, $gameInfo->getDefaultRating());
|
||||||
$team2->addPlayer($p3, $gameInfo->getDefaultRating());
|
$team2->addPlayer($p3, $gameInfo->getDefaultRating());
|
||||||
|
|
||||||
$teams = Teams::concat($team1, $team2);
|
$teams = Teams::concat($team1, $team2);
|
||||||
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]);
|
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2]);
|
||||||
|
|
||||||
$p1NewRating = $newRatings->getRating($p1);
|
$p1NewRating = $newRatings->getRating($p1);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\TrueSkill;
|
namespace DNW\Skills\Tests\TrueSkill;
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php declare(strict_types=1);
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace DNW\Skills\Tests\TrueSkill;
|
namespace DNW\Skills\Tests\TrueSkill;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user