快捷方式

tensordict.nn.distributions.NormalParamExtractor

class tensordict.nn.distributions.NormalParamExtractor(scale_mapping: str = 'biased_softplus_1.0', scale_lb: Number = 0.0001)

一個非引數化的 nn.Module,它將輸入拆分為均值和標準差引數。

使用指定的 scale_mapping 將標準差引數對映到正值。

引數:
  • scale_mapping (str, optional) – 用於標準差的正向對映函式。預設值 = "biased_softplus_1.0" (即帶有偏差的 softplus 對映,使得 fn(0.0) = 1.0) 可選值: "softplus", "exp", "relu", "biased_softplus_1""none" (無對映)。更多詳情請參見 mappings()

  • scale_lb (Number, optional) – 方差可以取到的最小值。預設值為 1e-4。

示例

>>> import torch
>>> from tensordict.nn.distributions import NormalParamExtractor
>>> from torch import nn
>>> module = nn.Linear(3, 4)
>>> normal_params = NormalParamExtractor()
>>> tensor = torch.randn(3)
>>> loc, scale = normal_params(module(tensor))
>>> print(loc.shape, scale.shape)
torch.Size([2]) torch.Size([2])
>>> assert (scale > 0).all()
>>> # with modules that return more than one tensor
>>> module = nn.LSTM(3, 4)
>>> tensor = torch.randn(4, 2, 3)
>>> loc, scale, others = normal_params(*module(tensor))
>>> print(loc.shape, scale.shape)
torch.Size([4, 2, 2]) torch.Size([4, 2, 2])
>>> assert (scale > 0).all()

文件

訪問全面的 PyTorch 開發者文件

檢視文件

教程

為初學者和高階開發者提供深入的教程

檢視教程

資源

查詢開發資源並讓您的問題得到解答

檢視資源