Implements EMD, too slow to be useful.