public class Histogram<C> extends MappedAccumulator<C>
Separators: 0 1 2 3 4 5 6 7 8 9
-------+----+----+----+----+----+----+----+----+----+------
Frequencies: 20 | 12 | 14 | 17 | 12 | 11 | 13 | 11 | 10 | 19 | 18
-------+----+----+----+----+----+----+----+----+----+------
Histogram index: 0 1 2 3 4 5 6 7 8 9 10
Note that this implementation is not synchronized. If
multiple threads access this object concurrently, and at least one of the
threads modifies it, it must be synchronized externally._samples| Constructor and Description |
|---|
Histogram(Comparator<C> comparator,
C... separators)
Create a new Histogram with the given class separators.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accumulate(C value)
Accumulate the given value.
|
double |
chisqr(Function<C,Float64> cdf) |
double |
chisqr(Function<C,Float64> cdf,
C min,
C max) |
Histogram<C> |
clone() |
boolean |
equals(Object obj) |
Comparator<C> |
getComparator()
Return the comparator used for class search.
|
long[] |
getHistogram()
Return a copy of the current histogram.
|
long[] |
getHistogram(long[] histogram)
Copy the histogram into the given array.
|
double[] |
getProbabilities()
Return the histogram as probability array.
|
C[] |
getSeparators()
Return a copy of the class separators.
|
int |
hashCode() |
int |
length()
Return the number of classes of this histogram.
|
Histogram<C> |
plus(Histogram<C> histogram)
Add the given
histogram to this in a newly created one. |
<A extends Appendable> |
print(A out) |
String |
toString() |
static <C extends Comparable<? super C>> |
valueOf(C... separators)
Create a new Histogram with the given class separators.
|
static Histogram<Double> |
valueOf(Double min,
Double max,
int nclasses) |
static Histogram<Float64> |
valueOf(Float64 min,
Float64 max,
int nclasses)
Return a histogram for
Float64 values. |
static Histogram<Integer64> |
valueOf(Integer64 min,
Integer64 max,
int nclasses)
Return a histogram for
Integer64 values. |
static Histogram<Long> |
valueOf(Long min,
Long max,
int nclasses) |
double |
χ2(Function<C,Float64> cdf)
Calculate the χ2 value of the current histogram for the assumed
Cumulative density function
cdf. |
double |
χ2(Function<C,Float64> cdf,
C min,
C max)
Calculate the χ2 value of the current histogram for the assumed
Cumulative density function
cdf. |
getSamples, map@SafeVarargs public Histogram(Comparator<C> comparator, C... separators)
separators.length + 1. A valid histogram consists of
at least two classes (with one separator).comparator - the comparator for the separators.separators - the class separators.NullPointerException - if the classes of one of its elements
or the comparator is null.IllegalArgumentException - if the given separators array is empty.valueOf(Comparable...)public void accumulate(C value)
Accumulatoraccumulate in interface Accumulator<C>accumulate in class MappedAccumulator<C>value - the value to accumulate.public Histogram<C> plus(Histogram<C> histogram)
histogram to this in a newly created one.histogram - the histogram to add.IllegalArgumentException - if the length() and the
separators of this and the given histogram are
not the same.NullPointerException - if the given histogram is null.public Comparator<C> getComparator()
public C[] getSeparators()
public long[] getHistogram(long[] histogram)
getSeparators().length + 1).histogram - array to copy the histogram.NullPointerException - if the given array is null.public long[] getHistogram()
public int length()
public double[] getProbabilities()
public double χ2(Function<C,Float64> cdf, C min, C max)
cdf.cdf - the assumed Probability density function.min - the lower limit of the CDF domain. A null value means
an open interval.max - the upper limit of the CDF domain. A null value means
an open interval.NullPointerException - if cdf is null.public double χ2(Function<C,Float64> cdf)
cdf.cdf - the assumed Probability density function.NullPointerException - if cdf is null.public double chisqr(Function<C,Float64> cdf)
χ2(Function)public double chisqr(Function<C,Float64> cdf, C min, C max)
χ2(Function, Object, Object)public int hashCode()
hashCode in class MappedAccumulator<C>public boolean equals(Object obj)
equals in class MappedAccumulator<C>public String toString()
toString in class MappedAccumulator<C>public static <C extends Comparable<? super C>> Histogram<C> valueOf(C... separators)
separators - the class separators.NullPointerException - if the separators are null.IllegalArgumentException - if separators.length == 0.public static Histogram<Float64> valueOf(Float64 min, Float64 max, int nclasses)
Float64 values. The histogram
array of the returned Histogram will look like this:
min max
+----+----+----+----+ ~ +----+
| 1 | 2 | 3 | 4 | | nc |
+----+----+----+----+ ~ +----+
The range of all classes will be equal: (max - min)/nclasses.min - the minimum range value of the returned histogram.max - the maximum range value of the returned histogram.nclasses - the number of classes of the returned histogram. The
number of separators will be nclasses - 1.Float64 values.NullPointerException - if min or max is null.IllegalArgumentException - if min.compareTo(max) >= 0 or
nclasses < 2.public static Histogram<Double> valueOf(Double min, Double max, int nclasses)
valueOf(Float64, Float64, int)public static Histogram<Integer64> valueOf(Integer64 min, Integer64 max, int nclasses)
Integer64 values. The histogram
array of the returned Histogram will look like this:
min max
+----+----+----+----+ ~ +----+
| 1 | 2 | 3 | 4 | | nc |
+----+----+----+----+ ~ +----+
The range of all classes are more or less the same. But this is not
always possible due to integer rounding issues. Calling this method with
min = 13 and max = 99 will generate the following class
separators for the given number of classes:
nclasses = 2: [56] nclasses = 3: [41, 70] nclasses = 4: [34, 55, 77] nclasses = 5: [30, 47, 64, 81] nclasses = 6: [27, 41, 55, 69, 84] nclasses = 7: [25, 37, 49, 61, 73, 86] nclasses = 8: [23, 33, 44, 55, 66, 77, 88] nclasses = 9: [22, 31, 40, 49, 59, 69, 79, 89]
min - the minimum range value of the returned histogram.max - the maximum range value of the returned histogram.nclasses - the number of classes of the returned histogram. The
number of separators will be nclasses - 1.Integer64 values.NullPointerException - if min or max is null.IllegalArgumentException - if min.compareTo(max) >= 0 or
nclasses < 2.public static Histogram<Long> valueOf(Long min, Long max, int nclasses)
valueOf(Integer64, Integer64, int)public <A extends Appendable> A print(A out) throws IOException
IOException© 2007-2013 Franz Wilhelmstötter (2013-12-18 20:17)