Passed
Pull Request — master (#129)
by Marcin
03:19 queued 50s
created

ThresholdedReLU   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compute() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phpml\NeuralNetwork\ActivationFunction;
6
7
use Phpml\NeuralNetwork\ActivationFunction;
8
9
class ThresholdedReLU implements ActivationFunction
10
{
11
    /**
12
     * @var float
13
     */
14
    private $theta;
15
16
    /**
17
     * @param float $theta
18
     */
19
    public function __construct($theta = 1.0)
20
    {
21
        $this->theta = $theta;
22
    }
23
24
    /**
25
     * @param float|int $value
26
     *
27
     * @return float
28
     */
29
    public function compute($value): float
30
    {
31
        return $value > $this->theta ? $value : 0.0;
32
    }
33
}
34