Selling Icecreams: Difference between revisions
From Artificial Neural Network for PHP
Line 20: | Line 20: | ||
$humidity = new ANN_InputValue(0, 100); // Humidity |
$humidity = new ANN_InputValue(0, 100); // Humidity |
||
$icecream = new ANN_OutputValue(0, 300); // Ice- |
$icecream = new ANN_OutputValue(0, 300); // Ice-Creams |
||
$inputs = array( |
$inputs = array( |
||
array($temperature-> |
array($temperature->getInputValue(20), $humidity->getInputValue(10)), |
||
array($temperature-> |
array($temperature->getInputValue(30), $humidity->getInputValue(40)), |
||
array($temperature-> |
array($temperature->getInputValue(32), $humidity->getInputValue(30)), |
||
array($temperature-> |
array($temperature->getInputValue(33), $humidity->getInputValue(20)) |
||
); |
); |
||
$outputs = array( |
$outputs = array( |
||
array($icecream-> |
array($icecream->getOutputValue(20)), |
||
array($icecream-> |
array($icecream->getOutputValue(90)), |
||
array($icecream-> |
array($icecream->getOutputValue(70)), |
||
array($icecream-> |
array($icecream->getOutputValue(75)) |
||
); |
); |
||
Revision as of 09:24, 31 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-Creams
$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');