More types

This commit is contained in:
Jens True 2023-08-02 13:29:14 +00:00
parent 73781e9000
commit a2c5252cf2
6 changed files with 18 additions and 19 deletions

@ -6,15 +6,14 @@ class Message implements \Stringable
{ {
public function __construct(private ?object $value = null, private ?string $name = null) public function __construct(private ?object $value = null, private ?string $name = null)
{ {
} }
public function getValue() public function getValue(): ?object
{ {
return $this->value; return $this->value;
} }
public function setValue($value) public function setValue(?object $value): void
{ {
$this->value = $value; $this->value = $value;
} }

@ -4,7 +4,7 @@ namespace DNW\Skills\FactorGraphs;
class ScheduleLoop extends Schedule class ScheduleLoop extends Schedule
{ {
public function __construct($name, private readonly Schedule $scheduleToLoop, private $maxDelta) public function __construct(string $name, private readonly Schedule $scheduleToLoop, private float $maxDelta)
{ {
parent::__construct($name); parent::__construct($name);
} }

@ -4,7 +4,7 @@ namespace DNW\Skills\FactorGraphs;
class ScheduleStep extends Schedule class ScheduleStep extends Schedule
{ {
public function __construct(string $name, private readonly Factor $factor, private $index) public function __construct(string $name, private readonly Factor $factor, private int $index)
{ {
parent::__construct($name); parent::__construct($name);
} }

@ -7,8 +7,14 @@ namespace DNW\Skills;
*/ */
class HashMap class HashMap
{ {
/**
* @var mixed[] $hashToValue
*/
private array $hashToValue = []; private array $hashToValue = [];
/**
* @var mixed[] $hashToKey
*/
private array $hashToKey = []; private array $hashToKey = [];
public function getValue(string|object $key): mixed public function getValue(string|object $key): mixed
@ -27,11 +33,17 @@ class HashMap
return $this; return $this;
} }
/**
* @return mixed[]
*/
public function getAllKeys(): array public function getAllKeys(): array
{ {
return array_values($this->hashToKey); return array_values($this->hashToKey);
} }
/**
* @return mixed[]
*/
public function getAllValues(): array public function getAllValues(): array
{ {
return array_values($this->hashToValue); return array_values($this->hashToValue);

@ -63,18 +63,6 @@ class GaussianDistribution implements \Stringable
return 1.0 / (sqrt(2 * M_PI) * $this->standardDeviation); return 1.0 / (sqrt(2 * M_PI) * $this->standardDeviation);
} }
public function __clone()
{
$result = new GaussianDistribution();
$result->mean = $this->mean;
$result->standardDeviation = $this->standardDeviation;
$result->variance = $this->variance;
$result->precision = $this->precision;
$result->precisionMean = $this->precisionMean;
return $result;
}
public static function fromPrecisionMean(float $precisionMean, float $precision): self public static function fromPrecisionMean(float $precisionMean, float $precision): self
{ {
$result = new GaussianDistribution(); $result = new GaussianDistribution();
@ -174,7 +162,7 @@ class GaussianDistribution implements \Stringable
return 0.5 * $result; return 0.5 * $result;
} }
private static function errorFunctionCumulativeTo($x): float private static function errorFunctionCumulativeTo(float $x): float
{ {
// Derived from page 265 of Numerical Recipes 3rd Edition // Derived from page 265 of Numerical Recipes 3rd Edition
$z = abs($x); $z = abs($x);

@ -53,7 +53,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
} }
// When dealing with differences, there are always (n-1) differences, so add in the 1 // When dealing with differences, there are always (n-1) differences, so add in the 1
$totalTeamDifferences = is_countable($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()) ? count($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()) : 0; $totalTeamDifferences = count($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors());
$localFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors(); $localFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors();