Skip to content

Commit 1de40df

Browse files
committed
Fixes sum when the min value and the first bin's mean are the same
1 parent 03a9a2a commit 1de40df

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/java/com/bigml/histogram/Histogram.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,12 @@ public SumResult<T> extendedSum(double p) throws SumOutOfRangeException {
339339
bin_i1 = new Bin(_maximum, 0, emptyTarget.clone());
340340
}
341341

342-
double prevCount = 0;
343-
T prevTargetSum = (T) emptyTarget.clone();
344-
345-
if (bin_i.getMean() != _minimum) {
342+
double prevCount;
343+
T prevTargetSum;
344+
if (bin_i.getMean() == _minimum) {
345+
prevCount = _bins.first().getCount() / 2;
346+
prevTargetSum = (T) _bins.first().getTarget().clone().mult(0.5);
347+
} else {
346348
SumResult<T> prevSumResult = getPointToSumMap().get(bin_i.getMean());
347349
prevCount = prevSumResult.getCount();
348350
prevTargetSum = prevSumResult.getTargetSum();

test/bigml/histogram/test/core.clj

+6
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,9 @@
342342

343343
(deftest nil-target-sum
344344
(is (nil? (total-target-sum (create)))))
345+
346+
(deftest sum-edges
347+
(let [hist (reduce insert! (create) [0 10])]
348+
(is (== 1 (sum hist 5)))
349+
(is (== 0.5 (sum hist 0)))
350+
(is (== 2 (sum hist 10)))))

0 commit comments

Comments
 (0)