viva_tensor/hdc

HDC - Hyperdimensional Computing

“One-shot learning via binary vectors”

Operations on high-dimensional binary vectors (default 10,048 dimensions).

Core Concepts

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 const default_dim: Int

Default dimensionality (10,048 bits)

pub fn dim(vec: ffi.HdcVectorRef) -> Int

Get dimensionality of the vector

pub fn new(dim: Int) -> ffi.HdcVectorRef

Create a new empty hypervector (all zeros)

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 random(dim: Int, seed: Int) -> ffi.HdcVectorRef

Create a random hypervector

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)

Search Document