AI-NNFlex
view release on metacpan or search on metacpan
lib/AI/NNFlex/Backprop.pm view on Meta::CPAN
##########################################################
# AI::NNFlex::Backprop
##########################################################
# Backprop with simple (non adaptive) momentum
##########################################################
# Versions
# ========
#
# 1.0 20050121 CColbourn New module
# 1.1 20050201 CColbourn Added call to activation
# function slope instead
# of hardcoded 1-y*y
#
# 1.2 20050218 CColbourn Mod'd to change weight
# indexing to array for
# nnflex 0.16
#
# 1.3 20050307 CColbourn packaged as a subclass of NNFLex
#
# 1.4 20050313 CColbourn modified the slope function call
# to avoid using eval
#
# 1.5 20050314 CColbourn applied fahlman constant
# Renamed Backprop.pm, see CHANGES
#
##########################################################
# ToDo
# ----
#
#
###########################################################
#
package AI::NNFlex::Backprop;
use AI::NNFlex;
use AI::NNFlex::Feedforward;
use base qw(AI::NNFlex::Feedforward AI::NNFlex);
use strict;
sub calc_error
{
my $network = shift;
my $outputPatternRef = shift;
my @outputPattern = @$outputPatternRef;
my @debug = @{$network->{'debug'}};
if (scalar @debug > 0)
{$network->dbug ("Output pattern @outputPattern received by Backprop",4);}
my $outputLayer = $network->{'layers'}->[-1]->{'nodes'};
if (scalar @$outputLayer != scalar @outputPattern)
{
$network->dbug ("Wrong number of output values, net has ".scalar @$outputLayer." nodes",0);
return 0;
}
# Now calculate the error
my $counter=0;
foreach (@$outputLayer)
{
my $value = $_->{'activation'} - $outputPattern[$counter];
if ($_->{'errorfunction'})
{
my $errorfunction = $_->{'errorfunction'};
$value = $network->$errorfunction($value);
}
( run in 0.524 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )