Class Stats
- All Implemented Interfaces:
Serializable
,RevisionHandler
Upon initialization the variables take the following values:
count
= sum
= sumSq
= 0
mean
= stdDev
= min
= max
= Double.NaN
This is called the initial state.
For signaling that a Stats object has been provided with values that hint that something is either wrong with the data used or the algorithm used there is also the invalid state where the variables take the following values:
Once a Stats object goes into the invalid state it can't change its state
anymore.
A Stats object assumes that only values are subtracted (by using the
If the implementation detects a problem then the Stats object goes into the
invalid state.
The fields
For the fields
Where \ is the set difference.
For the field
count
= sum
= sumSq
= mean
=
stdDev
= min
= max
= Double.NaN
subtract(double)
or subtract(double, double)
methods)
that have previously been added (by using the add(double)
or
add(double, double)
methods) and the weights must be the same
too.
Otherwise the Stats object's fields' values are implementation defined.count
, sum
, sumSq
, min
and
max
are always updated whereas the field mean
and
stdDev
are only guaranteed to be updated after a call to
calculateDerived()
.min
and max
the following rules apply:
min(values_added \ values_subtracted) >=
min
>= min(values_added)
max(values_added \ values_subtracted) <= max
<= max(values_added)
stdDev
the following rules apply:
For the methods stdDev
=Double.NaN.stdDev
>= 0 and it should take on the value by best
effort of the implementation.add(double)
, add(double, double)
,
subtract(double)
and subtract(double, double)
the following
rules apply:
For subtract(double, double)
is used instead of
add(double, double)
with weight = -weight and vice versa.count
the following rules apply
count
goes below zero then all fields are set to
Double.NaN
except the count
field which gets tracked
normally.count
= 0 then the Stats object goes into the initial state.
count
> 0 for the first time, then the Stats object goes into
initial state and gets updated with the corresponding value and weight.
- Version:
- $Revision: 14072 $
- Author:
- Len Trigg (trigg@cs.waikato.ac.nz)
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptiondouble
The number of values seendouble
The maximum value seen, or Double.NaN if no values seendouble
The mean of values, or Double.NaN if no values seendouble
The minimum value seen, or Double.NaN if no values seendouble
The std deviation of values at the last calculateDerived() calldouble
The sum of values seendouble
The sum of values squared seen -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double value) Adds a value to the observed valuesvoid
add
(double value, double weight) Adds a weighted value to the observed valuesvoid
Tells the object to calculate any statistics that don't have their values automatically updated during add.Returns the revision string.static void
Tests the paired stats object from the command line.void
subtract
(double value) Removes a value to the observed values (no checking is done that the value being removed was actually added).void
subtract
(double value, double weight) Subtracts a weighted value from the observed valuestoString()
Returns a string summarising the stats so far.
-
Field Details
-
count
public double countThe number of values seen -
sum
public double sumThe sum of values seen -
sumSq
public double sumSqThe sum of values squared seen -
stdDev
public double stdDevThe std deviation of values at the last calculateDerived() call -
mean
public double meanThe mean of values, or Double.NaN if no values seen -
min
public double minThe minimum value seen, or Double.NaN if no values seen -
max
public double maxThe maximum value seen, or Double.NaN if no values seen
-
-
Constructor Details
-
Stats
public Stats()
-
-
Method Details
-
add
public void add(double value) Adds a value to the observed valuesIt's equivalent to
add(value, 1)
- Parameters:
value
- the observed value
-
add
public void add(double value, double weight) Adds a weighted value to the observed values- Parameters:
value
- the observed valueweight
- the weight of the observed value
-
subtract
public void subtract(double value) Removes a value to the observed values (no checking is done that the value being removed was actually added).It's equivalent to
subtract(value, 1)
- Parameters:
value
- the observed value
-
subtract
public void subtract(double value, double weight) Subtracts a weighted value from the observed values- Parameters:
value
- the observed valueweight
- the weight of the observed value
-
calculateDerived
public void calculateDerived()Tells the object to calculate any statistics that don't have their values automatically updated during add. Currently updates the standard deviation. -
toString
Returns a string summarising the stats so far. -
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-
main
Tests the paired stats object from the command line. reads line from stdin, expecting two values per line.- Parameters:
args
- ignored.
-