Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
X = np.zeros([num_pts_per_orbit, 2])
xcur, ycur = np.random.rand(), np.random.rand()
for idx in range(num_pts_per_orbit):
xcur = (xcur + param * ycur * (1. - ycur)) % 1
ycur = (ycur + param * xcur * (1. - xcur)) % 1
X[idx, :] = [xcur, ycur]
return X
labs = []
count = 0
num_diag_per_param = 1000 if "5K" in dataset else 20000
for lab, r in enumerate([2.5, 3.5, 4.0, 4.1, 4.3]):
print("Generating", num_diag_per_param, "orbits and diagrams for r = ", r, "...")
for dg in range(num_diag_per_param):
X = _gen_orbit(num_pts_per_orbit=1000, param=r)
alpha_complex = gd.AlphaComplex(points=X)
simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=1e50)
simplex_tree.persistence()
diag_file["Alpha0"].create_dataset(name=str(count),
data=np.array(simplex_tree.persistence_intervals_in_dimension(0)))
diag_file["Alpha1"].create_dataset(name=str(count),
data=np.array(simplex_tree.persistence_intervals_in_dimension(1)))
orbit_label = {"label": lab, "pcid": count}
labs.append(orbit_label)
count += 1
labels = pd.DataFrame(labs)
labels.set_index("pcid")
features = labels[["label"]]
features.to_csv(path_dataset + dataset + ".csv")
return diag_file.close()
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)
rips_diag = rips_stree.persistence()
print("#####################################################################")
print("AlphaComplex creation from points read in a OFF file")
message = "AlphaComplex with max_edge_length=" + repr(args.threshold)
print(message)
alpha_complex = gudhi.AlphaComplex(points=point_cloud)
alpha_stree = alpha_complex.create_simplex_tree(max_alpha_square=(args.threshold * args.threshold))
message = "Number of simplices=" + repr(alpha_stree.num_simplices())
print(message)
alpha_diag = alpha_stree.persistence()
max_b_distance = 0.0
for dim in range(args.max_dimension):
# Alpha persistence values needs to be transform because filtration
# values are alpha square values
funcs = [math.sqrt, math.sqrt]
alpha_intervals = []
for interval in alpha_stree.persistence_intervals_in_dimension(dim):
alpha_intervals.append(map(lambda func,value: func(value), funcs, interval))
num_pts_per_orbit = 1000
for lab, r in enumerate([2.5, 3.5, 4.0, 4.1, 4.3]):
print("Generating", num_diag_per_param, "orbits and diagrams for r = ", r, "...")
for dg in range(num_diag_per_param):
x0, y0 = np.random.rand(), np.random.rand()
xcur, ycur = x0, y0
X = np.zeros([num_pts_per_orbit, 2])
X[0, :] = [x0, y0]
for idx in range(num_pts_per_orbit - 1):
xcur += r * ycur * (1. - ycur)
xcur -= int(xcur)
ycur += r * xcur * (1. - xcur)
ycur -= int(ycur)
X[idx, :] = [xcur, ycur]
alpha_complex = gd.AlphaComplex(points=X)
simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=1e50)
simplex_tree.persistence()
diag_file["Alpha0"].create_dataset(name=str(count),
data=np.array(simplex_tree.persistence_intervals_in_dimension(0)))
diag_file["Alpha1"].create_dataset(name=str(count),
data=np.array(simplex_tree.persistence_intervals_in_dimension(1)))
orbit_label = {"label": lab, "pcid": count}
labs.append(orbit_label)
count += 1
labels = pd.DataFrame(labs)
labels.set_index("pcid")
features = labels[["label"]]
features.to_csv(path_dataset + dataset + ".csv")
return diag_file.close()
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("AlphaComplex creation from points read in a OFF file")
message = "AlphaComplex with max_edge_length=" + repr(args.max_alpha_square)
print(message)
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:
#!/usr/bin/env python
import numpy as np
import gudhi
ac = gudhi.AlphaComplex(off_file='../../data/points/tore3D_1307.off')
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],
def compareAlpha():
import gudhi
np.random.seed(2)
# Make a 4-sphere in 5 dimensions
X = np.random.randn(100, 5)
tic = time.time()
Is1 = alpha_filtration(X)
phattime = time.time() - tic
print("Phat Time: %.3g" % phattime)
tic = time.time()
alpha_complex = gudhi.AlphaComplex(points=X.tolist())
simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=np.inf)
pers = simplex_tree.persistence()
gudhitime = time.time() - tic
Is2 = convertGUDHIPD(pers, len(Is1))
print("GUDHI Time: %.3g" % gudhitime)
I1 = Is1[len(Is1) - 1]
I2 = Is2[len(Is2) - 1]
plt.scatter(I1[:, 0], I1[:, 1])
plt.scatter(I2[:, 0], I2[:, 1], 40, marker="x")
plt.show()
def compareAlpha():
import gudhi
np.random.seed(2)
# Make a 4-sphere in 5 dimensions
X = np.random.randn(100, 5)
tic = time.time()
Is1 = alpha_filtration(X)
phattime = time.time() - tic
print("Phat Time: %.3g"%phattime)
tic = time.time()
alpha_complex = gudhi.AlphaComplex(points = X.tolist())
simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square = np.inf)
pers = simplex_tree.persistence()
gudhitime = time.time()-tic
Is2 = convertGUDHIPD(pers, len(Is1))
print("GUDHI Time: %.3g"%gudhitime)
I1 = Is1[len(Is1)-1]
I2 = Is2[len(Is2)-1]
plt.scatter(I1[:, 0], I1[:, 1])
plt.scatter(I2[:, 0], I2[:, 1], 40, marker='x')
plt.show()