Permalink
Browse files

Variance calculation fix

  • Loading branch information...
1 parent ad05075 commit ba73316611f01c778829a60a43bd07fdfaf08e5f @ashenfad ashenfad committed Aug 31, 2012
Showing with 5 additions and 3 deletions.
  1. +1 −1 project.clj
  2. +2 −2 src/clj/histogram/core.clj
  3. +2 −0 test/histogram/test/core.clj
View
@@ -1,4 +1,4 @@
-(defproject histogram "1.9.8"
+(defproject histogram "1.9.9"
:description "Dynamic/streaming histograms"
:source-path "src/clj"
:java-source-path "src/java"
@@ -322,10 +322,10 @@
[^Histogram hist]
(let [h-mean (mean hist)
h-count (total-count hist)]
- (when (pos? h-count)
+ (when (> h-count 1)
(/ (reduce (fn [v {:keys [mean count]}]
(let [diff (- mean h-mean)]
(+ v (* count diff diff))))
0
(bins hist))
- h-count))))
+ (dec h-count)))))
@@ -262,6 +262,8 @@
(is (= (maximum hist1) (maximum hist2)))))
(deftest variance-test
+ (is (nil? (variance (insert! (create) 1))))
+ (is (= 3.5 (variance (reduce insert! (create) [1 2 3 4 5 6]))))
(is (about= (variance (reduce insert! (create) (normal-data 10000)))
1 0.05)))

0 comments on commit ba73316

Please sign in to comment.