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

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)
主站蜘蛛池模板: 鄂伦春自治旗| 闻喜县| 中江县| 根河市| 五家渠市| 金华市| 临沭县| 普安县| 台湾省| 响水县| 三门峡市| 蒙自县| 龙胜| 阿克| 阿尔山市| 长宁区| 滦平县| 绥芬河市| 溧水县| 绥中县| 壶关县| 天台县| 昌图县| 鹤庆县| 丰顺县| 象山县| 富阳市| 绥德县| 建始县| 监利县| 大兴区| 安仁县| 彩票| 驻马店市| 长治市| 潮州市| 黔江区| 逊克县| 织金县| 买车| 新余市|