Finished cost function for neural networks