torchhd

This module consists of the basic hypervector generation functions and operations used on hypervectors.

Basis-hypervector sets

empty(num_vectors, dimensions[, vsa])

Creates a set of hypervectors representing empty sets.

identity(num_vectors, dimensions[, vsa])

Creates a set of identity hypervectors.

random(num_vectors, dimensions[, vsa])

Creates a set of random independent hypervectors.

level(num_vectors, dimensions[, vsa, ...])

Creates a set of level correlated hypervectors.

thermometer(num_vectors, dimensions[, vsa, ...])

Creates a thermometer code for given dimensionality.

circular(num_vectors, dimensions[, vsa, ...])

Creates a set of circularly correlated hypervectors.

Operations

bind(input, other)

Binds two hypervectors which produces a hypervector dissimilar to both.

bundle(input, other)

Bundles two hypervectors which produces a hypervector maximally similar to both.

permute(input, *[, shifts])

Permutes hypervector by specified number of shifts.

inverse(input)

Inverse for the binding operation.

negative(input)

Inverse for the bundling operation.

cleanup(input, memory[, threshold])

Gets the most similar hypervector in memory.

randsel(input, other, *[, p, generator])

Bundles two hypervectors by selecting random elements.

multirandsel(input, *[, p, generator])

Bundling multiple hypervectors by sampling random elements.

create_random_permute(dim)

Creates random permutation functions.

resonator(input, estimates, domains)

A step of the resonator network that factorizes the input.

ridge_regression(samples, labels[, alpha])

Compute weights (readout matrix) with ridge regression.

soft_quantize(input)

Applies the hyperbolic tanh function to all elements of the input tensor.

hard_quantize(input)

Applies binary quantization to all elements of the input tensor.

Similarities

cosine_similarity(input, others, **kwargs)

Cosine similarity between the input vector and each vector in others.

dot_similarity(input, others, **kwargs)

Dot product between the input vector and each vector in others.

hamming_similarity(input, others)

Hamming similarity is the number of equal elements between the input vectors and each vector in others.

Encodings

multiset(input)

Multiset of input hypervectors.

multibind(input)

Binding of multiple hypervectors.

bundle_sequence(input)

Bundling-based sequence.

bind_sequence(input)

Binding-based sequence.

hash_table(keys, values)

Hash table from keys-values hypervector pairs.

cross_product(input, other)

Cross product between two sets of hypervectors.

ngrams(input[, n])

Creates a hypervector with the \(n\)-gram statistics of the input.

graph(input, *[, directed])

Graph from node hypervector pairs.

VSA Models

VSATensor

Base class

BSCTensor

Binary Spatter Codes

MAPTensor

Multiply Add Permute

HRRTensor

Holographic Reduced Representation

FHRRTensor

Fourier Holographic Reduced Representation

BSBCTensor

Binary Sparse Block Codes (B-SBC)

VTBTensor

Vector-Derived Transformation Binding

Utilities

ensure_vsa_tensor(data[, vsa, dtype, device])

Converts data into a VSA model tensor.

map_range(input, in_min, in_max, out_min, ...)

Maps the input real value range to an output real value range.

value_to_index(input, in_min, in_max, ...)

Maps the input real value range to an index range.

index_to_value(input, index_length, out_min, ...)

Maps the input index range to a real value range.