密度

class torchhd.embeddings.Density(in_features: int, out_features: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR'] = 'MAP', low: float = 0.0, high: float = 1.0, device=None, dtype=None, requires_grad: bool = False, **kwargs)[来源]

根据intRVFL模型将输入数据转换为超向量。

详情请参见Density Encoding Enables Resource-Efficient Randomly Connected Neural Networks

Parameters:
  • in_features (int) – 输入特征向量的维度。

  • out_features (int) – 超向量的维度。

  • vsa – (VSAOptions, 可选): 指定要实例化的超向量类型。默认值: "MAP".

  • low (float, 可选) – 温度计编码所代表的实数范围的下限。默认值:0.0

  • (浮点数, 可选) – 温度计编码所代表的实数范围的上限。默认值:1.0

  • dtype (torch.dtype, 可选) – 返回张量的期望数据类型。默认值:如果 None,则使用 VSATensor 的默认值。

  • device (torch.device, 可选) – 返回张量的期望设备。默认值:如果 None,则使用当前设备作为默认张量类型(参见 torch.set_default_tensor_type())。device 对于 CPU 张量类型将是 CPU,对于 CUDA 张量类型将是当前的 CUDA 设备。

  • requires_grad (bool, 可选) – 如果自动求导应该记录返回张量上的操作。默认值:False

示例:

>>> embed = embeddings.Density(6, 5)
>>> x = torch.randn(3, 6)
>>> x
tensor([[ 0.5430,  1.0740,  0.7250, -0.3410, -0.1318,  1.3188],
        [ 0.4373,  1.2400, -0.2264,  1.2448, -0.2040, -0.7831],
        [ 1.7460, -0.7359, -1.3271,  0.4338, -0.2401,  1.6553]])
>>> embed(x)
MAPTensor([[ 2.,  2., -2., -2.,  0.],
           [ 4.,  0.,  6.,  4.,  0.],
           [ 4., -4., -2., -4., -4.]])
forward(input: Tensor) Tensor[来源]

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

应该由所有子类覆盖。

注意

尽管前向传递的配方需要在此函数内定义,但之后应该调用Module实例而不是这个,因为前者负责运行已注册的钩子,而后者则默默地忽略它们。