/BinaryHypervectors.jl

Tools for hyperdimensional computing with binary vectors

Primary LanguageJuliaMIT LicenseMIT

BinaryHypervectors

Stable Dev Build Status Coverage DOI

This is a small Julia package for working with binary hypervectors in the context of hyperdimensional computing. Hyperdimensional computing is an approach to cognitive (neuro-) science and machine learning that uses very large vectors of random numbers to encode and retrieve information.

BinaryHypervectors is specialized for hyperdimensional computing with binary vectors. Binding (associating) vectors is done using bitwise XOR, bundling (combining) vectors is done using majority rule, and permuting is done using circshift. The implementation strives for efficiency and ease of use.

The package defines a simple type BinaryHypervector and the associated algebra: * or bind() for binding, + or bundle() for bundling, and circshift() for simple permutations. There is also a sequence_encoding function for creating correlated hypervectors.

For example, say we want to encode a sequence "A B" into a single hypervector. We first create hypervectors for A and B:

julia> using BinaryHypervectors
julia> A = BinaryHypervector()  # Default size is 2^13
julia> B = BinaryHypervector()

We then create a sequence encoding, which is a list of two correlated hypervectors:

julia> seq = sequence_encoding(2)

Then, we bind A and B to the first and second sequence vectors, which marks them as being in the relevant positions in the sequence:

julia> A1 = A * seq[1]
julia> B2 = B * seq[2]

And finally, we bundle the two sequence-encoded vectors to form a hyperdimensional representation of the sequece:

julia> A1B2 = A1 + B2

We can retrieve, e.g., the second item in the sequence by multiplying by seq[2], and then taking the vector, A or B, that most closely matches A1B2 * seq[2]:

julia> extract = A1B2 * seq[2]
julia> map(x -> hammingsimilarity(extract, x), [A, B])

See, e.g., Kanerva (2009, Cognitive Computing) for more detailed background.