fix bug for variational methods