nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
226d752
)
lib: add standard derivation computation to counter
author
Alexandre Terrasa
<alexandre@moz-code.org>
Thu, 6 Mar 2014 17:55:44 +0000
(12:55 -0500)
committer
Alexandre Terrasa
<alexandre@moz-code.org>
Fri, 7 Mar 2014 06:17:17 +0000
(
01:17
-0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
lib/counter.nit
patch
|
blob
|
history
diff --git
a/lib/counter.nit
b/lib/counter.nit
index
4c7b6d6
..
1c2b9ed
100644
(file)
--- a/
lib/counter.nit
+++ b/
lib/counter.nit
@@
-162,6
+162,16
@@
class Counter[E: Object]
end
return sum.to_f / values.length.to_f
end
+
+ # The standard derivation of the counter values
+ fun std_dev: Float do
+ var avg = self.avg
+ var sum = 0.0
+ for value in map.values do
+ sum += (value.to_f - avg).pow(2.0)
+ end
+ return (sum / map.length.to_f).sqrt
+ end
end
private class CounterSorter[E: Object]