# Infinite loop in inversion

**URL:** <https://simpeg.discourse.group/t/infinite-loop-in-inversion/107>\
**Category:** Potential Fields\
**Created:** [May 24, 2020, 2:33pm UTC](https://simpeg.discourse.group/t/infinite-loop-in-inversion/107 "2020-05-24T14:33:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Alexey](https://simpeg.discourse.group/u/Alexey)\
**Post date:** [May 24, 2020, 2:33pm UTC](https://simpeg.discourse.group/t/infinite-loop-in-inversion/107/1 "2020-05-24T14:33:29Z")

</div>

What might be the reason for repeating iteration #20?

```
opt = Optimization.ProjectedGNCG(maxIter=30, maxIterLS = 20, maxIterCG=20, tolCG = 1e-3)
betaest = Directives.BetaEstimate_ByEig() 
IRLS = Directives.Update_IRLS(f_min_change = 1e-2, maxIRLSiter = 20, minGNiter = 5) 
update_Jacobi = Directives.UpdatePreconditioner()

=============================== Projected GNCG ===============================
  # beta phi_d phi_m f |proj(x-g)-x| LS Comment   
-----------------------------------------------------------------------------
x0 has any nan: 0
   0 2.32e+01 1.30e+06 1.87e+01 1.30e+06 2.03e+02 0              
   1 1.16e+01 1.24e+06 1.19e+03 1.26e+06 1.90e+02 0              
   2 5.81e+00 1.20e+06 4.26e+03 1.22e+06 1.87e+02 0 Skip BFGS  
   3 2.91e+00 1.12e+06 1.45e+04 1.16e+06 1.82e+02 0 Skip BFGS  
   4 1.45e+00 9.89e+05 4.66e+04 1.06e+06 1.76e+02 0 Skip BFGS  
   5 7.26e-01 8.08e+05 1.38e+05 9.08e+05 1.68e+02 0 Skip BFGS  
   6 3.63e-01 5.89e+05 3.57e+05 7.19e+05 1.60e+02 0 Skip BFGS  
   7 1.82e-01 3.77e+05 7.74e+05 5.18e+05 1.53e+02 0 Skip BFGS  
   8 9.08e-02 2.17e+05 1.40e+06 3.44e+05 1.48e+02 0 Skip BFGS  
   9 4.54e-02 1.17e+05 2.17e+06 2.15e+05 1.45e+02 0 Skip BFGS  
  10 2.27e-02 6.02e+04 3.03e+06 1.29e+05 1.42e+02 0 Skip BFGS  
  11 1.13e-02 3.05e+04 3.94e+06 7.53e+04 1.37e+02 0 Skip BFGS  
  12 5.67e-03 1.57e+04 4.84e+06 4.32e+04 1.30e+02 0 Skip BFGS  
  13 2.84e-03 8.33e+03 5.75e+06 2.46e+04 1.20e+02 0 Skip BFGS  
  14 1.42e-03 4.43e+03 6.71e+06 1.39e+04 1.06e+02 0 Skip BFGS  
  15 7.09e-04 2.27e+03 7.77e+06 7.78e+03 9.14e+01 0 Skip BFGS  
  16 3.55e-04 1.09e+03 8.93e+06 4.26e+03 7.49e+01 0 Skip BFGS  
  17 1.77e-04 4.82e+02 1.01e+07 2.28e+03 6.23e+01 0 Skip BFGS  
  18 8.87e-05 1.96e+02 1.12e+07 1.19e+03 5.07e+01 0 Skip BFGS  
Reached starting chifact with l2-norm regularization: Start IRLS steps...
eps_p: 0.4993707616846184 eps_q: 0.4993707616846184
delta phim: 1.304e+06
  19 4.43e-05 7.53e+01 2.18e+07 1.04e+03 3.83e+01 0 Skip BFGS  
Beta search step
  19 9.36e-05 7.53e+01 2.18e+07 2.11e+03 6.46e+01 0 Skip BFGS  
Beta search step
  19 6.28e-05 7.53e+01 2.18e+07 1.44e+03 4.79e+01 0              
  20 6.28e-05 9.53e+01 2.12e+07 1.43e+03 4.95e+01 0 Skip BFGS  
Beta search step
  20 1.03e-04 9.53e+01 2.12e+07 2.29e+03 6.16e+01 0              
Beta search step
  20 6.56e-05 9.53e+01 2.12e+07 1.49e+03 4.98e+01 0              
Beta search step
  20 1.06e-04 9.53e+01 2.12e+07 2.34e+03 6.24e+01 0              
Beta search step
  20 6.62e-05 9.53e+01 2.12e+07 1.50e+03 4.99e+01 0              
Beta search step
  20 1.06e-04 9.53e+01 2.12e+07 2.35e+03 6.26e+01 0              
Beta search step
  20 6.64e-05 9.53e+01 2.12e+07 1.50e+03 4.99e+01 0              
Beta search step
  20 1.06e-04 9.53e+01 2.12e+07 2.35e+03 6.26e+01 0              
Beta search step
  20 6.64e-05 9.53e+01 2.12e+07 1.50e+03 4.99e+01 0              
Beta search step
  20 1.06e-04 9.53e+01 2.12e+07 2.35e+03 6.26e+01 0              
Beta search step
  20 6.64e-05 9.53e+01 2.12e+07 1.50e+03 4.99e+01 0              
Beta search step
  20 1.06e-04 9.53e+01 2.12e+07 2.35e+03 6.26e+01 0              
Beta search step
  20 6.64e-05 9.53e+01 2.12e+07 1.50e+03 4.99e+01 0
```

---

<div class="post-metadata">

**Author:** ![domfournier](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@domfournier](https://simpeg.discourse.group/u/domfournier)\
**Post date:** [June 17, 2020, 4:03pm UTC](https://simpeg.discourse.group/t/infinite-loop-in-inversion/107/2 "2020-06-17T16:03:41Z")

</div>

That can happen with the `beta_search=True` switched on.  
It’s not a super smart algorithm at this point, as it tries to re-adjust `beta` by multiplying it by fix constants to get to the target misfit.

```
if phi_d > target:
    beta *= mean([2, phi_d/target])
else:
    beta *= mean([0.75, phi_d/target])

```

So you can easily end up in an oscillatory pattern, like you have here, where you are just bouncing around the target but never take a step. I personally rarely use the beta\_search, and just let it progress even if it moves away from the target for a little while. The important part is that the `Directive.IRLS` WILL re-adjust `beta` in subsequent iterations to bring it back to target even without `beta_search=True`.

Feel free to think of a better approach to estimate the appropriate beta and share with us!
