Permalink
Browse files

Adjusts behavior when merging array backed hists

  • Loading branch information...
1 parent 233d3d6 commit 59bb9bbc224bcd9a5af63e3cc617a6bf0b56ed40 @ashenfad ashenfad committed Jan 25, 2012
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/java/com/bigml/histogram/Histogram.java
@@ -337,9 +337,14 @@ public double density(double p) {
* @param histogram the histogram to be merged
*/
public Histogram merge(Histogram<T> histogram) throws MixedInsertException {
- if ((_indexMap != null &&
- (histogram._indexMap == null || !_indexMap.equals(histogram._indexMap))) ||
- (_indexMap == null && histogram._indexMap != null)) {
+ if (_indexMap == null && histogram._indexMap != null) {
+ if (getBins().isEmpty()) {
+ _indexMap = histogram._indexMap;
+ } else {
+ throw new MixedInsertException();
+ }
+ }
+ if (_indexMap != null && !_indexMap.equals(histogram._indexMap)) {
throw new MixedInsertException();
} else if (!histogram.getBins().isEmpty()) {
checkType(histogram.getTargetType());
@@ -597,5 +602,5 @@ private static Double findZ(double a, double b, double c) {
private final HashMap<Double, Gap<T>> _binsToGaps;
private final DecimalFormat _decimalFormat;
private final boolean _countWeightedGaps;
- private final HashMap<Object, Integer> _indexMap;
+ private HashMap<Object, Integer> _indexMap;
}

0 comments on commit 59bb9bb

Please sign in to comment.