2017 © Pedro Peláez
 

library perceptron

Simple PHP implementation of a Perceptron.

image

jtet/perceptron

Simple PHP implementation of a Perceptron.

  • Monday, December 31, 2012
  • by jtet
  • Repository
  • 1 Watchers
  • 11 Stars
  • 66 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Perceptron

Build Status, (*1)

What is a Perceptron?

"the perceptron is an algorithm for supervised classification of an input into one of two possible outputs.
It is a type of linear classifier, i.e. a classification algorithm that makes its predictions based on a
linear predictor function combining a set of weights with the feature vector describing a given input."

read more at http://en.wikipedia.org/wiki/Perceptron, (*2)

Training

while($p->getIterationError() > $x)
{
    for ($i = 0; $i < count($inputVectors); $i++){
        $p->train($inputVectors[$i], $outcomes[$i);
    }
}

Test an Input

echo $p->test($inputVector)? "True": "False";

Example

The following code trains the Perceptron to act as a NAND gate, (*3)

$p = new \JTet\Perceptron\Perceptron(2);

$i = 0;
while($i < 100000)
{
    $input = array(0, 0);
    $output = 1;
    $p->train($input, $output);

    $input = array(0, 1);
    $output = 1;
    $p->train($input, $output);

    $input = array(1,0);
    $output = 1;
    $p->train($input, $output);

    $input = array(1,1);
    $output = 0;
    $p->train($input, $output);

    $i++;
}

echo $p->test(array(1,1))? "Incorrect\n": "Correct\n";
echo $p->test(array(0,1))? "Correct\n": "Incorrect\n";
echo $p->test(array(0,0))? "Correct\n": "Incorrect\n";
echo $p->test(array(1,0))? "Correct\n": "Incorrect\n";

Getting Perceptron

Add the following to your composer.json file and run composer update., (*4)

"require": {
        "jtet/perceptron": "dev-master"
    }

License

Perceptron is available for your use under the OSL-3.0 license., (*5)

The Versions

31/12 2012

dev-master

9999999-dev https://github.com/jtet/Perceptron

Simple PHP implementation of a Perceptron.

  Sources   Download

OSL-3.0

The Requires

  • php >=5.3.0

 

by Avatar jtet

perceptron artificial intelligence