function [ c, ptoc ] = wkm ( dim, n, p, w, k )

%% WKM carries out the weighted K-Means algorithm.
%

%
%  Initialize the cluster centers.
%
  c = kmeans_initialize ( dim, n, p, k );
%
%  Repeatedly update clusters and centers til no change.
%
  v = -1;
  while ( 1 )

    ptoc = kmeans_update_clusters ( dim, n, p, k, c );

    c = wkmeans_update_centers ( dim, n, p, w, k, ptoc );

    v_old = v;
    v = wkmeans_variance ( dim, n, p, w, k, c, ptoc );

    if ( v == v_old )
      break
    end

  end

  return
end

  
