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 |
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 |
Iterates over the clusters and formats them into a string to be presented in the summary. |
Instance Variable | _clusters |
Undocumented |
Instance Variable | _n |
Undocumented |
igraph.clustering.VertexCover
Constructs a cover with the given clusters.
Parameters | |
clusters | the 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. |
n | the 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. |
Returns the histogram of cluster sizes.
Parameters | |
bin | the bin width of the histogram |
Returns | |
a Histogram object |
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.
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 | |
verbosity | determines whether the cluster members should be printed. Zero verbosity prints the number of items and clusters only. |
width | Undocumented |
Returns | |
the summary of the cover as a string. |
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.
igraph.clustering.VertexCover
Iterates over the clusters and formats them into a string to be presented in the summary.