cleanup

torchhd.cleanup(input: VSATensor, memory: VSATensor, threshold=0.0) VSATensor[source]

Gets the most similar hypervector in memory.

If the cosine similarity is less than threshold, raises a KeyError.

Parameters:
  • input (VSATensor) – The hypervector to cleanup.

  • memory (VSATensor) – The hypervectors in memory.

  • threshold (float, optional) – minimal similarity between input and any hypervector in memory. Default: 0.0.

Shapes:
  • Input: \((d)\)

  • Memory: \((n, d)\)

  • Output: \((d)\)

Examples:

>>> x = torchhd.random(4, 6)
>>> x
tensor([[-1.,  1.,  1., -1., -1., -1.],
        [ 1.,  1., -1.,  1., -1.,  1.],
        [-1.,  1., -1., -1.,  1.,  1.],
        [ 1., -1.,  1.,  1.,  1., -1.]])
>>> torchhd.cleanup(x[0], x)
tensor([[-1.,  1.,  1., -1., -1., -1.]])