math.statistics: faster and simpler entropy word.

db4
John Benediktsson 2012-07-11 12:26:20 -07:00
parent f019ee8776
commit bdf02bfd2b
1 changed files with 1 additions and 2 deletions

View File

@ -330,8 +330,7 @@ ALIAS: corr sample-corr
[ ?first ] keep [ max dup ] map nip ;
: entropy ( seq -- n )
dup members [ [ = ] curry count ] with map
dup sum v/n dup [ log ] map v* sum neg ;
histogram values dup sum '[ _ / dup log * ] map-sum neg ;
: binary-entropy ( p -- h )
[ dup log * ] [ 1 swap - dup log * ] bi + neg 2 log / ;