### Question:
UnitVectorNormalizer extends AbstractVectorNormalizer implements Serializable { @Override public InvertibleFunction<Long2DoubleMap, Long2DoubleMap> makeTransformation(Long2DoubleMap reference) { double s = Vectors.euclideanNorm(reference); if (Math.abs(s) < tolerance) { return new IdentityVectorNormalizer().makeTransformation(reference); } else { return new ScalingTransform(s); } } @Inject  UnitVectorNormalizer();  UnitVectorNormalizer(double t); @Override InvertibleFunction<Long2DoubleMap, Long2DoubleMap> makeTransformation(Long2DoubleMap reference);  }### Answer:
@Test public void testMapVector() { Long2DoubleMap v = new Long2DoubleOpenHashMap(); v.put(1L, 1.0); v.put(4L, 1.0); Long2DoubleMap ref = new Long2DoubleOpenHashMap(); ref.put(1L, 1.0); ref.put(6L, 1.0); ref.put(3L, 2.0); InvertibleFunction<Long2DoubleMap, Long2DoubleMap> tx = norm.makeTransformation(ref); Long2DoubleMap out = tx.apply(v); assertThat(Vectors.euclideanNorm(out), closeTo(sqrt(2.0 / 6), 1.0e-6)); assertThat(out.size(), equalTo(2)); assertThat(out.get(1), closeTo(1 / sqrt(6), 1.0e-6)); assertThat(out.get(4), closeTo(1 / sqrt(6), 1.0e-6)); out = tx.unapply(out); assertThat(out.size(), equalTo(2)); assertThat(out.get(1), closeTo(1, 1.0e-6)); assertThat(out.get(4), closeTo(1, 1.0e-6)); assertThat(Vectors.sum(out), closeTo(2, 1.0e-6)); assertThat(Vectors.euclideanNorm(out), closeTo(sqrt(2), 1.0e-6)); }
@Test public void testScale() { Long2DoubleMap v = new Long2DoubleOpenHashMap(); v.put(1, 1); v.put(4, 1); Long2DoubleMap v2 = norm.makeTransformation(v).apply(v); assertThat(Vectors.euclideanNorm(v2), closeTo(1, 1.0e-6)); assertThat(v2.size(), equalTo(2)); assertThat(v2.get(1), closeTo(1 / sqrt(2), 1.0e-6)); assertThat(v2.get(4), closeTo(1 / sqrt(2), 1.0e-6)); }