Thermometer
- class torchhd.embeddings.Thermometer(num_embeddings: int, embedding_dim: int, vsa: Literal['BSC', 'MAP', 'HRR', 'FHRR', 'BSBC', 'VTB', 'MCR', 'CGR'] = 'MAP', low: float = 0.0, high: float = 1.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
thermometer().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".low (float, optional) – The lower bound of the real number range that the levels represent. Default:
0.0high (float, optional) – The upper bound of the real number range that the levels represent. Default:
1.0dtype (
torch.dtype, optional) – the desired data type of returned tensor. Default: ifNoneuses default of 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.
Values outside the interval between low and high are clipped to the closed bound.
Examples:
>>> emb = embeddings.Thermometer(4, 6) >>> x = torch.rand(4) >>> x tensor([0.5295, 0.0618, 0.0675, 0.1750]) >>> emb(x) 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.Thermometer(4, 6, "FHRR") >>> x = torch.rand(4) >>> x tensor([0.2668, 0.7668, 0.8083, 0.6247]) >>> emb(x) FHRRTensor([[ 1.+0.j, 1.+0.j, -1.+0.j, -1.+0.j, -1.+0.j, -1.+0.j], [ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, -1.+0.j, -1.+0.j], [ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, -1.+0.j, -1.+0.j], [ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, -1.+0.j, -1.+0.j]])
- 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.