Multiset
- class torchhd.structures.Multiset(dimensions: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', *, device=None, dtype=None)[source]
- class torchhd.structures.Multiset(input: VSATensor, *, size=0)
Hypervector multiset data structure.
Creates an empty multiset of dim dimensions or from an input tensor.
- Parameters:
dimensions (int) – number of dimensions of the multiset.
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 multiset.
size (int, optional) – the size of the multiset provided as input. Default:
0.
Examples:
>>> M = structures.Multiset(10000) >>> x = functional.random(1, 10000) >>> M = structures.Multiset(x[0], size=1)
- add(input: VSATensor) None[source]
Adds a new hypervector (input) to the multiset.
- Parameters:
input (VSATensor) – Hypervector to add to the multiset.
Examples:
>>> letters = list(string.ascii_lowercase) >>> letters_hv = torchhd.random(len(letters), 10000) >>> M.add(letters_hv[0])
- contains(input: VSATensor) VSATensor[source]
Returns the cosine similarity of the input vector against the multiset.
- Parameters:
input (VSATensor) – Hypervector to compare against the multiset.
Examples:
>>> M.contains(letters_hv[0]) tensor(0.4575)
- classmethod from_ngrams(input: VSATensor, n=3)[source]
Creates a multiset from the ngrams of a set of hypervectors.
See:
ngrams().- Parameters:
input (VSATensor) – Set of hypervectors to convert in a multiset.
n (int, optional) – The size of each \(n\)-gram, \(1 \leq n \leq m\). Default:
3.
Examples:
>>> x = functional.random(5, 3) >>> M = structures.Multiset.from_ngrams(x)
- classmethod from_tensor(input: VSATensor)[source]
Creates a multiset from a set of hypervectors.
See:
multiset().- Parameters:
input (VSATensor) – Set of hypervectors to convert in a multiset.
Examples:
>>> x = functional.random(3, 3) >>> M = structures.Multiset.from_tensor(x)