- PyTorch 1.x Reinforcement Learning Cookbook
- Yuxi (Hayden) Liu
- 150字
- 2021-06-24 12:34:44
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:
- Import the library and define the transition matrix:
>>> import torch
>>> T = torch.tensor([[0.4, 0.6],
... [0.8, 0.2]])
- 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)
- Define the initial distribution of two states:
>>> v = torch.tensor([[0.7, 0.3]])
- 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)
推薦閱讀
- Big Data Analytics with Hadoop 3
- 智能傳感器技術與應用
- Dreamweaver CS3網頁制作融會貫通
- 大數據處理平臺
- Embedded Programming with Modern C++ Cookbook
- 精通數據科學算法
- Kubernetes for Developers
- 內??刂萍捌鋺?/a>
- 貫通Java Web開發三劍客
- 智能生產線的重構方法
- Bayesian Analysis with Python
- Hands-On Dashboard Development with QlikView
- IBM? SmartCloud? Essentials
- Drupal高手建站技術手冊
- 自適應學習:人工智能時代的教育革命