markov-realization-0.1.0: Realizations of Markov chains.

Maintainer atloomis@math.arizona.edu experimental None Haskell2010

Markov.Examples

Description

Several examples of Markov chains. It is probably more helpful to read the source code than the Haddock documentation.

Synopsis

# Documentation

newtype FromMatrix Source #

An example defined from a matrix.

>>> chain [pure 't' :: Product Double :* Char] !! 100
[ (0.5060975609756099,'a')
, (0.201219512195122,'t')
, (0.29268292682926833,'l') ]


Constructors

 FromMatrix Char
Instances
 Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples MethodsshowList :: [FromMatrix] -> ShowS # Source # Instance detailsDefined in Markov.Examples Associated Typestype Rep FromMatrix :: Type -> Type # Methods Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methodsstep :: (Product Double, FromMatrix) -> [(Product Double, FromMatrix)] Source #chain :: [(Product Double, FromMatrix)] -> [[(Product Double, FromMatrix)]] Source # type Rep FromMatrix Source # Instance detailsDefined in Markov.Examples type Rep FromMatrix = D1 (MetaData "FromMatrix" "Markov.Examples" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "FromMatrix" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Char)))

newtype Simple Source #

A simple random walk. Possible outcomes of the first three steps:

>>> take 3 $chain0 [Simple 0] [ [0] , [-1,1] , [-2,0,2]]  Probability of each outcome: >>> take 3$ chain [pure 0 :: Product Double :* Simple]
[ [(1.0,0)]
, [(0.5,-1),(0.5,1)]
, [(0.25,-2),(0.5,0),(0.25,2)] ]


Number of ways to achieve each outcome:

>>> take 3 $chain [pure 0 :: Product Int :* Simple] [ [(1,0)] , [(1,-1),(1,1)] , [(1,-2),(2,0),(1,2)] ]  Number of times pred was applied, allowing steps in place (id) for more interesting output: >>> chain [pure 0 :: Sum Int :* Simple] !! 2 [ (2,-2) , (1,-1) , (1,0) , (0,0) , (0,1) , (0,2) ]  Constructors  Simple Int Instances  Source # Instance detailsDefined in Markov.Examples MethodstoEnum :: Int -> Simple #enumFrom :: Simple -> [Simple] #enumFromThen :: Simple -> Simple -> [Simple] #enumFromTo :: Simple -> Simple -> [Simple] #enumFromThenTo :: Simple -> Simple -> Simple -> [Simple] # Source # Instance detailsDefined in Markov.Examples Methods(==) :: Simple -> Simple -> Bool #(/=) :: Simple -> Simple -> Bool # Source # Instance detailsDefined in Markov.Examples Methods(+) :: Simple -> Simple -> Simple #(-) :: Simple -> Simple -> Simple #(*) :: Simple -> Simple -> Simple #abs :: Simple -> Simple # Source # Instance detailsDefined in Markov.Examples Methods(<) :: Simple -> Simple -> Bool #(<=) :: Simple -> Simple -> Bool #(>) :: Simple -> Simple -> Bool #(>=) :: Simple -> Simple -> Bool #max :: Simple -> Simple -> Simple #min :: Simple -> Simple -> Simple # Source # Instance detailsDefined in Markov.Examples MethodsshowsPrec :: Int -> Simple -> ShowS #showList :: [Simple] -> ShowS # Source # Instance detailsDefined in Markov.Examples Associated Typestype Rep Simple :: Type -> Type # Methodsfrom :: Simple -> Rep Simple x #to :: Rep Simple x -> Simple # Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methodstransition0 :: Simple -> [Simple -> Simple] Source #step0 :: Simple -> [Simple] Source #chain0 :: [Simple] -> [[Simple]] 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 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 # type Rep Simple Source # Instance detailsDefined in Markov.Examples type Rep Simple = D1 (MetaData "Simple" "Markov.Examples" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "Simple" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))) newtype Urn Source # An urn contains balls of two colors. At each step, a ball is chosen uniformly at random from the urn and a ball of the same color is added. Constructors  Urn (Int, Int) Instances  Source # Instance detailsDefined in Markov.Examples Methods(==) :: Urn -> Urn -> Bool #(/=) :: Urn -> Urn -> Bool # Source # Instance detailsDefined in Markov.Examples Methodscompare :: Urn -> Urn -> Ordering #(<) :: Urn -> Urn -> Bool #(<=) :: Urn -> Urn -> Bool #(>) :: Urn -> Urn -> Bool #(>=) :: Urn -> Urn -> Bool #max :: Urn -> Urn -> Urn #min :: Urn -> Urn -> Urn # Source # Instance detailsDefined in Markov.Examples MethodsshowsPrec :: Int -> Urn -> ShowS #show :: Urn -> String #showList :: [Urn] -> ShowS # Source # Instance detailsDefined in Markov.Examples Associated Typestype Rep Urn :: Type -> Type # Methodsfrom :: Urn -> Rep Urn x #to :: Rep Urn x -> Urn # Source # Instance detailsDefined in Markov.Examples Methods 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 # type Rep Urn Source # Instance detailsDefined in Markov.Examples type Rep Urn = D1 (MetaData "Urn" "Markov.Examples" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "Urn" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Int, Int)))) newtype Extinction Source # This is the chain from the README. Constructors  Extinction Int Instances  Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples MethodsshowList :: [Extinction] -> ShowS # Source # Instance detailsDefined in Markov.Examples Associated Typestype Rep Extinction :: Type -> Type # Methods Source # Instance detailsDefined in Markov.Examples Methodsstimes :: Integral b => b -> Extinction -> Extinction # Source # Instance detailsDefined in Markov.Examples Methods 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 Extinction Source # Instance detailsDefined in Markov.Examples type Rep Extinction = D1 (MetaData "Extinction" "Markov.Examples" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "Extinction" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))) data Tidal Source # A time inhomogenous random walk that vaguely models tides by periodically switching directions and falling back from a shore at the origin. Constructors  Tidal Fieldstime :: Double position :: Int Instances  Source # Instance detailsDefined in Markov.Examples Methods(==) :: Tidal -> Tidal -> Bool #(/=) :: Tidal -> Tidal -> Bool # Source # Instance detailsDefined in Markov.Examples Methods(<) :: Tidal -> Tidal -> Bool #(<=) :: Tidal -> Tidal -> Bool #(>) :: Tidal -> Tidal -> Bool #(>=) :: Tidal -> Tidal -> Bool #max :: Tidal -> Tidal -> Tidal #min :: Tidal -> Tidal -> Tidal # Source # Instance detailsDefined in Markov.Examples MethodsshowsPrec :: Int -> Tidal -> ShowS #show :: Tidal -> String #showList :: [Tidal] -> ShowS # Source # Instance detailsDefined in Markov.Examples Associated Typestype Rep Tidal :: Type -> Type # Methodsfrom :: Tidal -> Rep Tidal x #to :: Rep Tidal x -> Tidal # Source # Instance detailsDefined in Markov.Examples Methods 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 # type Rep Tidal Source # Instance detailsDefined in Markov.Examples type Rep Tidal = D1 (MetaData "Tidal" "Markov.Examples" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" False) (C1 (MetaCons "Tidal" PrefixI True) (S1 (MetaSel (Just "time") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Double) :*: S1 (MetaSel (Just "position") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))) newtype Room Source # A hidden Markov model. >>> filter ($$(_,Merge xs),_) -> xs == "aaa") multiChain [1 >*< Merge "" >*< 1 :: Product Rational :* Merge String :* Room] !! 3 [ ((3243 % 200000,"aaa"),Room 1) , ((9729 % 500000,"aaa"),Room 2) , ((4501 % 250000,"aaa"),Room 3) ]  Given that all three tokens recieved were "a", there is a probability of approximately 0.34 that the current room is Room 3. Constructors  Room Int Instances  Source # Instance detailsDefined in Markov.Examples Methods(==) :: Room -> Room -> Bool #(/=) :: Room -> Room -> Bool # Source # Instance detailsDefined in Markov.Examples Methods(+) :: Room -> Room -> Room #(-) :: Room -> Room -> Room #(*) :: Room -> Room -> Room #negate :: Room -> Room #abs :: Room -> Room #signum :: Room -> Room # Source # Instance detailsDefined in Markov.Examples MethodsshowsPrec :: Int -> Room -> ShowS #show :: Room -> String #showList :: [Room] -> ShowS # Source # Instance detailsDefined in Markov.Examples Associated Typestype Rep Room :: Type -> Type # Methodsfrom :: Room -> Rep Room x #to :: Rep Room x -> Room # Source # Instance detailsDefined in Markov.Examples Methods(<>) :: Room -> Room -> Room #stimes :: Integral b => b -> Room -> Room # Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methods type Rep Room Source # Instance detailsDefined in Markov.Examples type Rep Room = D1 (MetaData "Room" "Markov.Examples" "markov-realization-0.1.0-6GSvYD8yAhy2vCcDg5QqBj" True) (C1 (MetaCons "Room" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))) data FillBin Source # A collection of bins with gaps between them. At each step an empty space is chosen form a bin or from a gap. If it is in a bin, the space is filled. If it is in a gap, it is assigned to an adjacent bin, which expands to contain it and any intervening spaces, and then the space filled. Instances  Source # Instance detailsDefined in Markov.Examples Methods(==) :: FillBin -> FillBin -> Bool #(/=) :: FillBin -> FillBin -> Bool # Source # Instance detailsDefined in Markov.Examples Methods(<) :: FillBin -> FillBin -> Bool #(<=) :: FillBin -> FillBin -> Bool #(>) :: FillBin -> FillBin -> Bool #(>=) :: FillBin -> FillBin -> Bool # Source # Instance detailsDefined in Markov.Examples MethodsshowList :: [FillBin] -> ShowS # Source # Instance detailsDefined in Markov.Examples Associated Typestype Rep FillBin :: Type -> Type # Methodsto :: Rep FillBin x -> FillBin # Source # Instance detailsDefined in Markov.Examples Methods Source # Instance detailsDefined in Markov.Examples Methodsstep :: (Product Double, FillBin) -> [(Product Double, FillBin)] Source #chain :: [(Product Double, FillBin)] -> [[(Product Double, FillBin)]] Source # type Rep FillBin Source # Instance detailsDefined in Markov.Examples type Rep FillBin initial :: [Int] -> FillBin Source # Create state where all bins start as (0,0). >>> initial [5,7,0] 5 (0,0) 7 (0,0) 0  expectedLoss :: (Fractional a, Markov (Product a) FillBin) => [Product a :* FillBin] -> a Source # Expected loss of a set of pstates of [FillBin]. Loss is the \(l^2$$ distance between a finished state and a state with perfectly balanced bins. >>> expectedLoss [pure$ initial [1,0,3] :: Product Double :* FillBin]
2.0