Exemple #1
0
def test1():
    original = nx.uniform_random_intersection_graph(n=1000, m=10, p=0.1)
    ws = watts_strogatz_replicate(original, params={'k': 4})
    liu_chung = expected_degree_replicate(original)
    er = er_replicate(original)
    rand_noise1 = random_noise_replicate(original,
                                         params={
                                             'epsilon': .24,
                                             'preserve_degree': False
                                         })
    rand_noise2 = random_noise_replicate(original,
                                         params={
                                             'epsilon': .24,
                                             'preserve_degree': True
                                         })

    kron = kronecker_replicate(original=nx.path_graph(10),
                               params={'num_iterations': 4})

    import simpletesters
    assert graphutils.graph_santity_test(ws)
    assert graphutils.graph_santity_test(liu_chung)
    assert graphutils.graph_santity_test(er)
    assert graphutils.graph_santity_test(rand_noise1)
    assert graphutils.graph_santity_test(rand_noise2)
    assert graphutils.graph_santity_test(kron)

    print('Test 1 passed!')
Exemple #2
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 test1():
    original = nx.uniform_random_intersection_graph(n=1000, m=10, p=0.1)
    ws = watts_strogatz_replicate(original, params={'k':4})
    liu_chung = expected_degree_replicate(original)
    er = er_replicate(original)
    rand_noise1 = random_noise_replicate(original, params={'epsilon':.24, 'preserve_degree':False})
    rand_noise2 = random_noise_replicate(original, params={'epsilon':.24, 'preserve_degree':True})

    kron = kronecker_replicate(original=nx.path_graph(10), params={'num_iterations':4})
    
    import simpletesters
    assert graphutils.graph_santity_test(ws)
    assert graphutils.graph_santity_test(liu_chung)
    assert graphutils.graph_santity_test(er)
    assert graphutils.graph_santity_test(rand_noise1)
    assert graphutils.graph_santity_test(rand_noise2)
    assert graphutils.graph_santity_test(kron)

    print 'Test 1 passed!'
 def test_random_intersection_graph(self):
     G = nx.uniform_random_intersection_graph(10, 5, 0.5)
     assert_equal(len(G), 10)
Exemple #5
0
 def test_random_intersection_graph(self):
     G = nx.uniform_random_intersection_graph(10, 5, 0.5)
     assert len(G) == 10
Exemple #6
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_random_intersection_graph(self):
     G=nx.uniform_random_intersection_graph(10,5,0.5)
     assert_equal(len(G),10)
greatest_y_aristaGiant = sns.lineplot(data=dtb_giant, x="greatest_component", y="arista_number", hue="vertex_number")
greatest_y_aristaGiant.get_figure().savefig("../data/GG/greatest_y_aristaGG.png")


#Grafo extra: URIG
plist = [0] * 1000
rclist = [0] * 1000
vlist = [0] * 1000
vtimer = [0] * 1000
vertex = 0
for k in range(10):
    vertex = vertex +100

    for item in range(20):
        vlist[k * item] = vertex
        p = item / 20
        dtb = nx.uniform_random_intersection_graph(vertex, 20, p)
        ts = time.time()
        rc = nx.number_connected_components(dtb)
        plist[k * item] = p
        rclist[k * item] = rc
        vtimer[k * item] = time.time() -ts


dtb_cave = pd.DataFrame({"p": plist, "componentes": rclist, "vertices": vlist, "computation_time" : vtimer})

sns.pairplot(dtb_cave, hue="vertices", diag_kind='hist')
graficosGiant.savefig("../data/URIG/graficosURIG.png")