[英]PyBrains Q-Learning maze example. State values and the global policy
我正在嘗試PyBrains迷宮示例
我的設置是:
envmatrix = [[...]]
env = Maze(envmatrix, (1, 8))
task = MDPMazeTask(env)
table = ActionValueTable(states_nr, actions_nr)
table.initialize(0.)
learner = Q()
agent = LearningAgent(table, learner)
experiment = Experiment(task, agent)
for i in range(1000):
experiment.doInteractions(N)
agent.learn()
agent.reset()
右下角(1、8)為吸收狀態
我在mdp.py中添加了一個額外的懲罰狀態(1、7):
def getReward(self):
""" compute and return the current reward (i.e. corresponding to the last action performed) """
if self.env.goal == self.env.perseus:
self.env.reset()
reward = 1
elif self.env.perseus == (1,7):
reward = -1000
else:
reward = 0
return reward
現在,我不明白在每次運行1000次運行和200次交互之后,特工認為我的懲罰狀態是好狀態(您可以看到正方形是白色的)
我想在最終運行后查看每個州和政策的值。 我怎么做? 我發現該行table.params.reshape(81,4).max(1).reshape(9,9)
返回一些值,但是我不確定這些值是否對應於值函數的值
現在,我添加了另一個約束-通過在self.initPos = [(1, 1)]
添加self.initPos = [(1, 1)]
來使代理始終從相同的位置開始:(1,1),現在我在每次運行1000次后得到了此行為運行200次互動:
現在哪種方法有意義-機器人試圖從另一側繞過牆壁,從而避開狀態(1、7)
所以,我得到了奇怪的結果,因為代理過去常常從隨機位置開始,其中還包括懲罰狀態。
編輯:
另一點是,如果希望隨機產生代理,請確保它不是在可懲罰狀態下產生
def _freePos(self):
""" produce a list of the free positions. """
res = []
for i, row in enumerate(self.mazeTable):
for j, p in enumerate(row):
if p == False:
if self.punishing_states != None:
if (i, j) not in self.punishing_states:
res.append((i, j))
else:
res.append((i, j))
return res
另外,似乎那table.params.reshape(81,4).max(1).reshape(9,9)
從值函數返回每個狀態的值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.