Difference between revisions of "Logging network weights"
From Artificial Neural Network for PHP
Line 15: | Line 15: | ||
$objNetwork = new ANN_Network; |
$objNetwork = new ANN_Network; |
||
⚫ | |||
+ | $objValues = new ANN_Values; |
||
− | $arrInputs = array( |
||
− | array(0, 0), |
||
− | array(0, 1), |
||
− | array(1, 0), |
||
− | array(1, 1) |
||
− | ); |
||
+ | $objValues->train() |
||
− | $arrOutputs = array( |
||
+ | ->input(0,0)->output(0) |
||
− | array(0), |
||
+ | ->input(0,1)->output(1) |
||
− | array(1), |
||
+ | ->input(1,0)->output(1) |
||
− | array(1), |
||
+ | ->input(1,1)->output(0); |
||
− | array(0) |
||
− | ); |
||
+ | $objValues->saveToFile('values_xor.dat'); |
||
− | $objNetwork->setInputs($arrInputs); |
||
+ | |||
+ | unset($objValues); |
||
⚫ | |||
+ | |||
+ | try |
||
+ | { |
||
+ | $objValues = ANN_Values::loadFromFile('values_xor.dat'); |
||
+ | } |
||
+ | catch(Exception $e) |
||
+ | { |
||
+ | die('Loading of values failed'); |
||
+ | } |
||
− | $objNetwork-> |
+ | $objNetwork->setValues($objValues); // to be called as of version 2.0.6 |
$objNetwork->logWeightsToFile('network.csv'); // Start logging |
$objNetwork->logWeightsToFile('network.csv'); // Start logging |
Revision as of 08:41, 19 December 2008
Logging network weights while training
THIS EXAMPLE IS NOT UP TO DATE. PLEASE HAVE A LOOK TO XOR EXAMPLE!!!
require_once 'ANN/ANN_Loader.php';
try
{
$objNetwork = ANN_Network::loadFromFile('xor.dat');
}
catch(Exception $e)
{
print 'Creating a new one...';
$objNetwork = new ANN_Network;
$objValues = new ANN_Values;
$objValues->train()
->input(0,0)->output(0)
->input(0,1)->output(1)
->input(1,0)->output(1)
->input(1,1)->output(0);
$objValues->saveToFile('values_xor.dat');
unset($objValues);
}
try
{
$objValues = ANN_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
$objNetwork->logWeightsToFile('network.csv'); // Start logging
$objNetwork->train();
$objNetwork->saveToFile('xor.dat');