clustering function

Clustering algorithm.