Approximate Inference and Constrained Optimization