From cb2877f45c76c3afc66e639815cc70aef5a7fa82 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 12 Feb 2022 21:17:52 +0100 Subject: [PATCH] draft neuralnet --- Ai/NeuralNetwork/Neuron.php | 92 +++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Ai/NeuralNetwork/Neuron.php diff --git a/Ai/NeuralNetwork/Neuron.php b/Ai/NeuralNetwork/Neuron.php new file mode 100644 index 000000000..5ad2ab44e --- /dev/null +++ b/Ai/NeuralNetwork/Neuron.php @@ -0,0 +1,92 @@ +inputs = $inputs; + $this->weights = $weights; + $this->bias = $bias; + } + + public function addInput($input, float $weight) + { + $this->inputs[] = $input; + $this->weights[] = $weight; + } + + /** + * Create node output + * + * @return float + * + * @since 1.0.0 + */ + public function output() : float + { + $length = \count($this->intputs); + $output = 0.0; + + for ($i = 0; $i < $length; ++$i) { + $output += $this->inputs[$i]->output() * $this->weights[$i]; + } + + return $output + $this->bias; + + // return $this->activationFunction($output + $this->bias); + } +} \ No newline at end of file