FWIW I've finally had a bit of time to revisit this. Sorry its taken so long. The following code works fairly nicely - it learns very quickly, and generalises rather nicely. The problem appears to be that with a small learning constant (needed for large numbers) the network takes for ever to learn. With a large learning constant, the numbers rapidly get out of range.

In addition, bias should not be used (this is only needed for networks where zero activation levels may require true outputs) and the starting weights have been fixed to 1, to keep them as positive numbers.

use AI::NNFlex::Backprop; use AI::NNFlex::Dataset; my $network = AI::NNFlex::Backprop->new( learningrate=>.00001, fahlmanconstant=>0, fixedweights=>1, momentum=>0.3, bias=>0); $network->add_layer( nodes=>2, activationfunction=>"linear"); $network->add_layer( nodes=>2, activationfunction=>"linear"); $network->add_layer( nodes=>1, activationfunction=>"linear"); $network->init(); # Taken from Mesh ex_add.pl my $dataset = AI::NNFlex::Dataset->new([ [ 1, 1 ], [ 2 ], [ 1, 2 ], [ 3 ], [ 2, 2 ], [ 4 ], [ 20, 20 ], [ 40 ], [ 10, 10 ], [ 20 ], [ 15, 15 ], [ 30 ], [ 12, 8 ], [ 20 ], ]); my $err = 10; # Stop after 4096 epochs -- don't want to wait more than that for ( my $i = 0; ($err > 0.0001) && ($i < 4096); $i++ ) { $err = $dataset->learn($network); print "Epoch = $i error = $err\n"; } foreach (@{$dataset->run($network)}) { foreach (@$_){print $_} print "\n"; } print "this should be 4000 - "; $network->run([2000,2000]); foreach ( @{$network->output}){print $_."\n";} foreach my $a ( 1..10 ) { foreach my $b ( 1..10 ) { my($ans) = $a+$b; my($nnans) = @{$network->run([$a,$b])}; print "[$a] [$b] ans=$ans but nnans=$nnans\n" unless $ans == $nna +ns; } }

--------------------------------------------------------------

g0n, backpropagated monk


In reply to Re: NNflex problems (win32) by g0n
in thread NNflex problems (win32) by tlpriest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.