A formalization of cluster analysis, and gravitational clustering