sample

class zfit.core.sample.EventSpace(obs: Union[str, Iterable[str], zfit.Space], limits: Union[Tuple[Tuple[Tuple[float, ...]]], Tuple[float, float], bool], factory=None, name: Optional[str] = 'Space')[source]

Bases: zfit.core.limits.Space

EXPERIMENTAL SPACE CLASS!

Define a space with the name (obs) of the axes (and it’s number) and possibly it’s limits.

Parameters
  • obs (str, List[str,..]) –

  • () (limits) –

  • name (str) –

ANY = <Any>
ANY_LOWER = <Any Lower Limit>
ANY_UPPER = <Any Upper Limit>
AUTO_FILL = <object object>
add(other: Union[zfit.Space, Iterable[zfit.Space]])[source]

Add the limits of the spaces. Only works for the same obs.

In case the observables are different, the order of the first space is taken.

Parameters

other (Space) –

Returns

Return type

Space

area() → float

Return the total area of all the limits and axes. Useful, for example, for MC integration.

property axes

The axes (“obs with int”) the space is defined in.

Returns:

combine(other: Union[zfit.Space, Iterable[zfit.Space]])[source]

Combine spaces with different obs (but consistent limits).

Parameters

other (Space) –

Returns

Return type

Space

copy(name: Optional[str] = None, **overwrite_kwargs) → zfit.Space

Create a new Space using the current attributes and overwriting with overwrite_overwrite_kwargs.

Parameters
  • name (str) – The new name. If not given, the new instance will be named the same as the current one.

  • () (**overwrite_kwargs) –

Returns

Space

create_limits(n)[source]
property factory
classmethod from_axes(axes: Union[int, Iterable[int]], limits: Union[Tuple[Tuple[Tuple[float, ...]]], Tuple[float, float], bool, None] = None, name: str = None) → zfit.Space

Create a space from axes instead of from obs.

Parameters
  • () (limits) –

  • ()

  • name (str) –

Returns

Space

get_axes(obs: Union[str, Iterable[str], zfit.Space] = None, as_dict: bool = False, autofill: bool = False) → Union[Tuple[int], None, Dict[str, int]]

Return the axes corresponding to the obs (or all if None).

Parameters
  • () (obs) –

  • as_dict (bool) – If True, returns a ordered dictionary with {obs: axis}

  • autofill (bool) – If True and the axes are not specified, automatically fill them with the default numbering and return (not setting them).

Returns

Tuple, OrderedDict

Raises
get_obs_axes(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None)
get_reorder_indices(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None) → Tuple[int]

Indices that would order self.obs as obs respectively self.axes as axes.

Parameters
  • () (axes) –

  • ()

Returns:

get_subspace(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None, name: Optional[str] = None) → zfit.Space

Create a Space consisting of only a subset of the obs/axes (only one allowed).

Parameters
  • obs (str, Tuple[str]) –

  • axes (int, Tuple[int]) –

  • () (name) –

Returns:

property is_generator
iter_areas(rel: bool = False) → Tuple[float, ...][source]

Return the areas of each interval

Parameters

rel (bool) – If True, return the relative fraction of each interval

Returns

Return type

Tuple[float]

iter_limits(as_tuple: bool = True) → Union[Tuple[zfit.Space], Tuple[Tuple[Tuple[float]]], Tuple[Tuple[float]]]

Return the limits, either as Space objects or as pure limits-tuple.

This makes iterating over limits easier: for limit in space.iter_limits() allows to, for example, pass limit to a function that can deal with simple limits only or if as_tuple is True the limit can be directly used to calculate something.

Example

for lower, upper in space.iter_limits(as_tuple=True):
    integrals = integrate(lower, upper)  # calculate integral
integral = sum(integrals)
Returns

Return type

List[Space] or List[limit,…]

property limit1d

return the tuple(lower, upper).

Returns

so lower, upper = space.limit1d for a simple, 1 obs limit.

Return type

tuple(float, float)

Raises

RuntimeError – if the conditions (n_obs or n_limits) are not satisfied.

Type

Simplified limits getter for 1 obs, 1 limit only

property limit2d

return the tuple(low_obs1, low_obs2, up_obs1, up_obs2).

Returns

so low_x, low_y, up_x, up_y = space.limit2d for a single, 2 obs limit.

low_x is the lower limit in x, up_x is the upper limit in x etc.

Return type

tuple(float, float, float, float)

Raises

RuntimeError – if the conditions (n_obs or n_limits) are not satisfied.

Type

Simplified limits for exactly 2 obs, 1 limit

property limits

Return the limits.

Returns:

property limits1d

return the tuple(low_1, …, low_n, up_1, …, up_n).

Returns

so low_1, low_2, up_1, up_2 = space.limits1d for several, 1 obs limits.

low_1 to up_1 is the first interval, low_2 to up_2 is the second interval etc.

Return type

tuple(float, float, ..)

Raises

RuntimeError – if the conditions (n_obs or n_limits) are not satisfied.

Type

Simplified .limits for exactly 1 obs, n limits

property lower

Return the lower limits.

Returns:

property n_limits

The number of different limits.

Returns

int >= 1

property n_obs

Return the number of observables/axes.

Returns

int >= 1

property name

The name of the object.

property obs

The observables (“axes with str”)the space is defined in.

Returns:

property obs_axes
reorder_by_indices(indices: Tuple[int])

Return a Space reordered by the indices.

Parameters

() (indices) –

property upper

Return the upper limits.

Returns:

with_autofill_axes(overwrite: bool = False) → zfit.Space

Return a Space with filled axes corresponding to range(len(n_obs)).

Parameters

overwrite (bool) – If self.axes is not None, replace the axes with the autofilled ones. If axes is already set, don’t do anything if overwrite is False.

Returns

Space

with_axes(axes: Union[int, Iterable[int]]) → zfit.Space

Sort by obs and return the new instance.

Parameters

() (axes) –

Returns

Space

with_limits(limits: Union[Tuple[Tuple[Tuple[float, ...]]], Tuple[float, float], bool], name: Optional[str] = None) → zfit.Space

Return a copy of the space with the new limits (and the new name).

Parameters
  • () (limits) –

  • name (str) –

Returns

Space

with_obs(obs: Union[str, Iterable[str], zfit.Space]) → zfit.Space

Sort by obs and return the new instance.

Parameters

() (obs) –

Returns

Space

with_obs_axes(obs_axes: Dict[str, int], ordered: bool = False, allow_subset=False) → zfit.Space

Return a new Space with reordered observables and set the axes.

Parameters
  • obs_axes (OrderedDict[str, int]) – An ordered dict with {obs: axes}.

  • ordered (bool) – If True (and the obs_axes is an OrderedDict), the

  • () (allow_subset) –

Returns

Return type

Space

class zfit.core.sample.UniformSampleAndWeights[source]

Bases: object

zfit.core.sample.extended_sampling(pdfs: Union[Iterable[zfit.core.interfaces.ZfitPDF], zfit.core.interfaces.ZfitPDF], limits: zfit.core.limits.Space) → tensorflow.python.framework.ops.Tensor[source]

Create a sample from extended pdfs by sampling poissonian using the yield.

Parameters
Returns

Return type

Union[tf.Tensor]

zfit.core.sample.extract_extended_pdfs(pdfs: Union[Iterable[zfit.core.interfaces.ZfitPDF], zfit.core.interfaces.ZfitPDF]) → List[zfit.core.interfaces.ZfitPDF][source]

Return all extended pdfs that are daughters.

Parameters

pdfs (Iterable[pdfs]) –

Returns

Return type

List[pdfs]