BundleSequence

class torchhd.structures.BundleSequence(dimensions: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR'] = 'MAP', *, device=None, dtype=None)[来源]
class torchhd.structures.BundleSequence(input: VSATensor, *, size=0)

基于超向量捆绑的序列数据结构

创建一个具有dim维度的空序列或从输入张量创建。

Parameters:
  • 维度 (整数) – 序列的维度数量。

  • vsa – (VSAOptions, 可选): 指定使用的超向量类型和操作 (默认: "MAP").

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

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

  • 输入 (VSATensor) – 表示序列的张量。

  • size (int, 可选) – 作为输入提供的序列的长度。默认值:0

示例:

>>> S = structures.BundleSequence(10000)

>>> letters = list(string.ascii_lowercase)
>>> letters_hv = torchhd.random(len(letters), 10000)
>>> S = structures.BundleSequence(letters_hv[0], size=1)
__getitem__(index: int) VSATensor[来源]

从给定索引获取近似值。

Parameters:

index (int) – 序列中值的索引。

示例:

>>> S[0]
tensor([ 1., -1.,  1.,  ..., -1.,  1., -1.])
__len__() int[来源]

返回序列的长度。

示例:

>>> len(S)
0
append(input: VSATensor) None[来源]

将输入张量附加到序列的右侧。

Parameters:

输入 (VSATensor) – 要附加到序列的超向量。

示例:

>>> letters = list(string.ascii_lowercase)
>>> letters_hv = torchhd.random(len(letters), 10000)
>>> S.append(letters_hv[0])
appendleft(input: VSATensor) None[来源]

将输入张量附加到序列的左侧。

Parameters:

输入 (VSATensor) – 要附加到序列右侧的超向量。

示例:

>>> S.appendleft(letters_hv[1])
clear() None[来源]

清空序列。

示例:

>>> S.clear()
concat(seq: BundleSequence) BundleSequence[来源]

将当前序列与给定的序列连接起来。

Parameters:

seq (Sequence) – 要与当前序列连接的序列。

示例:

>>> S1 = structures.BundleSequence(dimensions=10000)
>>> S2 = S.concat(S1)
classmethod from_tensor(input: VSATensor)[来源]

从超向量创建序列。

参见:bundle_sequence()

Parameters:

输入 (VSATensor) – 包含形成序列的超向量的张量。

Examples::
>>> letters_hv = torchhd.random(len(letters), 10000)
>>> S = structures.BundleSequence.from_tensor(letters_hv)
pop(input: VSATensor) None[来源]

从序列的右侧弹出输入张量。

Parameters:

input (VSATensor) – 要从序列中弹出的超向量。

示例:

>>> S.pop(letters_hv[0])
popleft(input: VSATensor) None[来源]

从序列的左侧弹出输入张量。

Parameters:

input (VSATensor) – 要从序列左侧弹出的超向量。

示例:

>>> S.popleft(letters_hv[1])
replace(index: int, old: VSATensor, new: VSATensor) None[来源]

用新的超向量值替换给定索引处的旧超向量值。

Parameters:
  • index (int) – 序列中要替换其值的索引。

  • 旧值 (VSATensor) – 旧值超向量。

  • new (VSATensor) – 新的值超向量。

示例:

>>> S.replace(0, letters_hv[0], letters_hv[1])