AI-NeuralNet-BackProp
view release on metacpan or search on metacpan
examples/ex_add2.pl view on Meta::CPAN
=begin
File: examples/ex_add2.pl
Author: Rodin Porrata, <rodin@ursa.llnl.gov>
Desc:
This script runs a complete test of the networks ability to add and remember
data sets, as well as testing the optimum "inc" to learn and the optimum
number of layers for a network.
=cut
use AI::NeuralNet::BackProp;
use Benchmark;
use English;
my $ofile = "addnet_data.txt";
open( OUTFP, ">$ofile" ) or die "Could not open output file\n";
my ( $layers, $inputs, $outputs, $top, $inc, $top, $runtime,
$forgetfulness );
my @answers;
my @predictions;
my @percent_diff;
$inputs = 3;
$outputs = 1;
my ($maxinc,$maxtop,$incstep);
select OUTFP; $OUTPUT_AUTOFLUSH = 1; select STDOUT;
print OUTFP "layers inc top forgetfulness time \%diff1 \%diff2 \%diff3
\%diff4\n\n";
for( $layers = 1; $layers <= 3; $layers++ ){
if( $layers <= 2 ){
$incstep = 0.025;
}
else{
$incstep = 0.05;
}
for( $inc=0.025; $inc <= 0.4; $inc += $incstep ){
if( $inc > .3 ){
$maxtop = 3;
}
else{
$maxtop = 4;
}
for( $top=1; $top <=$maxtop; $top++ ){
addnet();
printf OUTFP "%d %.3f %d %g %s %f %f %f %f\n",
$layers, $inc, $top, $forgetfulness, timestr($runtime),
$percent_diff[0],
$percent_diff[1], $percent_diff[2], $percent_diff[3];
print "layers inc top forgetfulness time \%diff1 \%diff2 \%diff3
\%diff4\n";
printf "%d %.3f %d %g %s %f %f %f %f\n",
$layers, $inc, $top, $forgetfulness, timestr($runtime),
$percent_diff[0],
$percent_diff[1], $percent_diff[2], $percent_diff[3];
}
}
}
#....................................................
sub addnet
{
print "\nCreate a new net with $layers layers, 3 inputs, and 1 output\n";
my $net = AI::NeuralNet::BackProp->new($layers,3,1);
# Disable debugging
$net->debug(0);
my @data = (
[ 2633, 2665, 2685], [ 2633 + 2665 + 2685 ],
[ 2623, 2645, 2585], [ 2623 + 2645 + 2585 ],
[ 2627, 2633, 2579], [ 2627 + 2633 + 2579 ],
[ 2611, 2627, 2563], [ 2611 + 2627 + 2563 ],
[ 2640, 2637, 2592], [ 2640 + 2637 + 2592 ]
);
print "Learning started, will cycle $top times with inc = $inc\n";
# Make it learn the whole dataset $top times
my @list;
my $t1=new Benchmark;
for my $a (1..$top)
{
print "Outer Loop: $a : ";
( run in 0.701 second using v1.01-cache-2.11-cpan-39bf76dae61 )