Files
trueskill/src/FactorGraphs/Variable.php

41 lines
772 B
PHP
Raw Normal View History

<?php
2022-07-05 15:55:47 +02:00
2024-02-02 14:53:38 +00:00
declare(strict_types=1);
2022-07-05 15:33:34 +02:00
namespace DNW\Skills\FactorGraphs;
2023-08-08 07:51:05 +00:00
use DNW\Skills\Numerics\GaussianDistribution;
2022-07-05 16:21:06 +02:00
class Variable implements \Stringable
{
private readonly string $name;
2022-07-05 15:55:47 +02:00
2023-08-01 13:53:19 +00:00
private mixed $value;
2023-08-08 07:51:05 +00:00
public function __construct(string $name, private GaussianDistribution $prior)
{
2023-08-01 13:53:19 +00:00
$this->name = 'Variable[' . $name . ']';
$this->resetToPrior();
}
2023-08-08 07:51:05 +00:00
public function getValue(): GaussianDistribution
{
2023-08-01 13:53:19 +00:00
return $this->value;
}
2023-08-08 07:51:05 +00:00
public function setValue(GaussianDistribution $value): void
{
2023-08-01 13:53:19 +00:00
$this->value = $value;
}
public function resetToPrior(): void
{
2023-08-01 13:53:19 +00:00
$this->value = $this->prior;
}
2022-07-05 16:21:06 +02:00
public function __toString(): string
{
2023-08-01 13:53:19 +00:00
return $this->name;
}
2022-07-05 15:55:47 +02:00
}