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

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)
主站蜘蛛池模板: 玛沁县| 岚皋县| 闸北区| 阜阳市| 馆陶县| 芒康县| 随州市| 天长市| 霍城县| 马尔康县| 双牌县| 五莲县| 连山| 方山县| 神农架林区| 吉水县| 滦平县| 蓬莱市| 甘谷县| 新沂市| 竹山县| 宜兴市| 莱州市| 平湖市| 丹寨县| 津南区| 奈曼旗| 米林县| 古浪县| 平江县| 慈溪市| 天峻县| 余庆县| 蕲春县| 平南县| 常德市| 寻甸| 融水| 会同县| 伽师县| 台江县|