Perturb-and-max-product: Sampling and learning in discrete energy-based models