title: How to properly stop iteration in minimization in Python?
body: <p>I am posting this question because, my code is not stopping iteration at the right place. Could anyone make me sure what is wrong?</p>
  
  <p>Everything is working properly (as I always think which is mistake in reality..)</p>
  
  <p><strong>Question:</strong> </p>
  
  <p><strong>1)</strong> In each iteration, I am minimizing Unfortunately, it is not minimizing correctly (very poor result). Am I stopping iteration correctly in minimization process? Any suggestions?</p>
  
  <p><strong>Just run the following code:</strong></p>
  
  <pre><code>import numpy as np
  from scipy.stats import stats
  def run_iter():
      # Initial guess
      x_new = x0
      # just to pretend we have huge error
      phi0 = 1e20
      for i in range(iter_num):
           # first solution
           x_next = x_new
  
           # FIRST WAY
           # First assumption to stop the iteration...
  
           # SECOND WAY
           '''
           # Second assumption to stop the iteration
           '''
      return x_new
  
  def example_run():
  
  if __name__ == '__main__':
      print example_run()
  </code></pre>