From 964ffb2e3dcfce65219a240db5ccfbbab46af956 Mon Sep 17 00:00:00 2001 From: OlympioH Date: Mon, 28 Oct 2019 16:03:08 +0100 Subject: [PATCH] Update cech.py The build_thresh function takes a threshold parameter as input and build a proximity graph : an edge is in the proximity graph if the distance between two points is lower than the threshold value.It then checks for every simplex in the edges are in the proximity graph, and then computes the miniball of a simplex. The simplex is added iff the radius is lower than the given threshold.However it does not seem to accelerate the algorithm, maybe you can have some thoughts about it ? I know very little about CS and programming so there might be some stupid mistakes in the code --- cechmate/filtrations/cech.py | 77 ++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/cechmate/filtrations/cech.py b/cechmate/filtrations/cech.py index a7ee22b..8b46157 100644 --- a/cechmate/filtrations/cech.py +++ b/cechmate/filtrations/cech.py @@ -1,6 +1,5 @@ import itertools import numpy as np - from .base import BaseFiltration from .miniball import miniball_cache @@ -24,14 +23,14 @@ def build(self, X): Parameters =========== - + X: Nxd array N Euclidean vectors in d dimensions Returns ========== - - simplices: + + simplices: Cech filtration for the data X """ @@ -40,7 +39,7 @@ def build(self, X): xrl = xr.tolist() maxdim = self.maxdim if not self.maxdim: - maxdim = X.shape[1] - 1 + maxdim = X.shape[1] miniball = miniball_cache(X) @@ -48,11 +47,75 @@ def build(self, X): simplices = [([i], 0) for i in range(N)] # then higher order simplices - for k in range(maxdim + 1): - for idxs in itertools.combinations(xrl, k + 2): + for k in range(maxdim+1): + for idxs in itertools.combinations(xrl, k + 1): C, r2 = miniball(frozenset(idxs), frozenset([])) simplices.append((list(idxs), np.sqrt(r2))) self.simplices_ = simplices return simplices + + def build_thresh(self, X, r_max=20): + """Compute the Cech filtration of a Euclidean point set for simplices up to order :code:`self.max_dim`. + + Parameters + =========== + + X: Nxd array + N Euclidean vectors in d dimensions + + Returns + ========== + + simplices: + Cech filtration for the data X + """ + + N = X.shape[0] + xr = np.arange(N) + xrl = xr.tolist() + maxdim = self.maxdim + if not self.maxdim: + maxdim = X.shape[1] + + miniball = miniball_cache(X) + + # start with vertices + simplices = [([i], 0) for i in range(N)] + + #then insert edges (proximity graph) + prox_graph=[] + for i in range(N): + for j in range(i): + d=np.linalg.norm(X[i]-X[j]) + if d/2