
    (phRt                        S r SSKrSSKrSSKrSSKrSSKJrJ	r	  S/r
\R                  " S\R                  R                  S9\R                  " S\R                  R                  S94r\R                  " \S9r " S	 S
5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S5      r\	" SSSS9    SSSS.S jj5       rg)z>
basinhopping: The basinhopping global optimization algorithm
    N)check_random_state_transition_to_rngbasinhoppingres_new)kindres_old)
parametersc                   0    \ rS rSrSrS rS rS rS rSr	g)	Storage   z1
Class used to store the lowest energy structure
c                 &    U R                  U5        g N)_addselfminress     O/var/www/html/venv/lib/python3.13/site-packages/scipy/optimize/_basinhopping.py__init__Storage.__init__   s    		&    c                 n    Xl         [        R                  " UR                  5      U R                   l        g r   )r   npcopyxr   s     r   r   Storage._add   s    )r   c                     UR                   (       aQ  UR                  U R                  R                  :  d  U R                  R                   (       d  U R                  U5        gg)NTF)successfunr   r   r   s     r   updateStorage.update   s;    >>vzzDKKOO;&*kk&9&9IIfr   c                     U R                   $ r   r   )r   s    r   
get_lowestStorage.get_lowest%   s    {{r   r"   N)
__name__
__module____qualname____firstlineno____doc__r   r   r   r#   __static_attributes__ r   r   r   r      s    *r   r   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
BasinHoppingRunner)   a  This class implements the core of the basinhopping algorithm.

x0 : ndarray
    The starting coordinates.
minimizer : callable
    The local minimizer, with signature ``result = minimizer(x)``.
    The return value is an `optimize.OptimizeResult` object.
step_taking : callable
    This function displaces the coordinates randomly. Signature should
    be ``x_new = step_taking(x)``. Note that `x` may be modified in-place.
accept_tests : list of callables
    Each test is passed the kwargs `f_new`, `x_new`, `f_old` and
    `x_old`. These tests will be used to judge whether or not to accept
    the step. The acceptable return values are True, False, or ``"force
    accept"``. If any of the tests return False then the step is rejected.
    If ``"force accept"``, then this will override any other tests in
    order to accept the step. This can be used, for example, to forcefully
    escape from a local minimum that ``basinhopping`` is trapped in.
disp : bool, optional
    Display status messages.

c                    [         R                  " U5      U l        X l        X0l        X@l        XPl        SU l        [        R                  R                  5       U l        SU R                  l        U" U R                  5      nUR                  (       d;  U R                  =R                  S-  sl        U R                  (       a  [        S5        [         R                  " UR                  5      U l        UR                  U l        X`l        U R                  (       a$  [        SU R                  U R                   4-  5        [%        U5      U l        [)        US5      (       a  UR*                  U R                  l        [)        US5      (       a  UR,                  U R                  l        [)        US5      (       a  UR.                  U R                  l        g g )Nr      1warning: basinhopping: local minimization failurezbasinhopping step %d: f %gnfevnjevnhev)r   r   r   	minimizerstep_takingaccept_testsdispnstepscipyoptimizeOptimizeResultresminimization_failuresr   printr   energyincumbent_minresr   storagehasattrr2   r3   r4   )r   x0r5   r6   r7   r8   r   s          r   r   BasinHoppingRunner.__init__@   s9   "&(	
 >>002)*& 466"~~HH**a/*yyIJ"jj &99.$**dkk1JJK v66"""KKDHHM66"""KKDHHM66"""KKDHHM #r   c                 J   [         R                  " U R                  5      nU R                  U5      nU R	                  U5      nUR                  nUR
                  nUR                  (       d;  U R                  =R                  S-  sl        U R                  (       a  [        S5        [        US5      (       a)  U R                  =R                  UR                  -  sl        [        US5      (       a)  U R                  =R                  UR                  -  sl        [        US5      (       a)  U R                  =R                  UR                  -  sl        SnU R                   Hq  n[         R"                  " U5      [$        :X  a  U" X R&                  S9nOU" XCU R(                  U R                  S9nUS	:X  a  Sn  OUc  [+        S
5      eU(       a  Mo  SnMs     [        U R                  S5      (       a/  U R                  R-                  XTX0R(                  U R                  S9  XR4$ )zDo one Monte Carlo iteration

Randomly displace the coordinates, minimize, and decide whether
or not to accept the new coordinates.
r0   r1   r2   r3   r4   T)r   r   )f_newx_newf_oldx_oldzforce acceptz7accept_tests must return True, False, or 'force accept'Freport)r   r   r   r6   r5   r   r   r=   r>   r8   r?   rC   r2   r3   r4   r7   inspect	signature_new_accept_test_signaturerA   r@   
ValueErrorrK   )r   x_after_stepr   x_after_quenchenergy_after_quenchaccepttesttestress           r   _monte_carlo_step$BasinHoppingRunner._monte_carlo_stepc   s    wwtvv''5 -$jj~~HH**a/*yyIJ66""HHMMV[[(M66""HHMMV[[(M66""HHMMV[[(M %%D  &*DDv7L7LM%8%)[[@ .(  "2 3 3W &$ 4##X..##F*8*.&& $ 2 ~r   c                    U =R                   S-  sl         SnU R                  5       u  p#U(       aW  UR                  U l        [        R
                  " UR                  5      U l        X0l        U R                  R                  U5      nU R                  (       aG  U R                  UR                  U5        U(       a$  [        SU R                   U R                  4-  5        UR                  U l        UR                  U l        X l        U$ )z3Do one cycle of the basinhopping algorithm
        r0   Fz:found new global minimum on step %d with function value %g)r9   rV   r   r@   r   r   r   rA   rB   r   r8   print_reportr?   xtrialenergy_trialrS   )r   new_global_minrS   r   s       r   	one_cycleBasinHoppingRunner.one_cycle   s     	

a
//1 **DKWWVXX&DF$*!!\\008N 99fjj&1 "%)ZZ$=> ? hh"JJr   c                     U R                   R                  5       n[        SU R                  U R                  UX#R
                  4-  5        g)zprint a status updatez>basinhopping step %d: f %g trial_f %g accepted %d  lowest_f %gN)rB   r#   r?   r9   r@   r   )r   r[   rS   r   s       r   rY   BasinHoppingRunner.print_report   sA    ((*  $

DKK &

 44 	5r   )rS   r7   r8   r@   r[   rA   r5   r9   r=   r6   rB   r   rZ   N)F)
r%   r&   r'   r(   r)   r   rV   r]   rY   r*   r+   r   r   r-   r-   )   s    ,!(F7r85r   r-   c                   >    \ rS rSrSr  S
S jrS rS rS rS r	Sr
g	)AdaptiveStepsize   al  
Class to implement adaptive stepsize.

This class wraps the step taking class and modifies the stepsize to
ensure the true acceptance rate is as close as possible to the target.

Parameters
----------
takestep : callable
    The step taking routine.  Must contain modifiable attribute
    takestep.stepsize
accept_rate : float, optional
    The target step acceptance rate
interval : int, optional
    Interval for how often to update the stepsize
factor : float, optional
    The step size is multiplied or divided by this factor upon each
    update.
verbose : bool, optional
    Print information about each update

c                 j    Xl         X l        X0l        X@l        XPl        SU l        SU l        SU l        g )Nr   )takesteptarget_accept_rateintervalfactorverboser9   	nstep_totnaccept)r   re   accept_raterg   rh   ri   s         r   r   AdaptiveStepsize.__init__   s1     "- 
r   c                 $    U R                  U5      $ r   )	take_stepr   r   s     r   __call__AdaptiveStepsize.__call__   s    ~~a  r   c                    U R                   R                  n[        U R                  5      U R                  -  nX R
                  :  a*  U R                   =R                  U R                  -  sl        O)U R                   =R                  U R                  -  sl        U R                  (       a:  [        SUS SU R
                  S SU R                   R                  S SUS 35        g g )Nz#adaptive stepsize: acceptance rate fz target z new stepsize gz old stepsize )	re   stepsizefloatrk   r9   rf   rh   ri   r?   )r   old_stepsizerl   s      r   _adjust_step_size"AdaptiveStepsize._adjust_step_size   s    }}--DLL)DJJ6000 MM""dkk1" MM""dkk1"<<7Ah,,Q/~]]++A.n\!<LN O r   c                     U =R                   S-  sl         U =R                  S-  sl        U R                   U R                  -  S:X  a  U R                  5         U R	                  U5      $ )Nr0   r   )r9   rj   rg   ry   re   rp   s     r   ro   AdaptiveStepsize.take_step   sM    

a
!::%*""$}}Qr   c                 >    U(       a  U =R                   S-  sl         gg)z7called by basinhopping to report the result of the stepr0   N)rk   )r   rS   kwargss      r   rK   AdaptiveStepsize.report   s    LLAL r   )rh   rg   rk   r9   rj   re   rf   ri   N)      ?2   ?T)r%   r&   r'   r(   r)   r   rq   ry   ro   rK   r*   r+   r   r   rb   rb      s+    , GJ
!O r   rb   c                   (    \ rS rSrSrSS jrS rSrg)RandomDisplacementi  a  Add a random displacement of maximum size `stepsize` to each coordinate.

Calling this updates `x` in-place.

Parameters
----------
stepsize : float, optional
    Maximum stepsize in any dimension
rng : {None, int, `numpy.random.Generator`}, optional
    Random number generator
Nc                 0    Xl         [        U5      U l        g r   )rv   r   rng)r   rv   r   s      r   r   RandomDisplacement.__init__  s     %c*r   c                     XR                   R                  U R                  * U R                  [        R                  " U5      5      -  nU$ r   )r   uniformrv   r   shaperp   s     r   rq   RandomDisplacement.__call__  s9    	XXt}}ndmm hhqk+ 	+r   )r   rv   )r   Nr%   r&   r'   r(   r)   r   rq   r*   r+   r   r   r   r     s    
+r   r   c                   (    \ rS rSrSrSS jrS rSrg)MinimizerWrapperi  z0
wrap a minimizer function as a minimizer class
Nc                 (    Xl         X l        X0l        g r   )r5   funcr~   )r   r5   r   r~   s       r   r   MinimizerWrapper.__init__  s    "	r   c                     U R                   c  U R                  " U40 U R                  D6$ U R                  " U R                   U40 U R                  D6$ r   )r   r5   r~   )r   rD   s     r   rq   MinimizerWrapper.__call__"  sB    99>>"444>>$))R?4;;??r   )r   r~   r5   r   r   r+   r   r   r   r     s    
@r   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	
Metropolisi)  zMetropolis acceptance criterion.

Parameters
----------
T : float
    The "temperature" parameter for the accept or reject criterion.
rng : {None, int, `numpy.random.Generator`}, optional
    Random number generator used for acceptance test.

Nc                 Z    US:w  a  SU-  O
[        S5      U l        [        U5      U l        g )Nr         ?inf)rw   betar   r   )r   Tr   s      r   r   Metropolis.__init__5  s'      !AvC!G5<	%c*r   c                    [         R                  " SS9   UR                  UR                  -
  * U R                  -  n[        R
                  " [        SU5      5      nSSS5        U R                  R                  5       nWU:  =(       a$    UR                  =(       d    UR                  (       + $ ! , (       d  f       NX= f)z
Assuming the local search underlying res_new was successful:
If new energy is lower than old, it will always be accepted.
If new is higher than old, there is a chance it will be accepted,
less likely for larger differences.
ignore)invalidr   N)
r   errstater   r   mathexpminr   r   r   )r   r   r   prodwrands         r   accept_rejectMetropolis.accept_reject<  s     [[* [[7;;./$));DQ&A + xx!DyEgooDW__1DE +*s   AB//
B=c                6    [        U R                  X5      5      $ )z)
f_new and f_old are mandatory in kwargs
)boolr   )r   r   r   s      r   rq   Metropolis.__call__R  s     D&&w899r   )r   r   r   )	r%   r&   r'   r(   r)   r   r   rq   r*   r+   r   r   r   r   )  s    	+F,:r   r   seed   T)position_numreplace_docr   r   )rf   stepwise_factorc                Z   US::  d  US:  a  [        S5      eUS::  d  US:  a  [        S5      e[        R                  " U5      n[        U5      nUc
  [	        5       n[        [        R                  R                  U 40 UD6nUb<  [        U5      (       d  [        S5      e[        US5      (       a  [        XiUUU
S9nOUnO[        XLS9n[        UU	UUU
S9n/ nUb  [        U5      (       d  [        S	5      eU/n[        X<S
9nUR                  U5        Uc  US-   n[!        XUUU
S9n[        U5      (       aF  U" UR"                  R$                  R&                  UR"                  R$                  R(                  S5        Su  nnS/n[+        U5       Hu  nUR-                  5       n[        U5      (       a7  U" UR.                  UR0                  UR2                  5      nUb  U(       a  S/n  OUS-  nU(       a  SnMj  UU:  d  Mr  S/n  O   UR4                  nUR"                  R7                  5       Ul        [        R:                  " UR8                  R&                  5      Ul        UR8                  R(                  Ul        UUl        US-   Ul        UR8                  R@                  Ul         U$ )a2  Find the global minimum of a function using the basin-hopping algorithm.

Basin-hopping is a two-phase method that combines a global stepping
algorithm with local minimization at each step. Designed to mimic
the natural process of energy minimization of clusters of atoms, it works
well for similar problems with "funnel-like, but rugged" energy landscapes
[5]_.

As the step-taking, step acceptance, and minimization methods are all
customizable, this function can also be used to implement other two-phase
methods.

Parameters
----------
func : callable ``f(x, *args)``
    Function to be optimized.  ``args`` can be passed as an optional item
    in the dict `minimizer_kwargs`
x0 : array_like
    Initial guess.
niter : integer, optional
    The number of basin-hopping iterations. There will be a total of
    ``niter + 1`` runs of the local minimizer.
T : float, optional
    The "temperature" parameter for the acceptance or rejection criterion.
    Higher "temperatures" mean that larger jumps in function value will be
    accepted.  For best results `T` should be comparable to the
    separation (in function value) between local minima.
stepsize : float, optional
    Maximum step size for use in the random displacement.
minimizer_kwargs : dict, optional
    Extra keyword arguments to be passed to the local minimizer
    `scipy.optimize.minimize` Some important options could be:

    method : str
        The minimization method (e.g. ``"L-BFGS-B"``)
    args : tuple
        Extra arguments passed to the objective function (`func`) and
        its derivatives (Jacobian, Hessian).

take_step : callable ``take_step(x)``, optional
    Replace the default step-taking routine with this routine. The default
    step-taking routine is a random displacement of the coordinates, but
    other step-taking algorithms may be better for some systems.
    `take_step` can optionally have the attribute ``take_step.stepsize``.
    If this attribute exists, then `basinhopping` will adjust
    ``take_step.stepsize`` in order to try to optimize the global minimum
    search.
accept_test : callable, ``accept_test(f_new=f_new, x_new=x_new, f_old=fold, x_old=x_old)``, optional
    Define a test which will be used to judge whether to accept the
    step. This will be used in addition to the Metropolis test based on
    "temperature" `T`. The acceptable return values are True,
    False, or ``"force accept"``. If any of the tests return False
    then the step is rejected. If the latter, then this will override any
    other tests in order to accept the step. This can be used, for example,
    to forcefully escape from a local minimum that `basinhopping` is
    trapped in.
callback : callable, ``callback(x, f, accept)``, optional
    A callback function which will be called for all minima found. ``x``
    and ``f`` are the coordinates and function value of the trial minimum,
    and ``accept`` is whether that minimum was accepted. This can
    be used, for example, to save the lowest N minima found. Also,
    `callback` can be used to specify a user defined stop criterion by
    optionally returning True to stop the `basinhopping` routine.
interval : integer, optional
    interval for how often to update the `stepsize`
disp : bool, optional
    Set to True to print status messages
niter_success : integer, optional
    Stop the run if the global minimum candidate remains the same for this
    number of iterations.
rng : `numpy.random.Generator`, optional
    Pseudorandom number generator state. When `rng` is None, a new
    `numpy.random.Generator` is created using entropy from the
    operating system. Types other than `numpy.random.Generator` are
    passed to `numpy.random.default_rng` to instantiate a ``Generator``.

    The random numbers generated only affect the default Metropolis
    `accept_test` and the default `take_step`. If you supply your own
    `take_step` and `accept_test`, and these functions use random
    number generation, then those functions are responsible for the state
    of their random number generator.
target_accept_rate : float, optional
    The target acceptance rate that is used to adjust the `stepsize`.
    If the current acceptance rate is greater than the target,
    then the `stepsize` is increased. Otherwise, it is decreased.
    Range is (0, 1). Default is 0.5.

    .. versionadded:: 1.8.0

stepwise_factor : float, optional
    The `stepsize` is multiplied or divided by this stepwise factor upon
    each update. Range is (0, 1). Default is 0.9.

    .. versionadded:: 1.8.0

Returns
-------
res : OptimizeResult
    The optimization result represented as a `OptimizeResult` object.
    Important attributes are: ``x`` the solution array, ``fun`` the value
    of the function at the solution, and ``message`` which describes the
    cause of the termination. The ``OptimizeResult`` object returned by the
    selected minimizer at the lowest minimum is also contained within this
    object and can be accessed through the ``lowest_optimization_result``
    attribute.  See `OptimizeResult` for a description of other attributes.

See Also
--------
minimize :
    The local minimization function called once for each basinhopping step.
    `minimizer_kwargs` is passed to this routine.

Notes
-----
Basin-hopping is a stochastic algorithm which attempts to find the global
minimum of a smooth scalar function of one or more variables [1]_ [2]_ [3]_
[4]_. The algorithm in its current form was described by David Wales and
Jonathan Doye [2]_ http://www-wales.ch.cam.ac.uk/.

The algorithm is iterative with each cycle composed of the following
features

1) random perturbation of the coordinates

2) local minimization

3) accept or reject the new coordinates based on the minimized function
   value

The acceptance test used here is the Metropolis criterion of standard Monte
Carlo algorithms, although there are many other possibilities [3]_.

This global minimization method has been shown to be extremely efficient
for a wide variety of problems in physics and chemistry. It is
particularly useful when the function has many minima separated by large
barriers. See the `Cambridge Cluster Database
<https://www-wales.ch.cam.ac.uk/CCD.html>`_ for databases of molecular
systems that have been optimized primarily using basin-hopping. This
database includes minimization problems exceeding 300 degrees of freedom.

See the free software program `GMIN <https://www-wales.ch.cam.ac.uk/GMIN>`_
for a Fortran implementation of basin-hopping. This implementation has many
variations of the procedure described above, including more
advanced step taking algorithms and alternate acceptance criterion.

For stochastic global optimization there is no way to determine if the true
global minimum has actually been found. Instead, as a consistency check,
the algorithm can be run from a number of different random starting points
to ensure the lowest minimum found in each example has converged to the
global minimum. For this reason, `basinhopping` will by default simply
run for the number of iterations `niter` and return the lowest minimum
found. It is left to the user to ensure that this is in fact the global
minimum.

Choosing `stepsize`:  This is a crucial parameter in `basinhopping` and
depends on the problem being solved. The step is chosen uniformly in the
region from x0-stepsize to x0+stepsize, in each dimension. Ideally, it
should be comparable to the typical separation (in argument values) between
local minima of the function being optimized. `basinhopping` will, by
default, adjust `stepsize` to find an optimal value, but this may take
many iterations. You will get quicker results if you set a sensible
initial value for ``stepsize``.

Choosing `T`: The parameter `T` is the "temperature" used in the
Metropolis criterion. Basinhopping steps are always accepted if
``func(xnew) < func(xold)``. Otherwise, they are accepted with
probability::

    exp( -(func(xnew) - func(xold)) / T )

So, for best results, `T` should to be comparable to the typical
difference (in function values) between local minima. (The height of
"walls" between local minima is irrelevant.)

If `T` is 0, the algorithm becomes Monotonic Basin-Hopping, in which all
steps that increase energy are rejected.

.. versionadded:: 0.12.0

References
----------
.. [1] Wales, David J. 2003, Energy Landscapes, Cambridge University Press,
    Cambridge, UK.
.. [2] Wales, D J, and Doye J P K, Global Optimization by Basin-Hopping and
    the Lowest Energy Structures of Lennard-Jones Clusters Containing up to
    110 Atoms.  Journal of Physical Chemistry A, 1997, 101, 5111.
.. [3] Li, Z. and Scheraga, H. A., Monte Carlo-minimization approach to the
    multiple-minima problem in protein folding, Proc. Natl. Acad. Sci. USA,
    1987, 84, 6611.
.. [4] Wales, D. J. and Scheraga, H. A., Global optimization of clusters,
    crystals, and biomolecules, Science, 1999, 285, 1368.
.. [5] Olson, B., Hashmi, I., Molloy, K., and Shehu1, A., Basin Hopping as
    a General and Versatile Optimization Framework for the Characterization
    of Biological Macromolecules, Advances in Artificial Intelligence,
    Volume 2012 (2012), Article ID 674832, :doi:`10.1155/2012/674832`

Examples
--------
The following example is a 1-D minimization problem, with many
local minima superimposed on a parabola.

>>> import numpy as np
>>> from scipy.optimize import basinhopping
>>> func = lambda x: np.cos(14.5 * x - 0.3) + (x + 0.2) * x
>>> x0 = [1.]

Basinhopping, internally, uses a local minimization algorithm. We will use
the parameter `minimizer_kwargs` to tell basinhopping which algorithm to
use and how to set up that minimizer. This parameter will be passed to
`scipy.optimize.minimize`.

>>> minimizer_kwargs = {"method": "BFGS"}
>>> ret = basinhopping(func, x0, minimizer_kwargs=minimizer_kwargs,
...                    niter=200)
>>> # the global minimum is:
>>> ret.x, ret.fun
-0.1951, -1.0009

Next consider a 2-D minimization problem. Also, this time, we
will use gradient information to significantly speed up the search.

>>> def func2d(x):
...     f = np.cos(14.5 * x[0] - 0.3) + (x[1] + 0.2) * x[1] + (x[0] +
...                                                            0.2) * x[0]
...     df = np.zeros(2)
...     df[0] = -14.5 * np.sin(14.5 * x[0] - 0.3) + 2. * x[0] + 0.2
...     df[1] = 2. * x[1] + 0.2
...     return f, df

We'll also use a different local minimization algorithm. Also, we must tell
the minimizer that our function returns both energy and gradient (Jacobian).

>>> minimizer_kwargs = {"method":"L-BFGS-B", "jac":True}
>>> x0 = [1.0, 1.0]
>>> ret = basinhopping(func2d, x0, minimizer_kwargs=minimizer_kwargs,
...                    niter=200)
>>> print("global minimum: x = [%.4f, %.4f], f(x) = %.4f" % (ret.x[0],
...                                                           ret.x[1],
...                                                           ret.fun))
global minimum: x = [-0.1951, -0.1000], f(x) = -1.0109

Here is an example using a custom step-taking routine. Imagine you want
the first coordinate to take larger steps than the rest of the coordinates.
This can be implemented like so:

>>> class MyTakeStep:
...    def __init__(self, stepsize=0.5):
...        self.stepsize = stepsize
...        self.rng = np.random.default_rng()
...    def __call__(self, x):
...        s = self.stepsize
...        x[0] += self.rng.uniform(-2.*s, 2.*s)
...        x[1:] += self.rng.uniform(-s, s, x[1:].shape)
...        return x

Since ``MyTakeStep.stepsize`` exists basinhopping will adjust the magnitude
of `stepsize` to optimize the search. We'll use the same 2-D function as
before

>>> mytakestep = MyTakeStep()
>>> ret = basinhopping(func2d, x0, minimizer_kwargs=minimizer_kwargs,
...                    niter=200, take_step=mytakestep)
>>> print("global minimum: x = [%.4f, %.4f], f(x) = %.4f" % (ret.x[0],
...                                                           ret.x[1],
...                                                           ret.fun))
global minimum: x = [-0.1951, -0.1000], f(x) = -1.0109

Now, let's do an example using a custom callback function which prints the
value of every minimum found

>>> def print_fun(x, f, accepted):
...         print("at minimum %.4f accepted %d" % (f, int(accepted)))

We'll run it for only 10 basinhopping steps this time.

>>> rng = np.random.default_rng()
>>> ret = basinhopping(func2d, x0, minimizer_kwargs=minimizer_kwargs,
...                    niter=10, callback=print_fun, rng=rng)
at minimum 0.4159 accepted 1
at minimum -0.4317 accepted 1
at minimum -1.0109 accepted 1
at minimum -0.9073 accepted 1
at minimum -0.4317 accepted 0
at minimum -0.1021 accepted 1
at minimum -0.7425 accepted 1
at minimum -0.9073 accepted 1
at minimum -0.4317 accepted 0
at minimum -0.7425 accepted 1
at minimum -0.9073 accepted 1

The minimum at -1.0109 is actually the global minimum, found already on the
8th iteration.

g        r   z,target_accept_rate has to be in range (0, 1)z)stepwise_factor has to be in range (0, 1)ztake_step must be callablerv   )rg   rl   rh   ri   )rv   r   zaccept_test must be callable)r      )r8   T)r   r   zBrequested number of basinhopping iterations completed successfullyz7callback function requested stop early byreturning Truer0   r   zsuccess condition satisfied)!rO   r   arrayr   dictr   r:   r;   minimizecallable	TypeErrorrC   rb   r   r   appendr-   rB   r   r   r   ranger]   rZ   r[   rS   r=   r#   lowest_optimization_resultr   messagenitr   )r   rD   niterr   rv   minimizer_kwargsro   accept_testcallbackrg   r8   niter_successr   rf   r   wrapped_minimizertake_step_wrappeddisplacer7   
metropolisbhcountir   r\   valr=   s                              r   r   r   Y  s   V	 R#5#;GHH"2 5DEE	"B S
!C 6()@)@$ =+;= 	""899 9j)) 0.&	! !* &xA,X9K4C59; L$$:;;#} A'J
#		B3D(t
5B
 ""$$bjj&7&7&;&;TB HE1  G5\H299booryyAC 0 1G
E]"45G# ( &&C%'ZZ%:%:%<C"GGC22445CE,,00CGCK!eCG0088CKJr   )d   r   r   NNNNr   FNN)r)   numpyr   r   rL   scipy.optimizer:   scipy._lib._utilr   r   __all__	ParameterKEYWORD_ONLY_params	SignaturerN   r   r-   rb   r   r   r   r   r+   r   r   <module>r      s        C
 YW->->-K-KLYW->->-K-KLN$..'B  .T5 T5n? ?D .@ @ -: -:` F>69DHGKE 25cE ?Er   