gradient descent implemented in R