Class DynamicDataAnalyzerImpl
java.lang.Object
dataAnalysis.DynamicDataAnalyzerImpl
- All Implemented Interfaces:
DynamicDataAnalyzer
- Direct Known Subclasses:
QuantileDataAnalyzer
Dynamic data analyzer of the JSIM engine. It removes the initial transient of
the measured samples using the R5 heuristic [Fis73] and the MSER-5 stationarity
rule [Spr98], and then generates the confidence intervals with the spectral
method [HW81], as described in the JSIM chapters of the JMT user manual.
In detail, this class can remove the initial
transient period and performs calculation of variance and confidence
interval of the sample mean of a sequence.
It is robust to data correlation.
See:
(1) K. Pawlikowski, "SteadyState Simulation of Queueing Processes: A Survey
of Problems and Solutions", ACM Computing Surveys 22, 2 (1990), pp. 122--170
- Version:
- Modified 7/02/2003
- Author:
- Federico Granata, Bertoli Marco - Bugfixing statistical part (R5 and Schruben) 18-11-2005
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doublethe quantile required for the confidence intervalprotected intnumber of samples per batchprotected double[]mean of batchesprotected doubleconstant chosen to reduce bias of variance estimatorprotected intdegrees of freedom of the t-distributionprotected doublethe estimated confidence intervalsprotected booleanTransient period has been deleted or notprotected intprotected intnumber of discarded data in deleting transient periodprotected booleanend = true if the analysis has been completed (successfully or not)intFirst estimate of transient length: this number of samples is identified by the heuristic testprotected doublethe estimated meanprotected doublethe estimated varianceprotected booleanheuristic = true if the heuristic rule for startup period is successful.protected DoubleArrayListstarting data, not steady stateprotected intnumber of data that are replaced when detect initial test fails.protected booleaninitialized = true if the system is in steady stateprotected DoubleArrayListstarting weights, not steady stateprotected intnumber of points of the polyfitprotected intmaximum number of data to be collectedprotected intactual number of samplesprotected intnumber of batchesprotected SimParametersprotected intthe order of the polynomialprotected doublemaximum amplitude of confidence intervalprotected booleansuccess = true if the analysis is successful, the required precision has been metprotected doublethe sum of samples of the last batchprotected double[]mean of batches weighted -
Constructor Summary
ConstructorsConstructorDescriptionDynamicDataAnalyzerImpl(double alfa, double precision, int maxData) Creates a new DynamicDataAnalyzer -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddSample(double newSample, double weight) Adds the new sample to the statistic.protected voidupdates the conf intervalsdouble[]calcConstants(int K, int polyOrder) computes the degrees of freedom of the tStudent distribution used in the estimation of variance and confidence intervals C2, and a constant used to depolarize the variance estimatorprotected doublecalcEstimatorVar(int K, int polyOrder) computes the variance of the estimator of the varianceprotected voidcalcVar()updates the variancedoublecalcVar(double[] data, int start, int n, int K, int polyOrder) calculates the variance through Heidelberger & Welch method, if the data are the means of batches of size batchLen, the variance must be multiplied by batchLen.protected booleanApply the heuristic rule MSR5 to discard the most biased samples of the time series.doubleGets the estimated mean, even if the confidence requirements have not been reacheddoublegetAlfa()gets the actual requested alpha of the analyzerdoublegets the half width confidence interval estimated of the monitored data stream.double[]getData()Gets the batch means.intgets the number of discarded data.doubleThis method return inverse of the instantaneous valueintgets the maximum number of samples that can be analyzed.doublegetMean()gets the mean estimated of the monitored data streamdoubleThis method should be called only if mean is equal to zero (@see isZero()), that is when nullTest() returns true.doublegets the actual requested precision of the analyzerintnumber of samples elaborated up to nowbooleantrue if the analysis is successfuldoublegetVar()gets the variance estimated of the monitored data streamprotected booleanheuristicR5(double newSample, double Weight) It uses the heuristic rule R5.protected booleanHWtest()Applies the spectral test to generate the Confidence Intervals.booleanisZero()Returns true if null test has found out that this measure is zeroprotected booleannullTest()Verifies whether the measure is almost always equal to zeroprotected booleanschrubenTest(double newSample, double Weight) inserts a new value of the sequence, and detects when the initial transient period has ended.voidsetParameters(SimParameters parameters) Sets the reference to the class containing simulation parameters.voidstopMeasure(boolean success) Stops the measuring processtoString()creates a string of the principals parameters calculated
-
Field Details
-
parameters
-
numBatch
protected int numBatchnumber of batches -
batchLen
protected int batchLennumber of samples per batch -
batchMean
protected double[] batchMeanmean of batches -
weightBatchMean
protected double[] weightBatchMeanmean of batches weighted -
extMean
protected double extMeanthe estimated mean -
extVar
protected double extVarthe estimated variance -
confInt
protected double confIntthe estimated confidence intervals -
sumLastBatch
protected double sumLastBatchthe sum of samples of the last batch -
nSamples
protected int nSamplesactual number of samples -
maxData
protected int maxDatamaximum number of data to be collected -
C1
protected double C1constant chosen to reduce bias of variance estimator -
C2
protected int C2degrees of freedom of the t-distribution -
alfa
protected double alfathe quantile required for the confidence interval -
precision
protected double precisionmaximum amplitude of confidence interval -
initData
starting data, not steady state -
initWeight
starting weights, not steady state -
deleted
protected boolean deletedTransient period has been deleted or not -
initialized
protected boolean initializedinitialized = true if the system is in steady state -
end
protected boolean endend = true if the analysis has been completed (successfully or not) -
success
protected boolean successsuccess = true if the analysis is successful, the required precision has been met -
heuristic
protected boolean heuristicheuristic = true if the heuristic rule for startup period is successful. -
discarded
protected int discardednumber of discarded data in deleting transient period -
initial
protected int initialnumber of data that are replaced when detect initial test fails. -
delta
protected int delta -
K
protected int Knumber of points of the polyfit -
polyOrder
protected int polyOrderthe order of the polynomial -
eurDisc
public int eurDiscFirst estimate of transient length: this number of samples is identified by the heuristic test
-
-
Constructor Details
-
DynamicDataAnalyzerImpl
public DynamicDataAnalyzerImpl(double alfa, double precision, int maxData) Creates a new DynamicDataAnalyzer- Parameters:
alfa- the quantile required for the confidence intervalprecision- maximum amplitude of confidence interval (precision = maxamplitude / mean )maxData- maximum number of data to be analyzed (at least 5000)
-
-
Method Details
-
addSample
public boolean addSample(double newSample, double weight) Adds the new sample to the statistic.- Specified by:
addSamplein interfaceDynamicDataAnalyzer- Parameters:
newSample- the new sampleweight- the weight of the newSample, if it is not needed put 1.- Returns:
- true if the computation of confidence interval has finished (i.e. if the confidence interval is smaller than the one required by the user, or if the analyzed data are too many), false otherwise
-
heuristicR5
protected boolean heuristicR5(double newSample, double Weight) It uses the heuristic rule R5. Inserts a new value of the sequence, and approximately detects the initial transient period.
See
K. Pawlikowski "SteadyState Simulation of Queueing Processes: A Survey of Problems and Solutions" ACM Computing Surveys 22, 2 (1990), pp. 122--170. -
schrubenTest
protected boolean schrubenTest(double newSample, double Weight) inserts a new value of the sequence, and detects when the initial transient period has ended. -
deleteTransient
protected boolean deleteTransient()Apply the heuristic rule MSR5 to discard the most biased samples of the time series. It minimizes the Mean Square Error. -
HWtest
protected boolean HWtest()Applies the spectral test to generate the Confidence Intervals.
See:
P. Heidelberger,Peter D. Welch
"A spectral method for confidence interval generation and run length control in simulations"- Returns:
- true if the precision requirement is reached. false if not.
-
calcVar
protected void calcVar()updates the variance -
toString
-
getSamples
public int getSamples()number of samples elaborated up to now- Specified by:
getSamplesin interfaceDynamicDataAnalyzer- Returns:
- number of samples
-
getMean
public double getMean()gets the mean estimated of the monitored data stream- Specified by:
getMeanin interfaceDynamicDataAnalyzer- Returns:
- the mean
-
getVar
public double getVar()gets the variance estimated of the monitored data stream- Returns:
- the variance
-
getConfInt
public double getConfInt()gets the half width confidence interval estimated of the monitored data stream.- Specified by:
getConfIntin interfaceDynamicDataAnalyzer- Returns:
- the confidence interval requested
-
getSuccess
public boolean getSuccess()true if the analysis is successful- Specified by:
getSuccessin interfaceDynamicDataAnalyzer- Returns:
- true if the analysis respect all'users requests
-
calcVar
public double calcVar(double[] data, int start, int n, int K, int polyOrder) calculates the variance through Heidelberger & Welch method, if the data are the means of batches of size batchLen, the variance must be multiplied by batchLen.- Parameters:
data- array containing the sequence of datastart- the starting samplen- number of data of the sequence to be estimatedK- number of points used in the polynomial fitting must be <= n/4, typically is 25, 50polyOrder- the order of the polynomial to be fitted to the getLog of the spectrum of data typically is 2 or 3.- Returns:
- the estimated variance
-
calcConstants
public double[] calcConstants(int K, int polyOrder) computes the degrees of freedom of the tStudent distribution used in the estimation of variance and confidence intervals C2, and a constant used to depolarize the variance estimator- Parameters:
K- number of points of the polyfitpolyOrder- the order of the polynomial- Returns:
- the double array of dimension 2, at first position it is C1 and at second C2
-
calcEstimatorVar
protected double calcEstimatorVar(int K, int polyOrder) computes the variance of the estimator of the variance -
calcConfInterval
protected void calcConfInterval()updates the conf intervals -
getPrecision
public double getPrecision()gets the actual requested precision of the analyzer- Specified by:
getPrecisionin interfaceDynamicDataAnalyzer- Returns:
- the precision
-
getAlfa
public double getAlfa()gets the actual requested alpha of the analyzer- Specified by:
getAlfain interfaceDynamicDataAnalyzer- Returns:
- the alpha
-
getMaxData
public int getMaxData()gets the maximum number of samples that can be analyzed.- Specified by:
getMaxDatain interfaceDynamicDataAnalyzer- Returns:
- maxData
-
getDiscarded
public int getDiscarded()gets the number of discarded data.- Specified by:
getDiscardedin interfaceDynamicDataAnalyzer- Returns:
- discarded data
-
getData
public double[] getData()Gets the batch means. If the data is not over the transient period returns null.- Returns:
- batch means
-
nullTest
protected boolean nullTest()Verifies whether the measure is almost always equal to zero- Returns:
- true if the measure is almost always equal to zero
-
isZero
public boolean isZero()Returns true if null test has found out that this measure is zero- Specified by:
isZeroin interfaceDynamicDataAnalyzer- Returns:
- true if null test has found out that this measure is zero
-
getNullMeasure_upperLimit
public double getNullMeasure_upperLimit()This method should be called only if mean is equal to zero (@see isZero()), that is when nullTest() returns true.- Specified by:
getNullMeasure_upperLimitin interfaceDynamicDataAnalyzer- Returns:
- the upper limit of confidence interval when mean is equal to 0.0
-
estimatedMean
public double estimatedMean()Gets the estimated mean, even if the confidence requirements have not been reached- Specified by:
estimatedMeanin interfaceDynamicDataAnalyzer- Returns:
- the estimated mean
-
stopMeasure
public void stopMeasure(boolean success) Stops the measuring process- Specified by:
stopMeasurein interfaceDynamicDataAnalyzer- Parameters:
success- value to be reported by getSuccess()
-
setParameters
Sets the reference to the class containing simulation parameters. The parameters are updated with the passed values.- Specified by:
setParametersin interfaceDynamicDataAnalyzer- Parameters:
parameters-
-
getLastIntervalAvg
public double getLastIntervalAvg()Description copied from interface:DynamicDataAnalyzerThis method return inverse of the instantaneous value- Specified by:
getLastIntervalAvgin interfaceDynamicDataAnalyzer
-