% all function parameters are passed by reference (c++ style) % |
% prm implies Function Parameter % |
% Apply (traditional) -means Algorithm on the transition time data-set |
(the initial cluster centers are stored in Clus_Avg) % |
() var repeat_ _means = true; % repeat until a condition is met % |
() do % classify the samples according to the nearest mean |
(the sorted mean values are stored in Clus_Avg) % |
% in other words, split the array into partitions based on the distance from |
nearest mean (note: Time_Array is also a sorted array) % |
() var temp = 0; |
() for to do % calculate the distances from the centres % |
() var dist1 = Time_Array − Clus_Avgtemp; |
() var dist2 = Time_Array − Clus_Avgtemp + 1; |
() if dist1 > dist2 then % determine the new splitting positions % |
() Postemp = ; temp = temp + 1; |
() if temp == () then break; % exit the loop % |
end for |
() declare Old_Clus_Avg % stores the means of the previous iteration % |
() for to do % shift the mean values to Old_Clus_Avg % |
() Old_Clus_Avg] = Clus_Avg]; Clus_Avg = 0 |
end for |
% calculate the means of the (new) clusters and store them in Clus_Avg % |
() for to do |
() var temp1 = −1; var temp2 = −1; |
() if then |
() temp1 = 0; temp2 = Pos; |
() else if then |
() temp1 = Pos; temp2 = Pos; |
() else |
() temp1 = Pos; temp2 = ; |
() for = temp1 to temp2 do |
() Clus_Avg = Clus_Avg + Time_Array; |
end for |
() if Clus_Avg then |
() Clus_Avg = Clus_Avg/(temp2 − temp1 + 1); |
end for |
() repeat__means = false; |
() for to do |
() if Clus_Avg − Old_Clus_Avg > (very small) threshold value |
then % refers that the cluster means are significantly different % |
() repeat__means = true; break; % another iteration % |
end for |
() while repeat__means ≠ false % termination condition % |
% note: _Means_Algorithm() only updates the mean values |
(stored in Clus_Avg) and the array splitting positions (stored in Pos) % |