The second one follows the classical definition: normalize frequencies to add to 1, do the p ln p thing, add em up, and change the sign.

The first one looks like it does a little less work, by some algebraic manipulation, and might be a little faster.

Henry Rich



On 3/21/2013 8:29 PM, Scott Locklin wrote:

<quote author="Henry Rich">
entropy =: +/@:(* ^.) (^.@] - %) +/
or
entropy =: -@(+/)@:(* ^.)@(% +/)
</quote>

Hot dog! Thank you!
Puzzing this out a bit, the second one makes more sense to me. I can stick 
parens and y's in and see what makes it tick. Somehow the fork and the @: in 
the first one confuses me on initial inspection (@ seems to work OK too). As I 
learn more about forks, perhaps I will feel better about things like this.

mmdow was easy:
mmdow=: entropy + (_1 + #) % 2 * +/

Thanks again fellows! I'll drop another note in this thread when the script is 
done enough to share.

-Scott
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to