class 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; // smaller than all
      }
      if (previous != null && previous.getKey() <= score && score < entry.getKey()) {
        // interpolate and return
        final double dx = (entry.getKey() - previous.getKey()) / 2.0;
        return 1 - (previous.getValue() + dx * (entry.getValue() - previous.getValue()));
      }
      previous = entry;
    }
    // If we reach here, p value is 0.0
    return 0.0;
  }

  public  ObjectScoreDistribution(TermId objectId, int numTerms, int sampleSize, SortedMap<Double, Double> cumulativeFrequencies);

}