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

Error in Defintion of Rosenbrock Function #9442

Closed
rshanker779 opened this issue Nov 5, 2018 · 2 comments
Closed

Error in Defintion of Rosenbrock Function #9442

rshanker779 opened this issue Nov 5, 2018 · 2 comments
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.optimize
Milestone

Comments

@rshanker779
Copy link
Contributor

The Rosenbrock function in the docs is incorrectly defined.
This occurs in the section Constrained minimization of multivariate scalar functions at https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html
The correct definition is on wikipedia: https://en.wikipedia.org/wiki/Rosenbrock_function.

The definition used in docs is:

100 * (x_0 - x_1 ^2) ^2 + (1 - x_0) ^2

which should be

100 * (x_1 - x_0 ^2) ^2 + (1 - x_0) ^2

As a verification, this block of code (with index swapped) gives the minimum as defined in the docs.

Reproducing code example:

from scipy.optimize import minimize

def rosenbrock(x):
    return 100 * (x[1] - x[0]**2) ** 2 + (1 - x[0]) ** 2

ros_cons = [{'type': 'ineq', 'fun': lambda x: 1 - 2 * x[1] - x[0]},
            {'type': 'ineq', 'fun': lambda x: 1 - x[0] ** 2 - x[1]},
            {'type': 'ineq', 'fun': lambda x: 1 + x[1] - x[0] ** 2},
            {'type': 'eq', 'fun': lambda x: 2 * x[0] + x[1] - 1}]
opt_res = minimize(rosenbrock, x0=[2, -1], constraints=ros_cons, bounds=[(0, 1), (-0.5, 2)])```
print(opt_res.x)
[0.41494395 0.17011211]

Scipy/Numpy/Python version information:

import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)

1.1.0 1.15.1 sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0)

@ilayn ilayn added scipy.optimize Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org labels Nov 5, 2018
@ilayn
Copy link
Member

ilayn commented Nov 5, 2018

@rshanker779 Thanks for reporting. Do you mind submitting a PR? We are about to make a new release (tomorrowish) and this would be nice to have it.

@rshanker779
Copy link
Contributor Author

Not a problem, will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.optimize
Projects
None yet
Development

No branches or pull requests

2 participants