Circular
- class torchhd.embeddings.Circular(num_embeddings: int, embedding_dim: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', phase: float = 0.0, period: float = 6.283185307179586, randomness: float = 0.0, requires_grad: bool = False, max_norm: float | None = None, norm_type: float = 2.0, scale_grad_by_freq: bool = False, sparse: bool = False, device=None, dtype=None, **kwargs)[source]
Embedding wrapper around
circular().Class inherits from Embedding and supports the same keyword arguments.
- Parameters:
num_embeddings (int) – the number of hypervectors to generate.
embedding_dim (int) – the dimensionality of the hypervectors.
vsa – (
VSAOptions, optional): specifies the hypervector type to be instantiated. Default:"MAP".phase (float, optional) – The zero offset of the real number periodic interval that the circular levels represent. Default:
0.0period (float, optional) – The period of the real number periodic interval that the circular levels represent. Default:
2 * pirandomness (float, optional) – r-value to interpolate between circular-hypervectors at
0.0and random-hypervectors at1.0. Default:0.0.dtype (
torch.dtype, optional) – the desired data type of returned tensor. Default: ifNoneuses default ofVSATensor.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:
>>> emb = embeddings.Circular(4, 6) >>> angle = torch.tensor([0.0, 3.141, 6.282, 9.423]) >>> emb(angle) MAPTensor([[-1., -1., -1., -1., -1., 1.], [-1., -1., 1., 1., -1., -1.], [-1., -1., -1., -1., -1., 1.], [-1., -1., 1., 1., -1., -1.]]) >>> emb = embeddings.Circular(4, 6, "BSC") >>> angle = torch.tensor([0.0, 3.141, 6.282, 9.423]) >>> emb(angle) BSCTensor([[False, True, False, False, True, True], [False, False, False, False, False, True], [False, True, False, False, True, True], [False, False, False, False, False, True]])
- forward(input: Tensor) Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.