Permalink
Browse files

Fixes sum when the min value and the first bin's mean are the same

  • Loading branch information...
1 parent 03a9a2a commit 1de40df9db5bcfc967a11a78bf32ea02d6afa573 @ashenfad ashenfad committed Mar 12, 2013
Showing with 12 additions and 4 deletions.
  1. +6 −4 src/java/com/bigml/histogram/Histogram.java
  2. +6 −0 test/bigml/histogram/test/core.clj
@@ -339,10 +339,12 @@ public double sum(double p) throws SumOutOfRangeException {
bin_i1 = new Bin(_maximum, 0, emptyTarget.clone());
}
- double prevCount = 0;
- T prevTargetSum = (T) emptyTarget.clone();
-
- if (bin_i.getMean() != _minimum) {
+ double prevCount;
+ T prevTargetSum;
+ if (bin_i.getMean() == _minimum) {
+ prevCount = _bins.first().getCount() / 2;
+ prevTargetSum = (T) _bins.first().getTarget().clone().mult(0.5);
+ } else {
SumResult<T> prevSumResult = getPointToSumMap().get(bin_i.getMean());
prevCount = prevSumResult.getCount();
prevTargetSum = prevSumResult.getTargetSum();
@@ -342,3 +342,9 @@
(deftest nil-target-sum
(is (nil? (total-target-sum (create)))))
+
+(deftest sum-edges
+ (let [hist (reduce insert! (create) [0 10])]
+ (is (== 1 (sum hist 5)))
+ (is (== 0.5 (sum hist 0)))
+ (is (== 2 (sum hist 10)))))

0 comments on commit 1de40df

Please sign in to comment.