@Override
 public VectorTransformation makeTransformation(SparseVector reference) {
   double s = reference.norm();
   if (Math.abs(s) < tolerance) {
     return new IdentityVectorNormalizer().makeTransformation(reference);
   } else {
     return new ScalingTransform(s);
   }
 }
  @Override
  public double similarity(SparseVector vec1, SparseVector vec2) {
    final double distance;
    // One of the vector is empty
    if (Scalars.isZero(vec1.norm()) || Scalars.isZero(vec2.norm())) {
      return Double.NaN;
    }

    LongSet ts = LongUtils.setUnion(vec1.keySet(), vec2.keySet());

    MutableSparseVector v1 = MutableSparseVector.create(ts);
    v1.fill(0);
    v1.set(vec1);
    v1.multiply(1.0 / v1.norm());
    v1.addScaled(vec2, -1.0 / vec2.norm());

    distance = v1.norm();
    return 1 - distance;
  }