for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Phpml\NeuralNetwork\Node;
use Phpml\NeuralNetwork\ActivationFunction;
use Phpml\NeuralNetwork\ActivationFunction\Sigmoid;
use Phpml\NeuralNetwork\Node;
use Phpml\NeuralNetwork\Node\Neuron\Synapse;
class Neuron implements Node
{
/**
* @var Synapse[]
*/
protected $synapses = [];
* @var ActivationFunction
protected $activationFunction;
* @var float
protected $output;
public function __construct(?ActivationFunction $activationFunction = null)
$this->activationFunction = $activationFunction ?: new Sigmoid();
$this->synapses = [];
$this->output = 0;
$output
double
0
integer
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.
$answer = 42; $correct = false; $correct = (bool) $answer;
}
public function addSynapse(Synapse $synapse): void
$this->synapses[] = $synapse;
* @return Synapse[]
public function getSynapses()
return $this->synapses;
public function getOutput(): float
if ($this->output === 0) {
$sum = 0;
foreach ($this->synapses as $synapse) {
$sum += $synapse->getOutput();
$this->output = $this->activationFunction->compute($sum);
return $this->output;
public function getDerivative(float $value): float
return $this->activationFunction->differentiate($value);
public function reset(): void
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.