Difference between revisions of "Logical XOR function"

m
m
Line 1: Line 1:
= Logical XOR function =
 
 
 
== Training ==
 
== Training ==
   
Line 12: Line 10:
 
catch(Exception $e)
 
catch(Exception $e)
 
{
 
{
print "\nCreating a new one...";
+
print "Creating a new one...";
 
 
 
$network = new ANN_Network;
 
$network = new ANN_Network;
Line 51: Line 49:
 
catch(Exception $e)
 
catch(Exception $e)
 
{
 
{
print "\nNetwork not found.";
+
print "Network not found.";
 
}
 
}
   

Revision as of 12:05, 21 December 2007

Training

require_once 'ANN/ANN_Network.php';

try
{
  $network = ANN_Network::loadFromFile('xor.dat');
}
catch(Exception $e)
{
  print "Creating 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 "Network not found.";
}

$inputs = array(
	array(0, 0),
	array(0, 1),
	array(1, 0),
	array(1, 1)
);

$network->setInputs($inputs);

print_r($network->getOutputs());