def load_synthetic(mu, n=1000, tau1=3, tau2=1.5, edge_drop_percent=0.2): G = LFR_benchmark_graph(n, tau1, tau2, mu, average_degree=5, min_community=30, seed=10) for n in G.nodes: G.nodes[n]['value'] = list(G.nodes[n]['community'])[0] true_coms = list(nx.get_node_attributes(G, 'value').values()) com_keys = list(Counter(true_coms).keys()) for i in range(0, len(true_coms)): G.nodes[i]['value'] = com_keys.index(true_coms[i]) #remove self edges selfE = list(G.selfloop_edges()) for (i, j) in selfE: G.remove_edge(i, j) #convert all graph to undirected G = nx.Graph(G) ListOfNodes = list(G.nodes()) sample = int(len(ListOfNodes) * node_drop_percent) RandomSample = random.sample(ListOfNodes, sample) for n in G.nodes(): if (n not in RandomSample): G.nodes[n][label_name] = G.nodes[n]['value'] return (G, RandomSample)
def load_synthetic(n=250, tau1=3, tau2=1.5, mu=0.1): G = LFR_benchmark_graph(n, tau1, tau2, mu, average_degree=5, min_community=20, seed=10) for n in G.nodes: G.nodes[n]['value'] = list(G.nodes[n]['community'])[0] true_coms = list(nx.get_node_attributes(G,'value').values()) com_keys = list(Counter(true_coms).keys()) for i in range(0, len(true_coms)): G.nodes[i]['value'] = com_keys.index(true_coms[i]) true_labels = list(nx.get_node_attributes(G,'value').values()) true_labels = [ int(x) for x in true_labels ] #remove self edges selfE = list(G.selfloop_edges()) for (i,j) in selfE: G.remove_edge(i,j) #convert all graph to undirected G = nx.Graph(G) nG = nx.Graph(G) # first convert the networkx graph to igraph G = ig.Graph.Adjacency((nx.to_numpy_matrix(G) > 0).tolist()) G.to_undirected() return (G, nG, true_labels)