First gradient descent implementation