/** * {@inheritDoc} */ @Override public StorelessUnivariateStatistic copy() { // multiply quantile by 100 now as anyway constructor divides it by 100 PSquarePercentile copy = new PSquarePercentile(100d * quantile); if (markers != null) { copy.markers = (PSquareMarkers) markers.clone(); } copy.countOfObservations = countOfObservations; copy.pValue = pValue; copy.initialFive.clear(); copy.initialFive.addAll(initialFive); return copy; }
/** * Returns true iff {@code o} is a {@code PSquarePercentile} returning the * same values as this for {@code getResult()} and {@code getN()} and also * having equal markers * * @param o object to compare * @return true if {@code o} is a {@code PSquarePercentile} with * equivalent internal state */ @Override public boolean equals(Object o) { boolean result = false; if (this == o) { result = true; } else if (o != null && o instanceof PSquarePercentile) { PSquarePercentile that = (PSquarePercentile) o; boolean isNotNull = markers != null && that.markers != null; boolean isNull = markers == null && that.markers == null; result = isNotNull ? markers.equals(that.markers) : isNull; // markers as in the case of first // five observations result = result && getN() == that.getN(); } return result; }
/** * {@inheritDoc} */ @Override public int hashCode() { double result = getResult(); result = Double.isNaN(result) ? 37 : result; final double markersHash = markers == null ? 0 : markers.hashCode(); final double[] toHash = {result, quantile, markersHash, countOfObservations}; return Arrays.hashCode(toHash); }
/** * {@inheritDoc}The internal state updated due to the new value in this * context is basically of the marker positions and computation of the * approximate quantile. * * @param observation the observation currently being added. */ @Override public void increment(final double observation) { // Increment counter countOfObservations++; // Store last observation this.lastObservation = observation; // 0. Use Brute force for <5 if (markers == null) { if (initialFive.add(observation)) { Collections.sort(initialFive); pValue = initialFive .get((int) (quantile * (initialFive.size() - 1))); return; } // 1. Initialize once after 5th observation markers = newMarkers(initialFive, quantile); } // 2. process a Data Point and return pValue pValue = markers.processDataPoint(observation); }
/** * {@inheritDoc}The internal state updated due to the new value in this * context is basically of the marker positions and computation of the * approximate quantile. * * @param observation the observation currently being added. */ @Override public void increment(final double observation) { // Increment counter countOfObservations++; // Store last observation this.lastObservation = observation; // 0. Use Brute force for <5 if (markers == null) { if (initialFive.add(observation)) { Collections.sort(initialFive); pValue = initialFive .get((int) (quantile * (initialFive.size() - 1))); return; } // 1. Initialize once after 5th observation markers = newMarkers(initialFive, quantile); } // 2. process a Data Point and return pValue pValue = markers.processDataPoint(observation); }
/** * {@inheritDoc} */ @Override public int hashCode() { double result = getResult(); result = Double.isNaN(result) ? 37 : result; final double markersHash = markers == null ? 0 : markers.hashCode(); final double[] toHash = {result, quantile, markersHash, countOfObservations}; return Arrays.hashCode(toHash); }
/** * {@inheritDoc} */ @Override public StorelessUnivariateStatistic copy() { // multiply quantile by 100 now as anyway constructor divides it by 100 PSquarePercentile copy = new PSquarePercentile(100d * quantile); if (markers != null) { copy.markers = (PSquareMarkers) markers.clone(); } copy.countOfObservations = countOfObservations; copy.pValue = pValue; copy.initialFive.clear(); copy.initialFive.addAll(initialFive); return copy; }
/** * Returns true iff {@code o} is a {@code PSquarePercentile} returning the * same values as this for {@code getResult()} and {@code getN()} and also * having equal markers * * @param o object to compare * @return true if {@code o} is a {@code PSquarePercentile} with * equivalent internal state */ @Override public boolean equals(Object o) { boolean result = false; if (this == o) { result = true; } else if (o != null && o instanceof PSquarePercentile) { PSquarePercentile that = (PSquarePercentile) o; boolean isNotNull = markers != null && that.markers != null; boolean isNull = markers == null && that.markers == null; result = isNotNull ? markers.equals(that.markers) : isNull; // markers as in the case of first // five observations result = result && getN() == that.getN(); } return result; }