Exemplo n.º 1
0
def learn_parameters(G):
    tr_list = [0, 5, 10]
    h_list = [1, 10, 20, 50, 100]
    d_list = [0, 5, 10]
    p_list = [100, 10000, 10000000000000000]

    repeat = 10
    results = []
    for tr in tr_list:
        for h in h_list:
            for d in d_list:
                for p in p_list:
                    temp = []
                    for i in range(repeat):
                        cdr = cd.CommunityDetector(G, tr, h, d, p)
                        cdr.run()
                        temp.append(cdr.compute_accuracy(False))
                    results.append((sum(temp) / float(repeat), {
                        "tr": tr,
                        "h": h,
                        "d": d,
                        "p": p
                    }))

    sorted_results = sorted(results)[-10:]
    pprint.pprint(sorted_results)
Exemplo n.º 2
0
def main():
    G = gg.Graph()
    set1 = G.create_nodes(200, {"clustId": 1}, 0)
    set2 = G.create_nodes(400, {"clustId": 2}, 0)
    set3 = G.create_nodes(50, {"clustId": 3}, 0)
    set4 = G.create_nodes(50, {"clustId": 3}, 0)

    for i in range(10):
        G.create_random_edges(2500, [set1, set2, set3, set4],
                              [[0.29, 0.01, 0, 0], [0, 0.5, 0, 0],
                               [0, 0, 0.10, 0], [0, 0, 0, 0.10]], [
                                   gg.UniformDistrib(),
                                   gg.UniformDistrib(),
                                   gg.UniformDistrib(),
                                   gg.UniformDistrib()
                               ], i)
    for i in range(10, 15):
        G.create_random_edges(
            500, [set1, set2, set3, set4],
            [[0.1, 0, 0.4, 0], [0, 0.1, 0, 0.4], [0, 0, 0, 0], [0, 0, 0, 0]], [
                gg.UniformDistrib(),
                gg.UniformDistrib(),
                gg.UniformDistrib(),
                gg.UniformDistrib()
            ], i)

    for i in range(15, 25):
        G.create_random_edges(
            500, [set1, set2, set3, set4],
            [[0.2, 0, 0, 0], [0, 0.2, 0, 0], [0, 0, 0, 0.6], [0, 0, 0, 0]], [
                gg.UniformDistrib(),
                gg.UniformDistrib(),
                gg.UniformDistrib(),
                gg.UniformDistrib()
            ], i)

    # set5 = G.create_nodes(50, {"clustId":5}, 2)
    # G.create_random_edges(	200,
    # 						[set5],
    # 						[[1]],
    # 					    [gg.UniformDistrib()],
    # 					    2)
    # G.create_random_edges(	200,
    # 						[set5],
    # 						[[1]],
    # 					    [gg.UniformDistrib()],
    # 					    3)
    # G.create_random_edges(	100,
    # 						[set5],
    # 						[[1]],
    # 					    [gg.UniformDistrib()],
    # 					    4)

    # learn_parameters(G)

    # cdr = cd.CommunityDetector(G, sorted_results[-1][1]["tr"], sorted_results[-1][1]["h"], sorted_results[-1][1]["d"], sorted_results[-1][1]["p"])
    cdr = cd.CommunityDetector(G, 10, 100, 5, 10000)
    cdr.run(False, False)

    # G.create_random_edges(200, [set1, set2], [[0,1],[0,0]], [gg.UniformDistrib(), gg.UniformDistrib()],4)
    # G.create_random_edges(200, [set1, set2, set3, set4], [[0,0,0,0.5],[0,0,0.5,0],[0,0,0,0],[0,0,0,0]], [gg.UniformDistrib(), gg.UniformDistrib(), gg.UniformDistrib(), gg.UniformDistrib()],5)
    # G.create_random_edges(400, [set1, set2], [[0.49,0.02],[0.,0.49]], [gg.UniformDistrib(), gg.UniformDistrib()],10)
    # G.plot_sequence()

    # G = gg.Graph(True)
    # set1 = G.create_nodes(100)
    # set2 = G.create_nodes(80)
    # G.create_random_edges(500, [set1, set2], [[0.49,0.01],[0.01,0.49]], [gg.UniformDistrib(), gg.UniformDistrib()])
    # G.plot_sequence()

    # tree = st.SegmentTree()
    # elements = [(0,5),(0,5),(0,10),(0,7),(5,10),(15,20),(12,st.SegmentTree.infinite)]

    # for i in range(len(elements)):
    # 	tree.insert(i, elements[i])

    # # query = [0,3,5,7,11,12,20,98]
    # # for q in query:
    # # 	print "query=",q," - result=",tree.query(q)
    # # 	pdb.set_trace()

    # to_delete = range(len(elements))
    # random.shuffle(to_delete)
    # print to_delete
    # for d in to_delete:
    # 	tree.delete(d, elements[d])
    # 	print "query=",elements[d][1]," - result=",tree.query(elements[d][1])
    # 	pdb.set_trace()
Exemplo n.º 3
0
def main(factor):
    G = gg.Graph()
    set1 = G.create_nodes(200, {"clustId": 1}, 0)
    set2 = G.create_nodes(200, {"clustId": 2}, 0)
    set3 = G.create_nodes(200, {"clustId": 2}, 0)
    set4 = G.create_nodes(50, {"clustId": 4}, 0)
    set5 = G.create_nodes(50, {"clustId": 5}, 0)

    for i in range(4):
        G.create_random_edges(
            500 * factor, [set1, set2, set3, set4, set5],
            [[0.303, 0.005, 0.005, 0.001, 0.001],
             [0, 0.17, 0.24, 0.001, 0.001], [0, 0, 0.17, 0.001, 0.001],
             [0, 0, 0, 0.05, 0.001], [0, 0, 0, 0, 0.05]], [
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib()
             ], i)

    for i in range(4, 7):
        G.create_random_edges(
            40 * factor, [set1, set2, set3, set4, set5],
            [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
             [0, 0, 0, 0, 1], [0, 0, 0, 0, 0]], [
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib()
             ], i)

    for i in range(7, 9):
        G.delete_random_edges(
            200 * factor, [set1, set2, set3, set4, set5],
            [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], [
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib(),
                 gg.UniformDistrib()
             ], i)

    G.delete_random_edges(0, [set1, set2, set3, set4, set5],
                          [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0],
                           [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], [
                               gg.UniformDistrib(),
                               gg.UniformDistrib(),
                               gg.UniformDistrib(),
                               gg.UniformDistrib(),
                               gg.UniformDistrib()
                           ], 9)

    # for i in range(9,14):
    # 	G.delete_random_edges(	40*factor,
    # 							[set1, set2, set3, set4, set5],
    # 							[[0   ,0   ,0   ,0   ,0   ],
    # 							 [0   ,0   ,1   ,0   ,0   ],
    # 							 [0   ,0   ,0   ,0   ,0   ],
    # 							 [0   ,0   ,0   ,0   ,0   ],
    # 							 [0   ,0   ,0   ,0   ,0   ]],
    # 							[gg.UniformDistrib(), gg.UniformDistrib(), gg.UniformDistrib(), gg.UniformDistrib(), gg.UniformDistrib()],
    # 						    i)

    cdr = cd.CommunityDetector(G, 10, 100, 5, 10000)
    cdr.run(True, True, False, 0, 4)

    G.update_nodes(set5, {"clustId": 4})
    cdr.run(True, True, False, 4, 7)

    G.update_nodes(set3, {"clustId": 3})
    cdr.run(True, True, False, 7, 12)