HyperbolicTangent.php 686 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
14
15

namespace Phpml\NeuralNetwork\ActivationFunction;

use Phpml\NeuralNetwork\ActivationFunction;

class HyperbolicTangent implements ActivationFunction
{
    /**
     * @var float
     */
    private $beta;

16
    public function __construct(float $beta = 1.0)
17
18
19
20
21
22
23
    {
        $this->beta = $beta;
    }

    /**
     * @param float|int $value
     */
24
    public function compute($value): float
25
26
27
    {
        return tanh($this->beta * $value);
    }
28
29
30
31
32
33
34
35
36

    /**
     * @param float|int $value
     * @param float|int $computedvalue
     */
    public function differentiate($value, $computedvalue): float
    {
        return 1 - pow($computedvalue, 2);
    }
37
}