Hyper-Dimensional Computing — Binary Vector Algebra¶
High-dimensional binary vector algebra for symbolic reasoning in spiking networks. HDC maps naturally to stochastic computing hardware: bind = XOR gate, bundle = popcount tree, similarity = Hamming distance.
Theory¶
HDC represents symbols as random binary vectors of dimension D (typically D >= 10,000). At high D, random vectors are quasi-orthogonal with high probability: E[d_H(a,b)] = D/2. Three operations form an algebra:
| Operation | Implementation | Property |
|---|---|---|
| Bind (⊗) | XOR | Self-inverse: a ⊗ a = 0, a ⊗ b ⊗ b = a |
| Bundle (⊕) | Majority vote | Preserves similarity to all inputs |
| Permute (ρ) | Cyclic shift | Breaks commutativity for ordered structures |
Components¶
HDCEncoder— Generate random D-dimensional binary vectors and perform algebraic operations.
| Parameter | Default | Meaning |
|---|---|---|
dim |
10000 | Hypervector dimension |
Methods: generate_random_vector(), bind(v1, v2), bundle(vectors), permute(v, shifts).
AssociativeMemory— Clean-up memory via Hamming distance nearest-neighbor lookup. Store labeled vectors, retrieve by similarity. Tolerates up to ~35% bit noise.
Usage¶
from sc_neurocore.hdc import HDCEncoder, AssociativeMemory
import numpy as np
np.random.seed(42)
enc = HDCEncoder(dim=10000)
# Create symbols
country = enc.generate_random_vector()
capital = enc.generate_random_vector()
usa = enc.generate_random_vector()
washington = enc.generate_random_vector()
# Encode: USA_record = bind(country, usa) ⊕ bind(capital, washington)
record = enc.bundle([
enc.bind(country, usa),
enc.bind(capital, washington),
])
# Query: "What is the capital of USA?" → bind(record, capital)
query = enc.bind(record, capital)
# Store in associative memory and retrieve
mem = AssociativeMemory()
mem.store("washington", washington)
mem.store("usa", usa)
print(mem.query(query)) # → "washington"
See Tutorial 4: Hyper-Dimensional Computing.
sc_neurocore.hdc.base
¶
Hyperdimensional computing encoder and associative clean-up memory.
HDCEncoder
dataclass
¶
Hyperdimensional computing encoder.
Dimension D is usually >= 10,000.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
generate_random_vector()
¶
Generate a random D-dimensional binary vector in {0, 1}.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
28 29 30 31 32 | |
bind(v1, v2)
¶
Bind two hypervectors via XOR.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
34 35 36 37 | |
bundle(vectors)
¶
Bundle hypervectors by majority superposition.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
39 40 41 42 43 44 45 46 47 48 49 | |
permute(v, shifts=1)
¶
Permute a hypervector by a cyclic shift.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
51 52 53 54 | |
AssociativeMemory
dataclass
¶
Simple HDC associative clean-up memory.
Stores (key, value) pairs or bare prototypes for nearest-match retrieval.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
store(label, vector)
¶
Store a labelled hypervector in the clean-up memory.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
66 67 68 | |
query(query_vec)
¶
Return the label of the closest stored vector by Hamming distance.
Source code in src/sc_neurocore/hdc/base.py
| Python | |
|---|---|
70 71 72 73 74 75 76 77 78 79 80 81 82 | |