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)