AI-LibNeural
view release on metacpan or search on metacpan
LibNeural.pm view on Meta::CPAN
use strict;
use warnings;
use Carp;
require Exporter;
require DynaLoader;
use AutoLoader;
our @ISA = qw(Exporter DynaLoader);
# This allows declaration use AI::LibNeural ':all';
our %EXPORT_TAGS = ( 'all' => [ qw(
ALL
HIDDEN
INPUT
OUTPUT
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw(
);
our $VERSION = '0.02';
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function. If a constant is not found then control is passed
# to the AUTOLOAD in AutoLoader.
my $constname;
our $AUTOLOAD;
($constname = $AUTOLOAD) =~ s/.*:://;
croak "& not defined" if $constname eq 'constant';
my $val = constant($constname, @_ ? $_[0] : 0);
if ($! != 0) {
if ($! =~ /Invalid/ || $!{EINVAL}) {
$AutoLoader::AUTOLOAD = $AUTOLOAD;
goto &AutoLoader::AUTOLOAD;
}
else {
croak "Your vendor has not defined AI::LibNeural macro $constname";
}
}
{
no strict 'refs';
# Fixed between 5.005_53 and 5.005_61
# if ($] >= 5.00561) {
# *$AUTOLOAD = sub () { $val };
# }
# else {
*$AUTOLOAD = sub { $val };
# }
}
goto &$AUTOLOAD;
}
bootstrap AI::LibNeural $VERSION;
# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
=head1 NAME
AI::LibNeural - Perl extension libneural
=head1 SYNOPSIS
use AI::LibNeural;
my $nn = AI::LibNeural->new( 2, 4, 1 );
# teach it the logical AND
$nn->train( [ 0, 0 ], [ 0.05 ], 0.0000000005, 0.2 );
$nn->train( [ 0, 1 ], [ 0.05 ], 0.0000000005, 0.2 );
$nn->train( [ 1, 0 ], [ 0.05 ], 0.0000000005, 0.2 );
$nn->train( [ 1, 1 ], [ 0.95 ], 0.0000000005, 0.2 );
my $result = $nn->run( [ 1, 1 ] );
# result should be ~ 0.95
$result = $nn->run( [ 0, 1 ] );
# result should be ~ 0.05
$nn->save('and.mem');
=head1 ABSTRACT
Perl bindings for the libneural c++ neural netowrk library.
=head1 DESCRIPTION
Provides accessors for the libneural library as a perl object. libneural is a
C++ library that impelements a feed-forward back-proprogation neural network.
The interface is extremely simple and should take no more than a few minutes to
master given a reasonable knowledge of back proprogation neural networks.
=head2 FUNCTIONS
=over
=item $nn = AI:LibNeural->new()
Creates an empty AI::LibNeural object, should only be used when the load method
will be called soon after.
=item $nn = AI::LibNeural->new(FILENAME)
Creates a new AI::LibNeural object from the supplied memory file.
=item $nn = AI::LibNeural->new(INTPUTS,HIDDENS,OUTPUTS)
Creates a new AI::LibNeural object with INPUTS input nodes, HIDDENS hidden
nodes, and OUTPUTS output nodes.
=item $nn->train([I1,I2,...],[O1,O2,...],MINERR,TRAINRATE)
Completes a training cycle for the given inputs I1-IN, with the expected
results of O1-OM, where N is the number of inputs and M is the number of
( run in 0.559 second using v1.01-cache-2.11-cpan-39bf76dae61 )