Esempio n. 1
0
#!/usr/bin/env python

import numpy as np
import gudhi

points = np.array(gudhi.read_points_from_off_file('../../data/points/Kl.off'))
rc = gudhi.RipsComplex(points=points, max_edge_length=.2)
st = rc.create_simplex_tree(max_dimension=2)
# We are only going to plot the triangles
triangles = np.array([s[0] for s in st.get_skeleton(2) if len(s[0]) == 3])

# First possibility: plotly
import plotly.graph_objects as go

fig = go.Figure(data=[
    go.Mesh3d(
        # Use the first 3 coordinates, but we could as easily pick others
        x=points[:, 0],
        y=points[:, 1],
        z=points[:, 2],
        i=triangles[:, 0],
        j=triangles[:, 1],
        k=triangles[:, 2],
    )
])
fig.show()

# Second possibility: matplotlib
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
Esempio n. 2
0
    action="store_true",
    help="Flag for not to display the diagrams",
)

args = parser.parse_args()

with open(args.file, "r") as f:
    first_line = f.readline()
    if (first_line == "OFF\n") or (first_line == "nOFF\n"):
        print(
            "#####################################################################"
        )
        print(
            "EuclideanWitnessComplex creation from points read in a OFF file")

        witnesses = gudhi.read_points_from_off_file(off_file=args.file)
        landmarks = gudhi.pick_n_random_points(
            points=witnesses, nb_points=args.number_of_landmarks)

        message = ("EuclideanWitnessComplex with max_edge_length=" +
                   repr(args.max_alpha_square) + " - Number of landmarks=" +
                   repr(args.number_of_landmarks))
        print(message)

        witness_complex = gudhi.EuclideanWitnessComplex(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())
Esempio n. 3
0
    "persistence creation from points read in "
    "a OFF file. Bottleneck distance computation"
    " on each dimension",
    epilog="Example: "
    "example/alpha_rips_persistence_bottleneck_distance.py "
    "-f ../data/points/tore3D_1307.off -t 0.15 -d 3",
)
parser.add_argument("-f", "--file", type=str, required=True)
parser.add_argument("-t", "--threshold", type=float, default=0.5)
parser.add_argument("-d", "--max_dimension", type=int, default=1)

args = parser.parse_args()
with open(args.file, "r") as f:
    first_line = f.readline()
    if (first_line == "OFF\n") or (first_line == "nOFF\n"):
        point_cloud = gudhi.read_points_from_off_file(off_file=args.file)
        print("##############################################################")
        print("RipsComplex creation from points read in a OFF file")

        message = "RipsComplex with max_edge_length=" + repr(args.threshold)
        print(message)

        rips_complex = gudhi.RipsComplex(
            points=point_cloud, max_edge_length=args.threshold
        )

        rips_stree = rips_complex.create_simplex_tree(
            max_dimension=args.max_dimension)

        message = "Number of simplices=" + repr(rips_stree.num_simplices())
        print(message)
parser.add_argument("-f", "--file", type=str, required=True)
parser.add_argument("-a", "--max_alpha_square", type=float, required=False)
parser.add_argument("-b", "--band", type=float, default=0.0)
parser.add_argument(
    "--no-diagram",
    default=False,
    action="store_true",
    help="Flag for not to display the diagrams",
)

args = parser.parse_args()

print("##############################################################")
print("AlphaComplex creation from points read in a OFF file")

points = gd.read_points_from_off_file(off_file=args.file)
alpha_complex = gd.AlphaComplex(points=points)
if args.max_alpha_square is not None:
    print("with max_edge_length=", args.max_alpha_square)
    simplex_tree = alpha_complex.create_simplex_tree(
        max_alpha_square=args.max_alpha_square)
else:
    simplex_tree = alpha_complex.create_simplex_tree()

print("Number of simplices=", simplex_tree.num_simplices())

diag = simplex_tree.persistence()
print("betti_numbers()=", simplex_tree.betti_numbers())
if args.no_diagram == False:
    import matplotlib.pyplot as plot
    gd.plot_persistence_diagram(diag, band=args.band)
Esempio n. 5
0
def load_off_file(file):
    points = gd.read_points_from_off_file(off_file = file)
    points = np.array(points)
    points = points / np.max(np.abs(points))
    return points
#!/usr/bin/env python

import numpy as np
import gudhi as gd
points = gd.read_points_from_off_file(
    off_file='../../data/points/tore3D_1307.off')
ac = gd.AlphaComplex(points=points)
st = ac.create_simplex_tree()
points = np.array([ac.get_point(i) for i in range(st.num_vertices())])
# We want to plot the alpha-complex with alpha=0.1.
# We are only going to plot the triangles
triangles = np.array(
    [s[0] for s in st.get_skeleton(2) if len(s[0]) == 3 and s[1] <= .1])

# First possibility: plotly
import plotly.graph_objects as go
fig = go.Figure(data=[
    go.Mesh3d(
        x=points[:, 0],
        y=points[:, 1],
        z=points[:, 2],
        i=triangles[:, 0],
        j=triangles[:, 1],
        k=triangles[:, 2],
    )
])
fig.show()

# Second possibility: matplotlib
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt