예제 #1
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
def simulate_diffusion(nodes, edges, markov_matrix, t_max):
    """Simulate diffusion using diffusion engine.

    Returns:
        most_common: hyper_edges to their probabilities of occurrences
        most_common_nodes: similar to above, but with nodes
        states: list of states which were visited by workers
    """
    engine = DiffusionEngine(markov_matrix, t_per_walker=100)
    most_common, states = engine.simulate(t_max)
    most_common_nodes = count_nodes(nodes, edges, most_common)
    return most_common, most_common_nodes, states
예제 #3
0
def test_diffusion_engine():
    hyper_graph = generators.generic_hypergraph(10, ((3, 2), (4, 3), (5, 3)))
    t_max = 1000
    number_of_walkers = 1
    offset = 10

    markov_matrix = create_markov_matrix_model_nodes(hyper_graph)

    chosen_states = []
    for x in range(10, t_max, offset):
        engine = DiffusionEngine(markov_matrix)
        frequencies, states = engine.simulate(offset)

        chosen_states += states[0]

    nt.assert_equals(len(chosen_states), t_max / number_of_walkers - 10)
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')