官术网_书友最值得收藏!

How to do it...

To create a Markov chain for the study - and - sleep process and conduct some analysis on it, perform the following steps:

  1. Import the library and define the transition matrix:
>>> import torch
>>> T = torch.tensor([[0.4, 0.6],
... [0.8, 0.2]])
  1. Calculate the transition probability after k steps. Here, we use k = 2, 5, 10, 15, and 20 as examples:
>>> T_2 = torch.matrix_power(T, 2)
>>> T_5 = torch.matrix_power(T, 5)
>>> T_10 = torch.matrix_power(T, 10)
>>> T_15 = torch.matrix_power(T, 15)
>>> T_20 = torch.matrix_power(T, 20)
  1. Define the initial distribution of two states:
>>> v = torch.tensor([[0.7, 0.3]])
  1. Calculate the state distribution after k = 1, 2, 5, 10, 15, and 20 steps:
>>> v_1 = torch.mm(v, T)
>>> v_2 = torch.mm(v, T_2)
>>> v_5 = torch.mm(v, T_5)
>>> v_10 = torch.mm(v, T_10)
>>> v_15 = torch.mm(v, T_15)
>>> v_20 = torch.mm(v, T_20)
主站蜘蛛池模板: 禹城市| 鄂托克前旗| 开封县| 永州市| 胶州市| 丰镇市| 健康| 承德市| 金堂县| 福清市| 尼木县| 兖州市| 徐汇区| 杂多县| 宣恩县| 阿城市| 乐都县| 阳信县| 辰溪县| 大荔县| 西畴县| 长垣县| 新邵县| 高台县| 莱芜市| 德清县| 新津县| 河北区| 公安县| 峡江县| 湟源县| 承德市| 财经| 兴化市| 信宜市| 南丰县| 安康市| 仁寿县| 南乐县| 巴马| 碌曲县|