This module contains the Measurement Handler library functions. The purpose of the library is to provide the user with commonly used statistical functions.
SampleList = [number()]
Result = SampleSum | {error, Reason}
SampleSum = number()
Reason = term()
This function adds up a list of measurement samples.
sum_and_squaresum(SampleList) -> Result
SampleList = [number()]
Result = {SampleSum, SampleSquareSum} | {error, Reason}
SampleSum = SampleSquareSum = number()
Reason = term()
This function adds up a list of measurement samples, and also sums the square of each sample.
sample_mean(SampleList) -> Result
SampleList = [number()]
Result = EstimatedSampleMean | {error, Reason}
EstimatedSampleMean = number()
Reason = term()
Suppose that [X1, X2, X3, ..., Xn] are random variables (observations)
with finite population mean u.
The sample mean estimation m(n) = (X1 + X2 + X3 + ... +Xn) / n
sample_variance(SampleList) -> Result
SampleList = [number()]
Result = EstimatedSampleVariance | {error, Reason}
EstimatedSampleVariance = number()
Reason = term()
Suppose that [X1, X2, X3, ..., Xn] are random variables
(observations) with finite population mean u and finite
population variance V, and sample mean estimate m(n).
The sample variance estimation
S^2(n) = ((X1 - m(n))^2 + (X2 - m(n))^2 + ... + (Xn - m(n))^2) / (n - 1) =
= (X1^2 + X2^2 + ... + Xn^2 - (n * m(n)^2)) / (n - 1)
sample_mean_and_variance(SampleList) -> Result
SampleList = [number()]
Result = {EstimatedSampleMean, EstimatedSampleVariance} | {error, Reason}
EstimatedSampleMean = EstimatedSampleVariance = number()
Reason = term()
Suppose that [X1, X2, X3, ..., Xn] are random variables
(observations) with a finite population mean u with a finite
population variance V, and a sample mean estimate m(n).
The sample mean estimation m(n) = (X1 + X2 + X3 + ... +Xn) / n
The sample variance estimation
S^2(n) = ((X1 - m(n))^2 + (X2 - m(n))^2 + ... + (Xn - m(n))^2) / (n - 1) =
= (X1^2 + X2^2 + ... + Xn^2 - (n * m(n)^2)) / (n - 1)
mean_variance(MeanList) -> Result
MeanList = [EstimatedMeans]
EstimatedMeans = number()
Result = MeanVariance | {error, Reason}
MeanVariance = number()
Reason = term()
Suppose that [X1, X2, X3, ..., Xn] are independent random variables with a finite population mean u, a finite population variance V, and a sample mean estimate m(n). The variance of the estimated mean may be equated through the formula Var(m(n)) = S^2(n) / n NOTE: This formula is valid only if all Xi's are independent (uncorrelated)!!! This is normally not the case in simulations.
ewma_mean(Xnew, Wn, GP, MTP) -> Result
Xnew = Wn = GP = MTP = number()
Result = EstimatedMean | {error, Reason
EstimatedMean = number()
Reason = term()
This function computes the mean of a number of samples using the Exponentially Weighted Moving Average technique. Suppose that [X1, X2, X3, ..., Xn] are random variables (observations) with finite population mean u. Assume we have previously equated a mean value estimate Wn (where W0 may have been simply estimated). Let GP denote the granularity period, ie., the time elapsed between any two successive sample measurements, and let MTP denote the moving time period, ie., the time within which samples are considered. (For example, let GP be 5 ms, and MTP 1 s, which means that the EWMA mean will be based on 200 samples.) When we receive a new sample Xnew, the new estimate of the mean will be Wnew = f * Xnew + (1 - f) * Wn, where f = 2 * GP / (GP + MTP)
ewma_variance(Xnew, Wnew, Sn, GP, SMTP) -> Result
Xnew = Wnew = Sn = GP = SMTP = number()
Result = EstimatedVariance | {error, Reason
EstimatedVariance = number()
Reason = term()
This function computes the variance of a number of samples using the Exponentially Weighted Moving Average technique. Suppose that [X1, X2, X3, ..., Xn] are random variables (observations) with a finite population mean u. Also assume we have previously computed a variance value estimate Sn (where S0 may have been simply calculated). Let GP denote the granularity period, ie., the time elapsed between any two successive sample measurements. Also, let SMTP denote the second moving time period, ie., the effective time interval over which values are scanned to calculate an estimate of the variance. When we receive a new sample Xnew, the new estimate of the mean will be Snew = g * (Xnew - Wnew)^2 + (1 - g) * Sn, where g = 2 * GP / (GP + SMTP) NOTE: the bias can be shown to be u = 2*(1-f)^2/(2-f), times the variance of Xnew - Wnew (where f is taken from the ewma_mean formula). This may be used to reduce the bias in the calculations, using the formula S'n = Sn / u. The manager may decide whether to reduce the bias or ignore it.
uwma_mean(Xnew, SX, Xold, N) -> Result
Xnew = SX = Xold = N = number()
Result = {EstimatedMean, SampleSum} | {error, Reason
EstimatedMean = SampleSum = number()
Reason = term()
This function computes the variance of a number of samples using the Uniformly Weighted Moving Average technique. Suppose that [X1, X2, X3, ..., Xn] are random variables (observations) with finite population mean u, and sample sum SX. When we receive a new sample Xnew, the new estimate of the mean will be Wnew = Xnew + (SX - Xold) / N, where Xold is the oldest sample used in the calculation of SX (ie., the sample that will be replaced by Xnew when calculating Wnew), and N is the number of samples the calculation of Wnew is based on.
uwma_variance(Xnew, SX, SqSX, Xold, N) -> Result
Xnew = SX = SqSX = Xold = N = number()
Result = {EstimatedVariance, SampleSum, SampleSquareSum} | {error, Reason
EstimatedVariance = SampleSum = SampleSquareSum = number()
Reason = term()
This function computes the variance of a number of samples using the Uniformaly Weighted Moving Average technique. Suppose that [X1, X2, X3, ..., Xn] are random variables (observations) with finite population mean u and finite population variance V, and sample sum SX, and sample square sum SqSX, When we receive a new sample Xnew, the new estimate of the variance will be Snew = ((Xnew^2 + SqSX - Xold^2) - (Xnew + SX - Xold)^2 / N) / (N - 1), where Xold is the oldest sample used in the calculation of SX (ie., the sample that will be replaced by Xnew when calculating Snew), and N is the number of samples the calculation of Snew is based on.
mesh(3)