python - 如何在 openai-gym、强化学习的 Bipedalwalker-v3 中获得目标 Q 值?
问题描述
我是强化学习的新手,我正在尝试使用Deep Q learning解决BipedalWalker-v3。但是我发现并且我不知道如何添加和乘以,我尝试从LunarLander项目中复制我的代码。env.action_space.sample() = numpy array with 4 elements
rewards
(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)
解决方案
使用 DQN 算法解决连续动作空间环境(如 bipedal walker v3)是一个坏主意,因为 DQN 算法依赖于对(状态、动作)的迭代优化过程。我建议更改为另一种算法,例如 TD3、SAC 或 PPO。
推荐阅读
- textures - GPU上线性3D纹理插值的数值精度(OpenCL)
- java - 使用 Cassandra 的 Java 驱动程序的多租户
- python - Python/Pandas:希望数据帧索引中的唯一日期时间到一天中的不同时间
- php - 如何修复 apachetl 找不到 apache 实例并停止服务器?
- sharepoint - 如何在 SharePoint Online 中自定义 SharePoint Designer 工作流任务表单?
- visual-studio - Visual Studio 2012 TFS 用云中的最新版本替换本地版本
- swift - 为什么 timeIntervalSince1970 没有出现在 Xcode 中?
- google-apps-script - 如何从谷歌文档运行谷歌脚本?
- azure - 无法删除 Kubernetes 服务 - Azure
- python - 使用 Python3.7 的 Flask-MySQLdb 问题