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 FromLists = FromLists 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
An example defined from a matrix.
>>>
chain [pure (FromMatrix 't') :: (Product Double, FromMatrix)] !! 100
[ (0.5060975609756099,'a') , (0.201219512195122,'t') , (0.29268292682926833,'l') ]
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.Example | |
Eq Simple Source # | |
Num Simple Source # | |
Ord Simple Source # | |
Show Simple Source # | |
Generic Simple Source # | |
Grouping Simple Source # | |
Defined in Markov.Example | |
Combine Simple Source # | |
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.Example |
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.Example | |
Combine Tidal Source # | |
Markov ((,) (Product Double)) Tidal Source # | |
type Rep Tidal Source # | |
Defined in Markov.Example type Rep Tidal = D1 (MetaData "Tidal" "Markov.Example" "markov-realization-0.3.0-5G6aaFp9qxGCG9ox1pSRBj" 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") $ 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
.
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 states 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