random-fu-0.3.0.1: Random number generation

Safe Haskell | None
Language | Haskell2010

Data.Random.Distribution.Categorical

Synopsis

- data Categorical p a
- categorical :: (Num p, Distribution (Categorical p) a) => [(p, a)] -> RVar a
- categoricalT :: forall p a (m :: Type -> Type). (Num p, Distribution (Categorical p) a) => [(p, a)] -> RVarT m a
- weightedCategorical :: (Fractional p, Eq p, Distribution (Categorical p) a) => [(p, a)] -> RVar a
- weightedCategoricalT :: forall p a (m :: Type -> Type). (Fractional p, Eq p, Distribution (Categorical p) a) => [(p, a)] -> RVarT m a
- fromList :: Num p => [(p, a)] -> Categorical p a
- toList :: Num p => Categorical p a -> [(p, a)]
- totalWeight :: Num p => Categorical p a -> p
- numEvents :: Categorical p a -> Int
- fromWeightedList :: (Fractional p, Eq p) => [(p, a)] -> Categorical p a
- fromObservations :: (Fractional p, Eq p, Ord a) => [a] -> Categorical p a
- mapCategoricalPs :: (Num p, Num q) => (p -> q) -> Categorical p e -> Categorical q e
- normalizeCategoricalPs :: (Fractional p, Eq p) => Categorical p e -> Categorical p e
- collectEvents :: (Ord e, Num p, Ord p) => Categorical p e -> Categorical p e
- collectEventsBy :: Num p => (e -> e -> Ordering) -> ([(p, e)] -> (p, e)) -> Categorical p e -> Categorical p e

# Documentation

data 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 at least eliminate negative weights before sampling).

#### Instances

Instances details

Fractional p => Applicative (Categorical p) Source # |

Instance details

Defined in Data.Random.Distribution.Categorical

Methods

pure :: a -> Categorical p a Source #

(<*>) :: Categorical p (a -> b) -> Categorical p a -> Categorical p b Source #

liftA2 :: (a -> b -> c) -> Categorical p a -> Categorical p b -> Categorical p c Source #

(*>) :: Categorical p a -> Categorical p b -> Categorical p b Source #

(<*) :: Categorical p a -> Categorical p b -> Categorical p a Source #

Functor (Categorical p) Source # |
Instance details Defined in Data.Random.Distribution.Categorical Methods fmap :: (a -> b) -> Categorical p a -> Categorical p b Source # (<$) :: a -> Categorical p b -> Categorical p a Source #
Fractional p => Monad (Categorical p) Source # |
Instance details Defined in Data.Random.Distribution.Categorical Methods (>>=) :: Categorical p a -> (a -> Categorical p b) -> Categorical p b Source # (>>) :: Categorical p a -> Categorical p b -> Categorical p b Source # return :: a -> Categorical p a Source #
Foldable (Categorical p) Source # |

Instance details

Defined in Data.Random.Distribution.Categorical

Methods

fold :: Monoid m => Categorical p m -> m Source #

foldMap :: Monoid m => (a -> m) -> Categorical p a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Categorical p a -> m Source #

foldr :: (a -> b -> b) -> b -> Categorical p a -> b Source #

foldr' :: (a -> b -> b) -> b -> Categorical p a -> b Source #

foldl :: (b -> a -> b) -> b -> Categorical p a -> b Source #

foldl' :: (b -> a -> b) -> b -> Categorical p a -> b Source #

foldr1 :: (a -> a -> a) -> Categorical p a -> a Source #

foldl1 :: (a -> a -> a) -> Categorical p a -> a Source #

toList :: Categorical p a -> [a] Source #

null :: Categorical p a -> Bool Source #

length :: Categorical p a -> Int Source #

elem :: Eq a => a -> Categorical p a -> Bool Source #

maximum :: Ord a => Categorical p a -> a Source #

minimum :: Ord a => Categorical p a -> a Source #

sum :: Num a => Categorical p a -> a Source #

product :: Num a => Categorical p a -> a Source #

Traversable (Categorical p) Source # |

Instance details

Defined in Data.Random.Distribution.Categorical

Methods

traverse :: Applicative f => (a -> f b) -> Categorical p a -> f (Categorical p b) Source #

sequenceA :: Applicative f => Categorical p (f a) -> f (Categorical p a) Source #

mapM :: Monad m => (a -> m b) -> Categorical p a -> m (Categorical p b) Source #

sequence :: Monad m => Categorical p (m a) -> m (Categorical p a) Source #

(Fractional p, Ord p, Distribution Uniform p) => Distribution (Categorical p) a Source # |
Instance details Defined in Data.Random.Distribution.Categorical Methods rvar :: Categorical p a -> RVar a Source # rvarT :: forall (n :: Type -> Type). Categorical p a -> RVarT n a Source #
(Num p, Read p, Read a) => Read (Categorical p a) Source # |
Instance details Defined in Data.Random.Distribution.Categorical Methods readsPrec :: Int -> ReadS (Categorical p a) Source # readList :: ReadS [Categorical p a] Source # readPrec :: ReadPrec (Categorical p a) Source # readListPrec :: ReadPrec [Categorical p a] Source #
(Num p, Show p, Show a) => Show (Categorical p a) Source # |
Instance details Defined in Data.Random.Distribution.Categorical Methods showsPrec :: Int -> Categorical p a -> ShowS Source # show :: Categorical p a -> String Source # showList :: [Categorical p a] -> ShowS Source #
(Eq p, Eq a) => Eq (Categorical p a) Source # |
Instance details Defined in Data.Random.Distribution.Categorical Methods (==) :: Categorical p a -> Categorical p a -> Bool Source # (/=) :: Categorical p a -> Categorical p a -> Bool Source #

categorical :: (Num p, Distribution (Categorical p) a) => [(p, a)] -> RVar a Source #

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

categoricalT :: forall p a (m :: Type -> Type). (Num p, Distribution (Categorical p) a) => [(p, a)] -> RVarT m a Source #

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

weightedCategorical :: (Fractional p, Eq p, Distribution (Categorical p) a) => [(p, a)] -> RVar a Source #

Construct a `Categorical` random variable from a list of weights and categories. The weights do not have to sum to 1.

weightedCategoricalT :: forall p a (m :: Type -> Type). (Fractional p, Eq p, Distribution (Categorical p) a) => [(p, a)] -> RVarT m a Source #

Construct a `Categorical` random process from a list of weights and categories. The weights do not have to sum to 1.

fromList :: Num p => [(p, a)] -> Categorical p a Source #

Construct a `Categorical` distribution from a list of weighted categories.

toList :: Num p => Categorical p a -> [(p, a)] Source #

totalWeight :: Num p => Categorical p a -> p Source #

numEvents :: Categorical p a -> Int Source #

fromWeightedList :: (Fractional p, Eq p) => [(p, a)] -> Categorical p a Source #

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

fromObservations :: (Fractional p, Eq p, Ord a) => [a] -> Categorical p a Source #

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.

mapCategoricalPs :: (Num p, Num q) => (p -> q) -> Categorical p e -> Categorical q e Source #

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

normalizeCategoricalPs :: (Fractional p, Eq p) => Categorical p e -> Categorical p e Source #

Adjust all the weights of a categorical distribution so that they sum to unity and remove all events whose probability is zero.

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

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

collectEventsBy :: Num p => (e -> e -> Ordering) -> ([(p, e)] -> (p, e)) -> Categorical p e -> Categorical p e Source #

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.