Beispiel #1
0
def test_uniform_generator():
    number_of_nodes = 10
    number_of_edges = 5
    cardinality = 3
    hu = generators.uniform_hypergraph(number_of_nodes, number_of_edges,
                                       cardinality)
    nt.assert_true(hu)
    nt.assert_equals(len(hu.nodes()), number_of_nodes)
    nt.assert_equals(len(hu.hyper_edges()), number_of_edges)
    nt.assert_true(all(len(e) == cardinality for e in hu.hyper_edges()))
def test_uniform_generator():
    number_of_nodes = 10
    number_of_edges = 5
    cardinality = 3
    hu = generators.uniform_hypergraph(number_of_nodes, number_of_edges,
                                       cardinality)
    nt.assert_true(hu)
    nt.assert_equals(len(hu.nodes()), number_of_nodes)
    nt.assert_equals(len(hu.hyper_edges()), number_of_edges)
    nt.assert_true(all(len(e) == cardinality for e in hu.hyper_edges()))
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')
Beispiel #4
0
def show_different_hypergraphs(n=10, k=3, parts=10):
    for fraction in np.linspace(0, 1, parts)[1:]:
        plt.figure(figsize=(6, 6))
        g = uniform_hypergraph(n=n, k=k, number_of_edges=int(n * fraction))
        G = convert_to_nx_bipartite_graph(g.nodes(), g.hyper_edges())
        utils.plot_bipartite_graph(G, *utils.hypergraph_to_bipartite_parts(G))
        hyper_G = convert_to_custom_hyper_G(g.nodes(), g.hyper_edges())

        plt.figure(figsize=(6, 6))
        nx.draw(hyper_G, node_size=3000, cmap=plt.cm.Blues, alpha=0.6)

    plt.show()
def show_different_hypergraphs(n=10, k=3, parts=10):
    for fraction in np.linspace(0, 1, parts)[1:]:
        plt.figure(figsize=(6, 6))
        g = uniform_hypergraph(n=n, k=k,
                               number_of_edges=int(n * fraction))
        G = convert_to_nx_bipartite_graph(g.nodes(), g.hyper_edges())
        utils.plot_bipartite_graph(G, *utils.hypergraph_to_bipartite_parts(G))
        hyper_G = convert_to_custom_hyper_G(g.nodes(), g.hyper_edges())

        plt.figure(figsize=(6, 6))
        nx.draw(hyper_G,
                node_size=3000, cmap=plt.cm.Blues, alpha=0.6)

    plt.show()