Преобразовать временные ряды в матрицу перехода
def compute_transition_matrix(data, n, step = 1):
P = np.zeros((n, n))
m = len(data)
for i in range(m):
initial, final = i, i + step
if final < m:
P[data[initial]][data[final]] += 1
sums = np.sum(P, axis = 1)
for i in range(n):
for j in range(n):
P[i][j] = P[i][j] / sums[i]
return P
print(compute_transition_matrix([3, 0, 1, 3, 2, 6, 5, 4, 7, 5, 4], 8, 1))
# data is the input time series data, n is the total number of states in the Markov chain, step is the transition step.
Enchanting Eel