mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-16 01:47:39 +00:00
More types.
This commit is contained in:
@ -4,6 +4,9 @@ namespace DNW\Skills\FactorGraphs;
|
|||||||
|
|
||||||
class ScheduleSequence extends Schedule
|
class ScheduleSequence extends Schedule
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Schedule[] $schedules
|
||||||
|
*/
|
||||||
public function __construct(string $name, private readonly array $schedules)
|
public function __construct(string $name, private readonly array $schedules)
|
||||||
{
|
{
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
@ -24,7 +24,7 @@ class BasicMath
|
|||||||
/**
|
/**
|
||||||
* Sums the items in $itemsToSum
|
* Sums the items in $itemsToSum
|
||||||
*
|
*
|
||||||
* @param array $itemsToSum The items to sum,
|
* @param mixed[] $itemsToSum The items to sum,
|
||||||
* @param \Closure $callback The function to apply to each array element before summing.
|
* @param \Closure $callback The function to apply to each array element before summing.
|
||||||
* @return number The sum.
|
* @return number The sum.
|
||||||
*/
|
*/
|
||||||
|
@ -4,6 +4,9 @@ namespace DNW\Skills\Numerics;
|
|||||||
|
|
||||||
class Vector extends Matrix
|
class Vector extends Matrix
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param float[] $vectorValues
|
||||||
|
*/
|
||||||
public function __construct(array $vectorValues)
|
public function __construct(array $vectorValues)
|
||||||
{
|
{
|
||||||
$columnValues = [];
|
$columnValues = [];
|
||||||
|
@ -11,7 +11,7 @@ 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<array>
|
* @return array<array>
|
||||||
*/
|
*/
|
||||||
public static function sort(array &$teams, array &$teamRanks): array
|
public static function sort(array &$teams, array &$teamRanks): array
|
||||||
|
@ -91,6 +91,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
|||||||
return exp($expPart) * sqrt($sqrtPart);
|
return exp($expPart) * sqrt($sqrtPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Team[] $teamAssignmentsList
|
||||||
|
*/
|
||||||
private static function getPlayerMeansVector(array $teamAssignmentsList): Vector
|
private static function getPlayerMeansVector(array $teamAssignmentsList): Vector
|
||||||
{
|
{
|
||||||
// A simple vector of all the player means.
|
// A simple vector of all the player means.
|
||||||
@ -102,6 +105,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Team[] $teamAssignmentsList
|
||||||
|
*/
|
||||||
private static function getPlayerCovarianceMatrix(array $teamAssignmentsList): DiagonalMatrix
|
private static function getPlayerCovarianceMatrix(array $teamAssignmentsList): DiagonalMatrix
|
||||||
{
|
{
|
||||||
// This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all
|
// This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all
|
||||||
@ -117,6 +123,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that gets a list of values for all player ratings
|
* Helper function that gets a list of values for all player ratings
|
||||||
|
* @var Team[] $teamAssignmentsList
|
||||||
* @return int[]
|
* @return int[]
|
||||||
*/
|
*/
|
||||||
private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array
|
private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array
|
||||||
|
@ -5,6 +5,7 @@ namespace DNW\Skills\TrueSkill\Factors;
|
|||||||
use DNW\Skills\FactorGraphs\Message;
|
use DNW\Skills\FactorGraphs\Message;
|
||||||
use DNW\Skills\FactorGraphs\Variable;
|
use DNW\Skills\FactorGraphs\Variable;
|
||||||
use DNW\Skills\Guard;
|
use DNW\Skills\Guard;
|
||||||
|
use DNW\Skills\Team;
|
||||||
use DNW\Skills\Numerics\BasicMath;
|
use DNW\Skills\Numerics\BasicMath;
|
||||||
use DNW\Skills\Numerics\GaussianDistribution;
|
use DNW\Skills\Numerics\GaussianDistribution;
|
||||||
|
|
||||||
@ -15,18 +16,26 @@ use DNW\Skills\Numerics\GaussianDistribution;
|
|||||||
*/
|
*/
|
||||||
class GaussianWeightedSumFactor extends GaussianFactor
|
class GaussianWeightedSumFactor extends GaussianFactor
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var array<float[]> $variableIndexOrdersForWeights
|
||||||
|
*/
|
||||||
private array $variableIndexOrdersForWeights = [];
|
private array $variableIndexOrdersForWeights = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This following is used for convenience, for example, the first entry is [0, 1, 2]
|
* This following is used for convenience, for example, the first entry is [0, 1, 2]
|
||||||
* corresponding to v[0] = a1*v[1] + a2*v[2]
|
* corresponding to v[0] = a1*v[1] + a2*v[2]
|
||||||
* @var array<int[]> $weights
|
* @var array<float[]> $weights
|
||||||
*/
|
*/
|
||||||
private array $weights = [];
|
private array $weights = [];
|
||||||
|
/**
|
||||||
|
* @var array<float[]> $weightsSquared
|
||||||
|
*/
|
||||||
private array $weightsSquared = [];
|
private array $weightsSquared = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Variable[] $variablesToSum
|
||||||
|
* @param array<float> $variableWeights
|
||||||
|
*/
|
||||||
public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights = null)
|
public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights = null)
|
||||||
{
|
{
|
||||||
parent::__construct(self::createName($sumVariable, $variablesToSum, $variableWeights));
|
parent::__construct(self::createName($sumVariable, $variablesToSum, $variableWeights));
|
||||||
@ -132,6 +141,12 @@ class GaussianWeightedSumFactor extends GaussianFactor
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param float[] $weights
|
||||||
|
* @param float[] $weightsSquared
|
||||||
|
* @param Message[] $messages
|
||||||
|
* @param Variable[] $variables
|
||||||
|
*/
|
||||||
private function updateHelper(array $weights, array $weightsSquared, array $messages, array $variables): float
|
private function updateHelper(array $weights, array $weightsSquared, array $messages, array $variables): float
|
||||||
{
|
{
|
||||||
// Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as
|
// Potentially look at http://mathworld.wolfram.com/NormalSumDistribution.html for clues as
|
||||||
|
@ -6,6 +6,7 @@ use DNW\Skills\FactorGraphs\ScheduleStep;
|
|||||||
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
use DNW\Skills\FactorGraphs\ScheduleSequence;
|
||||||
use DNW\Skills\PartialPlay;
|
use DNW\Skills\PartialPlay;
|
||||||
use DNW\Skills\Player;
|
use DNW\Skills\Player;
|
||||||
|
use DNW\Skills\Team;
|
||||||
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
|
||||||
use DNW\Skills\FactorGraphs\Variable;
|
use DNW\Skills\FactorGraphs\Variable;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user