Scipy_Basinhopping

class sherpa.optmethods.optscipy.Scipy_Basinhopping(name: str | None = None, **kwargs)[source] [edit on github]

Bases: ScipyBase

Optimizer using scipy.optimize.basinhopping.

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.

See the scipy.optimize.basinhopping documentation for details of all parameters. Sherpa will automatically convert statistics functions, input values, parameter limits etc. to the format required by the scipy function. The following attributes can be set as attributes of this class.

niter

Number of iterations to perform.

Type:

int

T

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.

Type:

float

step_size

Maximum step size for use in the random displacement.

Type:

float

minimizer_kwargs

A dictionary of options to pass to the local minimizer.

Type:

dict

take_step

Replace the default step-taking routine with this routine.

Type:

callable

accept_test

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.

Type:

callable

callback

A callable called after each iteration.

Type:

callable

niter_success

Stop the run if the global minimum candidate remains the same for this number of iterations.

Type:

int

rng

Random number generator instance or seed.

Type:

{None, int, numpy.random.Generator}

target_acceptance_rate

The target acceptance rate for the step acceptance test.

Type:

float

stepwise_factor

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

Type:

float

Attributes Summary

default_config

The default settings for the optimiser.

Methods Summary

fit(statfunc, pars, parmins, parmaxes[, ...])

Run the optimiser.

Attributes Documentation

default_config

The default settings for the optimiser.

Methods Documentation

fit(statfunc: Callable[[Sequence[float] | ndarray], tuple[float, ndarray]], pars: Sequence[float] | ndarray, parmins: Sequence[float] | ndarray, parmaxes: Sequence[float] | ndarray, statargs: Any = None, statkwargs: Any = None) tuple[bool, ndarray, float, str, dict[str, Any]] [edit on github]

Run the optimiser.

Changed in version 4.18.0: The statargs and statkwargs arguments are now ignored.

Changed in version 4.16.0: The statkwargs argument now defaults to None rather than {}.

Parameters:
  • statfunc (function) – Given a list of parameter values as the first argument and, as the remaining positional arguments, statargs and statkwargs as keyword arguments, return the statistic value.

  • pars (sequence) – The start position of the model parameter values.

  • parmins (sequence) – The minimum allowed values for each model parameter. This must match the length of pars.

  • parmaxes (sequence) – The maximum allowed values for each model parameter. This must match the length of pars.

  • statargs (optional) – This is currently unused.

  • statkwargs (dict, optional) – This is currently unused.

Returns:

newpars – The tuple contains: boolean indicating whether the optimization succeeded or not, the best fit parameters as a NumPy array, the statistic value at the best-fit location, a string message indicating the status, and a dictionary containing information about the optimisation (this depends on the optimiser).

Return type:

tuple