def test_shuffle_adjacency(): graph_args = { "generator_type": "uniform", "sizes": [2, 2], "p_in": 1.0, "p_out": .0, "out_path": None, "visualize": False, "cull_disconnected": False, "connect_disconnected": False, "generator_type": "uniform", "shuffle_labels": True } graph = generate_appm.main(graph_args) adjacency_matrix = nx.adjacency_matrix( graph, np.arange(graph.number_of_nodes())).todense() node_list = list(graph.nodes()) first_node_index = node_list[0] second_node_index = node_list[1] third_node_index = node_list[2] # first and second should have an edge assert_equal(adjacency_matrix[first_node_index, second_node_index], 1) # first and third should not have an edge assert_equal(adjacency_matrix[first_node_index, third_node_index], 0)
def run_graph_generate(args): print("graph_generate") generate_args_base = { "sizes": args["cluster_sizes"], "p_in": args["p"], "p_out": args["q"], "seed": args["seed"], "cull_disconnected": args["cull_disconnected"], "connect_disconnected": args["connect_disconnected"], "generator_type": args["generator_type"], "out_path": None, "visualize": False, } graphs = {} num_graphs = args["num_graphs"] for i in range(num_graphs): if i == 0 or (i+1) % 100 == 0 or i == (num_graphs - 1): print(f"graph {i+1}/{num_graphs}") generate_args = generate_args_base.copy() if args.get('verbose', False): print(f"{i}: {generate_args}") graph = generate_appm.main(generate_args) graph_id = str(uuid.uuid4()) graphs[graph_id] = {'args': generate_args, 'graph': graph } out_path = (f"{args['results_base']}" f"/{datetime.now().strftime(TIMESTAMP_FORMAT)}.pk") dump_pickle(graphs, out_path)
def test_simple_adjacency(): graph_args = { "generator_type": "uniform", "sizes": [2, 2], "p_in": 1.0, "p_out": 1.0, "out_path": None, "visualize": False, "cull_disconnected": False, "connect_disconnected": True, "generator_type": "uniform", "shuffle_labels": False } graph = generate_appm.main(graph_args) adjacency_matrix = nx.adjacency_matrix(graph).todense() correct_adjacency = np.ones((4, 4)) # no self-edges correct_adjacency[np.arange(4), np.arange(4)] = 0 assert_true(np.allclose(adjacency_matrix, correct_adjacency))
def _generate_new_graph(self): graph = generate_appm.main(self.graph_args) self.graph = graph
def _generate_new_graph(self): if self.graph is not None and self._fixed_graph: return graph_args = generate_graph_args() graph = generate_appm.main(graph_args) self.graph = graph