]> gitweb.factorcode.org Git - factor.git/commitdiff
math.statistics, add docs for cum-sum0, add cum-product1 for symmetry
authorJon Harper <jon.harper87@gmail.com>
Tue, 8 Mar 2016 14:05:37 +0000 (15:05 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 8 Mar 2016 21:41:54 +0000 (13:41 -0800)
basis/math/statistics/statistics-docs.factor
basis/math/statistics/statistics-tests.factor
basis/math/statistics/statistics.factor

index 8ed42560a7f41f7b956db3b23fe68286ca1c67f2..df4a8c4d376c4cef66424bae6d6f8d47d7e91ea7 100644 (file)
@@ -188,6 +188,16 @@ HELP: cum-sum
     }
 } ;
 
+HELP: cum-sum0
+{ $values { "seq" sequence } { "seq'" sequence } }
+{ $description "Returns the cumulative sum of " { $snippet "seq" } " starting with 0 and not including the whole sum." }
+{ $examples
+    { $example "USING: math.statistics prettyprint ;"
+               "{ 1 -1 2 -1 4 } cum-sum0 ."
+               "{ 0 1 0 2 1 }"
+    }
+} ;
+
 HELP: cum-count
 { $values { "seq" sequence } { "quot" quotation } { "seq'" sequence } }
 { $description "Returns the cumulative count of how many times " { $snippet "quot" } " returns true." }
@@ -209,6 +219,16 @@ HELP: cum-product
     }
 } ;
 
+HELP: cum-product1
+{ $values { "seq" sequence } { "seq'" sequence } }
+{ $description "Returns the cumulative product of " { $snippet "seq" } " starting with 1 and not including the whole product." }
+{ $examples
+    { $example "USING: math.statistics prettyprint ;"
+               "{ 2 3 4 } cum-product1 ."
+               "{ 1 2 6 }"
+    }
+} ;
+
 HELP: cum-mean
 { $values { "seq" sequence } { "seq'" sequence } }
 { $description "Returns the cumulative mean of " { $snippet "seq" } "." }
@@ -309,6 +329,7 @@ $nl
     cum-sum
     cum-sum0
     cum-product
+    cum-product1
 }
 "Cumulative comparisons:"
 { $subsections
index 516e626928fcd46e55307e4c29fd0989cb502ab7..df58c7be7fbfea7dd11de7dc6f34acacb0f34c0e 100644 (file)
@@ -212,6 +212,9 @@ IN: math.statistics.tests
 { { 0 1 3 6 } }
 [ { 1 2 3 4 } cum-sum0 ] unit-test
 
+{ { 1 2 6 } }
+[ { 2 3 4 } cum-product1 ] unit-test
+
 {
     H{
         { 0 V{ 600 603 606 609 } }
index 080c7acc7eea41db3d98867a8a6902cbaa277d66..5b8d8127fcde7b9ea6181a70406107c50f4a98dd 100644 (file)
@@ -349,6 +349,9 @@ ALIAS: std sample-std
 : cum-product ( seq -- seq' )
     1 [ * ] accumulate* ;
 
+: cum-product1 ( seq -- seq' )
+    1 [ * ] accumulate nip ;
+
 : cum-mean ( seq -- seq' )
     0 swap [ [ + dup ] dip 1 + / ] map-index nip ;