Constrained Empirical Risk Minimization: Theory and Practice