Copyright | (c) David A Roberts 2015-2021 |
---|---|
License | GPL-3 |
Maintainer | d@vidr.cc |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- module Language.Stochaskell.Prelude
- data Expression t
- class Indexable a i e | a -> i e where
- (!) :: a -> i -> e
- bounds :: a -> Interval i
- deleteAt :: Indexable a i e => a -> i -> a
- insertAt :: Indexable a i e => a -> (i, e) -> a
- replaceAt :: Indexable a i e => a -> (i, e) -> a
- deleteIndex :: a -> i -> a
- insertIndex :: a -> i -> e -> a
- replaceIndex :: a -> i -> e -> a
- foldlE :: ExprType b => (Expression b -> Expression a -> Expression b) -> Expression b -> Expression [a] -> Expression b
- foldrE :: ExprType b => (Expression a -> Expression b -> Expression b) -> Expression b -> Expression [a] -> Expression b
- scanlE :: ExprType b => (Expression b -> Expression a -> Expression b) -> Expression b -> Expression [a] -> Expression [b]
- scanrE :: ExprType b => (Expression a -> Expression b -> Expression b) -> Expression b -> Expression [a] -> Expression [b]
- foldE :: forall t f. (Functor f, Constructor (f (FixE f)), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (Expression (f t) -> t) -> FixE' f -> t
- unfoldE :: forall t f. (Functor f, Constructor (f t), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (t -> Expression (f t)) -> t -> FixE' f
- constSymbol :: forall t. ExprType t => String -> Expression t
- d :: (ExprTuple s, ExprTuple t) => s -> t -> RMat
- factorial' :: Z -> Z
- logFactorial' :: Z -> R
- find' :: ExprType e => (Expression e -> B) -> Expression e -> Expression [e] -> Expression e
- findSortedInsertIndex :: R -> RVec -> Z
- findSortedInsertIndexBound :: Interval Z -> R -> RVec -> Z
- floor' :: R -> Z
- min' :: Expression a -> Expression a -> Expression a
- solve :: ExprTuple t => t -> t -> EEnv
- solveP :: ExprTuple t => P t -> t -> EEnv
- sum' :: (ExprType a, Num a) => Expression [a] -> Expression a
- symbol :: forall t. ExprType t => String -> Expression t
- symbols :: ExprType t => String -> [Expression t]
- class InnerProduct v e | v -> e where
- (<.>) :: v -> v -> e
- class LinearOperator m v | m -> v, v -> m where
- class Matrix m i e | m -> i e where
- matrix :: AbstractArray i e -> m
- blockMatrix :: [[m]] -> m
- eye :: i -> m
- zeros :: i -> i -> m
- matrixRows :: m -> i
- matrixCols :: m -> i
- designMatrix :: (Indexable v i e, Num i) => i -> AbstractArray i v -> m
- class Scalable a v | v -> a where
- (*>) :: a -> v -> v
- class SquareMatrix m e | m -> e where
- class Transposable m mt | m -> mt, mt -> m where
- class Vector v i e | v -> i e, i e -> v where
- vector :: AbstractArray i e -> v
- blockVector :: [v] -> v
- vectorSize :: v -> i
- type B = Expression Bool
- type R = Expression Double
- type Z = Expression Integer
- type BVec = Expression [Bool]
- type RVec = Expression [Double]
- type ZVec = Expression [Integer]
- type BMat = Expression [[Bool]]
- type RMat = Expression [[Double]]
- type ZMat = Expression [[Integer]]
- class Cast a b where
- cast :: a -> b
- boolean :: (Eq a, Boolean a, Boolean b) => a -> b
- integer :: (Integral i, Num n) => i -> n
- real :: (Real r, Fractional f) => r -> f
- list :: (IsList l, IsList l', Item l ~ Item l') => l -> l'
- type Interval i = (i, i)
- data AbstractArray i e
- (...) :: a -> a -> AbstractArray a a
- data P t
- class Monad m => Distribution d s m t | d m t -> s
- class Joint m i r f | m -> i where
- joint :: (AbstractArray i r -> f) -> AbstractArray i (m r) -> m f
- data Bernoulli p
- data Bernoullis p
- bernoulli :: Distribution Bernoulli s m t => s -> m t
- bernoullis :: Distribution Bernoullis s m t => s -> m t
- bernoulliLogit :: Distribution Bernoulli s m t => s -> m t
- bernoulliLogits :: Distribution Bernoullis s m t => s -> m t
- data Geometric a
- data NegBinomial a
- data PMF a
- data Poisson a
- geometric :: (Distribution Geometric t1 m t2, Num t2) => Integer -> t1 -> m t2
- negBinomial :: Distribution NegBinomial (a, b) m t => a -> b -> m t
- pmf :: Distribution PMF s m t => s -> m t
- poisson :: Distribution Poisson s m t => s -> m t
- data Beta a
- data Cauchy a
- data Gamma a
- data InvGamma a
- data Logistic a
- data Normal a
- data Normals a
- data Uniform a
- data Uniforms a
- beta :: Distribution Beta (a, b) m t => a -> b -> m t
- cauchy :: Distribution Cauchy (a, b) m t => a -> b -> m t
- gamma :: Distribution Gamma (a, b) m t => a -> b -> m t
- invGamma :: Distribution InvGamma (a, b) m t => a -> b -> m t
- logistic :: Distribution Logistic (a, b) m t => a -> b -> m t
- normal :: Distribution Normal (a, b) m t => a -> b -> m t
- normals :: Distribution Normals (a, b) m t => a -> b -> m t
- uniform :: Distribution Uniform (a, b) m t => a -> b -> m t
- uniforms :: Distribution Uniforms (a, b) m t => a -> b -> m t
- data OrderedSample a
- data PoissonProcess a
- orderedSample :: Distribution OrderedSample (a, b) m t => a -> b -> m t
- poissonProcess :: Distribution PoissonProcess (a, b, c) m t => a -> b -> c -> m t
- data LKJ a
- corrLKJ :: Distribution LKJ (a, b) m t => a -> b -> m t
- lpdf :: (ExprTuple t, Show t) => P t -> t -> R
- lpdfAux :: (ExprTuple t, Show t) => P t -> t -> R
- lpdfAuxC :: (Constructor t, Show t) => P (Expression t) -> Expression t -> R
- lpdfCond :: (ExprTuple s, ExprTuple t, Show t) => (s -> P t) -> s -> t -> R
- pdf :: (ExprTuple t, Show t) => P t -> t -> R
- density :: ExprTuple t => P t -> t -> LogFloat
- density' :: ExprTuple t => P t -> t -> LogFloat
- lpdfGamma :: Double -> Double -> Double -> Double
- lpdfNegBinomial :: Integer -> Double -> Double -> Double
- lpdfNormal :: Floating a => a -> a -> a -> a
- lpdfPoisson :: Integer -> Double -> Double
- lpdfUniform :: (Ord p, Floating p) => p -> p -> p -> p
- lpdfDiscreteUniform :: (Floating p, Integral a) => a -> a -> a -> p
- mixture :: forall t. ExprTuple t => [(R, P t)] -> P t
- mixture' :: ExprTuple t => [(R, P t)] -> P t
- truncated :: Expression t -> Expression t -> P (Expression t) -> P (Expression t)
- foldP :: forall t f. (Traversable f, Constructor (f (FixE f)), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (Expression (f t) -> P t) -> FixE' f -> P t
- unfoldP :: forall t f. (Traversable f, Constructor (f t), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (t -> P (Expression (f t))) -> t -> P (FixE' f)
- chain' :: ExprTuple t => Z -> (t -> P t) -> t -> P t
- chainRange' :: forall t. ExprTuple t => Interval Z -> (Z -> t -> P t) -> t -> P t
- lognormal :: (Distribution Normal (a, b1) m b2, Floating b2) => a -> b1 -> m b2
- normalChol :: Z -> RVec -> RMat -> P RVec
- normalsChol :: Z -> Z -> RVec -> RMat -> P RMat
- normalCond :: Z -> (Expression t -> Expression t -> R) -> R -> Expression [t] -> RVec -> Expression t -> P R
- compileCC :: forall s t. (ExprTuple s, ExprTuple t) => (s -> P t) -> IO (s -> IO t)
- runCC :: forall s t. (ExprTuple s, ExprTuple t) => (s -> P t) -> s -> IO t
- runStep :: forall t. ExprTuple t => (t -> P t) -> t -> IO t
- simulate :: ExprTuple t => P t -> IO t
- hmcStan :: ExprTuple t => Int -> P t -> IO [t]
- hmcStanInit :: ExprTuple t => Int -> P t -> t -> IO [t]
- rjmc :: (ExprTuple t, IfB t, BooleanOf t ~ B, Show t) => P t -> (t -> P t) -> t -> P t
- rjmcC :: (Constructor t, Show t) => P (Expression t) -> (t -> P (Expression t)) -> Expression t -> P (Expression t)
- rjmc1 :: (ExprType t, ExprTuple t, IfB t, BooleanOf t ~ B, Show t) => P t -> (t -> P t) -> t -> P t
- rjmc1Ratio :: (ExprTuple t, Show t) => P t -> (t -> P t) -> t -> t -> R
- binarize :: (forall a. (Num a, EqB a, OrdB a) => a -> BooleanOf a) -> ConstVal -> ConstVal
- caseZ :: forall t. ExprTuple t => Z -> [t] -> t
- chain :: Monad m => Int -> (b -> m b) -> b -> m b
- chainRange :: (Num i, Monad m) => (Int, Int) -> (i -> x -> m x) -> x -> m x
- debug :: ExprTuple t => String -> t -> t
- deepseq :: NFData a => a -> b -> b
- fromCase :: forall c t. (Constructor c, ExprTuple t) => (c -> t) -> Expr c -> t
- fromCaseP :: forall c t. (Constructor c, ExprTuple t) => (c -> P t) -> Expression c -> P t
- fromCaseP' :: forall c t. (Constructor c, ExprTuple t) => (c -> P t) -> Expression c -> P t
- fromRight' :: Either String b -> b
- interpolate :: (Ord a, Fractional a) => [(a, a)] -> a -> a
- iterateLimit :: Monad m => Int -> (a -> m a) -> a -> m [a]
- linspace :: (IsList l, e ~ Item l, Fractional e, Integral i) => (e, e) -> i -> l
- logFromLogFloat :: LogFloat -> Double
- loop :: Monad m => a -> (a -> m a) -> m ()
- mean :: (Foldable t, Fractional a) => t a -> a
- qfDiag :: RMat -> RVec -> RMat
- readRealMatrix :: FilePath -> IO ConstVal
- selectItems :: [a] -> [Bool] -> [a]
- setRandomSeed :: Int -> IO ()
- silence' :: IO a -> IO a
- slice :: ConstVal -> AbstractArray Integer [Integer] -> ConstVal
- square :: Num a => a -> a
- staircase :: Ord a => [a] -> [a] -> a -> a
- stochaskell :: IO ()
- tic :: IO NominalDiffTime
- toc :: NominalDiffTime -> IO NominalDiffTime
- vizIR :: ExprTuple t => P t -> IO String
- module Data.Either.Utils
- uniq :: Eq a => [a] -> [a]
- subIndex :: Eq a => [a] -> [a] -> Maybe Int
- grab :: Int -> State [a] [a]
- fixedWidth :: [Int] -> WholeFunc a [a]
- wholeMap :: WholeFunc a b -> [a] -> [b]
- seqList :: [a] -> [a]
- alwaysElemRIndex :: Eq a => a -> [a] -> Int
- elemRIndex :: Eq a => a -> [a] -> Maybe Int
- countElem :: Eq a => a -> [a] -> Int
- strToAL :: (Read a, Read b) => String -> [(a, b)]
- strFromAL :: (Show a, Show b) => [(a, b)] -> String
- flipAL :: (Eq key, Eq val) => [(key, val)] -> [(val, [key])]
- hasKeyAL :: Eq a => a -> [(a, b)] -> Bool
- valuesAL :: [(a, value)] -> [value]
- keysAL :: [(key, a)] -> [key]
- delFromAL :: Eq key => [(key, a)] -> key -> [(key, a)]
- addToAL :: Eq key => [(key, elt)] -> key -> elt -> [(key, elt)]
- contains :: Eq a => [a] -> [a] -> Bool
- genericJoin :: Show a => String -> [a] -> String
- replace :: Eq a => [a] -> [a] -> [a] -> [a]
- split :: Eq a => [a] -> [a] -> [[a]]
- breakList :: ([a] -> Bool) -> [a] -> ([a], [a])
- spanList :: ([a] -> Bool) -> [a] -> ([a], [a])
- dropWhileList :: ([a] -> Bool) -> [a] -> [a]
- takeWhileList :: ([a] -> Bool) -> [a] -> [a]
- hasAny :: Eq a => [a] -> [a] -> Bool
- endswith :: Eq a => [a] -> [a] -> Bool
- startswith :: Eq a => [a] -> [a] -> Bool
- mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
- merge :: Ord a => [a] -> [a] -> [a]
- newtype WholeFunc a b = WholeFunc ([a] -> (WholeFunc a b, [a], [b]))
- class PartialOrd a => Transfinite a where
- infinity :: a
- negativeInfinity :: a
- notANumber :: a
- class IsList l where
Documentation
module Language.Stochaskell.Prelude
Expressions
data Expression t #
Stochaskell expression representation (statically typed)
Instances
Array manipulation
class Indexable a i e | a -> i e where #
generalised array interface
see (
!
)
see bounds
deleteAt :: Indexable a i e => a -> i -> a #
a `
-- remove deleteAt
` ii
'th element of array
insertAt :: Indexable a i e => a -> (i, e) -> a #
a `
--
move insertAt
` (i,e)a!i
and following elements up one, and set a!i = e
replaceAt :: Indexable a i e => a -> (i, e) -> a #
a `
-- set replaceAt
` (i,e)a!i = e
deleteIndex :: a -> i -> a #
insertIndex :: a -> i -> e -> a #
replaceIndex :: a -> i -> e -> a #
Instances
Recursion
foldlE :: ExprType b => (Expression b -> Expression a -> Expression b) -> Expression b -> Expression [a] -> Expression b #
Stochaskell equivalent of foldl
foldrE :: ExprType b => (Expression a -> Expression b -> Expression b) -> Expression b -> Expression [a] -> Expression b #
Stochaskell equivalent of foldr
scanlE :: ExprType b => (Expression b -> Expression a -> Expression b) -> Expression b -> Expression [a] -> Expression [b] #
Stochaskell equivalent of scanl
scanrE :: ExprType b => (Expression a -> Expression b -> Expression b) -> Expression b -> Expression [a] -> Expression [b] #
Stochaskell equivalent of scanr
foldE :: forall t f. (Functor f, Constructor (f (FixE f)), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (Expression (f t) -> t) -> FixE' f -> t #
unfoldE :: forall t f. (Functor f, Constructor (f t), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (t -> Expression (f t)) -> t -> FixE' f #
Helpers
constSymbol :: forall t. ExprType t => String -> Expression t #
create a symbol
assumed to have a known value
factorial' :: Z -> Z #
logFactorial' :: Z -> R #
find' :: ExprType e => (Expression e -> B) -> Expression e -> Expression [e] -> Expression e #
find p d v
: find leftmost element of v
satisfying p
,
else d
if no elements satisfy p
findSortedInsertIndex :: R -> RVec -> Z #
given a value and a sorted vector, find the index at which we could
insertAt
the value whilst keeping the vector sorted
findSortedInsertIndexBound :: Interval Z -> R -> RVec -> Z #
like findSortedInsertIndex
but with the given bounds on the index
min' :: Expression a -> Expression a -> Expression a #
minimum of two values
sum' :: (ExprType a, Num a) => Expression [a] -> Expression a #
Stochaskell equivalent of sum
symbol :: forall t. ExprType t => String -> Expression t #
create a symbolic variable
Linear algebra
class InnerProduct v e | v -> e where #
Instances
InnerProduct ConstVal ConstVal # | |
InnerProduct (Expression [e]) (Expression e) # | |
Defined in Data.Expression (<.>) :: Expression [e] -> Expression [e] -> Expression e # |
class LinearOperator m v | m -> v, v -> m where #
generalised linear operator interface
(#>) :: m -> v -> v infixr 8 #
see #>
see <#
convert vector to diagonal matrix
convert vector to column
convert vector to row
outer :: (LinearOperator m v, Semigroup m) => v -> v -> m #
outer product
Instances
LinearOperator ConstVal ConstVal # | |
LinearOperator DExpr DExpr # | |
LinearOperator (Expression [[e]]) (Expression [e]) # | |
Defined in Data.Expression (#>) :: Expression [[e]] -> Expression [e] -> Expression [e] # (<#) :: Expression [e] -> Expression [[e]] -> Expression [e] # diag :: Expression [e] -> Expression [[e]] # asColumn :: Expression [e] -> Expression [[e]] # asRow :: Expression [e] -> Expression [[e]] # outer :: Expression [e] -> Expression [e] -> Expression [[e]] # |
class Matrix m i e | m -> i e where #
generalised matrix interface
matrix :: AbstractArray i e -> m #
convert from abstract array
blockMatrix :: [[m]] -> m #
create a block matrix
identity matrix
zero matrix
matrixRows :: m -> i #
number of rows
matrixCols :: m -> i #
number of columns
designMatrix :: (Indexable v i e, Num i) => i -> AbstractArray i v -> m #
pack vectors as rows of a matrix
Instances
Matrix ConstVal Integer ConstVal # | |
Defined in Data.Expression.Const matrix :: AbstractArray Integer ConstVal -> ConstVal # blockMatrix :: [[ConstVal]] -> ConstVal # zeros :: Integer -> Integer -> ConstVal # matrixRows :: ConstVal -> Integer # matrixCols :: ConstVal -> Integer # designMatrix :: (Indexable v Integer ConstVal, Num Integer) => Integer -> AbstractArray Integer v -> ConstVal # | |
Matrix DExpr DExpr DExpr # | |
Defined in Data.Expression | |
ExprType e => Matrix (Expression [[e]]) Z (Expression e) # | |
Defined in Data.Expression matrix :: AbstractArray Z (Expression e) -> Expression [[e]] # blockMatrix :: [[Expression [[e]]]] -> Expression [[e]] # eye :: Z -> Expression [[e]] # zeros :: Z -> Z -> Expression [[e]] # matrixRows :: Expression [[e]] -> Z # matrixCols :: Expression [[e]] -> Z # designMatrix :: (Indexable v Z (Expression e), Num Z) => Z -> AbstractArray Z v -> Expression [[e]] # |
class Scalable a v | v -> a where #
Instances
Scalable ConstVal ConstVal # | |
Scalable R RVec # | |
(IArray UArray e, Num e, Ix i) => Scalable e (UArray i e) # | |
Defined in Data.Array.Abstract | |
(Num e, Ix i) => Scalable e (Array i e) # | |
Defined in Data.Array.Abstract | |
ExprType e => Scalable (Expression e) (Expression [[e]]) # | |
Defined in Data.Expression (*>) :: Expression e -> Expression [[e]] -> Expression [[e]] # |
class SquareMatrix m e | m -> e where #
lower-triangular Cholesky decomposition, see chol
see inv
see det
logarithm of the absolute value of the determinant
Instances
SquareMatrix ConstVal ConstVal # | |
SquareMatrix DExpr DExpr # | |
SquareMatrix (Expression [[e]]) (Expression e) # | |
Defined in Data.Expression chol :: Expression [[e]] -> Expression [[e]] # inv :: Expression [[e]] -> Expression [[e]] # det :: Expression [[e]] -> Expression e # logDet :: Expression [[e]] -> Expression e # |
class Transposable m mt | m -> mt, mt -> m where #
Instances
Transposable ConstVal ConstVal # | |
Transposable DExpr DExpr # | |
(CTrans t, Container Vector t) => Transposable (Matrix t) (Matrix t) | |
ExprType e => Transposable (Expression [[e]]) (Expression [[e]]) # | |
Defined in Data.Expression tr :: Expression [[e]] -> Expression [[e]] # tr' :: Expression [[e]] -> Expression [[e]] # |
class Vector v i e | v -> i e, i e -> v where #
generalised vector interface
vector :: AbstractArray i e -> v #
convert from abstract array
blockVector :: [v] -> v #
see blockMatrix
vectorSize :: v -> i #
number of elements in vector
Instances
Vector ConstVal Integer ConstVal # | |
Defined in Data.Expression.Const vector :: AbstractArray Integer ConstVal -> ConstVal # blockVector :: [ConstVal] -> ConstVal # vectorSize :: ConstVal -> Integer # | |
Vector DExpr DExpr DExpr # | |
Defined in Data.Expression vector :: AbstractArray DExpr DExpr -> DExpr # blockVector :: [DExpr] -> DExpr # vectorSize :: DExpr -> DExpr # | |
ExprType e => Vector (Expression [e]) Z (Expression e) # | |
Defined in Data.Expression vector :: AbstractArray Z (Expression e) -> Expression [e] # blockVector :: [Expression [e]] -> Expression [e] # vectorSize :: Expression [e] -> Z # |
Types
= Expression Bool | boolean |
= Expression Double | real |
= Expression Integer | integer |
= Expression [Bool] | boolean vector |
= Expression [Double] | real vector |
= Expression [Integer] | integer vector |
= Expression [[Bool]] | boolean matrix |
= Expression [[Double]] | real matrix |
= Expression [[Integer]] | integer matrix |
Type casting
cast a value of one type to another
Instances
Cast Int R # | |
Defined in Data.Expression | |
Cast Z R # | |
Defined in Data.Expression | |
ExprType t => Cast t (Expression t) # | |
Defined in Data.Expression cast :: t -> Expression t # | |
Cast (Expression t) (Expression [[t]]) # | |
Defined in Data.Expression cast :: Expression t -> Expression [[t]] # | |
Cast (Expression t) (Expression [t]) # | |
Defined in Data.Expression cast :: Expression t -> Expression [t] # |
Abstract arrays
data AbstractArray i e #
create abstract arrays with an expression like
[ i + j | i <- 1...rows, j <- 1...cols ]
Instances
(...) :: a -> a -> AbstractArray a a infix 5 #
create abstract array containing given integer range
Probability distributions
Stochaskell probabilistic program intermediate representation
Instances
class Monad m => Distribution d s m t | d m t -> s #
generalised probability distribution interface
sample
Instances
class Joint m i r f | m -> i where #
joint :: (AbstractArray i r -> f) -> AbstractArray i (m r) -> m f #
create distribution over arrays as the product of an array of independent distributions, eg.
joint matrix [ normal i j | i <- 1...m, j <- 1...n ]
Instances
Joint IO Integer e f # | |
Defined in Data.Array.Abstract joint :: (AbstractArray Integer e -> f) -> AbstractArray Integer (IO e) -> IO f # | |
(ExprType r, ExprType f, Show f) => Joint P Z (Expression r) (Expression f) # | |
Defined in Data.Program joint :: (AbstractArray Z (Expression r) -> Expression f) -> AbstractArray Z (P (Expression r)) -> P (Expression f) # |
Primitives
Boolean
data Bernoullis p #
Instances
Distribution Bernoullis RVec P BVec # | |
Defined in Data.Program sample :: Bernoullis RVec -> P BVec |
bernoulli :: Distribution Bernoulli s m t => s -> m t #
bernoullis :: Distribution Bernoullis s m t => s -> m t #
bernoulliLogit :: Distribution Bernoulli s m t => s -> m t #
bernoulliLogits :: Distribution Bernoullis s m t => s -> m t #
Discrete
data NegBinomial a #
Instances
Distribution NegBinomial (Double, Double) IO Integer # | |
Defined in Data.Random.Distribution.Abstract | |
Distribution NegBinomial (R, R) P Z # | |
Defined in Data.Program |
negBinomial :: Distribution NegBinomial (a, b) m t => a -> b -> m t #
pmf :: Distribution PMF s m t => s -> m t #
distribution over indices given by vector of probabilities
poisson :: Distribution Poisson s m t => s -> m t #
Continuous
Instances
Random t => Distribution Uniform (t, t) IO t # | |
Defined in Data.Random.Distribution.Abstract | |
Distribution Uniform (Z, Z) P Z # | |
Distribution Uniform (R, R) P R # | |
beta :: Distribution Beta (a, b) m t => a -> b -> m t #
cauchy :: Distribution Cauchy (a, b) m t => a -> b -> m t #
gamma :: Distribution Gamma (a, b) m t => a -> b -> m t #
invGamma :: Distribution InvGamma (a, b) m t => a -> b -> m t #
logistic :: Distribution Logistic (a, b) m t => a -> b -> m t #
normal :: Distribution Normal (a, b) m t => a -> b -> m t #
normals :: Distribution Normals (a, b) m t => a -> b -> m t #
uniform :: Distribution Uniform (a, b) m t => a -> b -> m t #
uniforms :: Distribution Uniforms (a, b) m t => a -> b -> m t #
Vector
data OrderedSample a #
Instances
ExprType t => Distribution OrderedSample (Z, P (Expression t)) P (Expression [t]) # | |
Defined in Data.Program sample :: OrderedSample (Z, P (Expression t)) -> P (Expression [t]) |
data PoissonProcess a #
Instances
Distribution PoissonProcess (R, R -> R, R) P RVec # | |
Defined in Data.Program |
orderedSample :: Distribution OrderedSample (a, b) m t => a -> b -> m t #
orderedSample n d
gives an ordered vector of n
samples from a base
distribution d
poissonProcess :: Distribution PoissonProcess (a, b, c) m t => a -> b -> c -> m t #
Matrix
corrLKJ :: Distribution LKJ (a, b) m t => a -> b -> m t #
Logarithmic probability density functions
lpdf :: (ExprTuple t, Show t) => P t -> t -> R #
compute log pdf of distribution represented by probabilistic program
lpdfAux :: (ExprTuple t, Show t) => P t -> t -> R #
compute joint pdf of primitive random variables within the given program
lpdfAuxC :: (Constructor t, Show t) => P (Expression t) -> Expression t -> R #
Primitives
lpdfNormal :: Floating a => a -> a -> a -> a #
lpdfPoisson :: Integer -> Double -> Double #
lpdfUniform :: (Ord p, Floating p) => p -> p -> p -> p #
lpdfDiscreteUniform :: (Floating p, Integral a) => a -> a -> a -> p #
Transformers
mixture :: forall t. ExprTuple t => [(R, P t)] -> P t #
creates a mixture distribution, eg.
mixture [(0.7, uniform 0 1), (0.3, normal 0 1)]
mixture' :: ExprTuple t => [(R, P t)] -> P t #
like mixture
, but produces a flattened intermediate representation
that uses a case expression rather than a switch statement
truncated :: Expression t -> Expression t -> P (Expression t) -> P (Expression t) #
truncate distribution to given bounds
foldP :: forall t f. (Traversable f, Constructor (f (FixE f)), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (Expression (f t) -> P t) -> FixE' f -> P t #
unfoldP :: forall t f. (Traversable f, Constructor (f t), ExprTuple t, ExprType (f (FixE f)), ExprType (f t)) => (t -> P (Expression (f t))) -> t -> P (FixE' f) #
Iteration
chain' :: ExprTuple t => Z -> (t -> P t) -> t -> P t #
convenience function for calling chainRange'
starting at 1 and ignoring indices
chainRange' :: forall t. ExprTuple t => Interval Z -> (Z -> t -> P t) -> t -> P t #
iterate a Markov chain over the given integer range, eg.
chainRange' (1,10) (\i x -> normal x 1) 0 -- 10-step standard normal random walk from 0
Pre-defined probabilistic programs
lognormal :: (Distribution Normal (a, b1) m b2, Floating b2) => a -> b1 -> m b2 #
log-normal distribution
normalChol :: Z -> RVec -> RMat -> P RVec #
multivariate normal via Cholesky decomposition of covariance matrix
normalsChol :: Z -> Z -> RVec -> RMat -> P RMat #
iid normalChol
samples as rows
normalCond :: Z -> (Expression t -> Expression t -> R) -> R -> Expression [t] -> RVec -> Expression t -> P R #
Gaussian process conditioned on observations
Sampling
compileCC :: forall s t. (ExprTuple s, ExprTuple t) => (s -> P t) -> IO (s -> IO t) #
compile probabilistic program to native machine code, via the C++ backend
runCC :: forall s t. (ExprTuple s, ExprTuple t) => (s -> P t) -> s -> IO t #
sample probabilistic program via compileCC
runStep :: forall t. ExprTuple t => (t -> P t) -> t -> IO t #
sample probabilistic program via Stochaskell's interpreter
Inference
hmcStan :: ExprTuple t => Int -> P t -> IO [t] #
perform Hamiltonian Monte Carlo inference on the given posterior program, via the Stan code generation backend, returning the given number of samples
see runStan
for a more advanced interface
hmcStanInit :: ExprTuple t => Int -> P t -> t -> IO [t] #
like hmcStan
but specifying the initial MC state
rjmc :: (ExprTuple t, IfB t, BooleanOf t ~ B, Show t) => P t -> (t -> P t) -> t -> P t #
Reversible Jump Monte Carlo inference
rjmcC :: (Constructor t, Show t) => P (Expression t) -> (t -> P (Expression t)) -> Expression t -> P (Expression t) #
like rjmc
but for ADTs that implement the Constructor
typeclass
rjmc1 :: (ExprType t, ExprTuple t, IfB t, BooleanOf t ~ B, Show t) => P t -> (t -> P t) -> t -> P t #
like rjmc
but assumes the Jacobian factor is equal to one
Miscellaneous
binarize :: (forall a. (Num a, EqB a, OrdB a) => a -> BooleanOf a) -> ConstVal -> ConstVal #
map boolean function over elements of array
chainRange :: (Num i, Monad m) => (Int, Int) -> (i -> x -> m x) -> x -> m x #
like chainRange'
but for arbitrary monads
debug :: ExprTuple t => String -> t -> t #
Stochaskell equivalent of trace
that runs within generated code
deepseq :: NFData a => a -> b -> b #
deepseq
: fully evaluates the first argument, before returning the
second.
The name deepseq
is used to illustrate the relationship to seq
:
where seq
is shallow in the sense that it only evaluates the top
level of its argument, deepseq
traverses the entire data structure
evaluating it completely.
deepseq
can be useful for forcing pending exceptions,
eradicating space leaks, or forcing lazy I/O to happen. It is
also useful in conjunction with parallel Strategies (see the
parallel
package).
There is no guarantee about the ordering of evaluation. The
implementation may evaluate the components of the structure in
any order or in parallel. To impose an actual order on
evaluation, use pseq
from Control.Parallel in the
parallel
package.
Since: deepseq-1.1.0.0
fromCase :: forall c t. (Constructor c, ExprTuple t) => (c -> t) -> Expr c -> t #
fromCaseP :: forall c t. (Constructor c, ExprTuple t) => (c -> P t) -> Expression c -> P t #
fromCaseP' :: forall c t. (Constructor c, ExprTuple t) => (c -> P t) -> Expression c -> P t #
fromRight' :: Either String b -> b #
extract result from an Either
value when possible, throw an exception
with the error string otherwise
interpolate :: (Ord a, Fractional a) => [(a, a)] -> a -> a #
piecewise linear interpolation
iterateLimit :: Monad m => Int -> (a -> m a) -> a -> m [a] #
parameter order equal to that of nest
linspace :: (IsList l, e ~ Item l, Fractional e, Integral i) => (e, e) -> i -> l #
evenly spaced points over interval
logFromLogFloat :: LogFloat -> Double #
Return the log-domain value itself without conversion.
mean :: (Foldable t, Fractional a) => t a -> a #
calculate the mean of a set
readRealMatrix :: FilePath -> IO ConstVal #
read CSV file into a matrix
selectItems :: [a] -> [Bool] -> [a] #
extract elements of first list where second list contains True
setRandomSeed :: Int -> IO () #
sets the global random seed
Warning: does not yet cover all sources of randomness
slice :: ConstVal -> AbstractArray Integer [Integer] -> ConstVal #
extract the given indices from an array, eg.
diagonal = table `slice` [[i,i] | i <- 1...n]
stochaskell :: IO () #
perform initialisation for interactive use
tic :: IO NominalDiffTime #
start a stopwatch
toc :: NominalDiffTime -> IO NominalDiffTime #
read a stopwatch
Re-exports
module Data.Either.Utils
Data.List.Utils
Given a list, returns a new list with all duplicate elements removed. For example:
uniq "Mississippi" -> "Misp"
You should not rely on this function necessarily preserving order, though the current implementation happens to.
This function is not compatible with infinite lists.
This is presently an alias for Data.List.nub
subIndex :: Eq a => [a] -> [a] -> Maybe Int #
Similar to Data.List.elemIndex. Instead of looking for one element in a list, this function looks for the first occurance of a sublist in the list, and returns the index of the first element of that occurance. If there is no such list, returns Nothing.
If the list to look for is the empty list, will return Just 0 regardless of the content of the list to search.
Examples:
subIndex "foo" "asdfoobar" -> Just 3 subIndex "foo" [] -> Nothing subIndex "" [] -> Just 0 subIndex "" "asdf" -> Just 0 subIndex "test" "asdftestbartest" -> Just 4 subIndex [(1::Int), 2] [0, 5, 3, 2, 1, 2, 4] -> Just 4
grab :: Int -> State [a] [a] #
Helps you pick out fixed-width components from a list.
Example:
conv :: String -> (String,String) conv = runState $ do f3 <- grab 3 n2 <- grab 2 return $ f3 ++ "," ++ n2 main = print $ conv "TestIng"
Prints:
("Tes,tI","ng")
fixedWidth :: [Int] -> WholeFunc a [a] #
A parser designed to process fixed-width input fields. Use it with
wholeMap
.
The Int list passed to this function is the list of the field widths desired from the input. The result is a list of those widths, if possible. If any of the input remains after processing this list, it is added on as the final element in the result list. If the input is less than the sum of the requested widths, then the result list will be short the appropriate number of elements, and its final element may be shorter than requested.
Examples:
wholeMap (fixedWidth [1, 2, 3]) "1234567890" --> ["1","23","456","7890"] wholeMap (fixedWidth (repeat 2)) "123456789" --> ["12","34","56","78","9"] wholeMap (fixedWidth []) "123456789" --> ["123456789"] wholeMap (fixedWidth [5, 3, 6, 1]) "Hello, This is a test." --> ["Hello",", T","his is"," ","a test."]
wholeMap :: WholeFunc a b -> [a] -> [b] #
This is an enhanced version of the concatMap or map functions in Data.List.
Unlike those functions, this one:
- Can consume a varying number of elements from the input list during each iteration
- Can arbitrarily decide when to stop processing data
- Can return a varying number of elements to insert into the output list
- Can actually switch processing functions mid-stream
- Is not even restricted to processing the input list intact
The function used by wholeMap, of type WholeFunc
, is repeatedly called
with the input list. The function returns three things: the function
to call for the next iteration (if any), what remains of the input list,
and the list of output elements generated during this iteration. The return
value of wholeMap
is the concatenation of the output element lists from
all iterations.
Processing stops when the remaining input list is empty. An example
of a WholeFunc
is fixedWidth
.
alwaysElemRIndex :: Eq a => a -> [a] -> Int #
Like elemRIndex, but returns -1 if there is nothing found.
elemRIndex :: Eq a => a -> [a] -> Maybe Int #
Returns the rightmost index of the given element in the given list.
countElem :: Eq a => a -> [a] -> Int #
Returns a count of the number of times the given element occured in the given list.
strFromAL :: (Show a, Show b) => [(a, b)] -> String #
Converts an association list to a string. The string will have one pair per line, with the key and value both represented as a Haskell string.
This function is designed to work with [(String, String)] association lists, but may work with other types as well.
flipAL :: (Eq key, Eq val) => [(key, val)] -> [(val, [key])] #
Flips an association list. Converts (key1, val), (key2, val) pairs to (val, [key1, key2]).
valuesAL :: [(a, value)] -> [value] #
Returns the values the comprise the (key, value) pairs of the given AL.
Same as:
map snd
keysAL :: [(key, a)] -> [key] #
Returns the keys that comprise the (key, value) pairs of the given AL.
Same as:
map fst
delFromAL :: Eq key => [(key, a)] -> key -> [(key, a)] #
Removes all (key, value) pairs from the given list where the key matches the given one.
addToAL :: Eq key => [(key, elt)] -> key -> elt -> [(key, elt)] #
Adds the specified (key, value) pair to the given list, removing any existing pair with the same key already present.
contains :: Eq a => [a] -> [a] -> Bool #
Returns true if the given parameter is a sublist of the given list; false otherwise.
Example:
contains "Haskell" "I really like Haskell." -> True contains "Haskell" "OCaml is great." -> False
This function was submitted to GHC and was applied as
isInfixOf
. This function therefore is deprecated and will
be removed in future versions.
genericJoin :: Show a => String -> [a] -> String #
Like join
, but works with a list of anything showable, converting
it to a String.
Examples:
genericJoin ", " [1, 2, 3, 4] -> "1, 2, 3, 4" genericJoin "|" ["foo", "bar", "baz"] -> "\"foo\"|\"bar\"|\"baz\""
replace :: Eq a => [a] -> [a] -> [a] -> [a] #
Given a list and a replacement list, replaces each occurance of the search list with the replacement list in the operation list.
Example:
replace "," "." "127,0,0,1" -> "127.0.0.1"
This could logically be thought of as:
replace old new l = join new . split old $ l
split :: Eq a => [a] -> [a] -> [[a]] #
Given a delimiter and a list (or string), split into components.
Example:
split "," "foo,bar,,baz," -> ["foo", "bar", "", "baz", ""]
split "ba" ",foo,bar,,baz," -> [",foo,","r,,","z,"]
breakList :: ([a] -> Bool) -> [a] -> ([a], [a]) #
Similar to Data.List.break, but performs the test on the entire remaining list instead of just one element.
spanList :: ([a] -> Bool) -> [a] -> ([a], [a]) #
Similar to Data.List.span, but performs the test on the entire remaining list instead of just one element.
spanList p xs
is the same as (takeWhileList p xs, dropWhileList p xs)
dropWhileList :: ([a] -> Bool) -> [a] -> [a] #
Similar to Data.List.dropWhile, drops elements while the func is true. The function is given the remainder of the list to examine.
takeWhileList :: ([a] -> Bool) -> [a] -> [a] #
Similar to Data.List.takeWhile, takes elements while the func is true. The function is given the remainder of the list to examine.
Returns true if the given list contains any of the elements in the search list.
endswith :: Eq a => [a] -> [a] -> Bool #
Returns true if the given list ends with the specified elements; false otherwise. (This is an alias for "Data.List.isSuffixOf".)
Example:
endswith "lo" "Hello" -> True
startswith :: Eq a => [a] -> [a] -> Bool #
Returns true if the given list starts with the specified elements; false otherwise. (This is an alias for "Data.List.isPrefixOf".)
Example:
startswith "He" "Hello" -> True
mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a] #
Merge two sorted lists using into a single, sorted whole, allowing the programmer to specify the comparison function.
QuickCheck test property:
prop_mergeBy xs ys = mergeBy cmp (sortBy cmp xs) (sortBy cmp ys) == sortBy cmp (xs ++ ys) where types = xs :: [ (Int, Int) ] cmp (x1,_) (x2,_) = compare x1 x2
merge :: Ord a => [a] -> [a] -> [a] #
Merge two sorted lists into a single, sorted whole.
Example:
merge [1,3,5] [1,2,4,6] -> [1,1,2,3,4,5,6]
QuickCheck test property:
prop_merge xs ys = merge (sort xs) (sort ys) == sort (xs ++ ys) where types = xs :: [Int]
Data.Number.Transfinite
class PartialOrd a => Transfinite a where #
Many numbers are not Bounded
yet, even though they can
represent arbitrarily large values, they are not necessarily
able to represent transfinite values such as infinity itself.
This class is for types which are capable of representing such
values. Notably, this class does not require the type to be
Fractional
nor Floating
since integral types could also have
representations for transfinite values. By popular demand the
Num
restriction has been lifted as well, due to complications
of defining Show
or Eq
for some types.
In particular, this class extends the ordered projection to have
a maximum value infinity
and a minimum value negativeInfinity
,
as well as an exceptional value notANumber
. All the natural
laws regarding infinity
and negativeInfinity
should pertain.
(Some of these are discussed below.)
Hugs (September 2006) has buggy Prelude definitions for
isNaN
and isInfinite
on Float and Double.
This module provides correct definitions, so long as Hugs.RealFloat
is compiled correctly.
A transfinite value which is greater than all finite values.
Adding or subtracting any finite value is a no-op. As is
multiplying by any non-zero positive value (including
infinity
), and dividing by any positive finite value. Also
obeys the law negate infinity = negativeInfinity
with all
appropriate ramifications.
negativeInfinity :: a #
A transfinite value which is less than all finite values.
Obeys all the same laws as infinity
with the appropriate
changes for the sign difference.
notANumber :: a #
An exceptional transfinite value for dealing with undefined
results when manipulating infinite values. The following
operations must return notANumber
, where inf
is any value
which isInfinite
:
infinity + negativeInfinity
negativeInfinity + infinity
infinity - infinity
negativeInfinity - negativeInfinity
inf * 0
0 * inf
inf / inf
inf `div` inf
0 / 0
0 `div` 0
Additionally, any mathematical operations on notANumber
must also return notANumber
, and any equality or ordering
comparison on notANumber
must return False
(violating
the law of the excluded middle, often assumed but not required
for Eq
; thus, eq
and ne
are preferred over (==
) and
(/=
)). Since it returns false for equality, there may be
more than one machine representation of this value
.
Instances
Transfinite Double | |
Defined in Data.Number.Transfinite | |
Transfinite Float | |
Defined in Data.Number.Transfinite | |
Transfinite ConstVal # | |
Defined in Data.Expression.Const | |
(Ord t, ExprType t) => Transfinite (Expression t) # | |
Defined in Data.Expression infinity :: Expression t # negativeInfinity :: Expression t # notANumber :: Expression t # isInfinite :: Expression t -> Bool # isNaN :: Expression t -> Bool # |
GHC.Exts
The IsList
class and its methods are intended to be used in
conjunction with the OverloadedLists extension.
Since: base-4.7.0.0
The fromList
function constructs the structure l
from the given
list of Item l
fromListN :: Int -> [Item l] -> l #
The fromListN
function takes the input list's length as a hint. Its
behaviour should be equivalent to fromList
. The hint can be used to
construct the structure l
more efficiently compared to fromList
. If
the given hint does not equal to the input list's length the behaviour of
fromListN
is not specified.
The toList
function extracts a list of Item l
from the structure l
.
It should satisfy fromList . toList = id.
Instances
IsList CallStack | Be aware that 'fromList . toList = id' only for unfrozen Since: base-4.9.0.0 |
IsList Version | Since: base-4.8.0.0 |
IsList String | |
IsList IntSet | Since: containers-0.5.6.2 |
IsList ByteArray | Since: primitive-0.6.3.0 |
IsList ShortText | Note: Surrogate pairs ( Since: text-short-0.1.2 |
IsList ConstVal # | |
IsList RMat # | |
IsList ZVec # | |
IsList RVec # | |
IsList BVec # | |
IsList [a] | Since: base-4.7.0.0 |
Storable a => IsList (Vector a) | |
IsList (NonEmpty a) | Since: base-4.9.0.0 |
PrimType ty => IsList (UArray ty) | |
PrimType ty => IsList (Block ty) | |
IsList c => IsList (NonEmpty c) | |
IsList (IntMap a) | Since: containers-0.5.6.2 |
IsList (Seq a) | |
Ord a => IsList (Set a) | Since: containers-0.5.6.2 |
IsList (DList a) | |
PrimUnlifted a => IsList (UnliftedArray a) | Since: primitive-0.6.4.0 |
Defined in Data.Primitive.UnliftedArray type Item (UnliftedArray a) :: Type # fromList :: [Item (UnliftedArray a)] -> UnliftedArray a # fromListN :: Int -> [Item (UnliftedArray a)] -> UnliftedArray a # toList :: UnliftedArray a -> [Item (UnliftedArray a)] # | |
Prim a => IsList (PrimArray a) | Since: primitive-0.6.4.0 |
IsList (SmallArray a) | |
Defined in Data.Primitive.SmallArray type Item (SmallArray a) :: Type # fromList :: [Item (SmallArray a)] -> SmallArray a # fromListN :: Int -> [Item (SmallArray a)] -> SmallArray a # toList :: SmallArray a -> [Item (SmallArray a)] # | |
IsList (Array a) | |
(Eq a, Hashable a) => IsList (HashSet a) | |
Prim a => IsList (Vector a) | |
IsList (Vector a) | |
(Eq k, Hashable k) => IsList (HashMap k v) | |
Ord k => IsList (Map k v) | Since: containers-0.5.6.2 |