-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathPReLU.php
45 lines (40 loc) · 979 Bytes
/
PReLU.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Rubix\Engine\NeuralNetwork\ActivationFunctions;
class PReLU implements ActivationFunction
{
/**
* The amount of leakage to allow to pass through when not activated.
*
* @var float
*/
protected $leakage;
/**
* @param float $leakage
* @return void
*/
public function __construct(float $leakage = 0.01)
{
$this->leakage = $leakage;
}
/**
* Compute the output value.
*
* @param float $value
* @return float
*/
public function compute(float $value) : float
{
return $value >= 0.0 ? $value : $this->leakage * $value;
}
/**
* Calculate the partial derivative with respect to the computed output.
*
* @param float $value
* @param float $computed
* @return float
*/
public function differentiate(float $value, float $computed) : float
{
return $computed >= 0.0 ? 1.0 : $this->leakage;
}
}