def initialise(self, grid):
     """ Called at the beginning of an episode. Use it to construct
     the initial state.
     """
     # Reset the total reward for the episode
     self.total_reward = 0
     cv2.imshow("Enduro", self._image)
     cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #2
0
    def sense(self, grid):
        """ Constructs the next state from sensory signals.

        gird -- 2-dimensional numpy array containing the latest grid
                representation of the environment
        """
        # Visualise the environment grid
        cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #3
0
    def sense(self, grid):
        """ Constructs the next state from sensory signals.

        gird -- 2-dimensional numpy array containing the latest grid
                representation of the environment
        """
        # Visualise the environment grid
        cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #4
0
    def initialise(self, grid):
        """ Called at the beginning of an episode. Use it to construct
        the initial state.
        """
        # Reset the total reward for the episode
        self.total_reward = 0

        cv2.imshow("Enduro", self._image)
        cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #5
0
ファイル: q_agent.py プロジェクト: DukeEnglish/RL
 def sense(self, grid):
     self.s_ = "xxxxxxxxxx"
     i = 0
     for i in range(1, 9):
         if grid[0][i] == 2:
             i = i
             break
     self.s_ = str(i) + self.s_
     for j in range(0, 10):
         for k in range(0, 8):
             if grid[k][j] == 1:
                 self.s_ = self.s_[:j] + str(k) + self.s_[j + 1:]
     cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #6
0
    def sense(self, grid):
        """ Constructs the next state from sensory signals.

        gird -- 2-dimensional numpy array containing the latest grid
                representation of the environment
        """
        # Visualise the environment grid
        print(grid)
        # pos_i = grid[1].index(2)
        print("----------------------")
        print(list(grid[0]).index(2))
        print("----------------------")
        cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #7
0
ファイル: q_agent.py プロジェクト: hakobtam/q-learning
    def initialise(self, grid):
        """ Called at the beginning of an episode
        """
        self.total_reward = 0
        self.prev_state = None
        self.curr_state = None
        self.sense(grid)
        self.last_reward = None
        self.last_action = None

        if not self.learning:
            cv2.imshow("Enduro", self._image)
            cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
            with open('policy.p', 'rb') as handle:
                self.policy = pickle.load(handle)
コード例 #8
0
ファイル: q_agent.py プロジェクト: Digas29/RL-CW1
    def sense(self, grid):
        """ Constructs the next state from sensory signals.

        grid -- 2-dimensional numpy array containing the latest grid
                representation of the environment
        """

        index = searchState(self.history["states"], grid[:self.lookahead])

        if (index == -1):
            self.history["states"].append(grid[:self.lookahead])
            self.history["Q"].append(np.zeros(len(self.getActionsSet())))
            self.next_state = len(self.history["Q"]) - 1
        else:
            self.next_state = index

        # Visualise the environment grid
        cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #9
0
ファイル: q_agent2.py プロジェクト: DukeEnglish/RL
    def sense(self, grid):
        """ Constructs the next state from sensory signals.

        gird -- 2-dimensional numpy array containing the latest grid
                representation of the environment
        """
        # Visualise the environment grid
        # m=np.where(grid==2)
        # n1=m[0]
        # n2=m[1]
        # p1=n1[0]
        # p2=n2[0]
        # index_agent=np.where(grid==2)
        # index_cars=np.where(grid[:8,:]==1)
        #self.next_state=unicode(grid)
        # self.next_state=grid.flatten()
        # self.next_state=np.array2string(self.next_state)
        #self.next_state=str(grid[0:2,:])
        #self.check_ifstate_exist(ob_)
        cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #10
0
ファイル: q_agent.py プロジェクト: hakobtam/q-learning
    def sense(self, grid):
        """ Constructs the next state from sensory signals.

        gird -- 2-dimensional numpy array containing the latest grid
                representation of the environment
        """
        self.prev_state = self.curr_state

        position2 = np.where(grid == 2)
        x2 = position2[1][0]
        position1 = np.where(grid == 1)
        x1_1 = None
        y1_1 = None
        x1_2 = None
        y1_2 = None
        dist = None

        for x, y in zip(position1[1], position1[0]):
            if (dist is None) or abs(x - x2) + y < dist:
                x1_1 = x
                y1_1 = y
                dist = max(abs(x - x2) - 1, 0) + y

        x1_1 = -1 if x1_1 is None else -1 if dist > 9 or abs(x1_1 -
                                                             x2) > 2 else x1_1
        dist = None
        for x, y in zip(position1[1], position1[0]):
            if (x != x1_1 or y != y1_1) and ((dist is None)
                                             or abs(x - x2) + y < dist):
                x1_2 = x
                y1_2 = y
                dist = max(abs(x - x2) - 1, 0) + y
        x1_2 = -1 if x1_2 is None else -1 if dist > 9 or abs(x1_2 -
                                                             x2) > 2 else x1_2
        a = 100 if x1_1 == -1 else x2 - x1_1
        b = 100 if x1_2 == -1 else x2 - x1_2
        self.curr_state = (a, b, x2 >= 7, x2 <= 2)

        if not self.learning:
            # Visualise the environment grid
            cv2.imshow("Environment Grid", EnvironmentState.draw(grid))
コード例 #11
0
    def sense(self, grid):
        self.next_state = self.buildState(grid)

        # Visualise the environment grid
        cv2.imshow("Environment Grid", EnvironmentState.draw(grid))