fixed output layer gradient calculations