Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Variance calculation fix

  • Loading branch information...
commit ba73316611f01c778829a60a43bd07fdfaf08e5f 1 parent ad05075
@ashenfad ashenfad authored
View
2  project.clj
@@ -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"
View
4 src/clj/histogram/core.clj
@@ -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)))))
View
2  test/histogram/test/core.clj
@@ -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)))
Please sign in to comment.
Something went wrong with that request. Please try again.