python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Module clustering :: Class Cover
[hide private]

Class Cover

source code

object --+
         |
        Cover
Known Subclasses:

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
Instance Methods [hide private]
 
__init__(self, clusters, n=0)
Constructs a cover with the given clusters.
source code
 
__getitem__(self, index)
Returns the cluster with the given index.
source code
 
__iter__(self)
Iterates over the clusters in this cover.
source code
 
__len__(self)
Returns the number of clusters in this cover.
source code
 
__str__(self)
Returns a string representation of the cover.
source code
 
size(self, idx)
Returns the size of a given cluster.
source code
 
sizes(self, *args)
Returns the size of given clusters.
source code
 
size_histogram(self, bin_width=1)
Returns the histogram of cluster sizes.
source code
 
summary(self, verbosity=0, width=None)
Returns the summary of the cover.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]
  membership
Returns the membership vector of this cover.
  n
Returns the number of elements in the set covered by this cover.

Inherited from object: __class__

Method Details [hide private]

__init__(self, clusters, n=0)
(Constructor)

source code 

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.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Returns a string representation of the cover.

Overrides: object.__str__

size(self, idx)

source code 

Returns the size of a given cluster.

Parameters:
  • idx - the cluster in which we are interested.

sizes(self, *args)

source code 

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.

size_histogram(self, bin_width=1)

source code 

Returns the histogram of cluster sizes.

Parameters:
  • bin_width - the bin width of the histogram
Returns:
a Histogram object

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

source code 

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.
Returns:
the summary of the cover as a string.

Property Details [hide private]

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.

Get Method:
unreachable.membership(self) - Returns the membership vector of this cover.

n

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

Get Method:
unreachable.n(self) - Returns the number of elements in the set covered by this cover.

   Home       Trees       Indices       Help