Example #1
0
 /**
  * @param \Sereban\NeuronNet\Neuron $to
  * @param \Sereban\NeuronNet\Neuron $from
  * @return bool
  */
 protected function _weightCorrection(Neuron $to, Neuron $from)
 {
     $weightDiff = self::ACCELERATOR * $from->getValue() * $to->getValue();
     $this->_weight += $weightDiff;
     //increase weight
     return true;
 }
Example #2
0
function test(Neuron $neuron)
{
    $neuronResult = [];
    for ($x = MIN; $x <= MAX; $x += STEP) {
        $neuronResult[] = [$x, $neuron->border($x)];
    }
    $dots = [];
    foreach (getTestData() as $testData) {
        $dots[$testData->getExpectedResult()][] = [$testData->getData()[0], $testData->getData()[1]];
    }
    ?>

        <div class="graphs">
            <div class="graph2d" style="width:600px; height: 300px"
                    data-data="<?php 
    echo json_encode($neuronResult);
    ?>
"
                    data-dots="<?php 
    echo htmlspecialchars(json_encode($dots), ENT_QUOTES, 'UTF-8');
    ?>
"></div>
        </div>
        <script>draw()</script>

    <?php 
}
Example #3
0
 public function calculate($layer, array $inputs)
 {
     $neurons = $this->layers[$layer];
     $result = [];
     $n = new Neuron();
     foreach ($neurons as $neuron => $array) {
         $n->reset();
         if (count($array) !== count($inputs)) {
             throw new RuntimeException('Counts are different');
         }
         foreach ($array as $link => $weight) {
             $n->addWeight($link, $weight);
         }
         $result[] = $n->power($inputs);
     }
     return $result;
 }
Example #4
0
 function __construct($numberOfData)
 {
     parent::__construct($numberOfData);
 }
Example #5
0
 function __construct($weightsCount)
 {
     parent::__construct($weightsCount);
     //$this->oldWeights = $this->weights;
 }
Example #6
0
 private function calculateForNeuron(Neuron $neuron, $k)
 {
     $sum = 0;
     //        echo '<div style="padding-left: 40px;">';
     foreach ($this->neurons as $j => $neuron2) {
         if ($neuron == $neuron2) {
             continue;
         }
         //                echo 'w<sub>'.$k.''.$j.'</sub> * y<sub>'.$j.'</sub>(t-1)<br>';
         //                echo round($neuron->getWeights()[$j], 2).' * '.$neuron->getPreviousResult().'<br>';
         $sum += $neuron->getWeights()[$j] * $neuron2->getPreviousResult();
     }
     //        echo '</div>';
     return $sum + $neuron->getBias() > 0 ? 1 : -1;
 }