private double calculateDenom(SparseVector a, SparseVector b) {
double result = 0;
TIntDoubleHashMap diff = new TIntDoubleHashMap();
for (int i = 0; i < a.numEntries(); i++) {
int ind = a.getIndexAt(i);
double val = a.getValueAt(i);
if (!diff.containsKey(ind)) {
diff.put(ind, 0);
}
diff.put(ind, diff.get(ind) + val);
}
for (int i = 0; i < b.numEntries(); i++) {
int ind = b.getIndexAt(i);
double val = b.getValueAt(i);
if (!diff.containsKey(ind)) {
diff.put(ind, 0);
}
diff.put(ind, diff.get(ind) - val);
}
for (TIntDoubleIterator iterator = diff.iterator(); iterator.hasNext();) {
iterator.advance();
result += Math.pow(iterator.value(), 2);
}
return result;