Convergent approximate message passing by alternating constrained minimization of bethe free energy