Skip to content

A neural network (Simple Perceptron) implemented in PHP.

Notifications You must be signed in to change notification settings

gzanitti/cperceptron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

cPerceptron

A neural network (Simple Perceptron) implemented in PHP.

Usage

You need to create a training set of input and output values to train the network, like these:

$trainIn = array(
	array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
	array(1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1),
	array(-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1),
	array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1));

$trainOut = array(
	array(1,1,1),
	array(1,-1,1),
	array(-1,1,-1),
	array(-1,-1,-1));

After this, you can call the function trainPS with the following parameters:

$cp = new cperceptron();
$w = $cp->trainPS($trainIn, $trainOut, $error, $iter, $vel);
  • $trainIn: Training set, input values.
  • $trainOut: Training set, output values.
  • $error: Maximum level of error.
  • $iter: Maximum number of iterations.
  • $vel: Learning speed.

The result of this call is a weight matrix corresponding to the neural network trained with the training set introduced.

Now, everything is ready to test the network. You just have to make the following function call:

$test = $cp->matrix2Vector($trainIn, 1);
$res = $cp->prodMatrix($test, $w);
$out = $cp->signMatrix($res);

Where 1 represents the input value you want to test. The result should be the value assigned in the Training Set (output value).

You can also test the network with altered values and let this approximates the results. For example, with this input value:

array(1,1,1,-1,1,1,1,1,1,1,1,1,-1,1,1,1,1,1,1,1,1,-1,1,1,1)

License

cPerceptron is released under the MIT License.

About

A neural network (Simple Perceptron) implemented in PHP.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published