Clustering data through an analogy to the Potts model