Selling Icecreams: Difference between revisions

From Artificial Neural Network for PHP
(New page: == Training == <source lang="php"> require_once 'ANN/ANN_Network.php'; try { $network = ANN_Network::loadFromFile('icecreams.dat'); } catch(Exception $e) { print "Creating a new one...)
 
Line 18: Line 18:
$temperature = new ANN_InputValue(-15, 50); // Temperature
$temperature = new ANN_InputValue(-15, 50); // Temperature


$humidity = new ANN_InputValue(0, 100); // Humidity
$humidity = new ANN_InputValue(0, 100); // Humidity


$icecream = new ANN_OutputValue(0, 300); // Ice-Cream
$icecream = new ANN_OutputValue(0, 300); // Ice-Cream


$inputs = array(
$inputs = array(

Revision as of 12:48, 21 December 2007

Training

require_once 'ANN/ANN_Network.php';

try
{
  $network = ANN_Network::loadFromFile('icecreams.dat');
}
catch(Exception $e)
{
  print "Creating a new one...";
	
  $network = new ANN_Network(2,8,1);
}

$temperature = new ANN_InputValue(-15, 50); // Temperature

$humidity    = new ANN_InputValue(0, 100);  // Humidity

$icecream    = new ANN_OutputValue(0, 300); // Ice-Cream

$inputs = array(
	array($temperature->GetInputValue(20), $humidity->GetInputValue(10)),
	array($temperature->GetInputValue(30), $humidity->GetInputValue(40)),
	array($temperature->GetInputValue(32), $humidity->GetInputValue(30)),
	array($temperature->GetInputValue(33), $humidity->GetInputValue(20))
);

$outputs = array(
	array($icecream->GetOutputValue(20)),
	array($icecream->GetOutputValue(90)),
	array($icecream->GetOutputValue(70)),
	array($icecream->GetOutputValue(75))
);

$network->setInputs($inputs);

$network->setOutputs($outputs);

$network->train();

$network->saveToFile('icecreams.dat');