Package org.hipparchus.stat
Class Frequency<T extends Comparable<T>>
java.lang.Object
org.hipparchus.stat.Frequency<T>
- Type Parameters:
T- the element type
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
LongFrequency
Maintains a frequency distribution of Comparable values.
The values are ordered using the default (natural order), unless a
Comparator is supplied in the constructor.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Frequency(Comparator<? super T> comparator) Constructor allowing values Comparator to be specified. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds 1 to the frequency count for v.voidclear()Clears the frequency tableReturn an Iterator over the set of keys and values that have been added.booleanlongReturns the number of values equal to v.longgetCumFreq(T v) Returns the cumulative frequency of values less than or equal to v.doubleReturns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).getMode()Returns the mode value(s) in comparator order.doubleReturns the percentage of values that are equal to v (as a proportion between 0 and 1).longReturns the sum of all frequencies.intReturns the number of values in the frequency table.inthashCode()voidincrementValue(T v, long increment) Increments the frequency count for v.voidmerge(Collection<? extends Frequency<? extends T>> others) Merge aCollectionofFrequencyobjects into this instance.voidMerge another Frequency object's counts into this instance.toString()Return a string representation of this frequency distribution.Returns an Iterator over the set of values that have been added.
-
Constructor Details
-
Frequency
public Frequency()Default constructor. -
Frequency
Constructor allowing values Comparator to be specified.- Parameters:
comparator- Comparator used to order values
-
-
Method Details
-
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
-
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
-
getSumFreq
public long getSumFreq()Returns the sum of all frequencies.- Returns:
- the total frequency count.
-
getCount
Returns the number of values equal to v. Returns 0 if the value is not comparable.- 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:
-
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.
-
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
-
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
-
toString
Return a string representation of this frequency distribution. -
hashCode
public int hashCode() -
equals
-