Utility
Class Tally

java.lang.Object
  |
  +--Utility.Tally
Direct Known Subclasses:
WeightedTally

public class Tally
extends java.lang.Object

Statistic Collection Objects
The Tally class is used for collecting simple statistics for a set of numbers. It provides functions to compute min, max, variance, standard deviation, sum, and sum of squares. All values are represented using doubles.
Note that the original source code for these classes was written by Zhonge Xiao in C++. The C++ code was ported over to Java and some minor design changes were made.


Field Summary
protected  double fCount
          Count of values in the tally.
protected  java.util.Vector fDataPoints
           
protected  double fMax
          Maximum value in the tally.
protected  double fMin
          Minimum value in the tally.
protected  java.lang.String fName
          The name of the tally.
protected  double fSum
          Sum of the values in the tally.
protected  double fSumSq
          Sum of the squares in the tally.
static java.lang.String seperator
          Represents the string used for seperating consecutive numerical values.
static boolean STORE_POINTS
           
static boolean SUMMARY_ONLY
           
static boolean WITH_HEADER
           
static boolean WO_HEADER
           
 
Constructor Summary
Tally()
          Initialize the object.
Tally(java.lang.String name, boolean storePoints)
          Initialize the object, give the Tally a name.
 
Method Summary
 double average()
          Report the mean data point.
 double count()
          Report how many data points are in the tally.
 boolean isStoringPoints()
          Report whether or not this Tally object is storing the actual data points.
 double max()
          Report the maximum data point.
 double min()
          Report the minimum data point.
 void outputPoints(java.io.PrintStream out, boolean withHeader)
          Output all the data points stored in the Tally object.
 void outputSummary(java.io.PrintStream out, boolean withHeader)
          Output the summary statistics that were collected for the Tally.
 void reset()
          Remove all data points from the Tally.
 double stdDev()
          Report the standard deviation of the data points.
 double sum()
          Report the sum of the data points.
 double sumSq()
          Report the sum of the squares of the data points.
 void update(double x)
          Updates the statistics with the data item x.
 void updateBatch(Tally data)
          Update Tally with batch data.
 double variance()
          Report the variance of the data points.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fCount

protected double fCount
Count of values in the tally.


fSum

protected double fSum
Sum of the values in the tally.


fSumSq

protected double fSumSq
Sum of the squares in the tally.


fMin

protected double fMin
Minimum value in the tally.


fMax

protected double fMax
Maximum value in the tally.


fName

protected java.lang.String fName
The name of the tally.


STORE_POINTS

public static final boolean STORE_POINTS
See Also:
Constant Field Values

SUMMARY_ONLY

public static final boolean SUMMARY_ONLY
See Also:
Constant Field Values

fDataPoints

protected java.util.Vector fDataPoints

WITH_HEADER

public static final boolean WITH_HEADER
See Also:
Constant Field Values

WO_HEADER

public static final boolean WO_HEADER
See Also:
Constant Field Values

seperator

public static java.lang.String seperator
Represents the string used for seperating consecutive numerical values. The user should feel free to change this to whatever he deems appropriate.

Constructor Detail

Tally

public Tally()
Initialize the object. With this constructor, no data points will be collected; only the summary statistics will be computed. Also, the tally will have no name.


Tally

public Tally(java.lang.String name,
             boolean storePoints)
Initialize the object, give the Tally a name.

Parameters:
name - The name of the Tally object. This will be used with the output functions.
storePoints - Whether or not the Tally should record all individiual data points. Tally.STORE_POINTS means the object should store data points, and Tally.SUMMARY_ONLY means the object should only compute summary statistics.
Method Detail

reset

public void reset()
Remove all data points from the Tally.


update

public void update(double x)
Updates the statistics with the data item x.

Parameters:
x - The value to record in the tally.

updateBatch

public void updateBatch(Tally data)
Update Tally with batch data.

Parameters:
data - The tally whose data will be added to this tally.
Throws:
java.lang.RuntimeException - A RuntimeException is thrown if the Tally object data is not storing data points but the current Tally object is. There is no problem however if we are not storing points but the data object is.

count

public double count()
Report how many data points are in the tally.

Returns:
The count of points in the tally.

sum

public double sum()
Report the sum of the data points.

Returns:
The sum of the values in the tally. If there are no values in the tally then 0 is returned.

sumSq

public double sumSq()
Report the sum of the squares of the data points.

Returns:
The sum of the squares of the values in the tally. If there are no values in the tally then 0 is returned.

min

public double min()
Report the minimum data point.

Returns:
The minimum value in the Tally. If there are no values in the tally then 0 is returned.

max

public double max()
Report the maximum data point.

Returns:
The maximum value in the Tally. If there are no values in the tally then 0 is returned.

average

public double average()
Report the mean data point.

Returns:
The average of the values in the tally. If there are no values in the tally then 0 is returned.

stdDev

public double stdDev()
Report the standard deviation of the data points.

Returns:
The standard deviation of the values in the tally. If there are fewer than 2 values in the tally then 0 is returned.

variance

public double variance()
Report the variance of the data points.

Returns:
The sample variance of the values in the tally. If there are fewer than 2 values in the tally then 0 is returned.

outputPoints

public void outputPoints(java.io.PrintStream out,
                         boolean withHeader)
Output all the data points stored in the Tally object.

Parameters:
out - The PrintStream to send the output to.
withHeader - true to print a header, false to skip the header. Tally.WITH_HEADER and Tally.WO_HEADER can be used instead of true and false.
Throws:
java.lang.RuntimeException - A RuntimeException is thrown if the Tally object is not currently storing data points.

outputSummary

public void outputSummary(java.io.PrintStream out,
                          boolean withHeader)
Output the summary statistics that were collected for the Tally.

Parameters:
out - The PrintStream to send the output to.
withHeader - true to print a header, false to skip the header. Tally.WITH_HEADER and Tally.WO_HEADER can be used instead of true and false.

isStoringPoints

public boolean isStoringPoints()
Report whether or not this Tally object is storing the actual data points.

Returns:
true if this Tally object is recording individual data points, false if it is only collecting summary statistics.