mirror of
https://github.com/furyfire/trueskill.git
synced 2025-04-19 20:34:28 +00:00
Pint applied for formatting
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
use Exception;
|
||||
|
||||
@ -7,7 +9,7 @@ class DefaultVariable extends Variable
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("Default", null);
|
||||
parent::__construct('Default', null);
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
@ -19,4 +21,4 @@ class DefaultVariable extends Variable
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,24 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
use Exception;
|
||||
use DNW\Skills\Guard;
|
||||
use DNW\Skills\HashMap;
|
||||
use Exception;
|
||||
|
||||
abstract class Factor
|
||||
{
|
||||
private $_messages = array();
|
||||
private $_messages = [];
|
||||
|
||||
private $_messageToVariableBinding;
|
||||
|
||||
private $_name;
|
||||
private $_variables = array();
|
||||
|
||||
private $_variables = [];
|
||||
|
||||
protected function __construct($name)
|
||||
{
|
||||
$this->_name = "Factor[" . $name . "]";
|
||||
$this->_name = 'Factor['.$name.']';
|
||||
$this->_messageToVariableBinding = new HashMap();
|
||||
}
|
||||
|
||||
@ -46,14 +50,17 @@ abstract class Factor
|
||||
|
||||
/**
|
||||
* 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");
|
||||
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), 'messageIndex');
|
||||
$message = $this->_messages[$messageIndex];
|
||||
$variable = $this->_messageToVariableBinding->getValue($message);
|
||||
|
||||
return $this->updateMessageVariable($message, $variable);
|
||||
}
|
||||
|
||||
@ -75,28 +82,32 @@ abstract class Factor
|
||||
|
||||
/**
|
||||
* 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");
|
||||
Guard::argumentIsValidIndex($messageIndex, count($this->_messages), 'messageIndex');
|
||||
|
||||
$message = $this->_messages[$messageIndex];
|
||||
$variable = $this->_messageToVariableBinding->getValue($message);
|
||||
|
||||
return $this->sendMessageVariable($message, $variable);
|
||||
}
|
||||
|
||||
protected abstract function sendMessageVariable(Message $message, Variable $variable);
|
||||
abstract protected function sendMessageVariable(Message $message, Variable $variable);
|
||||
|
||||
public abstract function createVariableToMessageBinding(Variable $variable);
|
||||
abstract public function createVariableToMessageBinding(Variable $variable);
|
||||
|
||||
protected function createVariableToMessageBindingWithMessage(Variable $variable, Message $message)
|
||||
{
|
||||
$this->_messageToVariableBinding->setValue($message, $variable);
|
||||
$this->_messages[] = $message;
|
||||
$this->_variables[] = $variable;
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
@ -104,4 +115,4 @@ abstract class Factor
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class FactorGraph
|
||||
{
|
||||
@ -13,4 +15,4 @@ class FactorGraph
|
||||
{
|
||||
$this->_variableFactory = $factory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
// edit this
|
||||
abstract class FactorGraphLayer
|
||||
{
|
||||
private $_localFactors = array();
|
||||
private $_outputVariablesGroups = array();
|
||||
private $_inputVariablesGroups = array();
|
||||
private $_localFactors = [];
|
||||
|
||||
private $_outputVariablesGroups = [];
|
||||
|
||||
private $_inputVariablesGroups = [];
|
||||
|
||||
private $_parentFactorGraph;
|
||||
|
||||
protected function __construct(FactorGraph $parentGraph)
|
||||
@ -54,7 +60,7 @@ abstract class FactorGraphLayer
|
||||
$this->_localFactors[] = $factor;
|
||||
}
|
||||
|
||||
public abstract function buildLayer();
|
||||
abstract public function buildLayer();
|
||||
|
||||
public function createPriorSchedule()
|
||||
{
|
||||
@ -65,4 +71,4 @@ abstract class FactorGraphLayer
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
/**
|
||||
* Helper class for computing the factor graph's normalization constant.
|
||||
*/
|
||||
class FactorList
|
||||
{
|
||||
private $_list = array();
|
||||
private $_list = [];
|
||||
|
||||
public function getLogNormalization()
|
||||
{
|
||||
@ -45,6 +47,7 @@ class FactorList
|
||||
public function addFactor(Factor $factor)
|
||||
{
|
||||
$this->_list[] = $factor;
|
||||
|
||||
return $factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class KeyedVariable extends Variable
|
||||
{
|
||||
@ -14,4 +16,4 @@ class KeyedVariable extends Variable
|
||||
{
|
||||
return $this->_key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class Message
|
||||
{
|
||||
private $_name;
|
||||
|
||||
private $_value;
|
||||
|
||||
public function __construct($value = null, $name = null)
|
||||
@ -23,6 +26,6 @@ class Message
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return (string)$this->_name;
|
||||
return (string) $this->_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
abstract class Schedule
|
||||
{
|
||||
@ -9,10 +11,10 @@ abstract class Schedule
|
||||
$this->_name = $name;
|
||||
}
|
||||
|
||||
public abstract function visit($depth = -1, $maxDepth = 0);
|
||||
abstract public function visit($depth = -1, $maxDepth = 0);
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleLoop extends Schedule
|
||||
{
|
||||
private $_maxDelta;
|
||||
|
||||
private $_scheduleToLoop;
|
||||
|
||||
public function __construct($name, Schedule $scheduleToLoop, $maxDelta)
|
||||
@ -23,4 +26,4 @@ class ScheduleLoop extends Schedule
|
||||
|
||||
return $delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleSequence extends Schedule
|
||||
{
|
||||
@ -22,4 +24,4 @@ class ScheduleSequence extends Schedule
|
||||
|
||||
return $maxDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleStep extends Schedule
|
||||
{
|
||||
private $_factor;
|
||||
|
||||
private $_index;
|
||||
|
||||
public function __construct($name, Factor $factor, $index)
|
||||
@ -16,6 +19,7 @@ class ScheduleStep extends Schedule
|
||||
{
|
||||
$currentFactor = $this->_factor;
|
||||
$delta = $currentFactor->updateMessageIndex($this->_index);
|
||||
|
||||
return $delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class Variable
|
||||
{
|
||||
private $_name;
|
||||
|
||||
private $_prior;
|
||||
|
||||
private $_value;
|
||||
|
||||
public function __construct($name, $prior)
|
||||
{
|
||||
$this->_name = "Variable[" . $name . "]";
|
||||
$this->_name = 'Variable['.$name.']';
|
||||
$this->_prior = $prior;
|
||||
$this->resetToPrior();
|
||||
}
|
||||
@ -33,4 +36,4 @@ class Variable
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace DNW\Skills\FactorGraphs;
|
||||
<?php
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class VariableFactory
|
||||
{
|
||||
@ -14,6 +16,7 @@ class VariableFactory
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$newVar = new Variable($name, $initializer());
|
||||
|
||||
return $newVar;
|
||||
}
|
||||
|
||||
@ -21,6 +24,7 @@ class VariableFactory
|
||||
{
|
||||
$initializer = $this->_variablePriorInitializer;
|
||||
$newVar = new KeyedVariable($key, $name, $initializer());
|
||||
|
||||
return $newVar;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user