Implement the gradient descent