View Javadoc
1   package org.djutils.stats.summarizers.quantileaccumulator;
2   
3   import org.djutils.exceptions.Throw;
4   import org.djutils.stats.DistNormalTable;
5   import org.djutils.stats.summarizers.Tally;
6   
7   /**
8    * The no storage accumulator accumulates nothing and estimates all requested quantiles from mean, standard deviation, etc. (as
9    * accumulated by the Tally class object). This is sensible if the input values are normally distributed. Do not use this
10   * accumulator when the input values are not normally distributes.<br>
11   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
12   */
13  public class NoStorageAccumulator implements QuantileAccumulator
14  {
15      @Override
16      public double register(final double value)
17      {
18          Throw.when(Double.isNaN(value), IllegalArgumentException.class, "accumulator can not accumulate NaN value");
19          return value;
20      }
21  
22      @Override
23      public double getQuantile(final Tally tally, final double probability)
24      {
25          Throw.whenNull(tally, "tally cannot be null");
26          Throw.when(probability < 0 || probability > 1, IllegalArgumentException.class,
27                  "probability should be between 0 and 1 (inclusive)");
28          return DistNormalTable.getInverseCumulativeProbability(tally.getSampleMean(), Math.sqrt(tally.getSampleVariance()),
29                  probability);
30      }
31  
32      @Override
33      public double getCumulativeProbability(final Tally tally, final double quantile) throws IllegalArgumentException
34      {
35          if (tally.getN() == 0)
36          {
37              return Double.NaN;
38          }
39          return DistNormalTable.getCumulativeProbability(tally.getPopulationMean(), tally.getPopulationStDev(), quantile);
40      }
41  
42      @Override
43      public String toString()
44      {
45          return "NoStorageAccumulator";
46      }
47  
48      @Override
49      public void initialize()
50      {
51          // Do nothing
52      }
53  
54  }