SparseFeatureVector extends FeatureVector { public double innerProduct(FeatureVector other) { double result = 0.0; for (FeatureVector.Entry entry : this) { result += entry.value * other.get(entry.index); } return result; } SparseFeatureVector();  SparseFeatureVector(FeatureVector fv); double get(int index); java.util.Iterator<Entry> iterator(); void set(int index, double value); double innerProduct(FeatureVector other);  }
@Test public void testInnerProduct() throws Throwable { FeatureVector fv = new SparseFeatureVector(); fv.set(1, 1); fv.set(3, 2.5); fv.set(6, 0.5); assertEquals(fv.innerProduct(fv2), 11, delta); assertEquals(fv2.innerProduct(fv), 11, delta); }