コード例 #1
0
ファイル: utils.py プロジェクト: pjhartout/TDA_ADNI_MLCB
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
コード例 #2
0
def test_sc_transform_shape(X, metric, metric_params):
    sc = Scaler(metric=metric, metric_params=metric_params, n_jobs=1)
    X_res = sc.fit_transform(X)
    assert X_res.shape == X.shape

    X_inv_res = sc.inverse_transform(X_res)
    assert_almost_equal(X_inv_res, X)
コード例 #3
0
def test_dd_transform(X, metric, metric_params):
    dsc = Scaler(metric=metric, metric_params=metric_params, n_jobs=1)
    X_res = dsc.fit_transform(X)
    assert X_res.shape == X.shape

    dsc = Scaler(metric=metric, metric_params=metric_params, n_jobs=1)
    X_inv_res = dsc.fit(X_res).inverse_transform(X_res)
    assert X_inv_res.shape == X.shape
コード例 #4
0
 def parallel_embed_(self, embedding):
     vr = VietorisRipsPersistence(
         metric='euclidean',
         homology_dimensions=self.homology_dimensions_,
         n_jobs=self.n_job)
     diagram_scaler = Scaler(n_jobs=self.n_job)
     persistence_diagrams = diagram_scaler.fit_transform(
         vr.fit_transform([embedding]))
     if self.filtering_:
         diagram_filter = Filtering(
             epsilon=0.1, homology_dimensions=self.filtering_dimensions_)
         persistence_diagrams = diagram_filter.fit_transform(
             persistence_diagrams)
     return persistence_diagrams[0]
コード例 #5
0
def cubical_persistence(patch):
    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(patch)
    sc = Scaler(metric="bottleneck")
    scaled_diagrams_cubical_persistence = sc.fit_transform(
        diagrams_cubical_persistence)
    print("Computed cubical persistence")
    return scaled_diagrams_cubical_persistence