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

hess option does not work in minimize function #14535

Closed
CatNofishing opened this issue Aug 4, 2021 · 5 comments · Fixed by #14720
Closed

hess option does not work in minimize function #14535

CatNofishing opened this issue Aug 4, 2021 · 5 comments · Fixed by #14720
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.optimize
Milestone

Comments

@CatNofishing
Copy link

CatNofishing commented Aug 4, 2021

issue

i traied use hess= {2-point’, ‘3-point’, ‘cs’, HessianUpdateStrategy} according to doc,but it failed.
image

Reproducing code example:

import numpy as np
from scipy.optimize import minimize,show_options,SR1
import sys
def rosen(x):
    """The Rosenbrock function"""
    return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)

def rosen_der(x):
    xm = x[1:-1]
    xm_m1 = x[:-2]
    xm_p1 = x[2:]
    der = np.zeros_like(x)
    der[1:-1] = 200*(xm-xm_m1**2) - 400*(xm_p1 - xm**2)*xm - 2*(1-xm)
    der[0] = -400*x[0]*(x[1]-x[0]**2) - 2*(1-x[0])
    der[-1] = 200*(x[-1]-x[-2]**2)
    return der


x0 = np.array([1.3, 0.7, 0.8, 1.9, 1.2])
minimize(rosen, x0, method='Newton-CG',
               options={'disp': False},jac=rosen_der,hess='cs')

Error message:

image

Scipy/Numpy/Python version information:

1.5.4 1.19.2 sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
@tupui tupui added Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.optimize labels Aug 4, 2021
@tupui
Copy link
Member

tupui commented Aug 4, 2021

Thanks @CatNofishing. I think this is just a phrasing issue as it also says:

Available quasi-Newton methods implementing this interface are:

BFGS;
SR1.

Meaning Newton-CG is not compatible here. There could be a validation here as well.

Is this correct @andyfaff?

@CatNofishing
Copy link
Author

CatNofishing commented Aug 5, 2021

@tupui Sorry, I still do not understand the description in the document, I suggest to provide a few examples of the use of the hess option parameter。 I set hess=‘2-point’/‘3-point’/’cs’ to all the solvers that provide the hess option, all of them do not work。

@tupui
Copy link
Member

tupui commented Aug 5, 2021

@tupui Sorry, I still do not understand the description in the document, I suggest to provide a few examples of the use of the hess option parameter。 I set hess=‘2-point’/‘3-point’/’cs’ to all the solvers that provide the hess option, all of them do not work。

All the trust methods (except exact as the doc states) are working fine. It's true that 'newton-cg', 'dogleg' do not work.

Ex.

minimize(rosen, x0, method='trust-krylov',
         jac=rosen_der, hess='cs')

Any improvement to the doc is always welcome if you want to help.

@tupui tupui added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Aug 5, 2021
@tupui
Copy link
Member

tupui commented Aug 5, 2021

@andyfaff this goes on the pile for the general rework of the interface. We should really plan this for SciPy 2.

@tupui tupui added the good first issue Good topic for first contributor pull requests, with a relatively straightforward solution label Aug 5, 2021
@Vipbone
Copy link

Vipbone commented Aug 31, 2021

I am a new contributor and want to share my opinion

minimize function needs to somehow get to know what frequencies and response are. Need to modify minimize function so that it takes those two parameters in, and then add an argument in your call to minimize to include those arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org good first issue Good topic for first contributor pull requests, with a relatively straightforward solution scipy.optimize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants