2010-09-18 11:11:44 -04:00
|
|
|
<?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;
|
2010-09-18 11:11:44 -04:00
|
|
|
|
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
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2023-08-01 13:53:19 +00:00
|
|
|
private string $name;
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2023-08-01 13:53:19 +00:00
|
|
|
private mixed $value;
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2023-08-08 07:51:05 +00:00
|
|
|
public function __construct(string $name, private GaussianDistribution $prior)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2023-08-01 13:53:19 +00:00
|
|
|
$this->name = 'Variable[' . $name . ']';
|
2010-09-18 11:11:44 -04:00
|
|
|
$this->resetToPrior();
|
|
|
|
}
|
|
|
|
|
2023-08-08 07:51:05 +00:00
|
|
|
public function getValue(): GaussianDistribution
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2023-08-01 13:53:19 +00:00
|
|
|
return $this->value;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2023-08-08 07:51:05 +00:00
|
|
|
public function setValue(GaussianDistribution $value): void
|
2016-05-24 14:10:39 +02:00
|
|
|
{
|
2023-08-01 13:53:19 +00:00
|
|
|
$this->value = $value;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2023-08-01 12:56:37 +00:00
|
|
|
public function resetToPrior(): void
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2023-08-01 13:53:19 +00:00
|
|
|
$this->value = $this->prior;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2022-07-05 16:21:06 +02:00
|
|
|
public function __toString(): string
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2023-08-01 13:53:19 +00:00
|
|
|
return $this->name;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|