Fixed bug in grad_logpy calculation.