VDNMixer¶
- class torchrl.modules.VDNMixer(n_agents: int, device: Union[device, str, int])[源代码]¶
值分解网络混合器。
通过将智能体的局部 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 或 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)