random-fu-0.2.6.2: Random number generation

Safe HaskellNone
LanguageHaskell98

Data.Random.Distribution

Synopsis

Documentation

class Distribution d t where Source

A Distribution is a data representation of a random variable's probability structure. For example, in Data.Random.Distribution.Normal, the Normal distribution is defined as:

data Normal a
    = StdNormal
    | Normal a a

Where the two parameters of the Normal data constructor are the mean and standard deviation of the random variable, respectively. To make use of the Normal type, one can convert it to an rvar and manipulate it or sample it directly:

x <- sample (rvar (Normal 10 2))
x <- sample (Normal 10 2)

A Distribution is typically more transparent than an RVar but less composable (precisely because of that transparency). There are several practical uses for types implementing Distribution:

  • Typically, a Distribution will expose several parameters of a standard mathematical model of a probability distribution, such as mean and std deviation for the normal distribution. Thus, they can be manipulated analytically using mathematical insights about the distributions they represent. For example, a collection of bernoulli variables could be simplified into a (hopefully) smaller collection of binomial variables.
  • Because they are generally just containers for parameters, they can be easily serialized to persistent storage or read from user-supplied configurations (eg, initialization data for a simulation).
  • If a type additionally implements the CDF subclass, which extends Distribution with a cumulative density function, an arbitrary random variable x can be tested against the distribution by testing fmap (cdf dist) x for uniformity.

On the other hand, most Distributions will not be closed under all the same operations as RVar (which, being a monad, has a fully turing-complete internal computational model). The sum of two uniformly-distributed variables, for example, is not uniformly distributed. To support general composition, the Distribution class defines a function rvar to construct the more-abstract and more-composable RVar representation of a random variable.

Minimal complete definition

Nothing

Methods

rvar :: d t -> RVar t Source

Return a random variable with this distribution.

rvarT :: d t -> RVarT n t Source

Return a random variable with the given distribution, pre-lifted to an arbitrary RVarT. Any arbitrary RVar can also be converted to an 'RVarT m' for an arbitrary m, using either lift or sample.

Instances

Distribution StdUniform Bool 
Distribution StdUniform Char 
Distribution StdUniform Double 
Distribution StdUniform Float 
Distribution StdUniform Int 
Distribution StdUniform Int8 
Distribution StdUniform Int16 
Distribution StdUniform Int32 
Distribution StdUniform Int64 
Distribution StdUniform Ordering 
Distribution StdUniform Word 
Distribution StdUniform Word8 
Distribution StdUniform Word16 
Distribution StdUniform Word32 
Distribution StdUniform Word64 
Distribution StdUniform () 
Distribution Uniform Bool 
Distribution Uniform Char 
Distribution Uniform Double 
Distribution Uniform Float 
Distribution Uniform Int 
Distribution Uniform Int8 
Distribution Uniform Int16 
Distribution Uniform Int32 
Distribution Uniform Int64 
Distribution Uniform Integer 
Distribution Uniform Ordering 
Distribution Uniform Word 
Distribution Uniform Word8 
Distribution Uniform Word16 
Distribution Uniform Word32 
Distribution Uniform Word64 
Distribution Uniform () 
(Floating a, Distribution StdUniform a) => Distribution Exponential a 
(Floating a, Distribution StdUniform a) => Distribution StretchedExponential a 
Distribution Normal Double 
Distribution Normal Float 
(Floating a, Ord a, Distribution Normal a, Distribution StdUniform a) => Distribution Gamma a 
Distribution Beta Double 
Distribution Beta Float 
(Fractional t, Distribution Gamma t) => Distribution ChiSquare t 
(RealFloat a, Distribution StdUniform a) => Distribution Rayleigh a 
(Floating a, Distribution Normal a, Distribution ChiSquare a) => Distribution T a 
(RealFloat a, Ord a, Distribution StdUniform a) => Distribution Triangular a 
(Floating a, Distribution StdUniform a) => Distribution Weibull a 
(Floating a, Distribution StdUniform a) => Distribution Pareto a 
HasResolution r => Distribution StdUniform (Fixed r) 
HasResolution r => Distribution Uniform (Fixed r) 
(Fractional a, Distribution Gamma a) => Distribution Dirichlet [a] 
(Fractional b, Ord b, Distribution StdUniform b) => Distribution (Bernoulli b) Bool 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Word64 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Word32 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Word16 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Word8 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Word 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Int64 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Int32 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Int16 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Int8 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Int 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Integer 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Double 
Distribution (Bernoulli b0) Bool => Distribution (Bernoulli b) Float 
(Fractional p, Ord p, Distribution Uniform p) => Distribution (Categorical p) a 
(Num t, Ord t, Vector v t) => Distribution (Ziggurat v) t 
(Integral a, Floating b, Ord b, Distribution Normal b, Distribution StdUniform b) => Distribution (Erlang a) b 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Word64 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Word32 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Word16 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Word8 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Word 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Int64 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Int32 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Int16 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Int8 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Int 
(Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b) Integer 
Distribution (Binomial b0) Integer => Distribution (Binomial b) Double 
Distribution (Binomial b0) Integer => Distribution (Binomial b) Float 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Word64) b0, Distribution (Binomial b0) Word64) => Distribution (Poisson b) Word64 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Word32) b0, Distribution (Binomial b0) Word32) => Distribution (Poisson b) Word32 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Word16) b0, Distribution (Binomial b0) Word16) => Distribution (Poisson b) Word16 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Word8) b0, Distribution (Binomial b0) Word8) => Distribution (Poisson b) Word8 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Word) b0, Distribution (Binomial b0) Word) => Distribution (Poisson b) Word 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Int64) b0, Distribution (Binomial b0) Int64) => Distribution (Poisson b) Int64 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Int32) b0, Distribution (Binomial b0) Int32) => Distribution (Poisson b) Int32 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Int16) b0, Distribution (Binomial b0) Int16) => Distribution (Poisson b) Int16 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Int8) b0, Distribution (Binomial b0) Int8) => Distribution (Poisson b) Int8 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Int) b0, Distribution (Binomial b0) Int) => Distribution (Poisson b) Int 
(RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Integer) b0, Distribution (Binomial b0) Integer) => Distribution (Poisson b) Integer 
Distribution (Poisson b0) Integer => Distribution (Poisson b) Double 
Distribution (Poisson b0) Integer => Distribution (Poisson b) Float 
(Distribution (Bernoulli b) Bool, RealFloat a) => Distribution (Bernoulli b) (Complex a) 
(Distribution (Bernoulli b) Bool, Integral a) => Distribution (Bernoulli b) (Ratio a) 
(Num a, Eq a, Fractional p, Distribution (Binomial p) a) => Distribution (Multinomial p) [a] 

class Distribution d t => CDF d t where Source

Methods

cdf :: d t -> t -> Double Source

Return the cumulative distribution function of this distribution. That is, a function taking x :: t to the probability that the next sample will return a value less than or equal to x, according to some order or partial order (not necessarily an obvious one).

In the case where t is an instance of Ord, cdf should correspond to the CDF with respect to that order.

In other cases, cdf is only required to satisfy the following law: fmap (cdf d) (rvar d) must be uniformly distributed over (0,1). Inclusion of either endpoint is optional, though the preferred range is (0,1].

Note that this definition requires that cdf for a product type should _not_ be a joint CDF as commonly defined, as that definition violates both conditions. Instead, it should be a univariate CDF over the product type. That is, it should represent the CDF with respect to the lexicographic order of the product.

The present specification is probably only really useful for testing conformance of a variable to its target distribution, and I am open to suggestions for more-useful specifications (especially with regard to the interaction with product types).

Instances

CDF StdUniform Bool 
CDF StdUniform Char 
CDF StdUniform Double 
CDF StdUniform Float 
CDF StdUniform Int 
CDF StdUniform Int8 
CDF StdUniform Int16 
CDF StdUniform Int32 
CDF StdUniform Int64 
CDF StdUniform Ordering 
CDF StdUniform Word 
CDF StdUniform Word8 
CDF StdUniform Word16 
CDF StdUniform Word32 
CDF StdUniform Word64 
CDF StdUniform () 
CDF Uniform Bool 
CDF Uniform Char 
CDF Uniform Double 
CDF Uniform Float 
CDF Uniform Int 
CDF Uniform Int8 
CDF Uniform Int16 
CDF Uniform Int32 
CDF Uniform Int64 
CDF Uniform Integer 
CDF Uniform Ordering 
CDF Uniform Word 
CDF Uniform Word8 
CDF Uniform Word16 
CDF Uniform Word32 
CDF Uniform Word64 
CDF Uniform () 
(Real a, Distribution Exponential a) => CDF Exponential a 
(Real a, Distribution StretchedExponential a) => CDF StretchedExponential a 
(Real a, Distribution Normal a) => CDF Normal a 
(Real a, Distribution Gamma a) => CDF Gamma a 
(Real t, Distribution ChiSquare t) => CDF ChiSquare t 
(Real a, Distribution Rayleigh a) => CDF Rayleigh a 
(Real a, Distribution T a) => CDF T a 
(RealFrac a, Distribution Triangular a) => CDF Triangular a 
(Real a, Distribution Weibull a) => CDF Weibull a 
(Real a, Distribution Pareto a) => CDF Pareto a 
HasResolution r => CDF StdUniform (Fixed r) 
HasResolution r => CDF Uniform (Fixed r) 
(Distribution (Bernoulli b) Bool, Real b) => CDF (Bernoulli b) Bool 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Word64 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Word32 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Word16 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Word8 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Word 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Int64 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Int32 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Int16 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Int8 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Int 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Integer 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Double 
CDF (Bernoulli b0) Bool => CDF (Bernoulli b) Float 
(Integral a, Real b, Distribution (Erlang a) b) => CDF (Erlang a) b 
(Real b0, Distribution (Binomial b0) Word64) => CDF (Binomial b) Word64 
(Real b0, Distribution (Binomial b0) Word32) => CDF (Binomial b) Word32 
(Real b0, Distribution (Binomial b0) Word16) => CDF (Binomial b) Word16 
(Real b0, Distribution (Binomial b0) Word8) => CDF (Binomial b) Word8 
(Real b0, Distribution (Binomial b0) Word) => CDF (Binomial b) Word 
(Real b0, Distribution (Binomial b0) Int64) => CDF (Binomial b) Int64 
(Real b0, Distribution (Binomial b0) Int32) => CDF (Binomial b) Int32 
(Real b0, Distribution (Binomial b0) Int16) => CDF (Binomial b) Int16 
(Real b0, Distribution (Binomial b0) Int8) => CDF (Binomial b) Int8 
(Real b0, Distribution (Binomial b0) Int) => CDF (Binomial b) Int 
(Real b0, Distribution (Binomial b0) Integer) => CDF (Binomial b) Integer 
CDF (Binomial b0) Integer => CDF (Binomial b) Double 
CDF (Binomial b0) Integer => CDF (Binomial b) Float 
(Real b0, Distribution (Poisson b0) Word64) => CDF (Poisson b) Word64 
(Real b0, Distribution (Poisson b0) Word32) => CDF (Poisson b) Word32 
(Real b0, Distribution (Poisson b0) Word16) => CDF (Poisson b) Word16 
(Real b0, Distribution (Poisson b0) Word8) => CDF (Poisson b) Word8 
(Real b0, Distribution (Poisson b0) Word) => CDF (Poisson b) Word 
(Real b0, Distribution (Poisson b0) Int64) => CDF (Poisson b) Int64 
(Real b0, Distribution (Poisson b0) Int32) => CDF (Poisson b) Int32 
(Real b0, Distribution (Poisson b0) Int16) => CDF (Poisson b) Int16 
(Real b0, Distribution (Poisson b0) Int8) => CDF (Poisson b) Int8 
(Real b0, Distribution (Poisson b0) Int) => CDF (Poisson b) Int 
(Real b0, Distribution (Poisson b0) Integer) => CDF (Poisson b) Integer 
CDF (Poisson b0) Integer => CDF (Poisson b) Double 
CDF (Poisson b0) Integer => CDF (Poisson b) Float 
(CDF (Bernoulli b) Bool, RealFloat a) => CDF (Bernoulli b) (Complex a) 
(CDF (Bernoulli b) Bool, Integral a) => CDF (Bernoulli b) (Ratio a)