random-fu-0.1.3: Random number generation

Data.Random.Distribution.Categorical

Synopsis

# Documentation

categorical :: Distribution (Categorical p) a => [(p, a)] -> RVar aSource

Construct a `Categorical` random variable from a list of probabilities and categories, where the probabilities all sum to 1.

categoricalT :: Distribution (Categorical p) a => [(p, a)] -> RVarT m aSource

Construct a `Categorical` random process from a list of probabilities and categories, where the probabilities all sum to 1.

weightedCategorical :: Fractional p => [(p, a)] -> Categorical p aSource

Construct a `Categorical` distribution from a list of weighted categories, where the weights do not necessarily sum to 1.

empirical :: (Fractional p, Ord a) => [a] -> Categorical p aSource

Construct a `Categorical` distribution from a list of observed outcomes. Equivalent events will be grouped and counted, and the probabilities of each event in the returned distribution will be proportional to the number of occurrences of that event.

newtype Categorical p a Source

Categorical distribution; a list of events with corresponding probabilities. The sum of the probabilities must be 1, and no event should have a zero or negative probability (at least, at time of sampling; very clever users can do what they want with the numbers before sampling, just make sure that if you're one of those clever ones, you normalize before sampling).

Constructors

 Categorical [(p, a)]

Instances

 Fractional p => Monad (Categorical p) Functor (Categorical p) Fractional p => Applicative (Categorical p) Foldable (Categorical p) Traversable (Categorical p) (Fractional p, Ord p, Distribution StdUniform p) => Distribution (Categorical p) a (Eq p, Eq a) => Eq (Categorical p a) (Show p, Show a) => Show (Categorical p a)

mapCategoricalPs :: (p -> q) -> Categorical p e -> Categorical q eSource

Like `fmap`, but for the probabilities of a categorical distribution.

normalizeCategoricalPs :: Fractional p => Categorical p e -> Categorical p eSource

Adjust all the weights of a categorical distribution so that they sum to unity.

collectEvents :: (Ord e, Num p, Ord p) => Categorical p e -> Categorical p eSource

Simplify a categorical distribution by combining equivalent categories (the new category will have a probability equal to the sum of all the originals).

collectEventsBy :: (e -> e -> Ordering) -> ([(p, e)] -> (p, e)) -> Categorical p e -> Categorical p eSource

Simplify a categorical distribution by combining equivalent events (the new event will have a weight equal to the sum of all the originals). The comparator function is used to identify events to combine. Once chosen, the events and their weights are combined by the provided probability and event aggregation function.