added gradient for denominator of 3rd order diagonal stats, plus improvements to numerator gradient computation