Ejemplo n.º 1
0
Archivo: Layer.php Proyecto: 0-php/AI
 /**
  * @uses Neuron::setDelta()
  * @uses Neuron::getWeight()
  * @uses Neuron::getDelta()
  * @uses Neuron::getOutput()
  * @uses getNeurons()
  */
 public function calculateHiddenDeltas()
 {
     $floatDelta = 0;
     $floatSum = 0;
     $arrNeuronsNextLayer = $this->objNextLayer->getNeurons();
     /* @var $objNeuron Neuron */
     foreach ($this->arrNeurons as $intKeyNeuron => $objNeuron) {
         /* @var $objNeuronNextLayer Neuron */
         foreach ($arrNeuronsNextLayer as $objNeuronNextLayer) {
             $floatSum += $objNeuronNextLayer->getWeight($intKeyNeuron) * $objNeuronNextLayer->getDelta() * $this->objNetwork->floatMomentum;
         }
         $floatOutput = $objNeuron->getOutput();
         $floatDelta = $floatOutput * (1 - $floatOutput) * $floatSum;
         $objNeuron->setDelta($floatDelta);
     }
 }
Ejemplo n.º 2
0
Archivo: Network.php Proyecto: 0-php/AI
 /**
  * @uses Layer::getNeurons()
  * @uses Logging::logData()
  * @uses Neuron::getWeights()
  * @uses getNetworkError()
  */
 protected function logWeights()
 {
     $arrData = array();
     $arrData['E'] = $this->getNetworkError();
     // ****** arrHiddenLayers ****************
     foreach ($this->arrHiddenLayers as $intKeyLayer => $objHiddenLayer) {
         $arrNeurons = $objHiddenLayer->getNeurons();
         foreach ($arrNeurons as $intKeyNeuron => $objNeuron) {
             foreach ($objNeuron->getWeights() as $intKeyWeight => $weight) {
                 $arrData["H{$intKeyLayer}-N{$intKeyNeuron}-W{$intKeyWeight}"] = round($weight, 5);
             }
         }
     }
     // ****** objOutputLayer *****************
     $arrNeurons = $this->objOutputLayer->getNeurons();
     foreach ($arrNeurons as $intKeyNeuron => $objNeuron) {
         foreach ($objNeuron->getWeights() as $intKeyWeight => $weight) {
             $arrData["O-N{$intKeyNeuron}-W{$intKeyWeight}"] = round($weight, 5);
         }
     }
     // ************************************
     $this->objLoggingWeights->logData($arrData);
 }