Search code examples
pythonscipyscipy-optimize

What `visit` parameter value is allowed in scipy.optimize.dual_annealing?


I tried using scipy.optimize.dual_annealing to minimize a function of 8 parameters. The search space (as defined by my bounds) is rather broad but I know the solution to be close to x0. So, after reading the documentation found here, I decided to use a smaller value of the visitparameter, which defaults to 2.62 and is supposedly in the range (0, 3].

When I used visit=0.8, I got a RuntimeWarning: invalid value encountered in log and indeed, in the source code I found this:

self._factor2 = np.exp((4.0 - self._visiting_param) * np.log(self._visiting_param - 1.0))

(l.62 of _dual_annealing.py) (basically self._visiting_param is straighforwardly assigned the value of visit)

So I thought maybe the documentation is wrong, and the range for visit is (1,3].

When I used visit=1.2, I got a FloatingPointError: invalid value encountered in log, due this time to

x *= np.exp(-(self._visiting_param - 1.0) * np.log(self._factor6 / factor4) / (3.0 - self._visiting_param))

(l.121 of _dual_annealing.py) where self._factor6 is negative.

Is this a real bug, a mistaken documentation, or is it just me misunderstanding something? What values can I use for the visit parameter in order to search close to x0?


Solution

  • My understanding is that you are right and the value range of the visiting parameter is not specified correctly. In fact, in the limiting case 1, the algorithm (theoretically) recovers (classical) simulated annealing as explained in this paper. However, the actual implementation as described therein, from which also scipy's implementation is taken, appears to work only for values greater 1.4.

    I have created an issue on github for this: https://github.com/scipy/scipy/issues/12384