<jupyter_start><jupyter_text>Markovské řetězce s diskrétním časem<jupyter_code>import numpy as np
import scipy.linalg as la<jupyter_output><empty_output><jupyter_text>Příklad 7.1<jupyter_code>a = 1/5
b = 3/4
# matice přechodu
P = np.matrix([[1-a,a],[b,1-b]])
print("P =\n", P)
print(np.sum(P,axis = 1))
# dvoukroková matice přechodu
print("P^2 = \n", P**2 )
print(np.sum(P**2,axis = 1))
# počáteční rozdělení
p0 = np.matrix([0,1])
print("p(0) =", p0)
# rozdělení v čase n
n = 100
pn = p0 * P**n
print("p(n) =",pn)
(15/19, 4/19)
# stacionární rozdělení
W = np.transpose(P-np.eye(P.shape[0])) 
pi = la.null_space(W)
pi = np.transpose(pi/sum(pi)) # normalizace
print("pi =",pi)
pi*P
# pomocí vlastních čísel
D = np.transpose(P)
vl_cis, vl_vec = np.linalg.eig(D)
print(vl_cis)
pi = vl_vec[:,0]
pi = pi/np.sum(pi)
pi = np.transpose(pi)
print(pi)
def StacDist(P):
    W = np.transpose(P-np.eye(P.shape[0])) 
    pi = la.null_space(W)
    pi = np.transpose(pi/sum(pi))
    return pi
pi = StacDist(P)
print("pi =",pi)<jupyter_output><empty_output><jupyter_text>Příklad 7.2<jupyter_code>P = np.matrix([[0.1, 0.2, 0.4, 0.3],
               [0.1, 0.2, 0.4, 0.3],
               [0.3, 0.4, 0.3, 0],
               [0.1, 0.2, 0.4, 0.3]])
print("P = \n", P)
pi = StacDist(P)
print("pi =",pi)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20811017597551645, 'fraction_numerical': 0.04973221117061974, 'mean_word_length': 3.898876404494382, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '649031', 'license': 'MIT', 'n_tokens_mistral': 689, 'n_tokens_neox': 665, 'n_words': 118, 'path': 'hrabak-cvika/07-Stationary.ipynb', 'repo_name': 'TaIos/ni-vsm-openbook-test-helper', 'size': '1307'}