SumFunc#
- class zfit.func.SumFunc(funcs, obs=None, name='SumFunc', **kwargs)[source]#
Bases:
BaseFunctorFuncV1- add_cache_deps(cache_deps, allow_non_cachable=True)#
Add dependencies that render the cache invalid if they change.
- analytic_integrate(limits, norm=None, *, norm_range=None)#
Analytical integration over function and raise Error if not possible.
- Parameters:
limits (
Union[Tuple[Tuple[float,...]],Tuple[float,...],bool,Space]) – Limits of the integration.norm (
Union[Tuple[Tuple[float,...]],Tuple[float,...],bool,Space]) – Normalization of the integration. By default, this is the same as the default space of the PDF.Falsemeans no normalization and returns the unnormed integral.
- Return type:
- Returns:
The integral value
- Raises:
AnalyticIntegralNotImplementedError – If no analytical integral is available (for this limits).
NormRangeNotImplementedError – if the norm argument is not supported. This means that no analytical normalization is available, explicitly: the analytical integral over the limits = norm 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.
- create_sampler(n=None, limits=None, fixed_params=True)#
Create a
Samplerthat acts asDatabut can be resampled, also with changed parameters and n.If
limitsis not specified,spaceis used (if the space contains limits). Ifnis None and the model is an extended pdf, ‘extended’ is used by default.- Parameters:
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]) – From which space to sample.fixed_params (
bool|list[ZfitParameter] |tuple[ZfitParameter]) – A list ofParametersthat will be fixed during severalresamplecalls. If True, all are fixed, if False, all are floating. If aParameteris not fixed and its value gets updated (e.g. by aParameter.set_value()call), this will be reflected inresample. If fixed, the Parameter will still have the same value as theSamplerhas been created with when it resamples.
- Return type:
Sampler- Returns:
Sampler- Raises:
NotExtendedPDFError – if ‘extended’ is chosen (implicitly by default or explicitly) as an option for
nbut 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: DType#
The dtype of the object.
- func(x, name='value')#
The function evaluated at
x.
- get_cache_deps(only_floating=True)#
Return a set of all independent
Parameterthat this object depends on.- Parameters:
only_floating (
bool) – IfTrue, only return floatingParameter- Return type:
OrderedSet
- get_dependencies(only_floating: bool = True) ztyping.DependentsType#
DEPRECATED FUNCTION
Deprecated: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use
get_paramsinstead if you want to retrieve the independent parameters orget_cache_depsin case you need the numerical cache dependents (advanced). :rtype: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=Nonewill return parameters that are floating as well as parameters that are fixed.
- None: do not filter on this. E.g.
True: only return parameters that fulfil this criterion
- False: only return parameters that do not fulfil this criterion. E.g.
floating=Falsewill return only parameters that are not floating.
- False: only return parameters that do not fulfil this criterion. E.g.
- Parameters:
floating (
bool|None) – if a parameter is floating, e.g. iffloating()returnsTrueis_yield (
bool|None) – 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 (
bool|None) – If the parameter is an independent parameter, i.e. if it is aZfitIndependentParameter.
- Return type:
set[ZfitParameter]
- numeric_integrate(limits, norm=None, *, options=None, norm_range=None)#
Numerical integration over the model.
- Parameters:
limits (
Union[Tuple[Tuple[float,...]],Tuple[float,...],bool,Space]) – Limits of the integration.norm (
Union[Tuple[Tuple[float,...]],Tuple[float,...],bool,Space]) – Normalization of the integration. By default, this is the same as the default space of the PDF.Falsemeans no normalization and returns the unnormed integral.options –
Options for the integration. Additional options for the integration. Currently supported options are: - type: one of (
bins)This hints that bins are integrated. A method that is vectorizable, non-dynamic and therefore less suitable for complicated functions is chosen.
- Return type:
- Returns:
The integral value
- classmethod register_additional_repr(**kwargs)#
Register an additional attribute to add to the repr.
- Parameters:
an (any keyword argument. The value has to be gettable from the instance (has to be) –
self. (attribute or callable method of) –
- classmethod register_analytic_integral(cls, func, limits=None, priority=50, *, supports_norm=None, supports_norm_range=None, supports_multiple_limits=None)#
Register an analytic integral with the class. (deprecated arguments)
Deprecated: SOME ARGUMENTS ARE DEPRECATED:
(supports_norm_range). They will be removed in a future version. Instructions for updating: Usesupports_norminstead.- 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.
- x (
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.
- norm_range (
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]) – If aSpaceis given, it is used as limits. Otherwise arguments to instantiate a Range class can be given as follows.|limits_init|priority (
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) – IfTrue, the ``limits` given to the integration function can have multiple limits. IfFalse, only simple limits will pass through and multiple limits will be auto-handled.supports_norm (
bool) – IfTrue,normargument to the function may not beNone. IfFalse,normwill always beNoneand care is taken of the normalization automatically.
- Return type:
- register_cacher(cacher)#
Register a
cacherthat caches values produces by this instance; a dependent.- Parameters:
cacher (ztyping.CacherOrCachersType) –
- classmethod register_inverse_analytic_integral(func)#
Register an inverse analytical integral, the inverse (unnormalized) cdf.
- reset_cache_self()#
Clear the cache of self and all dependent cachers.
- sample(n=None, limits=None, x=None)#
Sample
npoints withinlimitsfrom the model.If
limitsis not specified,spaceis used (if the space contains limits). Ifnis None and the model is an extended pdf, ‘extended’ is used by default.- Parameters:
- Return type:
SampleData- Returns:
SampleData(n_obs, n_samples)
- Raises:
NotExtendedPDFError – if ‘extended’ is (implicitly by default or explicitly) chosen as an option for
nbut 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.
- update_integration_options(draws_per_dim=None, mc_sampler=None, tol=None, max_draws=None, draws_simpson=None)#
Set the integration options.
- Parameters:
max_draws (default ~1'000'000) – Maximum number of draws when integrating . Typically 500’000 - 5’000’000.
tol – Tolerance on the error of the integral. typically 1e-4 to 1e-8
draws_per_dim – The draws for MC integration to do per iteration. Can be set to
'auto’.draws_simpson – Number of points in one dimensional Simpson integration. Can be set to
'auto'.