快捷方式

DdpgMlpActor

class torchrl.modules.DdpgMlpActor(action_dim: int, mlp_net_kwargs: dict | None = None, device: DEVICE_TYPING | None = None)[source]

DDPG Actor 類。

出自論文“CONTINUOUS CONTROL WITH DEEP REINFORCEMENT LEARNING”,https://arxiv.org/pdf/1509.02971.pdf

DDPG Actor 接收觀察向量作為輸入,並從中返回一個動作。它經過訓練以最大化 DDPG Q 值網路返回的值。

引數:
  • action_dim (int) – 動作向量的長度

  • mlp_net_kwargs (dict, optional) –

    MLP 的 kwargs。預設為

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

  • device (torch.device, optional) – 建立模組的裝置。

示例

>>> import torch
>>> from torchrl.modules import DdpgMlpActor
>>> actor = DdpgMlpActor(action_dim=4)
>>> print(actor)
DdpgMlpActor(
  (mlp): MLP(
    (0): LazyLinear(in_features=0, out_features=400, bias=True)
    (1): ELU(alpha=1.0)
    (2): Linear(in_features=400, out_features=300, bias=True)
    (3): ELU(alpha=1.0)
    (4): Linear(in_features=300, out_features=4, bias=True)
  )
)
>>> obs = torch.zeros(10, 6)
>>> action = actor(obs)
>>> print(action.shape)
torch.Size([10, 4])
forward(observation: Tensor) Tensor[source]

定義每次呼叫時執行的計算。

應由所有子類重寫。

注意

雖然 forward pass 的實現需要在該函式內定義,但之後應該呼叫 Module 例項而不是此函式本身,因為前者會處理註冊的鉤子,而後者則會默默忽略它們。

文件

訪問 PyTorch 的完整開發者文件

檢視文件

教程

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

檢視教程

資源

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

檢視資源