public void testLocation () { int curidx = 0; int max = idxs[idxs.length - 1]; for (int idx = 0; idx < max; idx++) { if (idx == idxs[curidx]) { assertEquals (dbl1[curidx], s1.value (idx), 1e-10); curidx++; } else { assertEquals (0, s1.value (idx), 1e-10); } } assertEquals (0, s1.value (max+1), 1e-10); }
public void testLocation () { int curidx = 0; int max = idxs[idxs.length - 1]; for (int idx = 0; idx < max; idx++) { if (idx == idxs[curidx]) { assertEquals (dbl1[curidx], s1.value (idx), 1e-10); curidx++; } else { assertEquals (0, s1.value (idx), 1e-10); } } assertEquals (0, s1.value (max+1), 1e-10); }
public void testDotProduct () { IndexedSparseVector t1 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 }); assertEquals (0.6, t1.dotProduct (s1), 0.00001); assertEquals (0.6, s1.dotProduct (t1), 0.00001); assertEquals (19.0, s1.dotProduct (s2), 0.00001); assertEquals (19.0, s2.dotProduct (s1), 0.00001); assertEquals (11.9, s1.dotProduct (d1), 0.00001); assertEquals (10.1, s2.dotProduct (d1), 0.00001); }
public void testDotProduct () { IndexedSparseVector t1 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 }); assertEquals (0.6, t1.dotProduct (s1), 0.00001); assertEquals (0.6, s1.dotProduct (t1), 0.00001); assertEquals (19.0, s1.dotProduct (s2), 0.00001); assertEquals (19.0, s2.dotProduct (s1), 0.00001); assertEquals (11.9, s1.dotProduct (d1), 0.00001); assertEquals (10.1, s2.dotProduct (d1), 0.00001); }
public void testEmptyLocations () { IndexedSparseVector s = new IndexedSparseVector (new int[0], new double [0]); assertEquals (0.0, s.value (38), 1e-10); assertEquals (0.0, s.dotProduct (s1), 1e-10); }
private void checkAnswer (IndexedSparseVector actual, double[] ans) { assertEquals ("Wrong number of locations:", ans.length, actual.numLocations()); for (int i = 0; i < actual.numLocations(); i++) { assertEquals ("Value incorrect at location "+i+": ", ans[i], actual.valueAtLocation (i) , 0.0); } }
private void checkAnswer (IndexedSparseVector actual, double[] ans) { assertEquals ("Wrong number of locations:", ans.length, actual.numLocations()); for (int i = 0; i < actual.numLocations(); i++) { assertEquals ("Value incorrect at location "+i+": ", ans[i], actual.valueAtLocation (i) , 0.0); } }
public void testEmptyLocations () { IndexedSparseVector s = new IndexedSparseVector (new int[0], new double [0]); assertEquals (0.0, s.value (38), 1e-10); assertEquals (0.0, s.dotProduct (s1), 1e-10); }
public void testBinaryVector () { IndexedSparseVector binary1 = new IndexedSparseVector (idxs, null, idxs.length, idxs.length, false, false, false); IndexedSparseVector binary2 = new IndexedSparseVector (idx2, null, idx2.length, idx2.length, false, false, false); assertEquals (3, binary1.dotProduct (binary2), 0.0001); assertEquals (3, binary2.dotProduct (binary1), 0.0001); assertEquals (15.0, binary1.dotProduct (s1), 0.0001); assertEquals (15.0, s1.dotProduct (binary1), 0.0001); assertEquals (9.0, binary2.dotProduct (s1), 0.0001); assertEquals (9.0, s1.dotProduct (binary2), 0.0001); IndexedSparseVector dblVec = (IndexedSparseVector) s1.cloneMatrix (); dblVec.plusEqualsSparse (binary1); checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 }); IndexedSparseVector dblVec2 = (IndexedSparseVector) s1.cloneMatrix (); dblVec2.plusEqualsSparse (binary2); checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 }); }
public void testBinaryVector () { IndexedSparseVector binary1 = new IndexedSparseVector (idxs, null, idxs.length, idxs.length, false, false, false); IndexedSparseVector binary2 = new IndexedSparseVector (idx2, null, idx2.length, idx2.length, false, false, false); assertEquals (3, binary1.dotProduct (binary2), 0.0001); assertEquals (3, binary2.dotProduct (binary1), 0.0001); assertEquals (15.0, binary1.dotProduct (s1), 0.0001); assertEquals (15.0, s1.dotProduct (binary1), 0.0001); assertEquals (9.0, binary2.dotProduct (s1), 0.0001); assertEquals (9.0, s1.dotProduct (binary2), 0.0001); IndexedSparseVector dblVec = (IndexedSparseVector) s1.cloneMatrix (); dblVec.plusEqualsSparse (binary1); checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 }); IndexedSparseVector dblVec2 = (IndexedSparseVector) s1.cloneMatrix (); dblVec2.plusEqualsSparse (binary2); checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 }); }
public void testSerializable2 () throws IOException, ClassNotFoundException { SparseVector[][] vecs = new SparseVector[2][]; vecs[0] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), (SparseVector) s1.cloneMatrix (), }; vecs[1] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), }; SparseVector[][] vecsPrime = (SparseVector[][]) TestSerializable.cloneViaSerialization (vecs); assertEquals (vecs.length, vecsPrime.length); }
public void testSerializable2 () throws IOException, ClassNotFoundException { SparseVector[][] vecs = new SparseVector[2][]; vecs[0] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), (SparseVector) s1.cloneMatrix (), }; vecs[1] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), }; SparseVector[][] vecsPrime = (SparseVector[][]) TestSerializable.cloneViaSerialization (vecs); assertEquals (vecs.length, vecsPrime.length); }
public void testSerializable () throws IOException, ClassNotFoundException { IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix (); IndexedSparseVector sPrime = (IndexedSparseVector) TestSerializable.cloneViaSerialization (s); assertEquals (s.numLocations (), sPrime.numLocations ()); assertTrue (Arrays.equals (s.getIndices (), sPrime.getIndices ())); assertTrue (Arrays.equals (s.getValues (), sPrime.getValues ())); }
public void testSerializable () throws IOException, ClassNotFoundException { IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix (); IndexedSparseVector sPrime = (IndexedSparseVector) TestSerializable.cloneViaSerialization (s); assertEquals (s.numLocations (), sPrime.numLocations ()); assertTrue (Arrays.equals (s.getIndices (), sPrime.getIndices ())); assertTrue (Arrays.equals (s.getValues (), sPrime.getValues ())); }
s5.plusEqualsSparse (s1); for (int i = 0; i < s5.numLocations(); i++) { assertEquals (7, s5.indexAtLocation (i)); assertEquals (3.2, s5.valueAtLocation (i), 0.0); s6.plusEqualsSparse (s1, 3.5); for (int i = 0; i < s6.numLocations(); i++) { assertEquals (7, s6.indexAtLocation (i)); assertEquals (10.7, s6.valueAtLocation (i), 0.0);
s5.plusEqualsSparse (s1); for (int i = 0; i < s5.numLocations(); i++) { assertEquals (7, s5.indexAtLocation (i)); assertEquals (3.2, s5.valueAtLocation (i), 0.0); s6.plusEqualsSparse (s1, 3.5); for (int i = 0; i < s6.numLocations(); i++) { assertEquals (7, s6.indexAtLocation (i)); assertEquals (10.7, s6.valueAtLocation (i), 0.0);