]> gitweb.factorcode.org Git - factor.git/commitdiff
remove old median, fix docs
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 18 May 2009 07:41:58 +0000 (02:41 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 18 May 2009 07:41:58 +0000 (02:41 -0500)
basis/math/statistics/statistics-docs.factor
basis/math/statistics/statistics.factor

index 7a7eb70dd27d2e03a7b9371ad08e4a9d4954be4a..1a29d611f916d8500573fbe7283bcb7d4feff612 100644 (file)
@@ -2,26 +2,26 @@ USING: help.markup help.syntax debugger ;
 IN: math.statistics
 
 HELP: geometric-mean
-{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
+{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
 { $description "Computes the geometric mean of all elements in " { $snippet "seq" } ". The geometric mean measures the central tendency of a data set that minimizes the effects of extreme values." }
 { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } geometric-mean ." "1.81712059283214" } }
 { $errors "Throws a " { $link signal-error. } " (square-root of 0) if the sequence is empty." } ;
 
 HELP: harmonic-mean
-{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
+{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
 { $description "Computes the harmonic mean of the elements in " { $snippet "seq" } ". The harmonic mean is appropriate when the average of rates is desired." }
 { $notes "Positive reals only." }
 { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } harmonic-mean ." "6/11" } }
 { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
 
 HELP: mean
-{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
+{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
 { $description "Computes the arithmetic mean of all elements in " { $snippet "seq" } "." }
 { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } mean ." "2" } }
 { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
 
 HELP: median
-{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
+{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
 { $description "Computes the median of " { $snippet "seq" } " by sorting the sequence from lowest value to highest and outputting the middle one. If there is an even number of elements in the sequence, the median is not unique, so the mean of the two middle values is outputted." }
 { $examples
   { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } median ." "2" }
@@ -29,7 +29,7 @@ HELP: median
 { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
 
 HELP: range
-{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
+{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
 { $description "Computes the distance of the maximum and minimum values in " { $snippet "seq" } "." }
 { $examples
   { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } range ." "2" }
index 5b0439906c3af50890358c51e5e020c941720488..3812e79ec595fe56035513b5a93c5dd7fb307815 100644 (file)
@@ -5,22 +5,15 @@ math.functions math.order sequences sorting locals
 sequences.private ;
 IN: math.statistics
 
-: mean ( seq -- n )
+: mean ( seq -- x )
     [ sum ] [ length ] bi / ;
 
-: geometric-mean ( seq -- n )
+: geometric-mean ( seq -- x )
     [ length ] [ product ] bi nth-root ;
 
-: harmonic-mean ( seq -- n )
+: harmonic-mean ( seq -- x )
     [ recip ] sigma recip ;
 
-: slow-median ( seq -- n )
-    natural-sort dup length even? [
-        [ midpoint@ dup 1 - 2array ] keep nths mean
-    ] [
-        [ midpoint@ ] keep nth
-    ] if ;
-
 :: kth-smallest ( seq k -- elt )
     #! Wirth's method, Algorithm's + Data structues = Programs p. 84
     #! The algorithm modifiers seq, so we clone it
@@ -67,7 +60,7 @@ IN: math.statistics
     #! find the min and max of a seq in one pass
     [ 1/0. -1/0. ] dip [ [ min ] [ max ] bi-curry bi* ] each ;
 
-: range ( seq -- n )
+: range ( seq -- x )
     minmax swap - ;
 
 : var ( seq -- x )