def test_attribute_vertex_list(self): tree, altitudes = TestAttributes.get_test_tree() res = hg.attribute_vertex_list(tree) ref = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [0, 1], [2, 5], [3, 4], [6, 7], [6, 7, 8], [0, 1, 2, 5], [0, 1, 2, 5, 6, 7, 8], [0, 1, 2, 5, 6, 7, 8, 3, 4]] self.assertTrue(len(ref) == len(res)) for i in range(len(ref)): self.assertTrue(set(ref[i]) == set(res[i]))
def test_attribute_gaussian_region_weights_model_scalar(self): tree, altitudes = TestAttributes.get_test_tree() vertex_list = hg.attribute_vertex_list(tree) np.random.seed(42) vertex_weights = np.random.rand(tree.num_leaves()) mean, variance = hg.attribute_gaussian_region_weights_model(tree, vertex_weights) for i in tree.leaves_to_root_iterator(): m = np.mean(vertex_weights[vertex_list[i]]) v = np.var(vertex_weights[vertex_list[i]]) self.assertTrue(np.isclose(m, mean[i])) self.assertTrue(np.isclose(v, variance[i]))
def test_attribute_gaussian_region_weights_model_vectorial(self): tree, altitudes = TestAttributes.get_test_tree() vertex_list = hg.attribute_vertex_list(tree) np.random.seed(42) vertex_weights = np.random.rand(tree.num_leaves(), 3) mean, variance = hg.attribute_gaussian_region_weights_model(tree, vertex_weights) for i in tree.leaves_to_root_iterator(include_leaves=True): m = np.mean(vertex_weights[vertex_list[i]], 0) self.assertTrue(np.allclose(m, mean[i, :])) # numpy wrongly interprets a single observation with several variables as # multiple observations of a single variables if i >= tree.num_leaves(): v = np.cov(vertex_weights[vertex_list[i]], rowvar=False, bias=True) self.assertTrue(np.allclose(v, variance[i, ...])) else: v = np.zeros_like(variance[i, ...]) self.assertTrue(np.allclose(v, variance[i, ...]))