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 ingest(final double value)
18      {
19          Throw.when(Double.isNaN(value), IllegalArgumentException.class, "accumulator can not accumlate 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 String toString()
37      {
38          return "NoStorageAccumulator";
39      }
40  
41      /** {@inheritDoc} */
42      @Override
43      public void initialize()
44      {
45          // Do nothing
46      }
47  
48  }