multirandsel

torchhd.multirandsel(input: VSATensor, *, p: FloatTensor | None = None, generator: Generator | None = None) VSATensor[source]

Bundling multiple hypervectors by sampling random elements.

Bundles all the input hypervectors together. The resulting hypervector has elements selected at random from the input tensor of hypervectors.

\[\bigoplus_{i=0}^{n-1} V_i\]
Parameters:
  • input (VSATensor) – input hypervector tensor

  • p (FloatTensor, optional) – probability of selecting elements from the input hypervector. Default: uniform.

  • generator (torch.Generator, optional) – a pseudorandom number generator for sampling.

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

  • Probability (p): \((*, n)\)

  • Output: \((*, d)\)

Examples:

>>> x = torchhd.random(4, 6, "FHRR")
>>> x
tensor([[-0.6344+0.7730j, -0.5673+0.8235j,  0.9051-0.4253j,  0.1355-0.9908j, -0.6559-0.7549j,  0.7526-0.6585j],
        [ 0.9136+0.4067j,  0.7351+0.6780j,  0.9999-0.0108j, -0.5853+0.8108j, -0.8442-0.5361j,  0.9487-0.3162j],
        [ 0.6320-0.7750j, -0.9836+0.1806j, -0.6542-0.7563j, -0.8747+0.4846j,  0.4030+0.9152j,  0.1324+0.9912j],
        [ 0.3632+0.9317j, -0.9414+0.3373j,  0.4078-0.9131j,  0.9815-0.1914j,  0.2741+0.9617j,  0.5697+0.8219j]])
>>> torchhd.multirandsel(x)
tensor([ 0.3632+0.9317j, -0.9836+0.1806j, -0.6542-0.7563j,  0.9815-0.1914j, -0.6559-0.7549j,  0.7526-0.6585j])