markov-realization-0.1.0: Realizations of Markov chains.

Maintainer atloomis@math.arizona.edu experimental None Haskell2010

Markov

Description

Three type classes for deterministically analyzing Markov chains with known parameters. Markov0 is intended to list possible outcomes, Markov should allow for more sophisticated analysis, and MultiMarkov is intended to make implementing hidden Markov models easier. See Examples for examples. See README for a detailed description.

Synopsis

# Markov0

class Eq m => Markov0 m where Source #

A basic implementation of Markov chains.

Minimal complete definition

transition0

Methods

transition0 :: m -> [m -> m] Source #

The transition functions from a state.

step0 :: m -> [m] Source #

chain0 :: [m] -> [[m]] Source #

Iterated steps.

Instances
 Source # Instance detailsDefined in Markov.Examples Methodstransition0 :: Simple -> [Simple -> Simple] Source #step0 :: Simple -> [Simple] Source #chain0 :: [Simple] -> [[Simple]] Source #

# Markov

class (Combine t, Grouping t, Grouping m, Monoid t) => Markov t m where Source #

An implementation of Markov chains. To speed up chain, try instead:

chain = DL.iterate' $map summarize' . NE.group . DL.sort . concatMap step where summarize' xs@((_,b)NE.:|_) = (summarize . fmap fst$ xs, b)

Minimal complete definition

transition

Methods

transition :: m -> [(t, m -> m)] Source #

step :: (t, m) -> [(t, m)] Source #

chain :: [(t, m)] -> [[(t, m)]] Source #

Instances
 Source # Instance detailsDefined in Markov.Examples Methodsstep :: (Product Double, FillBin) -> [(Product Double, FillBin)] Source #chain :: [(Product Double, FillBin)] -> [[(Product Double, FillBin)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Tidal -> [(Product Double, Tidal -> Tidal)] Source #step :: (Product Double, Tidal) -> [(Product Double, Tidal)] Source #chain :: [(Product Double, Tidal)] -> [[(Product Double, Tidal)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Urn -> [(Product Double, Urn -> Urn)] Source #step :: (Product Double, Urn) -> [(Product Double, Urn)] Source #chain :: [(Product Double, Urn)] -> [[(Product Double, Urn)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Simple -> [(Product Double, Simple -> Simple)] Source #step :: (Product Double, Simple) -> [(Product Double, Simple)] Source #chain :: [(Product Double, Simple)] -> [[(Product Double, Simple)]] Source # Source # Instance detailsDefined in Markov.Examples Methodsstep :: (Product Double, FromMatrix) -> [(Product Double, FromMatrix)] Source #chain :: [(Product Double, FromMatrix)] -> [[(Product Double, FromMatrix)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Simple -> [(Product Int, Simple -> Simple)] Source #step :: (Product Int, Simple) -> [(Product Int, Simple)] Source #chain :: [(Product Int, Simple)] -> [[(Product Int, Simple)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Simple -> [(Sum Int, Simple -> Simple)] Source #step :: (Sum Int, Simple) -> [(Sum Int, Simple)] Source #chain :: [(Sum Int, Simple)] -> [[(Sum Int, Simple)]] Source # Source # Instance detailsDefined in Markov.Examples Methodsstep :: ((Sum Int, Product Rational), Extinction) -> [((Sum Int, Product Rational), Extinction)] Source #chain :: [((Sum Int, Product Rational), Extinction)] -> [[((Sum Int, Product Rational), Extinction)]] Source #

# MultiMarkov

randomProduct :: (Real a, MonadRandom m) => [(a, b)] -> m (a, b) Source #

Randomly choose from a list by probability.

randomPath :: (Markov a b, Real a, RandomGen g) => (a, b) -> g -> [(a, b)] Source #

Returns a single realization of a Markov chain.

class (Combine m, Grouping m, Semigroup m) => MultiMarkov m where Source #

An implementation of Markov chains that allows multi-transition steps.

Minimal complete definition

multiTransition

Methods

multiTransition :: m -> [m -> [m]] Source #

multiStep :: m -> [m] Source #

multiChain :: [m] -> [[m]] Source #

Instances
 Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methods

# Combine

class Combine a where Source #

Within equivalence classes, combine should be associative, commutative, and should be idempotent up to equivalence. I.e. if x == y == z,

(x combine y) combine z = x combine (y combine z)
x combine y = y combine x
x combine x == x

Minimal complete definition

combine

Methods

combine :: a -> a -> a Source #

summarize :: NonEmpty a -> a Source #

Instances
 Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methods Num a => Combine (Product a) Source # Instance detailsDefined in Markov Methodscombine :: Product a -> Product a -> Product a Source # Combine (Sum a) Source # Instance detailsDefined in Markov Methodscombine :: Sum a -> Sum a -> Sum a Source #summarize :: NonEmpty (Sum a) -> Sum a Source # Combine (Merge a) Source # Instance detailsDefined in Markov Methodscombine :: Merge a -> Merge a -> Merge a Source #summarize :: NonEmpty (Merge a) -> Merge a Source # (Combine a, Combine b) => Combine (a, b) Source # Instance detailsDefined in Markov Methodscombine :: (a, b) -> (a, b) -> (a, b) Source #summarize :: NonEmpty (a, b) -> (a, b) Source # (Combine a, Combine b, Combine c) => Combine (a, b, c) Source # Instance detailsDefined in Markov Methodscombine :: (a, b, c) -> (a, b, c) -> (a, b, c) Source #summarize :: NonEmpty (a, b, c) -> (a, b, c) Source #

newtype Merge a Source #

Values from a Monoid which have the respective binary operation applied each step. E.g., strings with concatenation.

Constructors

 Merge a
Instances
 Enum a => Enum (Merge a) Source # Instance detailsDefined in Markov Methodssucc :: Merge a -> Merge a #pred :: Merge a -> Merge a #toEnum :: Int -> Merge a #fromEnum :: Merge a -> Int #enumFrom :: Merge a -> [Merge a] #enumFromThen :: Merge a -> Merge a -> [Merge a] #enumFromTo :: Merge a -> Merge a -> [Merge a] #enumFromThenTo :: Merge a -> Merge a -> Merge a -> [Merge a] # Eq a => Eq (Merge a) Source # Instance detailsDefined in Markov Methods(==) :: Merge a -> Merge a -> Bool #(/=) :: Merge a -> Merge a -> Bool # Fractional a => Fractional (Merge a) Source # Instance detailsDefined in Markov Methods(/) :: Merge a -> Merge a -> Merge a #recip :: Merge a -> Merge a # Num a => Num (Merge a) Source # Instance detailsDefined in Markov Methods(+) :: Merge a -> Merge a -> Merge a #(-) :: Merge a -> Merge a -> Merge a #(*) :: Merge a -> Merge a -> Merge a #negate :: Merge a -> Merge a #abs :: Merge a -> Merge a #signum :: Merge a -> Merge a # Show a => Show (Merge a) Source # Instance detailsDefined in Markov MethodsshowsPrec :: Int -> Merge a -> ShowS #show :: Merge a -> String #showList :: [Merge a] -> ShowS # Generic (Merge a) Source # Instance detailsDefined in Markov Associated Typestype Rep (Merge a) :: Type -> Type # Methodsfrom :: Merge a -> Rep (Merge a) x #to :: Rep (Merge a) x -> Merge a # Semigroup a => Semigroup (Merge a) Source # Instance detailsDefined in Markov Methods(<>) :: Merge a -> Merge a -> Merge a #sconcat :: NonEmpty (Merge a) -> Merge a #stimes :: Integral b => b -> Merge a -> Merge a # Monoid a => Monoid (Merge a) Source # Instance detailsDefined in Markov Methodsmempty :: Merge a #mappend :: Merge a -> Merge a -> Merge a #mconcat :: [Merge a] -> Merge a # Grouping a => Grouping (Merge a) Source # Instance detailsDefined in Markov Methodsgrouping :: Group (Merge a) # Combine (Merge a) Source # Instance detailsDefined in Markov Methodscombine :: Merge a -> Merge a -> Merge a Source #summarize :: NonEmpty (Merge a) -> Merge a Source # Source # Instance detailsDefined in Markov.Examples Methods type Rep (Merge a) Source # Instance detailsDefined in Markov type Rep (Merge a) = D1 (MetaData "Merge" "Markov" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "Merge" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))

newtype Sum a Source #

Values which are added each step. E.g., number of times a red ball is picked from an urn.

Constructors

 Sum a
Instances
 Enum a => Enum (Sum a) Source # Instance detailsDefined in Markov Methodssucc :: Sum a -> Sum a #pred :: Sum a -> Sum a #toEnum :: Int -> Sum a #fromEnum :: Sum a -> Int #enumFrom :: Sum a -> [Sum a] #enumFromThen :: Sum a -> Sum a -> [Sum a] #enumFromTo :: Sum a -> Sum a -> [Sum a] #enumFromThenTo :: Sum a -> Sum a -> Sum a -> [Sum a] # Eq a => Eq (Sum a) Source # Instance detailsDefined in Markov Methods(==) :: Sum a -> Sum a -> Bool #(/=) :: Sum a -> Sum a -> Bool # Fractional a => Fractional (Sum a) Source # Instance detailsDefined in Markov Methods(/) :: Sum a -> Sum a -> Sum a #recip :: Sum a -> Sum a # Num a => Num (Sum a) Source # Instance detailsDefined in Markov Methods(+) :: Sum a -> Sum a -> Sum a #(-) :: Sum a -> Sum a -> Sum a #(*) :: Sum a -> Sum a -> Sum a #negate :: Sum a -> Sum a #abs :: Sum a -> Sum a #signum :: Sum a -> Sum a # Show a => Show (Sum a) Source # Instance detailsDefined in Markov MethodsshowsPrec :: Int -> Sum a -> ShowS #show :: Sum a -> String #showList :: [Sum a] -> ShowS # Generic (Sum a) Source # Instance detailsDefined in Markov Associated Typestype Rep (Sum a) :: Type -> Type # Methodsfrom :: Sum a -> Rep (Sum a) x #to :: Rep (Sum a) x -> Sum a # Num a => Semigroup (Sum a) Source # Instance detailsDefined in Markov Methods(<>) :: Sum a -> Sum a -> Sum a #sconcat :: NonEmpty (Sum a) -> Sum a #stimes :: Integral b => b -> Sum a -> Sum a # Num a => Monoid (Sum a) Source # Instance detailsDefined in Markov Methodsmempty :: Sum a #mappend :: Sum a -> Sum a -> Sum a #mconcat :: [Sum a] -> Sum a # Grouping a => Grouping (Sum a) Source # Instance detailsDefined in Markov Methodsgrouping :: Group (Sum a) # Combine (Sum a) Source # Instance detailsDefined in Markov Methodscombine :: Sum a -> Sum a -> Sum a Source #summarize :: NonEmpty (Sum a) -> Sum a Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Simple -> [(Sum Int, Simple -> Simple)] Source #step :: (Sum Int, Simple) -> [(Sum Int, Simple)] Source #chain :: [(Sum Int, Simple)] -> [[(Sum Int, Simple)]] Source # Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methodsstep :: ((Sum Int, Product Rational), Extinction) -> [((Sum Int, Product Rational), Extinction)] Source #chain :: [((Sum Int, Product Rational), Extinction)] -> [[((Sum Int, Product Rational), Extinction)]] Source # type Rep (Sum a) Source # Instance detailsDefined in Markov type Rep (Sum a) = D1 (MetaData "Sum" "Markov" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "Sum" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))

newtype Product a Source #

Values which are multiplied each step, and combined additively for equal states. E.g., probabilities.

Constructors

 Product a
Instances
 Enum a => Enum (Product a) Source # Instance detailsDefined in Markov Methodssucc :: Product a -> Product a #pred :: Product a -> Product a #toEnum :: Int -> Product a #fromEnum :: Product a -> Int #enumFrom :: Product a -> [Product a] #enumFromThen :: Product a -> Product a -> [Product a] #enumFromTo :: Product a -> Product a -> [Product a] #enumFromThenTo :: Product a -> Product a -> Product a -> [Product a] # Eq (Product a) Source # Instance detailsDefined in Markov Methods(==) :: Product a -> Product a -> Bool #(/=) :: Product a -> Product a -> Bool # Fractional a => Fractional (Product a) Source # Instance detailsDefined in Markov Methods(/) :: Product a -> Product a -> Product a #recip :: Product a -> Product a # Num a => Num (Product a) Source # Instance detailsDefined in Markov Methods(+) :: Product a -> Product a -> Product a #(-) :: Product a -> Product a -> Product a #(*) :: Product a -> Product a -> Product a #negate :: Product a -> Product a #abs :: Product a -> Product a #signum :: Product a -> Product a # Show a => Show (Product a) Source # Instance detailsDefined in Markov MethodsshowsPrec :: Int -> Product a -> ShowS #show :: Product a -> String #showList :: [Product a] -> ShowS # Source # Instance detailsDefined in Markov Associated Typestype Rep (Product a) :: Type -> Type # Methodsfrom :: Product a -> Rep (Product a) x #to :: Rep (Product a) x -> Product a # Num a => Semigroup (Product a) Source # Instance detailsDefined in Markov Methods(<>) :: Product a -> Product a -> Product a #sconcat :: NonEmpty (Product a) -> Product a #stimes :: Integral b => b -> Product a -> Product a # Num a => Monoid (Product a) Source # Instance detailsDefined in Markov Methodsmappend :: Product a -> Product a -> Product a #mconcat :: [Product a] -> Product a # Source # Instance detailsDefined in Markov Methods Num a => Combine (Product a) Source # Instance detailsDefined in Markov Methodscombine :: Product a -> Product a -> Product a Source # Source # Instance detailsDefined in Markov.Examples Methodsstep :: (Product Double, FillBin) -> [(Product Double, FillBin)] Source #chain :: [(Product Double, FillBin)] -> [[(Product Double, FillBin)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Tidal -> [(Product Double, Tidal -> Tidal)] Source #step :: (Product Double, Tidal) -> [(Product Double, Tidal)] Source #chain :: [(Product Double, Tidal)] -> [[(Product Double, Tidal)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Urn -> [(Product Double, Urn -> Urn)] Source #step :: (Product Double, Urn) -> [(Product Double, Urn)] Source #chain :: [(Product Double, Urn)] -> [[(Product Double, Urn)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Simple -> [(Product Double, Simple -> Simple)] Source #step :: (Product Double, Simple) -> [(Product Double, Simple)] Source #chain :: [(Product Double, Simple)] -> [[(Product Double, Simple)]] Source # Source # Instance detailsDefined in Markov.Examples Methodsstep :: (Product Double, FromMatrix) -> [(Product Double, FromMatrix)] Source #chain :: [(Product Double, FromMatrix)] -> [[(Product Double, FromMatrix)]] Source # Source # Instance detailsDefined in Markov.Examples Methodstransition :: Simple -> [(Product Int, Simple -> Simple)] Source #step :: (Product Int, Simple) -> [(Product Int, Simple)] Source #chain :: [(Product Int, Simple)] -> [[(Product Int, Simple)]] Source # Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methodsstep :: ((Sum Int, Product Rational), Extinction) -> [((Sum Int, Product Rational), Extinction)] Source #chain :: [((Sum Int, Product Rational), Extinction)] -> [[((Sum Int, Product Rational), Extinction)]] Source # type Rep (Product a) Source # Instance detailsDefined in Markov type Rep (Product a) = D1 (MetaData "Product" "Markov" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "Product" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))

# Misc

type (:*) a b = (a, b) Source #

Easier way to write nested 2-tuples.

(>*<) :: a -> b -> a :* b infixl 5 Source #

Easier way to write nested 2-tuples, since a >*< b >*< c >*< d is much easier to read than (((a,b),c),d). Left associative, binds weaker than + but stronger than ==.

fromLists :: Eq b => [[a]] -> [b] -> b -> [(a, b -> b)] Source #

Create a transition function from a transition matrix. If [[a]] is an n x n matrix, length [b] should be n.