|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatistics
public class Statistics
Holds some statistics about a series of sample values. Given a series of sample values s0, s1, s2, s3..., this class computes minimum, maximum, mean, root mean square and standard deviation. Statistics are computed on the fly using the Kahan summation algorithm for reducing the numerical errors; the sample values are never stored in memory.
An instance of Statistics is initially empty (i.e. all statistical values are set
to NaN). The statistics are updated every time an add(double)
method is invoked with a non-NaN value. A typical usage of this
class is:
double[] data = new double[1000];
// (Compute some data values here...)
Statistics stats = new Statistics();
for (int i=0; i<data.length; i++) {
stats.add(data[i]);
}
System.out.println(stats);
| utility/geotk-utility (download) | View source code for this class |
| Nested Class Summary | |
|---|---|
static class |
Statistics.Delta
Holds some statistics about a series of sample values and the difference between them. |
| Constructor Summary | |
|---|---|
Statistics()
Constructs an initially empty set of statistics. |
|
| Method Summary | |
|---|---|
void |
add(double sample)
Updates statistics for the specified sample. |
void |
add(long sample)
Updates statistics for the specified sample. |
void |
add(Statistics stats)
Updates statistics with all samples from the specified stats. |
Statistics |
clone()
Returns a clone of this statistics. |
void |
configure(NumberFormat format)
Configures the given formatter for writing a set of data described by this statistics. |
int |
count()
Returns the number of samples, excluding NaN values. |
int |
countNaN()
Returns the number of NaN samples. |
boolean |
equals(Object object)
Compares this statistics with the specified object for equality. |
NumberFormat |
getNumberFormat(Locale locale)
Suggests a formatter for writing a set of data described by this statistics. |
int |
hashCode()
Returns a hash code value for this statistics. |
double |
maximum()
Returns the maximum sample value, or NaN if none. |
double |
mean()
Returns the mean value, or NaN if none. |
double |
minimum()
Returns the minimum sample value, or NaN if none. |
static void |
printTable(CharSequence[] header,
Statistics[] statistics,
Locale locale)
Prints to the standard output stream the given array of statistics as a table. |
double |
range()
Returns the range of sample values. |
void |
reset()
Resets the statistics to their initial NaN values. |
double |
rms()
Returns the root mean square, or NaN if none. |
double |
standardDeviation(boolean allPopulation)
Returns the standard deviation. |
double |
sum()
Returns the sum, or 0 if none. |
String |
toString()
Returns a string representation of this statistics. |
String |
toString(Locale locale,
boolean tabulations)
Returns a localized string representation of this statistics. |
static void |
writeTable(Writer out,
CharSequence[] header,
Statistics[] statistics,
Locale locale)
Formats the given array of statistics as a table. |
| Methods inherited from class Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Statistics()
Double.NaN.
| Method Detail |
|---|
public void reset()
NaN values.
This method reset this object state as if it was just created.
public void add(double sample)
add
method is usually invoked inside a for loop.
sample - The sample value. NaN values are ignored.add(long),
add(Statistics)public void add(long sample)
add
method is usually invoked inside a for loop.
sample - The sample value.add(double),
add(Statistics)public void add(Statistics stats)
stats. Invoking this
method is equivalent (except for rounding errors) to invoking add
for all samples that were added to stats.
stats - The statistics to be added to this, or null if none.public int countNaN()
NaN samples. NaN samples are
ignored in all other statistical computation. This method count them for information
purpose only.
public int count()
NaN values.
public double minimum()
NaN if none.
maximum()public double maximum()
NaN if none.
minimum()public double range()
maximum -
minimum, except for rounding error. If no samples were added,
then returns NaN.
minimum(),
maximum()public double sum()
public double mean()
NaN if none.
public double rms()
NaN if none.
public double standardDeviation(boolean allPopulation)
add(...)
methods have a uniform distribution, then the returned value should be close to
sqrt(range2 / 12). If they have a
gaussian distribution (which is the most common case), then the returned value
is related to the error
function.
As a remainder, the table below gives the probability for a sample value to be inside the mean ± n×deviation range, assuming that the distribution is gaussian (first column) or assuming that the distribution is uniform (second column).
| n | gaussian | uniform |
|---|---|---|
| 0.5 | 69.1% | 28.9% |
| 1.0 | 84.2% | 57.7% |
| 1.5 | 93.3% | 86.6% |
| 2.0 | 97.7% | 100% |
| 3.0 | 99.9% | 100% |
allPopulation - true if sample values given to add methods are the totality
of the population under study, or false if they are only a sampling.
public NumberFormat getNumberFormat(Locale locale)
locale - The locale for the formatter, or null for the default.
public void configure(NumberFormat format)
getNumberFormat(Locale).
format - The format to configure.public final String toString()
toString(Locale, boolean) using the default locale and spaces
separator.
toString in class Object
public String toString(Locale locale,
boolean tabulations)
Compte: 8726 Minimum: 6.853 Maximum: 8.259 Moyenne: 7.421 RMS: 7.846 Écart-type: 6.489
locale - The locale to use for formatting the string representation,
or null for the default one.tabulations - If true, then labels (e.g. "Minimum") and values (e.g. "6.853")
are separated by tabulations. Otherwise, they are separated by spaces.
public static void printTable(CharSequence[] header,
Statistics[] statistics,
Locale locale)
header - The column headers in the table, or null if none.statistics - The statistics to format.locale - The locale, or null for the default locale.
public static void writeTable(Writer out,
CharSequence[] header,
Statistics[] statistics,
Locale locale)
throws IOException
out - Where to format the statistics table.header - The column headers in the table, or null if none.statistics - The statistics to format.locale - The locale, or null for the default locale.
IOException - if an error occurred while writing to out.public Statistics clone()
clone in class ObjectObject.clone()public int hashCode()
hashCode in class Objectpublic boolean equals(Object object)
equals in class Objectobject - The object to compare with.
true if both objects are equal.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||