Example #1
0
 public function testBackpropagationForXORLearning()
 {
     $network = new MultilayerPerceptron([2, 2, 1]);
     $training = new Backpropagation($network);
     $training->train([[1, 0], [0, 1], [1, 1], [0, 0]], [[1], [1], [0], [0]], $desiredError = 0.3, 40000);
     $this->assertEquals(0, $network->setInput([1, 1])->getOutput()[0], '', $desiredError);
     $this->assertEquals(0, $network->setInput([0, 0])->getOutput()[0], '', $desiredError);
     $this->assertEquals(1, $network->setInput([1, 0])->getOutput()[0], '', $desiredError);
     $this->assertEquals(1, $network->setInput([0, 1])->getOutput()[0], '', $desiredError);
 }
Example #2
0
 /**
  * @param array $sample
  *
  * @return array
  */
 protected function predictSample(array $sample)
 {
     return $this->perceptron->setInput($sample)->getOutput();
 }