How it works...

In Step 2, we calculated the transition probability after k steps, which is the kth power of the transition matrix. You will see the following output:

>>> print("Transition probability after 2 steps:\n{}".format(T_2))Transition probability after 2 steps:tensor([[0.6400, 0.3600],        [0.4800, 0.5200]])>>> print("Transition probability after 5 steps:\n{}".format(T_5))Transition probability after 5 steps:tensor([[0.5670, 0.4330],        [0.5773, 0.4227]])>>> print("Transition probability after 10 steps:\n{}".format(T_10))Transition probability after 10 steps:tensor([[0.5715, 0.4285],        [0.5714, 0.4286]])>>> print("Transition probability after 15 steps:\n{}".format(T_15))Transition probability after 15 steps:tensor([[0.5714, 0.4286], [0.5714, ...

Get PyTorch 1.x Reinforcement Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.