added epsilon as input
changed distance to affinity