快捷方式

VDNMixer

class torchrl.modules.VDNMixer(n_agents: int, device: Union[device, str, int])[source]

价值分解网络混合器。

将代理的局部 Q 值通过求和的方式混合成一个全局 Q 值。出自论文 https://arxiv.org/abs/1706.05296

它将每个代理选择动作的局部值(形状为 (*B, self.n_agents, 1))转换为一个全局值(形状为 (*B, 1))。与 torchrl.objectives.QMixerLoss 一起使用。示例请参见 examples/multiagent/qmix_vdn.py

参数:
  • n_agents (int) – 代理数量。

  • device (strtorch.Device) – 网络使用的 torch 设备。

示例

>>> import torch
>>> from tensordict import TensorDict
>>> from tensordict.nn import TensorDictModule
>>> from torchrl.modules.models.multiagent import VDNMixer
>>> n_agents = 4
>>> vdn = TensorDictModule(
...     module=VDNMixer(
...         n_agents=n_agents,
...         device="cpu",
...     ),
...     in_keys=[("agents","chosen_action_value")],
...     out_keys=["chosen_action_value"],
... )
>>> td = TensorDict({"agents": TensorDict({"chosen_action_value": torch.zeros(32, n_agents, 1)}, [32, n_agents])}, [32])
>>> td
TensorDict(
    fields={
        agents: TensorDict(
            fields={
                chosen_action_value: Tensor(shape=torch.Size([32, 4, 1]), device=cpu, dtype=torch.float32, is_shared=False)},
            batch_size=torch.Size([32, 4]),
            device=None,
            is_shared=False)},
    batch_size=torch.Size([32]),
    device=None,
    is_shared=False)
>>> vdn(td)
TensorDict(
    fields={
        agents: TensorDict(
            fields={
                chosen_action_value: Tensor(shape=torch.Size([32, 4, 1]), device=cpu, dtype=torch.float32, is_shared=False)},
            batch_size=torch.Size([32, 4]),
            device=None,
            is_shared=False),
        chosen_action_value: Tensor(shape=torch.Size([32, 1]), device=cpu, dtype=torch.float32, is_shared=False)},
    batch_size=torch.Size([32]),
    device=None,
    is_shared=False)
mix(chosen_action_value: Tensor, state: Tensor)[source]

混合器的前向传播。

参数:

chosen_action_value – 形状为 [*B, n_agents] 的张量

返回:

形状为 [*B] 的张量

返回类型:

chosen_action_value

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源