OptMethod
- class sherpa.optmethods.OptMethod(name: str, optfunc: Callable[[Concatenate[Callable[[Concatenate[Sequence[float] | ndarray, P]], tuple[float, ndarray]], Sequence[float] | ndarray, Sequence[float] | ndarray, Sequence[float] | ndarray, P]], tuple[bool, ndarray, float, str, dict[str, Any]]])[source] [edit on github]
Bases:
NoNewAttributesAfterInit
Base class for the optimisers.
- Parameters:
name (str) – The name of the optimiser.
optfunc (function) – The function which optimises the model: its arguments are a function which evaluates the statistic given a list of parameter values, the starting parameters, minima, and maxima, followed by keyword arguments matching the configuration data.
Notes
The optfunc argument is used to define the configuration options: they are taken from the keyword arguments and used to create the
default_config
dictionary which is then used to create the user-editableconfig
field.The optfunc function must accept the positional arguments:
fcn: OptFunc x0: ArrayType xmin: ArrayType xmax: ArrayType
and the remaining arguments are sent in as keyword arguments, and so can be specific to the optimization function. The x0, xmin, and xmax values specify the starting values and their minimum and maximum limits; they are intended to be sent in as 1D numeric arrays.
The function returns the statistic value and per-bin statistic values for the given values - which are the first argument it is sent, and then it can take other arguments which are set by the statargs and statkwargs arguments sent to the
fit
call.Attributes Summary
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[[Concatenate[Sequence[float] | ndarray, P]], tuple[float, ndarray]], pars: Sequence[float] | ndarray, parmins: Sequence[float] | ndarray, parmaxes: Sequence[float] | ndarray, statargs: Sequence[Any] = (), statkwargs: dict[str, Any] | None = None) tuple[bool, ndarray, float, str, dict[str, Any]] [source] [edit on github]
Run the optimiser.
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
andstatkwargs
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) – Additional positional arguments to send to
statfunc
.statkwargs (dict, optional) – Additional keyword arguments to send to
statfunc
.
- 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: