File size: 1,588 Bytes
1c08905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Small exact models used by examples and the independent test suite."""
from fractions import Fraction as Q
from .arithmetic import Field
from .source import Source


def fair(field="phi"):
    f=Field(field)
    return Source(f,1,[(0,0,0,1,Q(1,2)),(0,0,1,1,Q(1,2))],[1])


def markov(field="phi"):
    # Stationary pi=(4/5,1/5), zero transition 1 -> 1.
    f=Field(field)
    return Source(f,2,[(0,0,0,1,Q(3,4)),(0,1,1,1,Q(1,4)),
                       (1,0,0,1,1)],[Q(4,5),Q(1,5)])


def periodic(field="phi"):
    f=Field(field)
    return Source(f,2,[(0,1,1,1,1),(1,0,0,1,1)],[Q(1,2),Q(1,2)])


def mixture():
    return Source(Field("integer"),2,[(0,0,0,1,Q(1,2)),(0,0,1,1,Q(1,2)),
                                        (1,1,0,1,1)],[Q(1,2),Q(1,2)])


def variable(field="phi"):
    # Same two vertex transition probabilities as markov(), with branch clocks 1/2.
    return Source(Field(field),2,[(0,0,0,1,Q(3,4)),(0,1,1,2,Q(1,4)),
                                  (1,0,1,1,1)],[Q(4,5),Q(1,5)])


def hidden():
    # Three hidden states, overlapping emissions, genuinely hidden rather than visible Markov digits.
    es=[(0,0,0,1,Q(1,2)),(0,1,1,2,Q(1,2)),
        (1,1,0,1,Q(1,2)),(1,2,1,1,Q(1,2)),
        (2,2,1,2,Q(1,2)),(2,0,0,1,Q(1,2))]
    return Source(Field("phi"),3,es,[Q(1,3)]*3)


def correlated(field="phi"):
    # Stationary correlated source with both sides of arithmetic overlaps allowed.
    return Source(Field(field),2,[(0,0,0,1,Q(3,4)),(0,1,1,1,Q(1,4)),
                                  (1,0,0,1,Q(1,2)),(1,1,1,1,Q(1,2))],
                  [Q(2,3),Q(1,3)])