]> gitweb.factorcode.org Git - factor.git/commitdiff
statistics tweaks
authorSlava Pestov <slava@factorcode.org>
Mon, 31 Oct 2005 05:41:17 +0000 (05:41 +0000)
committerSlava Pestov <slava@factorcode.org>
Mon, 31 Oct 2005 05:41:17 +0000 (05:41 +0000)
contrib/math/TODO.txt
contrib/math/statistics.factor

index cc1a723d74121919a10c844410434221119b21e9..c394efa7ec4d0a744bbeaa3c0fc63019e72d1045 100644 (file)
@@ -12,7 +12,8 @@ Nice to have:
   - infinite limits, sums, products
   - finding roots with Newton's method
   - solving ODEs with Runge-Kutta
-  - matrices: singular value decomposition, eigenvalues, LU decomposition
+  - matrices: singular value decomposition, eigenvalues, LU decomposition,
+    polar decomposition
   - square root of a matrix, e^matrix
   - finding roots of polynomials
 - Algebra:
@@ -32,7 +33,6 @@ Nice to have:
   - minimal and characteristic polynomials of algebraic numbers
   - norm and trace of algebraic numbers
   - minimal and characteristic polynomials of matrices
-  - eigenvalues of matrices
 - Graphs:
   - minimum spanning trees
 - Logic:
index 78582b201c6da8661105c367f9ed845cf59c0826..ac52361941c84b742fe5cf443e661f8d3c139e2b 100644 (file)
@@ -5,10 +5,14 @@ USING: kernel math sequences ;
     #! arithmetic mean, sum divided by length
     [ sum ] keep length / ;
 
-: geo-mean ( seq -- n )
+: geometric-mean ( seq -- n )
     #! geometric mean, nth root of product
     [ product ] keep length swap nth-root ;
 
+: harmonic-mean ( seq -- n )
+    #! harmonic mean, reciprocal of sum of reciprocals.
+    [ recip ] map sum recip ;
+
 : median ( seq -- n )
     #! middle number if odd, avg of two middle numbers if even
     number-sort dup length dup even? [
@@ -19,7 +23,7 @@ USING: kernel math sequences ;
 
 : range ( seq -- n )
     #! max - min
-    number-sort [ first ] keep pop swap - ;
+    dup first 2dup [ min ] reduce >r [ max ] reduce r> - ;
 
 : var ( seq -- )
     #! variance, normalize by N-1