AI-NNFlex
view release on metacpan or search on metacpan
lib/AI/NNFlex.pm view on Meta::CPAN
#
# 0.21 20050316 CColbourn Rewrote perldocs, implemented fahlman
# constant, chopped out old legacy stuff
# put math functions in mathlib, etc etc
#
# 0.22 20050317 CColbourn Implemented ::connect method
#
# 0.23 20050424 CColbourn Included Hopfield module in dist.
#
# 0.24 20050620 CColbourn Corrected a bug in the bias weight
# calculation
#
#
###############################################################################
# ToDo
# ====
#
# Modify init to allow recurrent layer/node connections
# write cmd & gui frontends
# Speed the bugger up!
#
# Odd thought - careful coding of a network would allow grafting of
# two different network types or learning algorithms, like an effectve
# single network with 2 layers unsupervised and 2 layers supervised
#
# Clean up the perldocs
#
###############################################################################
$VERSION = "0.24";
###############################################################################
my @DEBUG; # a single, solitary, shameful global variable. Couldn't
#avoid it really. It allows correct control of debug
#information before the $network object is created
# (in ::layer->new & ::node->new for example).
###############################################################################
###############################################################################
# package NNFlex
###############################################################################
###############################################################################
package AI::NNFlex;
use AI::NNFlex::Mathlib;
use base qw(AI::NNFlex::Mathlib);
###############################################################################
# AI::NNFlex::new
###############################################################################
sub new
{
my $class = shift;
my $network={};
bless $network,$class;
# intercept the new style 'empty network' constructor call
# Maybe I should deprecate the old one, but its convenient, provided you
# can follow the mess of hashes
if (!grep /HASH/,@_)
{
my %config = @_;
foreach (keys %config)
{
$network->{$_} = $config{$_};
}
return $network;
}
# Otherwise, continue assuming that the whole network is defined in
# a pair of anonymous hashes
my $params = shift;
my $netParams = shift;
my @layers;
dbug ($netParams,"Entered AI::NNFlex::new with params $params $netParams",2);
# clean up case & spaces in layer defs from pre 0.14 constructor calls:
my $cleanParams;
foreach my $layer(@{$params})
{
my %cleanLayer;
foreach (keys %$layer)
{
my $key = lc($_);
$key =~ s/\s//g;
$cleanLayer{$key} = $$layer{$_};
}
push @$cleanParams,\%cleanLayer;
}
# Network wide parameters (e.g. random weights)
foreach (keys %$netParams)
{
my $key = lc($_);
$key =~ s/\s//g; # up to 0.14 we had params with spaces in, now deprecated
$network->{$key} = ${$netParams}{$_};
}
if( $network->{'debug'})
{
@DEBUG = @{$network->{'debug'}};
}
# build the network
foreach (@$cleanParams)
{
if (!($$_{'nodes'})){next}
my %layer = %{$_};
push @layers,AI::NNFlex::layer->new(\%layer);
( run in 0.976 second using v1.01-cache-2.11-cpan-524268b4103 )