This neural network was written in C++ by Dr. Mike Gashler and is released under the CC0 license. The native PHP module is compiled using PHP-CPP.
Install build utilities. (Ubuntu e.g.)
sudo apt-get install build-essential php7.0 php7.0-dev -y
Install PHP-CPP.
git clone https://github.com/CopernicaMarketingSoftware/PHP-CPP.git
cd PHP-CPP
make
sudo make install
Build, install, and enable the module.
make
sudo make install
sudo phpenmod jpuck-neural-network
See the tests for more detailed usage.
<?php
// intialize with the number of inputs,
// number of nodes per hidden layer (must have at least 1),
// and lastly the number of outputs.
// e.g. 3 inputs, 1 hidden layer with 16 nodes, and 2 outputs
$nn = new jpuck\NeuralNetwork(3, 16, 2);
// train the network with some features, labels, and a bias.
$inputs = [
0.12,
-0.38,
0.77,
];
$outputs = [
0.54,
-0.25,
];
$nn->refine($inputs, $outputs, 0.02);
// get a prediction
$prediction = $nn->predict(...$inputs);