A distance function for stochastic matrices