我为具有 4 种可能状态和 4 种可能操作的板设置了一个简单的 MDP。董事会和奖励设置如下所示:
这里S4是目标状态,S2是吸收状态。我在我编写的代码中定义了转移概率矩阵和奖励矩阵,以获得此 MDP 的最佳值函数。但是,当我运行代码,我得到一个错误,指出:OverflowError: cannot convert float infinity to integer。我无法理解这样做的原因。
import mdptoolbox
import numpy as np
transitions = np.array([
# action 1 (Right)
[
[0.1, 0.7, 0.1, 0.1],
[0.3, 0.3, 0.3, 0.1],
[0.1, 0.2, 0.2, 0.5],
[0.1, 0.1, 0.1, 0.7]
],
# action 2 (Down)
[
[0.1, 0.4, 0.4, 0.1],
[0.3, 0.3, 0.3, 0.1],
[0.4, 0.1, 0.4, 0.1],
[0.1, 0.1, 0.1, 0.7]
],
# action 3 (Left)
[
[0.4, 0.3, 0.2, 0.1],
[0.2, 0.2, 0.4, 0.2],
[0.5, 0.1, 0.3, 0.1],
[0.1, 0.1, 0.1, 0.7]
],
# action 4 (Top)
[
[0.1, 0.4, 0.4, 0.1],
[0.3, 0.3, 0.3, 0.1],
[0.4, 0.1, 0.4, 0.1],
[0.1, 0.1, 0.1, 0.7]
]
])
rewards = np.array([
[-1, -100, -1, 1],
[-1, -100, -1, 1],
[-1, -100, -1, 1],
[1, 1, 1, 1]
])
vi = mdptoolbox.mdp.ValueIteration(transitions, rewards, discount=0.5)
vi.setVerbose()
vi.run()
print("Value function:")
print(vi.V)
print("Policy function")
print(vi.policy)
如果我将 的值更改discount为1from 0.5,它工作正常。值迭代不适用于折扣值0.5或任何其他十进制值的原因是什么?
更新:看起来我的奖励矩阵有问题。我无法按照我的意图编写它。因为如果我改变奖励矩阵中的一些值,错误就会消失。
30秒到达战场
相关分类