Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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  }