This looks pretty cool!

If you allow me to make some remarks: it looks like a very C-ish/Perl 5-ish piece of Perl 6 code.

And I think there is one error in it:

method BUILD($inputneuron, $outputneuron, $y1 = 1000000.rand) +{ $.weight = $y1; }

The $.weight is equivalent to self.weight. You can only use the accessor as a mutator if the attribute is marked is rw. So either you can change the assignment to $!weight = $y1 (directly accessing the attribute), or you can add is rw to the attribute declaration: has $.weight is rw. The choice is really whether you want the weight to be assignable from the outside or not and/or you want subclasses to be able to define their own "weight" method or not.

With regards to C-ism / Perl 5-isms: it feels to me that the following loop

loop (my $i = 0; $i < @.inputsynapses.length; $i++) { if (@.inputsynapses[$i].weight * @.inputsynapses[$i].outputneuron. +input >= 0) { @.inputsynapses[$i].outputneuron.input = 1; } else { @.inputsynapses[$i].outputneuron.input = 0; } }

could be simplified to:

.outputneuron.input = +(.weight * .outputneuron.input >= 0) for @.inputsynapses;

This will iterate over all of the inputsynapses without needing to index. The +( ) is what transforms a Boolean True / False to 1 or 0.

Hope this helps


In reply to Re: Hopfield Neural Network in perl6 by liz
in thread Hopfield Neural Network in perl6 by holyghost

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.