2016-08-05 08:20:31 +00:00
|
|
|
<?php
|
|
|
|
|
2016-11-20 21:53:17 +00:00
|
|
|
declare(strict_types=1);
|
2016-08-05 08:20:31 +00:00
|
|
|
|
|
|
|
namespace tests\Phpml\NeuralNetwork;
|
|
|
|
|
|
|
|
use Phpml\NeuralNetwork\Layer;
|
2017-11-06 07:56:37 +00:00
|
|
|
use Phpml\NeuralNetwork\Node\Bias;
|
2016-08-05 08:20:31 +00:00
|
|
|
use Phpml\NeuralNetwork\Node\Neuron;
|
2017-02-03 11:58:25 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-05 08:20:31 +00:00
|
|
|
|
2017-02-03 11:58:25 +00:00
|
|
|
class LayerTest extends TestCase
|
2016-08-05 08:20:31 +00:00
|
|
|
{
|
|
|
|
public function testLayerInitialization()
|
|
|
|
{
|
|
|
|
$layer = new Layer();
|
|
|
|
|
|
|
|
$this->assertEquals([], $layer->getNodes());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLayerInitializationWithDefaultNodesType()
|
|
|
|
{
|
|
|
|
$layer = new Layer($number = 5);
|
|
|
|
|
|
|
|
$this->assertCount($number, $layer->getNodes());
|
|
|
|
foreach ($layer->getNodes() as $node) {
|
|
|
|
$this->assertInstanceOf(Neuron::class, $node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLayerInitializationWithExplicitNodesType()
|
|
|
|
{
|
|
|
|
$layer = new Layer($number = 5, $class = Bias::class);
|
|
|
|
|
|
|
|
$this->assertCount($number, $layer->getNodes());
|
|
|
|
foreach ($layer->getNodes() as $node) {
|
|
|
|
$this->assertInstanceOf($class, $node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Phpml\Exception\InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testThrowExceptionOnInvalidNodeClass()
|
|
|
|
{
|
|
|
|
new Layer(1, \stdClass::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddNodesToLayer()
|
|
|
|
{
|
|
|
|
$layer = new Layer();
|
|
|
|
$layer->addNode($node1 = new Neuron());
|
|
|
|
$layer->addNode($node2 = new Neuron());
|
|
|
|
|
|
|
|
$this->assertEquals([$node1, $node2], $layer->getNodes());
|
|
|
|
}
|
|
|
|
}
|