fix: correct centrality comparison script
This commit is contained in:
@@ -26,7 +26,7 @@ def leverage(g, weight):
|
|||||||
neighbours = g.get_all_neighbours(v)
|
neighbours = g.get_all_neighbours(v)
|
||||||
ki = len(neighbours)
|
ki = len(neighbours)
|
||||||
# sum
|
# sum
|
||||||
for nv, props in neighbours:
|
for nv in neighbours:
|
||||||
other_neighbours = g.get_all_neighbours(nv)
|
other_neighbours = g.get_all_neighbours(nv)
|
||||||
kj = len(other_neighbours)
|
kj = len(other_neighbours)
|
||||||
li += (ki - kj) / (ki + kj)
|
li += (ki - kj) / (ki + kj)
|
||||||
@@ -104,6 +104,14 @@ def spatial_graph(adata):
|
|||||||
|
|
||||||
def apply(g, seed, weight, convex_hull, ax, method, method_name):
|
def apply(g, seed, weight, convex_hull, ax, method, method_name):
|
||||||
# calculate centrality values
|
# calculate centrality values
|
||||||
|
vp = 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 = method(g, weight=weight)
|
||||||
vp.a = np.nan_to_num(vp.a) # correct floating point values
|
vp.a = np.nan_to_num(vp.a) # correct floating point values
|
||||||
|
|
||||||
@@ -128,7 +136,7 @@ def apply(g, seed, weight, convex_hull, ax, method, method_name):
|
|||||||
[lambda x: m_opt * x + c0_opt, lambda x: m_opt * b_opt + c0_opt]
|
[lambda x: m_opt * x + c0_opt, lambda x: m_opt * b_opt + c0_opt]
|
||||||
)
|
)
|
||||||
# plot model containing modeled piece-wise linear function
|
# plot model containing modeled piece-wise linear function
|
||||||
plot.quantification_plot(ax, quantification, d_curve, C_curve, 'Models', aic_opt)
|
plot.quantification_plot(ax, quantification, d_curve, C_curve, method_name, aic_opt)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -139,30 +147,33 @@ def apply(g, seed, weight, convex_hull, ax, method, method_name):
|
|||||||
# - apply centrality measure to the next axis
|
# - apply centrality measure to the next axis
|
||||||
# - Draw the corresponding resulting models into a grid
|
# - Draw the corresponding resulting models into a grid
|
||||||
#
|
#
|
||||||
points, seed = random_graph()
|
points, seed = random_graph(n=5000)
|
||||||
g, weight = spatial_graph(points)
|
g, weight = spatial_graph(points)
|
||||||
g = GraphView(g)
|
g = GraphView(g)
|
||||||
# calculate convex hull
|
# calculate convex hull
|
||||||
convex_hull = centrality.convex_hull(g)
|
convex_hull = centrality.convex_hull(g)
|
||||||
|
|
||||||
# plot graph with convex_hull
|
# plot graph with convex_hull
|
||||||
fig_graph, ax_graph = plt.subplots(figsize=(15, 5))
|
fig_graph, ax_graph = plt.subplots(figsize=(15, 12))
|
||||||
# draw without any centrality measure `vp`
|
# draw without any centrality measure `vp`
|
||||||
plot.graph_plot(fig_graph, ax_graph, g, vp, convex_hull, f"Pointcloud (seed: {seed}\n{method_name}")
|
vp = g.new_vertex_property("double")
|
||||||
|
plot.graph_plot(fig_graph, ax_graph, g, vp, convex_hull, f"Pointcloud (seed: {seed}")
|
||||||
fig_graph.savefig("Pointcloud_graph.svg", format='svg')
|
fig_graph.savefig("Pointcloud_graph.svg", format='svg')
|
||||||
|
|
||||||
fig = plt.figure(figsize=(15, 10))
|
fig = plt.figure(figsize=(15, 12))
|
||||||
axs = fig.subplots(2, 4)
|
row1, row2 = fig.subplots(2, 4)
|
||||||
|
|
||||||
for ax in axs:
|
ax1, ax2, ax3, ax4 = row1
|
||||||
# TODO select corresponding centrality measure method
|
# TODO select corresponding centrality measure method
|
||||||
apply(g, seed, weight, convex_hull, ax, closeness, "Closeness")
|
apply(g, seed, weight, convex_hull, ax1, closeness, "Closeness")
|
||||||
apply(g, seed, weight, convex_hull, ax, pagerank, "PageRank")
|
apply(g, seed, weight, convex_hull, ax2, pagerank, "PageRank")
|
||||||
apply(g, seed, weight, convex_hull, ax, betweeness, "Betweeness")
|
apply(g, seed, weight, convex_hull, ax3, betweenness, "Betweeness")
|
||||||
apply(g, seed, weight, convex_hull, ax, eigenvector, "Eigenvector")
|
apply(g, seed, weight, convex_hull, ax4, eigenvector, "Eigenvector")
|
||||||
apply(g, seed, weight, convex_hull, ax, katz, "Katz")
|
|
||||||
apply(g, seed, weight, convex_hull, ax, hits, "Hits")
|
ax1, ax2, ax3, ax4 = row2
|
||||||
apply(g, seed, weight, convex_hull, ax, leverage, "Leverage")
|
apply(g, seed, weight, convex_hull, ax1, katz, "Katz")
|
||||||
apply(g, seed, weight, convex_hull, ax, degree, "Degree")
|
apply(g, seed, weight, convex_hull, ax2, hits, "Hits")
|
||||||
|
apply(g, seed, weight, convex_hull, ax3, leverage, "Leverage")
|
||||||
|
apply(g, seed, weight, convex_hull, ax4, degree, "Degree")
|
||||||
|
|
||||||
fig.savefig(f"Comparison_Pointcloud.svg", format='svg')
|
fig.savefig(f"Comparison_Pointcloud.svg", format='svg')
|
||||||
|
|||||||
Reference in New Issue
Block a user