Class EventBasedTally
- java.lang.Object
 - 
- org.djutils.event.EventProducer
 - 
- org.djutils.stats.summarizers.event.EventBasedTally
 
 
 
- 
- All Implemented Interfaces:
 Serializable,EventListener,EventListenerInterface,EventProducerInterface,BasicTallyInterface,TallyInterface
public class EventBasedTally extends EventProducer implements EventListenerInterface, TallyInterface
The EventBasedTally class ingests a series of values and provides mean, standard deviation, etc. of the ingested values. It extends an EventProducer so it can keep listeners informed about new observations, and it listens to external events to be able to receive observations, in addition to the ingest(...) method.Copyright (c) 2002-2021 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://simulation.tudelft.nl/dsol/3.0/license.html.
- Author:
 - Alexander Verbraeck, Peter Jacobs , Peter Knoppers
 - See Also:
 - Serialized Form
 
 
- 
- 
Field Summary
- 
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl 
- 
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION 
 - 
 
- 
Constructor Summary
Constructors Constructor Description EventBasedTally(String description)Convenience constructor that uses a NoStorageAccumulator to estimate quantiles.EventBasedTally(String description, QuantileAccumulator quantileAccumulator)Constructs a new EventBasedTally. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfireEvents()Method that can be overridden to fire own events or additional events when ingesting an observation.double[]getConfidenceInterval(double alpha)returns the confidence interval on either side of the mean.double[]getConfidenceInterval(double alpha, ConfidenceInterval side)returns the confidence interval based of the mean.StringgetDescription()returns the description of this tally.doublegetMax()Returns the max.doublegetMin()Returns the min.longgetN()Returns the number of observations.doublegetPopulationExcessKurtosis()Return the population excess kurtosis of the ingested data.doublegetPopulationKurtosis()Return the (biased) population kurtosis of the ingested data.doublegetPopulationSkewness()Return the (biased) population skewness of the ingested data.doublegetPopulationStDev()Returns the current (biased) population standard deviation of all observations since the initialization.doublegetPopulationVariance()Returns the current (biased) population variance of all observations since the initialization.doublegetQuantile(double probability)Compute the quantile for the given probability.doublegetSampleExcessKurtosis()Return the sample excess kurtosis of the ingested data.doublegetSampleKurtosis()Return the sample kurtosis of the ingested data.doublegetSampleMean()Returns the sample mean of all observations since the initialization.doublegetSampleSkewness()Return the (unbiased) sample skewness of the ingested data.doublegetSampleStDev()Returns the current (unbiased) sample standard deviation of all observations since the initialization.doublegetSampleVariance()Returns the current (unbiased) sample variance of all observations since the initialization.SerializablegetSourceId()doublegetSum()Return the sum of the values of the observations.doubleingest(double value)Process one observed value.voidinitialize()initializes the Tally.voidnotify(EventInterface event)StringtoString()- 
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener 
- 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
- 
Methods inherited from interface org.djutils.stats.summarizers.TallyInterface
getPopulationMean 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
EventBasedTally
public EventBasedTally(String description, QuantileAccumulator quantileAccumulator)
Constructs a new EventBasedTally.- Parameters:
 description- String; the description of this tallyquantileAccumulator- QuantileAccumulator; the input series accumulator that can approximate or compute quantiles.
 
- 
EventBasedTally
public EventBasedTally(String description)
Convenience constructor that uses a NoStorageAccumulator to estimate quantiles.- Parameters:
 description- String; the description of this tally
 
 - 
 
- 
Method Detail
- 
getSourceId
public Serializable getSourceId()
- Specified by:
 getSourceIdin interfaceEventProducerInterface- Specified by:
 getSourceIdin classEventProducer
 
- 
getSampleMean
public final double getSampleMean()
Returns the sample mean of all observations since the initialization.- Specified by:
 getSampleMeanin interfaceTallyInterface- Returns:
 - double; the sample mean
 
 
- 
getQuantile
public final double getQuantile(double probability)
Compute the quantile for the given probability.- Specified by:
 getQuantilein interfaceTallyInterface- Parameters:
 probability- double; the probability for which the quantile is to be computed. The value should be between 0 and 1, inclusive.- Returns:
 - double; the quantile for the probability
 
 
- 
getConfidenceInterval
public final double[] getConfidenceInterval(double alpha)
returns the confidence interval on either side of the mean.- Specified by:
 getConfidenceIntervalin interfaceTallyInterface- Parameters:
 alpha- double; Alpha is the significance level used to compute the confidence level. The confidence level equals 100*(1 - alpha)%, or in other words, an alpha of 0.05 indicates a 95 percent confidence level.- Returns:
 - double[]; the confidence interval of this tally
 
 
- 
getConfidenceInterval
public final double[] getConfidenceInterval(double alpha, ConfidenceInterval side)returns the confidence interval based of the mean.- Specified by:
 getConfidenceIntervalin interfaceTallyInterface- Parameters:
 alpha- double; Alpha is the significance level used to compute the confidence level. The confidence level equals 100*(1 - alpha)%, or in other words, an alpha of 0.05 indicates a 95 percent confidence level.side- ConfidenceInterval; the side of the confidence interval with respect to the mean- Returns:
 - double[]; the confidence interval of this tally
 
 
- 
getDescription
public final String getDescription()
returns the description of this tally.- Specified by:
 getDescriptionin interfaceBasicTallyInterface- Returns:
 - Sting description
 
 
- 
getMax
public final double getMax()
Returns the max.- Specified by:
 getMaxin interfaceBasicTallyInterface- Returns:
 - double
 
 
- 
getMin
public final double getMin()
Returns the min.- Specified by:
 getMinin interfaceBasicTallyInterface- Returns:
 - double
 
 
- 
getN
public final long getN()
Returns the number of observations.- Specified by:
 getNin interfaceBasicTallyInterface- Returns:
 - long n
 
 
- 
getSampleStDev
public final double getSampleStDev()
Returns the current (unbiased) sample standard deviation of all observations since the initialization. The sample standard deviation is defined as the square root of the sample variance.- Specified by:
 getSampleStDevin interfaceTallyInterface- Returns:
 - double; the sample standard deviation
 
 
- 
getPopulationStDev
public final double getPopulationStDev()
Returns the current (biased) population standard deviation of all observations since the initialization. The population standard deviation is defined as the square root of the population variance.- Specified by:
 getPopulationStDevin interfaceTallyInterface- Returns:
 - double; the population standard deviation
 
 
- 
getSum
public final double getSum()
Return the sum of the values of the observations.- Specified by:
 getSumin interfaceTallyInterface- Returns:
 - double; sum
 
 
- 
getSampleVariance
public final double getSampleVariance()
Returns the current (unbiased) sample variance of all observations since the initialization. The calculation of the sample variance in relation to the population variance is undisputed. The formula is:
S2 = (1 / (n - 1)) * [ Σx2 - (Σx)2 / n ]
which can be calculated on the basis of the calculated population variance σ2 as follows:
S2 = σ2 * n / (n - 1)- Specified by:
 getSampleVariancein interfaceTallyInterface- Returns:
 - double; the current sample variance of this tally
 
 
- 
getPopulationVariance
public final double getPopulationVariance()
Returns the current (biased) population variance of all observations since the initialization. The population variance is defined as:
σ2 = (1 / n) * [ Σx2 - (Σx)2 / n ]- Specified by:
 getPopulationVariancein interfaceTallyInterface- Returns:
 - double; the current population variance of this tally
 
 
- 
getSampleSkewness
public final double getSampleSkewness()
Return the (unbiased) sample skewness of the ingested data. There are different formulas to calculate the unbiased (sample) skewness from the biased (population) skewness. Minitab, for instance calculates unbiased skewness as:
Skewunbiased = Skewbiased [ ( n - 1) / n ] 3/2
whereas SAS, SPSS and Excel calculate it as:
Skewunbiased = Skewbiased √[ n ( n - 1)] / (n - 2)
Here we follow the last mentioned formula. All formulas converge to the same value with larger n.- Specified by:
 getSampleSkewnessin interfaceTallyInterface- Returns:
 - double; the sample skewness of the ingested data
 
 
- 
getPopulationSkewness
public final double getPopulationSkewness()
Return the (biased) population skewness of the ingested data. The population skewness is defined as:
Skewbiased = [ Σ ( x - μ ) 3 ] / [ n . S3 ]
where S2 is the sample variance. So the denominator is equal to [ n . sample_var3/2 ] .- Specified by:
 getPopulationSkewnessin interfaceTallyInterface- Returns:
 - double; the skewness of the ingested data
 
 
- 
getSampleKurtosis
public final double getSampleKurtosis()
Return the sample kurtosis of the ingested data. The sample kurtosis can be defined in multiple ways. Here, we choose the following formula:
Kurtunbiased = [ Σ ( x - μ ) 4 ] / [ ( n - 1 ) . S4 ]
where S2 is the sample variance. So the denominator is equal to [ ( n - 1 ) . sample_var2 ] .- Specified by:
 getSampleKurtosisin interfaceTallyInterface- Returns:
 - double; the sample kurtosis of the ingested data
 
 
- 
getPopulationKurtosis
public final double getPopulationKurtosis()
Return the (biased) population kurtosis of the ingested data. The population kurtosis is defined as:
Kurtbiased = [ Σ ( x - μ ) 4 ] / [ n . σ4 ]
where σ2 is the population variance. So the denominator is equal to [ n . pop_var2 ] .- Specified by:
 getPopulationKurtosisin interfaceTallyInterface- Returns:
 - double; the population kurtosis of the ingested data
 
 
- 
getSampleExcessKurtosis
public final double getSampleExcessKurtosis()
Return the sample excess kurtosis of the ingested data. The sample excess kurtosis is the sample-corrected value of the excess kurtosis. Several formulas exist to calculate the sample excess kurtosis from the population kurtosis. Here we use:
ExcessKurtunbiased = ( n - 1 ) / [( n - 2 ) * ( n - 3 )] [ ( n + 1 ) * ExcessKurtbiased + 6]
This is the excess kurtosis that is calculated by, for instance, SAS, SPSS and Excel.- Specified by:
 getSampleExcessKurtosisin interfaceTallyInterface- Returns:
 - double; the sample excess kurtosis of the ingested data
 
 
- 
getPopulationExcessKurtosis
public final double getPopulationExcessKurtosis()
Return the population excess kurtosis of the ingested data. The kurtosis value of the normal distribution is 3. The excess kurtosis is the kurtosis value shifted by -3 to be 0 for the normal distribution.- Specified by:
 getPopulationExcessKurtosisin interfaceTallyInterface- Returns:
 - double; the population excess kurtosis of the ingested data
 
 
- 
initialize
public void initialize()
initializes the Tally. This methods sets the max, min, n, sum and variance values to their initial values.- Specified by:
 initializein interfaceBasicTallyInterface
 
- 
notify
public void notify(EventInterface event)
- Specified by:
 notifyin interfaceEventListenerInterface
 
- 
ingest
public double ingest(double value)
Process one observed value.- Specified by:
 ingestin interfaceTallyInterface- Parameters:
 value- double; the value to process- Returns:
 - double; the value
 
 
- 
fireEvents
protected void fireEvents()
Method that can be overridden to fire own events or additional events when ingesting an observation. 
 - 
 
 -