AI-FANN-Evolving
view release on metacpan
or search on metacpan
LICENSE
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | The MIT License (MIT)
Copyright (c) 2014 Naturalis Biodiversity Center
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software" ), to deal in
the Software without restriction, including without limitation the rights to
use , copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS" , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
META.json
view on Meta::CPAN
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | },
"name" : "AI-FANN-Evolving" ,
"no_index" : {
"directory" : [
"t" ,
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"AI::FANN" : "0" ,
"Algorithm::Genetic::Diploid" : "0"
}
}
},
"release_status" : "stable" ,
"version" : "0.4"
}
|
META.yml
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ---
abstract: 'artificial neural network that evolves'
author:
- 'Rutger Vos <rutger.vos@naturalis.nl>'
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.132830'
license: unknown
meta-spec:
version: 1.4
name: AI-FANN-Evolving
no_index:
directory:
- t
- inc
requires:
AI::FANN: 0
Algorithm::Genetic::Diploid: 0
version: 0.4
|
MYMETA.json
view on Meta::CPAN
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | },
"name" : "AI-FANN-Evolving" ,
"no_index" : {
"directory" : [
"t" ,
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"AI::FANN" : "0" ,
"Algorithm::Genetic::Diploid" : "0"
}
}
},
"release_status" : "stable" ,
"version" : "0.4"
}
|
MYMETA.yml
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ---
abstract: 'artificial neural network that evolves'
author:
- 'Rutger Vos <rutger.vos@naturalis.nl>'
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 0
generated_by: 'ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.132830'
license: unknown
meta-spec:
version: 1.4
name: AI-FANN-Evolving
no_index:
directory:
- t
- inc
requires:
AI::FANN: 0
Algorithm::Genetic::Diploid: 0
version: 0.4
|
lib/AI/FANN/Evolving.pm
view on Meta::CPAN
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | sub new {
my $class = shift ;
my %args = @_ ;
my $self = {};
bless $self , $class ;
$self ->_init( %args );
|
lib/AI/FANN/Evolving.pm
view on Meta::CPAN
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | sub error {
my $self = shift ;
if ( @_ ) {
my $value = shift ;
$log ->debug( "setting error threshold to $value" );
return $self ->{ 'error' } = $value ;
}
else {
$log ->debug( "getting error threshold" );
return $self ->{ 'error' };
}
}
|
lib/AI/FANN/Evolving.pm
view on Meta::CPAN
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | return $self ->{ 'epochs' } = $value ;
}
else {
$log ->debug( "getting training epochs" );
return $self ->{ 'epochs' };
}
}
sub epoch_printfreq {
my $self = shift ;
if ( @_ ) {
my $value = shift ;
$log ->debug( "setting epoch printfreq to $value" );
return $self ->{ 'epoch_printfreq' } = $value ;
}
|
lib/AI/FANN/Evolving.pm
view on Meta::CPAN
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | return $self ->{ 'neurons' } = $value ;
}
else {
$log ->debug( "getting neurons" );
return $self ->{ 'neurons' };
}
}
sub neuron_printfreq {
my $self = shift ;
if ( @_ ) {
my $value = shift ;
$log ->debug( "setting neuron printfreq to $value" );
return $self ->{ 'neuron_printfreq' } = $value ;
|
lib/AI/FANN/Evolving.pm
view on Meta::CPAN
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 | else {
$log ->debug( "getting activation function" );
return $self ->{ 'activation_function' };
}
}
sub AUTOLOAD {
my $self = shift ;
my $method = $AUTOLOAD ;
$method =~ s/.+://;
if ( $method !~ /^[A-Z]+$/ ) {
my $invocant ;
|
lib/AI/FANN/Evolving/Experiment.pm
view on Meta::CPAN
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
lib/AI/FANN/Evolving/Gene.pm
view on Meta::CPAN
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | }
else {
$log ->debug( "getting ANN" );
return $self ->{ 'ann' };
}
}
sub make_function {
my $self = shift ;
my $ann = $self ->ann;
my $error_func = $self ->experiment->error_func;
$log ->debug( "making fitness function" );
|
lib/AI/FANN/Evolving/Gene.pm
view on Meta::CPAN
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
$log ->debug( "Observed: " .Dumper( $observed ));
$log ->debug( "Expected: " .Dumper( $expected ));
$fitness += $error_func ->( $observed , $expected );
}
$fitness /= $env -> length ;
$self ->{ 'fitness' } = $fitness ;
my $outfile = $self ->experiment->workdir . "/${fitness}.ann" ;
$self ->ann->save( $outfile );
return $self ->{ 'fitness' };
}
}
sub fitness { shift ->{ 'fitness' } }
|
lib/AI/FANN/Evolving/TrainData.pm
view on Meta::CPAN
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | sub new {
my $self = shift ->SUPER::new(
'ignore' => [ 'ID' ],
'dependent' => [ 'CLASS' ],
'header' => {},
'table' => [],
|
lib/AI/FANN/Evolving/TrainData.pm
view on Meta::CPAN
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | my %seen ;
for my $dep ( @dependents ) {
my $key = join '/' , @{ $dep };
$seen { $key }++;
}
for my $key ( keys %seen ) {
$log ->debug( "counts: $key => $seen{$key}" );
$seen { $key } = int ( $seen { $key } * $sample );
$log ->debug( "rescaled: $key => $seen{$key}" );
}
my @dc = map { $self ->{ 'header' }->{ $_ } } $self ->dependent_columns;
my @new_table ;
my @table = @{ $clone1 ->{ 'table' } };
SAMPLE: while ( grep { !! $_ } values %seen ) {
for my $i ( 0 .. $#table ) {
|
script/aivolver
view on Meta::CPAN
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
t/01-run.t
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/usr/bin/perl
BEGIN {
use_ok( 'AI::FANN::Evolving::Factory' );
use_ok( 'AI::FANN::Evolving::TrainData' );
use_ok( 'AI::FANN::Evolving' );
use_ok( 'Algorithm::Genetic::Diploid::Logger' );
}
my $log = new_ok( 'Algorithm::Genetic::Diploid::Logger' );
$log ->level( 'level' => 4 );
|
t/03-fann-wrapper.t
view on Meta::CPAN
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ok( $data ->size == 4, "instantiate data correctly" );
my $ann = AI::FANN::Evolving->new( 'data' => $data , 'epoch_printfreq' => 0 );
$ann ->train( $data ->to_fann);
my @result = ( -1, +1, +1, -1 );
my @input = ( [ -1, -1 ], [ -1, +1 ], [ +1, -1 ], [ +1, +1 ] );
for my $i ( 0 .. $#input ) {
my $output = $ann ->run( $input [ $i ]);
ok( ! ( $result [ $i ] < 0 xor $output ->[0] < 0 ), "observed and expected signs match" );
}
|