2017-09-02 19:30:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-01-06 12:09:33 +00:00
|
|
|
namespace Phpml\Tests\NeuralNetwork\ActivationFunction;
|
2017-09-02 19:30:35 +00:00
|
|
|
|
|
|
|
use Phpml\NeuralNetwork\ActivationFunction\ThresholdedReLU;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class ThresholdedReLUTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider thresholdProvider
|
|
|
|
*/
|
2017-11-14 20:21:23 +00:00
|
|
|
public function testThresholdedReLUActivationFunction($theta, $expected, $value): void
|
2017-09-02 19:30:35 +00:00
|
|
|
{
|
|
|
|
$thresholdedReLU = new ThresholdedReLU($theta);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $thresholdedReLU->compute($value));
|
|
|
|
}
|
|
|
|
|
2017-11-22 21:16:10 +00:00
|
|
|
public function thresholdProvider(): array
|
2017-09-02 19:30:35 +00:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[1.0, 0, 1.0],
|
|
|
|
[0.5, 3.75, 3.75],
|
|
|
|
[0.0, 0.5, 0.5],
|
2017-11-22 21:16:10 +00:00
|
|
|
[0.9, 0, 0.1],
|
2017-09-02 19:30:35 +00:00
|
|
|
];
|
|
|
|
}
|
2018-01-09 10:09:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider thresholdDerivativeProvider
|
|
|
|
*/
|
|
|
|
public function testThresholdedReLUDerivative($theta, $expected, $value): void
|
|
|
|
{
|
|
|
|
$thresholdedReLU = new ThresholdedReLU($theta);
|
|
|
|
$activatedValue = $thresholdedReLU->compute($value);
|
|
|
|
$this->assertEquals($expected, $thresholdedReLU->differentiate($value, $activatedValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function thresholdDerivativeProvider(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[0, 1, 1],
|
|
|
|
[0, 1, 0],
|
|
|
|
[0.5, 1, 1],
|
|
|
|
[0.5, 1, 1],
|
|
|
|
[0.5, 0, 0],
|
|
|
|
[2, 0, -1],
|
|
|
|
];
|
|
|
|
}
|
2017-09-02 19:30:35 +00:00
|
|
|
}
|