def test_get_dist_func_cosine(self): f = LSHNearestNeighborIndex._get_dist_func('cosine') ntools.assert_is_instance(f, types.FunctionType) ntools.assert_almost_equal(f(numpy.array([1, 0]), numpy.array([0, 1])), 1.0) ntools.assert_almost_equal(f(numpy.array([1, 0]), numpy.array([1, 1])), 0.5)
def test_get_dist_func_euclidean(self): f = LSHNearestNeighborIndex._get_dist_func('euclidean') self.assertIsInstance(f, types.FunctionType) self.assertAlmostEqual( f(np.array([0, 0]), np.array([0, 1])), 1.0 )
def test_get_dist_func_cosine(self): f = LSHNearestNeighborIndex._get_dist_func('cosine') self.assertIsInstance(f, types.FunctionType) self.assertAlmostEqual( f(np.array([1, 0]), np.array([0, 1])), 1.0 ) self.assertAlmostEqual( f(np.array([1, 0]), np.array([1, 1])), 0.5 )
def test_get_dist_func_euclidean(self): f = LSHNearestNeighborIndex._get_dist_func('euclidean') ntools.assert_is_instance(f, types.FunctionType) ntools.assert_almost_equal(f(numpy.array([0, 0]), numpy.array([0, 1])), 1.0)