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')
Пример #2
0
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
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
Пример #4
0
def entropy_value(states, nodes, edges):
    """Compute entropy values from states, nodes and edges.

    It recomputes edge occurrences to node occurences.
    It's too much coupled with bipartite model.
    #TODO - decouple it

    """
    cum_states = chain(*states)
    most_common = Counter(cum_states).most_common()
    most_common_nodes = count_nodes(nodes, edges, most_common)
    frequencies = (utils.get_names_and_occurrences(most_common_nodes)[1])
    return entropy(frequencies)
Пример #5
0
def entropy_value(states, nodes, edges):
    """Compute entropy values from states, nodes and edges.

    It recomputes edge occurrences to node occurences.
    It's too much coupled with bipartite model.
    #TODO - decouple it

    """
    cum_states = chain(*states)
    most_common = Counter(cum_states).most_common()
    most_common_nodes = count_nodes(nodes, edges, most_common)
    frequencies = (utils.get_names_and_occurrences(most_common_nodes)[1])
    return entropy(frequencies)