brute

SeparableModelResult.brute(params=None, Ns=20, keep=50)

Use the brute method to find the global minimum of a function.

The following parameters are passed to scipy.optimize.brute and cannot be changed:

brute() arg Value Description
full_output 1 Return the evaluation grid and the objective function’s values on it.
finish None No “polishing” function is to be used after the grid search.
disp False Do not print convergence messages (when finish is not None).

It assumes that the input Parameters have been initialized, and a function to minimize has been properly set up.

Parameters:
  • params (Parameters, optional) – Contains the Parameters for the model. If None, then the Parameters used to initialize the Minimizer object are used.
  • Ns (int, optional) – Number of grid points along the axes, if not otherwise specified (see Notes).
  • keep (int, optional) – Number of best candidates from the brute force method that are stored in the candidates attribute. If ‘all’, then all grid points from scipy.optimize.brute are stored as candidates.
Returns:

Object containing the parameters from the brute force method. The return values (x0, fval, grid, Jout) from scipy.optimize.brute are stored as brute_<parname> attributes. The MinimizerResult also contains the candidates attribute and show_candidates() method. The candidates attribute contains the parameters and chisqr from the brute force method as a namedtuple, (‘Candidate’, [‘params’, ‘score’]), sorted on the (lowest) chisqr value. To access the values for a particular candidate one can use result.candidate[#].params or result.candidate[#].score, where a lower # represents a better candidate. The show_candidates(#) uses the pretty_print() method to show a specific candidate-# or all candidates when no number is specified.

Return type:

MinimizerResult

New in version 0.9.6.

Notes

The brute() method evalutes the function at each point of a multidimensional grid of points. The grid points are generated from the parameter ranges using Ns and (optional) brute_step. The implementation in scipy.optimize.brute requires finite bounds and the range is specified as a two-tuple (min, max) or slice-object (min, max, brute_step). A slice-object is used directly, whereas a two-tuple is converted to a slice object that interpolates Ns points from min to max, inclusive.

In addition, the brute() method in lmfit, handles three other scenarios given below with their respective slice-object:

  • lower bound (min) and brute_step are specified:
    range = (min, min + Ns * brute_step, brute_step).
  • upper bound (max) and brute_step are specified:
    range = (max - Ns * brute_step, max, brute_step).
  • numerical value (value) and brute_step are specified:
    range = (value - (Ns//2) * brute_step, value + (Ns//2) * brute_step, brute_step).