In [2]:
from sympy import *; init_session()
from applpy import *
import numpy as np


IPython console for SymPy 0.7.7.dev (Python 2.7.10-64-bit) (ground types: python)

These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
>>> init_printing()

Documentation can be found at http://docs.sympy.org/dev

In [2]:
P = np.array([
    [0, 0.1, 0.5, 0, 0.2, 0.2, 0, 0],
    [0.1, 0.2, 0, 0, 0.6, 0, 0, 0.1],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0.2, 0, 0.8],
    [0, 0.3, 0, 0, 0, 0.4, 0.1, 0.2],
    [0, 0, 0, 0, 0, 0.6, 0, 0.4]
    ])
P2 = np.array([
        [0.2,0,0,0.8,0],
        [0,1,0,0,0],
        [0,0.1,0.5,0,0.4],
        [0.4,0,0,0.6,0],
        [0,0.3,0,0,0.7]
    ])

In [6]:
X = MarkovChain(P =[
    [0, 0.1, 0.5, 0, 0.2, 0.2, 0, 0],
    [0.1, 0.2, 0, 0, 0.6, 0, 0, 0.1],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0.2, 0, 0.8],
    [0, 0.3, 0, 0, 0, 0.4, 0.1, 0.2],
    [0, 0, 0, 0, 0, 0.6, 0, 0.4]
    ], 
    states = ['blue','green','purple','red',
        'yellow', 'black', 'orange', 'white'])

In [7]:
X.classify_states()


Out[7]:
{'Recurrent 1': ['red', 'yellow'],
 'Recurrent 2': ['black', 'white'],
 'Recurrent 3': ['purple'],
 'Transient': ['blue', 'green', 'orange']}

In [8]:
X.reducible


Out[8]:
True

In [3]:
X = MarkovChain(P =[
    [0, 0.1, 0.5, 0, 0.2, 0.2, 0, 0],
    [0.1, 0.2, 0, 0, 0.6, 0, 0, 0.1],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0, 0],
    [0, 0, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0.2, 0, 0.8],
    [0, 0.3, 0, 0, 0, 0.4, 0.1, 0.2],
    [0, 0, 0, 0, 0, 0.6, 0, 0.4]
    ])
X.reachability()


Out[3]:
array([[ True,  True,  True,  True,  True,  True, False,  True],
       [ True,  True,  True,  True,  True,  True, False,  True],
       [False, False,  True, False, False, False, False, False],
       [False, False, False,  True,  True, False, False, False],
       [False, False, False,  True,  True, False, False, False],
       [False, False, False, False, False,  True, False,  True],
       [ True,  True,  True,  True,  True,  True,  True,  True],
       [False, False, False, False, False,  True, False,  True]], dtype=bool)

In [ ]: