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
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
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
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
46 @Override
47 public String toString()
48 {
49 return "NoStorageAccumulator";
50 }
51
52
53 @Override
54 public void initialize()
55 {
56
57 }
58
59 }