implemented some of the analytic gradients