【问题标题】:PyBrain Reinforcement Learning - Maze and GraphPyBrain 强化学习 - 迷宫和图形
【发布时间】:2012-08-16 02:47:26
【问题描述】:

我试图在 PyBrain 中实现类似于迷宫问题的东西。但是,它更类似于带有紧急出口的房间,您可以将代理人留在其中一个房间中以找到出口。 要将其转换为计算机方法,可以使用带有权重的双向图来显示房间之间的路径。

我试图实现一个新环境,但我有点迷失了应该是什么。 比如基于抽象环境类我想过这个:

#!/usr/bin/python2.7

class RoomEnv(Environment):
    # number of action values acceptable by the environment
    # Two events: go forward and go back through the door (but, how we know what room is connect to another?)
    indim = 2
    # Maybe a matrix where 0 is no connection and 1 is a connection(?)
    #            A,B,C,D,E,F
    #indim = array([[0,0,0,0,0,0],  # A
                    [0,0,0,0,0,1],  # B
                    [0,0,0,0,0,0],  # C
                    [0,0,0,0,0,0],  # D
                    [0,0,0,0,0,1],  # E
                    [0,0,0,0,0,1],  # F
                  ])

    # the number of sensors is the number of the rooms
    outdim = 6

    def getSensors(self):
        # Initial state:
        # Could be any room, maybe something random(?)

    def performAction(self, action):
        # We should look at all the states possible to learn what are the best option to go to the outside state.
        # Maybe a for loop that goes through all the paths and use some weight to know where is the best option?

        print "Action performed: ", action

    def reset(self):
        #Most environments will implement this optional method that allows for reinitialization. 

此致,

【问题讨论】:

    标签: python-2.7 reinforcement-learning pybrain


    【解决方案1】:

    在pybrain中,您可以将房间定义为一个数组,然后将结构传递给迷宫以创建一个新环境。例如:

    structure = array([[1, 1, 1, 1, 1, 1, 1, 1, 1],
                       [1, 0, 0, 1, 0, 0, 0, 0, 1],
                       [1, 0, 0, 1, 0, 0, 1, 0, 1],
                       [1, 0, 0, 1, 0, 0, 1, 0, 1],
                       [1, 0, 0, 1, 0, 1, 1, 0, 1],
                       [1, 0, 0, 0, 0, 0, 1, 0, 1],
                       [1, 1, 1, 1, 1, 1, 1, 0, 1],
                       [1, 0, 0, 0, 0, 0, 0, 0, 1],
                       [1, 1, 1, 1, 1, 1, 1, 1, 1]])
    
    # defining the environment
    environment = Maze(structure, (7, 7))
    

    在上面的示例中,1 表示墙壁,0 表示代理可以行走的网格。所以你可以修改结构来制作你自己的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 2015-02-03
      • 2011-02-14
      • 2018-11-05
      • 2016-10-24
      • 2013-12-06
      • 1970-01-01
      相关资源
      最近更新 更多