Hopfield
- class torchhd.memory.Hopfield(vector_dim: int, kappa: int | None = None, dtype=None, device=None, requires_grad=False)[source]
-
- Parameters:
vector_dim (int) – The dimensionality of the vectors in the memory.
kappa (int, optional) – The maximum count for each memory cell, values are clipped between [-kappa, kappa]. Default: no clipping.
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.
- Shapes:
Memory: \((d, d)\)
- Examples::
>>> items = torchhd.random(6, 512) >>> hopfield = torchhd.memory.Hopfield(512) >>> hopfield.write(items) >>> read = hopfield.read(items).sign() >>> torchhd.cosine_similarity(read, items) tensor([[ 1.0000, 0.0156, -0.0039, -0.0742, 0.0000, -0.0195], [ 0.0156, 1.0000, -0.0352, -0.0586, 0.0000, -0.0039], [-0.0039, -0.0352, 1.0000, 0.0156, 0.0820, -0.0234], [-0.0742, -0.0586, 0.0156, 1.0000, -0.0039, 0.0000], [ 0.0000, 0.0000, 0.0820, -0.0039, 1.0000, 0.0195], [-0.0195, -0.0039, -0.0234, 0.0000, 0.0195, 1.0000]])