minimize

class zfit.minimize.MinuitMinimizer(strategy: zfit.minimizers.baseminimizer.ZfitStrategy = None, minimize_strategy: int = 1, tolerance: float = None, verbosity: int = 5, name: str = None, ncall: int = 10000, use_minuit_grad: bool = None, **minimizer_options)[source]

Bases: zfit.minimizers.minimizer_minuit.Minuit

DEPRECATED FUNCTION

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use zfit.minimize.Minuit instead.

add_cache_deps(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)

Add dependencies that render the cache invalid if they change.

Parameters:
  • cache_deps (ZfitGraphCachable) –
  • allow_non_cachable (bool) – If True, allow cache_dependents to be non-cachables. If False, any cache_dependents that is not a ZfitCachable will raise an error.
Raises:

TypeError – if one of the cache_dependents is not a ZfitCachable _and_ allow_non_cachable if False.

copy()
graph_caching_methods = []
instances = <_weakrefset.WeakSet object>
minimize(loss: zfit.core.interfaces.ZfitLoss, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None) → zfit.minimizers.fitresult.FitResult

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

register_cacher(cacher: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]])

Register a cacher that caches values produces by this instance; a dependent.

Parameters:() (cacher) –
reset_cache(reseter: zfit.util.cache.ZfitGraphCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

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

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
class zfit.minimize.ScipyMinimizer(minimizer='L-BFGS-B', tolerance=None, verbosity=5, name=None, **minimizer_options)[source]

Bases: zfit.minimizers.minimizers_scipy.Scipy

DEPRECATED FUNCTION

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use zfit.minimize.Scipy instead.

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

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)

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
class zfit.minimize.AdamMinimizer(tolerance=None, learning_rate=0.2, beta1=0.9, beta2=0.999, epsilon=1e-08, name='Adam', **kwargs)[source]

Bases: zfit.minimizers.optimizers_tf.Adam

DEPRECATED FUNCTION

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use zfit.minimize.Adam instead.

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

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)

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
class zfit.minimize.WrapOptimizer(optimizer, tolerance=None, verbosity=None, name=None, **kwargs)[source]

Bases: zfit.minimizers.baseminimizer.BaseMinimizer

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

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)

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
class zfit.minimize.Adam(tolerance=None, learning_rate=0.2, beta1=0.9, beta2=0.999, epsilon=1e-08, name='Adam', **kwargs)[source]

Bases: zfit.minimizers.base_tf.WrapOptimizer

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

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)

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
class zfit.minimize.Minuit(strategy: zfit.minimizers.baseminimizer.ZfitStrategy = None, minimize_strategy: int = 1, tolerance: float = None, verbosity: int = 5, name: str = None, ncall: int = 10000, use_minuit_grad: bool = None, **minimizer_options)[source]

Bases: zfit.minimizers.baseminimizer.BaseMinimizer, zfit.util.cache.GraphCachable

Parameters:
  • () (strategy) – A ZfitStrategy object that defines the behavior of
  • minimizer in certain situations. (the) –
  • minimize_strategy (int) – A number used by minuit to define the strategy, either 0, 1 or 2.
  • tolerance (float) – Stopping criteria: the Estimated Distance to Minimum (EDM) has to be lower then tolerance
  • verbosity (int) – Regulates how much will be printed during minimization. Values between 0 and 10 are valid.
  • name (str) – Name of the minimizer
  • ncall (int) – Maximum number of minimization steps.
  • use_minuit_grad (bool) – If True, iminuit uses it’s internal numerical gradient calculation instead of the (analytic/numerical) gradient provided by TensorFlow/zfit.
add_cache_deps(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)

Add dependencies that render the cache invalid if they change.

Parameters:
  • cache_deps (ZfitGraphCachable) –
  • allow_non_cachable (bool) – If True, allow cache_dependents to be non-cachables. If False, any cache_dependents that is not a ZfitCachable will raise an error.
Raises:

TypeError – if one of the cache_dependents is not a ZfitCachable _and_ allow_non_cachable if False.

copy()[source]
graph_caching_methods = []
instances = <_weakrefset.WeakSet object>
minimize(loss: zfit.core.interfaces.ZfitLoss, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None) → zfit.minimizers.fitresult.FitResult

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

register_cacher(cacher: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]])

Register a cacher that caches values produces by this instance; a dependent.

Parameters:() (cacher) –
reset_cache(reseter: zfit.util.cache.ZfitGraphCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

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

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
class zfit.minimize.Scipy(minimizer='L-BFGS-B', tolerance=None, verbosity=5, name=None, **minimizer_options)[source]

Bases: zfit.minimizers.baseminimizer.BaseMinimizer

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

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)

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
class zfit.minimize.BFGS(strategy: zfit.minimizers.baseminimizer.ZfitStrategy = None, tolerance: float = 1e-05, verbosity: int = 5, max_calls: int = 3000, name: str = 'BFGS_TFP', options: Mapping[KT, VT_co] = None)[source]

Bases: zfit.minimizers.baseminimizer.BaseMinimizer

Parameters:
  • strategy (ZfitStrategy) – Strategy that handles NaN and more (to come, experimental)
  • tolerance (float) – Difference between the function value that suffices to stop minimization
  • verbosity – The higher, the more is printed. Between 1 and 10 typically
  • max_calls (int) – Maximum number of calls, approximate
  • name – Name of the Minimizer
  • options – A dict containing the options given to the minimization function, overriding the default
copy()
minimize(loss: zfit.core.interfaces.ZfitLoss, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None) → zfit.minimizers.fitresult.FitResult

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)

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

Parameters:() (params) –

Returns:

Raises:MinimizeStepNotImplementedError – if the step method is not implemented in the minimizer.
tolerance
zfit.minimize.DefaultStrategy

alias of zfit.minimizers.baseminimizer.PushbackStrategy

class zfit.minimize.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[KT, VT_co] = None) → float