mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-10 17:24:44 +00:00
6421a2ba41
* Fix Backpropagation test with explicit random generator seed * remove custom seed - not working :( * Updated links in readme
30 lines
979 B
PHP
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);
|
|
}
|
|
}
|