More type work

This commit is contained in:
2023-08-02 09:36:44 +00:00
parent 16ad8175d9
commit a60187a3fd
14 changed files with 38 additions and 31 deletions

View File

@ -7,9 +7,12 @@ namespace DNW\Skills\FactorGraphs;
*/
class FactorList
{
/**
* @var Factor[] $list
*/
private array $list = [];
public function getLogNormalization()
public function getLogNormalization(): float
{
$list = $this->list;
foreach ($list as &$currentFactor) {
@ -39,12 +42,12 @@ class FactorList
return $sumLogZ + $sumLogS;
}
public function count()
public function count(): int
{
return count($this->list);
}
public function addFactor(Factor $factor)
public function addFactor(Factor $factor): Factor
{
$this->list[] = $factor;

View File

@ -8,10 +8,10 @@ abstract class Schedule implements \Stringable
{
}
abstract public function visit(int $depth = -1, int $maxDepth = 0);
abstract public function visit(int $depth = -1, int $maxDepth = 0): float;
public function __toString(): string
{
return (string) $this->name;
return $this->name;
}
}

View File

@ -9,7 +9,7 @@ class ScheduleLoop extends Schedule
parent::__construct($name);
}
public function visit(int $depth = -1, int $maxDepth = 0)
public function visit(int $depth = -1, int $maxDepth = 0): float
{
$totalIterations = 1;
$delta = $this->scheduleToLoop->visit($depth + 1, $maxDepth);

View File

@ -4,12 +4,12 @@ namespace DNW\Skills\FactorGraphs;
class ScheduleSequence extends Schedule
{
public function __construct($name, private readonly array $schedules)
public function __construct(string $name, private readonly array $schedules)
{
parent::__construct($name);
}
public function visit($depth = -1, $maxDepth = 0)
public function visit(int $depth = -1, int $maxDepth = 0): float
{
$maxDelta = 0;

View File

@ -4,12 +4,12 @@ namespace DNW\Skills\FactorGraphs;
class ScheduleStep extends Schedule
{
public function __construct($name, private readonly Factor $factor, private $index)
public function __construct(string $name, private readonly Factor $factor, private $index)
{
parent::__construct($name);
}
public function visit(int $depth = -1, int $maxDepth = 0)
public function visit(int $depth = -1, int $maxDepth = 0): float
{
$currentFactor = $this->factor;