所以,我在网上发现了这个类,这是一个用PHP编程的神经网络。您可以在此处找到它:http://pastebin.com/vVn4CABh
但是,我希望它根据输入执行操作。输入将是一个3 * 3网格,填充黑色或白色方块。方块创建'H'或'T'。所以,我为此创建了一些PHP代码。但我正在努力解决它。
在下面的代码中,我制作了一个T形黑色正方形,但它仍然认为它是T形。
$n = new NeuralNetwork(3, 4, 1);
$n->setVerbose(false);
//shape of T and H in 3*3 grid
$n->addTestData(array(1, 1, 1, 0, 1, 0, 0, 1, 0), array (0));
$n->addTestData(array(1, 0, 1, 1, 1, 1, 1, 0, 1), array (1));
$max = 3;
while (!($success = $n->train(1000, 0.01)) && $max -- > 0) {
echo "Nothing found...<hr />";
}
if ($success) {
$epochs = $n->getEpoch();
echo "Success in $epochs training rounds!<hr />";
}
//T with one black square
$shape = $n->calculate(array(1,0,1,0,1,0,0,1,0));
$shape = $n->calculate(array(1,0,1,0,1,0,0,1,0));
print "output from neural network = (".implode(", ", $shape).")\n";
if ($shape > 0.5) {
print "The shape is an H.";
} else {
print "The shape is a T.";
}