Safe Policy Optimization 复现

文章对比了RCPO、CRPO和CPO在PointGoal1、CarGoal1、Velocity-Walker2d任务上的性能,发现RCPO和CRPO能得出满足约束的解,但存在稳定性问题。CPO虽然奖励最高,但无法得到可行解。针对CRPO的不稳定性,文章提出了降低学习率和自适应调整α的改进方法,提升了训练效率和奖励。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

复现结果

在 PointGoal1、CarGoal1、Velocity-Walker2d 三个任务上测试了 RCPO,CRPO 以及 Safe-Policy-Optimization 中实现的 CPO,PPO-Lag 算法。

CarGoal

在这里插入图片描述

PointGoal

PointGoal1 和 CarGoal1 任务相对比较困难,在探索初期就很容易违反约束。

PPO-Lag 和 TRPO-Lag 都不能得到满足约束的解,故没有在途中画出。

使用 RCPO 将拉格朗日乘子初值设置为 2 之后,可以跑出可行解,但是 reward 不高,且仍然会出现震荡的现象。

使用 CRPO 可以跑出可行解,reward 与 RCPO 持平,后面会对其进行修改。

另外尝试使用 CPO,发现虽然 reward 最高,但是得不到可行解。

Walker2d

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6jjGDce1-1689530625453)(results.assets/wk.png)]

在 Velocity-Walker2d 中使用 ppo-lag 会产生周期性的震荡。原因是 KaTeX parse error: Undefined control sequence: \part at position 7: \frac{\̲p̲a̲r̲t̲ ̲L}{\part\lambda…,而 λ \lambda λ 增大又会使得 EpCosts 减小。如果 λ \lambda λ 更新过快,就会导致这两个过程的时间差较长,从而产生周期较大的波动。

这个任务比较简单,其他的算法差别不大。

对CRPO的改进

在PointGoal1 和 CarGoal1中发现 CRPO 训练过程中不稳定,而且训练到一定程度的时候 reward 难以继续提高。因为这两个任务的约束比较强,即使在没有充分探索的前期就很容易违反约束。CRPO 在违反约束时立即转向,导致很容易被束缚住而探索不到好的策略。同时,cost 负梯度和 reward 梯度的方向一般是相反的,就会导致参数发生震荡。

因此做了两点改进:

  1. 减小学习率。
  2. 在违反约束时参数更新方向不再是单一的减小 cost 的方向,而是 cost 的负梯度 * alpha + reward 的梯度 * (1-alpha)

第 2 点中的 alpha 尝试了固定值(0.7,0.85)以及自适应值(类似 PDO 更新拉格朗日乘子),发现自适应的更新 alpha 效果更好,与改进前相比,前期训练表现提升较快,也能得到满足约束的解,并且 reward 有较大提高。当然,与标准的 CRPO 相比这会导致训练过程中存在违反约束的时间增加。

CarGoal

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zTJMjRj3-1689530625454)(results.assets/cg2.png)]

PointGoal

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vJCGPaD4-1689530625454)(results.assets/pg2.png)]

思考

构造拉格朗日函数:
L ( θ , λ ) = J R π θ − λ ⋅ ( J C π θ − d ) L(\theta, \lambda)=J_R^{\pi_\theta} - \lambda\cdot(J_C^{\pi_\theta}-d) L(θ,λ)=JRπθλ(JCπθd)
原问题等价于如下无约束问题:

max ⁡ θ min ⁡ λ ≥ 0 L ( θ , λ ) \max_\theta \min_{\lambda\geq 0} L(\theta, \lambda) θmaxλ0minL(θ,λ)
其拉格朗日对偶问题是原问题的一个上界:

min ⁡ λ ≥ 0 max ⁡ θ L ( θ , λ ) \min_{\lambda\geq 0}\max_\theta L(\theta, \lambda) λ0minθmaxL(θ,λ)
PDO 以及 RCPO 优化的是对偶问题,用较快速度更新 θ \theta θ,较慢速度更新 λ \lambda λ

而 CRPO 可以看作直接优化原问题:给定一个 θ \theta θ,如果约束都被满足,那么最优的 λ \lambda λ 为 0,此时对 θ \theta θ 求梯度就是 J R π θ J_R^{\pi_\theta} JRπθ θ \theta θ 的梯度;如果有一个约束没有满足,那么对应的 λ \lambda λ 会趋向无穷大,这时对 θ \theta θ 求梯度就是 J C π θ J_C^{\pi_\theta} JCπθ θ \theta θ 的梯度。

由此猜测对于多约束问题,除了论文中的随机挑选一个违反的约束进行优化,可能还可以同时优化所有违反的约束。

局限性

PDO,RCPO 也可以看作是 reward shaping 的方法。虽然不再需要手动调节参数,但是 lambda 初值和学习率设置不当会导致训练难以收敛。如果学习率过高,表现也会周期性波动;如果过低,就很难收敛到合法解。同样,如果 lambda 初值距离最优值太远,也会很难收敛到合法解。

而 CRPO 在训练后期震荡还是比较明显。

### Group Relative Policy Optimization in Machine Learning #### Definition Group Relative Policy Optimization (GRPO) refers to an advanced reinforcement learning technique that aims at optimizing multiple policies simultaneously within a group setting. This approach extends beyond traditional single-agent optimization by considering interactions between different agents or policies during training. The goal is not only to improve individual performance but also to enhance collective behavior through coordinated actions. In GRPO, each agent's policy update takes into account relative performances among all members of the group rather than focusing solely on absolute rewards received individually. By doing so, this method encourages cooperation while still promoting competition when beneficial for overall system efficiency[^1]. #### Implementation Methods To implement GRPO effectively, several key components must be addressed: - **Policy Representation**: Policies should allow flexible adjustments according to feedback from both internal objectives and external comparisons against other group members' achievements. - **Reward Shaping**: Design reward functions carefully to reflect desired behaviors such as collaboration versus rivalry depending upon specific application requirements. - **Learning Algorithm Selection**: Choose appropriate algorithms capable of handling multi-policy scenarios efficiently without compromising convergence properties significantly over time. An example implementation could involve using Proximal Policy Optimization (PPO), where updates are made based partly on direct experiences gathered via interaction with environments alongside indirect information derived from observing peers’ successes or failures[^2]: ```python import numpy as np from stable_baselines3 import PPO def collect_comparison_data(policy_list): """Collects comparison data across given list of policies.""" # Simulate environment interactions here... def train_new_rm_and_policy(current_best_policy, peer_policies): """Trains new ranking model and corresponding improved policy.""" comp_data = collect_comparison_data([current_best_policy] + peer_policies) rm_model.fit(comp_data) ppo_agent = PPO('MlpPolicy', env=env, verbose=0).learn(total_timesteps=int(1e4)) return ppo_agent.policy # Example usage loop iterating steps 2 & 3 mentioned earlier for iteration in range(num_iterations): updated_policy = train_new_rm_and_policy(best_policy_so_far, competing_policies) ``` This code snippet demonstrates how one might iterate continuously between collecting more comparative data about currently optimal strategies and subsequently refining those approaches further through additional rounds of training informed by observed outcomes amongst competitors.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值