How to use the igraph.VertexCover function in igraph

To help you get started, we’ve selected a few igraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Lab41 / Circulo / circulo / data / amazon / run.py View on Github external
def get_ground_truth(self, G):

        cluster_dict = {}

        for idx, cluster_str in enumerate(G.vs()['groundtruth_str']):
            for c in  cluster_str.split():
                if c not in cluster_dict:
                    cluster_dict[c] = []

                #have to re-do this since id's likely changed by removing isolates
                cluster_dict[c].append(idx)

        return  ig.VertexCover(G,[v for v in cluster_dict.values()])
github Lab41 / Circulo / circulo / data / house_voting / run.py View on Github external
def get_ground_truth(self, G):

        cluster_list = [[],[],[]]

        for vertex_id, party in enumerate(G.vs['party']):
            cluster_list[self.__party_to_cluster__(party)].append(vertex_id)

        return VertexCover(G, cluster_list)
github Lab41 / Circulo / circulo / algorithms / congo.py View on Github external
# Just in case the original graph is disconnected
    if not G.is_connected():
        raise RuntimeError("Congo only makes sense for connected graphs.")

    # initializing attributes of copied graph
    G.vs['CONGA_orig'] = [i.index for i in OG.vs]
    G.es['eb'] = 0
    G.vs['pb'] = [{uw : 0 for uw in itertools.combinations(G.neighbors(vertex), 2)} for vertex in G.vs]

    # initializing all pair and edge betweennesses
    do_initial_betweenness(G, h)
    nClusters = 1

    # The first cover is simply the entire connected graph.
    allCovers = {nClusters : ig.VertexCover(OG)}
    while G.es:

        logging.info("%d edges remaining", len(G.es))
        # get the edge with the max edge betweenness, and its betweenness.
        maxEdge, maxEb = max(enumerate(G.es['eb']), key=operator.itemgetter(1))
        G.vs['vb'] = G.betweenness(cutoff=h)

        # since split betweennes is upper bounded by vertex betweenness, we
        # only need to look at the vertices for which the vertex betweenness
        # is greater than the max edge betweenness. (We multiply by 2
        # because our edge betweenness calculations yield values in both
        # directions.)

        # TODO check if I need to multiply by 2
        vInteresting = [i for i, b in enumerate(G.vs['vb']) if 2 * b > maxEb]
github Lab41 / Circulo / circulo / data / flights / run.py View on Github external
def get_ground_truth(self, G):
        """
        This Ground Truth is the country of the airport
        """

        if G is None:
            return

        cluster_dict = defaultdict(list)

        for airport_id, airport_location in enumerate(G.vs['country']):
            cluster_dict[airport_location].append(airport_id)

        return VertexCover(G, [v for v in cluster_dict.values()]
)
github Lab41 / Circulo / circulo / setup / run_algos.py View on Github external
Returns:
        VertexCover.

    Raises:
        Exception if the input is of an unrecognized type
    '''

    cover = None
    if isinstance(result, igraph.VertexClustering):
        cover = result.as_cover()
    elif isinstance(result, igraph.VertexDendrogram):
        cover = result.as_clustering().as_cover()
    elif isinstance(result,CrispOverlap):
        cover = result.as_cover()
    elif isinstance(result, igraph.VertexCover):
        cover = result
    else:
        raise Exception("Algorithm output type not recognized")
    return cover
github Lab41 / Circulo / circulo / algorithms / conga.py View on Github external
Defines the CONGA algorithm outlined in the Gregory 2007 paper
    (An Algorithm to Find Overlapping Community Structure in Networks)

    Returns a CrispOverlap object of all of the covers.
    """

    G = OG.copy()

    comm = G.components()

    # Just in case the original graph is disconnected
    nClusters = len(comm)

    # Store the original ids of all vertices
    G.vs['CONGA_orig'] = [i.index for i in OG.vs]
    allCovers = {nClusters : ig.VertexCover(OG)}
    while G.es:
        split = remove_edge_or_split_vertex(G)
        if split:
            comm = G.components().membership
            cover = get_cover(G, OG, comm)
            nClusters += 1
            # short circuit stuff would go here.
            allCovers[nClusters] = cover
    if calculate_modularities is None: calculate_modularities = "lazar"
    return circulo.algorithms.overlap.CrispOverlap(OG, allCovers,
                                    modularity_measure=calculate_modularities,
                                    optimal_count=optimal_count)
github Lab41 / Circulo / circulo / metrics / cover.py View on Github external
dot_str = '.' * num_dots
            if(k != "Subgraphs"):
                print("{}{}{}".format(k, dot_str,v[cover_id]))
            else:
                print("Subgraph_____")
                #for k,v in v.items():
                #    print("{}...".format(k))
                for i in v:
                    print(i)

Cover.fraction_over_median_degree = fomd
VertexCover.metrics = None
VertexCover.metrics_stats = None
VertexCover.print_metrics = print_metrics
VertexCover.compare_omega = compare_omega
VertexCover.compute_metrics = compute_metrics
VertexCover.external_edges = external_edges
VertexCover.expansion = expansion
VertexCover.cut_ratio = cut_ratio
VertexCover.conductance = conductance
VertexCover.normalized_cut = normalized_cut
VertexCover._out_degree_fraction = out_degree_fraction
VertexCover.maximum_out_degree_fraction = maximum_out_degree_fraction
VertexCover.average_out_degree_fraction = average_out_degree_fraction
VertexCover.flake_out_degree_fraction = flake_out_degree_fraction
VertexCover.separability = separability
github Lab41 / Circulo / circulo / data / senate_voting / run.py View on Github external
def get_ground_truth(self, G):

        cluster_list = [[],[],[]]

        for vertex_id, party in enumerate(G.vs['party']):
            cluster_list[self.__party_to_cluster__(party)].append(vertex_id)

        return VertexCover(G, cluster_list)
github Lab41 / Circulo / experiments / run_omega.py View on Github external
def cover_from_membership(membership, G):

    if(membership is None):
        return None

    cluster_dict = {}

    for vertex_id, cluster_id_list in enumerate(membership):
        for cluster_id in cluster_id_list:
            if(cluster_id not in cluster_dict):
                cluster_dict[cluster_id] = []
            cluster_dict[cluster_id].append(vertex_id)

    return VertexCover(G, [v for v in cluster_dict.values()])