diff --git a/comparison.py b/comparison.py index b9f843a..3749187 100644 --- a/comparison.py +++ b/comparison.py @@ -26,7 +26,7 @@ def leverage(g, weight): neighbours = g.get_all_neighbours(v) ki = len(neighbours) # sum - for nv, props in neighbours: + for nv in neighbours: other_neighbours = g.get_all_neighbours(nv) kj = len(other_neighbours) li += (ki - kj) / (ki + kj) @@ -104,7 +104,15 @@ def spatial_graph(adata): def apply(g, seed, weight, convex_hull, ax, method, method_name): # calculate centrality values - vp = method(g, weight=weight) + 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.a = np.nan_to_num(vp.a) # correct floating point values # normalization @@ -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] ) # 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 # - Draw the corresponding resulting models into a grid # -points, seed = random_graph() +points, seed = random_graph(n=5000) 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, 5)) +fig_graph, ax_graph = plt.subplots(figsize=(15, 12)) # 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 = plt.figure(figsize=(15, 10)) -axs = fig.subplots(2, 4) +fig = plt.figure(figsize=(15, 12)) +row1, row2 = fig.subplots(2, 4) -for ax in axs: - # TODO select corresponding centrality measure method - apply(g, seed, weight, convex_hull, ax, closeness, "Closeness") - apply(g, seed, weight, convex_hull, ax, pagerank, "PageRank") - apply(g, seed, weight, convex_hull, ax, betweeness, "Betweeness") - apply(g, seed, weight, convex_hull, ax, eigenvector, "Eigenvector") - apply(g, seed, weight, convex_hull, ax, katz, "Katz") - apply(g, seed, weight, convex_hull, ax, hits, "Hits") - apply(g, seed, weight, convex_hull, ax, leverage, "Leverage") - apply(g, seed, weight, convex_hull, ax, degree, "Degree") +ax1, ax2, ax3, ax4 = row1 +# TODO select corresponding centrality measure method +apply(g, seed, weight, convex_hull, ax1, closeness, "Closeness") +apply(g, seed, weight, convex_hull, ax2, pagerank, "PageRank") +apply(g, seed, weight, convex_hull, ax3, betweenness, "Betweeness") +apply(g, seed, weight, convex_hull, ax4, eigenvector, "Eigenvector") + +ax1, ax2, ax3, ax4 = row2 +apply(g, seed, weight, convex_hull, ax1, katz, "Katz") +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')