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, 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]]
||Returns the members of the specified cluster.|
||Iterates over the clusters in this clustering.|
||Returns the number of clusters.|
||Compares this clustering to another one using some similarity or distance metric.|
||Returns the size of a given cluster.|
||Returns the histogram of cluster sizes.|
||Returns the size of given clusters.|
||Returns the summary of the clustering.|
||Returns the membership vector.|
||Returns the number of elements covered by this clustering.|
||Iterates over the clusters and formats them into a string to be presented in the summary.|
Returns the members of the specified cluster.
|idx||the index of the cluster|
|the members of the specified cluster as a list|
|if the index is out of bounds|
|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.|
Iterates over the clusters in this clustering.
This method will return a generator that generates the clusters one by one.
Returns the number of clusters.
|the number of clusters|
Returns the size of a given cluster.
|idx||the cluster in which we are interested.|
Returns the histogram of cluster sizes.
|bin||the bin width of the histogram|
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 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.
|verbosity||determines whether the cluster members should be printed. Zero verbosity prints the number of items and clusters only.|
|the summary of the clustering as a string.|
membership = ¶
Returns the membership vector.
n = ¶
Returns the number of elements covered by this clustering.
Iterates over the clusters and formats them into a string to be presented in the summary.