int numDims = termToIndex.numDimensions();
// Iterate through the document's tokens and build the document
// representation for those terms that have an existing basis in the
// space
SparseDoubleVector docVec = new SparseHashDoubleVector(numDims);
while (docTokens.hasNext()) {
int dim = termToIndex.getDimension(docTokens.next());
if (dim >= 0)
docVec.add(dim, 1d);
}
// Transform the vector according to this instance's transform's state,
// which should normalize the vector as the original vectors were.
DoubleVector transformed = transform.transform(docVec);
// Represent the document as a 1-column matrix
Matrix queryAsMatrix = new ArrayMatrix(1, numDims);
for (int nz : docVec.getNonZeroIndices())
queryAsMatrix.set(0, nz, transformed.get(nz));
// Project the new document vector, d, by using
//
// d * U_k * Sigma_k^-1