Getting rid of more warnings.

This commit is contained in:
Jens True 2023-08-03 13:08:04 +00:00
parent f0f4a0c2d6
commit 22cc0da96d
10 changed files with 43 additions and 10 deletions

@ -1,6 +1,7 @@
<?php
namespace DNW\Skills\FactorGraphs;
use DNW\Skills\FactorGraphs\ScheduleSequence;
abstract class FactorGraphLayer
{
@ -9,15 +10,23 @@ abstract class FactorGraphLayer
*/
private array $localFactors = [];
/**
* @var array<int,array<int,object>>
*/
private array $outputVariablesGroups = [];
/**
* @var array<int,array<int,object>>
*/
private $inputVariablesGroups = [];
protected function __construct(private readonly FactorGraph $parentFactorGraph)
{
}
protected function getInputVariablesGroups()
/**
* @return array<int,array<int,object>>
*/
protected function getInputVariablesGroups(): array
{
return $this->inputVariablesGroups;
}
@ -31,6 +40,7 @@ abstract class FactorGraphLayer
/**
* This reference is still needed
* @return array<int,array<int,object>>
*/
public function &getOutputVariablesGroups(): array
{
@ -45,11 +55,17 @@ abstract class FactorGraphLayer
return $this->localFactors;
}
/**
* @param array<int,array<int,object>> $value
*/
public function setInputVariablesGroups(array $value): void
{
$this->inputVariablesGroups = $value;
}
/**
* @param Schedule[] $itemsToSequence
*/
protected function scheduleSequence(array $itemsToSequence, string $name): ScheduleSequence
{
return new ScheduleSequence($name, $itemsToSequence);

@ -4,6 +4,9 @@ namespace DNW\Skills\Numerics;
class DiagonalMatrix extends Matrix
{
/**
* @param float[] $diagonalValues
*/
public function __construct(array $diagonalValues)
{
$diagonalCount = count($diagonalValues);

@ -8,10 +8,16 @@ class Matrix
{
public const ERROR_TOLERANCE = 0.0000000001;
/**
* @param array<int,array<int,float>> $matrixRowData
*/
public function __construct(private int $rowCount = 0, private int $columnCount = 0, private array $matrixRowData = array())
{
}
/**
* @param array<int,array<int,float>> $columnValues
*/
public static function fromColumnValues(int $rows, int $columns, array $columnValues): self
{
$data = [];

@ -12,7 +12,7 @@ class RankSorter
*
* @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.
* @return array<array>
* @return array<mixed>
*/
public static function sort(array &$teams, array &$teamRanks): array
{

@ -92,7 +92,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
}
/**
* @var Team[] $teamAssignmentsList
* @param Team[] $teamAssignmentsList
*/
private static function getPlayerMeansVector(array $teamAssignmentsList): Vector
{
@ -106,7 +106,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
}
/**
* @var Team[] $teamAssignmentsList
* @param Team[] $teamAssignmentsList
*/
private static function getPlayerCovarianceMatrix(array $teamAssignmentsList): DiagonalMatrix
{
@ -123,7 +123,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
/**
* Helper function that gets a list of values for all player ratings
* @var Team[] $teamAssignmentsList
* @param Team[] $teamAssignmentsList
* @return int[]
*/
private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array

@ -230,6 +230,10 @@ class GaussianWeightedSumFactor extends GaussianFactor
);
}
/**
* @param Variable[] $variablesToSum
* @param float[] $weights
*/
private static function createName(string $sumVariable, array $variablesToSum, array $weights): string
{
// TODO: Perf? Use PHP equivalent of StringBuilder? implode on arrays?

@ -40,7 +40,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
public function createPriorSchedule(): ?ScheduleSequence
{
switch (is_countable($this->getInputVariablesGroups()) ? count($this->getInputVariablesGroups()) : 0) {
switch (count($this->getInputVariablesGroups())) {
case 0:
case 1:
throw new Exception('InvalidOperation');

@ -9,6 +9,7 @@ use DNW\Skills\Player;
use DNW\Skills\Team;
use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor;
use DNW\Skills\FactorGraphs\Variable;
use DNW\Skills\FactorGraphs\KeyedVariable;
class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer
{
@ -42,7 +43,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
}
/**
* @param Team[] $teamMembers
* @param KeyedVariable[] $teamMembers
*/
protected function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor
{
@ -81,6 +82,9 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
return $this->scheduleSequence($allFactors, "all of the team's sum iterations");
}
/**
* @param KeyedVariable[] $team
*/
private function createOutputVariable(array $team): Variable
{
$memberNames = array_map(fn ($currentPlayer) => (string) ($currentPlayer->getKey()), $team);

@ -24,7 +24,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer
public function buildLayer(): void
{
$inputVarGroups = $this->getInputVariablesGroups();
$inputVarGroupsCount = is_countable($inputVarGroups) ? count($inputVarGroups) : 0;
$inputVarGroupsCount = count($inputVarGroups);
for ($i = 0; $i < $inputVarGroupsCount; $i++) {
$isDraw = ($this->teamRanks[$i] == $this->teamRanks[$i + 1]);

@ -10,7 +10,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG
public function buildLayer(): void
{
$inputVariablesGroups = $this->getInputVariablesGroups();
$inputVariablesGroupsCount = is_countable($inputVariablesGroups) ? count($inputVariablesGroups) : 0;
$inputVariablesGroupsCount = count($inputVariablesGroups);
$outputVariablesGroup = &$this->getOutputVariablesGroups();
for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) {