GridSearch

class sherpa.optmethods.GridSearch(name='gridsearch')[source] [edit on github]

Bases: OptMethod

Grid Search optimization method.

This method evaluates the fit statistic for each point in the parameter space grid; the best match is the grid point with the lowest value of the fit statistic. It is intended for use with template models as it is very inefficient for general models.

num

The size of the grid for each parameter when sequence is None, so npar^num fits will be evaluated, where npar is the number of free parameters. The grid spacing is uniform.

Type:

int

sequence

The list through which to evaluate. Leave as None to use a uniform grid spacing as determined by the num attribute.

Type:

sequence of numbers or None

numcores

The number of CPU cores to use. The default is 1 and a value of None will use all the cores on the machine.

Type:

int or None

maxfev

The maxfev attribute if method is not None.

Type:

int or None

ftol

The ftol attribute if method is not None.

Type:

number

method

The optimization method to use to refine the best-fit location found using the grid search. If None then this step is not run.

Type:

str or None

verbose

The amount of information to print during the fit. The default is 0, which means no output.

Type:

int

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, pars, parmins, parmaxes, statargs=(), statkwargs=None) [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 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) – 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:

tuple