python-igraph API reference

List of all classes, functions and methods in python-igraph

class documentation

class Cover:

Known subclasses: igraph.clustering.VertexCover

View In Hierarchy

Class representing a cover of an arbitrary ordered set.

Covers are similar to clusterings, but each element of the set may belong to more than one cluster in a cover, and elements not belonging to any cluster are also allowed.

Cover instances provide a similar API as Clustering instances; for instance, iterating over a Cover will iterate over the clusters just like with a regular Clustering instance. However, they are not derived from each other or from a common superclass, and there might be functions that exist only in one of them or the other.

Clusters of an individual cover can be accessed by the [] operator:

>>> cl = Cover([[0,1,2,3], [2,3,4], [0,1,6]])
>>> cl[0]
[0, 1, 2, 3]

The membership vector can be accessed by the membership property. Note that contrary to Clustering instances, the membership vector will contain lists that contain the cluster indices each item belongs to:

>>> cl.membership
[[0, 2], [0, 2], [0, 1], [0, 1], [1], [], [2]]

The number of clusters can be retrieved by the len function:

>>> len(cl)
3

You can iterate over the cover as if it were a regular list of clusters:

>>> for cluster in cl:
...     print(" ".join(str(idx) for idx in cluster))
...
0 1 2 3
2 3 4
0 1 6

If you need all the clusters at once as lists, you can simply convert the cover to a list:

>>> cluster_list = list(cl)
>>> print(cluster_list)
[[0, 1, 2, 3], [2, 3, 4], [0, 1, 6]]

Clustering objects can readily be converted to Cover objects using the constructor:

>>> clustering = Clustering([0, 0, 0, 0, 1, 1, 1, 2, 2, 2])
>>> cover = Cover(clustering)
>>> list(clustering) == list(cover)
True
Method __getitem__ Returns the cluster with the given index.
Method __init__ Constructs a cover with the given clusters.
Method __iter__ Iterates over the clusters in this cover.
Method __len__ Returns the number of clusters in this cover.
Method __str__ Returns a string representation of the cover.
Method size Returns the size of a given cluster.
Method size_histogram Returns the histogram of cluster sizes.
Method sizes Returns the size of given clusters.
Method summary Returns the summary of the cover.
Property membership Returns the membership vector of this cover.
Property n Returns the number of elements in the set covered by this cover.
Method _formatted_cluster_iterator Iterates over the clusters and formats them into a string to be presented in the summary.
Instance Variable _clusters Undocumented
Instance Variable _n Undocumented
def __getitem__(self, index):

Returns the cluster with the given index.

def __init__(self, clusters, n=0):

Constructs a cover with the given clusters.

Parameters
clustersthe clusters in this cover, as a list or iterable. Each cluster is specified by a list or tuple that contains the IDs of the items in this cluster. IDs start from zero.
nthe total number of elements in the set that is covered by this cover. If it is less than the number of unique elements found in all the clusters, we will simply use the number of unique elements, so it is safe to leave this at zero. You only have to specify this parameter if there are some elements that are covered by none of the clusters.
def __iter__(self):

Iterates over the clusters in this cover.

def __len__(self):

Returns the number of clusters in this cover.

def __str__(self):

Returns a string representation of the cover.

def size(self, idx):

Returns the size of a given cluster.

Parameters
idxthe cluster in which we are interested.
def size_histogram(self, bin_width=1):

Returns the histogram of cluster sizes.

Parameters
bin_widththe bin width of the histogram
Returns
a Histogram object
def sizes(self, *args):

Returns the size of given clusters.

The indices are given as positional arguments. If there are no positional arguments, the function will return the sizes of all clusters.

def summary(self, verbosity=0, width=None):

Returns the summary of the cover.

The summary includes the number of items and clusters, and also the list of members for each of the clusters if the verbosity is nonzero.

Parameters
verbositydetermines whether the cluster members should be printed. Zero verbosity prints the number of items and clusters only.
widthUndocumented
Returns
the summary of the cover as a string.
@property
membership =

Returns the membership vector of this cover.

The membership vector of a cover covering n elements is a list of length n, where element i contains the cluster indices of the ith item.

@property
n =

Returns the number of elements in the set covered by this cover.

def _formatted_cluster_iterator(self):

Iterates over the clusters and formats them into a string to be presented in the summary.

_clusters =

Undocumented

_n =

Undocumented