úΞ ™LP      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOSafe\!Distribution over values of type a.'Due to their internal representations,  Distribution can not have Functor or Monad instances. However,   is the equivalent of fmap for distributions and  and $ are respectively the equivalent of return and >>=.dConverts the distribution to a mapping from values to their probability. Values with probability 0. are not included in the resulting mapping.'Probability. Should be between 0 and 1.^Converts the distribution to a list of increasing values whose probability is greater than 0.. To each value is associated its probability.Q Returns the number of elements with non-zero probability in the distribution.5Values in the distribution with non-zero probability."Distribution that assigns to each value from the given (value, weight)( pairs a probability proportional to weight.'fromList [('A', 1), ('B', 2), ('C', 1)].fromList [('A',1 % 4),('B',1 % 2),('C',1 % 4)]¿Values may appear multiple times in the list. In this case, their total weight is the sum of the different associated weights. Values whose total weight is zero or negative are ignored.Distribution that assigns to x the probability of 1.always 0fromList [(0,1 % 1)] always 42fromList [(42,1 % 1)]„Uniform distribution over the values. The probability of each element is proportional to its number of appearance in the list.uniform [1 .. 6]FfromList [(1,1 % 6),(2,1 % 6),(3,1 % 6),(4,1 % 6),(5,1 % 6),(6,1 % 6)] True with given probability and False with complementary probability. 5Applies a function to the values in the distribution.select abs $ uniform [-1, 0, 1]fromList [(0,1 % 3),(1,2 % 3)] QReturns a new distribution conditioning on the predicate holding on the value.!assuming (> 2) $ uniform [1 .. 6]2fromList [(3,1 % 4),(4,1 % 4),(5,1 % 4),(6,1 % 4)]lNote that the resulting distribution will be invalid if the predicate does not hold on any of the values.!assuming (> 7) $ uniform [1 .. 6] fromList [] :Returns a new distribution using the Bayesian update rule.Using this example: Lhttps://en.wikipedia.org/wiki/Bayesian_inference#Probability_of_a_hypothesis ÿ(data CookieBowl = Bowl1 | Bowl2 deriving (Eq,Ord) data CookieType = Plain | ChocolateChip deriving (Eq,Ord) assumption :: Distribution CookieBowl assumption = uniform [Bowl1,Bowl2] update :: Cookie -> Distribution CookieBowl -> Distribution CookieBowl update c = observing f where f b = case b of -- Bowl #1 contains 10 chocolate chip cookies and 30 plain cookies Bowl1 -> fromList [(c == ChocolateChip,10),(c == Plain,30)] -- Bowl #2 contains 20 of each flavour of cookie Bowl2 -> fromList [(c == ChocolateChip,20),(c == Plain,20)]¥The "update" function in this example can be used to update the probability distribution of which bowl you have based on observing a random cookie inside the bowl.NBinomial distribution. Assigns to each number of successes its probability. trials 2 $ uniform [True, False](fromList [(0,1 % 4),(1,1 % 2),(2,1 % 4)]Takes nL samples from the distribution and returns the distribution of their sum.times 2 $ uniform [1 .. 3]<fromList [(2,1 % 9),(3,2 % 9),(4,1 % 3),(5,2 % 9),(6,1 % 9)].This function makes use of the more efficient trials. functions for input distributions of size 2.$size $ times 10000 $ uniform [1, 10]10001—Computes for each value in the distribution a new distribution, and then combines those distributions, giving each the weight of the original value.4uniform [1 .. 3] `andThen` (\ n -> uniform [1 .. n])+fromList [(1,11 % 18),(2,5 % 18),(3,1 % 9)]See the  Experiment data type in the  3 module for a more "natural" monadic interface. ' Determines if a distribution is valid.sA distribution is valid if and only if its domain is non-empty. Invalid distributions may arise from the use of   for instance.PLiterals are interpreted as distributions that always return the given value.42 == always 42TruefBinary operations on distributions are defined to be the binary operation on each pair of elements.For this reason, (+) and (*)C are not related in the same way as they are on natural numbers.1For instance, it is not always the case that: 3 * d == d + d + dlet d = uniform [0, 1]3 * dfromList [(0,1 % 2),(3,1 % 2)] d + d + d2fromList [(0,1 % 8),(1,3 % 8),(2,3 % 8),(3,1 % 8)]&For this particular behavior, see the  function.OLifts the bounds to the distributions that return them with probability one./Note that the degenerate distributions of size 0' will be less than the distribution minBound.FAppart from that, all other distributions d have the property that minBound <= d <= maxBound= if this property holds on the values of the distribution.A distribution d1& is less than some other distribution d2A if the smallest value that has a different probability in d1 and d2 is more probable in d1.QBy convention, empty distributions are less than everything except themselves.P   P 7Safe!Possible outcomes of a coin flip.&Distribution over the sides of a coin. Fair coin. Flips n5 times the given coin and counts the number of heads.!HRerolls the coin once if the first outcome satifies the given predicate. ! ! ! !Safe ')Distribution of the result of dice rolls.( Fair dice of n faces.) Fair dice of 4 faces.* Fair dice of 6 faces.+ Fair dice of 8 faces., Fair dice of 10 faces.Q Fair dice of 12 faces.- Fair dice of 20 faces..Rolls n+ times the given dice and sums the results./HRerolls the dice once if the first outcome satifies the given predicate. '()*+,Q-./ '()*+,-./ '()*+,-./ '()*+,Q-./Safe 07Probability that a predicate holds on the distribution.8probability (\ x -> x == 1 || x == 6) $ uniform [1 .. 6]1 % 3Takes O(n) time. See 1 and 2; for a more efficient ways to query elements and ranges.1Probability of a given value.Takes  O(log(n)) time.2Probability of a the inclusive  [low, high] range. When  low > high, the probability is 0.Takes  O(log(n) + m) time, where n( is the size of the distribution and m the size of the range.34Returns the expectation, or mean, of a distribution.expectation $ uniform [0, 1]0.5+Empty distributions have an expectation of 0.4'Returns the variance of a distribution.variance $ always 10.0variance $ uniform [0 .. 1]0.25variance $ uniform [1 .. 7]4.0'Empty distributions have a variance of 0.5Standard deviation.standardDeviation $ always 10.0$standardDeviation $ uniform [0 .. 1]0.5$standardDeviation $ uniform [1 .. 7]2.06PReturns the smallest value in the distribution such that at least a fraction p' of the values are less or equal to it. quantile 0.0 $ uniform [1, 2, 3]Just 1 quantile 0.5 $ uniform [1, 2, 3]Just 2 quantile 1.0 $ uniform [1, 2, 3]Just 3quantile 0.5 $ fromList []Nothing7†Returns the median of the values. The median is the smallest value such that at least 50% of the values are less or equal to it.&median $ fromList [(1, 0.6), (2, 0.4)]Just 1&median $ fromList [(1, 0.4), (2, 0.6)]Just 28 Synonym of 3.90Returns all values whose probability is maximal. 0123456789 0123456789 0123845796 0123456789Safe%&:%Monadic description of distributions.;DConverts a concrete distribution into its monadic representation.<TConverts the monadic description of the distribution to a concrete distribution. :RST;<=>?:;<:;<:RST;<=>?Safe:\ @#Generator of random values of type a.QCan be created in linear time from distributions and sampled in constant time.UNumber of buckets.V"Probability to stay in the bucket.WValue in the bucket.X9Index of the "guest" value. Used when the bucket is left.A:Creates a generator from the given non-empty distribution.Runs in O(n) time where n! is the size of the distribution.BSafe version of A . Returns Nothing) when the given distribution is empty.C(Picks a random value from the generator.Runs in constant O(1) time.D(Picks a random value from the generator.Runs in constant O(1) time. @YUVWXABCDE@ABCD@ABDC@YUVWXABCDESafe F(Functions that can modify probabilities.GIApplies the aggregator and returns the modified list of probabilities.Hv Applies an aggregator on a list of values tagged with their probability. The values themselves are left unchanged.Iu Creates an aggregator from a function ignoring the values. The function should not modify the number of elements.J`Creates an aggregator from a function. The function should not modify the number of elements.KAAggregator 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.LJAdds to each probability the sum of the probabilities earlier in the list.4aggregateWith cumulative $ toList $ uniform [1 .. 5]3[(1,1 % 5),(2,2 % 5),(3,3 % 5),(4,4 % 5),(5,1 % 1)]M,Replaces each probability by its complement.7aggregateWith complementary $ toList $ uniform [1 .. 5]3[(1,4 % 5),(2,4 % 5),(3,4 % 5),(4,4 % 5),(5,4 % 5)]NDAdds to each probability the sum of probabilities later in the list.5aggregateWith decreasing $ toList $ uniform [1 .. 5]3[(1,1 % 1),(2,4 % 5),(3,3 % 5),(4,2 % 5),(5,1 % 5)]OZ? is the aggregator that leaves probabilities untouched, and [ compose aggregators. F\GHIJKLMNO FGHIJKLMN FGJIKGHLNM F\GHIJKLMNOSafe. 0123456789:;<@ABCDFGHIJKLMN]     !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY Z[\]^_`aJbcdbcePf+distribution-1.1.1.0-CCwMUcIDsr02h5MeQSNzK4Data.Distribution.CoreData.Distribution.Domain.CoinData.Distribution.Domain.DiceData.Distribution.MeasureData.Distribution.MonadicData.Distribution.SampleData.Distribution.AggregatorData.DistributionMonadic DistributiontoMap ProbabilitytoListsizesupportfromListalwaysuniformwithProbabilityselectassuming observing combineWithtrialstimesiidandThenisValid$fMonoidDistribution$fFloatingDistribution$fFractionalDistribution$fNumDistribution$fBoundedDistribution$fOrdDistribution$fShowDistribution$fEqDistributionCoinSideHeadTailCoincoinflipsOfreflipOn $fEqCoinSide $fOrdCoinSide$fShowCoinSide$fReadCoinSide$fEnumCoinSideDicediced4d6d8d10d20rollsOfrerollOn probability probabilityAt probabilityIn expectationvariancestandardDeviationquantilemedianmeanmodes Experimentfromrun$fMonadExperiment$fApplicativeExperiment$fFunctorExperiment GeneratorfromDistributionsafeFromDistribution getSamplesample$fFunctorGenerator AggregatormodifyProbabilities aggregateWithmakePureAggregatormakeAggregator separated cumulative complementary decreasing$fMonoidAggregatord12ReturnBindPrimcapacity probabilitiesvaluesindexesbaseGHC.Basememptymappend