change NaN bug in CosineDistanceMetric