Package jasima.core.statistics
Class SummaryStat
- java.lang.Object
-
- jasima.core.statistics.SummaryStat
-
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
QuantileEstimator,SamplingSummaryStat,TimeWeightedSummaryStat
public class SummaryStat extends Object implements Serializable, Cloneable
Class to collect the most important statistics without having to store all values encountered. It can return mean, standard deviation, variance, min, max etc. in O(1) time. Values are passed by calling thevalue(double)method. Values can be weighted, just callvalue(double, double)instead.In other simulation packages this is sometimes called "tally".
This implementation is based on: D. H. D. West (1979). Communications of the ACM, 22, 9, 532-535: Updating Mean and Variance Estimates: An Improved Method
- Author:
- Torsten Hildebrandt
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static doubleDEF_ERROR_PROBprotected doublelastValueprotected doublelastWeight
-
Constructor Summary
Constructors Constructor Description SummaryStat()SummaryStat(SummaryStat vs)Create a new SummaryStat-object initialized with the values of "vs".
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Resets this object.SummaryStatclone()Clones this object.SummaryStatcombine(SummaryStat other)Combines the data inotherwith this SummaryStat-Object.static SummaryStatcombine(SummaryStat stats1, SummaryStat stats2)Creates a newSummaryStatobject that behaves if all values seen bystats1andstats2would have been passed to it.doubleconfidenceIntervalLower()doubleconfidenceIntervalLower(double errorProb)doubleconfidenceIntervalUpper()doubleconfidenceIntervalUpper(double errorProb)doubleconfIntRangeSingle(double errorProb)doublelastValue()Returns the last value passed tovalue(double)orvalue(double, double).doublelastWeight()Returns the weight of the last value passed tovalue(double)orvalue(double, double).doublemax()Returns the maximum value seen so far.doublemean()Returns the mean of all values given tovalue(double).doublemin()Returns the minimum value seen so far.intnumObs()Returns the number of times,value(double)orvalue(double, double)were called.doublestdDev()The standard deviation of all values.doublesum()Returns the sum of allvalue(double)s (taking into account potential weights ifvalue(double, double)is used).static SummaryStatsummarize(double... values)This method creates a newSummaryStatobject and passes all values to it.static SummaryStatsummarize(int... values)This method creates a newSummaryStatobject and passes all values to it.SummaryStatvalue(double v)Adds the given value with a weight of 1.SummaryStatvalue(double v, double weight)Adds a value with a given weight.SummaryStatvalues(double... vs)Convenience method to add all values given as arguments with a weight of 1.doublevarCoeff()doublevariance()Returns the sample variance of the values.doublevariancePopulation()Returns the population variance of the values.doubleweightSum()Returns the sum of all weights.
-
-
-
Field Detail
-
DEF_ERROR_PROB
protected static final double DEF_ERROR_PROB
- See Also:
- Constant Field Values
-
lastValue
protected double lastValue
-
lastWeight
protected double lastWeight
-
-
Constructor Detail
-
SummaryStat
public SummaryStat()
-
SummaryStat
public SummaryStat(SummaryStat vs)
Create a new SummaryStat-object initialized with the values of "vs". Copy constructor.
-
-
Method Detail
-
clear
public void clear()
Resets this object.
-
values
public SummaryStat values(double... vs)
Convenience method to add all values given as arguments with a weight of 1.- Parameters:
vs- The values to add.- Returns:
this, to allow easy chaining of calls.
-
value
public SummaryStat value(double v)
Adds the given value with a weight of 1.- Parameters:
v- The value to add.- Returns:
this, to allow easy chaining of calls.
-
value
public SummaryStat value(double v, double weight) throws IllegalArgumentException
Adds a value with a given weight.- Parameters:
v- The value to add.weight- The weight to give to this value. Has to be positive.- Returns:
this, to allow easy chaining of calls.- Throws:
IllegalArgumentException- If weight was negative.
-
mean
public double mean()
Returns the mean of all values given tovalue(double).- Returns:
- The arithmetic mean of all values seen so far.
-
stdDev
public double stdDev()
The standard deviation of all values.- Returns:
- The standard deviation of all values given to
value(double).
-
variance
public double variance()
Returns the sample variance of the values.- Returns:
- The (sample) variance of all values given to
value(double). Returns NaN, if no values were added yet.
-
variancePopulation
public double variancePopulation()
Returns the population variance of the values.- Returns:
- The (sample) variance of all values given to
value(double). Returns NaN, if no values were added yet.
-
varCoeff
public double varCoeff()
- Returns:
- The coefficient of variation.
-
sum
public double sum()
Returns the sum of allvalue(double)s (taking into account potential weights ifvalue(double, double)is used).- Returns:
- The sum of all values.
-
weightSum
public double weightSum()
Returns the sum of all weights. If onlyvalue(double)is used, then the value returned is identical to the value returned bynumObs.- Returns:
- The weight sum.
-
numObs
public int numObs()
Returns the number of times,value(double)orvalue(double, double)were called.- Returns:
- The number of calls to
value(double)orvalue(double, double).
-
min
public double min()
Returns the minimum value seen so far.- Returns:
- The minimum value seen so far, or NaN, if no values were given so far.
-
max
public double max()
Returns the maximum value seen so far.- Returns:
- The maximum value seen so far, or NaN, if no values were given so far.
-
combine
public SummaryStat combine(SummaryStat other)
Combines the data inotherwith this SummaryStat-Object. The combined object behaves as if it had also seen the data of "other".- Parameters:
other- TheSummaryStatto combine with this object.- Returns:
- Returns
thisto allow easy chaining of calls.
-
clone
public SummaryStat clone()
Clones this object. We can use the standard functionality here, as there are only primitive fields.- Overrides:
clonein classObject- Returns:
- A clone of this
SummaryStat.
-
confidenceIntervalLower
public double confidenceIntervalLower()
- Returns:
- lower value of a confidence interval with a 0.95-confidence level
-
confidenceIntervalUpper
public double confidenceIntervalUpper()
-
confidenceIntervalLower
public double confidenceIntervalLower(double errorProb)
-
confidenceIntervalUpper
public double confidenceIntervalUpper(double errorProb)
-
confIntRangeSingle
public double confIntRangeSingle(double errorProb)
-
lastValue
public double lastValue()
Returns the last value passed tovalue(double)orvalue(double, double).- Returns:
- The last value, or NaN if no
numObs==0.
-
lastWeight
public double lastWeight()
Returns the weight of the last value passed tovalue(double)orvalue(double, double).- Returns:
- The last value's weight, or NaN if no
numObs==0.
-
summarize
public static SummaryStat summarize(double... values)
This method creates a newSummaryStatobject and passes all values to it.- Parameters:
values- The values to use.- Returns:
- A
SummaryStatsummarizing the values.
-
summarize
public static SummaryStat summarize(int... values)
This method creates a newSummaryStatobject and passes all values to it.- Parameters:
values- The values to use.- Returns:
- A
SummaryStatsummarizing the values.
-
combine
public static SummaryStat combine(SummaryStat stats1, SummaryStat stats2)
Creates a newSummaryStatobject that behaves if all values seen bystats1andstats2would have been passed to it.- Parameters:
stats1-SummaryStatsummarizing first set of values.stats2-SummaryStatsummarizing second set of values.- Returns:
- New
SummaryStatobject summarizing the union of first and second value set.
-
-