def comparing_pipeline(t_max=10000): """Generate various hypergraphs, run diffusion and compare models """ # TODO rewrite to use new hypergraph models with differenty created transition matrices for n in range(20, 31, 5): for k in range(3, 4): for f in range(90, 91, 10): f = float(f) / 100 # number_of_nodes, cardinality, fraction_of_hyperedges print(n, k, f) HG = utils.create_graph(n, k, f) number_of_nodes = analytical.prediction(HG) number_of_nodes_clique = analytical.prediction(HG, model="clique") # TODO change to matrix model nodes markov_matrix_loops = create_markov_matrix(HG.hyper_edges(), count_itself=True) markov_matrix = create_markov_matrix(HG.hyper_edges(), count_itself=False) simulated_n_o_n = diffusion_on_hypergraph(HG, markov_matrix, t_max) simulated_n_o_n_i = diffusion_on_hypergraph(HG, markov_matrix_loops, t_max) simulated_n_o_n_c = diffusion_on_clique(HG, t_max=t_max) plt.figure(figsize=(12, 10)) width = 0.15 plt.bar(HG.nodes(), simulated_n_o_n, width=width, color='crimson', label='Simulated markov hypergraph') plt.bar(np.array(HG.nodes()) + width, simulated_n_o_n_i, width, color='burlywood', label='Simulated markov hypergraph with loops') plt.bar(np.array(HG.nodes()) + 2 * width, number_of_nodes, width, label='Analytical diffusion model on hypergraph', color="#65df25") plt.bar(np.array(HG.nodes()) + 3 * width, simulated_n_o_n_c, width, label='Simulated clique graph') plt.bar(np.array(HG.nodes()) + 4 * width, number_of_nodes_clique, width, label='Analytical diffusion model on clique', color="#dcab11") plt.legend(loc=0) plt.savefig("next_diffusion_%s_%s_%s.png" % (n, k, f))
t_per_walker=100, title=None, filename=None): """Simulate diffusion and show how entropy changes in time""" nodes = HG.nodes() edges = HG.hyper_edges() states_per_time = compute_states_per_time(HG, t_max, t_per_walker) state_indices = list(range(len(states_per_time))[4:]) ys = [ entropy_value(states_per_time[:i], nodes, edges) for i in state_indices ] plt.plot(state_indices, ys) if title: plt.title(title) if filename: plt.savefig(filename) if __name__ == '__main__': k = 3 f = 1.6 for n in range(10, 30, 5): HG = utils.create_graph(n, k, f) filename = 'entropy_h_%s_%s_%s.png' % (n, k, f) compare_entropy(HG, filename=filename)
def compare_entropy(HG, t_max=10000, t_per_walker=100, title=None, filename=None): """Simulate diffusion and show how entropy changes in time""" nodes = HG.nodes() edges = HG.hyper_edges() states_per_time = compute_states_per_time(HG, t_max, t_per_walker) state_indices = list(range(len(states_per_time))[4:]) ys = [entropy_value(states_per_time[:i], nodes, edges) for i in state_indices] plt.plot(state_indices, ys) if title: plt.title(title) if filename: plt.savefig(filename) if __name__ == '__main__': k = 3 f = 1.6 for n in range(10, 30, 5): HG = utils.create_graph(n, k, f) filename = 'entropy_h_%s_%s_%s.png' % (n, k, f) compare_entropy(HG, filename=filename)