def testCosineDistance2D(self):
        with self.test_session() as test_session:
            x1 = np.array([[0., 1.], [2., 3.]])
            x2 = np.array([[0., 1.], [-2., -3.]])

            actual_output = test_session.run(cosine_distance(x1, x2))
            correct_output = [[1.], [-1.]]

            self.assertAllClose(actual_output, correct_output)
    def testCosineDistanceSame(self):
        with self.test_session() as test_session:
            x1 = np.array([[1., 1.]])
            x2 = np.array([[1., 1.]])

            actual_output = list(test_session.run(cosine_distance(x1, x2)))
            correct_output = [[1.]]

            self.assertAllClose(actual_output, correct_output)
    def testCosineDistanceOrthogonal(self):
        with self.test_session() as test_session:
            x1 = np.array([[-1., 1.]])
            x2 = np.array([[1., 1.]])

            actual_output = test_session.run(cosine_distance(x1, x2))
            correct_output = [0.]

            self.assertEqual(actual_output, correct_output)
예제 #4
0
    def testCosineDistanceOpposite(self):
        with self.cached_session() as test_session:
            x1 = np.array([[-1., -1.]])
            x2 = np.array([[1., 1.]])

            actual_output = test_session.run(cosine_distance(x1, x2))
            correct_output = [[-1.]]

            self.assertAllClose(actual_output, correct_output)