title: How to add noise to gradient descent?
body: <p>I have the following code where I have implemented gradient descent for a function using pyTorch. How do I add noise to the code so that it identifies both local minima?</p>
  <pre><code>import torch
  
  
  startVal = -5.0
  alpha = 0.001
  space = &quot; &quot;
  progressionCheck = True 
  
  x = torch.tensor(startVal, requires_grad=True)
  
  def function(a):
      f = a**4 - a**3 - a**2 + a - 1
      return f
  
  for i in range(1000):
      function(x).backward()
      newVal = x - alpha * (x.grad)
      progressionCheck = function(newVal) &lt; function(startVal)
      x = newVal.detach().clone().requires_grad_()
      print(x)
  
  print(&quot;The minimum value occurs at&quot; + space + str(float(x)))
  print(&quot;The minimum value is&quot; + space + str(function(float(x))))
  </code></pre>