random-fu-0.2.7.0: Random number generation

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.

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

 Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methodsrvar :: StdUniform () -> RVar () Source #rvarT :: StdUniform () -> RVarT n () Source # Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methodsrvar :: Uniform () -> RVar () Source #rvarT :: Uniform () -> RVarT n () Source # Source # Methodsrvar :: Exponential a -> RVar a Source #rvarT :: Exponential a -> RVarT n a Source # Source # Methods Source # Methods Source # Methods Source # Methodsrvar :: Gamma a -> RVar a Source #rvarT :: Gamma a -> RVarT n a Source # Source # Methods Source # Methods Source # Methodsrvar :: ChiSquare t -> RVar t Source #rvarT :: ChiSquare t -> RVarT n t Source # Source # Methodsrvar :: Rayleigh a -> RVar a Source #rvarT :: Rayleigh a -> RVarT n a Source # Source # Methodsrvar :: T a -> RVar a Source #rvarT :: T a -> RVarT n a Source # Source # Methodsrvar :: Triangular a -> RVar a Source #rvarT :: Triangular a -> RVarT n a Source # Source # Methodsrvar :: Weibull a -> RVar a Source #rvarT :: Weibull a -> RVarT n a Source # Source # Methodsrvar :: Pareto a -> RVar a Source #rvarT :: Pareto a -> RVarT n a Source # Source # Methodsrvar :: StdUniform (Fixed r) -> RVar (Fixed r) Source #rvarT :: StdUniform (Fixed r) -> RVarT n (Fixed r) Source # Source # Methodsrvar :: Uniform (Fixed r) -> RVar (Fixed r) Source #rvarT :: Uniform (Fixed r) -> RVarT n (Fixed r) Source # Source # Methodsrvar :: Dirichlet [a] -> RVar [a] Source #rvarT :: Dirichlet [a] -> RVarT n [a] Source # Source # Methodsrvar :: StdSimplex [a] -> RVar [a] Source #rvarT :: StdSimplex [a] -> RVarT n [a] Source # Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods (Fractional p, Ord p, Distribution Uniform p) => Distribution (Categorical p) a Source # Methodsrvar :: Categorical p a -> RVar a Source #rvarT :: Categorical p a -> RVarT n a Source # (Num t, Ord t, Vector v t) => Distribution (Ziggurat v) t Source # Methodsrvar :: Ziggurat v t -> RVar t Source #rvarT :: Ziggurat v t -> RVarT n t Source # Source # Methodsrvar :: Erlang a b -> RVar b Source #rvarT :: Erlang a b -> RVarT n b Source # (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Word64 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Word32 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Word16 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Word8 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Word Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Int64 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Int32 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Int16 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Int8 Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Int Source # Methods (Floating b0, Ord b0, Distribution Beta b0, Distribution StdUniform b0) => Distribution (Binomial b0) Integer Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods (RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Word) b0, Distribution (Binomial b0) Word) => Distribution (Poisson b0) Word Source # Methods Source # Methods Source # Methods Source # Methods (RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Int8) b0, Distribution (Binomial b0) Int8) => Distribution (Poisson b0) Int8 Source # Methods (RealFloat b0, Distribution StdUniform b0, Distribution (Erlang Int) b0, Distribution (Binomial b0) Int) => Distribution (Poisson b0) Int Source # Methods Source # Methods Source # Methods Source # Methods (Distribution (Bernoulli b) Bool, RealFloat a) => Distribution (Bernoulli b) (Complex a) Source # Methodsrvar :: Bernoulli b (Complex a) -> RVar (Complex a) Source #rvarT :: Bernoulli b (Complex a) -> RVarT n (Complex a) Source # (Distribution (Bernoulli b) Bool, Integral a) => Distribution (Bernoulli b) (Ratio a) Source # Methodsrvar :: Bernoulli b (Ratio a) -> RVar (Ratio a) Source #rvarT :: Bernoulli b (Ratio a) -> RVarT n (Ratio a) Source # (Num a, Eq a, Fractional p, Distribution (Binomial p) a) => Distribution (Multinomial p) [a] Source # Methodsrvar :: Multinomial p [a] -> RVar [a] Source #rvarT :: Multinomial p [a] -> RVarT n [a] Source #

class Distribution d t => PDF d t where Source #

Methods

pdf :: d t -> t -> Double Source #

logPdf :: d t -> t -> Double Source #

Instances

 Source # Methods Source # Methods (Real a, Floating a, Distribution Normal a) => PDF Normal a Source # Methodspdf :: Normal a -> a -> Double Source #logPdf :: Normal a -> a -> Double Source # Source # Methods Source # Methods (Real b0, Distribution (Binomial b0) Word64) => PDF (Binomial b0) Word64 Source # Methods (Real b0, Distribution (Binomial b0) Word32) => PDF (Binomial b0) Word32 Source # Methods (Real b0, Distribution (Binomial b0) Word16) => PDF (Binomial b0) Word16 Source # Methods (Real b0, Distribution (Binomial b0) Word8) => PDF (Binomial b0) Word8 Source # Methods (Real b0, Distribution (Binomial b0) Word) => PDF (Binomial b0) Word Source # Methodspdf :: Binomial b0 Word -> Word -> Double Source # (Real b0, Distribution (Binomial b0) Int64) => PDF (Binomial b0) Int64 Source # Methods (Real b0, Distribution (Binomial b0) Int32) => PDF (Binomial b0) Int32 Source # Methods (Real b0, Distribution (Binomial b0) Int16) => PDF (Binomial b0) Int16 Source # Methods (Real b0, Distribution (Binomial b0) Int8) => PDF (Binomial b0) Int8 Source # Methodspdf :: Binomial b0 Int8 -> Int8 -> Double Source # (Real b0, Distribution (Binomial b0) Int) => PDF (Binomial b0) Int Source # Methodspdf :: Binomial b0 Int -> Int -> Double Source # (Real b0, Distribution (Binomial b0) Integer) => PDF (Binomial b0) Integer Source # Methods PDF (Binomial b0) Integer => PDF (Binomial b0) Double Source # Methods PDF (Binomial b0) Integer => PDF (Binomial b0) Float Source # Methods

class Distribution d t => CDF d t where Source #

Minimal complete definition

cdf

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

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