Package Utils.Distribution
Class Distribution<V>
- java.lang.Object
-
- Utils.Distribution.Distribution<V>
-
- Type Parameters:
V
- The type of object
- Direct Known Subclasses:
ComparableDistribution
public class Distribution<V> extends java.lang.Object
Represents a discrete distribution of objects. Each object has a count associated with it
-
-
Constructor Summary
Constructors Constructor Description Distribution(CountMap<V> counts)
Default constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.stream.Stream<org.apache.commons.lang3.tuple.ImmutablePair<V,java.lang.Integer>>
allCounts()
Gets a stream of (object, count) pairsjava.util.stream.Stream<org.apache.commons.lang3.tuple.ImmutablePair<V,java.lang.Double>>
allProportions()
Get a stream of (object, proportion) pairsstatic <W> Distribution<W>
constantDistribution(W w)
Creates a constant distribution - ia distribution containing a single objectint
getCount(V v)
Get the count for an objectdouble
getProportion(V v)
Get the proportion for n object.int
getTotal()
Get the total count for all objectsV
sample()
Get a sample from the distribution
-
-
-
Method Detail
-
getProportion
public double getProportion(V v)
Get the proportion for n object. That is count / total count- Parameters:
v
- The object- Returns:
- The proportion
-
getCount
public int getCount(V v)
Get the count for an object- Parameters:
v
- The object- Returns:
- The count
-
getTotal
public int getTotal()
Get the total count for all objects- Returns:
- Total count
-
allCounts
public java.util.stream.Stream<org.apache.commons.lang3.tuple.ImmutablePair<V,java.lang.Integer>> allCounts()
Gets a stream of (object, count) pairs- Returns:
- The stream
-
allProportions
public java.util.stream.Stream<org.apache.commons.lang3.tuple.ImmutablePair<V,java.lang.Double>> allProportions()
Get a stream of (object, proportion) pairs- Returns:
- The stream
-
sample
public V sample()
Get a sample from the distribution- Returns:
- The sampled object
-
constantDistribution
public static <W> Distribution<W> constantDistribution(W w)
Creates a constant distribution - ia distribution containing a single object- Type Parameters:
W
- Type of the object- Parameters:
w
- The object- Returns:
- The constant distribution
-
-