Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Phpml\NeuralNetwork\Training\Backpropagation;
6
 
7
use Phpml\NeuralNetwork\Node\Neuron;
8
 
9
class Sigma
10
{
11
    /**
12
     * @var Neuron
13
     */
14
    private $neuron;
15
 
16
    /**
17
     * @var float
18
     */
19
    private $sigma;
20
 
21
    public function __construct(Neuron $neuron, float $sigma)
22
    {
23
        $this->neuron = $neuron;
24
        $this->sigma = $sigma;
25
    }
26
 
27
    public function getNeuron(): Neuron
28
    {
29
        return $this->neuron;
30
    }
31
 
32
    public function getSigma(): float
33
    {
34
        return $this->sigma;
35
    }
36
 
37
    public function getSigmaForNeuron(Neuron $neuron): float
38
    {
39
        $sigma = 0.0;
40
 
41
        foreach ($this->neuron->getSynapses() as $synapse) {
42
            if ($synapse->getNode() == $neuron) {
43
                $sigma += $synapse->getWeight() * $this->getSigma();
44
            }
45
        }
46
 
47
        return $sigma;
48
    }
49
}