@@ -32,6 +32,12 @@ class HierarchicalClustering(BaseClusterMethod):
3232 Implementation of the hierarchical clustering method as explained in a
3333 tutorial_ by *matteucc*.
3434
35+ Object prerequisites:
36+
37+ * Items must be sortable (See `issue #11`_)
38+ * Items must be hashable.
39+
40+ .. _issue #11: https://github.com/exhuma/python-cluster/issues/11
3541 .. _tutorial: http://www.elet.polimi.it/upload/matteucc/Clustering/tutorial_html/hierarchical.html
3642
3743 Example:
@@ -48,13 +54,20 @@ class HierarchicalClustering(BaseClusterMethod):
4854
4955 See :py:class:`~cluster.method.base.BaseClusterMethod` for more details.
5056
57+ :param data: The collection of items to be clustered.
58+ :param distance_function: A function which takes two elements of ``data``
59+ and returns a distance between both elements.
5160 :param linkage: The method used to determine the distance between two
5261 clusters. See :py:meth:`~.HierarchicalClustering.set_linkage_method` for
53- the available methods .
62+ possible values .
5463 :param num_processes: If you want to use multiprocessing to split up the
5564 work and run ``genmatrix()`` in parallel, specify num_processes > 1 and
5665 this number of workers will be spun up, the work split up amongst them
5766 evenly.
67+ :param progress_callback: A function to be called on each iteration to
68+ publish the progress. The function is called with two integer arguments
69+ which represent the total number of elements in the cluster, and the
70+ remaining elements to be clustered.
5871 """
5972
6073 def __init__ (self , data , distance_function , linkage = None , num_processes = 1 ,
@@ -70,15 +83,24 @@ def __init__(self, data, distance_function, linkage=None, num_processes=1,
7083 self .__cluster_created = False
7184
7285 def publish_progress (self , total , current ):
86+ """
87+ If a progress function was supplied, this will call that function with
88+ the total number of elements, and the remaining number of elements.
89+
90+ :param total: The total number of elements.
91+ :param remaining: The remaining number of elements.
92+ """
7393 if self .progress_callback :
7494 self .progress_callback (total , current )
7595
7696 def set_linkage_method (self , method ):
7797 """
7898 Sets the method to determine the distance between two clusters.
7999
80- :param method: The name of the method to use. It must be one of
81- ``'single'``, ``'complete'``, ``'average'`` or ``'uclus'``.
100+ :param method: The method to use. It can be one of ``'single'``,
101+ ``'complete'``, ``'average'`` or ``'uclus'``, or a callable. The
102+ callable should take two collections as parameters and return a
103+ distance value between both collections.
82104 """
83105 if method == 'single' :
84106 self .linkage = single
0 commit comments