The Kernel Trick for Distances