Logical XOR function: Difference between revisions
From Artificial Neural Network for PHP
(New page: = Logical XOR function = == Training == <source lang="php"> require_once '../ANN/ANN_Network.php'; try { $network = ANN_Network::loadFromFile('xor.dat'); } catch(Exception $e) { pri...) |
mNo edit summary |
||
Line 4: | Line 4: | ||
<source lang="php"> |
<source lang="php"> |
||
require_once ' |
require_once 'ANN/ANN_Network.php'; |
||
try |
try |
||
Line 43: | Line 43: | ||
<source lang="php"> |
<source lang="php"> |
||
require_once(' |
require_once('ANN/ANN_Network.php'); |
||
try |
try |
Revision as of 10:00, 21 December 2007
Logical XOR function
Training
require_once 'ANN/ANN_Network.php';
try
{
$network = ANN_Network::loadFromFile('xor.dat');
}
catch(Exception $e)
{
print "\nCreating a new one...";
$network = new ANN_Network;
}
$inputs = array(
array(0, 0),
array(0, 1),
array(1, 0),
array(1, 1)
);
$outputs = array(
array(0),
array(1),
array(1),
array(0)
);
$network->setInputs($inputs);
$network->setOutputs($outputs);
$network->train();
$network->saveToFile('xor.dat');
Using a trained network
require_once('ANN/ANN_Network.php');
try
{
$network = ANN_Network::loadFromFile('xor.dat');
}
catch(Exception $e)
{
print "\nNetwork not found.";
}
$inputs = array(
array(0, 0),
array(0, 1),
array(1, 0),
array(1, 1)
);
$network->setInputs($inputs);
print_r($network->getOutputs());