mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-09 13:38:41 +00:00
draft neuralnet
This commit is contained in:
parent
eb9298ec98
commit
cb2877f45c
92
Ai/NeuralNetwork/Neuron.php
Normal file
92
Ai/NeuralNetwork/Neuron.php
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package phpOMS\Ai\NeuralNetwork
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\Ai\NeuralNetwork;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Neuron
|
||||||
|
*
|
||||||
|
* @package phpOMS\Ai\NeuralNetwork
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Neuron {
|
||||||
|
/**
|
||||||
|
* Neuron inputs
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private array $inputs = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Input weights
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private array $weights = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bias
|
||||||
|
*
|
||||||
|
* @var float
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public float $bias = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param array $inputs Neuron inputs/connections
|
||||||
|
* @param array $weights Input weights
|
||||||
|
* @param float $bias Input bias
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function __construct(array $inputs = [], array $weights = [], float $bias = 0.0)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user