Skip to content

Commit ed4d3f6

Browse files
committed
Added some textbook tests
1 parent 5a0ad60 commit ed4d3f6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sympy/stats/tests/test_stochastic_process.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,28 @@ def test_DiscreteMarkovChain():
199199
assert recurrence == (True, True, False, True, False)
200200
assert periods == (1, 1, 1, 1, 1)
201201

202+
# test canonical form
203+
# see https://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/Chapter11.pdf
204+
# example 11.13
205+
T = Matrix([[1, 0, 0, 0, 0],
206+
[S(1) / 2, 0, S(1) / 2, 0, 0],
207+
[0, S(1) / 2, 0, S(1) / 2, 0],
208+
[0, 0, S(1) / 2, 0, S(1) / 2],
209+
[0, 0, 0, 0, S(1)]])
210+
DW = DiscreteMarkovChain('DW', [0, 1, 2, 3, 4], T)
211+
states, A, B, C = DW.decompose()
212+
assert states == [0, 4, 1, 2, 3]
213+
assert A == Matrix([[1, 0], [0, 1]])
214+
assert B == Matrix([[S(1)/2, 0], [0, 0], [0, S(1)/2]])
215+
assert C == Matrix([[0, S(1)/2, 0], [S(1)/2, 0, S(1)/2], [0, S(1)/2, 0]])
216+
states, new_matrix = DW.canonical_form()
217+
assert states == [0, 4, 1, 2, 3]
218+
assert new_matrix == Matrix([[1, 0, 0, 0, 0],
219+
[0, 1, 0, 0, 0],
220+
[S(1)/2, 0, 0, S(1)/2, 0],
221+
[0, 0, S(1)/2, 0, S(1)/2],
222+
[0, S(1)/2, 0, S(1)/2, 0]])
223+
202224
# test custom state space
203225
Y10 = DiscreteMarkovChain('Y', [1, 2, 3], TO2)
204226
tuples = Y10.communication_classes()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy