2016-08-02 13:07:47 +02:00
|
|
|
<?php
|
|
|
|
|
2016-11-20 22:53:17 +01:00
|
|
|
declare(strict_types=1);
|
2016-08-02 13:07:47 +02:00
|
|
|
|
2018-01-06 13:09:33 +01:00
|
|
|
namespace Phpml\Tests\NeuralNetwork\ActivationFunction;
|
2016-08-02 13:07:47 +02:00
|
|
|
|
|
|
|
use Phpml\NeuralNetwork\ActivationFunction\BinaryStep;
|
2017-02-03 12:58:25 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-02 13:07:47 +02:00
|
|
|
|
2017-02-03 12:58:25 +01:00
|
|
|
class BinaryStepTest extends TestCase
|
2016-08-02 13:07:47 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider binaryStepProvider
|
|
|
|
*/
|
2017-11-14 21:21:23 +01:00
|
|
|
public function testBinaryStepActivationFunction($expected, $value): void
|
2016-08-02 13:07:47 +02:00
|
|
|
{
|
|
|
|
$binaryStep = new BinaryStep();
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $binaryStep->compute($value));
|
|
|
|
}
|
|
|
|
|
2017-11-22 22:16:10 +01:00
|
|
|
public function binaryStepProvider(): array
|
2016-08-02 13:07:47 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[1, 1],
|
|
|
|
[1, 0],
|
|
|
|
[0, -0.1],
|
|
|
|
];
|
|
|
|
}
|
2018-01-09 11:09:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider binaryStepDerivativeProvider
|
|
|
|
*/
|
|
|
|
public function testBinaryStepDerivative($expected, $value): void
|
|
|
|
{
|
|
|
|
$binaryStep = new BinaryStep();
|
|
|
|
$activatedValue = $binaryStep->compute($value);
|
|
|
|
$this->assertEquals($expected, $binaryStep->differentiate($value, $activatedValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function binaryStepDerivativeProvider(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[0, -1],
|
|
|
|
[1, 0],
|
|
|
|
[0, 1],
|
|
|
|
];
|
|
|
|
}
|
2016-08-02 13:07:47 +02:00
|
|
|
}
|