Difference between revisions of "Logging network weights"
From Artificial Neural Network for PHP
(6 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
<source lang="php"> |
<source lang="php"> |
||
− | require_once 'ANN/ |
+ | require_once 'ANN/Loader.php'; |
+ | |||
+ | use ANN\Network; |
||
+ | use ANN\Values; |
||
try |
try |
||
{ |
{ |
||
− | $ |
+ | $objNetwork = Network::loadFromFile('xor.dat'); |
} |
} |
||
catch(Exception $e) |
catch(Exception $e) |
||
Line 12: | Line 15: | ||
print 'Creating a new one...'; |
print 'Creating a new one...'; |
||
− | $ |
+ | $objNetwork = new Network; |
⚫ | |||
+ | $objValues = new Values; |
||
− | $inputs = array( |
||
− | array(0, 0), |
||
− | array(0, 1), |
||
− | array(1, 0), |
||
− | array(1, 1) |
||
− | ); |
||
+ | $objValues->train() |
||
− | $outputs = 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'); |
||
− | $network->setInputs($inputs); |
||
+ | |||
+ | unset($objValues); |
||
⚫ | |||
+ | |||
+ | try |
||
+ | { |
||
+ | $objValues = 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 |
||
− | $network->setOutputs($outputs); |
||
− | $ |
+ | $objNetwork->logWeightsToFile('network.csv'); // Start logging |
− | $ |
+ | $objNetwork->train(); |
− | $ |
+ | $objNetwork->saveToFile('xor.dat'); |
</source> |
</source> |
Latest revision as of 14:13, 1 June 2011
Logging network weights while training
require_once 'ANN/Loader.php';
use ANN\Network;
use ANN\Values;
try
{
$objNetwork = Network::loadFromFile('xor.dat');
}
catch(Exception $e)
{
print 'Creating a new one...';
$objNetwork = new Network;
$objValues = new 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 = 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');