def test_callable_input(self, adj): """Tests if function returns the correct output given a custom method set by the user""" objective_return = (0, [0]) def custom_method(*args, **kwargs): """Mockup of custom-method function fed to ``search``""" return objective_return result = subgraph.search( graph=adj, nodes=3, iterations=10, options={"heuristic": { "method": custom_method }}) assert result == objective_return
def test_valid_input(self, graph, monkeypatch, methods): """Tests if function returns the correct output under normal conditions. The method is here monkey patched to return a known result.""" objective_return = (0, [0]) def custom_method(*args, **kwargs): """Mockup of custom-method function fed to ``search``""" return objective_return with monkeypatch.context() as m: m.setattr(subgraph, "METHOD_DICT", {methods: custom_method}) result = subgraph.search( graph=graph, nodes=3, iterations=10, options={"heuristic": { "method": methods }}) assert result == objective_return
# .. raw:: html # :file: ../../examples_gbs/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:`~.gbs.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 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