hyperdimensional-computing / torchhd

Torchhd is a Python library for Hyperdimensional Computing and Vector Symbolic Architectures
https://torchhd.readthedocs.io
MIT License
229 stars 24 forks source link

Allow multiple fixed permutation operators #77

Closed rgayler closed 1 year ago

rgayler commented 2 years ago

The current implementation of the permutation operator is shift/rotate. This is only one permutation. There is a shift argument that specifies how far to shift, but all the values of that correspond only to different powers of the one permutation operator.

Some applications require more than one permutation operator. For example, when encoding a ternary tree you might use a different permutation to encode each of the children of each node.

With hypervectors a randomly selected permutation is with exceptionally high probability orthogonal to any other randomly selected permutation. Each permutation is fixed for the life of a VSA circuit, so each random permutation is generated at-initialisation. You can have a generic permutation function that takes a permutation vector (specifying the permutation to be applied) as an argument. For example, see https://rgayler.github.io/VSA_altitude_hold/vsa_basic_operators.html#4_Permute_vector Any VSA circuit generally uses a small number of fixed distinct permutations.

When you use a permutation you often need its inverse, so a function to create the inverse of a given permutation is generally needed (see https://rgayler.github.io/VSA_altitude_hold/vsa_basic_operators.html#42_Generate_inverse_permutation).

In some applications you need low powers of a given permutation. The permutation vectors for these can be precalculated rather than applying the permutation operator multiple times. Calculating the inverse permutation vector is a special case of calculating an arbitrary power of a permutation - so it might be good to create a generalised function for v\calculating powers of permutation vectors.