2016-08-02 11:07:47 +00:00
|
|
|
<?php
|
|
|
|
|
2016-11-20 21:53:17 +00:00
|
|
|
declare(strict_types=1);
|
2016-08-02 11:07:47 +00:00
|
|
|
|
|
|
|
namespace Phpml\NeuralNetwork\ActivationFunction;
|
|
|
|
|
|
|
|
use Phpml\NeuralNetwork\ActivationFunction;
|
|
|
|
|
|
|
|
class BinaryStep implements ActivationFunction
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param float|int $value
|
|
|
|
*/
|
2017-11-22 21:16:10 +00:00
|
|
|
public function compute($value): float
|
2016-08-02 11:07:47 +00:00
|
|
|
{
|
|
|
|
return $value >= 0 ? 1.0 : 0.0;
|
|
|
|
}
|
2018-01-09 10:09:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float|int $value
|
|
|
|
* @param float|int $computedvalue
|
|
|
|
*/
|
|
|
|
public function differentiate($value, $computedvalue): float
|
|
|
|
{
|
|
|
|
if ($value === 0 || $value === 0.0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-02 11:07:47 +00:00
|
|
|
}
|