php-ml/tests/Phpml/NeuralNetwork/Training/BackpropagationTest.php
Arkadiusz Kondas 6421a2ba41 Develop to master (#18)
* Fix Backpropagation test with explicit random generator seed

* remove custom seed - not working :(

* Updated links in readme
2016-08-21 14:03:20 +02:00

30 lines
979 B
PHP

<?php
declare (strict_types = 1);
namespace tests\Phpml\NeuralNetwork\Training;
use Phpml\NeuralNetwork\Network\MultilayerPerceptron;
use Phpml\NeuralNetwork\Training\Backpropagation;
class BackpropagationTest extends \PHPUnit_Framework_TestCase
{
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,
30000
);
$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);
}
}