# integration¶

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

Parameters
• 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

Returns

Return type

Tuple[int]

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).

Parameters
Returns

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.

Parameters
• 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 (Space) – 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

Returns

Return type

Union[tf.Tensor, float]

Raises

NotImplementedError – 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.

Parameters
• 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.limits.Space, 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]

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

Parameters
• sample (List[tf.Tensor]) –

• () (space) –

property axes

Return the axes.

copy(deep: bool = False, **overwrite_params) → zfit.core.interfaces.ZfitObject
property n_obs

Return the number of observables.

property name

Name prepended to all ops created by this model.

property obs

Return the observables.

sort_by_axes(axes, allow_superset: bool = False)[source]
sort_by_obs(obs, allow_superset: bool = False)[source]
property space

Return the Space object that defines the dimensionality of the object.

unstack_x(always_list=False)[source]
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.

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

• limits (Space) – 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) –

Returns

the integral

Return type

numerical

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]
zfit.core.integration.numeric_integrate()[source]

Integrate func using numerical methods.