baseminimizer

Definition of minimizers, wrappers etc.

class zfit.minimizers.baseminimizer.BaseMinimizer(name, tolerance, verbosity, minimizer_options, strategy=None, **kwargs)[source]

Bases: zfit.minimizers.interface.ZfitMinimizer

Minimizer for loss functions.

Additional minimizer_options (given as **kwargs) can be accessed and changed via the attribute (dict) minimizer.minimizer_options

copy()[source]
minimize(loss: zfit.core.interfaces.ZfitLoss, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None) → zfit.minimizers.fitresult.FitResult[source]

Fully minimize the loss with respect to params.

Parameters
  • loss (ZfitLoss) – Loss to be minimized.

  • params (list(zfit.Parameter) – The parameters with respect to which to minimize the loss. If None, the parameters will be taken from the loss.

Returns

The fit result.

Return type

FitResult

step(loss, params: Union[Iterable[zfit.core.interfaces.ZfitParameter], None, Iterable[str]] = None)[source]

Perform a single step in the minimization (if implemented).

Parameters

() (params) –

Returns:

Raises

MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.

property tolerance
class zfit.minimizers.baseminimizer.BaseStrategy[source]

Bases: zfit.minimizers.baseminimizer.ZfitStrategy

minimize_nan(loss: zfit.core.interfaces.ZfitLoss, params: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], minimizer: zfit.minimizers.interface.ZfitMinimizer, values: Mapping = None) → float[source]
zfit.minimizers.baseminimizer.DefaultStrategy

alias of zfit.minimizers.baseminimizer.PushbackStrategy

class zfit.minimizers.baseminimizer.DefaultToyStrategy(nan_penalty: Union[float, int] = 100, nan_tolerance: int = 30, **kwargs)[source]

Bases: zfit.minimizers.baseminimizer.PushbackStrategy, zfit.minimizers.baseminimizer.ToyStrategyFail

Same as DefaultStrategy, but does not raise an error on full failure, instead return an invalid FitResult.

This can be useful for toy studies, where multiple fits are done and a failure should simply be counted as a failure instead of rising an error.

Pushback by adding nan_penalty * counter to the loss if NaNs are encountered.

The counter indicates how many NaNs occurred in a row. The nan_tolerance is the upper limit, if this is exceeded, the fallback will be used and an error is raised. :param nan_penalty: Value to add to the previous loss in order to penalize the step taken :param nan_tolerance: If the number of NaNs encountered in a row exceeds this number, the fallback is used.

minimize_nan(loss: zfit.core.interfaces.ZfitLoss, params: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], minimizer: zfit.minimizers.interface.ZfitMinimizer, values: Mapping = None) → float
exception zfit.minimizers.baseminimizer.FailMinimizeNaN[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class zfit.minimizers.baseminimizer.PushbackStrategy(nan_penalty: Union[float, int] = 100, nan_tolerance: int = 30, **kwargs)[source]

Bases: zfit.minimizers.baseminimizer.BaseStrategy

Pushback by adding nan_penalty * counter to the loss if NaNs are encountered.

The counter indicates how many NaNs occurred in a row. The nan_tolerance is the upper limit, if this is exceeded, the fallback will be used and an error is raised. :param nan_penalty: Value to add to the previous loss in order to penalize the step taken :param nan_tolerance: If the number of NaNs encountered in a row exceeds this number, the fallback is used.

minimize_nan(loss: zfit.core.interfaces.ZfitLoss, params: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], minimizer: zfit.minimizers.interface.ZfitMinimizer, values: Mapping = None) → float
class zfit.minimizers.baseminimizer.ToyStrategyFail[source]

Bases: zfit.minimizers.baseminimizer.BaseStrategy

minimize_nan(loss: zfit.core.interfaces.ZfitLoss, params: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], minimizer: zfit.minimizers.interface.ZfitMinimizer, values: Mapping = None) → float
class zfit.minimizers.baseminimizer.ZfitStrategy[source]

Bases: abc.ABC

abstract minimize_nan(loss: zfit.core.interfaces.ZfitLoss, params: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], minimizer: zfit.minimizers.interface.ZfitMinimizer, values: Mapping = None) → float[source]
zfit.minimizers.baseminimizer.print_gradients(params, values, gradients, loss=None)[source]
zfit.minimizers.baseminimizer.print_params(params, values, loss=None)[source]