K-medoids[PAM algorithm]

K-medoids method needs to compare the distance between two points in the data set, so time complexity is so enormous. To avoid the time complexity issue, we can use PAM algorithm.

PAM: Partition Around Medoids.

[ Notation ]

  • OO: The set of whole objects.

  • SS : The set of selected objects.

  • UU : The set of unselected objects

  • DpD_p: The dissimilarity between ppand the closest object in SS

  • EpE_p: The dissimilarity between ppand the second closet object in SS

U = O - S

[ Process ]

BUILD PHASE

  1. [Initialization] Put the point for which the sum of the distances to all other objects is minimal into set S

  2. Fori∈Ui \in U, consider it as a candidate for SS

  3. For j∈U−{i}j\in U-\{i\}, compute DjD_j

  4. If Dj>d(i,j) D_j > d(i, j)select object ii, let Cji=max{Dj−d(j,i),0}C_{ji}=max\{D_j-d(j,i),0\}

  5. Compute the total gain. gi=∑j∈UCjg_i = \sum_{j\in U} C_{j}

  6. Choose that object iithat maximizes gig_i

  7. Let S:=S∪{i}S := S \cup \{i\}and U=U−{i}U = U-\{i\}

  8. Repeat 1-7 until kkobjects have been selected.

SWAP PHASE

This phase is the step switching the element in SS to one in UU(The other way around also). It improves the quality of the clustering.

Considers all pairs (i,h)∈S×U(i,h) \in S \times U

If d(j,i)>Djd(j,i) > D_j

  1. if d(j,h)≥Djd(j,h) \geq D_j, then Kjih=0K_{jih}=0

  2. if d(j,h)<Djd(j,h) < D_j, then Kjih=d(j,h)−DjK_{jih}=d(j,h)-D_j

In both subcases, Kjih=min{d(j,h)−Dj,0}K_{jih} = min\{d(j,h)-D_j,0\}

If d(j,i)=Djd(j,i)=D_j

  1. if d(j,h)<Ejd(j,h) < E_j, then Kjih=d(j,h)−DjK_{jih} = d(j,h)-D_j(KK can be negative)

  2. if d(j,h)≥Ejd(j,h) \geq E_j, then Kjih=Ej−DjK_{jih} = E_j-D_j ( K>0K > 0 )

In both subcases, Kjih=min{d(j,h),Ej}−DjK_{jih} = min\{d(j,h),E_j\}-D_j

  1. Compute the total result of swap as Tih=∑{Kijh∣j∈U}T_{ih}=\sum\{K_{ijh} | j\in U\}

  2. Select a pair (i,h)∈S×U(i,h) \in S \times U that minimizes TihT_{ih}

  3. If Tih<0 T_{ih}<0, the swap is carried out and DpD_pandEpE_pare updated for every object pp. After it, return to Step1. If minTih>0minT_{ih}>0, the algorithm halts. (All Tih>0T_{ih}>0 is also the halting condition.)

Time complexity of numpy expend_dims is much bigger than using for statement.

ref: https://www.cs.umb.edu/cs738/pam1.pdf

Last updated

Was this helpful?