def cubical_persistence(images, title, plot_diagrams=False, betti_curves=False, scaled=False): homology_dimensions = (0, 1, 2) cp = CubicalPersistence( homology_dimensions=homology_dimensions, coeff=2, periodic_dimensions=None, infinity_values=None, reduced_homology=True, n_jobs=N_JOBS, ) diagrams_cubical_persistence = cp.fit_transform(images) if scaled: sc = Scaler(metric="bottleneck") diagrams_cubical_persistence = sc.fit_transform( diagrams_cubical_persistence) else: scaled_diagrams_cubical_persistence = diagrams_cubical_persistence if plot_diagrams: fig = cp.plot(diagrams_cubical_persistence) fig.update_layout(title=title) fig.show() if betti_curves: BC = BettiCurve() X_betti_curves = BC.fit_transform(diagrams_cubical_persistence) fig = BC.plot(X_betti_curves) fig.update_layout(title=title) fig.show() if title is not None: print(f"Computed CP for {title}") return diagrams_cubical_persistence
def vr_persistent_homology(patch_pc): homology_dimensions = (0, 1, 2) VR = VietorisRipsPersistence( metric="euclidean", max_edge_length=5, homology_dimensions=homology_dimensions, n_jobs=N_JOBS, ) diagrams_VietorisRips = VR.fit_transform(np.asarray(patch_pc)) VR.plot(diagrams_VietorisRips).show() BC = BettiCurve() X_betti_curves = BC.fit_transform(diagrams_VietorisRips) BC.plot(X_betti_curves).show() return diagrams_VietorisRips
def test_bc_transform_shape(n_bins): bc = BettiCurve(n_bins=n_bins) X_res = bc.fit_transform(X) assert X_res.shape == (1, bc._n_dimensions, n_bins)