def process_planted(min_size, max_size, max_count, n_samples): """Fixture for loading samples from the Planted dataset""" samples = p_planted[:n_samples] d = subgraph.search(samples, g_planted, min_size, max_size, max_count) return d
# .. raw:: html # :file: ../../examples_apps/planted.html # # .. note:: # The command ``plotly.offline.plot()`` is used to display plots in the documentation. In # practice, you can simply use ``plot_graph.show()`` to view the graph. ############################################################################## # A more interesting challenge is to find dense subgraphs of different sizes; it is often # useful to identify many high-density subgraphs, not just the densest ones. This is the purpose of # the :func:`~.subgraph.search` function in the :mod:`~.apps.subgraph` module: to identify # collections of dense subgraphs for a range of sizes. The output of this function is a # dictionary whose keys correspond to subgraph sizes within the specified range. The values in # the dictionary are the top subgraphs of that size and their corresponding density. dense = subgraph.search(samples, pl_graph, 8, 16, max_count=3) # we look at top 3 densest subgraphs for k in range(8, 17): print(dense[k][0]) # print only the densest subgraph of each size ############################################################################## # From the results of the search we learn that, depending on their size, the densest subgraphs # belong to different regions of the graph: dense subgraphs of less than ten nodes are contained # within the planted subgraph, whereas larger dense subgraphs appear outside of the planted # subgraph. Smaller dense subgraphs can be cliques, characterized by having # maximum density of 1, while larger subgraphs are less dense. Let's see what the smallest and # largest subgraphs look like: densest_8 = plot.graph(pl_graph, dense[8][0][1]) densest_16 = plot.graph(pl_graph, dense[12][0][1]) plotly.offline.plot(densest_8, filename="densest_8.html")
def graphDensity(self, samples, min_pho, max_pho, subgraph_size, max_count): dense = subgraph.search(samples, pl_graph, subgraph_size, min_pho, max_count=max_count) dense_freq = [] for k in range(subgraph_size, min_pho+1): dense_freq.append([k,len(dense[k])]) return dense, dense_freq