Code for similarity metrics.