mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-19 20:34:28 +00:00
General cleanup and removal of all unnecessary references
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
use Exception;
|
||||
|
||||
// XXX: This class is not used anywhere
|
||||
class DefaultVariable extends Variable
|
||||
{
|
||||
public function __construct()
|
||||
@ -9,12 +10,12 @@ class DefaultVariable extends Variable
|
||||
parent::__construct("Default", null);
|
||||
}
|
||||
|
||||
public function &getValue()
|
||||
public function getValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setValue(&$value)
|
||||
public function setValue($value)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
@ -34,24 +34,26 @@ abstract class Factor
|
||||
return count($this->_messages);
|
||||
}
|
||||
|
||||
protected function &getVariables()
|
||||
protected function getVariables()
|
||||
{
|
||||
return $this->_variables;
|
||||
}
|
||||
|
||||
protected function &getMessages()
|
||||
protected function getMessages()
|
||||
{
|
||||
return $this->_messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the message and marginal of the i-th variable that the factor is connected to
|
||||
* @param $messageIndex
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateMessageIndex($messageIndex)
|
||||
{
|
||||
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex");
|
||||
$message = &$this->_messages[$messageIndex];
|
||||
$variable = &$this->_messageToVariableBinding->getValue($message);
|
||||
$message = $this->_messages[$messageIndex];
|
||||
$variable = $this->_messageToVariableBinding->getValue($message);
|
||||
return $this->updateMessageVariable($message, $variable);
|
||||
}
|
||||
|
||||
@ -65,41 +67,41 @@ abstract class Factor
|
||||
*/
|
||||
public function resetMarginals()
|
||||
{
|
||||
$allValues = &$this->_messageToVariableBinding->getAllValues();
|
||||
foreach ($allValues as &$currentVariable) {
|
||||
$allValues = $this->_messageToVariableBinding->getAllValues();
|
||||
foreach ($allValues as $currentVariable) {
|
||||
$currentVariable->resetToPrior();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the ith message to the marginal and returns the log-normalization constant
|
||||
* @param $messageIndex
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendMessageIndex($messageIndex)
|
||||
{
|
||||
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), "messageIndex");
|
||||
|
||||
$message = &$this->_messages[$messageIndex];
|
||||
$variable = &$this->_messageToVariableBinding->getValue($message);
|
||||
$message = $this->_messages[$messageIndex];
|
||||
$variable = $this->_messageToVariableBinding->getValue($message);
|
||||
return $this->sendMessageVariable($message, $variable);
|
||||
}
|
||||
|
||||
protected abstract function sendMessageVariable(Message &$message, Variable &$variable);
|
||||
protected abstract function sendMessageVariable(Message $message, Variable $variable);
|
||||
|
||||
public abstract function &createVariableToMessageBinding(Variable &$variable);
|
||||
public abstract function createVariableToMessageBinding(Variable $variable);
|
||||
|
||||
protected function &createVariableToMessageBindingWithMessage(Variable &$variable, Message &$message)
|
||||
protected function createVariableToMessageBindingWithMessage(Variable $variable, Message $message)
|
||||
{
|
||||
$index = count($this->_messages);
|
||||
$localMessages = &$this->_messages;
|
||||
$localMessages[] = &$message;
|
||||
$this->_messageToVariableBinding->setValue($message, $variable);
|
||||
$localVariables = &$this->_variables;
|
||||
$localVariables[] = &$variable;
|
||||
$this->_messages[] = $message;
|
||||
$this->_variables[] = $variable;
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return ($this->_name != null) ? $this->_name : base::__toString();
|
||||
return ($this->_name != null) ? $this->_name : null;
|
||||
}
|
||||
}
|
@ -4,14 +4,13 @@ class FactorGraph
|
||||
{
|
||||
private $_variableFactory;
|
||||
|
||||
public function &getVariableFactory()
|
||||
public function getVariableFactory()
|
||||
{
|
||||
$factory = &$this->_variableFactory;
|
||||
return $factory;
|
||||
return $this->_variableFactory;
|
||||
}
|
||||
|
||||
public function setVariableFactory(VariableFactory &$factory)
|
||||
public function setVariableFactory(VariableFactory $factory)
|
||||
{
|
||||
$this->_variableFactory = &$factory;
|
||||
$this->_variableFactory = $factory;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?php namespace Moserware\Skills\FactorGraphs;
|
||||
|
||||
// edit this
|
||||
abstract class FactorGraphLayer
|
||||
{
|
||||
private $_localFactors = array();
|
||||
@ -7,38 +7,39 @@ abstract class FactorGraphLayer
|
||||
private $_inputVariablesGroups = array();
|
||||
private $_parentFactorGraph;
|
||||
|
||||
protected function __construct(FactorGraph &$parentGraph)
|
||||
protected function __construct(FactorGraph $parentGraph)
|
||||
{
|
||||
$this->_parentFactorGraph = &$parentGraph;
|
||||
$this->_parentFactorGraph = $parentGraph;
|
||||
}
|
||||
|
||||
protected function &getInputVariablesGroups()
|
||||
protected function getInputVariablesGroups()
|
||||
{
|
||||
$inputVariablesGroups = &$this->_inputVariablesGroups;
|
||||
return $inputVariablesGroups;
|
||||
return $this->_inputVariablesGroups;
|
||||
}
|
||||
|
||||
// HACK
|
||||
|
||||
public function &getParentFactorGraph()
|
||||
public function getParentFactorGraph()
|
||||
{
|
||||
$parentFactorGraph = &$this->_parentFactorGraph;
|
||||
return $parentFactorGraph;
|
||||
return $this->_parentFactorGraph;
|
||||
}
|
||||
|
||||
/**
|
||||
* This reference is still needed
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function &getOutputVariablesGroups()
|
||||
{
|
||||
$outputVariablesGroups = &$this->_outputVariablesGroups;
|
||||
return $outputVariablesGroups;
|
||||
return $this->_outputVariablesGroups;
|
||||
}
|
||||
|
||||
public function &getLocalFactors()
|
||||
public function getLocalFactors()
|
||||
{
|
||||
$localFactors = &$this->_localFactors;
|
||||
return $localFactors;
|
||||
return $this->_localFactors;
|
||||
}
|
||||
|
||||
public function setInputVariablesGroups(&$value)
|
||||
public function setInputVariablesGroups($value)
|
||||
{
|
||||
$this->_inputVariablesGroups = $value;
|
||||
}
|
||||
@ -48,7 +49,7 @@ abstract class FactorGraphLayer
|
||||
return new ScheduleSequence($name, $itemsToSequence);
|
||||
}
|
||||
|
||||
protected function addLayerFactor(Factor &$factor)
|
||||
protected function addLayerFactor(Factor $factor)
|
||||
{
|
||||
$this->_localFactors[] = $factor;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ class FactorList
|
||||
|
||||
public function getLogNormalization()
|
||||
{
|
||||
$list = &$this->_list;
|
||||
$list = $this->_list;
|
||||
foreach ($list as &$currentFactor) {
|
||||
$currentFactor->resetMarginals();
|
||||
}
|
||||
@ -42,7 +42,7 @@ class FactorList
|
||||
return count($this->_list);
|
||||
}
|
||||
|
||||
public function &addFactor(Factor &$factor)
|
||||
public function addFactor(Factor $factor)
|
||||
{
|
||||
$this->_list[] = $factor;
|
||||
return $factor;
|
||||
|
@ -4,15 +4,14 @@ class KeyedVariable extends Variable
|
||||
{
|
||||
private $_key;
|
||||
|
||||
public function __construct(&$key, $name, &$prior)
|
||||
public function __construct($key, $name, $prior)
|
||||
{
|
||||
parent::__construct($name, $prior);
|
||||
$this->_key = &$key;
|
||||
$this->_key = $key;
|
||||
}
|
||||
|
||||
public function &getKey()
|
||||
public function getKey()
|
||||
{
|
||||
$key = &$this->_key;
|
||||
return $key;
|
||||
return $this->_key;
|
||||
}
|
||||
}
|
@ -5,21 +5,20 @@ class Message
|
||||
private $_name;
|
||||
private $_value;
|
||||
|
||||
public function __construct(&$value = null, $name = null)
|
||||
public function __construct($value = null, $name = null)
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->_value = $value;
|
||||
}
|
||||
|
||||
public function& getValue()
|
||||
public function getValue()
|
||||
{
|
||||
$value = &$this->_value;
|
||||
return $value;
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
public function setValue(&$value)
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = &$value;
|
||||
$this->_value = $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
|
@ -5,7 +5,7 @@ class ScheduleLoop extends Schedule
|
||||
private $_maxDelta;
|
||||
private $_scheduleToLoop;
|
||||
|
||||
public function __construct($name, Schedule &$scheduleToLoop, $maxDelta)
|
||||
public function __construct($name, Schedule $scheduleToLoop, $maxDelta)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->_scheduleToLoop = $scheduleToLoop;
|
||||
|
@ -14,8 +14,8 @@ class ScheduleSequence extends Schedule
|
||||
{
|
||||
$maxDelta = 0;
|
||||
|
||||
$schedules = &$this->_schedules;
|
||||
foreach ($schedules as &$currentSchedule) {
|
||||
$schedules = $this->_schedules;
|
||||
foreach ($schedules as $currentSchedule) {
|
||||
$currentVisit = $currentSchedule->visit($depth + 1, $maxDepth);
|
||||
$maxDelta = max($currentVisit, $maxDelta);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ class ScheduleStep extends Schedule
|
||||
private $_factor;
|
||||
private $_index;
|
||||
|
||||
public function __construct($name, Factor &$factor, $index)
|
||||
public function __construct($name, Factor $factor, $index)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->_factor = $factor;
|
||||
@ -14,7 +14,7 @@ class ScheduleStep extends Schedule
|
||||
|
||||
public function visit($depth = -1, $maxDepth = 0)
|
||||
{
|
||||
$currentFactor = &$this->_factor;
|
||||
$currentFactor = $this->_factor;
|
||||
$delta = $currentFactor->updateMessageIndex($this->_index);
|
||||
return $delta;
|
||||
}
|
||||
|
@ -7,22 +7,21 @@ class Variable
|
||||
private $_prior;
|
||||
private $_value;
|
||||
|
||||
public function __construct($name, &$prior)
|
||||
public function __construct($name, $prior)
|
||||
{
|
||||
$this->_name = "Variable[" . $name . "]";
|
||||
$this->_prior = $prior;
|
||||
$this->resetToPrior();
|
||||
}
|
||||
|
||||
public function &getValue()
|
||||
public function getValue()
|
||||
{
|
||||
$value = &$this->_value;
|
||||
return $value;
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
public function setValue(&$value)
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = &$value;
|
||||
$this->_value = $value;
|
||||
}
|
||||
|
||||
public function resetToPrior()
|
||||
|
@ -7,17 +7,17 @@ class VariableFactory
|
||||
|
||||
public function __construct($variablePriorInitializer)
|
||||
{
|
||||
$this->_variablePriorInitializer = &$variablePriorInitializer;
|
||||
$this->_variablePriorInitializer = $variablePriorInitializer;
|
||||
}
|
||||
|
||||
public function &createBasicVariable($name)
|
||||
public function createBasicVariable($name)
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$newVar = new Variable($name, $initializer());
|
||||
return $newVar;
|
||||
}
|
||||
|
||||
public function &createKeyedVariable(&$key, $name)
|
||||
public function createKeyedVariable($key, $name)
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$newVar = new KeyedVariable($key, $name, $initializer());
|
||||
|
Reference in New Issue
Block a user