dot_similarity

torchhd.dot_similarity(input: VSATensor, others: VSATensor, **kwargs) VSATensor[source]

Dot product between the input vector and each vector in others.

Aliased as torchhd.dot.

Parameters:
  • input (VSATensor) – hypervectors to compare against others

  • others (VSATensor) – hypervectors to compare with

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

  • Others: \((n, d)\) or \((d)\)

  • Output: \((*, n)\) or \((*)\), depends on shape of others

Note

Output dtype for torch.bool is torch.long, for torch.complex64 is torch.float, for torch.complex128 is torch.double, otherwise same as input dtype.

Examples:

>>> x = torchhd.random(3, 6)
>>> x
tensor([[ 1., -1.,  1.,  1.,  1.,  1.],
        [-1., -1.,  1., -1., -1.,  1.],
        [-1.,  1.,  1., -1.,  1.,  1.]])
>>> torchhd.dot_similarity(x, x)
tensor([[6., 0., 0.],
        [0., 6., 2.],
        [0., 2., 6.]])

>>> x = torchhd.random(3, 6, "FHRR")
>>> x
tensor([[-0.123-0.992j,  0.342-0.939j, -0.840-0.542j, -0.999+0.041j, -0.861-0.508j,  0.658-0.752j],
        [-0.754+0.656j,  0.574-0.818j, -0.449+0.893j, -0.705-0.708j,  0.652-0.757j,  0.444-0.895j],
        [ 0.805+0.593j, -0.647-0.762j, -0.192-0.981j, -0.796-0.605j, -0.380-0.924j, -0.556+0.830j]])
>>> torchhd.dot_similarity(x, x)
tensor([[ 6.0000,  1.7658,  1.0767],
        [ 1.7658,  6.0000, -0.3047],
        [ 1.0767, -0.3047,  6.0000]])