mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 10:12:28 +01:00 
			
		
		
		
	More types
This commit is contained in:
		@@ -8,12 +8,18 @@ use Exception;
 | 
			
		||||
 | 
			
		||||
abstract class Factor implements \Stringable
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Message[] $messages
 | 
			
		||||
     */
 | 
			
		||||
    private array $messages = [];
 | 
			
		||||
 | 
			
		||||
    private HashMap $messageToVariableBinding;
 | 
			
		||||
 | 
			
		||||
    private string $name;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Variable[] $variables
 | 
			
		||||
     */
 | 
			
		||||
    private array $variables = [];
 | 
			
		||||
 | 
			
		||||
    protected function __construct(string $name)
 | 
			
		||||
@@ -64,7 +70,7 @@ abstract class Factor implements \Stringable
 | 
			
		||||
        return $this->updateMessageVariable($message, $variable);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function updateMessageVariable(Message $message, Variable $variable)
 | 
			
		||||
    protected function updateMessageVariable(Message $message, Variable $variable): float
 | 
			
		||||
    {
 | 
			
		||||
        throw new Exception();
 | 
			
		||||
    }
 | 
			
		||||
@@ -82,13 +88,9 @@ abstract class Factor implements \Stringable
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sends the ith message to the marginal and returns the log-normalization constant
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $messageIndex
 | 
			
		||||
     * @return
 | 
			
		||||
     *
 | 
			
		||||
     * @throws Exception
 | 
			
		||||
     */
 | 
			
		||||
    public function sendMessageIndex($messageIndex)
 | 
			
		||||
    public function sendMessageIndex(int $messageIndex): float|int
 | 
			
		||||
    {
 | 
			
		||||
        Guard::argumentIsValidIndex($messageIndex, count($this->messages), 'messageIndex');
 | 
			
		||||
 | 
			
		||||
@@ -98,7 +100,7 @@ abstract class Factor implements \Stringable
 | 
			
		||||
        return $this->sendMessageVariable($message, $variable);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    abstract protected function sendMessageVariable(Message $message, Variable $variable);
 | 
			
		||||
    abstract protected function sendMessageVariable(Message $message, Variable $variable): float|int;
 | 
			
		||||
 | 
			
		||||
    abstract public function createVariableToMessageBinding(Variable $variable);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,9 @@ namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
abstract class FactorGraphLayer
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var Factor[] $localFactors
 | 
			
		||||
     */
 | 
			
		||||
    private array $localFactors = [];
 | 
			
		||||
 | 
			
		||||
    private array $outputVariablesGroups = [];
 | 
			
		||||
@@ -34,6 +37,9 @@ abstract class FactorGraphLayer
 | 
			
		||||
        return $this->outputVariablesGroups;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Factor[]
 | 
			
		||||
     */
 | 
			
		||||
    public function getLocalFactors(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->localFactors;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
class PartialPlay
 | 
			
		||||
{
 | 
			
		||||
    public static function getPartialPlayPercentage($player)
 | 
			
		||||
    public static function getPartialPlayPercentage(Player $player): float
 | 
			
		||||
    {
 | 
			
		||||
        // If the player doesn't support the interface, assume 1.0 == 100%
 | 
			
		||||
        $supportsPartialPlay = $player instanceof ISupportPartialPlay;
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@ use DNW\Skills\PlayersRange;
 | 
			
		||||
use DNW\Skills\RankSorter;
 | 
			
		||||
use DNW\Skills\SkillCalculator;
 | 
			
		||||
use DNW\Skills\SkillCalculatorSupportedOptions;
 | 
			
		||||
use DNW\Skills\Team;
 | 
			
		||||
use DNW\Skills\TeamsRange;
 | 
			
		||||
use DNW\Skills\RatingContainer;
 | 
			
		||||
 | 
			
		||||
@@ -151,11 +152,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
        $playerAssignments = [];
 | 
			
		||||
        $totalPreviousPlayers = 0;
 | 
			
		||||
 | 
			
		||||
        $teamAssignmentsListCount = is_countable($teamAssignmentsList) ? count($teamAssignmentsList) : 0;
 | 
			
		||||
 | 
			
		||||
        $currentColumn = 0;
 | 
			
		||||
 | 
			
		||||
        for ($i = 0; $i < $teamAssignmentsListCount - 1; $i++) {
 | 
			
		||||
        for ($i = 0; $i < count($teamAssignmentsList) - 1; $i++) {
 | 
			
		||||
            $currentTeam = $teamAssignmentsList[$i];
 | 
			
		||||
 | 
			
		||||
            // Need to add in 0's for all the previous players, since they're not
 | 
			
		||||
@@ -185,6 +184,6 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
 | 
			
		||||
            $currentColumn++;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return Matrix::fromColumnValues($totalPlayers, $teamAssignmentsListCount - 1, $playerAssignments);
 | 
			
		||||
        return Matrix::fromColumnValues($totalPlayers, count($teamAssignmentsList) - 1, $playerAssignments);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function buildLayer()
 | 
			
		||||
    public function buildLayer(): void
 | 
			
		||||
    {
 | 
			
		||||
        $inputVariablesGroups = $this->getInputVariablesGroups();
 | 
			
		||||
        $this->TeamPerformancesToTeamPerformanceDifferencesLayer->setInputVariablesGroups($inputVariablesGroups);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user