Copyright | (C) 2019 Stevan Andjelkovic |
---|---|

License | BSD-style (see the file LICENSE) |

Maintainer | Stevan Andjelkovic <stevan.andjelkovic@strath.ac.uk> |

Stability | provisional |

Portability | non-portable (GHC extensions) |

Safe Haskell | None |

Language | Haskell2010 |

This module contains helper functions for testing using Markov chains.

## Synopsis

- data Markov state cmd_ prob
- makeMarkov :: Ord state => [Map state [Transition state cmd_ prob]] -> Markov state cmd_ prob
- toAdjacencyMap :: Ord state => Markov state cmd_ prob -> Map state (Map state (cmd_, prob))
- (-<) :: Fractional prob => state -> [Either (cmd_, state) ((cmd_, prob), state)] -> Map state [Transition state cmd_ prob]
- (>-) :: (cmd_, prob) -> state -> Either (cmd_, state) ((cmd_, prob), state)
- (/-) :: cmd_ -> state -> Either (cmd_, state) ((cmd_, prob), state)
- markovGenerator :: forall state cmd_ cmd model. (Show state, Show cmd_) => (Ord state, Ord cmd_) => Markov state cmd_ Double -> Map cmd_ (model Symbolic -> Gen (cmd Symbolic)) -> (model Symbolic -> state) -> (state -> Bool) -> model Symbolic -> Maybe (Gen (cmd Symbolic))
- coverMarkov :: (Show state, Show cmd_, Testable prop) => Markov state cmd_ Double -> prop -> Property
- tabulateMarkov :: forall model state cmd cmd_ m resp prop. Testable prop => (Show state, Show cmd_) => StateMachine model cmd m resp -> (model Symbolic -> state) -> (cmd Symbolic -> cmd_) -> Commands cmd resp -> prop -> Property
- transitionMatrix :: forall state cmd_. Ord state => (Generic state, GEnum FiniteEnum (Rep state), GBounded (Rep state)) => Markov state cmd_ Double -> Matrix Double
- stimulusMatrix :: forall state cmd. (Ord state, Ord cmd) => (Generic state, GEnum FiniteEnum (Rep state), GBounded (Rep state)) => (Generic cmd, GEnum FiniteEnum (Rep cmd), GBounded (Rep cmd)) => Markov state cmd Double -> Matrix Double
- historyObservations :: forall model cmd m resp state cmd_ prob. Ord state => Ord cmd_ => (Generic state, GEnum FiniteEnum (Rep state), GBounded (Rep state)) => StateMachine model cmd m resp -> Markov state cmd_ prob -> (model Concrete -> state) -> (cmd Concrete -> cmd_) -> History cmd resp -> (Matrix Double, Matrix Double)
- markovToDot :: (Show state, Show cmd_, Show prob) => state -> state -> Markov state cmd_ prob -> String
- markovToPs :: (Show state, Show cmd_, Show prob) => state -> state -> Markov state cmd_ prob -> FilePath -> IO ()
- data StatsDb m = StatsDb {}
- type PropertyName = String
- nullStatsDb :: Monad m => StatsDb m
- fileStatsDb :: FilePath -> PropertyName -> StatsDb IO
- persistStats :: Monad m => StatsDb m -> (Matrix Double, Matrix Double) -> PropertyM m ()
- computeReliability :: Monad m => StatsDb m -> Matrix Double -> (Matrix Double, Matrix Double) -> m (Double, Double)
- printReliability :: Testable prop => StatsDb IO -> Matrix Double -> (Matrix Double, Matrix Double) -> prop -> Property
- quickCheckReliability :: Testable prop => StatsDb IO -> Matrix Double -> prop -> IO ()
- testChainToDot :: forall state cmd_ prob m. (Show state, Ord state, Monad m) => (Generic state, GEnum FiniteEnum (Rep state)) => StatsDb m -> state -> state -> Markov state cmd_ prob -> m String

# Documentation

makeMarkov :: Ord state => [Map state [Transition state cmd_ prob]] -> Markov state cmd_ prob Source #

Constructor for `Markov`

chains.

toAdjacencyMap :: Ord state => Markov state cmd_ prob -> Map state (Map state (cmd_, prob)) Source #

Expose inner graph structure of markov chain

(-<) :: Fractional prob => state -> [Either (cmd_, state) ((cmd_, prob), state)] -> Map state [Transition state cmd_ prob] infixl 5 Source #

Infix operator for starting to creating a transition in the `Markov`

chain,
finish the transition with one of '(>-)' or '(/-)' depending on whether the
transition has a specific or a uniform probability.

(>-) :: (cmd_, prob) -> state -> Either (cmd_, state) ((cmd_, prob), state) infixl 5 Source #

Finish making a transition with a specified probability distribution.

(/-) :: cmd_ -> state -> Either (cmd_, state) ((cmd_, prob), state) infixl 5 Source #

Finish making a transition with an uniform probability distribution.

markovGenerator :: forall state cmd_ cmd model. (Show state, Show cmd_) => (Ord state, Ord cmd_) => Markov state cmd_ Double -> Map cmd_ (model Symbolic -> Gen (cmd Symbolic)) -> (model Symbolic -> state) -> (state -> Bool) -> model Symbolic -> Maybe (Gen (cmd Symbolic)) Source #

Create a generator from a `Markov`

chain.

coverMarkov :: (Show state, Show cmd_, Testable prop) => Markov state cmd_ Double -> prop -> Property Source #

Variant of QuickCheck's `coverTable`

which works on `Markov`

chains.

tabulateMarkov :: forall model state cmd cmd_ m resp prop. Testable prop => (Show state, Show cmd_) => StateMachine model cmd m resp -> (model Symbolic -> state) -> (cmd Symbolic -> cmd_) -> Commands cmd resp -> prop -> Property Source #

transitionMatrix :: forall state cmd_. Ord state => (Generic state, GEnum FiniteEnum (Rep state), GBounded (Rep state)) => Markov state cmd_ Double -> Matrix Double Source #

stimulusMatrix :: forall state cmd. (Ord state, Ord cmd) => (Generic state, GEnum FiniteEnum (Rep state), GBounded (Rep state)) => (Generic cmd, GEnum FiniteEnum (Rep cmd), GBounded (Rep cmd)) => Markov state cmd Double -> Matrix Double Source #

historyObservations :: forall model cmd m resp state cmd_ prob. Ord state => Ord cmd_ => (Generic state, GEnum FiniteEnum (Rep state), GBounded (Rep state)) => StateMachine model cmd m resp -> Markov state cmd_ prob -> (model Concrete -> state) -> (cmd Concrete -> cmd_) -> History cmd resp -> (Matrix Double, Matrix Double) Source #

markovToDot :: (Show state, Show cmd_, Show prob) => state -> state -> Markov state cmd_ prob -> String Source #

markovToPs :: (Show state, Show cmd_, Show prob) => state -> state -> Markov state cmd_ prob -> FilePath -> IO () Source #

type PropertyName = String Source #

nullStatsDb :: Monad m => StatsDb m Source #

fileStatsDb :: FilePath -> PropertyName -> StatsDb IO Source #

computeReliability :: Monad m => StatsDb m -> Matrix Double -> (Matrix Double, Matrix Double) -> m (Double, Double) Source #