BinaryStep.php 583 Bytes
Newer Older
1
2
<?php

Arkadiusz Kondas's avatar
Arkadiusz Kondas committed
3
declare(strict_types=1);
4
5
6
7
8
9
10
11
12
13

namespace Phpml\NeuralNetwork\ActivationFunction;

use Phpml\NeuralNetwork\ActivationFunction;

class BinaryStep implements ActivationFunction
{
    /**
     * @param float|int $value
     */
14
    public function compute($value): float
15
16
17
    {
        return $value >= 0 ? 1.0 : 0.0;
    }
18
19
20
21
22
23
24
25
26
27
28
29
30

    /**
     * @param float|int $value
     * @param float|int $computedvalue
     */
    public function differentiate($value, $computedvalue): float
    {
        if ($value === 0 || $value === 0.0) {
            return 1;
        }

        return 0;
    }
31
}