def compare_hypergraph_with_cliques(number_of_nodes, cardinality, fraction, t_max, plot_representations=False): """Create hypergraph and clique, run diffusion and compare""" HG = uniform_hypergraph( n=number_of_nodes, k=cardinality, number_of_edges=int( number_of_nodes * fraction)) nodes = HG.nodes() hyperedges = HG.hyper_edges() all_nodes = [] for hyperedge in hyperedges: all_nodes += hyperedge if plot_representations: utils.plot_different_representations(nodes, hyperedges) markov_matrix = create_markov_matrix(hyperedges) print(markov_matrix) engine = DiffusionEngine(markov_matrix) most_common, states = engine.simulate(t_max) plt.figure(figsize=(12, 10)) utils.plot_hyperedges_frequencies(most_common, hyperedges, 'Occurrences of hyperedges' ' in a hypergraph') most_common_nodes = count_nodes(nodes, hyperedges, most_common) plt.figure(figsize=(12, 10)) utils.plot_nodes_frequencies(most_common_nodes, 'Nodes in a hypergraph') clique_graph = converters.convert_to_clique_graph(nodes, hyperedges) clique_markov_matrix = create_markov_matrix(clique_graph.edges()) print("clique markov matrix") print(clique_markov_matrix) engine = DiffusionEngine(markov_matrix) most_common, states = engine.simulate(t_max) plt.figure(figsize=(12, 10)) utils.plot_hyperedges_frequencies(most_common, clique_graph.edges(), 'Occurrences of edges in a graph') most_common_nodes = count_nodes(clique_graph.nodes(), clique_graph.edges(), most_common) plt.figure(figsize=(12, 10)) utils.plot_nodes_frequencies(most_common_nodes, 'Nodes in a graph')
def diffusion_on_clique(hypergraph, t_max, plot_results=False): """Simulate diffusion on corresponding clique graph""" nodes = hypergraph.nodes() hyper_edges = hypergraph.hyper_edges() clique_graph = converters.convert_to_clique_graph(nodes, hyper_edges) markov_matrix = create_markov_matrix(clique_graph.edges(), count_itself=False) edges = clique_graph.edges() most_common, most_common_nodes, states = simulate_diffusion( nodes, edges, markov_matrix, t_max) if plot_results: return plot_diffusion_results(most_common, most_common_nodes, hyper_edges, "clique") else: return utils.get_names_and_occurrences(most_common_nodes)[1]
def diffusion_on_clique(hypergraph, t_max, plot_results=False): """Simulate diffusion on corresponding clique graph""" nodes = hypergraph.nodes() hyper_edges = hypergraph.hyper_edges() clique_graph = converters.convert_to_clique_graph(nodes, hyper_edges) markov_matrix = create_markov_matrix(clique_graph.edges(), count_itself=False) edges = clique_graph.edges() most_common, most_common_nodes, states = simulate_diffusion( nodes, edges, markov_matrix, t_max) if plot_results: return plot_diffusion_results(most_common, most_common_nodes, hyper_edges, "clique") else: return utils.get_names_and_occurrences(most_common_nodes)[1]
def plot_different_representations(nodes, hyperedges): print("Drawing different representations of hypergraph") print("Bipartite graph") nx_bipartite = converters.convert_to_nx_bipartite_graph(nodes, hyperedges) plot_bipartite_graph(nx_bipartite, *hypergraph_to_bipartite_parts(nx_bipartite)) print("Graph of hypereges as nodes") custom_hyper_g = converters.convert_to_custom_hyper_G(nodes, hyperedges) plt.figure() nx.draw(custom_hyper_g) print("Clique graph") clique_graph = converters.convert_to_clique_graph(nodes, hyperedges) plt.figure() nx.draw(clique_graph)
def plot_different_representations(nodes, hyperedges): print("Drawing different representations of hypergraph") print("Bipartite graph") nx_bipartite = converters.convert_to_nx_bipartite_graph(nodes, hyperedges) plot_bipartite_graph(nx_bipartite, *hypergraph_to_bipartite_parts(nx_bipartite)) print("Graph of hypereges as nodes") custom_hyper_g = converters.convert_to_custom_hyper_G(nodes, hyperedges) plt.figure() nx.draw(custom_hyper_g) print("Clique graph") clique_graph = converters.convert_to_clique_graph(nodes, hyperedges) plt.figure() nx.draw(clique_graph)