Implemented training function for neural net.