SSJ  3.3.1
Stochastic Simulation in Java
Classes | Public Member Functions | Protected Attributes | List of all members
Tally Class Reference

A subclass of StatProbe. More...

Inheritance diagram for Tally:
[legend]
Collaboration diagram for Tally:
[legend]

Public Member Functions

 Tally ()
 Constructs a new unnamed Tally statistical probe.
 
 Tally (String name)
 Constructs a new Tally statistical probe with name name. More...
 
void setName (String name)
 Set the name of this Tally to name. More...
 
void init ()
 
void add (double x)
 Gives a new observation x to the statistical collector. More...
 
void add (double[] x, int number)
 Adds the first number observations from the array x to this probe.
 
int numberObs ()
 Returns the number of observations given to this probe since its last initialization. More...
 
double sum ()
 
double average ()
 Returns the average value of the observations since the last initialization.
 
double variance ()
 Returns the sample variance of the observations since the last initialization. More...
 
double standardDeviation ()
 Returns the sample standard deviation of the observations since the last initialization. More...
 
void confidenceIntervalNormal (double level, double[] centerAndRadius)
 Computes a confidence interval on the mean. More...
 
void confidenceIntervalStudent (double level, double[] centerAndRadius)
 Computes a confidence interval on the mean. More...
 
String formatCINormal (double level, int d)
 Similar to confidenceIntervalNormal. More...
 
String formatCINormal (double level)
 Equivalent to formatCINormal (level, 3). More...
 
String formatCIStudent (double level, int d)
 Similar to confidenceIntervalStudent. More...
 
String formatCIStudent (double level)
 Equivalent to formatCIStudent (level, 3). More...
 
void confidenceIntervalVarianceChi2 (double level, double[] interval)
 Computes a confidence interval on the variance. More...
 
String formatCIVarianceChi2 (double level, int d)
 Similar to confidenceIntervalVarianceChi2. More...
 
String report ()
 Returns a formatted string that contains a report on this probe. More...
 
String report (double level, int d)
 Returns a formatted string that contains a report on this probe with a confidence interval level level using \(d\) fractional decimal digits. More...
 
String shortReportHeader ()
 
String shortReport ()
 Formats and returns a short statistical report for this tally. More...
 
String reportAndCIStudent (double level, int d)
 Returns a formatted string that contains a report on this probe (as in report ), followed by a confidence interval (as in formatCIStudent ), using \(d\) fractional decimal digits. More...
 
String reportAndCIStudent (double level)
 Same as reportAndCIStudent(level, 3). More...
 
double getConfidenceLevel ()
 Returns the level of confidence for the intervals on the mean displayed in reports. More...
 
void setConfidenceLevel (double level)
 Sets the level of confidence for the intervals on the mean displayed in reports. More...
 
void setConfidenceIntervalNone ()
 Indicates that no confidence interval needs to be printed in reports formatted by report, and shortReport. More...
 
void setConfidenceIntervalNormal ()
 Indicates that a confidence interval on the true mean, based on the central limit theorem, needs to be included in reports formatted by report and shortReport. More...
 
void setConfidenceIntervalStudent ()
 Indicates that a confidence interval on the true mean, based on the normality assumption, needs to be included in reports formatted by report and shortReport. More...
 
void setShowNumberObs (boolean showNumObs)
 Determines if the number of observations must be displayed in reports. More...
 
Tally clone ()
 Clones this object.
 
- Public Member Functions inherited from StatProbe
abstract void init ()
 Initializes the statistical collector.
 
void setName (String name)
 Sets the name of this statistical collector to name.
 
String getName ()
 Returns the name associated with this probe, or null if no name was specified upon construction. More...
 
double min ()
 Returns the smallest value taken by the variable since the last initialization of this probe. More...
 
double max ()
 Returns the largest value taken by the variable since the last initialization of this probe. More...
 
double sum ()
 Returns the sum cumulated so far for this probe. More...
 
abstract double average ()
 Returns the average for this collector. More...
 
abstract String report ()
 Returns a string containing a report for this statistical collector. More...
 
abstract String shortReport ()
 Formats and returns a short, one-line report about this statistical probe. More...
 
abstract String shortReportHeader ()
 Returns a string containing the name of the values returned in the report strings. More...
 
boolean isBroadcasting ()
 Determines if this statistical probe is broadcasting observations to registered observers. More...
 
void setBroadcasting (boolean b)
 Instructs the probe to turn its broadcasting ON or OFF. More...
 
boolean isCollecting ()
 Determines if this statistical probe is collecting values. More...
 
void setCollecting (boolean b)
 Turns ON or OFF the collection of statistical observations. More...
 
void addObservationListener (ObservationListener l)
 Adds the observation listener l to the list of observers of this statistical probe. More...
 
void removeObservationListener (ObservationListener l)
 Removes the observation listener l from the list of observers of this statistical probe. More...
 
void clearObservationListeners ()
 Removes all observation listeners from the list of observers of this statistical probe.
 
void notifyListeners (double x)
 Notifies the observation x to all registered observers if broadcasting is ON. More...
 
StatProbe clone () throws CloneNotSupportedException
 

Protected Attributes

int numObs
 
CIType confidenceInterval = CIType.CI_NONE
 
double level = 0.95
 
int digits = 3
 
- Protected Attributes inherited from StatProbe
String name
 
double maxValue
 
double minValue
 
double sumValue
 
boolean collect = true
 
boolean broadcast = false
 
boolean showNobs = true
 

Additional Inherited Members

- Static Public Member Functions inherited from StatProbe
static String report (String globalName, StatProbe[] probes)
 Formats short reports for each statistical probe in the array probes while aligning the probes’ names. More...
 
static String report (String globalName, Iterable<? extends StatProbe > probes)
 Equivalent to #report(String,StatProbe[]), except that probes is an Iterable object instead of an array. More...
 

Detailed Description

A subclass of StatProbe.

This type of statistical collector takes a sequence of real-valued observations \(X_1,X_2,X_3,…\) and can return the average, the variance, a confidence interval for the theoretical mean, etc. Each call to add provides a new observation. When the broadcasting to observers is activated, the method add will also pass this new information to its registered observers. This type of collector does not memorize the individual observations, but only their number, sum, sum of squares, maximum, and minimum. The subclass TallyStore offers a collector that memorizes the observations.

Constructor & Destructor Documentation

◆ Tally()

Tally ( String  name)

Constructs a new Tally statistical probe with name name.

Parameters
namename of the tally

Member Function Documentation

◆ add()

void add ( double  x)

Gives a new observation x to the statistical collector.

If broadcasting to observers is activated for this object, this method also transmits the new information to the registered observers by invoking the method notifyListeners.

Parameters
xobservation being added to this Tally object

◆ confidenceIntervalNormal()

void confidenceIntervalNormal ( double  level,
double []  centerAndRadius 
)

Computes a confidence interval on the mean.

Returns, in elements 0 and 1 of the array object centerAndRadius[], the center and half-length (radius) of a confidence interval on the true mean of the random variable \(X\), with confidence level level, assuming that the \(n\) observations given to this collector are independent and identically distributed (i.i.d.) copies of \(X\), and that \(n\) is large enough for the central limit theorem to hold. This confidence interval is computed based on the statistic

\[ Z = {\bar{X}_n - \mu\over{S_{n,x}/\sqrt{n}}} \]

where \(n\) is the number of observations given to this collector since its last initialization, \(\bar{X}_n =\) average() is the average of these observations, \(S_{n,x} =\) standardDeviation() is the empirical standard deviation. Under the assumption that the observations of \(X\) are i.i.d. and \(n\) is large, \(Z\) has the standard normal distribution. The confidence interval given by this method is valid only if this assumption is approximately verified.

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
centerAndRadiusarray of size 2 in which are returned the center and radius of the confidence interval, respectively

◆ confidenceIntervalStudent()

void confidenceIntervalStudent ( double  level,
double []  centerAndRadius 
)

Computes a confidence interval on the mean.

Returns, in elements 0 and 1 of the array object centerAndRadius[], the center and half-length (radius) of a confidence interval on the true mean of the random variable \(X\), with confidence level level, assuming that the observations given to this collector are independent and identically distributed (i.i.d.) copies of \(X\), and that \(X\) has the normal distribution. This confidence interval is computed based on the statistic

\[ T = {\bar{X}_n - \mu\over{S_{n,x}/\sqrt{n}}} \]

where \(n\) is the number of observations given to this collector since its last initialization, \(\bar{X}_n =\) average() is the average of these observations, \(S_{n,x} =\) standardDeviation() is the empirical standard deviation. Under the assumption that the observations of \(X\) are i.i.d. and normally distributed, \(T\) has the Student distribution with \(n-1\) degrees of freedom. The confidence interval given by this method is valid only if this assumption is approximately verified, or if \(n\) is large enough so that \(\bar{X}_n\) is approximately normally distributed.

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
centerAndRadiusarray of size 2 in which are returned the center and radius of the confidence interval, respectively

◆ confidenceIntervalVarianceChi2()

void confidenceIntervalVarianceChi2 ( double  level,
double []  interval 
)

Computes a confidence interval on the variance.

Returns, in elements 0 and 1 of array interval, the left and right boundaries \([I_1,I_2]\) of a confidence interval on the true variance \(\sigma^2\) of the random variable \(X\), with confidence level level, assuming that the observations given to this collector are independent and identically distributed (i.i.d.) copies of \(X\), and that \(X\) has the normal distribution. This confidence interval is computed based on the statistic \( \chi^2_{n-1} = (n-1)S^2_n/\sigma^2 \) where \(n\) is the number of observations given to this collector since its last initialization, and \(S^2_n =\) variance() is the empirical variance of these observations. Under the assumption that the observations of \(X\) are i.i.d. and normally distributed, \(\chi^2_{n-1}\) has the chi-square distribution with \(n-1\) degrees of freedom. Given the level \( = 1 - \alpha\), one has \(P[\chi^2_{n-1} < x_1] = P[\chi^2_{n-1} > x_2] = \alpha/2\) and \([I_1,I_2] = [(n-1)S^2_n/x_2,\; (n-1)S^2_n/x_1]\).

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
intervalarray of size 2 in which are returned the left and right boundaries of the confidence interval, respectively

◆ formatCINormal() [1/2]

String formatCINormal ( double  level,
int  d 
)

Similar to confidenceIntervalNormal.

Returns the confidence interval in a formatted string of the form

"95% confidence interval for mean (normal): (32.431, 32.487)",

using \(d\) fractional decimal digits.

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
dnumber of fractional decimal digits
Returns
a confidence interval formatted as a string

◆ formatCINormal() [2/2]

String formatCINormal ( double  level)

Equivalent to formatCINormal (level, 3).

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
Returns
a confidence interval formatted as a string

◆ formatCIStudent() [1/2]

String formatCIStudent ( double  level,
int  d 
)

Similar to confidenceIntervalStudent.

Returns the confidence interval in a formatted string of the form

"95% confidence interval for mean (student): (32.431, 32.487)",

using \(d\) fractional decimal digits.

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
dnumber of fractional decimal digits
Returns
a confidence interval formatted as a string

◆ formatCIStudent() [2/2]

String formatCIStudent ( double  level)

Equivalent to formatCIStudent (level, 3).

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
Returns
a confidence interval formatted as a string

◆ formatCIVarianceChi2()

String formatCIVarianceChi2 ( double  level,
int  d 
)

Similar to confidenceIntervalVarianceChi2.

Returns the confidence interval in a formatted string of the form

"95.0% confidence interval for variance (chi2): ( 510.642, 519.673 )",

using \(d\) fractional decimal digits.

Parameters
leveldesired probability that the (random) confidence interval covers the true variance
dnumber of fractional decimal digits
Returns
a confidence interval formatted as a string

◆ getConfidenceLevel()

double getConfidenceLevel ( )

Returns the level of confidence for the intervals on the mean displayed in reports.

The default confidence level is 0.95.

Returns
desired probability that the (random) confidence interval covers the true mean (a constant)

◆ numberObs()

int numberObs ( )

Returns the number of observations given to this probe since its last initialization.

Returns
the number of collected observations

◆ report() [1/2]

String report ( )

Returns a formatted string that contains a report on this probe.

Returns
a statistical report formatted as a string

◆ report() [2/2]

String report ( double  level,
int  d 
)

Returns a formatted string that contains a report on this probe with a confidence interval level level using \(d\) fractional decimal digits.

Parameters
leveldesired probability that the confidence interval covers the true mean
dnumber of fractional decimal digits
Returns
a statistical report formatted as a string

◆ reportAndCIStudent() [1/2]

String reportAndCIStudent ( double  level,
int  d 
)

Returns a formatted string that contains a report on this probe (as in report ), followed by a confidence interval (as in formatCIStudent ), using \(d\) fractional decimal digits.

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
dnumber of fractional decimal digits
Returns
a statistical report with a confidence interval, formatted as a string

◆ reportAndCIStudent() [2/2]

String reportAndCIStudent ( double  level)

Same as reportAndCIStudent(level, 3).

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)
Returns
a statistical report with a confidence interval, formatted as a string

◆ setConfidenceIntervalNone()

void setConfidenceIntervalNone ( )

Indicates that no confidence interval needs to be printed in reports formatted by report, and shortReport.

This restores the default behavior of the reporting system.

◆ setConfidenceIntervalNormal()

void setConfidenceIntervalNormal ( )

Indicates that a confidence interval on the true mean, based on the central limit theorem, needs to be included in reports formatted by report and shortReport.

The confidence interval is formatted using formatCINormal.

◆ setConfidenceIntervalStudent()

void setConfidenceIntervalStudent ( )

Indicates that a confidence interval on the true mean, based on the normality assumption, needs to be included in reports formatted by report and shortReport.

The confidence interval is formatted using formatCIStudent.

◆ setConfidenceLevel()

void setConfidenceLevel ( double  level)

Sets the level of confidence for the intervals on the mean displayed in reports.

Parameters
leveldesired probability that the (random) confidence interval covers the true mean (a constant)

◆ setName()

void setName ( String  name)

Set the name of this Tally to name.

Parameters
namename of the tally

◆ setShowNumberObs()

void setShowNumberObs ( boolean  showNumObs)

Determines if the number of observations must be displayed in reports.

By default, the number of observations is displayed.

Parameters
showNumObsthe value of the indicator.

◆ shortReport()

String shortReport ( )

Formats and returns a short statistical report for this tally.

The returned single-line report contains the minimum value, the maximum value, the average, the variance, and the standard deviation, in that order, separated by three spaces. If the number of observations is shown in the short report, a column containing the number of observations in this tally is added.

Returns
the string containing the report.

◆ standardDeviation()

double standardDeviation ( )

Returns the sample standard deviation of the observations since the last initialization.

This returns Double.NaN if the tally contains less than two observations.

Returns
the standard deviation of the observations

◆ variance()

double variance ( )

Returns the sample variance of the observations since the last initialization.

This returns Double.NaN if the tally contains less than two observations.

Returns
the variance of the observations

The documentation for this class was generated from the following file: