Difference between revisions of "FAQ"

(What are the dat-files?)
(What are the dat-files?)
Line 1: Line 1:
 
== What are the dat-files? ==
 
== What are the dat-files? ==
   
A dat-file is an auto-generated file. Its contents is a serialized structure of the saved object. It will be generated while training the neural network by using '''ANN_InputValue::saveToFile()''' or '''ANN_Network::saveToFile()''' and can be reloaded into the running network by '''ANN_InputValue::loadFromFile()''' or '''ANN_InputValue::loadFromFile()'''.
+
A dat-file is an auto-generated file. Its contents is a serialized structure of the saved object. It will be generated while training the neural network by using '''\ANN\InputValue::saveToFile()''' or '''\ANN\Network::saveToFile()''' and can be reloaded into the running network by '''\ANN\InputValue::loadFromFile()''' or '''\ANN\InputValue::loadFromFile()'''.
   
 
The dat-files are not included to the example code downloads because they are auto-generated.
 
The dat-files are not included to the example code downloads because they are auto-generated.
Line 37: Line 37:
 
<source lang="php">
 
<source lang="php">
 
require_once 'ANN/Loader.php';
 
require_once 'ANN/Loader.php';
  +
  +
use ANN\Network;
  +
use ANN\Values;
   
 
try
 
try
 
{
 
{
$objNetwork = ANN_Network::loadFromFile('dats/xor.dat');
+
$objNetwork = Network::loadFromFile('dats/xor.dat');
 
}
 
}
 
catch(Exception $e)
 
catch(Exception $e)
Line 46: Line 49:
 
print 'Creating a new one...';
 
print 'Creating a new one...';
 
 
$objNetwork = new ANN_Network;
+
$objNetwork = new Network;
   
$objValues = new ANN_Values;
+
$objValues = new Values;
   
 
$objValues->train()
 
$objValues->train()
Line 63: Line 66:
 
try
 
try
 
{
 
{
$objValues = ANN_Values::loadFromFile('dats/values_xor.dat');
+
$objValues = Values::loadFromFile('dats/values_xor.dat');
 
}
 
}
 
catch(Exception $e)
 
catch(Exception $e)

Revision as of 14:24, 1 June 2011

What are the dat-files?

A dat-file is an auto-generated file. Its contents is a serialized structure of the saved object. It will be generated while training the neural network by using \ANN\InputValue::saveToFile() or \ANN\Network::saveToFile() and can be reloaded into the running network by \ANN\InputValue::loadFromFile() or \ANN\InputValue::loadFromFile().

The dat-files are not included to the example code downloads because they are auto-generated.

To save the dat-files the directory you are saving the files should have write permission to the PHP process running.

For example if your PHP script is running as a PHP module by Apache and the Apache is running as user www-data, so you can use the following code to set the permissions.

Change to the directory where your own ANN script is stored.

>cd <PROJECTDIR-OF-YOUR-ANN>

Create a subdirectory for all your dat-files.

>mkdir dats

Change the group owner of this subdirectory to www-data.

>chgrp www-data dats

Change the UNIX permissions to the group for write access to this subdirectory.

>chmod g+w dats

Due to security remove all others permissions in this case.

>chmod o-rwx dats

List your permissions.

>ls -la dats
drwxrwx---  7  user  www-data  4.0K  2009-10-28  08:52  dats

Use this subdirectory in your PHP scripts:

require_once 'ANN/Loader.php';

use ANN\Network;
use ANN\Values;

try
{
  $objNetwork = Network::loadFromFile('dats/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('dats/values_xor.dat');
  
  unset($objValues);
}

try
{
  $objValues = Values::loadFromFile('dats/values_xor.dat');
}
catch(Exception $e)
{
  die('Loading of values failed');
}

$objNetwork->setValues($objValues); // to be called as of version 2.0.6

$boolTrained = $objNetwork->train();

print ($boolTrained)
        ? 'Network trained'
        : 'Network not trained completely. Please re-run the script';

$objNetwork->saveToFile('dats/xor.dat');

$objNetwork->printNetwork();