Class 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) pairs
      java.util.stream.Stream<org.apache.commons.lang3.tuple.ImmutablePair<V,​java.lang.Double>> allProportions()
      Get a stream of (object, proportion) pairs
      static <W> Distribution<W> constantDistribution​(W w)
      Creates a constant distribution - ia distribution containing a single object
      int getCount​(V v)
      Get the count for an object
      double getProportion​(V v)
      Get the proportion for n object.
      int getTotal()
      Get the total count for all objects
      V sample()
      Get a sample from the distribution
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Distribution

        public Distribution​(CountMap<V> counts)
        Default constructor
        Parameters:
        counts - Map from object to count
    • 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