public void TestDotProduct_DoubleArray() { var other = new[] { 0, 1.5, 2.0, 3.0 }; var instance = new SparseIntegerVector(new[] { 1, 2, 0, 0 }); var result = instance.DotProduct(other); Assert.Equal(expected: 3.0, actual: result); }
public void TestDotProduct() { var other = new SparseIntegerVector(new[] { 0, 2, 0, 1 }); var instance = new SparseIntegerVector(new[] { 1, 2, 1, 0 }); var result = instance.DotProduct(other); Assert.Equal(expected: 4.0, actual: result); }
public void TestCosineSimilarity() { var other = new SparseIntegerVector(new[] { 0, 1, 2, 3 }); var instance = new SparseIntegerVector(new[] { 1, 2, 0, 0 }); var expectedResult = instance.DotProduct(other) / (instance.Norm() * other.Norm()); var result = instance.CosineSimilarity(other); Assert.Equal(expected: expectedResult, actual: result); }