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      /** {@inheritDoc} */
16      @Override
17      public double register(final double value)
18      {
19          Throw.when(Double.isNaN(value), IllegalArgumentException.class, "accumulator can not accumulate NaN value");
20          return value;
21      }
22  
23      /** {@inheritDoc} */
24      @Override
25      public double getQuantile(final Tally tally, final double probability)
26      {
27          Throw.whenNull(tally, "tally cannot be null");
28          Throw.when(probability < 0 || probability > 1, IllegalArgumentException.class,
29                  "probability should be between 0 and 1 (inclusive)");
30          return DistNormalTable.getInverseCumulativeProbability(tally.getSampleMean(), Math.sqrt(tally.getSampleVariance()),
31                  probability);
32      }
33  
34      /** {@inheritDoc} */
35      @Override
36      public double getCumulativeProbability(final Tally tally, final double quantile) throws IllegalArgumentException
37      {
38          if (tally.getN() == 0)
39          {
40              return Double.NaN;
41          }
42          return DistNormalTable.getCumulativeProbability(tally.getPopulationMean(), tally.getPopulationStDev(), quantile);
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      public String toString()
48      {
49          return "NoStorageAccumulator";
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public void initialize()
55      {
56          // Do nothing
57      }
58  
59  }