ObjectScoreDistribution implements Serializable { public double estimatePValue(double score) { Entry<Double, Double> previous = null; for (Entry<Double, Double> entry : cumulativeFrequencies.entrySet()) { if (previous == null && score <= entry.getKey()) { return 1.0; } if (previous != null && previous.getKey() <= score && score < entry.getKey()) { final double dx = (entry.getKey() - previous.getKey()) / 2.0; return 1 - (previous.getValue() + dx * (entry.getValue() - previous.getValue())); } previous = entry; } return 0.0; } ObjectScoreDistribution(TermId objectId, int numTerms, int sampleSize, SortedMap<Double, Double> cumulativeFrequencies); double estimatePValue(double score); List<Double> observedScores(); SortedMap<Double, Double> getCumulativeFrequencies(); TermId getObjectId(); int getNumTerms(); int getSampleSize(); @Override String toString();  }
@Test public void testEstimatePValue() { assertEquals(1.0, objDist.estimatePValue(0.0), 0.01); assertEquals(1.0, objDist.estimatePValue(0.1), 0.01); assertEquals(0.82, objDist.estimatePValue(0.2), 0.01); assertEquals(0.82, objDist.estimatePValue(0.4), 0.01); assertEquals(0.42, objDist.estimatePValue(0.6), 0.01); assertEquals(0.42, objDist.estimatePValue(0.8), 0.01); assertEquals(0.0, objDist.estimatePValue(0.99), 0.01); }