There’s a quicker way to compute average similarity. Fortunately, it turns out that there is a more efficient way to compute average similarity than actually comparing all document pairs. First, define the centroid document to be the average document, i.e., the result of adding all NDoc vectors and dividing by NDoc. Then the average similarity can also be defined in terms of the distance of each document from this center: