/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }
/** * Create a histogram from a set of ranges with associated event counters. * * @throws IllegalArgumentException If the items contain mixed signs. */ public Histogram(Stream<RangeWithCount> items) { final List<RangeWithCount> iter = cleanup_(items.map(RangeWithCount::clone).collect(Collectors.toList())); if (iter.isEmpty()) { buckets_ = EMPTY_LIST; return; } if (iter.stream() .map(RangeWithCount::getCount) .map(Math::signum) .distinct() .count() > 1) { throw new IllegalArgumentException("mixed sign"); } final List<Bucket> buckets = new ArrayList<>(iter.size()); double running_total = 0; for (RangeWithCount rwc : iter) { running_total += rwc.getCount(); buckets.add(new Bucket(rwc.getRange(), rwc.getCount(), running_total)); } buckets_ = unmodifiableList(buckets); }
/** * Create a new histogram, after applying the function on each of the event * counters. */ public Histogram modifyEventCounters(BiFunction<Range, Double, Double> fn) { return new Histogram(stream() .map(entry -> { entry.setCount(fn.apply(entry.getRange(), entry.getCount())); return entry; })); }
.comparing((RangeWithCount range_count) -> range_count.getRange().getFloor()) .thenComparing(Comparator.comparing((RangeWithCount range_count) -> range_count.getRange().getCeil())); if (head.getRange().equals(succ.getRange())) { succ.setCount(succ.getCount() + head.getCount()); continue; if (head.getRange().getFloor() == succ.getRange().getFloor()) { final double mid = head.getRange().getCeil(); final double ceil = succ.getRange().getCeil(); final double succ_range = succ.getRange().getWidth(); final double succ_left_fraction = (mid - succ.getRange().getFloor()) / succ_range; final double succ_right_fraction = 1 - succ_left_fraction; if (head.getRange().getCeil() <= succ.getRange().getFloor()) { if (Math.signum(head.getCount()) != 0) result.add(head); assert (head.getRange().getFloor() < succ.getRange().getFloor()); assert (succ.getRange().getFloor() < head.getRange().getCeil()); final double floor = head.getRange().getFloor(); final double ceil = succ.getRange().getFloor(); final double head_range = head.getRange().getWidth(); final double head_left_fraction = (ceil - floor) / head_range; final double head_right_fraction = 1 - head_left_fraction; imed.add(0, head); imed.add(0, new RangeWithCount(new Range(floor, ceil), head_left_fraction * head.getCount()));
.comparing((RangeWithCount range_count) -> range_count.getRange().getFloor()) .thenComparing(Comparator.comparing((RangeWithCount range_count) -> range_count.getRange().getCeil())); if (head.getRange().equals(succ.getRange())) { succ.setCount(succ.getCount() + head.getCount()); continue; if (head.getRange().getFloor() == succ.getRange().getFloor()) { final double mid = head.getRange().getCeil(); final double ceil = succ.getRange().getCeil(); final double succ_range = succ.getRange().getWidth(); final double succ_left_fraction = (mid - succ.getRange().getFloor()) / succ_range; final double succ_right_fraction = 1 - succ_left_fraction; if (head.getRange().getCeil() <= succ.getRange().getFloor()) { if (Math.signum(head.getCount()) != 0) result.add(head); assert (head.getRange().getFloor() < succ.getRange().getFloor()); assert (succ.getRange().getFloor() < head.getRange().getCeil()); final double floor = head.getRange().getFloor(); final double ceil = succ.getRange().getFloor(); final double head_range = head.getRange().getWidth(); final double head_left_fraction = (ceil - floor) / head_range; final double head_right_fraction = 1 - head_left_fraction; imed.add(0, head); imed.add(0, new RangeWithCount(new Range(floor, ceil), head_left_fraction * head.getCount()));
/** * Create a new histogram, after applying the function on each of the event * counters. */ public Histogram modifyEventCounters(BiFunction<Range, Double, Double> fn) { return new Histogram(stream() .map(entry -> { entry.setCount(fn.apply(entry.getRange(), entry.getCount())); return entry; })); }