Package org.apache.commons.math4.stat
Class Frequency<T extends java.lang.Comparable<T>>
java.lang.Object
org.apache.commons.math4.stat.Frequency<T>
- Type Parameters:
T- a comparable type used in the frequency distribution
- All Implemented Interfaces:
java.io.Serializable
public class Frequency<T extends java.lang.Comparable<T>>
extends java.lang.Object
implements java.io.Serializable
Maintains a frequency distribution.
The values are ordered using the default (natural order), unless a
Comparator is supplied in the constructor.
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaddValue(T v)Adds 1 to the frequency count for v.voidclear()Clears the frequency tablejava.util.Iterator<java.util.Map.Entry<T,java.lang.Long>>entrySetIterator()Return an Iterator over the set of keys and values that have been added.booleanequals(java.lang.Object obj)longgetCount(T v)Returns the number of values equal to v.longgetCumFreq(T v)Returns the cumulative frequency of values less than or equal to v.doublegetCumPct(T v)Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).java.util.List<T>getMode()Returns the mode value(s) in comparator order.doublegetPct(T v)Returns the percentage of values that are equal to v (as a proportion between 0 and 1).longgetSumFreq()Returns the sum of all frequencies.intgetUniqueCount()Returns the number of values in the frequency table.inthashCode()voidincrementValue(T v, long increment)Increments the frequency count for v.voidmerge(java.util.Collection<Frequency<T>> others)Merge aCollectionofFrequencyobjects into this instance.voidmerge(Frequency<T> other)Merge another Frequency object's counts into this instance.java.lang.StringtoString()Return a string representation of this frequency distribution.java.util.Iterator<T>valuesIterator()Returns an Iterator over the set of values that have been added.
-
Constructor Details
-
Method Details
-
toString
public java.lang.String toString()Return a string representation of this frequency distribution.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation.
-
addValue
Adds 1 to the frequency count for v.- Parameters:
v- the value to add.
-
incrementValue
Increments the frequency count for v.- Parameters:
v- the value to add.increment- the amount by which the value should be incremented- Since:
- 3.1
-
clear
public void clear()Clears the frequency table -
valuesIterator
Returns an Iterator over the set of values that have been added.- Returns:
- values Iterator
-
entrySetIterator
Return an Iterator over the set of keys and values that have been added. Using the entry set to iterate is more efficient in the case where you need to access respective counts as well as values, since it doesn't require a "get" for every key...the value is provided in the Map.Entry.- Returns:
- entry set Iterator
- Since:
- 3.1
-
getSumFreq
public long getSumFreq()Returns the sum of all frequencies.- Returns:
- the total frequency count.
-
getCount
Returns the number of values equal to v.- Parameters:
v- the value to lookup.- Returns:
- the frequency of v.
-
getUniqueCount
public int getUniqueCount()Returns the number of values in the frequency table.- Returns:
- the number of unique values that have been added to the frequency table.
- See Also:
valuesIterator()
-
getPct
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).Returns
Double.NaNif no values have been added.- Parameters:
v- the value to lookup- Returns:
- the proportion of values equal to v
-
getCumFreq
Returns the cumulative frequency of values less than or equal to v.- Parameters:
v- the value to lookup.- Returns:
- the proportion of values equal to v
-
getCumPct
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).Returns
Double.NaNif no values have been added.- Parameters:
v- the value to lookup- Returns:
- the proportion of values less than or equal to v
-
getMode
Returns the mode value(s) in comparator order.- Returns:
- a list containing the value(s) which appear most often.
- Since:
- 3.3
-
merge
Merge another Frequency object's counts into this instance. This Frequency's counts will be incremented (or set when not already set) by the counts represented by other.- Parameters:
other- the otherFrequencyobject to be merged- Throws:
NullArgumentException- ifotheris null- Since:
- 3.1
-
merge
Merge aCollectionofFrequencyobjects into this instance. This Frequency's counts will be incremented (or set when not already set) by the counts represented by each of the others.- Parameters:
others- the otherFrequencyobjects to be merged- Throws:
NullArgumentException- if the collection is null- Since:
- 3.1
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-