distribution-1.0.0.0: Finite discrete probability distributions.

Safe HaskellSafe-Inferred

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)

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

Creation

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

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

makePureAggregator :: ([Probability] -> [Probability]) -> Aggregator aSource

 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 aSource

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 aSource

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 aSource

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 aSource

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)]