pythonnumpyscipy

Is it possible to force scipy.optimize.minimize_scalar to look only in the specified interval


I want to find a minimum of a function on a given interval [a, b] and tried out scipy.optimize.minimize_scalar with method = "Golden" and bracket = [a, b].

The problem is that it returns solutions outside the given interval [a, b]. Is there some way to force the interval or some other scipy/numpy method that can be used?


Solution

  • You can try using the bounded method instead of golden.

    method="golden" (i think method="brent" too) take a bracket as a starting guess and may sample outside it.

    method="bounded" enforces bounds strictly causing all evaluations and the solution to stay in [a, b]