circular
- torchhd.circular(num_vectors: int, dimensions: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', *, randomness: float = 0.0, requires_grad=False, **kwargs) VSATensor[source]
Creates a set of circularly correlated hypervectors.
Implements circular-hypervectors based on level-hypervectors as described in An Extension to Basis-Hypervectors for Learning from Circular Data in Hyperdimensional Computing. Any hypervector is quasi-orthogonal to the hypervector opposite site of the circle.
Note
Circular hypervectors cannot be created directly with Holographic Reduced Representations (HRR) because of imprecisions inherent to HRR. One way around this is to use FHRR for the creation of circular hypervectors and then transform them to HRR vectors. Example:
>>> hv = torchhd.circular(10, 6, "FHRR") >>> hv = torch.real(torch.fft.ifft(hv)).as_subclass("HRR")
- 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".randomness (float, optional) – r-value to interpolate between circular at
0.0and random-hypervectors at1.0. Default:0.0.generator (
torch.Generator, optional) – a pseudorandom number generator for sampling.dtype (
torch.dtype, optional) – the desired data type of returned tensor. Default: ifNonedepends on VSATensor.device (
torch.device, optional) – the desired device of returned tensor. Default: ifNone, uses the current device for the default tensor type (see torch.set_default_tensor_type()).devicewill 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.circular(10, 6, "BSC") tensor([[False, False, True, False, True, True], [False, False, True, False, True, True], [False, False, True, False, True, True], [False, False, True, True, True, True], [ True, False, True, True, True, True], [ True, False, True, True, True, True], [ True, False, True, True, True, True], [ True, False, True, True, True, True], [ True, False, True, False, True, True], [False, False, True, False, True, True]]) >>> torchhd.circular(10, 6, "MAP") 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.], [-1., -1., -1., 1., -1., 1.], [-1., -1., 1., 1., -1., 1.], [-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.circular(10, 6, "FHRR") tensor([[-0.887-0.460j, -0.906+0.421j, -0.727-0.686j, -0.271+0.962j, -0.387+0.921j, -0.895-0.445j], [-0.887-0.460j, -0.906+0.421j, -0.727-0.686j, -0.947+0.319j, -0.387+0.921j, -0.895-0.445j], [-0.887-0.460j, -0.906+0.421j, -0.828+0.560j, -0.947+0.319j, -0.387+0.921j, -0.895-0.445j], [-0.887-0.460j, -0.906+0.421j, -0.828+0.560j, -0.947+0.319j, -0.387+0.921j, -0.895-0.445j], [ 0.983-0.183j, 0.732+0.680j, -0.828+0.560j, -0.947+0.319j, -0.387+0.921j, -0.895-0.445j], [ 0.983-0.183j, 0.732+0.680j, -0.828+0.560j, -0.947+0.319j, -0.705-0.709j, 0.562-0.827j], [ 0.983-0.183j, 0.732+0.680j, -0.828+0.560j, -0.271+0.962j, -0.705-0.709j, 0.562-0.827j], [ 0.983-0.183j, 0.732+0.680j, -0.727-0.686j, -0.271+0.962j, -0.705-0.709j, 0.562-0.827j], [ 0.983-0.183j, 0.732+0.680j, -0.727-0.686j, -0.271+0.962j, -0.705-0.709j, 0.562-0.827j], [-0.887-0.460j, -0.906+0.421j, -0.727-0.686j, -0.271+0.962j, -0.705-0.709j, 0.562-0.827j]])