Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scipy.optimize.shgo fails on one-dimensional objective functions with particular symmetry #10538

Open
gmagoon opened this issue Jul 28, 2019 · 2 comments
Labels
enhancement A new feature or improvement scipy.optimize

Comments

@gmagoon
Copy link

gmagoon commented Jul 28, 2019

It appears that scipy.optimize.shgo is failing on certain one-dimensional cases (see example below) with the default simplicial sampling. Based on the apparent 3-point sampling used (x=a, x=(a+b)/2, and x=b where the bounds are [(a,b)]), I suspect this issue will manifest for the nontrivial set of functions / domains where f(a)=f((a+b)/2)=f(b).

In the case below, x=0, x=0.5, and x=1 are sampled, and the function values at these points are all zero. As can be seen, when run with sobol sampling, the issue is not encountered.

So I suspect this is a sampling issue that may be related either directly or indirectly to #10429.

Reproducing code example:

>>> import scipy.optimize
>>> result=scipy.optimize.shgo(lambda x: x*(x-1.0)*(x-0.5),[(0,1)])
>>> print result
     fun: array([0.])
 message: 'Failed to find a feasible minimiser point. Lowest sampling point = [0.]'
    nfev: 3
     nit: 2
   nlfev: 0
   nlhev: 0
   nljev: 0
 success: False
       x: array([0.])
>>> result=scipy.optimize.shgo(lambda x: x*(x-1.0)*(x-0.5),[(0,1)],sampling_method='sobol')
>>> print result
     fun: -0.04811252243243487
    funl: array([-0.04811252,  0.        ])
 message: 'Optimization terminated successfully.'
    nfev: 212
     nit: 2
   nlfev: 12
   nlhev: 0
   nljev: 4
 success: True
       x: array([0.78867494])
      xl: array([[0.78867494],
       [0.        ]])

Scipy/Numpy/Python version information:

>>>import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
('1.2.2', '1.16.4', sys.version_info(major=2, minor=7, micro=15, releaselevel='candidate', serial=1))

Tagging @Stefan-Endres in case he has any thoughts.

@mdhaber
Copy link
Contributor

mdhaber commented Jan 27, 2023

@Stefan-Endres You marked that gh-16313 would close this, but the original code still fails; the user must pass n explicitly (e.g. n=101 to solve the problem. Is this problem pathological, or is it reasonable to keep this enhancement request (for shgo to solve the problem with default settings) open? Or is changing default n something you wanted to do in that follow-up PR?

@Stefan-Endres
Copy link
Contributor

This is true, the previous defaults masked this I should have checked more carefully what the actual issue here was (which was previously also solved by forcing one minimisation per iteration, but this had to be taken out to match the benchmarks of scipy main).

I will unmark it and make a enchancement PR at a later date so that we do not clog the already large PR with more detailed technical discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.optimize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants