BindSequence
- class torchhd.structures.BindSequence(dimensions: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', *, device=None, dtype=None)[source]
- class torchhd.structures.BindSequence(input: VSATensor, *, size=0)
Hypervector binding-based sequence data structure.
Creates an empty sequence of dim dimensions or from an input tensor.
- Parameters:
dimensions (int) – number of dimensions of the sequence.
vsa – (
VSAOptions, optional): specifies the hypervector type and operations used (Default:"MAP").dtype (
torch.dtype, optional) – the desired data type of returned tensor. Default: ifNone, uses a global default (seetorch.set_default_tensor_type()).device (
torch.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (see torch.set_default_tensor_type()).devicewill be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.input (VSATensor) – tensor representing a binding-based sequence.
size (int, optional) – the length of the sequence provided as input. Default:
0.
Examples:
>>> DS = structures.BindSequence(10000)
- append(input: VSATensor) None[source]
Appends the input tensor to the right of the sequence.
- Parameters:
input (VSATensor) – Hypervector to append to the sequence.
Examples:
>>> letters = list(string.ascii_lowercase) >>> letters_hv = torchhd.random(len(letters), 10000) >>> DS.append(letters_hv[0])
- appendleft(input: VSATensor) None[source]
Appends the input tensor to the left of the sequence.
- Parameters:
input (VSATensor) – Hypervector to append to the right of the sequence.
Examples:
>>> DS.appendleft(letters_hv[1])
- classmethod from_tensor(input: VSATensor)[source]
Creates a sequence from tensor.
See:
bind_sequence().- Parameters:
input (VSATensor) – Tensor containing hypervectors that form the sequence.
- Examples::
>>> letters_hv = torchhd.random(len(letters), 10000) >>> DS = structures.BindSequence.from_tensor(letters_hv)
- pop(input: VSATensor) None[source]
Pops the input tensor from the right of the sequence.
- Parameters:
input (VSATensor) – Hypervector to pop from the sequence.
Examples:
>>> DS.pop(letters_hv[0])
- popleft(input: VSATensor) None[source]
Pops the input tensor from the left of the sequence.
- Parameters:
input (VSATensor) – Hypervector to pop left from the sequence.
Examples:
>>> DS.popleft(letters_hv[1])