How to Choose the Right Encoding
PyHDC provides 15 encoding classes. The decision tree and notes below narrow the choice for most use cases.
Quick decision guide
Start here and follow the branches:
Need GPU / PyTorch integration? → all encodings support both backends
Need binary output (1-bit elements)?
Need complex / phase-based values? →
FHRROtherwise (continuous float vectors)?
General purpose →
MAP_C(best default)Normalized bundling theory →
HRRFixed-width integers →
MAP_IorMAP_I_Bits
Full comparison table
Encoding |
Element type |
Default dtype |
Binding |
Bundling |
Similarity |
Unbind |
Notes |
|---|---|---|---|---|---|---|---|
|
float [-1,1] |
float32 |
ElementMultiply |
Add + cut |
Cosine |
Yes |
Best all-round default |
|
int {-1,1} |
int32 |
ElementMultiply |
Add + cut |
Cosine |
Yes |
Integer; needs bit generator |
|
int (custom width) |
int32 |
ElementMultiply |
Add (clipped) |
Cosine |
Yes |
|
|
binary {0,1} |
int8 |
ElementMultiply |
Add (clipped) |
Cosine |
Yes |
Binary MAP |
|
float (normal) |
float32 |
CircularConv |
Add + normalise |
Cosine |
Yes |
Theoretically clean |
|
float (normal) |
float32 |
CircularConv |
Add (no norm) |
Cosine |
Yes |
Faster than HRR |
|
float (normal) |
float32 |
CircularConv |
Add / √M |
Cosine |
Yes |
Constant-norm bundles |
|
angle [0, 2π] |
float32 |
AngleAdd |
AngleAdd |
AngleDist |
Yes |
Phase/periodic signals |
|
float (normal) |
float32 |
VDTransform |
Add + normalise |
Cosine |
Yes |
Matrix derived from key |
|
float (normal) |
float32 |
MatrixMult |
Add + normalise |
Cosine |
Yes (+ metadata) |
Random matrix; save |
|
binary {0,1} |
int8 |
XOR |
Majority vote |
Hamming |
Yes (exact) |
Dense binary; XOR is exact inverse |
|
sparse {0,1} |
int8 |
CDThinning |
OR |
Overlap |
No |
Context-dependent thinning |
|
sparse {0,1} |
int8 |
CircShift |
OR |
Overlap |
Yes |
Shift-based; good for sequences |
|
sparse segmented |
int8 |
SegShift |
OR |
Overlap |
Yes |
Per-segment shift |
|
sparse {0,1} |
int8 |
CircShift |
OR + thin |
Overlap |
Yes |
Best sparse default (v1.1.0+) |
Side-by-side example
The encoding API is identical across families; only the constructor call changes:
import pyhdc
for EncClass in [pyhdc.MAP_C, pyhdc.HRR, pyhdc.BSC, pyhdc.BSDC_THIN]:
enc = EncClass(dimension=10_000)
a = enc.generate()
b = enc.generate()
c = a.bind(b)
print(f"{EncClass.__name__:12s} "
f"sim(a,a)={a.similarity(a):.2f} "
f"sim(a,bind(a,b))={a.similarity(c):.2f}")