mod update corresponding examples

This commit is contained in:
2026-04-09 08:48:07 +02:00
parent be101411cd
commit a89c6d4833
6 changed files with 155 additions and 111 deletions
+11 -9
View File
@@ -6,7 +6,6 @@ from graph_tool.all import *
from src import centrality
from src import plot
from src import fitting
def random_graph(n=5000, seed=None):
@@ -40,19 +39,21 @@ def spatial_graph(adata):
def apply(g, seed, weight, convex_hull, ax, ax2, method):
# calculate centrality values
vp, ep = method(g, weight=weight)
vp.a = np.nan_to_num(vp.a) # correct floating point values
ep.a = np.nan_to_num(ep.a) # correct floating point values
min_val, max_val = ep.a.min(), ep.a.max()
ep.a = (ep.a - min_val) / (max_val - min_val)
# euklidian distance
quantification = plot.quantification_data(g, vp, convex_hull)
quantification = plot.quantification_data(g, ep, convex_hull)
plot.quantification_plot(ax, quantification, None, None, "Euklidian Distance", None)
# generate model based on convex hull and associated centrality values
# path distance
quantification = plot.quantification_data_path_distance(g, weight, vp, convex_hull)
quantification = plot.quantification_data_path_distance(g, weight, ep, convex_hull)
plot.quantification_plot(ax2, quantification, None, None, "Shortest Path Distance", None)
points, seed = random_graph(n=5000)
points, seed = random_graph(n=5000, seed=77011137629244244786159039169016117129)
g, weight = spatial_graph(points)
g = GraphView(g)
# calculate convex hull
@@ -62,12 +63,13 @@ fig = plt.figure(figsize=(21, 5))
ax1, ax2, ax3 = fig.subplots(1, 3)
# plot graph with convex_hull
# draw without any centrality measure `vp`
vp, ep = betweenness(g, weight=weight)
vp.a = np.nan_to_num(vp.a) # correct floating point values
ep.a = np.nan_to_num(ep.a) # correct floating point values
min_val, max_val = ep.a.min(), ep.a.max()
ep.a = (ep.a - min_val) / (max_val - min_val)
plot.graph_plot(fig, ax1, g, vp, convex_hull, f"Pointcloud (seed: {seed})")
plot.graph_plot(fig, ax1, g, ep, convex_hull, f"Pointcloud (seed: {seed})", True)
apply(g, seed, weight, convex_hull, ax2, ax3, betweenness)
fig.savefig(f"Distance_5000_betweenness_euklidian.svg", format='svg')
fig.savefig(f"Distance_5000_betweenness_edge_euklidian.svg", format='svg')