func

class zfit.func.BaseFunc(obs=None, dtype: Type[CT_co] = tf.float64, name: str = 'BaseFunc', params: Any = None)[source]

Bases: zfit.core.basemodel.BaseModel, zfit.core.interfaces.ZfitFunc

TODO(docs): explain subclassing

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

Add dependents that render the cache invalid if they change.

Parameters:
  • cache_dependents (ZfitCachable) –
  • 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.

analytic_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'analytic_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Analytical integration over function and raise Error if not possible.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

Raises:
  • NotImplementedError – If no analytical integral is available (for this limits).
  • NormRangeNotImplementedError – if the norm_range argument is not supported. This means that no analytical normalization is available, explicitly: the analytical integral over the limits = norm_range is not available.
as_pdf() → zfit.core.interfaces.ZfitPDF[source]

Create a PDF out of the function

Returns:a PDF with the current function as the unnormalized probability.
Return type:ZfitPDF
axes

Return the axes.

convert_sort_space(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None, limits: Union[Tuple[Tuple[Tuple[float, ...]]], Tuple[float, float], bool] = None) → Optional[zfit.core.limits.Space]

Convert the inputs (using eventually obs, axes) to Space and sort them according to own obs.

Parameters:
  • () (limits) –
  • ()
  • ()

Returns:

copy(**override_params)[source]
create_sampler(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, fixed_params: Union[bool, List[zfit.core.interfaces.ZfitParameter], Tuple[zfit.core.interfaces.ZfitParameter]] = True, name: str = 'create_sampler') → zfit.core.data.Sampler

Create a Sampler that acts as Data but can be resampled, also with changed parameters and n.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.
Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • () (name) – From which space to sample.
  • () – A list of Parameters that will be fixed during several resample calls. If True, all are fixed, if False, all are floating. If a Parameter is not fixed and its value gets updated (e.g. by a Parameter.set_value() call), this will be reflected in resample. If fixed, the Parameter will still have the same value as the Sampler has been created with when it resamples.
  • ()
Returns:

py:class:~`zfit.core.data.Sampler`

Raises:
  • NotExtendedPDFError – if ‘extended’ is chosen (implicitly by default or explicitly) as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
dtype

The dtype of the object

func(x: Union[float, tensorflow.python.framework.ops.Tensor], name: str = 'value') → Union[float, tensorflow.python.framework.ops.Tensor][source]

The function evaluated at x.

Parameters:
  • x (Data) –
  • name (str) –
Returns:

# TODO(Mayou36): or dataset? Update: rather not, what would obs be?

Return type:

tf.Tensor

get_dependents(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])

Return a set of all independent Parameter that this object depends on.

Parameters:only_floating (bool) – If True, only return floating Parameter
get_params(only_floating: bool = False, names: Union[str, List[str], None] = None) → List[zfit.core.interfaces.ZfitParameter]

Return the parameters. If it is empty, automatically return all floating variables.

Parameters:
  • () (names) – If True, return only the floating parameters.
  • () – The names of the parameters to return.
Returns:

Return type:

list(ZfitParameters)

gradients(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None)[source]
graph_caching_methods = []
integrate(**kwargs)
n_obs

Return the number of observables.

name

The name of the object.

numeric_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Numerical integration over the model.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

obs

Return the observables.

old_graph_caching_methods = []
params
partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(x: Union[float, tensorflow.python.framework.ops.Tensor], limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'partial_numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Force numerical partial integration of the function over the limits and evaluate it at x.

Dimension of limits and x have to add up to the full dimension and be therefore equal to the dimensions of norm_range (if not False)

Parameters:
  • x (numerical) – The value at which the partially integrated function will be evaluated
  • limits (tuple, Space) – the limits to integrate over. Can contain only some axes
  • norm_range (tuple, Space, False) – the limits to normalize over. Has to have all axes
  • name (str) –
Returns:

the value of the partially integrated function evaluated at x.

Return type:

Tensor

classmethod register_additional_repr(**kwargs)

Register an additional attribute to add to the repr.

Parameters:
  • keyword argument. The value has to be gettable from the instance (has to be an (any) –
  • or callable method of self. (attribute) –
classmethod register_analytic_integral(func: Callable, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, priority: Union[int, float] = 50, *, supports_norm_range: bool = False, supports_multiple_limits: bool = False) → None

Register an analytic integral with the class.

Parameters:
  • func (callable) –

    A function that calculates the (partial) integral over the axes limits. The signature has to be the following:

    • x (ZfitData, None): the data for the remaining axes in a partial
      integral. If it is not a partial integral, this will be None.
    • limits (Space): the limits to integrate over.
    • norm_range (Space, None): Normalization range of the integral.
      If not supports_supports_norm_range, this will be None.
    • params (Dict[param_name, zfit.Parameters]): The parameters of the model.
    • model (ZfitModel):The model that is being integrated.
  • () (limits) – |limits_arg_descr|
  • priority (int) – Priority of the function. If multiple functions cover the same space, the one with the highest priority will be used.
  • supports_multiple_limits (bool) – If True, the limits given to the integration function can have multiple limits. If False, only simple limits will pass through and multiple limits will be auto-handled.
  • supports_norm_range (bool) – If True, norm_range argument to the function may not be None. If False, norm_range will always be None and care is taken of the normalization automatically.
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) –
classmethod register_inverse_analytic_integral(func: Callable) → None

Register an inverse analytical integral, the inverse (unnormalized) cdf.

Parameters:() (func) –
reset_cache(reseter: zfit.util.cache.ZfitCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'sample') → zfit.core.data.SampleData

Sample n points within limits from the model.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.

Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • limits (tuple, Space) – In which region to sample in
  • name (str) –
Returns:

SampleData(n_obs, n_samples)

Raises:
  • NotExtendedPDFError – if ‘extended’ is (implicitly by default or explicitly) chosen as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
space

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

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters:
  • draws_per_dim (int) – The draws for MC integration to do
  • () (mc_sampler) –
class zfit.func.ProdFunc(funcs: Iterable[zfit.core.interfaces.ZfitFunc], obs: Union[str, Iterable[str], zfit.Space] = None, name: str = 'SumFunc', **kwargs)[source]

Bases: zfit.models.functions.BaseFunctorFunc

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

Add dependents that render the cache invalid if they change.

Parameters:
  • cache_dependents (ZfitCachable) –
  • 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.

analytic_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'analytic_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Analytical integration over function and raise Error if not possible.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

Raises:
  • NotImplementedError – If no analytical integral is available (for this limits).
  • NormRangeNotImplementedError – if the norm_range argument is not supported. This means that no analytical normalization is available, explicitly: the analytical integral over the limits = norm_range is not available.
as_pdf() → zfit.core.interfaces.ZfitPDF

Create a PDF out of the function

Returns:a PDF with the current function as the unnormalized probability.
Return type:ZfitPDF
axes

Return the axes.

convert_sort_space(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None, limits: Union[Tuple[Tuple[Tuple[float, ...]]], Tuple[float, float], bool] = None) → Optional[zfit.core.limits.Space]

Convert the inputs (using eventually obs, axes) to Space and sort them according to own obs.

Parameters:
  • () (limits) –
  • ()
  • ()

Returns:

copy(**override_params)
create_sampler(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, fixed_params: Union[bool, List[zfit.core.interfaces.ZfitParameter], Tuple[zfit.core.interfaces.ZfitParameter]] = True, name: str = 'create_sampler') → zfit.core.data.Sampler

Create a Sampler that acts as Data but can be resampled, also with changed parameters and n.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.
Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • () (name) – From which space to sample.
  • () – A list of Parameters that will be fixed during several resample calls. If True, all are fixed, if False, all are floating. If a Parameter is not fixed and its value gets updated (e.g. by a Parameter.set_value() call), this will be reflected in resample. If fixed, the Parameter will still have the same value as the Sampler has been created with when it resamples.
  • ()
Returns:

py:class:~`zfit.core.data.Sampler`

Raises:
  • NotExtendedPDFError – if ‘extended’ is chosen (implicitly by default or explicitly) as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
dtype

The dtype of the object

func(x: Union[float, tensorflow.python.framework.ops.Tensor], name: str = 'value') → Union[float, tensorflow.python.framework.ops.Tensor]

The function evaluated at x.

Parameters:
  • x (Data) –
  • name (str) –
Returns:

# TODO(Mayou36): or dataset? Update: rather not, what would obs be?

Return type:

tf.Tensor

get_dependents(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])

Return a set of all independent Parameter that this object depends on.

Parameters:only_floating (bool) – If True, only return floating Parameter
get_models(names=None) → List[zfit.core.interfaces.ZfitModel]
get_params(only_floating: bool = False, names: Union[str, List[str], None] = None) → List[zfit.core.interfaces.ZfitParameter]

Return the parameters. If it is empty, automatically return all floating variables.

Parameters:
  • () (names) – If True, return only the floating parameters.
  • () – The names of the parameters to return.
Returns:

Return type:

list(ZfitParameters)

gradients(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None)
graph_caching_methods = []
integrate(**kwargs)
models

Return the models of this Functor. Can be pdfs or funcs.

n_obs

Return the number of observables.

name

The name of the object.

numeric_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Numerical integration over the model.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

obs

Return the observables.

old_graph_caching_methods = []
params
partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(x: Union[float, tensorflow.python.framework.ops.Tensor], limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'partial_numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Force numerical partial integration of the function over the limits and evaluate it at x.

Dimension of limits and x have to add up to the full dimension and be therefore equal to the dimensions of norm_range (if not False)

Parameters:
  • x (numerical) – The value at which the partially integrated function will be evaluated
  • limits (tuple, Space) – the limits to integrate over. Can contain only some axes
  • norm_range (tuple, Space, False) – the limits to normalize over. Has to have all axes
  • name (str) –
Returns:

the value of the partially integrated function evaluated at x.

Return type:

Tensor

classmethod register_additional_repr(**kwargs)

Register an additional attribute to add to the repr.

Parameters:
  • keyword argument. The value has to be gettable from the instance (has to be an (any) –
  • or callable method of self. (attribute) –
classmethod register_analytic_integral(func: Callable, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, priority: Union[int, float] = 50, *, supports_norm_range: bool = False, supports_multiple_limits: bool = False) → None

Register an analytic integral with the class.

Parameters:
  • func (callable) –

    A function that calculates the (partial) integral over the axes limits. The signature has to be the following:

    • x (ZfitData, None): the data for the remaining axes in a partial
      integral. If it is not a partial integral, this will be None.
    • limits (Space): the limits to integrate over.
    • norm_range (Space, None): Normalization range of the integral.
      If not supports_supports_norm_range, this will be None.
    • params (Dict[param_name, zfit.Parameters]): The parameters of the model.
    • model (ZfitModel):The model that is being integrated.
  • () (limits) – |limits_arg_descr|
  • priority (int) – Priority of the function. If multiple functions cover the same space, the one with the highest priority will be used.
  • supports_multiple_limits (bool) – If True, the limits given to the integration function can have multiple limits. If False, only simple limits will pass through and multiple limits will be auto-handled.
  • supports_norm_range (bool) – If True, norm_range argument to the function may not be None. If False, norm_range will always be None and care is taken of the normalization automatically.
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) –
classmethod register_inverse_analytic_integral(func: Callable) → None

Register an inverse analytical integral, the inverse (unnormalized) cdf.

Parameters:() (func) –
reset_cache(reseter: zfit.util.cache.ZfitCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'sample') → zfit.core.data.SampleData

Sample n points within limits from the model.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.

Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • limits (tuple, Space) – In which region to sample in
  • name (str) –
Returns:

SampleData(n_obs, n_samples)

Raises:
  • NotExtendedPDFError – if ‘extended’ is (implicitly by default or explicitly) chosen as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
space

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

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters:
  • draws_per_dim (int) – The draws for MC integration to do
  • () (mc_sampler) –
class zfit.func.SumFunc(funcs: Iterable[zfit.core.interfaces.ZfitFunc], obs: Union[str, Iterable[str], zfit.Space] = None, name: str = 'SumFunc', **kwargs)[source]

Bases: zfit.models.functions.BaseFunctorFunc

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

Add dependents that render the cache invalid if they change.

Parameters:
  • cache_dependents (ZfitCachable) –
  • 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.

analytic_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'analytic_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Analytical integration over function and raise Error if not possible.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

Raises:
  • NotImplementedError – If no analytical integral is available (for this limits).
  • NormRangeNotImplementedError – if the norm_range argument is not supported. This means that no analytical normalization is available, explicitly: the analytical integral over the limits = norm_range is not available.
as_pdf() → zfit.core.interfaces.ZfitPDF

Create a PDF out of the function

Returns:a PDF with the current function as the unnormalized probability.
Return type:ZfitPDF
axes

Return the axes.

convert_sort_space(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None, limits: Union[Tuple[Tuple[Tuple[float, ...]]], Tuple[float, float], bool] = None) → Optional[zfit.core.limits.Space]

Convert the inputs (using eventually obs, axes) to Space and sort them according to own obs.

Parameters:
  • () (limits) –
  • ()
  • ()

Returns:

copy(**override_params)
create_sampler(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, fixed_params: Union[bool, List[zfit.core.interfaces.ZfitParameter], Tuple[zfit.core.interfaces.ZfitParameter]] = True, name: str = 'create_sampler') → zfit.core.data.Sampler

Create a Sampler that acts as Data but can be resampled, also with changed parameters and n.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.
Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • () (name) – From which space to sample.
  • () – A list of Parameters that will be fixed during several resample calls. If True, all are fixed, if False, all are floating. If a Parameter is not fixed and its value gets updated (e.g. by a Parameter.set_value() call), this will be reflected in resample. If fixed, the Parameter will still have the same value as the Sampler has been created with when it resamples.
  • ()
Returns:

py:class:~`zfit.core.data.Sampler`

Raises:
  • NotExtendedPDFError – if ‘extended’ is chosen (implicitly by default or explicitly) as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
dtype

The dtype of the object

func(x: Union[float, tensorflow.python.framework.ops.Tensor], name: str = 'value') → Union[float, tensorflow.python.framework.ops.Tensor]

The function evaluated at x.

Parameters:
  • x (Data) –
  • name (str) –
Returns:

# TODO(Mayou36): or dataset? Update: rather not, what would obs be?

Return type:

tf.Tensor

get_dependents(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])

Return a set of all independent Parameter that this object depends on.

Parameters:only_floating (bool) – If True, only return floating Parameter
get_models(names=None) → List[zfit.core.interfaces.ZfitModel]
get_params(only_floating: bool = False, names: Union[str, List[str], None] = None) → List[zfit.core.interfaces.ZfitParameter]

Return the parameters. If it is empty, automatically return all floating variables.

Parameters:
  • () (names) – If True, return only the floating parameters.
  • () – The names of the parameters to return.
Returns:

Return type:

list(ZfitParameters)

gradients(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None)
graph_caching_methods = []
integrate(**kwargs)
models

Return the models of this Functor. Can be pdfs or funcs.

n_obs

Return the number of observables.

name

The name of the object.

numeric_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Numerical integration over the model.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

obs

Return the observables.

old_graph_caching_methods = []
params
partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(x: Union[float, tensorflow.python.framework.ops.Tensor], limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'partial_numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Force numerical partial integration of the function over the limits and evaluate it at x.

Dimension of limits and x have to add up to the full dimension and be therefore equal to the dimensions of norm_range (if not False)

Parameters:
  • x (numerical) – The value at which the partially integrated function will be evaluated
  • limits (tuple, Space) – the limits to integrate over. Can contain only some axes
  • norm_range (tuple, Space, False) – the limits to normalize over. Has to have all axes
  • name (str) –
Returns:

the value of the partially integrated function evaluated at x.

Return type:

Tensor

classmethod register_additional_repr(**kwargs)

Register an additional attribute to add to the repr.

Parameters:
  • keyword argument. The value has to be gettable from the instance (has to be an (any) –
  • or callable method of self. (attribute) –
classmethod register_analytic_integral(func: Callable, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, priority: Union[int, float] = 50, *, supports_norm_range: bool = False, supports_multiple_limits: bool = False) → None

Register an analytic integral with the class.

Parameters:
  • func (callable) –

    A function that calculates the (partial) integral over the axes limits. The signature has to be the following:

    • x (ZfitData, None): the data for the remaining axes in a partial
      integral. If it is not a partial integral, this will be None.
    • limits (Space): the limits to integrate over.
    • norm_range (Space, None): Normalization range of the integral.
      If not supports_supports_norm_range, this will be None.
    • params (Dict[param_name, zfit.Parameters]): The parameters of the model.
    • model (ZfitModel):The model that is being integrated.
  • () (limits) – |limits_arg_descr|
  • priority (int) – Priority of the function. If multiple functions cover the same space, the one with the highest priority will be used.
  • supports_multiple_limits (bool) – If True, the limits given to the integration function can have multiple limits. If False, only simple limits will pass through and multiple limits will be auto-handled.
  • supports_norm_range (bool) – If True, norm_range argument to the function may not be None. If False, norm_range will always be None and care is taken of the normalization automatically.
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) –
classmethod register_inverse_analytic_integral(func: Callable) → None

Register an inverse analytical integral, the inverse (unnormalized) cdf.

Parameters:() (func) –
reset_cache(reseter: zfit.util.cache.ZfitCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'sample') → zfit.core.data.SampleData

Sample n points within limits from the model.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.

Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • limits (tuple, Space) – In which region to sample in
  • name (str) –
Returns:

SampleData(n_obs, n_samples)

Raises:
  • NotExtendedPDFError – if ‘extended’ is (implicitly by default or explicitly) chosen as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
space

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

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters:
  • draws_per_dim (int) – The draws for MC integration to do
  • () (mc_sampler) –
class zfit.func.SimpleFunc(obs: Union[str, Iterable[str], zfit.Space], func: Callable, name: str = 'Function', **params)[source]

Bases: zfit.core.basefunc.BaseFunc

Create a simple function out of of func with the observables obs depending on parameters.

Parameters:
  • func (function) –
  • obs (Union[str, Tuple[str]]) –
  • name (str) –
  • () (**params) – The parameters as keyword arguments. E.g. mu=Parameter(…)
add_cache_dependents(cache_dependents: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)

Add dependents that render the cache invalid if they change.

Parameters:
  • cache_dependents (ZfitCachable) –
  • 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.

analytic_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'analytic_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Analytical integration over function and raise Error if not possible.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

Raises:
  • NotImplementedError – If no analytical integral is available (for this limits).
  • NormRangeNotImplementedError – if the norm_range argument is not supported. This means that no analytical normalization is available, explicitly: the analytical integral over the limits = norm_range is not available.
as_pdf() → zfit.core.interfaces.ZfitPDF

Create a PDF out of the function

Returns:a PDF with the current function as the unnormalized probability.
Return type:ZfitPDF
axes

Return the axes.

convert_sort_space(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None, limits: Union[Tuple[Tuple[Tuple[float, ...]]], Tuple[float, float], bool] = None) → Optional[zfit.core.limits.Space]

Convert the inputs (using eventually obs, axes) to Space and sort them according to own obs.

Parameters:
  • () (limits) –
  • ()
  • ()

Returns:

copy(**override_params)
create_sampler(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, fixed_params: Union[bool, List[zfit.core.interfaces.ZfitParameter], Tuple[zfit.core.interfaces.ZfitParameter]] = True, name: str = 'create_sampler') → zfit.core.data.Sampler

Create a Sampler that acts as Data but can be resampled, also with changed parameters and n.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.
Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • () (name) – From which space to sample.
  • () – A list of Parameters that will be fixed during several resample calls. If True, all are fixed, if False, all are floating. If a Parameter is not fixed and its value gets updated (e.g. by a Parameter.set_value() call), this will be reflected in resample. If fixed, the Parameter will still have the same value as the Sampler has been created with when it resamples.
  • ()
Returns:

py:class:~`zfit.core.data.Sampler`

Raises:
  • NotExtendedPDFError – if ‘extended’ is chosen (implicitly by default or explicitly) as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
dtype

The dtype of the object

func(x: Union[float, tensorflow.python.framework.ops.Tensor], name: str = 'value') → Union[float, tensorflow.python.framework.ops.Tensor]

The function evaluated at x.

Parameters:
  • x (Data) –
  • name (str) –
Returns:

# TODO(Mayou36): or dataset? Update: rather not, what would obs be?

Return type:

tf.Tensor

get_dependents(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])

Return a set of all independent Parameter that this object depends on.

Parameters:only_floating (bool) – If True, only return floating Parameter
get_params(only_floating: bool = False, names: Union[str, List[str], None] = None) → List[zfit.core.interfaces.ZfitParameter]

Return the parameters. If it is empty, automatically return all floating variables.

Parameters:
  • () (names) – If True, return only the floating parameters.
  • () – The names of the parameters to return.
Returns:

Return type:

list(ZfitParameters)

gradients(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None)
graph_caching_methods = []
integrate(**kwargs)
n_obs

Return the number of observables.

name

The name of the object.

numeric_integrate(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Numerical integration over the model.

Parameters:
  • limits (tuple, Space) – the limits to integrate over
  • norm_range (tuple, Space, False) – the limits to normalize over
  • name (str) –
Returns:

the integral value

Return type:

Tensor

obs

Return the observables.

old_graph_caching_methods = []
params
partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(x: Union[float, tensorflow.python.framework.ops.Tensor], limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'partial_numeric_integrate') → Union[float, tensorflow.python.framework.ops.Tensor]

Force numerical partial integration of the function over the limits and evaluate it at x.

Dimension of limits and x have to add up to the full dimension and be therefore equal to the dimensions of norm_range (if not False)

Parameters:
  • x (numerical) – The value at which the partially integrated function will be evaluated
  • limits (tuple, Space) – the limits to integrate over. Can contain only some axes
  • norm_range (tuple, Space, False) – the limits to normalize over. Has to have all axes
  • name (str) –
Returns:

the value of the partially integrated function evaluated at x.

Return type:

Tensor

classmethod register_additional_repr(**kwargs)

Register an additional attribute to add to the repr.

Parameters:
  • keyword argument. The value has to be gettable from the instance (has to be an (any) –
  • or callable method of self. (attribute) –
classmethod register_analytic_integral(func: Callable, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, priority: Union[int, float] = 50, *, supports_norm_range: bool = False, supports_multiple_limits: bool = False) → None

Register an analytic integral with the class.

Parameters:
  • func (callable) –

    A function that calculates the (partial) integral over the axes limits. The signature has to be the following:

    • x (ZfitData, None): the data for the remaining axes in a partial
      integral. If it is not a partial integral, this will be None.
    • limits (Space): the limits to integrate over.
    • norm_range (Space, None): Normalization range of the integral.
      If not supports_supports_norm_range, this will be None.
    • params (Dict[param_name, zfit.Parameters]): The parameters of the model.
    • model (ZfitModel):The model that is being integrated.
  • () (limits) – |limits_arg_descr|
  • priority (int) – Priority of the function. If multiple functions cover the same space, the one with the highest priority will be used.
  • supports_multiple_limits (bool) – If True, the limits given to the integration function can have multiple limits. If False, only simple limits will pass through and multiple limits will be auto-handled.
  • supports_norm_range (bool) – If True, norm_range argument to the function may not be None. If False, norm_range will always be None and care is taken of the normalization automatically.
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) –
classmethod register_inverse_analytic_integral(func: Callable) → None

Register an inverse analytical integral, the inverse (unnormalized) cdf.

Parameters:() (func) –
reset_cache(reseter: zfit.util.cache.ZfitCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n: Union[int, tensorflow.python.framework.ops.Tensor, str] = None, limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None, name: str = 'sample') → zfit.core.data.SampleData

Sample n points within limits from the model.

If limits is not specified, space is used (if the space contains limits). If n is None and the model is an extended pdf, ‘extended’ is used by default.

Parameters:
  • n (int, tf.Tensor, str) –

    The number of samples to be generated. Can be a Tensor that will be or a valid string. Currently implemented:

    • ’extended’: samples poisson(yield) from each pdf that is extended.
  • limits (tuple, Space) – In which region to sample in
  • name (str) –
Returns:

SampleData(n_obs, n_samples)

Raises:
  • NotExtendedPDFError – if ‘extended’ is (implicitly by default or explicitly) chosen as an option for n but the pdf itself is not extended.
  • ValueError – if n is an invalid string option.
  • InvalidArgumentError – if n is not specified and pdf is not extended.
space

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

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters:
  • draws_per_dim (int) – The draws for MC integration to do
  • () (mc_sampler) –