peersim.util
Class IncrementalStats

java.lang.Object
  extended by peersim.util.IncrementalStats
Direct Known Subclasses:
MedianStats, MomentStats

public class IncrementalStats
extends java.lang.Object

A class that can keep track of some statistics like variance, average, min, max incrementally. That is, when adding a new data item, it updates the statistics.


Constructor Summary
IncrementalStats()
          Calls reset().
 
Method Summary
 void add(double item)
          Updates the statistics according to this element.
 void add(double item, int k)
          Updates the statistics assuming element item is added k times.
 double getAverage()
          The average of the data items
 double getMax()
          The maximum of the data items
 int getMaxCount()
          Returns the number of data items whose value equals the maximum.
 double getMin()
          The minimum of the data items
 int getMinCount()
          Returns the number of data items whose value equals the minimum.
 int getN()
          The number of data items processed so far
 double getSqrSum()
          The sum of the squares of the data items
 double getStD()
          the empirical standard deviation of the data items
 double getSum()
          The sum of the data items
 double getVar()
          The empirical variance of the data items.
 void reset()
          Resets the statistics to reflect the zero elements set.
 java.lang.String toString()
          Prints the following quantities separated by spaces in a single line in this order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IncrementalStats

public IncrementalStats()
Calls reset().

Method Detail

reset

public void reset()
Resets the statistics to reflect the zero elements set. Min and max are set to positive and negative infinity, respectively.


add

public final void add(double item)
Updates the statistics according to this element. It calls add(item,1).

See Also:
add(double,int)

add

public void add(double item,
                int k)
Updates the statistics assuming element item is added k times.


getN

public int getN()
The number of data items processed so far


getMax

public double getMax()
The maximum of the data items


getMin

public double getMin()
The minimum of the data items


getMaxCount

public int getMaxCount()
Returns the number of data items whose value equals the maximum.


getMinCount

public int getMinCount()
Returns the number of data items whose value equals the minimum.


getSum

public double getSum()
The sum of the data items


getSqrSum

public double getSqrSum()
The sum of the squares of the data items


getAverage

public double getAverage()
The average of the data items


getVar

public double getVar()
The empirical variance of the data items. Guaranteed to be larger or equal to 0.0. If due to rounding errors the value becomes negative, it returns 0.0.


getStD

public double getStD()
the empirical standard deviation of the data items


toString

public java.lang.String toString()
Prints the following quantities separated by spaces in a single line in this order. Minimum, maximum, number of items, average, variance, number of minimal items, number of maximal items.

Overrides:
toString in class java.lang.Object