首页 > 解决方案 > 如何在 openai-gym、强化学习的 Bipedalwalker-v3 中获得目标 Q 值?

问题描述

我是强化学习的新手,我正在尝试使用Deep Q learning解决BipedalWalker-v3。但是我发现并且我不知道如何添加和乘以,我尝试从LunarLander项目中复制我的代码。env.action_space.sample() = numpy array with 4 elementsrewards(1-done_list)

在月球着陆器的情况下env.action_space.sample() = integer

这是我更新“月球着陆器”模型的方法:

def update_model(self):
        random_sample = random.sample(self.replay_buffer, self.batch_size)
        
        states, actions, rewards, next_states, done_list = self.get_attributes_from_sample(random_sample)
        # How do I fix the below target for BipedalWalker
        targets = rewards + self.gamma * (np.max(self.model.predict_on_batch(next_states), axis=1)) * (1 - done_list)
        
        target_vec = self.model.predict_on_batch(states) # shape = (64, 4)
        indexes = np.array([i for i in range(self.batch_size)])
        target_vec[[indexes], [actions]] = targets

        self.model.fit(states, target_vec, epochs=1, verbose=0)

这在 LunarLander 环境中运行得非常好。

我需要在BiPedalWalker项目中实现这一点。可以在这里找到:链接

然而,即使在 1000 集之后,该模型也没有产生任何好的结果。

这是BipedalWalker的相同方法:

   def update_model(self):
        # replay_buffer size Check
        if len(self.replay_buffer) < self.batch_size or self.counter != 0:
            return

        # Early Stopping
        if np.mean(self.rewards_list[-10:]) > 180:
            return

        # take a random sample:
        random_sample = random.sample(self.replay_buffer, self.batch_size)
        # Extract the attributes from sample
        states, actions, rewards, next_states, done_list = self.get_attributes_from_sample(random_sample)
        targets = np.tile(rewards, (self.num_action_space, 1)).T + np.multiply(np.tile((1 - done_list), (self.action_space.sample().size, 1)).T, np.multiply(self.gamma, self.model.predict_on_batch(next_states)))
        # print(targets.shape) = (64,)
        target_vec = self.model.predict_on_batch(states) # shape = (64, 4)
        indexes = np.array([i for i in range(self.batch_size)])
        target_vec = targets

        self.model.fit(states, target_vec, epochs=1, verbose=0)

标签: pythontensorflowdeep-learningreinforcement-learningopenai-gym

解决方案


使用 DQN 算法解决连续动作空间环境(如 bipedal walker v3)是一个坏主意,因为 DQN 算法依赖于对(状态、动作)的迭代优化过程。我建议更改为另一种算法,例如 TD3、SAC 或 PPO。


推荐阅读