Scipy_DifferentialEvolution

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

Bases: ScipyBase

Optimizer using scipy.optimize.differential_evolution.

The differential evolution method is stochastic and can search large areas of candidate space at the cost of running a longer than typical gradient-based methods.

See the scipy.optimize.differential_evolution 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.

strategy

The differential evolution strategy to use. See the scipy.optimize.differential_evolution documentation for a list of available strategies.

Type:

str

maxiter

The maximum number of generations to be evaluated.

Type:

int

popsize

A multiplier for setting the total population size.

Type:

int

tol

Relative tolerance for convergence.

Type:

float

mutation

The mutation constant.

Type:

float or tuple

recombination

The recombination constant.

Type:

float

rng

Random number generator instance or seed.

Type:

{None, int, numpy.random.Generator}

disp

Set to True to print convergence messages.

Type:

bool

callback

A callable called after each iteration.

Type:

callable

polish

If True, the best solution is refined by a local optimizer.

Type:

bool

init

The method used to initialize the population, see the scipy.optimize.differential_evolution documentation for a full list.

Type:

str or array_like

atol

Absolute tolerance for convergence.

Type:

float

updating

Whether to update the population immediately or only once per generation.

Type:

{‘immediate’, ‘deferred’}

workers

The number of workers to use for parallelization.

Type:

int or map-like callable

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 = None, statkwargs: Any | None = 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