mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-10 09:02:15 +00:00
31 lines
989 B
PHP
31 lines
989 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace tests\Phpml\NeuralNetwork\Training;
|
|
|
|
use Phpml\NeuralNetwork\Network\MultilayerPerceptron;
|
|
use Phpml\NeuralNetwork\Training\Backpropagation;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class BackpropagationTest extends 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,
|
|
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);
|
|
}
|
|
}
|