PureOne's picture
Release VELORYN v1.0.0: boundary-kernel entropy theory
1c08905 verified
Raw History Blame Contribute Delete
1.59 kB
"""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)])