Computes all the average distances to the center in each cluster.
Computes the overall distance of the samples from their respective cluster centers.
Compute the pairwise distances ‘pair_dists’, between every two clusters centers and returns them sorted. Returns:
a list with tuples, where every tuple has in it’s first coord the distance between to clusters, and in the second coord has a tuple, with the numbers of the clusters measured. Output example:
(d2,(cluster_3,cluster_4)), ... (dn, (cluster_n,cluster_n+1))]
Discard clusters with fewer than THETA_M.
Define initial clusters centers as startup. By default, the method is “linspace”. Other method available is “random”.
Auxiliar function to set default values to all the parameters not given a value by the user.
Classify a numpy ‘img’ using Isodata algorithm. Parameters: a dictionary with the following keys.
img: an input numpy array that contains the image to classify.
parameters: a dictionary with the initial values. If ‘parameters’ are not specified, the algorithm uses the default ones.
- number of clusters desired. K = 15
- max number of iterations. I = 100
- max number of pairs of clusters which can be ,erged. P = 2
- threshold value for min number in each cluster. THETA_M = 10
- threshold value for standard deviation (for split). THETA_S = 0.1
- threshold value for pairwise distances (for merge). THETA_C = 2
- threshold change in the clusters between each iter. THETA_O = 0.01
- Note: if some(or all) parameters are nos providen, default values
- will be used.
Merge by pair of clusters in ‘below_threshold’ to form new clusters.
Stop algorithm by low change in the clusters values between each iteration.
|Returns:||True if should stop, otherwise False.|
Sort the array ‘centers’ and the with indices of the sorted centers order the array ‘clusters_list’. Example: centers=[22, 33, 0, 11] and cluster_list=[7,6,5,4] returns (array([ 0, 11, 22, 33]), array([5, 4, 7, 6]))
Split clusters to form new clusters.
Stop algorithm if there is no change in the clusters values between each iteration.
Define initial clusters centers as startup.
By default, the method is “linspace”. Other method available is “random”.
Classify a numpy ‘image’ according K-means algorithm.
Update the cluster center, computing the mean of all cluster members.