/
Sigmoid.php
69 lines (63 loc) · 1.46 KB
/
Sigmoid.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Rubix\ML\NeuralNet\ActivationFunctions;
use Tensor\Matrix;
/**
* Sigmoid
*
* A bounded S-shaped function (sometimes called the *Logistic* function) with an output value
* between 0 and 1. The output of the sigmoid function has the advantage of being interpretable
* as a probability, however it is not zero-centered and tends to saturate if inputs become large.
*
* @category Machine Learning
* @package Rubix/ML
* @author Andrew DalPino
*/
class Sigmoid implements ActivationFunction
{
/**
* Compute the activation.
*
* @internal
*
* @param Matrix $input
* @return Matrix
*/
public function activate(Matrix $input) : Matrix
{
return $input->map('Rubix\ML\sigmoid');
}
/**
* Calculate the derivative of the activation.
*
* @internal
*
* @param Matrix $input
* @param Matrix $output
* @return Matrix
*/
public function differentiate(Matrix $input, Matrix $output) : Matrix
{
return $output->map([$this, '_differentiate']);
}
/**
* @internal
*
* @param float $output
* @return float
*/
public function _differentiate(float $output) : float
{
return $output * (1.0 - $output);
}
/**
* Return the string representation of the object.
*
* @internal
*
* @return string
*/
public function __toString() : string
{
return 'Sigmoid';
}
}