LibTernary: Balanced ternary vectors
Still a work in progress, LibTernary is a library for working with vectors of balanced ternary (-1, 0, 1) digits, or trits. I usually omit the “balanced” and just refer to them as ternary vectors, because ternary is usually only interesting when it’s balanced ternary.
“What’s the point?” you ask? I’m glad you asked. I refer you to An Introduction to Random Indexing by Magnus Sahlgren. The upshot is that mapping text (or perhaps other data) to ternary vectors leads to a very simple and computationally fast way of approximating a vector space model à la latent semantic analysis.
Create a vector of 6400 values, 30 of which will be nonzero:
var vector = new TernaryVector(6400, 30);
Combine two vectors into one “context” vector:
var vector1 = new TernaryVector(6400, 30); var vector2 = new TernaryVector(6400, 30); var context = new TernaryVector(6400, 0); vector1.Merge(vector2, context);