level
- torchhd.level(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 level correlated hypervectors.
Implements level-hypervectors as an interpolation between random-hypervectors as described in An Extension to Basis-Hypervectors for Learning from Circular Data in Hyperdimensional Computing. The first and last hypervector in the generated set are quasi-orthogonal.
- 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 level 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.level(5, 6, "BSC") tensor([[ True, True, True, True, False, False], [ True, True, True, True, False, False], [False, True, True, True, True, False], [False, True, True, True, True, False], [False, True, True, True, True, False]]) >>> torchhd.level(5, 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.]]) >>> torchhd.level(5, 6, "FHRR") tensor([[-0.996+0.079j, 0.447+0.894j, -0.840-0.541j, -0.999+0.020j, -0.742+0.669j, -0.999+0.042j], [-0.886-0.462j, 0.447+0.894j, -0.840-0.541j, -0.999+0.020j, -0.742+0.669j, -0.886+0.462j], [-0.886-0.462j, 0.447+0.894j, -0.146-0.989j, -0.999+0.020j, -0.350-0.936j, -0.886+0.462j], [-0.886-0.462j, 0.507+0.861j, -0.146-0.989j, -0.999+0.020j, -0.350-0.936j, -0.886+0.462j], [-0.886-0.462j, 0.507+0.861j, -0.146-0.989j, -0.611-0.791j, -0.350-0.936j, -0.886+0.462j]])