math.statistics: adding a normalized-histogram word.

db4
John Benediktsson 2012-09-26 08:39:11 -07:00
parent 6072e58db3
commit 7fb8db2e74
2 changed files with 6 additions and 0 deletions

View File

@ -77,6 +77,9 @@ IN: math.statistics.tests
"aabbcc" histogram
] unit-test
{ H{ { 1 1/2 } { 2 1/6 } { 3 1/3 } } }
[ { 1 1 1 1 1 1 2 2 3 3 3 3 } normalized-histogram ] unit-test
{
V{ 0 3 6 9 }
V{ 1 4 7 }

View File

@ -227,6 +227,9 @@ PRIVATE>
: sorted-histogram ( seq -- alist )
histogram sort-values ;
: normalized-histogram ( seq -- alist )
[ histogram ] [ length ] bi '[ _ / ] assoc-map ;
: collect-pairs ( seq quot: ( x -- v k ) -- hashtable )
[ push-at ] sequence>hashtable ; inline