src/Network.php
public function trainInput(array $in, array $expected)
    {
        if ($this->getInputLayer()->size !== count($in)) {
            throw new RuntimeException('Input array length must be the same as input length.');
        }

        if ($this->getOutputLayer()->size !== count($expected)) {
            throw new RuntimeException('Expected array length must be the same as output length.');
        }

        $out = $this->pulseInput($in);

        $layer = $this->getOutputLayer();

        for ($i = 0; $i < $layer->size; $i++) {
            $neuron = $layer->neurons[$i];
            $neuron->gradiant = $neuron->axion * (1 - $neuron->axion) * ($expected[$i] - $neuron->axion);
        }

        for ($j = count($this->structure) - 2; $j >= 1; $j--) {
            $layer = $this->layers[$j];

            foreach ($layer->neurons as $neuron) {
                $sum = 0;

                foreach ($neuron->succ as $succ) {
                    $sum += $succ->neuronFrom->gradiant * $succ->w;
                }

                $neuron->gradiant = $neuron->axion * (1 - $neuron->axion) * $sum;
            }
        }

        for ($j = 1; $j < count($this->structure); $j++) {
            foreach ($this->layers[$j]->neurons as $neuron) {
                foreach ($neuron->dendrites as $dendrite) {
                    $dendrite->w += $this->e * $neuron->gradiant * $dendrite->neuron->axion;
                }
            }
        }

        return $out;
    }
public function trainInput(array $in, array $expected)
    {
        if ($this->getInputLayer()->size !== count($in)) {
            throw new RuntimeException('Input array length must be the same as input length.');
        }

        if ($this->getOutputLayer()->size !== count($expected)) {
            throw new RuntimeException('Expected array length must be the same as output length.');
        }

        $out = $this->pulseInput($in);

        $layer = $this->getOutputLayer();

        for ($i = 0; $i < $layer->size; $i++) {
            $neuron = $layer->neurons[$i];
            $neuron->gradiant = $neuron->axion * (1 - $neuron->axion) * ($expected[$i] - $neuron->axion);
        }

        for ($j = count($this->structure) - 2; $j >= 1; $j--) {
            $layer = $this->layers[$j];

            foreach ($layer->neurons as $neuron) {
                $sum = 0;

                foreach ($neuron->succ as $succ) {
                    $sum += $succ->neuronFrom->gradiant * $succ->w;
                }

                $neuron->gradiant = $neuron->axion * (1 - $neuron->axion) * $sum;
            }
        }

        for ($j = 1; $j < count($this->structure); $j++) {
            foreach ($this->layers[$j]->neurons as $neuron) {
                foreach ($neuron->dendrites as $dendrite) {
                    $dendrite->w += $this->e * $neuron->gradiant * $dendrite->neuron->axion;
                }
            }
        }

        return $out;
    }
@param float[] $in
@param float[] $expected

@return float[]