mod update corresponding examples
This commit is contained in:
+16
-24
@@ -85,23 +85,18 @@ def spatial_graph(adata):
|
||||
|
||||
def apply(g, seed, weight, convex_hull, ax, method, method_name):
|
||||
# calculate centrality values
|
||||
vp = None
|
||||
ep = None
|
||||
if method_name == "Betweeness":
|
||||
vp, ep = method(g, weight=weight)
|
||||
elif method_name == "Eigenvector":
|
||||
ep, vp = method(g, weight=weight)
|
||||
elif method_name == "Hits":
|
||||
ep, vp, hub_centrality = method(g, weight=weight)
|
||||
else:
|
||||
vp = method(g, weight=weight)
|
||||
vp.a = np.nan_to_num(vp.a) # correct floating point values
|
||||
ep = method(g, weight=weight)
|
||||
ep.a = np.nan_to_num(ep.a) # correct floating point values
|
||||
|
||||
# normalization
|
||||
min_val, max_val = vp.a.min(), vp.a.max()
|
||||
vp.a = (vp.a - min_val) / (max_val - min_val)
|
||||
min_val, max_val = ep.a.min(), ep.a.max()
|
||||
ep.a = (ep.a - min_val) / (max_val - min_val)
|
||||
|
||||
# generate model based on convex hull and associated centrality values
|
||||
quantification = plot.quantification_data(g, vp, convex_hull)
|
||||
quantification = plot.quantification_data_edges(g, ep, convex_hull)
|
||||
|
||||
# optimize model's piece-wise linear function
|
||||
d = quantification[:, 0]
|
||||
@@ -129,16 +124,16 @@ def apply(g, seed, weight, convex_hull, ax, method, method_name):
|
||||
# - Draw the corresponding resulting models into a grid
|
||||
#
|
||||
points, seed = random_graph(n=5000)
|
||||
g, weight = spatial_graph(adata.obsm['spatial'])
|
||||
g, weight = spatial_graph(points)
|
||||
g = GraphView(g)
|
||||
# calculate convex hull
|
||||
convex_hull = centrality.convex_hull(g)
|
||||
|
||||
# plot graph with convex_hull
|
||||
fig_graph, ax_graph = plt.subplots(figsize=(15, 12))
|
||||
# draw without any centrality measure `vp`
|
||||
vp = g.new_vertex_property("double")
|
||||
plot.graph_plot(fig_graph, ax_graph, g, vp, convex_hull, f"Pointcould (seed: {seed})")
|
||||
# draw without any centrality measure `ep`
|
||||
ep = g.new_edge_property("double")
|
||||
plot.graph_plot(fig_graph, ax_graph, g, ep, convex_hull, f"Pointcould (seed: {seed})", True) # draw edges
|
||||
fig_graph.savefig(f"comparison_edge_scores_artificial_graph.svg", format='svg')
|
||||
|
||||
fig = plt.figure(figsize=(15, 12))
|
||||
@@ -148,15 +143,12 @@ row1, row2 = fig.subplots(2, 4)
|
||||
# - some share similarities to the node based counter parts
|
||||
|
||||
ax1, ax2, ax3, ax4 = row1
|
||||
apply(g, None, weight, convex_hull, ax1, closeness, "Closeness")
|
||||
apply(g, None, weight, convex_hull, ax2, pagerank, "PageRank")
|
||||
apply(g, None, weight, convex_hull, ax3, betweenness, "Betweeness")
|
||||
apply(g, None, weight, convex_hull, ax4, eigenvector, "Eigenvector")
|
||||
apply(g, None, weight, convex_hull, ax1, betweenness, "Betweeness")
|
||||
|
||||
ax1, ax2, ax3, ax4 = row2
|
||||
apply(g, None, weight, convex_hull, ax1, katz, "Katz")
|
||||
apply(g, None, weight, convex_hull, ax2, hits, "Hits")
|
||||
apply(g, None, weight, convex_hull, ax3, leverage, "Leverage")
|
||||
apply(g, None, weight, convex_hull, ax4, degree, "Degree")
|
||||
# ax1, ax2, ax3, ax4 = row2
|
||||
# apply(g, None, weight, convex_hull, ax1, katz, "Katz")
|
||||
# apply(g, None, weight, convex_hull, ax2, hits, "Hits")
|
||||
# apply(g, None, weight, convex_hull, ax3, leverage, "Leverage")
|
||||
# apply(g, None, weight, convex_hull, ax4, degree, "Degree")
|
||||
|
||||
fig.savefig(f"Comparison_edge_centralities_artificial_.svg", format='svg')
|
||||
|
||||
Reference in New Issue
Block a user