constraint

class zfit.core.constraint.BaseConstraint(params: Dict[str, zfit.core.interfaces.ZfitParameter] = None, name: str = 'BaseConstraint', dtype=tf.float64, **kwargs)[source]

Bases: zfit.core.interfaces.ZfitConstraint, zfit.core.baseobject.BaseNumeric

Base class for constraints.

Parameters:
  • dtype (DType) – the dtype of the constraint
  • name (str) – the name of the constraint
  • params (Dict(str, Parameter)) – A dictionary with the internal name of the parameter and the parameters itself the constrains depends on
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.

copy(deep: bool = False, name: str = None, **overwrite_params) → zfit.core.interfaces.ZfitObject
dtype

The dtype of the object

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.
graph_caching_methods = []
instances = <_weakrefset.WeakSet object>
name

The name of the object.

params
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) –
reset_cache(reseter: zfit.util.cache.ZfitGraphCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

value()[source]
class zfit.core.constraint.GaussianConstraint(params: Union[zfit.core.interfaces.ZfitParameter, int, float, complex, tensorflow.python.framework.ops.Tensor], observation: Union[int, float, complex, tensorflow.python.framework.ops.Tensor], uncertainty: Union[int, float, complex, tensorflow.python.framework.ops.Tensor])[source]

Bases: zfit.core.constraint.TFProbabilityConstraint

Gaussian constraints on a list of parameters to some observed values with uncertainties.

A Gaussian constraint is defined as the likelihood of params given the observations and uncertainty from a different measurement.

\[constraint = Gauss(observation; params, uncertainty)\]
Parameters:
  • params (list(zfit.Parameter)) – The parameters to constraint; corresponds to mu in the Gaussian distribution.
  • observation (numerical, list(numerical)) – observed values of the parameter; corresponds to the x argument in the Gaussian distribution.
  • uncertainty (numerical, list(numerical) or array/tensor) – Uncertainties or covariance/error matrix of the observed values. Can either be a single value, a list of values, an array or a tensor. Corresponds to the sigma of the Gaussian distribution.
Raises:

ShapeIncompatibleError – if params, mu and sigma don’t have incompatible shapes

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.

copy(deep: bool = False, name: str = None, **overwrite_params) → zfit.core.interfaces.ZfitObject
covariance

Return the covariance matrix of the observed values of the parameters constrained.

distribution
dtype

The dtype of the object

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.
graph_caching_methods = []
instances = <_weakrefset.WeakSet object>
name

The name of the object.

observation

Return the observed values of the parameters constrained.

params
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) –
reset_cache(reseter: zfit.util.cache.ZfitGraphCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n)

Sample n points from the probability density function for the observed value of the parameters.

Parameters:n (int, tf.Tensor) – The number of samples to be generated.
Returns:n_samples)
Return type:Dict(Parameter
value()
class zfit.core.constraint.ProbabilityConstraint(observation: Union[int, float, complex, tensorflow.python.framework.ops.Tensor, zfit.core.interfaces.ZfitParameter], params: Dict[str, zfit.core.interfaces.ZfitParameter] = None, name: str = 'ProbabilityConstraint', dtype=tf.float64, **kwargs)[source]

Bases: zfit.core.constraint.BaseConstraint

Base class for constraints using a probability density function.

Parameters:
  • dtype (DType) – the dtype of the constraint
  • name (str) – the name of the constraint
  • params (list(zfit.Parameter)) – The parameters to constraint
  • observation (list(numerical) or list(zfit.Parameter)) – Observed values of the parameter to constraint obtained from auxiliary measurements.
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.

copy(deep: bool = False, name: str = None, **overwrite_params) → zfit.core.interfaces.ZfitObject
dtype

The dtype of the object

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.
graph_caching_methods = []
instances = <_weakrefset.WeakSet object>
name

The name of the object.

observation

Return the observed values of the parameters constrained.

params
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) –
reset_cache(reseter: zfit.util.cache.ZfitGraphCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n)[source]

Sample n points from the probability density function for the observed value of the parameters.

Parameters:n (int, tf.Tensor) – The number of samples to be generated.
Returns:n_samples)
Return type:Dict(Parameter
value()[source]
class zfit.core.constraint.SimpleConstraint(func: Callable, params: Optional[Dict[str, zfit.core.interfaces.ZfitParameter]])[source]

Bases: zfit.core.constraint.BaseConstraint

Constraint from a (function returning a) Tensor.

The parameters are named “param_{i}” with i starting from 0 and corresponding to the index of params.

Parameters:
  • func – Callable that constructs the constraint and returns a tensor.
  • params – The dependents (independent zfit.Parameter) of the loss. If not given, the dependents are figured out 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.

copy(deep: bool = False, name: str = None, **overwrite_params) → zfit.core.interfaces.ZfitObject
dtype

The dtype of the object

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.
graph_caching_methods = []
instances = <_weakrefset.WeakSet object>
name

The name of the object.

params
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) –
reset_cache(reseter: zfit.util.cache.ZfitGraphCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

value()
class zfit.core.constraint.TFProbabilityConstraint(observation: Union[int, float, complex, tensorflow.python.framework.ops.Tensor, zfit.core.interfaces.ZfitParameter], params: Dict[str, zfit.core.interfaces.ZfitParameter], distribution: tensorflow_probability.python.distributions.distribution.Distribution, dist_params, dist_kwargs=None, name: str = 'DistributionConstraint', dtype=tf.float64, **kwargs)[source]

Bases: zfit.core.constraint.ProbabilityConstraint

Base class for constraints using a probability density function from tensorflow_probability.

Parameters:distribution (tensorflow_probability.distributions.Distribution) – The probability density function used to constraint the 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.

copy(deep: bool = False, name: str = None, **overwrite_params) → zfit.core.interfaces.ZfitObject
distribution
dtype

The dtype of the object

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.
graph_caching_methods = []
instances = <_weakrefset.WeakSet object>
name

The name of the object.

observation

Return the observed values of the parameters constrained.

params
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) –
reset_cache(reseter: zfit.util.cache.ZfitGraphCachable)
reset_cache_self()

Clear the cache of self and all dependent cachers.

sample(n)

Sample n points from the probability density function for the observed value of the parameters.

Parameters:n (int, tf.Tensor) – The number of samples to be generated.
Returns:n_samples)
Return type:Dict(Parameter
value()