viva_tensor/hdc
HDC - Hyperdimensional Computing
“One-shot learning via binary vectors”
Operations on high-dimensional binary vectors (default 10,048 dimensions).
Core Concepts
- Binding: XOR operation. Associates two concepts. Invertible (A XOR B XOR B = A).
- Bundling: Majority vote. Combines multiple vectors into a superposition.
- Permutation: Cyclic shift. Encodes sequence/order.
- Similarity: Hamming distance. Measures relatedness (1.0 = identical, 0.5 = random).
Example
import viva_tensor/hdc
let a = hdc.random(seed: 1)
let b = hdc.random(seed: 2)
let c = hdc.bind(a, b)
hdc.similarity(c, a) // -> 0.5 (orthogonal)
hdc.similarity(hdc.bind(c, b), a) // -> 1.0 (retrieved)
Types
Hypervector reference (binary vector handle)
pub type HyperVector =
ffi.HdcVectorRef
Values
pub fn bind(
a: ffi.HdcVectorRef,
b: ffi.HdcVectorRef,
) -> ffi.HdcVectorRef
Bind two hypervectors (XOR)
Use to associate concepts: bind(role, filler) e.g., bind(key_name, “Alice”)
pub fn permute(
vec: ffi.HdcVectorRef,
shift: Int,
) -> ffi.HdcVectorRef
Permute vector (cyclic shift)
Use to encode sequence or order. permute(A, 1) is different from A, but related.
pub fn similarity(
a: ffi.HdcVectorRef,
b: ffi.HdcVectorRef,
) -> Float
Calculate similarity between two vectors
Returns Float in [0.0, 1.0] 1.0 = Identical 0.5 = Orthogonal (Unrelated) 0.0 = Opposite (but in HDC usually everything is >= 0.5)