laop-0.1.0.6

Copyright(c) Armando Santos 2019-2020
Maintainerarmandoifsantos@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

LAoP.Dist

Contents

Description

LAoP is a library for algebraic (inductive) construction and manipulation of matrices in Haskell. See my Msc Thesis for the motivation behind the library, the underlying theory, and implementation details.

This module exports a type synonym Dist that represents a stochastic distribution matrix and several distribution construction functions.

Synopsis

Documentation

If the sum of the rows of a column matrix is equal to 1 then this stochastic matrix can be seen as a probability distribution.

This module is still experimental but it's already possible to model probabilistic programming problems with it. Import Nat or Type to access LAoP matrix combinators and then all you have to do is to define your sample space, either by creating a new data type or by abstracting it out via Natural.

Write manipulation functions and promote them to matrices via fromF or fromF' and you're good to go!

Dist and Prob type synonyms

newtype Dist a Source #

Type synonym for column vector matrices. This represents a probability distribution.

Constructors

D (Matrix Prob () a) 
Instances
Eq (Dist a) Source # 
Instance details

Defined in LAoP.Dist.Internal

Methods

(==) :: Dist a -> Dist a -> Bool #

(/=) :: Dist a -> Dist a -> Bool #

Num (Dist a) Source # 
Instance details

Defined in LAoP.Dist.Internal

Methods

(+) :: Dist a -> Dist a -> Dist a #

(-) :: Dist a -> Dist a -> Dist a #

(*) :: Dist a -> Dist a -> Dist a #

negate :: Dist a -> Dist a #

abs :: Dist a -> Dist a #

signum :: Dist a -> Dist a #

fromInteger :: Integer -> Dist a #

Ord (Dist a) Source # 
Instance details

Defined in LAoP.Dist.Internal

Methods

compare :: Dist a -> Dist a -> Ordering #

(<) :: Dist a -> Dist a -> Bool #

(<=) :: Dist a -> Dist a -> Bool #

(>) :: Dist a -> Dist a -> Bool #

(>=) :: Dist a -> Dist a -> Bool #

max :: Dist a -> Dist a -> Dist a #

min :: Dist a -> Dist a -> Dist a #

Show (Dist a) Source # 
Instance details

Defined in LAoP.Dist.Internal

Methods

showsPrec :: Int -> Dist a -> ShowS #

show :: Dist a -> String #

showList :: [Dist a] -> ShowS #

NFData (Dist a) Source # 
Instance details

Defined in LAoP.Dist.Internal

Methods

rnf :: Dist a -> () #

type Prob = Double Source #

Type synonym for probability value

Constraint type synonyms

type Countable a = KnownNat (Count a) Source #

Constraint type synonyms to keep the type signatures less convoluted

type Liftable a b = (Bounded a, Bounded b, Enum a, Enum b, Eq b, Num Prob, Ord Prob) Source #

Functor instance equivalent functions

fmapD :: (Liftable a b, CountableDimensionsN a b, FromListsN b a) => (a -> b) -> Dist a -> Dist b Source #

Functor instance

Applicative equivalent functions

unitD :: Dist () Source #

Applicative/Monoidal instance unit function

multD :: (CountableDimensionsN a b, CountableN (a, b), FromListsN (a, b) a, FromListsN (a, b) b, TrivialP a b) => Dist a -> Dist b -> Dist (a, b) Source #

Applicative/Monoidal instance mult function

Selective equivalent functions

selectD :: (FromListsN b b, CountableN b) => Dist (Either a b) -> Matrix Prob a b -> Dist b Source #

Selective instance function

branchD :: (Num e, CountableDimensionsN a b, CountableDimensionsN c (Either b c), FromListsN c b, FromListsN a b, FromListsN a a, FromListsN b b, FromListsN c c, FromListsN b a, FromListsN b c, FromListsN (Either b c) b, FromListsN (Either b c) c) => Dist (Either a b) -> Matrix Prob a c -> Matrix Prob b c -> Dist c Source #

Chooses which of the two given effectful functions to apply to a given argument;

ifD :: (CountableDimensionsN a (Either () a), FromListsN a a, FromListsN a (), FromListsN () a, FromListsN (Either () a) a) => Dist Bool -> Dist a -> Dist a -> Dist a Source #

Branch on a Boolean value, skipping unnecessary computations.

Monad equivalent functions

returnD :: forall a. (Enum a, FromListsN () a, Countable a) => a -> Dist a Source #

Monad instance return function

bindD :: Dist a -> Matrix Prob a b -> Dist b Source #

Monad instance '(>>=)' function

Distribution construction functions

choose :: FromListsN () a => Prob -> Dist a Source #

Constructs a Bernoulli distribution

shape :: FromListsN () a => (Prob -> Prob) -> [a] -> Dist a Source #

Creates a distribution given a shape function

linear :: FromListsN () a => [a] -> Dist a Source #

Constructs a Linear distribution

uniform :: FromListsN () a => [a] -> Dist a Source #

Constructs an Uniform distribution

negExp :: FromListsN () a => [a] -> Dist a Source #

Constructs an Negative Exponential distribution

normal :: FromListsN () a => [a] -> Dist a Source #

Constructs an Normal distribution

Converto to list of pairs

toValues :: forall a. (Enum a, Countable a, FromListsN () a) => Dist a -> [(a, Prob)] Source #

Transforms a Dist into a list of pairs.

Pretty print distribution

prettyDist :: forall a. (Show a, Enum a, Countable a, FromListsN () a) => Dist a -> String Source #

Pretty a distribution

prettyPrintDist :: forall a. (Show a, Enum a, Countable a, FromListsN () a) => Dist a -> IO () Source #

Pretty Print a distribution