快捷方式

VDNMixer

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

值分解網路混音器 (Value-Decomposition Network mixer)。

透過求和將智慧體的區域性 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 (str or torch.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 的完整開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源