Gradient descent with termination criterion and repeater.py