implementation of cos distance in KMeansMapper