Beispiel #1
0
def compute_cfinder(n_vertex, edge_list, clique_size):
    g, weights = tf.compute_igraph_form(n_vertex, edge_list)

    t = time.time()
    clst = map(set, g.maximal_cliques(min=clique_size))

    if len(clst) == 0:
        clusters = []
        labels = xrange(n_vertex)
        for i in xrange(n_vertex):
            clusters.append(set([i]))
        exectime = time.time() - t
        return [labels, clusters, exectime]

    edgelist = []
    for i, j in combinations(range(len(clst)), 2):
        if len(clst[i].intersection(clst[j])) >= clique_size - 1:
            edgelist.append((i, j))
    cg = ig.Graph()
    cg.add_vertices(len(clst))
    cg.add_edges(edgelist)

    components = cg.clusters()

    clusters = []
    for component in components:
        cluster = set()
        for i in component:
            cluster.update(clst[i])
        clusters.append(cluster)
    exectime = time.time() - t

    labels = None

    return labels, clusters, exectime
Beispiel #2
0
def compute_modularity(labels_pred, edge_list):

	n_vertex = len(labels_pred)
	import igraph as ig
	from transform_functions import compute_igraph_form
	graph, weights = compute_igraph_form(n_vertex, edge_list);

	return graph.modularity(labels_pred, weights=weights)
Beispiel #3
0
def compute_lpa(n_vertex, edge_list):
    graph, weights = tf.compute_igraph_form(n_vertex, edge_list)

    t = time.time()
    clusters = graph.community_label_propagation(weights=weights, initial=None, fixed=None)
    exectime = time.time() - t

    labels = tf.compute_labels_from_clusters(n_vertex, clusters)

    return labels, clusters, exectime
Beispiel #4
0
def compute_walktrap(n_vertex, edge_list, n_clusters, n_steps):
    graph, weights = tf.compute_igraph_form(n_vertex, edge_list)

    t = time.time()
    dendrogram = graph.community_walktrap(weights, n_steps)
    clusters = dendrogram.as_clustering(n=n_clusters)
    exectime = time.time() - t

    labels = tf.compute_labels_from_clusters(n_vertex, clusters)

    return labels, clusters, exectime
Beispiel #5
0
def compute_clauset_newman(n_vertex, edge_list, n_clusters):

    graph, weights = tf.compute_igraph_form(n_vertex, edge_list)

    t = time.time()
    dendrogram = graph.community_fastgreedy(weights)
    clusters = dendrogram.as_clustering(n=n_clusters)
    exectime = time.time() - t

    labels = tf.compute_labels_from_clusters(n_vertex, clusters)

    return labels, clusters, exectime