快捷方式

DdpgMlpQNet

class torchrl.modules.DdpgMlpQNet(mlp_net_kwargs_net1: dict | None = None, mlp_net_kwargs_net2: dict | None = None, device: DEVICE_TYPING | None = None)[source]

DDPG Q 值 MLP 类。

在“CONTINUOUS CONTROL WITH DEEP REINFORCEMENT LEARNING”中提出,https://arxiv.org/pdf/1509.02971.pdf

DDPG Q 值网络接收观察值和动作作为输入,并从中返回一个标量。由于动作比观察值集成得晚,因此创建了两个网络。

参数:
  • mlp_net_kwargs_net1 (dict, 可选) –

    MLP 的 kwargs。默认为

    >>> {
    ...     'in_features': None,
    ...     'out_features': 400,
    ...     'depth': 0,
    ...     'num_cells': [],
    ...     'activation_class': nn.ELU,
    ...     'bias_last_layer': True,
    ...     'activate_last_layer': True,
    ...     }
    

  • mlp_net_kwargs_net2

    默认为

    >>> {
    ...     'in_features': None,
    ...     'out_features': 1,
    ...     'depth': 1,
    ...     'num_cells': [300, ],
    ...     'activation_class': nn.ELU,
    ...     'bias_last_layer': True,
    ... }
    

  • device (torch.device, 可选) – 创建模块的设备。

示例

>>> import torch
>>> from torchrl.modules import DdpgMlpQNet
>>> net = DdpgMlpQNet()
>>> print(net)
DdpgMlpQNet(
  (mlp1): MLP(
    (0): LazyLinear(in_features=0, out_features=400, bias=True)
    (1): ELU(alpha=1.0)
  )
  (mlp2): MLP(
    (0): LazyLinear(in_features=0, out_features=300, bias=True)
    (1): ELU(alpha=1.0)
    (2): Linear(in_features=300, out_features=1, bias=True)
  )
)
>>> obs = torch.zeros(1, 32)
>>> action = torch.zeros(1, 4)
>>> value = net(obs, action)
>>> print(value.shape)
torch.Size([1, 1])
forward(observation: Tensor, action: Tensor) Tensor[source]

定义每次调用时执行的计算。

应由所有子类覆盖。

注意

虽然前向传播 (forward pass) 的实现需要在本函数内定义,但之后应该调用 Module 实例而非直接调用此函数,因为前者会负责运行已注册的钩子 (hooks),而后者则会默默忽略它们。


© 版权所有 2022, Meta。

使用 Sphinx 构建,主题由 Read the Docs 提供。

文档

获取 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得问题解答

查看资源