2017 © Pedro Peláez
 

library neural-network

Artificial neural network

image

a1essandro/neural-network

Artificial neural network

  • Tuesday, July 11, 2017
  • by A1essandro
  • Repository
  • 2 Watchers
  • 10 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

neural-network

Build Status Coverage Status Code Climate Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

Language choice:

English Russian, (*2)

Requirements

This package is only supported on PHP 5.5 and above., (*3)

Installation

Method #1(recommended): Composer package

See more getcomposer.org., (*4)

Execute command, (*5)

composer require a1essandro/neural-network ^0.1.0

Or add line to composer.json, (*6)

"require": {
    ...
    "require a1essandro/neural-network": "^0.1.0"
},

Method #2: Clone repository

Execute command, (*7)

git clone https://github.com/A1essandro/neural-network

Usage

Common

XOR example:

use Neural\BackpropagationTeacher;
use Neural\MultilayerPerceptron;

require_once '../vendor/autoload.php';

//Creation neural network, with 2 input-neurons, one hidden layer with 2 neurons and one output neuron:
$p = new MultilayerPerceptron([2, 2, 1]); //You may add more hidden layers or neurons to layers: [2, 3, 2, 1]
$p->generateSynapses(); //automatically add synapses

$t = new BackpropagationTeacher($p); //Teacher with backpropagation algorithm

//Teach until it learns
$learningResult = $t->teachKit(
    [[1, 0], [0, 1], [1, 1], [0, 0]], //kit for learning
    [[1], [1], [0], [0]], //appropriate expectations 
    0.3, //error
    10000 //max iterations
);

if ($learningResult != -1) {
    echo '1,0: ' . round($p->input([1, 0])->output()[0]) . PHP_EOL;
    echo '0,1: ' . round($p->input([0, 1])->output()[0]) . PHP_EOL;
    echo '0,0: ' . round($p->input([0, 0])->output()[0]) . PHP_EOL;
    echo '1,1: ' . round($p->input([1, 1])->output()[0]) . PHP_EOL;
}

/* Result:
1,0: 1
0,1: 1
0,0: 0
1,1: 0
*/

Manually configuration of network

$p = new MultilayerPerceptron([2, 2, 1]);

//Equivalent to:

$p = new MultilayerPerceptron();
$p->addLayer(new Layer())->toLastLayer()
    ->addNode(new Input())
    ->addNode(new Input())
    ->addNode(new Bias());
$p->addLayer(new Layer())->toLastLayer()
    ->addNode(new Neuron())
    ->addNode(new Neuron())
    ->addNode(new Bias());
$p->addLayer(new Layer())->toLastLayer()
    ->addNode(new Neuron());

//Do not forget to add synapses:

$p->generateSynapses();

//Or you may direct the process:

$neuronFilter = function($node) {
    return $node instanceof Neuron;
};

$secondLayerNeuron = iterator_to_array($p->getLayers()[1]->getNodes($neuronFilter))[0];
$input = iterator_to_array($p->getLayers()[0]->getNodes())[0];
$secondLayerNeuron->addSynapse(new Synapse($input));

//and so on...

Specification

Network

Interface implementation of INetwork is a container comprising nodes (INode) interconnected by synapses (Synapse)., (*8)

Layers

Interface implementations of ILayer are formal groups of INode in a LayeredNetwork., (*9)

Nodes

INode - neurons, input-neurons etc., (*10)

Synapses

Synapse - is a connection between two nodes (INode). Synapse gets output (call output()) of neuron-transmitter and convert the value via its weight. Result value gets neuron-reciever (it call output() of ISynapse)., (*11)

Contribute

Contributions to the package are always welcome!, (*12)

License

The code base is licensed under the MIT license., (*13)

The Versions

11/07 2017

dev-master

9999999-dev

Artificial neural network

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar A1essandro

21/02 2017

dev-develop

dev-develop

Artificial neural network

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Avatar A1essandro

15/01 2017

v0.1.2

0.1.2.0

Artificial neural network

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar A1essandro

13/01 2017

v0.1.1

0.1.1.0

Artificial neural network

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar A1essandro

04/08 2016

v0.1.0

0.1.0.0

Artificial neural network

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Avatar A1essandro