馬爾科夫鏈的穩態分佈

crazypigf發表於2024-06-23
import numpy as np


def steady_distribution(A, b, max_iter=100):
    y = A @ b
    count = 1
    while not (y == b).all() and count < max_iter:
        print(y)
        b = y
        y = A @ b
        count += 1


if __name__ == '__main__':
    matrix = np.array([[0.4, 0.5], [0.6, 0.5]])
    p = np.array([0.1, 0.9])
    steady_distribution(matrix, p)

相關文章