This module contains functions for the numeric as well as the analytic (partial) integration.

class zfit.core.integration.AnalyticIntegral(*args, **kwargs)[source]

Bases: object

Hold analytic integrals and manage their dimensions, limits etc.

get_max_axes(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], axes: Union[int, Iterable[int]] = None) → Tuple[int][source]

Return the maximal available axes to integrate over analytically for given limits

  • limits (Space) – The integral function will be able to integrate over this limits

  • axes (tuple) – The axes over which (or over a subset) it will integrate


Return type


get_max_integral(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], axes: Union[int, Iterable[int]] = None) → Union[None, zfit.core.integration.Integral][source]

Return the integral over the limits with axes (or a subset of them).

  • limits (ZfitSpace) –

  • axes (Tuple[int]) –


Return a callable that integrated over the given limits.

Return type

Union[None, Integral]

integrate(x: Union[float, tensorflow.python.framework.ops.Tensor, None], limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], axes: Union[int, Iterable[int]] = None, norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, model: zfit.core.interfaces.ZfitModel = None, params: dict = None) → Union[float, tensorflow.python.framework.ops.Tensor][source]

Integrate analytically over the axes if available.

  • x (numeric) – If a partial integration is made, x are the value to be evaluated for the partial integrated function. If a full integration is performed, this should be None.

  • limits (ZfitSpace) – The limits to integrate

  • axes (Tuple[int]) – The dimensions to integrate over

  • norm_range (bool) – |norm_range_arg_descr|

  • params (dict) – The parameters of the function


Return type

Union[tf.Tensor, float]


AnalyticIntegralNotImplementedError – If the requested integral is not available.

register(func: Callable, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], priority: int = 50, *, supports_norm_range: bool = False, supports_multiple_limits: bool = False) → None[source]

Register an analytic integral.

  • func (callable) – The integral function. Takes 1 argument.

  • axes (tuple) – |dims_arg_descr|

  • limits (possible) – |limits_arg_descr| Limits can be None if func works for any

  • limits

  • priority (int) – If two or more integrals can integrate over certain limits, the one with the higher priority is taken (usually around 0-100).

  • supports_norm_range (bool) – If True, norm_range will (if needed) be given to func as an argument.

  • supports_multiple_limits (bool) – If True, multiple limits may be given as an argument to func.

class zfit.core.integration.Integral(func: Callable, limits: zfit.core.interfaces.ZfitSpace, priority: Union[int, float])[source]

Bases: object

A lightweight holder for the integral function.

class zfit.core.integration.Integration(mc_sampler, draws_per_dim)[source]

Bases: object

class zfit.core.integration.PartialIntegralSampleData(sample: List[tensorflow.python.framework.ops.Tensor], space: zfit.core.interfaces.ZfitSpace)[source]

Bases: zfit.core.dimension.BaseDimensional, zfit.core.interfaces.ZfitData

Takes a list of tensors and “fakes” a dataset. Useful for tensors with non-matching shapes.

  • sample (List[tf.Tensor]) –

  • () (space) –

property axes

Return the axes, integer based identifier(indices) for the coordinate system.

property n_obs

Return the number of observables, the dimensionality. Corresponds to the last dimension.

property obs

Return the observables, string identifier for the coordinate system.

sort_by_axes(axes, allow_superset: bool = True)[source]
sort_by_obs(obs, allow_superset: bool = True)[source]
property space
value(obs: List[str] = None)[source]
property weights
zfit.core.integration.auto_integrate(*, norm_range: bool = False, multiple_limits: bool = False) → Callable[source]
zfit.core.integration.chunked_average(func, x, num_batches, batch_size, space, mc_sampler)[source]
zfit.core.integration.mc_integrate(func: Callable, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], axes: Union[int, Iterable[int], None] = None, x: Union[float, tensorflow.python.framework.ops.Tensor, None] = None, n_axes: Optional[int] = None, draws_per_dim: int = 20000, method: str = None, dtype: Type = tf.float64, mc_sampler: Callable = <function sample_halton_sequence>, importance_sampling: Optional[Callable] = None) → tensorflow.python.framework.ops.Tensor[source]

Monte Carlo integration of func over limits.

  • func (callable) – The function to be integrated over

  • limits (ZfitSpace) – The limits of the integral

  • axes (tuple(int)) – The row to integrate over. None means integration over all value

  • x (numeric) – If a partial integration is performed, this are the value where x will be evaluated.

  • n_axes (int) – the number of total dimensions (old?)

  • draws_per_dim (int) – How many random points to draw per dimensions

  • method (str) – Which integration method to use

  • dtype (dtype) – |dtype_arg_descr|

  • mc_sampler (callable) – A function that takes one argument (n_draws or similar) and returns random value between 0 and 1.

  • () (importance_sampling) –


the integral

Return type


zfit.core.integration.normalization_chunked(func, n_axes, batch_size, num_batches, dtype, space, x=None, shape_after=())[source]
zfit.core.integration.normalization_nograd(func, n_axes, batch_size, num_batches, dtype, space, x=None, shape_after=())[source]

Integrate func using numerical methods.