mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-16 01:47:39 +00:00
More PHP types for static analysis
This commit is contained in:
@ -12,11 +12,11 @@ abstract class Factor implements \Stringable
|
|||||||
|
|
||||||
private $_messageToVariableBinding;
|
private $_messageToVariableBinding;
|
||||||
|
|
||||||
private $_name;
|
private string $_name;
|
||||||
|
|
||||||
private array $_variables = [];
|
private array $_variables = [];
|
||||||
|
|
||||||
protected function __construct($name)
|
protected function __construct(string $name)
|
||||||
{
|
{
|
||||||
$this->_name = 'Factor['.$name.']';
|
$this->_name = 'Factor['.$name.']';
|
||||||
$this->_messageToVariableBinding = new HashMap();
|
$this->_messageToVariableBinding = new HashMap();
|
||||||
@ -33,17 +33,17 @@ abstract class Factor implements \Stringable
|
|||||||
/**
|
/**
|
||||||
* @return int The number of messages that the factor has
|
* @return int The number of messages that the factor has
|
||||||
*/
|
*/
|
||||||
public function getNumberOfMessages()
|
public function getNumberOfMessages(): int
|
||||||
{
|
{
|
||||||
return count($this->_messages);
|
return count($this->_messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getVariables()
|
protected function getVariables(): array
|
||||||
{
|
{
|
||||||
return $this->_variables;
|
return $this->_variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMessages()
|
protected function getMessages(): array
|
||||||
{
|
{
|
||||||
return $this->_messages;
|
return $this->_messages;
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ abstract class Factor implements \Stringable
|
|||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function updateMessageIndex($messageIndex)
|
public function updateMessageIndex(int $messageIndex)
|
||||||
{
|
{
|
||||||
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), 'messageIndex');
|
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), 'messageIndex');
|
||||||
$message = $this->_messages[$messageIndex];
|
$message = $this->_messages[$messageIndex];
|
||||||
|
@ -28,30 +28,28 @@ abstract class FactorGraphLayer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This reference is still needed
|
* This reference is still needed
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function &getOutputVariablesGroups()
|
public function &getOutputVariablesGroups(): array
|
||||||
{
|
{
|
||||||
return $this->_outputVariablesGroups;
|
return $this->_outputVariablesGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLocalFactors()
|
public function getLocalFactors(): array
|
||||||
{
|
{
|
||||||
return $this->_localFactors;
|
return $this->_localFactors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setInputVariablesGroups($value)
|
public function setInputVariablesGroups(array $value): void
|
||||||
{
|
{
|
||||||
$this->_inputVariablesGroups = $value;
|
$this->_inputVariablesGroups = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function scheduleSequence(array $itemsToSequence, $name): ScheduleSequence
|
protected function scheduleSequence(array $itemsToSequence, string $name): ScheduleSequence
|
||||||
{
|
{
|
||||||
return new ScheduleSequence($name, $itemsToSequence);
|
return new ScheduleSequence($name, $itemsToSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addLayerFactor(Factor $factor)
|
protected function addLayerFactor(Factor $factor): void
|
||||||
{
|
{
|
||||||
$this->_localFactors[] = $factor;
|
$this->_localFactors[] = $factor;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class Team extends RatingContainer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addPlayer(Player $player, Rating $rating)
|
public function addPlayer(Player $player, Rating $rating): self
|
||||||
{
|
{
|
||||||
$this->setRating($player, $rating);
|
$this->setRating($player, $rating);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ namespace DNW\Skills;
|
|||||||
|
|
||||||
class Teams
|
class Teams
|
||||||
{
|
{
|
||||||
public static function concat(...$args/*variable arguments*/)
|
public static function concat(Team ...$args/*variable arguments*/): array
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
|
@ -15,15 +15,15 @@ class TruncatedGaussianCorrectionFunctions
|
|||||||
* correction of a single-sided truncated Gaussian with unit variance."
|
* correction of a single-sided truncated Gaussian with unit variance."
|
||||||
*
|
*
|
||||||
* @param $teamPerformanceDifference
|
* @param $teamPerformanceDifference
|
||||||
* @param number $drawMargin In the paper, it's referred to as just "ε".
|
* @param $drawMargin In the paper, it's referred to as just "ε".
|
||||||
* @param $c
|
* @param $c
|
||||||
*/
|
*/
|
||||||
public static function vExceedsMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
|
public static function vExceedsMarginScaled(float $teamPerformanceDifference, float $drawMargin, float $c): float
|
||||||
{
|
{
|
||||||
return self::vExceedsMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
return self::vExceedsMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function vExceedsMargin($teamPerformanceDifference, $drawMargin)
|
public static function vExceedsMargin(float $teamPerformanceDifference, float $drawMargin): float
|
||||||
{
|
{
|
||||||
$denominator = GaussianDistribution::cumulativeTo($teamPerformanceDifference - $drawMargin);
|
$denominator = GaussianDistribution::cumulativeTo($teamPerformanceDifference - $drawMargin);
|
||||||
|
|
||||||
@ -44,12 +44,12 @@ class TruncatedGaussianCorrectionFunctions
|
|||||||
* @param $drawMargin
|
* @param $drawMargin
|
||||||
* @param $c
|
* @param $c
|
||||||
*/
|
*/
|
||||||
public static function wExceedsMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
|
public static function wExceedsMarginScaled(float $teamPerformanceDifference, float $drawMargin, float $c): float
|
||||||
{
|
{
|
||||||
return self::wExceedsMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
return self::wExceedsMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function wExceedsMargin($teamPerformanceDifference, $drawMargin): float
|
public static function wExceedsMargin(float $teamPerformanceDifference, float $drawMargin): float
|
||||||
{
|
{
|
||||||
$denominator = GaussianDistribution::cumulativeTo($teamPerformanceDifference - $drawMargin);
|
$denominator = GaussianDistribution::cumulativeTo($teamPerformanceDifference - $drawMargin);
|
||||||
|
|
||||||
@ -67,13 +67,13 @@ class TruncatedGaussianCorrectionFunctions
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the additive correction of a double-sided truncated Gaussian with unit variance
|
// the additive correction of a double-sided truncated Gaussian with unit variance
|
||||||
public static function vWithinMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
|
public static function vWithinMarginScaled(float $teamPerformanceDifference, float $drawMargin, float $c): float
|
||||||
{
|
{
|
||||||
return self::vWithinMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
return self::vWithinMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// from F#:
|
// from F#:
|
||||||
public static function vWithinMargin($teamPerformanceDifference, $drawMargin): float
|
public static function vWithinMargin(float $teamPerformanceDifference, float $drawMargin): float
|
||||||
{
|
{
|
||||||
$teamPerformanceDifferenceAbsoluteValue = abs($teamPerformanceDifference);
|
$teamPerformanceDifferenceAbsoluteValue = abs($teamPerformanceDifference);
|
||||||
$denominator =
|
$denominator =
|
||||||
@ -99,13 +99,13 @@ class TruncatedGaussianCorrectionFunctions
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the multiplicative correction of a double-sided truncated Gaussian with unit variance
|
// the multiplicative correction of a double-sided truncated Gaussian with unit variance
|
||||||
public static function wWithinMarginScaled($teamPerformanceDifference, float|int $drawMargin, $c): float
|
public static function wWithinMarginScaled(float $teamPerformanceDifference, float $drawMargin, float $c): float
|
||||||
{
|
{
|
||||||
return self::wWithinMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
return self::wWithinMargin($teamPerformanceDifference / $c, $drawMargin / $c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// From F#:
|
// From F#:
|
||||||
public static function wWithinMargin($teamPerformanceDifference, float|int $drawMargin)
|
public static function wWithinMargin(float $teamPerformanceDifference, float $drawMargin): float
|
||||||
{
|
{
|
||||||
$teamPerformanceDifferenceAbsoluteValue = abs($teamPerformanceDifference);
|
$teamPerformanceDifferenceAbsoluteValue = abs($teamPerformanceDifference);
|
||||||
$denominator = GaussianDistribution::cumulativeTo($drawMargin - $teamPerformanceDifferenceAbsoluteValue)
|
$denominator = GaussianDistribution::cumulativeTo($drawMargin - $teamPerformanceDifferenceAbsoluteValue)
|
||||||
|
Reference in New Issue
Block a user