dueling network原理和实现

算法原理:
Q ( s , a ; θ , α , β ) = V ( s ; θ , β ) + ( A ( s , a ; θ , α ) − max ⁡ a ′ ∈ ∣ A ∣ A ( s , a ′ ; θ , α ) ) . \begin{gathered}Q(s,a;\theta,\alpha,\beta)=V(s;\theta,\beta)+\left(A(s,a;\theta,\alpha)-\max_{a'\in|\mathcal{A}|}A(s,a';\theta,\alpha)\right).\end{gathered} Q(s,a;θ,α,β)=V(s;θ,β)+(A(s,a;θ,α)aAmaxA(s,a;θ,α)).
注:DuelingNetwork只是改变最优动作价值网络的架构,原本用来训练DQN的策略依然可以使用:

​ 1、优先级经验回放;

​ 2、Double DQN;

​ 3、Multi-step TD;

在这里插入图片描述


代码实现,只需要将原来的DQN的最优动作价值网络修改成Dueling Network的形式:

class DuelingNetwork(nn.Module):
    """QNet.
    Input: feature
    Output: num_act of values
    """

    def __init__(self, dim_state, num_action):
        super().__init__()
        # A分支
        self.a_fc1 = nn.Linear(dim_state, 64)
        self.a_fc2 = nn.Linear(64, 32)
        self.a_fc3 = nn.Linear(32, num_action)
        # V分支
        self.v_fc1 = nn.Linear(dim_state, 64)
        self.v_fc2 = nn.Linear(64, 32)
        self.v_fc3 = nn.Linear(32, 1)

    def forward(self, state):
        # 计算A
        a_x = F.relu(self.a_fc1(state))
        a_x = F.relu(self.a_fc2(a_x))
        a_x = self.a_fc3(a_x)
        # 计算V
        v_x = F.relu(self.v_fc1(state))
        v_x = F.relu(self.v_fc2(v_x))
        v_x = self.v_fc3(v_x)
        # 计算输出
        x = a_x - v_x - a_x.max()
        return x
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KPer_Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值