Esempio n. 1
0
def exp2(name, step, max_partition):
    gzip_fname = utils.get_gzip_fname(name)
    s = network.Network.from_combined(name, gzip_fname)
    graph = s.graph
    graph_info = GraphInfo(graph)
    p = Partitioner(graph)
    exp2_impl(name, graph_info, p, max_partition, step)
Esempio n. 2
0
def exp1(name, step):
    exp1_info = {}
    gzip_fname = utils.get_gzip_fname(name)
    s = network.Network.from_combined(name, gzip_fname)
    graph = s.graph
    p = Partitioner(s.graph)
    cd_s = time.time()
    cd_partition = p.community_detection()
    exp1_info['community_detection'] = duration(cd_s)
    parts = len(cd_partition)
    exp1_info['parts'] = parts
    metis_s = time.time()
    metis_partition = p.metis_partition(parts)
    exp1_info['metis'] = duration(metis_s)
    random_s = time.time()
    rnd_partition = p.random_partition(parts)
    exp1_info['rnd'] = duration(random_s)
    graph_info = GraphInfo(graph)
    partitions = [cd_partition, metis_partition, rnd_partition]
    exp1_impl(name, graph_info, p, partitions, step)
    return exp1_info
Esempio n. 3
0
                for l in gzip_data:
                    edges = [int(e) for e in l.split()]
                    assert len(edges) == 2
                    G.add_edge(*edges)
            with open(pickle_file, "wb") as pickle_data:
                pickle.dump(G, pickle_data)
        return cls(G)

    @classmethod
    def from_ego(cls, name, ego_list):
        if utils.graph_directness[name]:
            G = nx.DiGraph()
        else:
            G = nx.Graph()
        for ego_id in ego_list:
            ego_graph = ego.Ego(name, ego_id)
            ego_graph.graph_generator()
            graph = ego_graph.graph
            G.add_nodes_from(graph.nodes())
            G.add_edges_from(graph.edges())
        return cls(G)


if __name__ == "__main__":
    log_helper.init_logger()
    name = "facebook"
    ego_list = utils.collect_ego_list(name)
    gzip_fname = utils.get_gzip_fname(name)
    social = Network.from_combined(name, gzip_fname)
    g_info = graph_info.GraphInfo(social.graph)
Esempio n. 4
0
        total = 0
        for node_id in note_set:
            local_set_size = self.get_local_set(partition_list, node_id)
            local += len(local_set_size)
            total += len(self.graph.neighbors(node_id))
        return float(local) / float(total)

    @staticmethod
    def dump_partition(partition_list):
        for d in partition_list:
            print(d)


if __name__ == "__main__":
    name = "facebook"
    gzip_fname = utils.get_gzip_fname("facebook")
    s = network.Network.from_combined(name, gzip_fname)
    p = Partitioner(s.graph)
    cd_partition = p.community_detection()
    parts = len(cd_partition)
    ego_list = utils.collect_ego_list(name)
    print(ego_list)
    cd_locality = p.locality_percentage(cd_partition, ego_list)
    print(cd_locality)
    metis_partition = p.metis_partition(parts)
    metis_locality = p.locality_percentage(metis_partition, ego_list)
    print(metis_locality)
    rnd_partition = p.random_partition(parts)
    rnd_locality = p.locality_percentage(rnd_partition, ego_list)
    print(rnd_locality)