def test_is_output_clique(self, dim): """Test that the output subgraph is a valid clique, in this case the maximum clique in a lollipop graph""" graph = nx.lollipop_graph(dim, dim) subgraph = list(range(2 * dim)) # subgraph is the entire graph resized = clique.shrink(subgraph, graph) assert clique.is_clique(graph.subgraph(resized)) assert resized == list(range(dim))
def test_c_1_swap_to_clique(self, dim): """Tests that :math:`c_1` set gives a valid clique after swapping """ A = nx.complete_graph(dim) A.remove_edge(0, 1) S = list(range(1, dim)) c1 = clique.c_1(S, A) swap_nodes = c1[0] S.remove(swap_nodes[0]) S.append(swap_nodes[1]) assert clique.is_clique(A.subgraph(S))
for s in samples: uniform = list(np.random.choice(24, 8, replace=False)) # generates uniform sample GBS_dens.append(nx.density(TA_graph.subgraph(s))) u_dens.append(nx.density(TA_graph.subgraph(uniform))) print("GBS mean density = {:.4f}".format(np.mean(GBS_dens))) print("Uniform mean density = {:.4f}".format(np.mean(u_dens))) ############################################################################## # Those look like great GBS samples 💪! To obtain cliques, we shrink the samples by greedily # removing nodes with low degree until a clique is found. shrunk = [clique.shrink(s, TA_graph) for s in samples] print(clique.is_clique(TA_graph.subgraph(shrunk[0]))) ############################################################################## # Let's take a look at some of these cliques. What are the clique sizes in the first ten samples? # What is the average clique size? How about the largest and smallest clique size? clique_sizes = [len(s) for s in shrunk] print("First ten clique sizes = ", clique_sizes[:10]) print("Average clique size = {:.3f}".format(np.mean(clique_sizes))) print("Maximum clique size = ", np.max(clique_sizes)) print("Minimum clique size = ", np.min(clique_sizes)) ############################################################################## # Even in the first few samples, we've already identified larger cliques than the 4-node clique # we studied before. Awesome! Indeed, this simple shrinking strategy gives cliques with average # size of roughly five. We can enlarge these cliques by searching for larger cliques in their
def test_no_false_positives(self, dim): """Tests that non-cliques are labelled as such""" g = nx.empty_graph(dim) assert not clique.is_clique(g)
def test_no_false_negatives(self, dim): """Tests that cliques are labelled as such""" g = nx.complete_graph(dim) assert clique.is_clique(g)