skyllh.core.minimizers package
Submodules
skyllh.core.minimizers.crs module
- class skyllh.core.minimizers.crs.CRSMinimizerImpl(**kwargs)
Bases:
MinimizerImpl
The SkyLLH minimizer implementation that utilizes the CRS minimizer from nlopt.
Creates a new instance having the property
cfg
.- Parameters:
cfg (instance of Config) – The instance of Config holding the local configuration.
- minimize(initials, bounds, func, func_args=None, **kwargs)
Minimizes the given function
func
with the given initial function argument valuesinitials
and within the given parameter boundsbounds
.- Parameters:
initials (1D numpy ndarray) – The ndarray holding the initial values of all the fit parameters.
bounds (2D (N_fitparams,2)-shaped numpy ndarray) – The ndarray holding the boundary values (vmin, vmax) of the fit parameters.
func (callable) –
The function that should get minimized. The call signature must be
__call__(x, *args)
The return value of
func
must be (f, grads), the function value at the function argumentsx
and the ndarray with the values of the function gradient for each fit parameter, if thefunc_provides_grads
keyword argument option is set to True. If set to False,func
must return only the function value.func_args (sequence | None) – Optional sequence of arguments for
func
.Arguments (Additional Keyword) –
---------------------------- –
minimizer (Additional keyword arguments include options for this) –
are (implementation. Possible options) –
- func_provides_gradsbool
Flag if the function
func
also returns its gradients. Default isTrue
.
Any additional keyword arguments are passed on to the underlaying
iminuit.minimize()
minimization function.- Returns:
xmin (1D ndarray) – The array containing the function arguments at the function’s minimum.
fmin (float) – The function value at its minimum.
res (dictionary) – A dictionary with additional information.
- get_message(status)
returns the message belonging to the minimizer status
- Parameters:
status (int) – The number of the minimizer status
- get_niter(status)
Returns the number of iterations needed to find the minimum.
- Parameters:
status (dict) – The dictionary with the status information about the minimization process.
- Returns:
niter (int) – The number of iterations needed to find the minimum.
- has_converged(status)
Analyzes the status information dictionary if the minimization process has converged. By definition the minimization process has converged if
status['is_valid']
equals True.- Parameters:
status (dict) – The dictionary with the status information about the minimization process.
- Returns:
converged (bool) – The flag if the minimization has converged (True), or not (False).
- is_repeatable(status)
Checks if the minimization process can be repeated to get a better result.
TODO: Implement a proper check. For now just return True.
- Parameters:
status (dict) – The dictionary with the status information about the last minimization process.
- Returns:
repeatable (bool) – The flag if the minimization process can be repeated to obtain a better minimum.
skyllh.core.minimizers.iminuit module
The minimizers/iminuit module provides a SkyLLH interface to the iminuit minimizer.
- class skyllh.core.minimizers.iminuit.FuncWithGradsFunctor(func, func_args=None, **kwargs)
Bases:
HasConfig
Helper class to evaluate the LLH function that returns the function value and its gradients in two seperate calls, one for the LLH function value and one for its gradient values.
Initializes a new functor instance for the given function
func
.- Parameters:
func (callable) –
The function with call signature
__call__(x, *args)
returning the a two-element tuple (f, grads).
func_args (tuple | None) – The optional positional arguments for the function
func
.
- get_f(x)
- get_grads(x)
- class skyllh.core.minimizers.iminuit.IMinuitMinimizerImpl(**kwargs)
Bases:
MinimizerImpl
The SkyLLH minimizer implementation that utilizes the iminuit minimizer.
Creates a new instance having the property
cfg
.- Parameters:
cfg (instance of Config) – The instance of Config holding the local configuration.
- minimize(initials, bounds, func, func_args=None, **kwargs)
Minimizes the given function
func
with the given initial function argument valuesinitials
and within the given parameter boundsbounds
.- Parameters:
initials (1D numpy ndarray) – The ndarray holding the initial values of all the fit parameters.
bounds (2D (N_fitparams,2)-shaped numpy ndarray) – The ndarray holding the boundary values (vmin, vmax) of the fit parameters.
func (callable) –
The function that should get minimized. The call signature must be
__call__(x, *args)
The return value of
func
must be (f, grads), the function value at the function argumentsx
and the ndarray with the values of the function gradient for each fit parameter, if thefunc_provides_grads
keyword argument option is set to True. If set to False,func
must return only the function value.func_args (sequence | None) – Optional sequence of arguments for
func
.Arguments (Additional Keyword) –
---------------------------- –
minimizer (Additional keyword arguments include options for this) –
are (implementation. Possible options) –
- func_provides_gradsbool
Flag if the function
func
also returns its gradients. Default isTrue
.
Any additional keyword arguments are passed on to the underlaying
iminuit.minimize()
minimization function.- Returns:
xmin (1D ndarray) – The array containing the function arguments at the function’s minimum.
fmin (float) – The function value at its minimum.
res (iminuit.OptimizeResult) – The iminuit OptimizeResult dictionary with additional information.
- get_niter(status)
Returns the number of iterations needed to find the minimum.
- Parameters:
status (dict) – The dictionary with the status information about the minimization process.
- Returns:
niter (int) – The number of iterations needed to find the minimum.
- has_converged(status)
Analyzes the status information dictionary if the minimization process has converged. By definition the minimization process has converged if
status['is_valid']
equals True.- Parameters:
status (dict) – The dictionary with the status information about the minimization process.
- Returns:
converged (bool) – The flag if the minimization has converged (True), or not (False).
- is_repeatable(status)
Checks if the minimization process can be repeated to get a better result.
TODO: Implement a proper check. For now just return True.
- Parameters:
status (dict) – The dictionary with the status information about the last minimization process.
- Returns:
repeatable (bool) – The flag if the minimization process can be repeated to obtain a better minimum.