max product inference for factor graph model