code: def sgd(
      grad, x, callback=None, num_iters=200, step_size=0.1, mass=0.9
  ):
      """Stochastic gradient descent with momentum.
      grad() must have signature grad(x, i), where i is the iteration number.
      """
      velocity = np.zeros(len(x))
      for i in range(num_iters):
          g = grad(x, i)
          if callback:
              callback(x, i, g)
          velocity = mass * velocity - (1.0 - mass) * g
          x = x + step_size * velocity
      return x
  
file_path: autograd/autograd/misc/optimizers.py
imports: from __future__ import absolute_import
  from builtins import range
  import autograd.numpy
  from autograd.misc import flatten
  from autograd.wrap_util import wraps
label_desc: Use image node_id 2 for calling a global function with example usage: sgd(grad, x, callback, num_iters, step_size, mass) and returns: x