def get_upper_star(pcpds_obj): f = d.fill_freudenthal(pcpds_obj.get_point_cloud().astype('f4'), False) m = d.homology_persistence(f) diagram = d.init_diagrams(m, f) pcpds_obj.set_persistance_diagram(diagram) pcpds_obj.set_filtration_used(Filtration.get_upper_star, "upper_star") return pcpds_obj
def compare_diagrams(n=16, negate=False, n_threads=4, seed=1, top_dim=2): # no wrap in Dionysus wrap = False # generate random grid data np.random.seed(seed) a = np.random.randn(n**3).reshape((n, n, n)) # compute diagrams with Oineus oin_dgms = oin.compute_diagrams_ls(a, negate, wrap, top_dim, n_threads) # compute diagrams with Dionysis fil_us = dion.fill_freudenthal(a, reverse=negate) p = dion.homology_persistence(fil_us) dion_dgms = dion.init_diagrams(p, fil_us) dist = 0.0 for dim in range(top_dim): # convert Oineus diagram to Dionysus format oin_dgm = dion.Diagram(oin_dgms[dim]) dion_dgm = dion_dgms[dim] dist += dion.bottleneck_distance(oin_dgm, dion_dgm) print("total dist: ", dist) assert (dist < 0.001)
def persistent(self): """ This method is used to create dionysus persistent homology implementation of given vectors :return: dionysus diagrams """ vectors = self._get_vectors() f_lower_star = dn.fill_freudenthal(vectors) p = dn.homology_persistence(f_lower_star) dgms = dn.init_diagrams(p, f_lower_star) return dgms
def compute_persistence(diagram): f_lower_star = d.fill_freudenthal(diagram, reverse = False) p = d.homology_persistence(f_lower_star) dgms_lower = d.init_diagrams(p, f_lower_star) return dgms_lower
def compute_persistence(directional_transform): f_lower_star = d.fill_freudenthal(directional_transform, reverse = True) p = d.homology_persistence(f_lower_star) dgms_lower = d.init_diagrams(p, f_lower_star) return dgms_lower
elif i == 1: h1.append(np.array((p.birth, p.death))) h0 = np.asarray(h0) h1 = np.asarray(h1) h0 = h0.reshape((-1, 2)) h1 = h1.reshape((-1, 2)) return [h0, h1] PI_null_images = [] PI_one_images = [] for i in range(images.shape[0]): print(i) f_lower_star = d.fill_freudenthal(images[i, :, :, 0].astype(float)) f_upper_star = d.fill_freudenthal(images[i, :, :, 0].astype(float), reverse=True) p = d.homology_persistence(f_lower_star) dgms_temp = d.init_diagrams(p, f_lower_star) h0_temp = homology_persistent_diagrams(dgms_temp)[0] h1_temp = homology_persistent_diagrams(dgms_temp)[1] pim = PersImage(pixels=[20, 20], spread=1) PI_0_temp = pim.transform(h0_temp[1:, :]) PI_1_temp = pim.transform(h1_temp) PI_null_images.append(PI_0_temp) PI_one_images.append(PI_1_temp) PI_null_images = np.array(PI_null_images, dtype=np.float32) PI_null_images = PI_null_images.reshape((-1, 20, 20, 1)) # reshape PI_null_images = PI_null_images / (PI_null_images.max() / 255.0) # normalize