distribution-1.1.1.0: Finite discrete probability distributions.

Safe HaskellSafe
LanguageHaskell98

Data.Distribution.Aggregator

Contents

Description

 Module containing functions to apply on lists of values tagged with their probability, in order to somehow aggregate or transform the probabilities.

Synopsis

Aggregation

data Aggregator a Source #

Functions that can modify probabilities.

Instances

Monoid (Aggregator a) Source #

mempty is the aggregator that leaves probabilities untouched, and mappend compose aggregators.

Creation

makeAggregator :: ([(a, Probability)] -> [Probability]) -> Aggregator a Source #

Creates an aggregator from a function. The function should not modify the number of elements.

makePureAggregator :: ([Probability] -> [Probability]) -> Aggregator a Source #

 Creates an aggregator from a function ignoring the values. The function should not modify the number of elements.

separated :: Ord a => a -> Aggregator a -> Aggregator a -> Aggregator a Source #

Aggregator that applies the first aggregator on values less than x and the second on values greater than x. Potential probability at x is left untouched.

Application

modifyProbabilities :: Aggregator a -> [(a, Probability)] -> [Probability] Source #

Applies the aggregator and returns the modified list of probabilities.

aggregateWith :: Aggregator a -> [(a, Probability)] -> [(a, Probability)] Source #

 Applies an aggregator on a list of values tagged with their probability. The values themselves are left unchanged.

Useful aggregators

cumulative :: Aggregator a Source #

Adds to each probability the sum of the probabilities earlier in the list.

>>> aggregateWith cumulative $ toList $ uniform [1 .. 5]
[(1,1 % 5),(2,2 % 5),(3,3 % 5),(4,4 % 5),(5,1 % 1)]

decreasing :: Aggregator a Source #

Adds to each probability the sum of probabilities later in the list.

>>> aggregateWith decreasing  $ toList $ uniform [1 .. 5]
[(1,1 % 1),(2,4 % 5),(3,3 % 5),(4,2 % 5),(5,1 % 5)]

complementary :: Aggregator a Source #

Replaces each probability by its complement.

>>> aggregateWith complementary $ toList $ uniform [1 .. 5]
[(1,4 % 5),(2,4 % 5),(3,4 % 5),(4,4 % 5),(5,4 % 5)]