skyllh.core.minimizers package

Submodules

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)

Bases: object

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(ftol=1e-06)

Bases: MinimizerImpl

The SkyLLH minimizer implementation that utilizes the iminuit minimizer.

Creates a new IMinuit minimizer instance to minimize a given function.

Parameters:

ftol (float) – The function value tolerance as absolute value.

minimize(initials, bounds, func, func_args=None, **kwargs)

Minimizes the given function func with the given initial function argument values initials and within the given parameter bounds bounds.

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 arguments x and the ndarray with the values of the function gradient for each fit parameter, if the func_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 is True.

  • underlaying (Any additional keyword arguments are passed on to the) –

:param 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.