How to use the gudhi.plot_persistence_diagram function in gudhi

To help you get started, we’ve selected a few gudhi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GUDHI / gudhi-devel / src / python / example / euclidean_witness_complex_diagram_persistence_from_off_file_example.py View on Github external
witnesses=witnesses, landmarks=landmarks
        )
        simplex_tree = witness_complex.create_simplex_tree(
            max_alpha_square=args.max_alpha_square, limit_dimension=args.limit_dimension
        )

        message = "Number of simplices=" + repr(simplex_tree.num_simplices())
        print(message)

        diag = simplex_tree.persistence()

        print("betti_numbers()=")
        print(simplex_tree.betti_numbers())

        if args.no_diagram == False:
            gudhi.plot_persistence_diagram(diag, band=args.band)
            plot.show()
    else:
        print(args.file, "is not a valid OFF file")

    f.close()
github GUDHI / gudhi-devel / src / python / example / alpha_complex_diagram_persistence_from_off_file_example.py View on Github external
alpha_complex = gudhi.AlphaComplex(off_file=args.file)
        simplex_tree = alpha_complex.create_simplex_tree(
            max_alpha_square=args.max_alpha_square
        )

        message = "Number of simplices=" + repr(simplex_tree.num_simplices())
        print(message)

        diag = simplex_tree.persistence()

        print("betti_numbers()=")
        print(simplex_tree.betti_numbers())

        if args.no_diagram == False:
            gudhi.plot_persistence_diagram(diag, band=args.band)
            plot.show()
    else:
        print(args.file, "is not a valid OFF file")

    f.close()
github GUDHI / gudhi-devel / src / python / example / rips_complex_diagram_persistence_from_correlation_matrix_file_example.py View on Github external
message = "Number of simplices=" + repr(simplex_tree.num_simplices())
print(message)

diag = simplex_tree.persistence()

print("betti_numbers()=")
print(simplex_tree.betti_numbers())

# invert the persistence diagram
invert_diag = [
    (diag[pers][0], (1.0 - diag[pers][1][0], 1.0 - diag[pers][1][1]))
    for pers in range(len(diag))
]

if args.no_diagram == False:
    gudhi.plot_persistence_diagram(invert_diag, band=args.band)
    plot.show()
github GUDHI / gudhi-devel / src / python / example / gudhi_graphical_tools_example.py View on Github external
(0, (0.0, 1.0)),
    (0, (0.0, 1.0)),
]
gudhi.plot_persistence_barcode(persistence)
plot.show()

print("#####################################################################")
print("Show diagram persistence example")

gudhi.plot_persistence_diagram(persistence)
plot.show()

print("#####################################################################")
print("Show diagram persistence example with a confidence band")

gudhi.plot_persistence_diagram(persistence, band=0.2)
plot.show()

print("#####################################################################")
print("Show barcode and diagram persistence side by side example")
fig, axes = plot.subplots(nrows=1, ncols=2)
gudhi.plot_persistence_barcode(persistence, axes = axes[0])
gudhi.plot_persistence_diagram(persistence, axes = axes[1])
fig.suptitle("barcode versus diagram")
plot.show()
github GUDHI / gudhi-devel / src / python / example / rips_complex_diagram_persistence_from_distance_matrix_file_example.py View on Github external
distance_matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file=args.file)
rips_complex = gudhi.RipsComplex(
    distance_matrix=distance_matrix, max_edge_length=args.max_edge_length
)
simplex_tree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension)

message = "Number of simplices=" + repr(simplex_tree.num_simplices())
print(message)

diag = simplex_tree.persistence()

print("betti_numbers()=")
print(simplex_tree.betti_numbers())

if args.no_diagram == False:
    gudhi.plot_persistence_diagram(diag, band=args.band)
    plot.show()
github GUDHI / gudhi-devel / src / python / example / gudhi_graphical_tools_example.py View on Github external
print("Show diagram persistence example")

gudhi.plot_persistence_diagram(persistence)
plot.show()

print("#####################################################################")
print("Show diagram persistence example with a confidence band")

gudhi.plot_persistence_diagram(persistence, band=0.2)
plot.show()

print("#####################################################################")
print("Show barcode and diagram persistence side by side example")
fig, axes = plot.subplots(nrows=1, ncols=2)
gudhi.plot_persistence_barcode(persistence, axes = axes[0])
gudhi.plot_persistence_diagram(persistence, axes = axes[1])
fig.suptitle("barcode versus diagram")
plot.show()
github GUDHI / gudhi-devel / src / python / example / sparse_rips_persistence_diagram.py View on Github external
__copyright__ = "Copyright (C) 2018 Inria"
__license__ = "MIT"

print("#####################################################################")
print("Sparse RipsComplex creation from points")
rips = gudhi.RipsComplex(
    points=[[0, 0], [0, 0.1], [1, 0], [0, 1], [1, 1]], max_edge_length=42, sparse=0.5
)

simplex_tree = rips.create_simplex_tree(max_dimension=2)


diag = simplex_tree.persistence(homology_coeff_field=2, min_persistence=0)
print("diag=", diag)

gudhi.plot_persistence_diagram(diag)
plot.show()
github MathieuCarriere / sklearn-tda / sklearn_tda / clustering.py View on Github external
inv_sorted_idxs[sorted_idxs[i]] = i

        if self.verbose:
            print("Computing tau")
        if self.tau is not None:
            tau = self.tau
        else:
            st = gd.SimplexTree()
            for i in range(num_pts):
                st.insert([i], filtration=-self.density_values[i])
            for i in range(num_pts):
                for j in range(i+1,num_pts):
                    if A[i,j] == 1.:
                        st.insert([i,j], filtration=max(-self.density_values[i],-self.density_values[j]))
            d = st.persistence()
            plot = gd.plot_persistence_diagram(d)
            plot.show()
            dgm = st.persistence_intervals_in_dimension(0)
            persistences = np.sort([abs(y-x) for (x,y) in dgm])
            if self.n_clusters is not None:
                tau = (persistences[-self.n_clusters-1] + persistences[-self.n_clusters]) / 2
            else:
                n_clusters = np.argmax(np.flip(persistences[1:-1] - persistences[:-2])) + 2
                tau = (persistences[-n_clusters-1] + persistences[-n_clusters]) / 2
        if self.verbose:
            print("tau = " + str(tau))

        if self.verbose:
            print("Applying UF sequentially")
        diag, parents = {}, -np.ones(num_pts, dtype=np.int32)
        for i in range(num_pts):
github scikit-tda / cechmate / PhatCech.py View on Github external
def rips__filtration_gudhi(D, p, coeff = 2, doPlot = False):
    """
    Do the rips filtration, wrapping around the GUDHI library (for comparison)
    :param X: An Nxk matrix of points
    :param p: The order of homology to go up to
    :param coeff: The field coefficient of homology
    :returns Is: A dictionary of persistence diagrams, where Is[k] is \
        the persistence diagram for Hk 
    """
    import gudhi
    rips = gudhi.RipsComplex(distance_matrix=D,max_edge_length=np.inf)
    simplex_tree = rips.create_simplex_tree(max_dimension=p+1)
    diag = simplex_tree.persistence(homology_coeff_field=coeff, min_persistence=0)
    if doPlot:
        pplot = gudhi.plot_persistence_diagram(diag)
        pplot.show()
    Is = []
    for i in range(p+1):
        Is.append([])
    for (i, (b, d)) in diag:
        Is[i].append([b, d])
    for i in range(len(Is)):
        Is[i] = np.array(Is[i])
    return Is