random

torchhd.random(num_vectors: int, dimensions: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', **kwargs) VSATensor[source]

Creates a set of random independent hypervectors.

The resulting hypervectors are sampled uniformly at random from the dimensions-dimensional hyperspace.

Parameters:
  • num_vectors (int) – the number of hypervectors to generate.

  • dimensions (int) – the dimensionality of the hypervectors.

  • vsa – (VSAOptions, optional): specifies the hypervector type to be instantiated. Default: "MAP".

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

  • dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None depends on VSATensor.

  • device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

Examples:

>>> torchhd.random(3, 6, "BSC")
tensor([[ True,  True,  True,  True,  True,  True],
        [False,  True, False, False,  True,  True],
        [ True,  True, False, False,  True,  True]])

>>> torchhd.random(3, 6, "MAP")
tensor([[ 1.,  1., -1.,  1., -1.,  1.],
        [ 1., -1.,  1., -1., -1., -1.],
        [ 1., -1.,  1.,  1.,  1., -1.]])

>>> torchhd.random(3, 6, "FHRR")
tensor([[-0.830-0.557j, -0.411+0.911j,  0.980-0.197j, -0.202+0.979j, -0.792+0.609j, -0.932-0.360j],
        [-0.977-0.212j,  0.191-0.981j,  0.340-0.940j,  0.902-0.431j,  0.141+0.990j, -0.661+0.749j],
        [-0.690+0.723j,  0.981-0.190j,  0.971+0.236j, -0.356-0.934j,  0.788-0.615j,  0.360-0.932j]])