use logsumexp where appropriate