Beispiel #1
0
def intersection_graphs():
    print("Intersection graphs")
    print("Uniform random intersection graph")
    G = nx.uniform_random_intersection_graph(n=14, m=5, p=0.07)
    draw_graph(G)
    print("K-random intersection graphs")
    G = nx.k_random_intersection_graph(n=12, m=6, k=5)
    draw_graph(G)
    print("General random intersection graphs")
    G = nx.general_random_intersection_graph(n=6,
                                             m=6,
                                             p=(0.25, 0.23, 0.8, 0.1, 0.8,
                                                0.06))
    draw_graph(G)
 def test_k_random_intersection_graph(self):
     G = nx.k_random_intersection_graph(10, 5, 2)
     assert_equal(len(G), 10)
Beispiel #3
0
 def test_k_random_intersection_graph(self):
     G = nx.k_random_intersection_graph(10, 5, 2)
     assert len(G) == 10
Beispiel #4
0
 def test_k_random_intersection_graph_seeded(self):
     G = nx.k_random_intersection_graph(10, 5, 2, seed=1234)
     assert len(G) == 10
Beispiel #5
0
def gen_laplacian(data_num=DATA_NUM, opt=27, cache=False):
    label = None

    if cache:
        print('Loading cached graph')
        graph = pk.load(open('tmp/g.pk', 'rb'))
    else:
        print('Generating graph opt {}'.format(opt))

        if 1 == opt:
            graph = gen_rand_graph(data_num=data_num)
        if 2 == opt:
            top_num = random.randint(1, data_num)
            bottom_num = data_num - top_num
            graph = nx.bipartite.random_graph(top_num, bottom_num, 0.9)
            label = [d['bipartite'] for n, d in graph.nodes(data=True)]
        elif 3 == opt:
            graph = nx.balanced_tree(4, 5)
        elif 4 == opt:
            graph = nx.complete_graph(data_num)
        elif 5 == opt:
            no1 = random.randint(1, data_num)
            no2 = random.randint(1, int(data_num / no1))
            no3 = data_num / no1 / no2
            graph = nx.complete_multipartite_graph(no1, no2, no3)
        elif 6 == opt:
            graph = nx.circular_ladder_graph(data_num)
        elif 7 == opt:
            graph = nx.cycle_graph(data_num)
        elif 8 == opt:
            graph = nx.dorogovtsev_goltsev_mendes_graph(5)
        elif 9 == opt:
            top_num = int(random.random() * data_num)
            bottom_num = data_num / top_num
            graph = nx.grid_2d_graph(top_num, bottom_num)
        elif 10 == opt:
            no1 = random.randint(1, data_num)
            no2 = random.randint(1, int(data_num / no1))
            no3 = data_num / no1 / no2
            graph = nx.grid_graph([no1, no2, no3])
        elif 11 == opt:
            graph = nx.hypercube_graph(10)
        elif 12 == opt:
            graph = nx.ladder_graph(data_num)
        elif 13 == opt:
            top_num = int(random.random() * data_num)
            bottom_num = data_num - top_num
            graph = nx.lollipop_graph(top_num, bottom_num)
        elif 14 == opt:
            graph = nx.path_graph(data_num)
        elif 15 == opt:
            graph = nx.star_graph(data_num)
        elif 16 == opt:
            graph = nx.wheel_graph(data_num)
        elif 17 == opt:
            graph = nx.margulis_gabber_galil_graph(35)
        elif 18 == opt:
            graph = nx.chordal_cycle_graph(data_num)
        elif 19 == opt:
            graph = nx.fast_gnp_random_graph(data_num, random.random())
        elif 20 == opt:  # jump eigen value
            graph = nx.gnp_random_graph(data_num, random.random())
        elif 21 == opt:  # disconnected graph
            graph = nx.dense_gnm_random_graph(data_num, data_num / 2)
        elif 22 == opt:  # disconnected graph
            graph = nx.gnm_random_graph(data_num, data_num / 2)
        elif 23 == opt:
            graph = nx.erdos_renyi_graph(data_num, data_num / 2)
        elif 24 == opt:
            graph = nx.binomial_graph(data_num, data_num / 2)
        elif 25 == opt:
            graph = nx.newman_watts_strogatz_graph(data_num, 5,
                                                   random.random())
        elif 26 == opt:
            graph = nx.watts_strogatz_graph(data_num, 5, random.random())
        elif 26 == opt:  # smooth eigen
            graph = nx.connected_watts_strogatz_graph(data_num, 5,
                                                      random.random())
        elif 27 == opt:  # smooth eigen
            graph = nx.random_regular_graph(5, data_num)
        elif 28 == opt:  # smooth eigen
            graph = nx.barabasi_albert_graph(data_num, 5)
        elif 29 == opt:  # smooth eigen
            graph = nx.powerlaw_cluster_graph(data_num, 5, random.random())
        elif 30 == opt:  # smooth eigen
            graph = nx.duplication_divergence_graph(data_num, random.random())
        elif 31 == opt:
            p = random.random()
            q = random.random()
            graph = nx.random_lobster(data_num, p, q)
        elif 32 == opt:
            p = random.random()
            q = random.random()
            k = random.random()

            graph = nx.random_shell_graph([(data_num / 3, 50, p),
                                           (data_num / 3, 40, q),
                                           (data_num / 3, 30, k)])
        elif 33 == opt:  # smooth eigen
            top_num = int(random.random() * data_num)
            bottom_num = data_num - top_num
            graph = nx.k_random_intersection_graph(top_num, bottom_num, 3)
        elif 34 == opt:
            graph = nx.random_geometric_graph(data_num, .1)
        elif 35 == opt:
            graph = nx.waxman_graph(data_num)
        elif 36 == opt:
            graph = nx.geographical_threshold_graph(data_num, .5)
        elif 37 == opt:
            top_num = int(random.random() * data_num)
            bottom_num = data_num - top_num
            graph = nx.uniform_random_intersection_graph(
                top_num, bottom_num, .5)

        elif 39 == opt:
            graph = nx.navigable_small_world_graph(data_num)
        elif 40 == opt:
            graph = nx.random_powerlaw_tree(data_num, tries=200)
        elif 41 == opt:
            graph = nx.karate_club_graph()
        elif 42 == opt:
            graph = nx.davis_southern_women_graph()
        elif 43 == opt:
            graph = nx.florentine_families_graph()
        elif 44 == opt:
            graph = nx.complete_multipartite_graph(data_num, data_num,
                                                   data_num)

        # OPT 1
        # norm_lap = nx.normalized_laplacian_matrix(graph).toarray()

        # OPT 2: renormalized

        # pk.dump(graph, open('tmp/g.pk', 'wb'))

    # plot_graph(graph, label)
    # note difference: normalized laplacian and normalzation by eigenvalue
    norm_lap, eigval, eigvec = normalize_lap(graph)

    return graph, norm_lap, eigval, eigvec
 def test_k_random_intersection_graph(self):
     G=nx.k_random_intersection_graph(10,5,2)
     assert_equal(len(G),10)
Beispiel #7
0
    #Random Small World Graph
    #path_output_data_type = path_output_data + 'small_world/'
    #makedir(path_output_data_type)

    #for i in range(default_no_entities):
    G = nx.navigable_small_world_graph(np.sqrt(default_size).astype(np.int8))
#    makedir(path_output_data_type + 'entity_' + str(i))
#    save_graph(path_output_data_type + 'entity_' + str(i) + '/' + 'J_ij.csv', G)

# Random Intersection Graph
path_output_data_type = path_output_data + 'intersection/'
makedir(path_output_data_type)

for i in range(default_no_entities):
    G = nx.k_random_intersection_graph(default_size, 10, 2)
    makedir(path_output_data_type + 'entity_' + str(i))
    save_graph(path_output_data_type + 'entity_' + str(i) + '/' + 'J_ij.csv',
               G)

# Social Graph
path_output_data = path_input + 'social/'
makedir(path_output_data)

# Karate club graph
path_output_data_type = path_output_data + 'karate_club/'
makedir(path_output_data_type)
G = nx.karate_club_graph()
makedir(path_output_data_type + 'entity_' + str(0))
save_graph(path_output_data_type + 'entity_' + str(0) + '/' + 'J_ij.csv', G)