standard gradient descent + r2bugs code based on relevant article.