added general train till convergence method for neural network layers