我在网上找到了一个神经网络,名为ANN - http://ann.thwien.de/index.php/Main_Page。这是我目前为ANN提供的培训文件:
<?php
require_once 'ANN/Loader.php';
$data = $_POST['data'];
$comma_separated = implode(", ", $data);
print $comma_separated;
use ANN\Network;
use ANN\Values;
try
{
$objNetwork = Network::loadFromFile('xor.dat');
}
catch(Exception $e)
{
print 'Creating a new one...';
$objNetwork = new Network;
$objValues = new Values;
$objValues->train()
->input($comma_separated)->output(1);
$objValues->saveToFile('values_xor.dat');
unset($objValues);
}
try
{
$objValues = Values::loadFromFile('values_xor.dat');
}
catch(Exception $e)
{
die('Loading of values failed');
}
$objNetwork->setValues($objValues); // to be called as of version 2.0.6
$boolTrained = $objNetwork->train();
print ($boolTrained)
? 'Network trained'
: 'Network not trained completely. Please re-run the script';
$objNetwork->saveToFile('xor.dat');
$objNetwork->printNetwork();
它需要像->input(1,0,0,1,1)->output(1);
这样的输入。从$_POST['data']
获取的数据为array(1,0,0,1,1)
,代码如下:
if (notice == 1) {
arr.push(1);
} else {
arr.push(0);
}
但是使用当前的方法,它一直说有0个输入,所以我做错了什么?