Completed
Push — master ( 970a19...ed87ad )
by Yasunori
12s queued 11s
created

Activation::ReLU()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace devfym\IntelliPHP\Math;
4
5
class Activation
6
{
7
    /**
8
     * @param float $input
9
     * @return float
10
     */
11
    public static function ReLU(float $input) : float
12
    {
13
        return max(0, $input);
14
    }
15
16
    /**
17
     * @param float $input
18
     * @return float
19
     */
20
    public static function Sigmoid(float $input) : float
21
    {
22
        return round(1 / (1 + exp(-$input)), 4);
23
    }
24
25
    /**
26
     * @param array $inputs
27
     * @return array
28
     */
29
    public static function Softmax(array $inputs) : array
30
    {
31
        $exp = array_map('exp', $inputs);
32
33
        $sum_exp = array_sum($exp);
34
35
        $y = [];
36
37
        foreach($exp as $e) {
38
39
            array_push($y,$e / $sum_exp);
40
41
        }
42
43
        return $y;
44
    }
45
}