In [1]:
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([
        [1,0,0,0],
        [Rational(3,10),Rational(4,10),Rational(1,10),Rational(2,10)],
        [0,0,1,0],
        [Rational(2,10),Rational(3,10),Rational(4,10),Rational(1,10)]
    ])

In [3]:
X = MarkovChain(P, states = ['red','blue','black','green'])

In [4]:
abs_red = X.absorption_prob('red')
vector_display(abs_red,X.state_space)


Out[4]:
Prob
red 1
blue 31/48
black 0
green 7/16

In [5]:
abs_steps = X.absorption_steps()
vector_display(abs_steps, X.state_space)


Out[5]:
Prob
red 0
blue 55/24
black 0
green 15/8

In [2]:
P2 = np.array([
        [Rational(2,10),0,0,Rational(8,10)],
        [0,1,0,0],
        [Rational(1,10),Rational(4,10),Rational(2,10),Rational(3,10)],
        [Rational(7,10),0,0,Rational(3,10)]         
    ])
X = MarkovChain(P2, states = ['red','blue','black','green'])

In [3]:
Pi = X.long_run_probs(method = 'rational')
matrix_display(Pi,X.state_space)


[7/15 8/15]
1/2
Out[3]:
red blue black green
red 7/15 0 0 8/15
blue 0 1 0 0
black 7/30 1/2 0 4/15
green 7/15 0 0 8/15

In [9]:
P2[0][0]


Out[9]:
$$\frac{1}{5}$$

In [ ]: