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
9
10
11
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
52 }
53
54 }