pdf¶
-
class
zfit.pdf.
BasePDF
(obs: Union[str, Iterable[str], zfit.Space], params: Dict[str, zfit.core.interfaces.ZfitParameter] = None, dtype: Type[CT_co] = tf.float64, name: str = 'BasePDF', **kwargs)[source]¶ Bases:
zfit.core.interfaces.ZfitPDF
,zfit.core.basemodel.BaseModel
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor][source]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)[source]¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF[source]¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF[source]¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF[source]¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter][source]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None)[source]¶
-
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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor][source]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor][source]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])[source]¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor][source]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
BaseFunctor
(pdfs, name='BaseFunctor', **kwargs)[source]¶ Bases:
zfit.models.basefunctor.FunctorMixin
,zfit.core.basepdf.BasePDF
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_models
(names=None) → List[zfit.core.interfaces.ZfitModel]¶
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
models
¶ Return the models of this Functor. Can be pdfs or funcs.
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**kwargs)¶
-
pdfs_extended
¶
-
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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
Exponential
(lambda_, obs: Union[str, Iterable[str], zfit.Space], name: str = 'Exponential', **kwargs)[source]¶ Bases:
zfit.core.basepdf.BasePDF
Exponential function exp(lambda * x).
The function is normalized over a finite range and therefore a pdf. So the PDF is precisely defined as \(\frac{ e^{\lambda \cdot x}}{ \int_{lower}^{upper} e^{\lambda \cdot x} dx}\)
Parameters: -
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
CrystalBall
(mu: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], sigma: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], alpha: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], n: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], obs: Union[str, Iterable[str], zfit.Space], name: str = 'CrystalBall', dtype: Type[CT_co] = tf.float64)[source]¶ Bases:
zfit.core.basepdf.BasePDF
`Crystal Ball shaped PDF`__. A combination of a Gaussian with an powerlaw tail.
The function is defined as follows:
\[f(x;\mu, \sigma, \alpha, n) = \begin{cases} \exp(- \frac{(x - \mu)^2}{2 \sigma^2}), & \mbox{for}\frac{x - \mu}{\sigma} \geqslant -\alpha \newline A \cdot (B - \frac{x - \mu}{\sigma})^{-n}, & \mbox{for }\frac{x - \mu}{\sigma} < -\alpha \end{cases}\]with
\[ \begin{align}\begin{aligned}A = \left(\frac{n}{\left| \alpha \right|}\right)^n \cdot \exp\left(- \frac {\left|\alpha \right|^2}{2}\right)\\B = \frac{n}{\left| \alpha \right|} - \left| \alpha \right|\end{aligned}\end{align} \]Parameters: __CBShape_
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
DoubleCB
(mu: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], sigma: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], alphal: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], nl: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], alphar: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], nr: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], obs: Union[str, Iterable[str], zfit.Space], name: str = 'DoubleCB', dtype: Type[CT_co] = tf.float64)[source]¶ Bases:
zfit.core.basepdf.BasePDF
`Double sided Crystal Ball shaped PDF`__. A combination of two CB using the mu (not a frac). on each side.
The function is defined as follows:
\[f(x;\mu, \sigma, \alpha_{L}, n_{L}, \alpha_{R}, n_{R}) = \begin{cases} A_{L} \cdot (B_{L} - \frac{x - \mu}{\sigma})^{-n}, & \mbox{for }\frac{x - \mu}{\sigma} < -\alpha_{L} \newline \exp(- \frac{(x - \mu)^2}{2 \sigma^2}), & -\alpha_{L} \leqslant \mbox{for}\frac{x - \mu}{\sigma} \leqslant \alpha_{R} \newline A_{R} \cdot (B_{R} - \frac{x - \mu}{\sigma})^{-n}, & \mbox{for }\frac{x - \mu}{\sigma} > \alpha_{R} \end{cases}\]with
\[ \begin{align}\begin{aligned}A_{L/R} = \left(\frac{n_{L/R}}{\left| \alpha_{L/R} \right|}\right)^n_{L/R} \cdot \exp\left(- \frac {\left|\alpha_{L/R} \right|^2}{2}\right)\\B_{L/R} = \frac{n_{L/R}}{\left| \alpha_{L/R} \right|} - \left| \alpha_{L/R} \right|\end{aligned}\end{align} \]Parameters: - mu (zfit.Parameter) – The mean of the gaussian
- sigma (zfit.Parameter) – Standard deviation of the gaussian
- alphal (zfit.Parameter) – parameter where to switch from a gaussian to the powertail on the left
- side –
- nl (zfit.Parameter) – Exponent of the powertail on the left side
- alphar (zfit.Parameter) – parameter where to switch from a gaussian to the powertail on the right
- side –
- nr (zfit.Parameter) – Exponent of the powertail on the right side
- obs (
Space
) – - name (str) –
- dtype (tf.DType) –
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
class
zfit.pdf.
Gauss
(mu: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], sigma: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], obs: Union[str, Iterable[str], zfit.Space], name: str = 'Gauss')[source]¶ Bases:
zfit.models.dist_tfp.WrapDistribution
Gaussian or Normal distribution with a mean (mu) and a standartdevation (sigma).
The gaussian shape is defined as
\[f(x \mid \mu, \sigma^2) = e^{ -\frac{(x - \mu)^{2}}{2\sigma^2} }\]with the normalization over [-inf, inf] of
\[\frac{1}{\sqrt{2\pi\sigma^2} }\]The normalization changes for different normalization ranges
Parameters: -
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
distribution
¶
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
Uniform
(low: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], high: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], obs: Union[str, Iterable[str], zfit.Space], name: str = 'Uniform')[source]¶ Bases:
zfit.models.dist_tfp.WrapDistribution
Uniform distribution which is constant between low, high and zero outside.
Parameters: -
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
distribution
¶
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
TruncatedGauss
(mu: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], sigma: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], low: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], high: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], obs: Union[str, Iterable[str], zfit.Space], name: str = 'TruncatedGauss')[source]¶ Bases:
zfit.models.dist_tfp.WrapDistribution
Gaussian distribution that is 0 outside of low, high. Equivalent to the product of Gauss and Uniform.
Parameters: - mu (
Parameter
) – Mean of the gaussian dist - sigma (
Parameter
) – Standard deviation or spread of the gaussian - low (
Parameter
) – Below this value, the pdf is zero. - high (
Parameter
) – Above this value, the pdf is zero. - obs (
Space
) – Observables and normalization range the pdf is defined in - name (str) – Name of the pdf
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
distribution
¶
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
- mu (
-
class
zfit.pdf.
WrapDistribution
(distribution, dist_params, obs, params=None, dist_kwargs=None, dtype=tf.float64, name=None, **kwargs)[source]¶ Bases:
zfit.core.basepdf.BasePDF
Baseclass to wrap tensorflow-probability distributions automatically.
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
distribution
¶
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
Chebyshev
(obs, coeffs: list, apply_scaling: bool = True, coeff0: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor, None] = None, name: str = 'Chebyshev')[source]¶ Bases:
zfit.models.polynomials.RecursivePolynomial
Linear combination of Chebyshev (first kind) polynomials of order len(coeffs), coeffs are scaling factors.
The 0th coefficient is set to 1 by default but can be explicitly set with coeff0. Since the PDF normalization removes a degree of freedom, the 0th coefficient is redundant and leads to an arbitrary overall scaling of all parameters.
Notice that this is already a sum of polynomials and the coeffs are simply scaling the individual orders of the polynomials.
The recursive definition of _a single order_ of the polynomial is
\[ \begin{align}\begin{aligned}T_{n+1}(x) = 2 x T_{n}(x) - T_{n-1}(x)\\with T_{0} = 1 T_{1} = x\end{aligned}\end{align} \]Notice that \(T_1\) is x as opposed to 2x in Chebyshev polynomials of the second kind.
Parameters: - obs – The default space the PDF is defined in.
- coeffs (list[params]) – A list of the coefficients for the polynomials of order 1+ in the sum.
- apply_scaling (bool) – Rescale the data so that the actual limits represent (-1, 1).
- coeff0 (param) – The scaling factor of the 0th order polynomial. If not given, it is set to 1.
- name (str) – Name of the polynomial
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
class
zfit.pdf.
Legendre
(obs: Union[str, Iterable[str], zfit.Space], coeffs: List[Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor]], apply_scaling: bool = True, coeff0: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor, None] = None, name: str = 'Legendre')[source]¶ Bases:
zfit.models.polynomials.RecursivePolynomial
Linear combination of Legendre polynomials of order len(coeffs), the coeffs are overall scaling factors.
The 0th coefficient is set to 1 by default but can be explicitly set with coeff0. Since the PDF normalization removes a degree of freedom, the 0th coefficient is redundant and leads to an arbitrary overall scaling of all parameters.
Notice that this is already a sum of polynomials and the coeffs are simply scaling the individual orders of the polynomials.
The recursive definition of _a single order_ of the polynomial is
\[ \begin{align}\begin{aligned}(n+1) P_{n+1}(x) = (2n + 1) x P_{n}(x) - n P_{n-1}(x)\\with P_0 = 1 P_1 = x\end{aligned}\end{align} \]Parameters: - obs – The default space the PDF is defined in.
- coeffs (list[params]) – A list of the coefficients for the polynomials of order 1+ in the sum.
- apply_scaling (bool) – Rescale the data so that the actual limits represent (-1, 1).
- coeff0 (param) – The scaling factor of the 0th order polynomial. If not given, it is set to 1.
- name (str) – Name of the polynomial
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
class
zfit.pdf.
Chebyshev2
(obs, coeffs: list, apply_scaling: bool = True, coeff0: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor, None] = None, name: str = 'Chebyshev2')[source]¶ Bases:
zfit.models.polynomials.RecursivePolynomial
Linear combination of Chebyshev (second kind) polynomials of order len(coeffs), coeffs are scaling factors.
The 0th coefficient is set to 1 by default but can be explicitly set with coeff0. Since the PDF normalization removes a degree of freedom, the 0th coefficient is redundant and leads to an arbitrary overall scaling of all parameters.
Notice that this is already a sum of polynomials and the coeffs are simply scaling the individual orders of the polynomials.
The recursive definition of _a single order_ of the polynomial is
\[ \begin{align}\begin{aligned}T_{n+1}(x) = 2 x T_{n}(x) - T_{n-1}(x)\\with T_{0} = 1 T_{1} = 2x\end{aligned}\end{align} \]Notice that \(T_1\) is 2x as opposed to x in Chebyshev polynomials of the first kind.
Parameters: - obs – The default space the PDF is defined in.
- coeffs (list[params]) – A list of the coefficients for the polynomials of order 1+ in the sum.
- apply_scaling (bool) – Rescale the data so that the actual limits represent (-1, 1).
- coeff0 (param) – The scaling factor of the 0th order polynomial. If not given, it is set to 1.
- name (str) – Name of the polynomial
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
class
zfit.pdf.
Hermite
(obs, coeffs: list, apply_scaling: bool = True, coeff0: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor, None] = None, name: str = 'Hermite')[source]¶ Bases:
zfit.models.polynomials.RecursivePolynomial
Linear combination of Hermite polynomials (for physics) of order len(coeffs), with coeffs as scaling factors.
The 0th coefficient is set to 1 by default but can be explicitly set with coeff0. Since the PDF normalization removes a degree of freedom, the 0th coefficient is redundant and leads to an arbitrary overall scaling of all parameters.
Notice that this is already a sum of polynomials and the coeffs are simply scaling the individual orders of the polynomials.
The recursive definition of _a single order_ of the polynomial is
\[H_{n+1}(x) = 2x H_{n}(x) - 2n H_{n-1}(x)\]with P_0 = 1 P_1 = 2x
Parameters: - obs – The default space the PDF is defined in.
- coeffs (list[params]) – A list of the coefficients for the polynomials of order 1+ in the sum.
- apply_scaling (bool) – Rescale the data so that the actual limits represent (-1, 1).
- coeff0 (param) – The scaling factor of the 0th order polynomial. If not given, it is set to 1.
- name (str) – Name of the polynomial
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
class
zfit.pdf.
Laguerre
(obs, coeffs: list, apply_scaling: bool = True, coeff0: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor, None] = None, name: str = 'Laguerre')[source]¶ Bases:
zfit.models.polynomials.RecursivePolynomial
Linear combination of Laguerre polynomials of order len(coeffs), the coeffs are overall scaling factors.
The 0th coefficient is set to 1 by default but can be explicitly set with coeff0. Since the PDF normalization removes a degree of freedom, the 0th coefficient is redundant and leads to an arbitrary overall scaling of all parameters.
Notice that this is already a sum of polynomials and the coeffs are simply scaling the individual orders of the polynomials.
The recursive definition of _a single order_ of the polynomial is
\[(n+1) L_{n+1}(x) = (2n + 1 + lpha - x) L_{n}(x) - (n + lpha) L_{n-1}(x)\]with P_0 = 1 P_1 = 1 - x
Parameters: - obs – The default space the PDF is defined in.
- coeffs (list[params]) – A list of the coefficients for the polynomials of order 1+ in the sum.
- apply_scaling (bool) – Rescale the data so that the actual limits represent (-1, 1).
- coeff0 (param) – The scaling factor of the 0th order polynomial. If not given, it is set to 1.
- name (str) – Name of the polynomial
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
class
zfit.pdf.
RecursivePolynomial
(obs, coeffs: list, apply_scaling: bool = True, coeff0: Optional[tensorflow.python.framework.ops.Tensor] = None, name: str = 'Polynomial')[source]¶ Bases:
zfit.core.basepdf.BasePDF
1D polynomial generated via three-term recurrence.
Base class to create 1 dimensional recursive polynomials that can be rescaled. Overwrite _poly_func.
Parameters: -
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
ProductPDF
(pdfs: List[zfit.core.interfaces.ZfitPDF], obs: Union[str, Iterable[str], zfit.Space] = None, name='ProductPDF')[source]¶ Bases:
zfit.models.functor.BaseFunctor
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_models
(names=None) → List[zfit.core.interfaces.ZfitModel]¶
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
models
¶ Return the models of this Functor. Can be pdfs or funcs.
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**kwargs)¶
-
pdfs_extended
¶
-
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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
SumPDF
(pdfs: List[zfit.core.interfaces.ZfitPDF], fracs: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor, None] = None, obs: Union[str, Iterable[str], zfit.Space] = None, name: str = 'SumPDF')[source]¶ Bases:
zfit.models.functor.BaseFunctor
Create the sum of the pdfs with fracs as coefficients or the yields, if extended pdfs are given.
If all pdfs are extended, the fracs is optional and the (normalized) yields will be used as fracs. If fracs is given, this will be used as the fractions, regardless of whether the pdfs have a yield or not.
The parameters of the SumPDF are the fractions that are used to multiply the output of each daughter pdf. They can be accessed with pdf.params and have names f”frac_{i}” with i starting from 0 and going to the number of pdfs given.
To get the component outputs of this pdf, e.g. to plot it, use pdf.params.values() to iterate through the fracs and pdfs to get the pdfs. For example
for pdf, frac in zip(sumpdf.pdfs, sumpdf.params.values()): frac_integral = pdf.integrate(...) * frac
Parameters: - pdfs (pdf) – The pdfs to be added.
- fracs (iterable) –
coefficients for the linear combination of the pdfs. Optional if all pdfs are extended. - len(frac) == len(basic) - 1 results in the interpretation of a non-extended pdf.
The last coefficient will equal to 1 - sum(frac)- len(frac) == len(pdf): the fracs will be used as is and no normalization attempt is taken.
- name (str) –
- Raises
- ModelIncompatibleError: if
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
fracs
¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_models
(names=None) → List[zfit.core.interfaces.ZfitModel]¶
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
models
¶ Return the models of this Functor. Can be pdfs or funcs.
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**kwargs)¶
-
pdfs_extended
¶
-
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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
class
zfit.pdf.
ZPDF
(obs: Union[str, Iterable[str], zfit.Space], name: str = 'ZPDF', **params)[source]¶ Bases:
zfit.core.basemodel.SimpleModelSubclassMixin
,zfit.core.basepdf.BasePDF
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
SimplePDF
(obs, func, name='SimplePDF', **params)[source]¶ Bases:
zfit.core.basepdf.BasePDF
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF[source]¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**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: 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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-
-
class
zfit.pdf.
SimpleFunctorPDF
(obs, pdfs, func, name='SimpleFunctorPDF', **params)[source]¶ Bases:
zfit.models.functor.BaseFunctor
,zfit.models.special.SimplePDF
-
add_cache_deps
(cache_deps: Union[zfit.core.interfaces.ZfitCachable, Iterable[zfit.core.interfaces.ZfitCachable]], allow_non_cachable: bool = True)¶ Add dependencies that render the cache invalid if they change.
Parameters: - cache_deps (ZfitGraphCachable) –
- 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) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Analytical integration over function and raise Error if not possible.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
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.
- limits (tuple,
-
apply_yield
(value: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = False, log: bool = False) → Union[float, tensorflow.python.framework.ops.Tensor]¶ If a norm_range is given, the value will be multiplied by the yield.
Parameters: - value (numerical) –
- () (norm_range) –
- log (bool) –
Returns: numerical
-
as_func
(norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = False)¶ Return a Function with the function model(x, norm_range=norm_range).
Parameters: () (norm_range) –
-
axes
¶ Return the axes, integer based identifier(indices) for the coordinate system.
-
convert_sort_space
(obs: Union[str, Iterable[str], zfit.Space, zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None, axes: Union[int, Iterable[int]] = None, limits: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Optional[zfit.core.interfaces.ZfitSpace]¶ Convert the inputs (using eventually obs, axes) to
ZfitSpace
and sort them according to own obs.Parameters: - () (limits) –
- () –
- () –
Returns:
-
copy
(**override_parameters) → zfit.core.basepdf.BasePDF¶ Creates a copy of the model.
Note: the copy model may continue to depend on the original initialization arguments.
Parameters: **override_parameters – String/value dictionary of initialization arguments to override with new value. Returns: - A new instance of type(self) initialized from the union
- of self.parameters and override_parameters, i.e., dict(self.parameters, **override_parameters).
Return type: model
-
create_extended
(yield_: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], name_addition='_extended') → zfit.core.interfaces.ZfitPDF¶ Return an extended version of this pdf with yield yield_. The parameters are shared.
Parameters: Returns:
-
create_projection_pdf
(limits_to_integrate: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None]) → zfit.core.interfaces.ZfitPDF¶ Create a PDF projection by integrating out some of the dimensions.
The new projection pdf is still fully dependent on the pdf it was created with.
Parameters: limits_to_integrate ( Space
) –Returns: a pdf without the dimensions from limits_to_integrate. Return type: ZfitPDF
-
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) → 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.
- () (fixed_params) – 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.
- n (int, tf.Tensor, str) –
-
dtype
¶ The dtype of the object
-
ext_integrate
(**kwargs)¶
-
ext_log_pdf
(**kwargs)¶
-
ext_pdf
(**kwargs)¶
-
get_cache_deps
(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_dependencies
(only_floating: bool = True) -> OrderedSet(['z', 'f', 'i', 't', '.', 'P', 'a', 'r', 'm', 'e'])¶ 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).
-
get_models
(names=None) → List[zfit.core.interfaces.ZfitModel]¶
-
get_params
(floating: Optional[bool] = True, is_yield: Optional[bool] = None, extract_independent: Optional[bool] = True, only_floating=<class 'zfit.util.checks.NotSpecified'>) → Set[zfit.core.interfaces.ZfitParameter]¶ 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 – if a parameter is floating, e.g. if
floating()
returns True - is_yield – 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 – If the parameter is an independent parameter, i.e. if it is a ZfitIndependentParameter.
-
get_yield
() → Optional[zfit.core.parameter.Parameter]¶ Return the yield (only for extended models).
Returns: the yield of the current model or None Return type: Parameter
-
gradients
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = 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>, <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)¶
-
log_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Log probability density function normalized over norm_range.
Parameters: Returns: a Tensor of type self.dtype.
Return type: log_pdf
-
models
¶ Return the models of this Functor. Can be pdfs or funcs.
-
n_obs
¶ Return the number of observables, the dimensionality. Corresponds to the last dimension.
-
name
¶ The name of the object.
-
norm_range
¶ Return the current normalization range. If None and the `obs`have limits, they are returned.
Returns: The current normalization range Return type: Space
or None
-
normalization
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool]) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Return the normalization of the function (usually the integral over limits).
Parameters: limits (tuple, Space
) – The limits on where to normalize overReturns: the normalization value Return type: Tensor
-
numeric_integrate
(limits: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool], norm_range: Union[Tuple[Tuple[float, ...]], Tuple[float, ...], bool] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ Numerical integration over the model.
Parameters: - limits (tuple,
ZfitSpace
) – the limits to integrate over - norm_range (tuple,
ZfitSpace
, False) – the limits to normalize over
Returns: the integral value
Return type: Tensor
- limits (tuple,
-
obs
¶ Return the observables, string identifier for the coordinate system.
-
params
¶
-
partial_analytic_integrate
(**kwargs)¶
-
partial_integrate
(**kwargs)¶
-
partial_numeric_integrate
(**kwargs)¶
-
pdf
(**kwargs)¶
-
pdfs_extended
¶
-
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.
- 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) – |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.
- func (callable) –
-
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.ZfitGraphCachable)¶
-
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) → 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: 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.
-
set_norm_range
(norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None])¶ Set the normalization range (temporarily if used with contextmanager).
Parameters: norm_range (tuple, Space
) –
-
space
¶
-
unnormalized_pdf
(x: Union[float, tensorflow.python.framework.ops.Tensor], component_norm_range: Union[zfit.core.interfaces.ZfitLimit, tensorflow.python.framework.ops.Tensor, numpy.ndarray, Iterable[float], float, Tuple[float], List[float], bool, None] = None) → Union[float, tensorflow.python.framework.ops.Tensor]¶ PDF “unnormalized”. Use functions for unnormalized pdfs. this is only for performance in special cases.
Parameters: - x (numerical) – The value, have to be convertible to a Tensor
- component_norm_range (
Space
) – The normalization range for the components. Needed for - composition (certain) – pdfs.
Returns: 1-dimensional
tf.Tensor
containing the unnormalized pdf.Return type: tf.Tensor
-