def make_gudhi_simplex_tree(points, edges, max_simplex_dim=2, metric=chebyshev): """Returns the `gudhi.SimplexTree()` object containing all simplices up to dimension `max_sim_dim` Parameters ---------- points: list of list of floats """ sim_tree = SimplexTree() vertices = list(range(len(points))) for v in vertices: sim_tree.insert(simplex=[v], filtration=0.0) for e in edges: p, q = points[e[0]], points[e[1]] sim_tree.insert(simplex=e, filtration=metric(p, q)) sim_tree.expansion(max_simplex_dim) return sim_tree
def create_simplex_tree(self, max_dimension): """ Args: max_dimension (int): graph expansion until this given dimension. """ dist = self.distance_matrix F = self.weights num_pts = len(dist) st = SimplexTree() for i in range(num_pts): if 2 * F[i] <= self.max_filtration: st.insert([i], 2 * F[i]) for i in range(num_pts): for j in range(i): value = max(2 * F[i], 2 * F[j], dist[i][j] + F[i] + F[j]) # max is needed when F is not 1-Lipschitz if value <= self.max_filtration: st.insert([i, j], filtration=value) st.expansion(max_dimension) return st
def test_expansion(): st = SimplexTree() assert st.__is_defined() == True assert st.__is_persistence_defined() == False # insert test assert st.insert([3, 2], 0.1) == True assert st.insert([2, 0], 0.2) == True assert st.insert([1, 0], 0.3) == True assert st.insert([3, 1], 0.4) == True assert st.insert([2, 1], 0.5) == True assert st.insert([6, 5], 0.6) == True assert st.insert([4, 2], 0.7) == True assert st.insert([3, 0], 0.8) == True assert st.insert([6, 4], 0.9) == True assert st.insert([6, 3], 1.0) == True assert st.num_vertices() == 7 assert st.num_simplices() == 17 assert list(st.get_filtration()) == [ ([2], 0.1), ([3], 0.1), ([2, 3], 0.1), ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4), ([1, 2], 0.5), ([5], 0.6), ([6], 0.6), ([5, 6], 0.6), ([4], 0.7), ([2, 4], 0.7), ([0, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0), ] st.expansion(3) assert st.num_vertices() == 7 assert st.num_simplices() == 22 assert list(st.get_filtration()) == [ ([2], 0.1), ([3], 0.1), ([2, 3], 0.1), ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4), ([1, 2], 0.5), ([0, 1, 2], 0.5), ([1, 2, 3], 0.5), ([5], 0.6), ([6], 0.6), ([5, 6], 0.6), ([4], 0.7), ([2, 4], 0.7), ([0, 3], 0.8), ([0, 1, 3], 0.8), ([0, 2, 3], 0.8), ([0, 1, 2, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0), ]