mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-19 20:34:28 +00:00
Upgrade with rector
This commit is contained in:
@ -17,7 +17,7 @@ class DefaultVariable extends Variable
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
public function setValue($value): never
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
@ -6,15 +6,15 @@ use DNW\Skills\Guard;
|
||||
use DNW\Skills\HashMap;
|
||||
use Exception;
|
||||
|
||||
abstract class Factor
|
||||
abstract class Factor implements \Stringable
|
||||
{
|
||||
private $_messages = [];
|
||||
private array $_messages = [];
|
||||
|
||||
private $_messageToVariableBinding;
|
||||
|
||||
private $_name;
|
||||
|
||||
private $_variables = [];
|
||||
private array $_variables = [];
|
||||
|
||||
protected function __construct($name)
|
||||
{
|
||||
@ -111,7 +111,7 @@ abstract class Factor
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
@ -5,17 +5,14 @@ namespace DNW\Skills\FactorGraphs;
|
||||
// edit this
|
||||
abstract class FactorGraphLayer
|
||||
{
|
||||
private $_localFactors = [];
|
||||
private array $_localFactors = [];
|
||||
|
||||
private $_outputVariablesGroups = [];
|
||||
private array $_outputVariablesGroups = [];
|
||||
|
||||
private $_inputVariablesGroups = [];
|
||||
|
||||
private $_parentFactorGraph;
|
||||
|
||||
protected function __construct(FactorGraph $parentGraph)
|
||||
protected function __construct(private readonly FactorGraph $_parentFactorGraph)
|
||||
{
|
||||
$this->_parentFactorGraph = $parentGraph;
|
||||
}
|
||||
|
||||
protected function getInputVariablesGroups()
|
||||
|
@ -7,7 +7,7 @@ namespace DNW\Skills\FactorGraphs;
|
||||
*/
|
||||
class FactorList
|
||||
{
|
||||
private $_list = [];
|
||||
private array $_list = [];
|
||||
|
||||
public function getLogNormalization()
|
||||
{
|
||||
@ -33,7 +33,7 @@ class FactorList
|
||||
$sumLogS = 0;
|
||||
|
||||
foreach ($list as &$currentFactor) {
|
||||
$sumLogS = $sumLogS + $currentFactor->getLogNormalization();
|
||||
$sumLogS += $currentFactor->getLogNormalization();
|
||||
}
|
||||
|
||||
return $sumLogZ + $sumLogS;
|
||||
|
@ -4,12 +4,9 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class KeyedVariable extends Variable
|
||||
{
|
||||
private $_key;
|
||||
|
||||
public function __construct($key, $name, $prior)
|
||||
public function __construct(private $_key, $name, $prior)
|
||||
{
|
||||
parent::__construct($name, $prior);
|
||||
$this->_key = $key;
|
||||
}
|
||||
|
||||
public function getKey()
|
||||
|
@ -2,16 +2,10 @@
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class Message
|
||||
class Message implements \Stringable
|
||||
{
|
||||
private $_name;
|
||||
|
||||
private $_value;
|
||||
|
||||
public function __construct($value = null, $name = null)
|
||||
public function __construct(private $_value = null, private $_name = null)
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->_value = $value;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
@ -24,7 +18,7 @@ class Message
|
||||
$this->_value = $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string) $this->_name;
|
||||
}
|
||||
|
@ -2,19 +2,16 @@
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
abstract class Schedule
|
||||
abstract class Schedule implements \Stringable
|
||||
{
|
||||
private $_name;
|
||||
|
||||
protected function __construct($name)
|
||||
protected function __construct(private $_name)
|
||||
{
|
||||
$this->_name = $name;
|
||||
}
|
||||
|
||||
abstract public function visit($depth = -1, $maxDepth = 0);
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->_name;
|
||||
return (string) $this->_name;
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,9 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleLoop extends Schedule
|
||||
{
|
||||
private $_maxDelta;
|
||||
|
||||
private $_scheduleToLoop;
|
||||
|
||||
public function __construct($name, Schedule $scheduleToLoop, $maxDelta)
|
||||
public function __construct($name, private readonly Schedule $_scheduleToLoop, private $_maxDelta)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->_scheduleToLoop = $scheduleToLoop;
|
||||
$this->_maxDelta = $maxDelta;
|
||||
}
|
||||
|
||||
public function visit($depth = -1, $maxDepth = 0)
|
||||
|
@ -4,12 +4,9 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleSequence extends Schedule
|
||||
{
|
||||
private $_schedules;
|
||||
|
||||
public function __construct($name, array $schedules)
|
||||
public function __construct($name, private readonly array $_schedules)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->_schedules = $schedules;
|
||||
}
|
||||
|
||||
public function visit($depth = -1, $maxDepth = 0)
|
||||
|
@ -4,22 +4,15 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleStep extends Schedule
|
||||
{
|
||||
private $_factor;
|
||||
|
||||
private $_index;
|
||||
|
||||
public function __construct($name, Factor $factor, $index)
|
||||
public function __construct($name, private readonly Factor $_factor, private $_index)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->_factor = $factor;
|
||||
$this->_index = $index;
|
||||
}
|
||||
|
||||
public function visit($depth = -1, $maxDepth = 0)
|
||||
{
|
||||
$currentFactor = $this->_factor;
|
||||
$delta = $currentFactor->updateMessageIndex($this->_index);
|
||||
|
||||
return $delta;
|
||||
return $currentFactor->updateMessageIndex($this->_index);
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,15 @@
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class Variable
|
||||
class Variable implements \Stringable
|
||||
{
|
||||
private $_name;
|
||||
|
||||
private $_prior;
|
||||
|
||||
private $_value;
|
||||
|
||||
public function __construct($name, $prior)
|
||||
public function __construct($name, private $_prior)
|
||||
{
|
||||
$this->_name = 'Variable['.$name.']';
|
||||
$this->_prior = $prior;
|
||||
$this->resetToPrior();
|
||||
}
|
||||
|
||||
@ -32,7 +29,7 @@ class Variable
|
||||
$this->_value = $this->_prior;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
@ -4,27 +4,21 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class VariableFactory
|
||||
{
|
||||
// using a Func<TValue> to encourage fresh copies in case it's overwritten
|
||||
private $_variablePriorInitializer;
|
||||
|
||||
public function __construct($variablePriorInitializer)
|
||||
public function __construct(private $_variablePriorInitializer)
|
||||
{
|
||||
$this->_variablePriorInitializer = $variablePriorInitializer;
|
||||
}
|
||||
|
||||
public function createBasicVariable($name)
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$newVar = new Variable($name, $initializer());
|
||||
|
||||
return $newVar;
|
||||
return new Variable($name, $initializer());
|
||||
}
|
||||
|
||||
public function createKeyedVariable($key, $name)
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$newVar = new KeyedVariable($key, $name, $initializer());
|
||||
|
||||
return $newVar;
|
||||
return new KeyedVariable($key, $name, $initializer());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user