AI-FANN

 view release on metacpan or  search on metacpan

lib/AI/FANN.pm  view on Meta::CPAN


  $out = $ann->run([1, 0.6]);
  print "@$out\n";

=item $ann->randomize_weights($min_weight, $max_weight)

=item $ann->train($input, $desired_output)

C<$input> and C<$desired_output> are arrays.

=item $ann->test($input, $desired_output)

C<$input> and C<$desired_output> are arrays.

It returns an array with the values of the output layer.

=item $ann->reset_MSE

-

=item $ann->train_on_file($filename, $max_epochs, $epochs_between_reports, $desired_error)

lib/AI/FANN.pm  view on Meta::CPAN

-

=back

=head1 INSTALLATION

See the README file for instruction on installing this module.

=head1 BUGS

Only tested on Linux.

I/O is not performed through PerlIO because the C library doesn't have
the required infrastructure to do that.

Send bug reports to my email address or use the CPAN RT system.

=head1 SEE ALSO

FANN homepage at L<http://leenissen.dk/fann/index.php>.

samples/add.pl  view on Meta::CPAN

        my $a = rand(2) - 1;
        my $b = rand(2) - 1;
        my $c = 0.5 * ($a + $b);

        $train->data($_, [$a, $b], [$c]);
    }

    $ann->train_on_data($train, 25000, 250, 0.00001);
    $ann->save("add.ann");
}
elsif ($ARGV[0] eq 'test') {

    my $ann = AI::FANN->new_from_file("add.ann");

    for (1..10) {
        my $a = rand(2) - 1;
        my $b = rand(2) - 1;

        my $c = 0.5 * ($a + $b);

        my $out = $ann->run([$a, $b]);

samples/ox.pl  view on Meta::CPAN

    print "\n";
    my $ann = AI::FANN->new_standard(@_);
    for (1..40) {
        $ann->train_on_data($train, 100, 1, 0.0001);
        # $ann->print_connections;
        $ann->print_parameters;
        $ann->save("ox.ann");
    }
}

sub make_test {
    my $rep = shift;
    my $ann = AI::FANN->new_from_file("ox.ann");
    print "ann read\n";
    for (0..$rep - 1) {
        my $im = GD::Image->new($size, $size);
        my $white = $im->colorAllocate(255,255,255);
        my $black = $im->colorAllocate(0,0,0);
        my $type = (rand > .5);
        my $r = $type ? draw_x($im, $black) : draw_o($im, $black);
        my $out = $ann->run(image_to_input($im));
        printf ("type: %f, r: %4.2f out type: %f, r: %4.2f\n", $type, $r, $out->[0], $out->[1]);
    }
}

if ($ARGV[0] eq 'train') {
    make_train($size * $size, 4 * $size * $size, 240, 200, 60, 20, 2);
}
elsif ($ARGV[0] eq 'test') {
    make_test($ARGV[1] || 10);
}
else {
    die "wrong action"
}

samples/xor.pl  view on Meta::CPAN

    my $xor_train = AI::FANN::TrainData->new( [-1, -1], [-1],
                                              [-1, 1], [1],
                                              [1, -1], [1],
                                              [1, 1], [-1] );

    $ann->train_on_data($xor_train, 500000, 100, 0.0001);

    $ann->save("xor.ann");

}
elsif ($ARGV[0] eq 'test') {

    my $ann = AI::FANN->new_from_file("xor.ann");

    for my $a (-1, 1) {
        for my $b (-1, 1) {
            my $out = $ann->run([$a, $b]);
            printf "xor(%f, %f) = %f\n", $a, $b, $out->[0];
        }
    }



( run in 2.259 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )