VDNMixer¶
- class torchrl.modules.VDNMixer(n_agents: int, device: Union[device, str, int])[來源]¶
Value-Decomposition Network 混合器。
透過將代理的本地 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)