【问题标题】:DDPG not convergingDDPG 不收敛
【发布时间】:2018-03-12 17:39:43
【问题描述】:

我正在尝试在 tensorflow 中实现深度确定性策略梯度算法,但该策略并没有收敛到任何远程好的东西。我正在测试cartpole 问题。

随着时间的推移,critic loss 减少到 0,actor 梯度也收敛到 0,但奖励没有增加。演员似乎接受了一种“恒定”的政策,将推车推向一个方向,直到剧集失败。我使用 Ornstein-Uhlenbeck 过程添加噪声,sigma 随时间衰减,初始角度是随机的,因此代理可以很好地探索状态空间。

对actor进行梯度上升和梯度下降似乎没有什么区别。一定有什么地方很不对劲,但我不知道如何找到它。

这是顶级演员更新:

            predicted_actions = actor.get_actions(session, replay_states)
            critic_action_gradients = critic.get_action_gradients(
                session, replay_states, predicted_actions
            )
            gradient_magnitude = actor.update_weights(
                session, replay_states, critic_action_gradients
            )
            actor.update_target_network(session)

这是评论家中的get_action_gradients

def get_action_gradients(self, session, states, actions):
    return [
        session.run(self.action_gradients, feed_dict={
            self.nnet_input_state: np.array([state], dtype=np.float32),
            self.nnet_input_action: np.array([action], dtype=np.float32),
        }) for state, action in zip(states, actions)
    ]

self.action_gradients 的位置很简单

    self.action_gradients = tf.gradients(self.output, self.nnet_input_action)

这是演员的update_weights

def update_weights(self, session, replay_states, critic_action_gradients):
    # each row of actor_gradients is multiplied by the corresponding critic gradient
    # then take a column-wise average
    # shape of actor_gradients is len(replay_states) x 6, each column has the
    # shape of the corresponding network weight
    critic_gradients = np.array(critic_action_gradients).reshape((len(replay_states), 1))
    actor_gradients = np.array(self.get_param_gradients(session, replay_states))
    avg_gradients = (actor_gradients * critic_gradients).mean(axis=0)

    new_params = session.run(self.update_weights_ops, feed_dict={
        op: grad for op, grad in zip(self.gradient_placeholders, avg_gradients)
    })

    return sum(np.sum(x) for g in avg_gradients for x in g)

更新权重的图操作是:

    self.network_params = [self.weights_1, self.bias_1,
                           self.weights_2, self.bias_2,
                           self.weights_3, self.bias_3]
    self.param_gradients = tf.gradients(self.output, self.network_params)

    self.gradient_placeholders = []
    self.update_weights_ops = []
    for param in self.network_params:
        gradient_placeholder = tf.placeholder(shape=param.shape, dtype=tf.float32)
        update_op = param.assign_add(self.learning_rate * gradient_placeholder)

        self.gradient_placeholders.append(gradient_placeholder)
        self.update_weights_ops.append(update_op)

【问题讨论】:

  • 你有没有偶然发现?
  • @MoneyBall 不幸的是,我没有:(
  • 嗨,你成功了吗?我正在尝试对类人任务执行相同的操作,如果您愿意,我可以查看您的代码,如果您在在线版本控制工具中有它。帮助你也可以帮助我指出我的错误。
  • 您使用的是 4 个网络吗?演员和评论家的本地和目标?然后使用soft_update,即。 polyak 平均更新目标网络,使其滞后本地网络 new_weights = self.tau * local_weights + (1 - self.tau) *target_weights target_model.set_weights(new_weights) 其中 tau 是介于 0 和 1 之间的数字(更接近 1?)
  • fyi,openai 的 spinup 文档很好地解释了 DDPG

标签: python tensorflow reinforcement-learning


【解决方案1】:

尝试使用 epsilon-greedy 策略进行探索,而不是使用 Ornstein-Uhlenbeck 过程噪声

【讨论】:

  • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
猜你喜欢
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 2017-12-22
  • 1970-01-01
  • 2016-01-19
  • 1970-01-01
  • 2018-04-12
  • 1970-01-01
相关资源
最近更新 更多