summary refs log tree commit diff stats
path: root/lib/pure/stats.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/stats.nim')
-rw-r--r--lib/pure/stats.nim25
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/pure/stats.nim b/lib/pure/stats.nim
index 2004337df..ce32108c2 100644
--- a/lib/pure/stats.nim
+++ b/lib/pure/stats.nim
@@ -1,11 +1,12 @@
 #
 #
 #            Nim's Runtime Library
-#        (c) Copyright 2015 Andreas Rumpf
+#        (c) Copyright 2015 Nim contributors
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
 #
+
 ## Statistical analysis framework for performing
 ## basic statistical analysis of data.
 ## The data is analysed in a single pass, when a data value
@@ -64,8 +65,6 @@ type
     y_stats*: RunningStat   ## stats for second set of data
     s_xy: float             ## accumulated data for combined xy
 
-{.deprecated: [TFloatClass: FloatClass, TRunningStat: RunningStat].}
-
 # ----------- RunningStat --------------------------
 proc clear*(s: var RunningStat) =
   ## reset `s`
@@ -181,6 +180,24 @@ proc `+`*(a, b: RunningStat): RunningStat =
 proc `+=`*(a: var RunningStat, b: RunningStat) {.inline.} =
   ## add a second RunningStats `b` to `a`
   a = a + b
+
+proc `$`*(a: RunningStat): string =
+  ## produces a string representation of the ``RunningStat``. The exact
+  ## format is currently unspecified and subject to change. Currently
+  ## it contains:
+  ##
+  ## - the number of probes
+  ## - min, max values
+  ## - sum, mean and standard deviation.
+  result = "RunningStat(\n"
+  result.add "  number of probes: " & $a.n & "\n"
+  result.add "  max: " & $a.max & "\n"
+  result.add "  min: " & $a.min & "\n"
+  result.add "  sum: " & $a.sum & "\n"
+  result.add "  mean: " & $a.mean & "\n"
+  result.add "  std deviation: " & $a.standardDeviation & "\n"
+  result.add ")"
+
 # ---------------------- standalone array/seq stats ---------------------
 proc mean*[T](x: openArray[T]): float =
   ## computes the mean of `x`
@@ -281,7 +298,7 @@ proc correlation*(r: RunningRegress): float =
   let t = r.x_stats.standardDeviation() * r.y_stats.standardDeviation()
   result = r.s_xy / ( toFloat(r.n) * t )
 
-proc `+`*(a, b: RunningRegress):  RunningRegress =
+proc `+`*(a, b: RunningRegress): RunningRegress =
   ## combine two `RunningRegress` objects.
   ##
   ## Useful if performing parallel analysis of data series