kmeans-like method