Package jsl.utilities.statistic
Class CachedHistogram
- java.lang.Object
- 
- jsl.utilities.statistic.AbstractCollector
- 
- jsl.utilities.statistic.AbstractStatistic
- 
- jsl.utilities.statistic.CachedHistogram
 
 
 
- 
- All Implemented Interfaces:
- java.lang.Comparable<AbstractStatistic>,- GetNameIfc,- IdentityIfc,- ArraySaverIfc,- CollectorIfc,- GetCSVStatisticIfc,- StatisticAccessorIfc
 
 public class CachedHistogram extends AbstractStatistic A CachedHistogram allow collection and forming of a histogram without pre-specifying the number of bins. It works by using an initial cache of the data to determine a reasonable number of bins and bin width based on the observed minimum and maximum of the data within the cache. Once the cache is observed, this class works essentially like a Histogram, which can be returned via the getHistogram() method.
- 
- 
Field SummaryFields Modifier and Type Field Description static intDEFAULT_CACHE_SIZEprotected StatisticmyCacheStatisticCollects statistical information on the data during cachingprotected booleanmyCachingFlagFlag indicating the histogram is caching values to compute adequate range.protected intmyCountCacheCounts number of observations in the cacheprotected double[]myDataCacheCache for accumulated values.protected HistogrammyHistogramCollects histogram statistics after caching is doneprotected intmyNumBinsThe number of bins for the histogram- 
Fields inherited from class jsl.utilities.statistic.AbstractStatisticDEFAULT_CONFIDENCE_LEVEL, myConfidenceLevel, myNumMissing
 - 
Fields inherited from interface jsl.utilities.statistic.ArraySaverIfcDEFAULT_DATA_ARRAY_SIZE
 
- 
 - 
Constructor SummaryConstructors Constructor Description CachedHistogram()Creates a CachedHistogram using the DEFAULT_CACHE_SIZE by determining a reasonable number of binsCachedHistogram(int cacheSize)Creates a CachedHistogram by determining a reasonable number of binsCachedHistogram(int cacheSize, int numBins)Creates a CachedHistogramCachedHistogram(int cacheSize, int numBins, java.lang.String name)Creates a CachedHistogramCachedHistogram(int cacheSize, java.lang.String name)Creates a CachedHistogram by determining a reasonable number of binsCachedHistogram(java.lang.String name)Creates a CachedHistogram using the DEFAULT_CACHE_SIZE by determining a reasonable number of bins
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcollect(double x)Collect on the supplied valueprotected voidcollectOnCache()When the cache is full this method is called to form the histogramdoublegetAverage()Gets the unweighted average of the observations.doublegetConfidenceLevel()Gets the confidence level.doublegetCount()Gets the count of the number of the observations.doublegetDeviationSumOfSquares()Gets the sum of squares of the deviations from the average This is the numerator in the classic sample variance formuladoublegetHalfWidth(double alpha)Gets the confidence interval half-width.HistogramgetHistogram()Returns a histogram based on the data or null if the cache limit has not been reached.doublegetKurtosis()Gets the kurtosis of the datadoublegetLag1Correlation()Gets the lag-1 generate correlation of the unweighted observations.doublegetLag1Covariance()Gets the lag-1 generate covariance of the unweighted observations.doublegetLastValue()Gets the last observed data pointintgetLeadingDigitRule(double a)Computes the right most meaningful digit according to (int)Math.floor(Math.log10(a*getStandardError())) See doi 10.1287.opre.1080.0529 by Song and SchmeiserdoublegetMax()Gets the maximum of the observations.doublegetMin()Gets the minimum of the observations.doublegetSkewness()Gets the skewness of the datadoublegetStandardDeviation()Gets the sample standard deviation of the observations.doublegetStandardError()Gets the standard error of the observations.doublegetSum()Gets the sum of the observations.doublegetVariance()Gets the sample variance of the observations.doublegetVonNeumannLag1TestStatistic()Gets the Von Neumann Lag 1 test statistic for checking the hypothesis that the data are uncorrelated Note: See Handbook of Simulation, Jerry Banks editor, McGraw-Hill, pg 253.doublegetVonNeumannLag1TestStatisticPValue()Returns the asymptotic p-value for the Von Nueumann Lag-1 Test Statistic:static voidmain(java.lang.String[] args)voidreset()Resets the collector as if no observations had been collected.java.lang.StringtoString()Returns a String representation of the Statistic- 
Methods inherited from class jsl.utilities.statistic.AbstractStatisticcompareTo, getNumberMissing, setConfidenceLevel
 - 
Methods inherited from class jsl.utilities.statistic.AbstractCollectorclearSavedData, getId, getName, getSavedData, getSaveOption, save, save, setArraySizeIncrement, setName, setSaveOption
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface jsl.utilities.statistic.CollectorIfccollect, collect, collect
 - 
Methods inherited from interface jsl.utilities.statistic.StatisticAccessorIfcgetConfidenceInterval, getConfidenceInterval, getCSVHeader, getCSVStatistic, getCSVStatisticHeader, getCSVValues, getHalfWidth, getName, getRelativeError, getRelativeWidth, getRelativeWidth, getStatistics, getStatisticsAsMap
 
- 
 
- 
- 
- 
Field Detail- 
DEFAULT_CACHE_SIZEpublic static final int DEFAULT_CACHE_SIZE - See Also:
- Constant Field Values
 
 - 
myNumBinsprotected int myNumBins The number of bins for the histogram
 - 
myCachingFlagprotected boolean myCachingFlag Flag indicating the histogram is caching values to compute adequate range.
 - 
myCountCacheprotected int myCountCache Counts number of observations in the cache
 - 
myDataCacheprotected double[] myDataCache Cache for accumulated values.
 - 
myCacheStatisticprotected Statistic myCacheStatistic Collects statistical information on the data during caching
 - 
myHistogramprotected Histogram myHistogram Collects histogram statistics after caching is done
 
- 
 - 
Constructor Detail- 
CachedHistogrampublic CachedHistogram() Creates a CachedHistogram using the DEFAULT_CACHE_SIZE by determining a reasonable number of bins
 - 
CachedHistogrampublic CachedHistogram(java.lang.String name) Creates a CachedHistogram using the DEFAULT_CACHE_SIZE by determining a reasonable number of bins- Parameters:
- name- the name of the histogram
 
 - 
CachedHistogrampublic CachedHistogram(int cacheSize, java.lang.String name)Creates a CachedHistogram by determining a reasonable number of bins- Parameters:
- cacheSize- The size of the cache for initializing the histogram
- name- the name of the histogram
 
 - 
CachedHistogrampublic CachedHistogram(int cacheSize) Creates a CachedHistogram by determining a reasonable number of bins- Parameters:
- cacheSize- The size of the cache for initializing the histogram
 
 - 
CachedHistogrampublic CachedHistogram(int cacheSize, int numBins)Creates a CachedHistogram- Parameters:
- cacheSize- The size of the cache for initializing the histogram
- numBins- The number of desired bins, must be >=0, if zero a reasonable number of bins is automatically determined
 
 - 
CachedHistogrampublic CachedHistogram(int cacheSize, int numBins, java.lang.String name)Creates a CachedHistogram- Parameters:
- cacheSize- The size of the cache for initializing the histogram
- numBins- The number of desired bins, must be >=0, if zero a reasonable number of bins is automatically determined
- name- the name of the histogram
 
 
- 
 - 
Method Detail- 
getHistogrampublic final Histogram getHistogram() Returns a histogram based on the data or null if the cache limit has not been reached.- Returns:
- the histogram
 
 - 
collectpublic final void collect(double x) Description copied from interface:CollectorIfcCollect on the supplied value- Parameters:
- x- a double representing the observation
 
 - 
collectOnCacheprotected final void collectOnCache() When the cache is full this method is called to form the histogram
 - 
getAveragepublic final double getAverage() Description copied from interface:StatisticAccessorIfcGets the unweighted average of the observations.- Returns:
- A double representing the average or Double.NaN if no observations.
 
 - 
getConfidenceLevelpublic final double getConfidenceLevel() Description copied from interface:StatisticAccessorIfcGets the confidence level. The default is given by Statistic.DEFAULT_CONFIDENCE_LEVEL = 0.95, which is a 95% confidence level- Specified by:
- getConfidenceLevelin interface- StatisticAccessorIfc
- Overrides:
- getConfidenceLevelin class- AbstractStatistic
- Returns:
- A double representing the confidence level
 
 - 
getCountpublic final double getCount() Description copied from interface:StatisticAccessorIfcGets the count of the number of the observations.- Returns:
- A double representing the count
 
 - 
getDeviationSumOfSquarespublic final double getDeviationSumOfSquares() Description copied from interface:StatisticAccessorIfcGets the sum of squares of the deviations from the average This is the numerator in the classic sample variance formula- Returns:
- A double representing the sum of squares of the deviations from the average
 
 - 
getHalfWidthpublic final double getHalfWidth(double alpha) Description copied from interface:StatisticAccessorIfcGets the confidence interval half-width. Simply the generate standard error times the confidence coefficient as determined by an appropriate sampling distribution- Parameters:
- alpha- the confidence level
- Returns:
- A double representing the half-width or Double.NaN if < 1 observation
 
 - 
getKurtosispublic final double getKurtosis() Description copied from interface:StatisticAccessorIfcGets the kurtosis of the data- Returns:
- A double representing the kurtosis
 
 - 
getLag1Correlationpublic final double getLag1Correlation() Description copied from interface:StatisticAccessorIfcGets the lag-1 generate correlation of the unweighted observations. Note: See Box, Jenkins, Reinsel, Time Series Analysis, 3rd edition, Prentice-Hall, pg 31- Returns:
- A double representing the generate correlation or Double.NaN if <=2 observations
 
 - 
getLag1Covariancepublic final double getLag1Covariance() Description copied from interface:StatisticAccessorIfcGets the lag-1 generate covariance of the unweighted observations. Note: See Box, Jenkins, Reinsel, Time Series Analysis, 3rd edition, Prentice-Hall, pg 31- Returns:
- A double representing the generate covariance or Double.NaN if <=2 observations
 
 - 
getLastValuepublic final double getLastValue() Description copied from interface:StatisticAccessorIfcGets the last observed data point- Returns:
- A double representing the last observations
 
 - 
getMaxpublic final double getMax() Description copied from interface:StatisticAccessorIfcGets the maximum of the observations.- Returns:
- A double representing the maximum
 
 - 
getMinpublic final double getMin() Description copied from interface:StatisticAccessorIfcGets the minimum of the observations.- Returns:
- A double representing the minimum
 
 - 
getSkewnesspublic final double getSkewness() Description copied from interface:StatisticAccessorIfcGets the skewness of the data- Returns:
- A double representing the skewness
 
 - 
getStandardDeviationpublic final double getStandardDeviation() Description copied from interface:StatisticAccessorIfcGets the sample standard deviation of the observations. Simply the square root of getVariance()- Returns:
- A double representing the generate standard deviation or Double.NaN if 1 or less observations.
 
 - 
getStandardErrorpublic final double getStandardError() Description copied from interface:StatisticAccessorIfcGets the standard error of the observations. Simply the generate standard deviation divided by the square root of the number of observations- Returns:
- A double representing the standard error or Double.NaN if < 1 observation
 
 - 
getSumpublic final double getSum() Description copied from interface:StatisticAccessorIfcGets the sum of the observations.- Returns:
- A double representing the unweighted sum
 
 - 
getVariancepublic final double getVariance() Description copied from interface:StatisticAccessorIfcGets the sample variance of the observations.- Returns:
- A double representing the generate variance or Double.NaN if 1 or less observations.
 
 - 
getVonNeumannLag1TestStatisticpublic final double getVonNeumannLag1TestStatistic() Description copied from interface:StatisticAccessorIfcGets the Von Neumann Lag 1 test statistic for checking the hypothesis that the data are uncorrelated Note: See Handbook of Simulation, Jerry Banks editor, McGraw-Hill, pg 253.- Returns:
- A double representing the Von Neumann test statistic
 
 - 
getVonNeumannLag1TestStatisticPValuepublic final double getVonNeumannLag1TestStatisticPValue() Description copied from interface:StatisticAccessorIfcReturns the asymptotic p-value for the Von Nueumann Lag-1 Test Statistic:Normal.stdNormalComplementaryCDF(getVonNeumannLag1TestStatistic()); - Returns:
- the p-value
 
 - 
getLeadingDigitRulepublic final int getLeadingDigitRule(double a) Description copied from interface:StatisticAccessorIfcComputes the right most meaningful digit according to (int)Math.floor(Math.log10(a*getStandardError())) See doi 10.1287.opre.1080.0529 by Song and Schmeiser- Parameters:
- a- the std error multiplier
- Returns:
- the meaningful digit
 
 - 
resetpublic final void reset() Description copied from interface:CollectorIfcResets the collector as if no observations had been collected.
 - 
toStringpublic java.lang.String toString() Description copied from interface:StatisticAccessorIfcReturns a String representation of the Statistic- Specified by:
- toStringin interface- StatisticAccessorIfc
- Overrides:
- toStringin class- java.lang.Object
- Returns:
- A String with basic summary statistics
 
 - 
mainpublic static void main(java.lang.String[] args) - Parameters:
- args-
 
 
- 
 
-