HashTable
- class torchhd.structures.HashTable(dimensions: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', *, device=None, dtype=None)[source]
- class torchhd.structures.HashTable(input: VSATensor, *, size=0)
Hypervector hash table data structure.
Creates an empty hash table of dim dimensions or a hash table from an input tensor.
- Parameters:
dimensions (int) – number of dimensions of the hash table.
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 hash table.
size (int, optional) – the size of the hash table provided as input. Default:
0.
Examples:
>>> H = structures.HashTable(10000) >>> x = functional.random(3, 10000) >>> M = structures.HashTable(x)
- __getitem__(key: VSATensor) VSATensor[source]
Gets the approximate value from the key in the hash table.
- Parameters:
key (VSATensor) – Hypervector used as key for looking its value.
Examples:
>>> H[letters_hv[0]] tensor([ 1., -1., 1., ..., -1., 1., -1.])
- add(key: VSATensor, value: VSATensor) None[source]
Adds one (key, value) pair to the hash table.
- Parameters:
Examples:
>>> letters = list(string.ascii_lowercase) >>> letters_hv = torchhd.random(len(letters), 10000) >>> values = functional.random(2, 10000) >>> H.add(letters_hv[0], values[0])
- classmethod from_tensors(keys: VSATensor, values: VSATensor)[source]
Creates a hash table from a set of keys and values hypervectors.
See:
hash_table().- Parameters:
- Examples::
>>> letters_hv = torchhd.random(len(letters), 10000) >>> values = torchhd.random(len(letters), 10000) >>> H = structures.HashTable.from_tensors(letters_hv, values)
- get(key: VSATensor) VSATensor[source]
Gets the approximate value from the key in the hash table.
- Parameters:
key (VSATensor) – Hypervector used as key for looking its value.
Examples:
>>> H.get(letters_hv[0]) tensor([ 1., -1., 1., ..., -1., 1., -1.])
- remove(key: VSATensor, value: VSATensor) None[source]
Removes one (key, value) pair from the hash table.
- Parameters:
Examples:
>>> H.remove(letters_hv[0], values[0])