예제 #1
0
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))
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')
예제 #3
0
def compute_states_per_time(HG, t_max, t_per_walker):
    markov_matrix = create_markov_matrix(HG.hyper_edges())

    engine = DiffusionEngine(markov_matrix, t_per_walker=t_per_walker)

    most_common, states = engine.simulate(t_max)
    plt.show()

    states_per_time = list(zip(*states))

    return states_per_time
예제 #4
0
def compute_states_per_time(HG, t_max, t_per_walker):
    markov_matrix = create_markov_matrix(HG.hyper_edges())

    engine = DiffusionEngine(markov_matrix, t_per_walker=t_per_walker)

    most_common, states = engine.simulate(t_max)
    plt.show()

    states_per_time = list(zip(*states))

    return states_per_time
예제 #5
0
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]