Maintainer | atloomis@math.arizona.edu |
---|---|
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Several examples of Markov chains. It is probably more helpful to read the source code than the Haddock documentation.
Synopsis
- newtype FromMatrix = FromMatrix Char
- newtype Simple = Simple Int
- newtype Urn = Urn (Int, Int)
- newtype Extinction = Extinction Int
- data Tidal = Tidal {}
- newtype Room = Room Int
- data FillBin
- initial :: [Int] -> FillBin
- expectedLoss :: (Fractional a, Markov (Product a) FillBin) => [Product a :* FillBin] -> a
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') ]
Instances
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) ]
Instances
Enum Simple Source # | |
Defined in Markov.Examples | |
Eq Simple Source # | |
Num Simple Source # | |
Ord Simple Source # | |
Show Simple Source # | |
Generic Simple Source # | |
Grouping Simple Source # | |
Defined in Markov.Examples | |
Markov0 Simple Source # | |
Markov (Product Double) Simple Source # | |
Markov (Product Int) Simple Source # | |
Markov (Sum Int) Simple Source # | |
type Rep Simple Source # | |
Defined in Markov.Examples |
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.
newtype Extinction Source #
This is the chain from the README.
Instances
A time inhomogenous random walk that vaguely models tides by periodically switching directions and falling back from a shore at the origin.
Instances
Eq Tidal Source # | |
Ord Tidal Source # | |
Show Tidal Source # | |
Generic Tidal Source # | |
Grouping Tidal Source # | |
Defined in Markov.Examples | |
Markov (Product Double) Tidal Source # | |
type Rep Tidal Source # | |
Defined 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))) |
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
.
Instances
Eq Room Source # | |
Num Room Source # | |
Show Room Source # | |
Generic Room Source # | |
Semigroup Room Source # | |
Grouping Room Source # | |
Defined in Markov.Examples | |
Combine Room Source # | |
MultiMarkov ((Product Rational :* Merge String) :* Room) Source # | |
Defined in Markov.Examples multiTransition :: ((Product Rational :* Merge String) :* Room) -> [((Product Rational :* Merge String) :* Room) -> [(Product Rational :* Merge String) :* Room]] Source # multiStep :: ((Product Rational :* Merge String) :* Room) -> [(Product Rational :* Merge String) :* Room] Source # multiChain :: [(Product Rational :* Merge String) :* Room] -> [[(Product Rational :* Merge String) :* Room]] Source # | |
type Rep Room Source # | |
Defined in Markov.Examples |
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.
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 [
.
Loss is the \(l^2\) distance between a finished state
and a state with perfectly balanced bins.FillBin
]
>>>
expectedLoss [pure $ initial [1,0,3] :: Product Double :* FillBin]
2.0