/** * Get the value at a given position. */ public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); // Undo position change made by mid.next(). if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); // Undo position change made by b.next(). final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; }
/** * Return the sum of the histogram. */ public double sum() { return buckets_.stream() .mapToDouble(b -> b.getRange().getMidPoint() * b.getEvents()) .sum(); }
.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; succ.setRange(new Range(mid, ceil)); imed.add(0, head); sort(imed, cmp); 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();
.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; succ.setRange(new Range(mid, ceil)); imed.add(0, head); sort(imed, cmp); 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();
public final Histogram_elemContext histogram_elem() throws RecognitionException { Histogram_elemContext _localctx = new Histogram_elemContext(_ctx, getState()); enterRule(_localctx, 172, RULE_histogram_elem); try { enterOuterAlt(_localctx, 1); { setState(1254); ((Histogram_elemContext)_localctx).s_floor = number(); setState(1255); match(DOT_DOT_LIT); setState(1256); ((Histogram_elemContext)_localctx).s_ceil = number(); setState(1257); match(EQ_KW); setState(1258); ((Histogram_elemContext)_localctx).s_count = number(); ((Histogram_elemContext)_localctx).s = new Histogram.RangeWithCount(new Histogram.Range(((Histogram_elemContext)_localctx).s_floor.s.doubleValue(), ((Histogram_elemContext)_localctx).s_ceil.s.doubleValue()), ((Histogram_elemContext)_localctx).s_count.s.doubleValue()); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
/** * Get the value at a given position. */ public double get(double index) { ListIterator<Bucket> b = buckets_.listIterator(0); ListIterator<Bucket> e = buckets_.listIterator(buckets_.size()); while (b.nextIndex() < e.previousIndex()) { final ListIterator<Bucket> mid = buckets_.listIterator(b.nextIndex() / 2 + e.nextIndex() / 2); final Bucket mid_bucket = mid.next(); mid.previous(); // Undo position change made by mid.next(). if (mid_bucket.getRunningEventsCount() == index && mid.nextIndex() >= e.previousIndex()) { return mid_bucket.getRange().getCeil(); } else if (mid_bucket.getRunningEventsCount() <= index) { b = mid; b.next(); } else if (mid_bucket.getRunningEventsCount() - mid_bucket.getEvents() > index) { e = mid; } else { b = mid; break; } } final Bucket bucket = b.next(); b.previous(); // Undo position change made by b.next(). final double low = bucket.getRunningEventsCount() - bucket.getEvents(); final double off = index - low; final double left_fraction = off / bucket.getEvents(); final double right_fraction = 1 - left_fraction; return bucket.getRange().getCeil() * left_fraction + bucket.getRange().getFloor() * right_fraction; }
public final Histogram_elemContext histogram_elem() throws RecognitionException { Histogram_elemContext _localctx = new Histogram_elemContext(_ctx, getState()); enterRule(_localctx, 94, RULE_histogram_elem); try { enterOuterAlt(_localctx, 1); { setState(698); ((Histogram_elemContext)_localctx).s_floor = number(); setState(699); match(DOT_DOT_LIT); setState(700); ((Histogram_elemContext)_localctx).s_ceil = number(); setState(701); match(EQ_KW); setState(702); ((Histogram_elemContext)_localctx).s_count = number(); ((Histogram_elemContext)_localctx).s = new Histogram.RangeWithCount(new Histogram.Range(((Histogram_elemContext)_localctx).s_floor.s.doubleValue(), ((Histogram_elemContext)_localctx).s_ceil.s.doubleValue()), ((Histogram_elemContext)_localctx).s_count.s.doubleValue()); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
public final Histogram_elemContext histogram_elem() throws RecognitionException { Histogram_elemContext _localctx = new Histogram_elemContext(_ctx, getState()); enterRule(_localctx, 94, RULE_histogram_elem); try { enterOuterAlt(_localctx, 1); { setState(698); ((Histogram_elemContext)_localctx).s_floor = number(); setState(699); match(DOT_DOT_LIT); setState(700); ((Histogram_elemContext)_localctx).s_ceil = number(); setState(701); match(EQ_KW); setState(702); ((Histogram_elemContext)_localctx).s_count = number(); ((Histogram_elemContext)_localctx).s = new Histogram.RangeWithCount(new Histogram.Range(((Histogram_elemContext)_localctx).s_floor.s.doubleValue(), ((Histogram_elemContext)_localctx).s_ceil.s.doubleValue()), ((Histogram_elemContext)_localctx).s_count.s.doubleValue()); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }
/** * Compare two histograms. */ @Override public int compareTo(Histogram o) { int cmp = 0; final Iterator<Bucket> iter = buckets_.iterator(), o_iter = o.buckets_.iterator(); while (cmp == 0 && iter.hasNext() && o_iter.hasNext()) { final Bucket next = iter.next(), o_next = o_iter.next(); cmp = Double.compare(next.getRange().getFloor(), o_next.getRange().getFloor()); if (cmp == 0) cmp = Double.compare(next.getRange().getCeil(), o_next.getRange().getCeil()); if (cmp == 0) cmp = Double.compare(next.getEvents(), o_next.getEvents()); } if (cmp == 0) cmp = (iter.hasNext() ? 1 : (o_iter.hasNext() ? -1 : 0)); return cmp; }
/** * Compare two histograms. */ @Override public int compareTo(Histogram o) { int cmp = 0; final Iterator<Bucket> iter = buckets_.iterator(), o_iter = o.buckets_.iterator(); while (cmp == 0 && iter.hasNext() && o_iter.hasNext()) { final Bucket next = iter.next(), o_next = o_iter.next(); cmp = Double.compare(next.getRange().getFloor(), o_next.getRange().getFloor()); if (cmp == 0) cmp = Double.compare(next.getRange().getCeil(), o_next.getRange().getCeil()); if (cmp == 0) cmp = Double.compare(next.getEvents(), o_next.getEvents()); } if (cmp == 0) cmp = (iter.hasNext() ? 1 : (o_iter.hasNext() ? -1 : 0)); return cmp; }
public RangeWithCount(double floor, double ceil, double count) { this(new Range(floor, ceil), count); }
/** * Return the minimum value in the histogram. */ public Optional<Double> min() { if (isEmpty()) return Optional.empty(); return Optional.of(buckets_.get(0).getRange().getFloor()); }
public RangeWithCount(double floor, double ceil, double count) { this(new Range(floor, ceil), count); }
/** * Return the minimum value in the histogram. */ public Optional<Double> min() { if (isEmpty()) return Optional.empty(); return Optional.of(buckets_.get(0).getRange().getFloor()); }
/** * Return the minimum value in the histogram. */ public Optional<Double> max() { if (isEmpty()) return Optional.empty(); return Optional.of(buckets_.get(buckets_.size() - 1).getRange().getCeil()); }
/** * Return the minimum value in the histogram. */ public Optional<Double> max() { if (isEmpty()) return Optional.empty(); return Optional.of(buckets_.get(buckets_.size() - 1).getRange().getCeil()); }