/** * @param array $samples * @param array $targets */ public function train(array $samples, array $targets) { $layers = $this->hiddenLayers; array_unshift($layers, count($samples[0])); $layers[] = count($targets[0]); $this->perceptron = new MultilayerPerceptron($layers, $this->activationFunction); $trainer = new Backpropagation($this->perceptron); $trainer->train($samples, $targets, $this->desiredError, $this->maxIterations); }
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); }