zfit.func module

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

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

TODO(docs): explain subclassing

copy(**override_params)[source]
gradients(x, norm_range=None, params=None)[source]
func(x, name='value')[source]

The function evaluated at x.

Parameters
Returns

or dataset? Update: rather not, what would obs be?

Return type

# TODO(Mayou36)

as_pdf()[source]

Create a PDF out of the function

Return type

ZfitPDF

Returns

A PDF with the current function as the unnormalized probability.

add_cache_deps(cache_deps, allow_non_cachable=True)

Add dependencies that render the cache invalid if they change.

Parameters
  • cache_deps (Union[ForwardRef, Iterable[ForwardRef]]) –

  • 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, norm_range=None)

Analytical integration over function and raise Error if not possible.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

Raises
  • AnalyticIntegralNotImplementedError – 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.

property axes
Return type

Optional[Tuple[int]]

convert_sort_space(obs=None, axes=None, limits=None)

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

Parameters

Returns:

Return type

Optional[ZfitSpace]

create_sampler(n=None, limits=None, fixed_params=True)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – From which space to sample.

  • fixed_params (Union[bool, List[ZfitParameter], Tuple[ZfitParameter]]) – 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.

Return type

Sampler

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.

property dtype

The dtype of the object

Return type

DType

get_cache_deps(only_floating=True)

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

Parameters

only_floating (bool) – If True, only return floating Parameter

Return type

OrderedSet

get_dependencies(only_floating=True)

DEPRECATED FUNCTION

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use get_params instead if you want to retrieve the independent parameters or get_cache_deps in case you need the numerical cache dependents (advanced).

Return type

OrderedSet

get_params(floating=True, is_yield=None, extract_independent=True, only_floating=<class 'zfit.util.checks.NotSpecified'>)

Recursively collect parameters that this object depends on according to the filter criteria.

Which parameters should be included can be steered using the arguments as a filter.
  • None: do not filter on this. E.g. floating=None will return parameters that are floating as well as

    parameters that are fixed.

  • True: only return parameters that fulfil this criterion

  • False: only return parameters that do not fulfil this criterion. E.g. floating=False will return

    only parameters that are not floating.

Parameters
  • floating (Optional[bool]) – if a parameter is floating, e.g. if floating() returns True

  • is_yield (Optional[bool]) – if a parameter is a yield of the _current_ model. This won’t be applied recursively, but may include yields if they do also represent a parameter parametrizing the shape. So if the yield of the current model depends on other yields (or also non-yields), this will be included. If, however, just submodels depend on a yield (as their yield) and it is not correlated to the output of our model, they won’t be included.

  • extract_independent (Optional[bool]) – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.

Return type

Set[ZfitParameter]

graph_caching_methods = [<function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>]
instances = <_weakrefset.WeakSet object>
integrate(**kwargs)
property n_obs
Return type

int

property name

The name of the object.

Return type

str

numeric_integrate(limits, norm_range=None)

Numerical integration over the model.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

property obs
Return type

Optional[Tuple[str, …]]

property params
Return type

~ParametersType

partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(**kwargs)
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, limits=None, priority=50, *, supports_norm_range=False, supports_multiple_limits=False)

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 (ZfitSpace): the limits to integrate over.

    • norm_range (ZfitSpace, 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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – If a :py:class:~`zfit.Space` is given, it is used as limits. Otherwise arguments to instantiate a Range class can be given as follows.|limits_init|

  • priority (Union[int, float]) – 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.

Return type

None

register_cacher(cacher)

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

Parameters

cacher (Union[ForwardRef, Iterable[ForwardRef]]) –

classmethod register_inverse_analytic_integral(func)

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

Parameters

func (Callable) – A function with the signature func(x, params), where x is a Data object and params is a dict.

Return type

None

reset_cache(reseter)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n=None, limits=None)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – In which region to sample in

Return type

SampleData

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.

property space
Return type

ZfitSpace

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters
  • draws_per_dim – The draws for MC integration to do

  • mc_sampler

class zfit.func.ProdFunc(funcs, obs=None, name='SumFunc', **kwargs)[source]

Bases: zfit.models.functions.BaseFunctorFunc

add_cache_deps(cache_deps, allow_non_cachable=True)

Add dependencies that render the cache invalid if they change.

Parameters
  • cache_deps (Union[ForwardRef, Iterable[ForwardRef]]) –

  • 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, norm_range=None)

Analytical integration over function and raise Error if not possible.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

Raises
  • AnalyticIntegralNotImplementedError – 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()

Create a PDF out of the function

Return type

ZfitPDF

Returns

A PDF with the current function as the unnormalized probability.

property axes
Return type

Optional[Tuple[int]]

convert_sort_space(obs=None, axes=None, limits=None)

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

Parameters

Returns:

Return type

Optional[ZfitSpace]

copy(**override_params)
create_sampler(n=None, limits=None, fixed_params=True)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – From which space to sample.

  • fixed_params (Union[bool, List[ZfitParameter], Tuple[ZfitParameter]]) – 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.

Return type

Sampler

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.

property dtype

The dtype of the object

Return type

DType

func(x, name='value')

The function evaluated at x.

Parameters
Returns

or dataset? Update: rather not, what would obs be?

Return type

# TODO(Mayou36)

get_cache_deps(only_floating=True)

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

Parameters

only_floating (bool) – If True, only return floating Parameter

Return type

OrderedSet

get_dependencies(only_floating=True)

DEPRECATED FUNCTION

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use get_params instead if you want to retrieve the independent parameters or get_cache_deps in case you need the numerical cache dependents (advanced).

Return type

OrderedSet

get_models(names=None)
Return type

List[ZfitModel]

get_params(floating=True, is_yield=None, extract_independent=True, only_floating=<class 'zfit.util.checks.NotSpecified'>)

Recursively collect parameters that this object depends on according to the filter criteria.

Which parameters should be included can be steered using the arguments as a filter.
  • None: do not filter on this. E.g. floating=None will return parameters that are floating as well as

    parameters that are fixed.

  • True: only return parameters that fulfil this criterion

  • False: only return parameters that do not fulfil this criterion. E.g. floating=False will return

    only parameters that are not floating.

Parameters
  • floating (Optional[bool]) – if a parameter is floating, e.g. if floating() returns True

  • is_yield (Optional[bool]) – if a parameter is a yield of the _current_ model. This won’t be applied recursively, but may include yields if they do also represent a parameter parametrizing the shape. So if the yield of the current model depends on other yields (or also non-yields), this will be included. If, however, just submodels depend on a yield (as their yield) and it is not correlated to the output of our model, they won’t be included.

  • extract_independent (Optional[bool]) – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.

Return type

Set[ZfitParameter]

gradients(x, norm_range=None, params=None)
graph_caching_methods = [<function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>]
instances = <_weakrefset.WeakSet object>
integrate(**kwargs)
property models

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

Return type

List[ZfitModel]

property n_obs
Return type

int

property name

The name of the object.

Return type

str

numeric_integrate(limits, norm_range=None)

Numerical integration over the model.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

property obs
Return type

Optional[Tuple[str, …]]

property params
Return type

~ParametersType

partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(**kwargs)
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, limits=None, priority=50, *, supports_norm_range=False, supports_multiple_limits=False)

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 (ZfitSpace): the limits to integrate over.

    • norm_range (ZfitSpace, 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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – If a :py:class:~`zfit.Space` is given, it is used as limits. Otherwise arguments to instantiate a Range class can be given as follows.|limits_init|

  • priority (Union[int, float]) – 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.

Return type

None

register_cacher(cacher)

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

Parameters

cacher (Union[ForwardRef, Iterable[ForwardRef]]) –

classmethod register_inverse_analytic_integral(func)

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

Parameters

func (Callable) – A function with the signature func(x, params), where x is a Data object and params is a dict.

Return type

None

reset_cache(reseter)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n=None, limits=None)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – In which region to sample in

Return type

SampleData

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.

property space
Return type

ZfitSpace

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters
  • draws_per_dim – The draws for MC integration to do

  • mc_sampler

class zfit.func.SumFunc(funcs, obs=None, name='SumFunc', **kwargs)[source]

Bases: zfit.models.functions.BaseFunctorFunc

add_cache_deps(cache_deps, allow_non_cachable=True)

Add dependencies that render the cache invalid if they change.

Parameters
  • cache_deps (Union[ForwardRef, Iterable[ForwardRef]]) –

  • 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, norm_range=None)

Analytical integration over function and raise Error if not possible.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

Raises
  • AnalyticIntegralNotImplementedError – 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()

Create a PDF out of the function

Return type

ZfitPDF

Returns

A PDF with the current function as the unnormalized probability.

property axes
Return type

Optional[Tuple[int]]

convert_sort_space(obs=None, axes=None, limits=None)

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

Parameters

Returns:

Return type

Optional[ZfitSpace]

copy(**override_params)
create_sampler(n=None, limits=None, fixed_params=True)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – From which space to sample.

  • fixed_params (Union[bool, List[ZfitParameter], Tuple[ZfitParameter]]) – 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.

Return type

Sampler

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.

property dtype

The dtype of the object

Return type

DType

func(x, name='value')

The function evaluated at x.

Parameters
Returns

or dataset? Update: rather not, what would obs be?

Return type

# TODO(Mayou36)

get_cache_deps(only_floating=True)

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

Parameters

only_floating (bool) – If True, only return floating Parameter

Return type

OrderedSet

get_dependencies(only_floating=True)

DEPRECATED FUNCTION

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use get_params instead if you want to retrieve the independent parameters or get_cache_deps in case you need the numerical cache dependents (advanced).

Return type

OrderedSet

get_models(names=None)
Return type

List[ZfitModel]

get_params(floating=True, is_yield=None, extract_independent=True, only_floating=<class 'zfit.util.checks.NotSpecified'>)

Recursively collect parameters that this object depends on according to the filter criteria.

Which parameters should be included can be steered using the arguments as a filter.
  • None: do not filter on this. E.g. floating=None will return parameters that are floating as well as

    parameters that are fixed.

  • True: only return parameters that fulfil this criterion

  • False: only return parameters that do not fulfil this criterion. E.g. floating=False will return

    only parameters that are not floating.

Parameters
  • floating (Optional[bool]) – if a parameter is floating, e.g. if floating() returns True

  • is_yield (Optional[bool]) – if a parameter is a yield of the _current_ model. This won’t be applied recursively, but may include yields if they do also represent a parameter parametrizing the shape. So if the yield of the current model depends on other yields (or also non-yields), this will be included. If, however, just submodels depend on a yield (as their yield) and it is not correlated to the output of our model, they won’t be included.

  • extract_independent (Optional[bool]) – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.

Return type

Set[ZfitParameter]

gradients(x, norm_range=None, params=None)
graph_caching_methods = [<function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>]
instances = <_weakrefset.WeakSet object>
integrate(**kwargs)
property models

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

Return type

List[ZfitModel]

property n_obs
Return type

int

property name

The name of the object.

Return type

str

numeric_integrate(limits, norm_range=None)

Numerical integration over the model.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

property obs
Return type

Optional[Tuple[str, …]]

property params
Return type

~ParametersType

partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(**kwargs)
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, limits=None, priority=50, *, supports_norm_range=False, supports_multiple_limits=False)

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 (ZfitSpace): the limits to integrate over.

    • norm_range (ZfitSpace, 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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – If a :py:class:~`zfit.Space` is given, it is used as limits. Otherwise arguments to instantiate a Range class can be given as follows.|limits_init|

  • priority (Union[int, float]) – 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.

Return type

None

register_cacher(cacher)

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

Parameters

cacher (Union[ForwardRef, Iterable[ForwardRef]]) –

classmethod register_inverse_analytic_integral(func)

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

Parameters

func (Callable) – A function with the signature func(x, params), where x is a Data object and params is a dict.

Return type

None

reset_cache(reseter)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n=None, limits=None)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – In which region to sample in

Return type

SampleData

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.

property space
Return type

ZfitSpace

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters
  • draws_per_dim – The draws for MC integration to do

  • mc_sampler

class zfit.func.SimpleFunc(obs, func, name='Function', **params)[source]

Bases: zfit.core.basefunc.BaseFunc

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

Parameters
add_cache_deps(cache_deps, allow_non_cachable=True)

Add dependencies that render the cache invalid if they change.

Parameters
  • cache_deps (Union[ForwardRef, Iterable[ForwardRef]]) –

  • 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, norm_range=None)

Analytical integration over function and raise Error if not possible.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

Raises
  • AnalyticIntegralNotImplementedError – 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()

Create a PDF out of the function

Return type

ZfitPDF

Returns

A PDF with the current function as the unnormalized probability.

property axes
Return type

Optional[Tuple[int]]

convert_sort_space(obs=None, axes=None, limits=None)

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

Parameters

Returns:

Return type

Optional[ZfitSpace]

copy(**override_params)
create_sampler(n=None, limits=None, fixed_params=True)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – From which space to sample.

  • fixed_params (Union[bool, List[ZfitParameter], Tuple[ZfitParameter]]) – 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.

Return type

Sampler

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.

property dtype

The dtype of the object

Return type

DType

func(x, name='value')

The function evaluated at x.

Parameters
Returns

or dataset? Update: rather not, what would obs be?

Return type

# TODO(Mayou36)

get_cache_deps(only_floating=True)

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

Parameters

only_floating (bool) – If True, only return floating Parameter

Return type

OrderedSet

get_dependencies(only_floating=True)

DEPRECATED FUNCTION

Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use get_params instead if you want to retrieve the independent parameters or get_cache_deps in case you need the numerical cache dependents (advanced).

Return type

OrderedSet

get_params(floating=True, is_yield=None, extract_independent=True, only_floating=<class 'zfit.util.checks.NotSpecified'>)

Recursively collect parameters that this object depends on according to the filter criteria.

Which parameters should be included can be steered using the arguments as a filter.
  • None: do not filter on this. E.g. floating=None will return parameters that are floating as well as

    parameters that are fixed.

  • True: only return parameters that fulfil this criterion

  • False: only return parameters that do not fulfil this criterion. E.g. floating=False will return

    only parameters that are not floating.

Parameters
  • floating (Optional[bool]) – if a parameter is floating, e.g. if floating() returns True

  • is_yield (Optional[bool]) – if a parameter is a yield of the _current_ model. This won’t be applied recursively, but may include yields if they do also represent a parameter parametrizing the shape. So if the yield of the current model depends on other yields (or also non-yields), this will be included. If, however, just submodels depend on a yield (as their yield) and it is not correlated to the output of our model, they won’t be included.

  • extract_independent (Optional[bool]) – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.

Return type

Set[ZfitParameter]

gradients(x, norm_range=None, params=None)
graph_caching_methods = [<function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>, <function FunctionWrapperRegistry.__call__.<locals>.concrete_func>]
instances = <_weakrefset.WeakSet object>
integrate(**kwargs)
property n_obs
Return type

int

property name

The name of the object.

Return type

str

numeric_integrate(limits, norm_range=None)

Numerical integration over the model.

Parameters
Return type

Union[float, Tensor]

Returns

The integral value

property obs
Return type

Optional[Tuple[str, …]]

property params
Return type

~ParametersType

partial_analytic_integrate(**kwargs)
partial_integrate(**kwargs)
partial_numeric_integrate(**kwargs)
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, limits=None, priority=50, *, supports_norm_range=False, supports_multiple_limits=False)

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 (ZfitSpace): the limits to integrate over.

    • norm_range (ZfitSpace, 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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – If a :py:class:~`zfit.Space` is given, it is used as limits. Otherwise arguments to instantiate a Range class can be given as follows.|limits_init|

  • priority (Union[int, float]) – 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.

Return type

None

register_cacher(cacher)

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

Parameters

cacher (Union[ForwardRef, Iterable[ForwardRef]]) –

classmethod register_inverse_analytic_integral(func)

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

Parameters

func (Callable) – A function with the signature func(x, params), where x is a Data object and params is a dict.

Return type

None

reset_cache(reseter)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n=None, limits=None)

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 (Union[int, Tensor, str, None]) –

    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 (Union[Tuple[Tuple[float, …]], Tuple[float, …], bool, Space, None]) – In which region to sample in

Return type

SampleData

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.

property space
Return type

ZfitSpace

update_integration_options(draws_per_dim=None, mc_sampler=None)

Set the integration options.

Parameters
  • draws_per_dim – The draws for MC integration to do

  • mc_sampler