Principled algorithms for finding local minima