Wednesday, April 27, 2022

[FIXED] How to hide `delta_grad == 0.0` warning in scipy.optimize.minimize?

Issue

I have a loop that executes several hundred optimizations using scipy.optimize.minimize. Unfortunately, I keep getting this annoying warning:

C:\Users\Leonidas\Anaconda3\lib\site-packages\scipy\optimize\_hessian_update_strategy.py:186: UserWarning: delta_grad == 0.0. Check if the approximated function is linear. If the function is linear better results can be obtained by defining the Hessian as zero instead of using quasi-Newton approximations.
  'approximations.', UserWarning)

Because I am running hundreds of optimizations, this warning shows up dozens and dozens of times during the loop, and it just clutters the console and obscures the rest of my program's output. Is there a way to either

  1. Check if this warning has already been displayed, and if so don't display it again, OR
  2. Completely suppress the warning altogether?

Solution

If you want to suppress the specific warning, you can add following at the beginning of your script:

import warnings
warnings.filterwarnings("ignore", message="delta_grad == 0.0. Check if the approximated function is linear.")


Answered By - igrinis
Answer Checked By - Mary Flores (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.