#74 · Linear Algebra · Medium
⊣ Solve on deep-ml.comCreate a composite hypervector for a dataset row using hyperdimensional computing. Given a row of feature values and a set of base hypervectors for each feature, encode the row as a single composite hypervector by binding (element-wise XOR or multiplication) each feature value with its position vector and then bundling (summing) them.
import numpy as np
def create_composite_hypervector(features, base_vectors, value_vectors):
dim = len(base_vectors[0])
composite = np.zeros(dim, dtype=float)
for i, value in enumerate(features):
# Bind: element-wise multiplication of feature base vector with value vector
bound = np.array(base_vectors[i]) * np.array(value_vectors[value])
# Bundle: accumulate
composite += bound
# Binarize: threshold at 0
composite = np.where(composite >= 0, 1, -1)
return composite.tolist()