]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/math/statistics/statistics.factor
math.statistics: fix typo
[factor.git] / basis / math / statistics / statistics.factor
index 9630eaf0fffc2ef88a5bc9c49341ce2fa7411ab5..ab5e10a6e6aa5ac359725f038790b2c9600a573f 100644 (file)
@@ -2,9 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs combinators
 combinators.short-circuit fry generalizations grouping kernel
-locals math math.functions math.order math.ranges math.vectors
+locals math math.functions math.order ranges math.vectors
 sequences sequences.private sorting ;
-FROM: math.ranges => [a,b] ;
 IN: math.statistics
 
 : power-mean ( seq p -- x )
@@ -25,7 +24,7 @@ GENERIC: sum-of-squares ( seq -- x )
 M: object sum-of-squares [ sq ] map-sum ;
 M: iota sum-of-squares
     n>> 1 - [ ] [ 1 + ] [ 1/2 + ] tri * * 3 / ;
-M: math.ranges:range sum-of-squares
+M: ranges:range sum-of-squares
     dup { [ step>> 1 = ] [ from>> integer? ] } 1&& [
         [ from>> ] [ length>> ] bi dupd +
         [ <iota> sum-of-squares ] bi@ swap -
@@ -34,7 +33,7 @@ M: math.ranges:range sum-of-squares
 GENERIC: sum-of-cubes ( seq -- x )
 M: object sum-of-cubes [ 3 ^ ] map-sum ;
 M: iota sum-of-cubes sum sq ;
-M: math.ranges:range sum-of-cubes
+M: ranges:range sum-of-cubes
     dup { [ step>> 1 = ] [ from>> integer? ] } 1&& [
         [ from>> ] [ length>> ] bi dupd +
         [ <iota> sum-of-cubes ] bi@ swap -
@@ -52,7 +51,7 @@ M: iota sum-of-quads
             * * * 30 /
         ] [ 0 ] if
     ] ;
-M: math.ranges:range sum-of-quads
+M: ranges:range sum-of-quads
     dup { [ step>> 1 = ] [ from>> integer? ] } 1&& [
         [ from>> ] [ length>> ] bi dupd +
         [ <iota> sum-of-quads ] bi@ swap -
@@ -125,7 +124,7 @@ PRIVATE>
     k seq nth-unsafe ; inline
 
 : (kth-object) ( seq k nth-quot exchange-quot quot: ( x y -- ? ) -- elt )
-    ! The algorithm modifiers seq, so we clone it
+    ! The algorithm modifies seq, so we clone it
     [ >array ] 4dip kth-object-impl ; inline
 
 : kth-object-unsafe ( seq k quot: ( x y -- ? ) -- elt )
@@ -252,11 +251,14 @@ PRIVATE>
 : trimean ( seq -- x )
     quartile first3 [ 2 * ] dip + + 4 / ;
 
+: histogram-by! ( assoc seq quot: ( x -- bin ) -- hashtable )
+    rot [ '[ @ _ inc-at ] each ] keep ; inline
+
 : histogram! ( hashtable seq -- hashtable )
-    over '[ _ inc-at ] each ;
+    [ ] histogram-by! ; inline
 
 : histogram-by ( seq quot: ( x -- bin ) -- hashtable )
-    H{ } clone [ '[ @ _ inc-at ] each ] keep ; inline
+    [ H{ } clone ] 2dip histogram-by! ; inline
 
 : histogram ( seq -- hashtable )
     [ ] histogram-by ;
@@ -411,7 +413,7 @@ PRIVATE>
     [ demean ] [ sample-std ] bi v/n ;
 
 : dcg ( scores -- dcg )
-    dup length 1 + 2 swap [a,b] [ log 2 log /f ] map v/ sum ;
+    dup length 1 + 2 swap [a..b] [ log 2 log /f ] map v/ sum ;
 
 : ndcg ( scores -- ndcg )
     [ 0.0 ] [