def test_dist_manhattan(self): """tests dist_manhattan tests inputs of empty mtx, zeros, and dense1 compared with calcs done by hand""" assert_allclose(dist_manhattan(self.zeromtx), zeros((4, 4), "d")) dense1expected = array( [[0.0, 5.0, 019.9], [5.0, 0.0, 24.9], [19.9, 24.90, 0.0]], "d") assert_allclose(dist_manhattan(self.dense1), dense1expected)
def test_dist_bray_curtis_faith(self): """tests dist_bray_curtis_faith tests inputs of empty mtx, zeros, and mtx1 compared with calcs done by hand""" assert_allclose(dist_manhattan(self.zeromtx), zeros((4, 4) * 1, "d")) mtx1expected = array([[0, 21.1 / 27.1], [21.1 / 27.1, 0]], "d") assert_allclose(dist_bray_curtis_faith(self.mtx1), mtx1expected)
def test_dist_bray_curtis(self): """tests dist_bray_curtis tests inputs of empty mtx, zeros, and mtx1 compared with calcs done by hand""" self.assertFloatEqual(dist_manhattan(self.zeromtx), zeros((4, 4) * 1, "d")) mtx1expected = array([[0, 21.1 / 27.1], [21.1 / 27.1, 0]], "d") self.assertFloatEqual(dist_bray_curtis(self.mtx1), mtx1expected)
def test_dist_soergel(self): """tests dist_soergel tests inputs of empty mtx, zeros, and dense1 compared with calcs done by hand/manhattan dist""" assert_allclose(dist_soergel(self.zeromtx), zeros((4, 4) * 1, "d")) dense1expected = dist_manhattan(self.dense1) dense1norm = array([[1, 8, 23], [8, 1, 27], [23, 27, 1]], "d") dense1expected /= dense1norm assert_allclose(dist_soergel(self.dense1), dense1expected)
def test_binary_dist_jaccard(self): """tests binary_dist_jaccard tests inputs of empty mtx, zeros, and sparse1 compared with calcs done by hand""" assert_allclose(binary_dist_jaccard(self.zeromtx), zeros((4, 4), "d")) sparse1expected = array( [[0, 0, 1.0, 1.0], [0, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]], "d") assert_allclose(binary_dist_jaccard(self.sparse1), sparse1expected) sparse1expected = dist_manhattan(self.sparse1.astype(bool)) sparse1norm = array( [[1, 1, 2, 1], [1, 1, 2, 1], [2, 2, 1, 1], [1, 1, 1, 100]], "d") sparse1expected /= sparse1norm assert_allclose(binary_dist_jaccard(self.sparse1), sparse1expected)