markov-realization-0.4: Realizations of Markov chains.

Markov.Example

Description

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

Synopsis

# Documentation

newtype FromLists Source #

An example defined from a matrix.

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


Constructors

 FromLists Char
Instances
 Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example MethodsshowList :: [FromLists] -> ShowS # Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methodsstep :: (Product Double, FromLists) -> [(Product Double, FromLists)] Source #sequential :: [FromLists -> [(Product Double, FromLists -> FromLists)]] Source #

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.Example MethodstoEnum :: Int -> Simple #enumFrom :: Simple -> [Simple] #enumFromThen :: Simple -> Simple -> [Simple] #enumFromTo :: Simple -> Simple -> [Simple] #enumFromThenTo :: Simple -> Simple -> Simple -> [Simple] # Source # Instance detailsDefined in Markov.Example Methods(==) :: Simple -> Simple -> Bool #(/=) :: Simple -> Simple -> Bool # Source # Instance detailsDefined in Markov.Example Methods(+) :: Simple -> Simple -> Simple #(-) :: Simple -> Simple -> Simple #(*) :: Simple -> Simple -> Simple #abs :: Simple -> Simple # Source # Instance detailsDefined in Markov.Example 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.Example MethodsshowsPrec :: Int -> Simple -> ShowS #showList :: [Simple] -> ShowS # Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methodstransition0 :: Simple -> [Simple -> Simple] Source #step0 :: Simple -> [Simple] Source # Source # Instance detailsDefined in Markov.Example Methodstransition :: Simple -> [(Product Double, Simple -> Simple)] Source #step :: (Product Double, Simple) -> [(Product Double, Simple)] Source #sequential :: [Simple -> [(Product Double, Simple -> Simple)]] Source # Source # Instance detailsDefined in Markov.Example Methodstransition :: Simple -> [(Product Int, Simple -> Simple)] Source #step :: (Product Int, Simple) -> [(Product Int, Simple)] Source #sequential :: [Simple -> [(Product Int, Simple -> Simple)]] Source # Source # Instance detailsDefined in Markov.Example Methodstransition :: Simple -> [(Sum Int, Simple -> Simple)] Source #step :: (Sum Int, Simple) -> [(Sum Int, Simple)] Source #sequential :: [Simple -> [(Sum Int, Simple -> Simple)]] Source # 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. >>> randomPath (mkStdGen 70) (Urn (2,5)) !! 8 :: (Product Double, Urn) (0.1648351648351649, Urn (2,13))  Constructors  Urn (Int, Int) Instances  Source # Instance detailsDefined in Markov.Example Methods(==) :: Urn -> Urn -> Bool #(/=) :: Urn -> Urn -> Bool # Source # Instance detailsDefined in Markov.Example 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.Example MethodsshowsPrec :: Int -> Urn -> ShowS #show :: Urn -> String #showList :: [Urn] -> ShowS # Source # Instance detailsDefined in Markov.Example Methodscombine :: Urn -> Urn -> Urn Source # Markov [] ((,) (Product Double)) Urn Source # Instance detailsDefined in Markov.Example Methodstransition :: Urn -> [(Product Double, Urn -> Urn)] Source #step :: (Product Double, Urn) -> [(Product Double, Urn)] Source #sequential :: [Urn -> [(Product Double, Urn -> Urn)]] Source # Source # Instance detailsDefined in Markov.Example Methodstransition :: Urn -> [(Product Double, Urn -> Urn)] Source #step :: (Product Double, Urn) -> [(Product Double, Urn)] Source #sequential :: [Urn -> [(Product Double, Urn -> Urn)]] Source # newtype Extinction Source # This is the chain from the README. Constructors  Extinction Int Instances  Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example MethodsshowList :: [Extinction] -> ShowS # Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methodsstep :: ((Sum Int, Product Rational), Extinction) -> [((Sum Int, Product Rational), Extinction)] Source #sequential :: [Extinction -> [((Sum Int, Product Rational), Extinction -> Extinction)]] Source # 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.Example Methods(==) :: Tidal -> Tidal -> Bool #(/=) :: Tidal -> Tidal -> Bool # Source # Instance detailsDefined in Markov.Example 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.Example MethodsshowsPrec :: Int -> Tidal -> ShowS #show :: Tidal -> String #showList :: [Tidal] -> ShowS # Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methodstransition :: Tidal -> [(Product Double, Tidal -> Tidal)] Source #step :: (Product Double, Tidal) -> [(Product Double, Tidal)] Source #sequential :: [Tidal -> [(Product Double, Tidal -> Tidal)]] Source # newtype Room Source # A hidden Markov model. >>> :{ filter ($$(_,Merge xs),_) -> xs == "aaa") chain  [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.Example Methods(==) :: Room -> Room -> Bool #(/=) :: Room -> Room -> Bool # Source # Instance detailsDefined in Markov.Example Methods(+) :: Room -> Room -> Room #(-) :: Room -> Room -> Room #(*) :: Room -> Room -> Room #negate :: Room -> Room #abs :: Room -> Room #signum :: Room -> Room # Source # Instance detailsDefined in Markov.Example Methodscompare :: Room -> Room -> Ordering #(<) :: Room -> Room -> Bool #(<=) :: Room -> Room -> Bool #(>) :: Room -> Room -> Bool #(>=) :: Room -> Room -> Bool #max :: Room -> Room -> Room #min :: Room -> Room -> Room # Source # Instance detailsDefined in Markov.Example MethodsshowsPrec :: Int -> Room -> ShowS #show :: Room -> String #showList :: [Room] -> ShowS # Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methodstransition :: Room -> [((Product Rational, Merge String), Room -> Room)] Source #step :: ((Product Rational, Merge String), Room) -> [((Product Rational, Merge String), Room)] Source #sequential :: [Room -> [((Product Rational, Merge String), Room -> Room)]] Source # 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.Example Methods(==) :: FillBin -> FillBin -> Bool #(/=) :: FillBin -> FillBin -> Bool # Source # Instance detailsDefined in Markov.Example Methods(<) :: FillBin -> FillBin -> Bool #(<=) :: FillBin -> FillBin -> Bool #(>) :: FillBin -> FillBin -> Bool #(>=) :: FillBin -> FillBin -> Bool # Source # Instance detailsDefined in Markov.Example MethodsshowList :: [FillBin] -> ShowS # Source # Instance detailsDefined in Markov.Example Methods Source # Instance detailsDefined in Markov.Example Methodsstep :: (Product Double, FillBin) -> [(Product Double, FillBin)] Source #sequential :: [FillBin -> [(Product Double, FillBin -> FillBin)]] Source # 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 states 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