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 plot_diffusion_results(most_common, most_common_nodes, edges, name):
    """Plot results of diffusion.

    Parameters:
        most_common: indexes of hyperedges and their frequences
        most_common_nodes: indexes of nodes and their frequences
        edges: names of edge
        name: name of object on which diffusion was simulated, used
            plot title

    Returns:
        probabilities of being in a node

    """
    plt.figure(figsize=(8, 4))
    utils.plot_hyperedges_frequencies(most_common,
                                      edges, ('Occurrences of hyperedges in'
                                              ' a {}').format(name),
                                      normed=True)

    plt.figure(figsize=(8, 4))
    return utils.plot_nodes_frequencies(most_common_nodes,
                                        'Nodes in a {}'.format(name),
                                        normed=True)
def plot_diffusion_results(most_common, most_common_nodes, edges, name):
    """Plot results of diffusion.

    Parameters:
        most_common: indexes of hyperedges and their frequences
        most_common_nodes: indexes of nodes and their frequences
        edges: names of edge
        name: name of object on which diffusion was simulated, used
            plot title

    Returns:
        probabilities of being in a node

    """
    plt.figure(figsize=(8, 4))
    utils.plot_hyperedges_frequencies(most_common, edges,
                                      ('Occurrences of hyperedges in'
                                       ' a {}').format(name),
                                      normed=True)

    plt.figure(figsize=(8, 4))
    return utils.plot_nodes_frequencies(most_common_nodes,
                                        'Nodes in a {}'.format(name),
                                        normed=True)