Memory
- class torchhd.structures.Memory(threshold=0.5)[source]
Associative memory of hypervector keys and any value.
Creates a memory object.
- Parameters:
threshold (float, optional) – minimal similarity between input and any hypervector in memory. Default:
0.0.
Examples:
>>> memory = structures.Memory()
- __delitem__(key: VSATensor) None[source]
Delete the (key, value) pair from an approximate key.
- Parameters:
key (VSATensor) – Hypervector key used for item lookup.
Examples:
>>> del memory[letters_hv[0]] >>> memory[letters_hv[0]] Exception: No elements in memory
- __getitem__(key: VSATensor) Tuple[VSATensor, Any][source]
Get the (key, value) pair from an approximate key.
- Parameters:
key (VSATensor) – Hypervector key used for item lookup.
Examples:
>>> memory[letters_hv[0]] (tensor([-1., 1., 1., ..., 1., 1., -1.]), 'a')
- __setitem__(key: VSATensor, value: Any) None[source]
Set the value of an (key, value) pair from an approximate key.
- Parameters:
key (VSATensor) – Hypervector key used for item lookup.
Examples:
>>> memory[letters_hv[0]] = letters[1] >>> memory[letters_hv[0]] (tensor([-1., 1., 1., ..., 1., 1., -1.]), 'b')
- add(key: VSATensor, value: Any) None[source]
Adds one (key, value) pair to memory.
- Parameters:
key (VSATensor) – Hypervector used as key for adding the key-value pair.
value (Any) – Value to be added to the memory.
Examples:
>>> letters = list(string.ascii_lowercase) >>> letters_hv = torchhd.random(len(letters), 10000) >>> memory.add(letters_hv[0], letters[0])