/** * Set the main flags to app */ public function setUp() { $this->_app = new App(); Net::setDirection(Net::DIRECT); Net::setMode(Net::TEACHER_MODE); Net::setDebugFlag(false); //disable output to console }
/** * @param array $signals * @param int $direction * @return array */ public function prepareNeuronToCalculation($signals = array(), $direction) { $assoc = Factory::neuron(Factory::ASSOC, 0); $react = Factory::neuron(Factory::REACT, 0); //Adding Signals foreach ($signals as $signal) { $assoc->addSignal($signal); $react->addSignal($signal); } $this->_addLayoutToNeuron($assoc); $this->_addLayoutToNeuron($react); //Calculation Net::setDirection($direction); return array(Factory::ASSOC => $assoc, Factory::REACT => $react); }
/** * @throws \Exception * @return bool */ public function calculate() { //Calculating value $_sum = array_sum($this->getSignals()); $_sum += $this->getLayout()->getOffset(); $this->_value = $this->_binarSigmoid($_sum); if (Net::isTeacherMode()) { Net::setDirection(Net::REVERSE); $_value = ($this->_teacherValue - $this->_value) * $this->_diffBinarSigmoid($_sum); //new value will be mistake if (Net::isDebugEnabled()) { //Print value and teacher value/ var_dump("Summ: {$_value}. Teacher : " . $this->_teacherValue . ". Value: " . $this->_value); } $this->setValue($_value); } else { $this->getLayout()->compare($this); //add to lead neurons if this neuron has the max value } return true; }
/** * Test Weight Correction after sending signal. Direction Should be always Reverse * @param $signal * @param $weight * @dataProvider prepareSendingData * @depends testDirectSend * @depends testReverseSend */ public function testWeightCorrection($signal, $weight) { Net::setDirection(Net::REVERSE); //signal propagation $this->_to->setValue($signal); $this->_from->setValue($this->_oldValue); $this->_relation->setWeight($weight); $this->_relation->send($this->_to); //Test whether weight correction is null or no $this->assertNotEquals($weight, $this->getWeightFromRelation($this->_relation), "Back Propagation Stuck"); }
public function rewind() { //Start From the beginning $this->_level = 0; Net::setDirection(Net::DIRECT); }
/** * @throws \Exception */ public function calculate() { Net::setDirection(Net::DIRECT); $this->setValue($this->_value); //do nothing }