File: Markov.hs

package info (click to toggle)
bali-phy 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,392 kB
  • sloc: cpp: 120,442; xml: 13,966; haskell: 9,975; python: 2,936; yacc: 1,328; perl: 1,169; lex: 912; sh: 343; makefile: 26
file content (27 lines) | stat: -rw-r--r-- 819 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Probability.Distribution.Markov where

import Probability.Random

sample_markov x0 next = do
  x1 <- next x0
  xs <- sample_markov x1 next
  return (x0:xs)

sample_markov_n 0 x0 next = return []
sample_markov_n n x0 next = do
  x1 <- next x0
  xs <- sample_markov_n (n-1) x1 next
  return (x0:xs)


-- I think if next has type (a->Dist a) and not just
-- (a->Sample a), then we could compute likelihoods.

-- The fastest way would be to represent the transition
-- probabilities in a matrix -- at least for integer
-- sequences -- but that is less general.  Maybe we should
-- make a markov_int distribution that takes a starting
-- distribution and a transition probability matrix?

-- I presume that we would need to make any markov DISTRIBUTION
-- have an actual length.  Do we want them to be lazy?  Strict?