mwc-probability-transition-0.3.0.2: A Markov stochastic transition operator with logging

Safe HaskellNone
LanguageHaskell2010

System.Random.MWC.Probability.Transition

Contents

Synopsis

Transition

data Transition message s m a Source #

A Markov transition kernel.

Instances

Functor m => Functor (Transition message s m) Source # 

Methods

fmap :: (a -> b) -> Transition message s m a -> Transition message s m b #

(<$) :: a -> Transition message s m b -> Transition message s m a #

Show (Transition msg s m a) Source # 

Methods

showsPrec :: Int -> Transition msg s m a -> ShowS #

show :: Transition msg s m a -> String #

showList :: [Transition msg s m a] -> ShowS #

mkTransition Source #

Arguments

:: Monad m 
=> (s -> Prob m t)

Random generation

-> (s -> t -> (a, s))

(Output, Next state)

-> (a -> s -> message)

Log message construction

-> Transition message s m a 

Construct a Transition from sampling, state transformation and logging functions.

NB: The three function arguments are used in the order in which they appear here:

  1. a random sample w :: t is produced, using the current state x :: s as input
  2. output z :: a and next state x' :: s are computed using w and x
  3. a logging message is constructed, using z and x' as arguments.

runTransition Source #

Arguments

:: Monad m 
=> Handler m message

Logging handler

-> Transition message s m a 
-> Int

Number of iterations

-> s

Initial state

-> Gen (PrimState m)

PRNG

-> m ([a], s)

(Outputs, Final state)

Run a Transition for a number of steps, while logging each iteration.

Returns both the list of outputs and the final state.

Specialized combinators

evalTransition Source #

Arguments

:: Monad m 
=> Handler m message 
-> Transition message s m a 
-> Int 
-> s 
-> Gen (PrimState m) 
-> m [a]

Outputs

Run a Transition for a number of steps, while logging each iteration.

Returns the list of outputs.

execTransition Source #

Arguments

:: Monad m 
=> Handler m message 
-> Transition message s m a 
-> Int 
-> s 
-> Gen (PrimState m) 
-> m s

Final state

Run a Transition for a number of steps, while logging each iteration.

Returns the final state.

Conditional execution

stepConditional Source #

Arguments

:: Monad m 
=> (a -> s -> s -> Bool)

Inputs: Model output, Current state, New state

-> (a -> s -> s -> l)

"

-> (a -> s -> s -> r)

"

-> Handler m message 
-> Transition message s m a 
-> s

Current state

-> Gen (PrimState m) 
-> m (Either l r) 

Perform one Transition and check output and updated state against the current state, producing an Either with the result of the comparison.

Can be useful for detecting early divergence or lack of convergence etc.

Helper functions

withSeverity :: (t -> String) -> WithSeverity t -> String Source #

Render a logging message along with an annotation of its severity.