ANN cost function with gradient commented