AI-ANN
view release on metacpan or search on metacpan
lib/AI/ANN/Neuron.pm view on Meta::CPAN
# }
# }
# if ($#neurons < $#neuronweights) {
# foreach my $i ($#neurons+1..$#neuronweights) {
# $neurons[$i]=0;
# }
# }
#print STDERR $self->{'id'}."\n";
#print STDERR join(',', @inputs)."\n";
#print STDERR join(',', @neurons)."\n";
#print STDERR join(',', @inputweights)."\n";
#print STDERR join(',', @neuronweights)."\n";
my $output = 0;
if ($self->{'inline_c'}) {
$output = _execute_internals( \@inputs, \@neurons, \@inputweights, \@neuronweights );
} else {
foreach my $id (0..$#inputweights) {
$output += ($inputweights[$id] || 0 ) * ($inputs[$id] || 0);
}
foreach my $id (0..$#neuronweights) {
$output += ($neuronweights[$id] || 0) * ($neurons[$id] || 0);
}
}
return $output;
}
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=head1 NAME
AI::ANN::Neuron - a neuron for an artificial neural network simulator
=head1 VERSION
version 0.008
=head1 METHODS
=head2 new
AI::ANN::Neuron->new( $neuronid, {$inputid => $weight, ...}, {$neuronid => $weight} )
Weights may be whatever the user chooses. Note that packages that use this
one may place their own restructions. Neurons and inputs are assumed to be
zero-indexed.
eta_inputs and eta_neurons are optional, required only if you wish to use the
Gaussian mutation in AI::ANN::Evolver.
=head2 ready
$neuron->ready( [$input0, $input1, ...], [$neuronvalue0, ...] )
All inputs must be provided or you're insane.
If a neuron is not yet available, make it undef, not zero.
Returns 1 if ready, 0 otherwise.
=head2 execute
$neuron->execute( [$input0, $input1, ...], {$neuronid => $neuronvalue, ...} )
You /must/ pass the correct number of inputs and neurons, and undefined values
/must/ be zeros, not undef.
Returns raw value (linear potential)
=head1 AUTHOR
Dan Collins <DCOLLINS@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 by Dan Collins.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
=cut
( run in 1.911 second using v1.01-cache-2.11-cpan-d80b1682f3f )