MonCar
- class sherpa.optmethods.MonCar(name: str = 'moncar', **kwargs)[source] [edit on github]
Bases:
OptMethodMonte Carlo optimization method.
This is an implementation of the differential-evolution algorithm from Storn and Price (1997) [1]. A population of fixed size - which contains n-dimensional vectors, where n is the number of free parameters - is randomly initialized. At each iteration, a new n-dimensional vector is generated by combining vectors from the pool of population, the resulting trial vector is selected if it lowers the objective function.
- Attributes:
- ftol
number The function tolerance to terminate the search for the minimum; the default is sqrt(DBL_EPSILON) ~ 1.19209289551e-07, where DBL_EPSILON is the smallest number x such that
1.0 != 1.0 + x.- maxfev
intorNone The maximum number of function evaluations; the default value of
Nonemeans to use8192 * n, wherenis the number of free parameters.- verbose: int
The amount of information to print during the fit. The default is
0, which means no output.- seed
int The seed for the random number generator.
- population_size
intorNone The population of potential solutions is allowed to evolve to search for the minimum of the fit statistics. The trial solution is randomly chosen from a combination from the current population, and it is only accepted if it lowers the statistics. A value of
Nonemeans to use a value16 * n, wherenis the number of free parameters.- xprob
num The crossover probability should be within the range [0.5,1.0]; default value is 0.9. A high value for the crossover probability should result in a faster convergence rate; conversely, a lower value should make the differential evolution method more robust.
- weighting_factor: num
The weighting factor should be within the range [0.5, 1.0]; default is 0.8. Differential evolution is more sensitive to the weighting_factor then the xprob parameter. A lower value for the weighting_factor, coupled with an increase in the population_size, gives a more robust search at the cost of efficiency.
- numcores
int The number of CPU cores to use. The default is
1.
- ftol
Methods
fit(statfunc, pars, parmins, parmaxes[, ...])Run the optimiser.
References
[1]Storn, R. and Price, K. “Differential Evolution: A Simple and Efficient Adaptive Scheme for Global Optimization over Continuous Spaces.” J. Global Optimization 11, 341-359, 1997. https://cse.engineering.nyu.edu/~mleung/CS909/s04/Storn95-012.pdf
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[[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,
statargsandstatkwargsas keyword arguments, return the statistic value.- parssequence
The start position of the model parameter values.
- parminssequence
The minimum allowed values for each model parameter. This must match the length of
pars.- parmaxessequence
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.
- statfunc
- Returns:
- newpars
tuple 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).
- newpars