view release on metacpan or search on metacpan
_Inline/build/AI/ANN/Neuron_6185/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'AI::ANN::Neuron_6185',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/t',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/_Inline/build/benchmark_pl_03a5/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'benchmark_pl_03a5',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/examples',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/_Inline/build/benchmark_pl_3d06/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'benchmark_pl_3d06',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/examples',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/_Inline/build/benchmark_pl_6dc1/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'benchmark_pl_6dc1',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/examples',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/_Inline/build/benchmark_pl_ac1b/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'benchmark_pl_ac1b',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/examples',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/_Inline/build/benchmark_pl_b832/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'benchmark_pl_b832',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/examples',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/_Inline/build/benchmark_pl_b905/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'benchmark_pl_b905',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/examples',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/_Inline/build/benchmark_pl_c51b/Makefile.PL view on Meta::CPAN
'/usr/share/perl/5.10/ExtUtils/typemap'
],
'NAME' => 'benchmark_pl_c51b',
'INC' => '-I/home/st47/sit-bmelab-labview/EANN/ANN/examples',
'VERSION' => '0.00'
}
};
WriteMakefile(%options);
# Remove the Makefile dependency. Causes problems on a few systems.
sub MY::makefile { '' }
examples/benchmark.pl view on Meta::CPAN
double afunc_c (float input) {
return afunc[(int) floor((input)*1000)+2000];
}
double dafunc_c (float input) {
return dafunc[(int) floor((input)*1000)+2000];
}
END_C
timethis(-1, 'generate_globals()');
sub afunc_pp {
return 2 * erf(int((shift)*1000)/1000);
}
sub dafunc_pp {
return 4 / sqrt(M_PI) * exp( -1 * ((int((shift)*1000)/1000) ** 2) );
}
cmpthese( -1, { 'afunc_c' => sub{afunc_c(4*rand()-2)},
'afunc_pp' => sub{afunc_pp(4*rand()-2)} });
cmpthese( -1, { 'dafunc_c' => sub{dafunc_c(4*rand()-2)},
'dafunc_pp' => sub{dafunc_pp(4*rand()-2)} });
lib/AI/ANN.pm view on Meta::CPAN
has 'input_count' => (is => 'ro', isa => 'Int', required => 1);
has 'outputneurons' => (is => 'ro', isa => 'ArrayRef[Int]', required => 1);
has 'network' => (is => 'ro', isa => 'ArrayRef[HashRef]', required => 1);
# network is an arrayref of hashrefs. Each hashref is:
# object => AI::ANN::Neuron
# and has several other elements
has 'inputs' => (is => 'ro', isa => 'ArrayRef[Int]');
has 'rawpotentials' => (is => 'ro', isa => 'ArrayRef[Int]');
has 'minvalue' => (is => 'rw', isa => 'Int', default => 0);
has 'maxvalue' => (is => 'rw', isa => 'Int', default => 1);
has 'afunc' => (is => 'rw', isa => 'CodeRef', default => sub {sub {shift}});
has 'dafunc' => (is => 'rw', isa => 'CodeRef', default => sub {sub {1}});
has 'backprop_eta' => (is => 'rw', isa => 'Num', default => 0.1);
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
my %data;
if ( @_ == 1 && ref $_[0] eq 'HASH' ) {
%data = %{$_[0]};
} else {
%data = @_;
}
if (exists $data{'inputs'} && not exists $data{'input_count'}) {
$data{'input_count'} = $data{'inputs'};
lib/AI/ANN.pm view on Meta::CPAN
$neuronlist->[$i]->{'eta_neurons'}
if defined $neuronlist->[$i]->{'eta_neurons'};
$data{'network'}->[$i]->{'object'} =
new AI::ANN::Neuron( @pass );
}
delete $data{'data'};
return $class->$orig(%data);
};
sub execute {
my $self = shift;
my $inputs = $self->{'inputs'} = shift;
# Don't bother dereferencing $inputs only to rereference a lot
my $net = $self->{'network'}; # For less typing
my $lastneuron = $#{$net};
my @neurons = ();
foreach my $i (0..$lastneuron) {
$neurons[$i] = 0;
}
foreach my $i (0..$lastneuron) {
lib/AI/ANN.pm view on Meta::CPAN
}
}
# Ok, hopefully all the neurons have happy values by now.
# Get the output values for neurons corresponding to outputneurons
my @output = map {$neurons[$_]} @{$self->{'outputneurons'}};
return \@output;
}
sub get_state {
my $self = shift;
my $net = $self->{'network'}; # For less typing
my @neurons = map {$net->[$_]->{'state'}} 0..$#{$self->{'network'}};
my @output = map {$net->[$_]->{'state'}} @{$self->{'outputneurons'}};
return $self->{'inputs'}, \@neurons, \@output;
}
sub get_internals {
my $self = shift;
my $net = $self->{'network'}; # For less typing
my $retval = [];
for (my $i = 0; $i <= $#{$self->{'network'}}; $i++) {
$retval->[$i] = { iamanoutput => 0,
inputs => $net->[$i]->{'object'}->inputs(),
neurons => $net->[$i]->{'object'}->neurons(),
eta_inputs => $net->[$i]->{'object'}->eta_inputs(),
eta_neurons => $net->[$i]->{'object'}->eta_neurons()
};
}
foreach my $i (@{$self->{'outputneurons'}}) {
$retval->[$i]->{'iamanoutput'} = 1;
}
return dclone($retval); # Dclone for safety.
}
sub readable {
my $self = shift;
my $retval = "This network has ". $self->{'inputcount'} ." inputs and ".
scalar(@{$self->{'network'}}) ." neurons.\n";
for (my $i = 0; $i <= $#{$self->{'network'}}; $i++) {
$retval .= "Neuron $i\n";
while (my ($k, $v) = each %{$self->{'network'}->[$i]->{'object'}->inputs()}) {
$retval .= "\tInput from input $k, weight is $v\n";
}
while (my ($k, $v) = each %{$self->{'network'}->[$i]->{'object'}->neurons()}) {
$retval .= "\tInput from neuron $k, weight is $v\n";
}
if (map {$_ == $i} $self->{'outputneurons'}) {
$retval .= "\tThis neuron is a network output\n";
}
}
return $retval;
}
sub backprop {
my $self = shift;
my $inputs = shift;
my $desired = shift;
my $actual = $self->execute($inputs);
my $net = $self->{'network'};
my $lastneuron = $#{$net};
my $deltas = [];
my $i = 0;
foreach my $neuron (@{$self->outputneurons()}) {
$deltas->[$neuron] = $desired->[$i] - $actual->[$i];
lib/AI/ANN/Evolver.pm view on Meta::CPAN
has 'max_value' => (is => 'rw', isa => 'Num', default => 1);
has 'min_value' => (is => 'rw', isa => 'Num', default => 0);
has 'mutation_chance' => (is => 'rw', isa => 'Num', default => 0);
has 'mutation_amount' => (is => 'rw', isa => 'CodeRef', default => sub{sub{2 * rand() - 1}});
has 'add_link_chance' => (is => 'rw', isa => 'Num', default => 0);
has 'kill_link_chance' => (is => 'rw', isa => 'Num', default => 0);
has 'sub_crossover_chance' => (is => 'rw', isa => 'Num', default => 0);
has 'gaussian_tau' => (is => 'rw', isa => 'CodeRef', default => sub{sub{1/sqrt(2*sqrt(shift))}});
has 'gaussian_tau_prime' => (is => 'rw', isa => 'CodeRef', default => sub{sub{1/sqrt(2*shift)}});
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
my %data;
if ( @_ == 1 && ref $_[0] eq 'HASH' ) {
%data = %{$_[0]};
} else {
%data = @_;
}
if ((not (ref $data{'mutation_amount'})) || ref $data{'mutation_amount'} ne 'CODE') {
my $range = $data{'mutation_amount'};
$data{'mutation_amount'} = sub { $range * (rand() * 2 - 1) };
}
return $class->$orig(%data);
};
sub crossover {
my $self = shift;
my $network1 = shift;
my $network2 = shift;
my $class = ref($network1);
my $inputcount = $network1->input_count();
my $minvalue = $network1->minvalue();
my $maxvalue = $network1->maxvalue();
my $afunc = $network1->afunc();
my $dafunc = $network1->dafunc();
# They better have the same number of inputs
lib/AI/ANN/Evolver.pm view on Meta::CPAN
my $network3 = $class->new ( 'inputs' => $inputcount,
'data' => $networkdata3,
'minvalue' => $minvalue,
'maxvalue' => $maxvalue,
'afunc' => $afunc,
'dafunc' => $dafunc);
return $network3;
}
sub mutate {
my $self = shift;
my $network = shift;
my $class = ref($network);
my $networkdata = $network->get_internals();
my $inputcount = $network->input_count();
my $minvalue = $network->minvalue();
my $maxvalue = $network->maxvalue();
my $afunc = $network->afunc();
my $dafunc = $network->dafunc();
my $neuroncount = $#{$networkdata}; # BTW did you notice that this
lib/AI/ANN/Evolver.pm view on Meta::CPAN
$network = $class->new ( 'inputs' => $inputcount,
'data' => $networkdata,
'minvalue' => $minvalue,
'maxvalue' => $maxvalue,
'afunc' => $afunc,
'dafunc' => $dafunc);
return $network;
}
sub mutate_gaussian {
my $self = shift;
my $network = shift;
my $class = ref($network);
my $networkdata = $network->get_internals();
my $inputcount = $network->input_count();
my $minvalue = $network->minvalue();
my $maxvalue = $network->maxvalue();
my $afunc = $network->afunc();
my $dafunc = $network->dafunc();
my $neuroncount = $#{$networkdata}; # BTW did you notice that this
lib/AI/ANN/Neuron.pm view on Meta::CPAN
END_C
has 'id' => (is => 'rw', isa => 'Int');
has 'inputs' => (is => 'rw', isa => 'ArrayRef', required => 1);
has 'neurons' => (is => 'rw', isa => 'ArrayRef', required => 1);
has 'eta_inputs' => (is => 'rw', isa => 'ArrayRef');
has 'eta_neurons' => (is => 'rw', isa => 'ArrayRef');
has 'inline_c' => (is => 'ro', isa => 'Int', required => 1, default => 1);
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
my %data;
if ( @_ >= 2 && ref $_[0] && ref $_[1]) {
%data = ('inputs' => $_[0], 'neurons' => $_[1]);
$data{'eta_inputs'} = $_[2] if defined $_[2];
$data{'eta_neurons'} = $_[3] if defined $_[3];
} elsif ( @_ >= 3 && ref $_[1] && ref $_[2]) {
%data = ('id' => $_[0], 'inputs' => $_[1], 'neurons' => $_[2]);
$data{'eta_inputs'} = $_[3] if defined $_[3];
lib/AI/ANN/Neuron.pm view on Meta::CPAN
foreach my $i (0..$#{$data{'eta_inputs'}}) {
$data{'eta_inputs'}->[$i] ||= 0;
}
foreach my $i (0..$#{$data{'eta_neurons'}}) {
$data{'eta_neurons'}->[$i] ||= 0;
}
return $class->$orig(%data);
};
sub ready {
my $self = shift;
my $inputs = shift;
my $neurons = shift;
if (ref $neurons eq 'HASH') {
my @temparray;
foreach my $i (keys %$neurons) {
if (defined $neurons->{$i} && $neurons->{$i} != 0) {
$temparray[$i]=$neurons->{$i};
}
}
lib/AI/ANN/Neuron.pm view on Meta::CPAN
}
foreach my $id (0..$#{$self->{'neurons'}}) {
unless ((not defined $self->{'neurons'}->[$id]) ||
$self->{'neurons'}->[$id] == 0 || defined $neurons[$id])
{return 0}
}
return 1;
}
sub execute {
my $self = shift;
my $inputs = shift;
my $neurons = shift;
if (ref $neurons eq 'HASH') {
my @temparray;
foreach my $i (keys %$neurons) {
$temparray[$i]=$neurons->{$i} || 0;
}
$neurons=\@temparray;
}