There are two ways to obtain a Stats instance:
Stats.of factory method below. Primitive arrays, iterables and iterators of any kind of
Number, and primitive varargs are supported.
StatsAccumulator instance,
feed values to it as you get them, then call StatsAccumulator#snapshot.
Static convenience methods called meanOf are also provided for users who wish to
calculate only the mean.
Java 8 users: If you are not using any of the variance statistics, you may wish to use built-in JDK libraries instead of this class.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | BYTES
The size of byte array representation in bytes. |
| private final long | |
| private final double | |
| private final double | |
| private final double | |
| private static final long | |
| private final double |
| Access | Constructor and Description |
|---|---|
| pack-priv | Stats(long count, double mean, double sumOfSquaresOfDeltas, double min, double max)
Internal constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public long | |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| public static Stats | fromByteArray(byte[] byteArray)
Creates a Stats instance from the given byte representation which was obtained by |
| public int | |
| public double | |
| public double | |
| public static double | meanOf(Iterable<? extends Number>
a series of values, which will be converted to values)double values (this may
cause loss of precision)Returns the arithmetic mean of the values. |
| public static double | meanOf(Iterator<? extends Number>
a series of values, which will be converted to values)double values (this may
cause loss of precision)Returns the arithmetic mean of the values. |
| public static double | |
| public static double | |
| public static double | meanOf(long...
a series of values, which will be converted to values)double values (this may
cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15))Returns the arithmetic mean of the values. |
| public double | |
| public static Stats | |
| public static Stats | |
| public static Stats | of(double...
a series of values values)Returns statistics over a dataset containing the given values. |
| public static Stats | |
| public static Stats | of(long...
a series of values, which will be converted to values)double values (this may
cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15))Returns statistics over a dataset containing the given values. |
| public static Stats | of(DoubleStream
a series of values values)Returns statistics over a dataset containing the given values. |
| public static Stats | |
| public static Stats | of(LongStream
a series of values, which will be converted to values)double values (this may
cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15))Returns statistics over a dataset containing the given values. |
| public double | |
| public double | |
| pack-priv static Stats | readFrom(ByteBuffer
A buffer)ByteBuffer with at least BYTES ByteBuffer#remaining, ordered as
ByteOrder#LITTLE_ENDIAN, from which a BYTES-long byte representation of this
instance is read. In the process increases the position of ByteBuffer by BYTES.Creates a Stats instance from the byte representation read from the given |
| public double | |
| public double | |
| public double | |
| pack-priv double | |
| public byte[] | |
| public static Collector | toStats()
Returns a |
| public String | |
| pack-priv void | writeTo(ByteBuffer
A buffer)ByteBuffer with at least BYTES ByteBuffer#remaining, ordered as
ByteOrder#LITTLE_ENDIAN, to which a BYTES-long byte representation of this instance
is written. In the process increases the position of ByteBuffer by BYTES.Writes to the given |
| BYTES | back to summary |
|---|---|
| pack-priv static final int BYTES The size of byte array representation in bytes. | |
| count | back to summary |
|---|---|
| private final long count | |
| max | back to summary |
|---|---|
| private final double max | |
| mean | back to summary |
|---|---|
| private final double mean | |
| min | back to summary |
|---|---|
| private final double min | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| sumOfSquaresOfDeltas | back to summary |
|---|---|
| private final double sumOfSquaresOfDeltas | |
| Stats | back to summary |
|---|---|
| pack-priv Stats(long count, double mean, double sumOfSquaresOfDeltas, double min, double max) Internal constructor. Users should use To ensure that the created instance obeys its contract, the parameters should satisfy the following constraints. This is the callers responsibility and is not enforced here.
| |
| count | back to summary |
|---|---|
| public long count() Returns the number of values. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. Note This tests exact equality of the calculated statistics, including the floating
point values. Two instances are guaranteed to be considered equal if one is copied from the
other using | |
| fromByteArray | back to summary |
|---|---|
| public static Stats fromByteArray(byte[] byteArray) Creates a Stats instance from the given byte representation which was obtained by Note No guarantees are made regarding stability of the representation between versions. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
Note This hash code is consistent with exact equality of the calculated statistics,
including the floating point values. See the note on
| |
| max | back to summary |
|---|---|
| public double max() Returns the highest value in the dataset. The count must be non-zero. Non-finite valuesIf the dataset contains
| |
| mean | back to summary |
|---|---|
| public double mean() Returns the arithmetic mean of the values. The count must be non-zero. If these values are a sample drawn from a population, this is also an unbiased estimator of the arithmetic mean of the population. Non-finite valuesIf the dataset contains If you only want to calculate the mean, use
| |
| meanOf | back to summary |
|---|---|
| public static double meanOf(Iterable<? extends Number> values) Returns the arithmetic mean of the values. The count must be non-zero. The definition of the mean is the same as
| |
| meanOf | back to summary |
|---|---|
| public static double meanOf(Iterator<? extends Number> values) Returns the arithmetic mean of the values. The count must be non-zero. The definition of the mean is the same as
| |
| meanOf | back to summary |
|---|---|
| public static double meanOf(double... values) Returns the arithmetic mean of the values. The count must be non-zero. The definition of the mean is the same as
| |
| meanOf | back to summary |
|---|---|
| public static double meanOf(int... values) Returns the arithmetic mean of the values. The count must be non-zero. The definition of the mean is the same as
| |
| meanOf | back to summary |
|---|---|
| public static double meanOf(long... values) Returns the arithmetic mean of the values. The count must be non-zero. The definition of the mean is the same as
| |
| min | back to summary |
|---|---|
| public double min() Returns the lowest value in the dataset. The count must be non-zero. Non-finite valuesIf the dataset contains
| |
| of | back to summary |
|---|---|
| public static Stats of(Iterable<? extends Number> values) Returns statistics over a dataset containing the given values. | |
| of | back to summary |
|---|---|
| public static Stats of(Iterator<? extends Number> values) Returns statistics over a dataset containing the given values. The iterator will be completely consumed by this method. | |
| of | back to summary |
|---|---|
| public static Stats of(double... values) Returns statistics over a dataset containing the given values.
| |
| of | back to summary |
|---|---|
| public static Stats of(int... values) Returns statistics over a dataset containing the given values.
| |
| of | back to summary |
|---|---|
| public static Stats of(long... values) Returns statistics over a dataset containing the given values.
| |
| of | back to summary |
|---|---|
| public static Stats of(DoubleStream values) Returns statistics over a dataset containing the given values. The stream will be completely consumed by this method. If you have a
| |
| of | back to summary |
|---|---|
| public static Stats of(IntStream values) Returns statistics over a dataset containing the given values. The stream will be completely consumed by this method. If you have a
| |
| of | back to summary |
|---|---|
| public static Stats of(LongStream values) Returns statistics over a dataset containing the given values. The stream will be completely consumed by this method. If you have a
| |
| populationStandardDeviation | back to summary |
|---|---|
| public double populationStandardDeviation() Returns the population standard deviation of the values. The count must be non-zero. This is guaranteed to return zero if the dataset contains only exactly one finite value. It is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values (
| |
| populationVariance | back to summary |
|---|---|
| public double populationVariance() Returns the population variance of the values. The count must be non-zero. This is guaranteed to return zero if the dataset contains only exactly one finite value. It is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values (
| |
| readFrom | back to summary |
|---|---|
| pack-priv static Stats readFrom(ByteBuffer buffer) Creates a Stats instance from the byte representation read from the given Note No guarantees are made regarding stability of the representation between versions.
| |
| sampleStandardDeviation | back to summary |
|---|---|
| public double sampleStandardDeviation() Returns the
corrected sample standard deviation of the values. If this dataset is a sample drawn from a
population, this is an estimator of the population standard deviation of the population which
is less biased than This is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values (
| |
| sampleVariance | back to summary |
|---|---|
| public double sampleVariance() Returns the unbiased sample variance of the values. If this dataset is a sample drawn from a population, this is an unbiased estimator of the population variance of the population. The count must be greater than one. This is not guaranteed to return zero when the dataset consists of the same value multiple times, due to numerical errors. However, it is guaranteed never to return a negative result. Non-finite valuesIf the dataset contains any non-finite values (
| |
| sum | back to summary |
|---|---|
| public double sum() Returns the sum of the values. Non-finite valuesIf the dataset contains | |
| sumOfSquaresOfDeltas | back to summary |
|---|---|
| pack-priv double sumOfSquaresOfDeltas() | |
| toByteArray | back to summary |
|---|---|
| public byte[] toByteArray() Gets a byte array representation of this instance. Note No guarantees are made regarding stability of the representation between versions. | |
| toStats | back to summary |
|---|---|
| public static Collector Returns a If you have any of the primitive streams
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| writeTo | back to summary |
|---|---|
| pack-priv void writeTo(ByteBuffer buffer) Writes to the given Note No guarantees are made regarding stability of the representation between versions.
| |