python-igraph manual

For using igraph from Python

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

Class Clustering

source code

object --+
         |
        Clustering
Known Subclasses:

Class representing a clustering of an arbitrary ordered set.

This is now used as a base for VertexClustering, but it might be useful for other purposes as well.

Members of an individual cluster can be accessed by the [] operator:

>>> cl = Clustering([0,0,0,0,1,1,1,2,2,2,2])
>>> cl[0]
[0, 1, 2, 3]

The membership vector can be accessed by the membership property:

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

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

>>> len(cl)
3

You can iterate over the clustering object 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
4 5 6
7 8 9 10

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

>>> cluster_list = list(cl)
>>> print cluster_list
[[0, 1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
Instance Methods [hide private]
 
__init__(self, membership, params=None)
Constructor.
source code
 
__getitem__(self, idx)
Returns the members of the specified cluster.
source code
 
__iter__(self)
Iterates over the clusters in this clustering.
source code
 
__len__(self)
Returns the number of clusters.
source code
 
__str__(self)
str(x)
source code
 
as_cover(self)
Returns a Cover that contains the same clusters as this clustering.
source code
 
compare_to(self, other, *args, **kwds)
Compares this clustering to another one using some similarity or distance metric.
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 clustering.
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.
  n
Returns the number of elements covered by this clustering.

Inherited from object: __class__

Method Details [hide private]

__init__(self, membership, params=None)
(Constructor)

source code 

Constructor.

Parameters:
  • membership - the membership list -- that is, the cluster index in which each element of the set belongs to.
  • params - additional parameters to be stored in this object's dictionary.
Overrides: object.__init__

__getitem__(self, idx)
(Indexing operator)

source code 

Returns the members of the specified cluster.

Parameters:
  • idx - the index of the cluster
Returns:
the members of the specified cluster as a list
Raises:
  • IndexError - if the index is out of bounds

__iter__(self)

source code 

Iterates over the clusters in this clustering.

This method will return a generator that generates the clusters one by one.

__len__(self)
(Length operator)

source code 

Returns the number of clusters.

Returns:
the number of clusters

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

compare_to(self, other, *args, **kwds)

source code 

Compares this clustering to another one using some similarity or distance metric.

This is a convenience method that simply calls compare_communities with the two clusterings as arguments. Any extra positional or keyword argument is also forwarded to compare_communities.

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 clustering.

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 clustering as a string.

Property Details [hide private]

membership

Returns the membership vector.

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

n

Returns the number of elements covered by this clustering.

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

   Home       Trees       Indices       Help