Skip to main content
. 2015 Apr 29;15(5):10100–10117. doi: 10.3390/s150510100

Algorithm 2. K-medoids algorithm.

Let Δ(x, y) denote the distance between two elements x, y ∈ Σ.
1. Choose an arbitrary partition Inline graphick = {Σk : k = 1,…, K} of Σ and an arbitrary set of medoids Λ = {m(Σk) ∈ Σk : k = 1,…, K}.
2. For every Σk ∈ Inline graphicK, compute the elements that are wrongly classified, i.e., x ∈ Σk satisfying Δ(x, m(Σj)) < Δ(x, m(Σk)) for Σj ≠ Σk. For these elements, update the partition as follows:
∑k′=∑k−{x} and ∑j′=∑j+{x}. The resultant partition is PK′={∑k′:k=1,…,K}.
3. Obtain the medoids set ∧′={m(∑k′):∑k′∈PK′} for the new partition PK′ by solving the following K optimization programs:
  m(∑k′)∈argmin{max{γk:Δ(x,y)≤γk,y∈∑k′}:x∈∑k′},∑k′∈PK′
4. If the medoids set does not change, i.e., if Λ′ = Λ, then the clustering process is completed. Otherwise, do Λ = Λ′, and go to Step 2.