# GaussianConstraint#

class zfit.constraint.GaussianConstraint(params, observation, *, uncertainty=None, sigma=None, cov=None)[source]#

Bases: TFProbabilityConstraint, SerializableMixin

Gaussian constraints on a list of parameters to some observed values with uncertainties. (deprecated arguments)

Deprecated: SOME ARGUMENTS ARE DEPRECATED: (uncertainty). They will be removed in a future version. Instructions for updating: Use sigma or cov instead.

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

$\text{constraint} = \text{Gauss}(\text{observation}; \text{params}, \text{uncertainty})$
Parameters:
• params (ztyping.ParamTypeInput) – The parameters to constraint; corresponds to x in the Gaussian distribution.

• observation (ztyping.NumericalScalarType) – observed values of the parameter; corresponds to mu in the Gaussian distribution.

• sigma (ztyping.NumericalScalarType) – Typically the uncertainties of the observed values. Can either be a single value, a list of values, an array or a tensor. Must be broadcastable to the shape of the parameters. Either sigma or cov can be given, not both. sigma is the square root of the diagonal of the covariance matrix.

• cov (ztyping.NumericalScalarType) – The covariance matrix of the observed values. Can either be a single value, a list of values, an array or a tensor that are either 1 or 2 dimensional. If 1D, it is interpreted as the diagonal of the covariance matrix. Either sigma or cov can be given, not both. cov is a 2D matrix with the shape (n, n) where n is the number of parameters and sigma squared on the diagonal.

Raises:

ShapeIncompatibleError – If params, mu and sigma have incompatible shapes.

property covariance#

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

add_cache_deps(cache_deps, allow_non_cachable=True)#

Add dependencies that render the cache invalid if they change.

Parameters:
• cache_deps (ztyping.CacherOrCachersType)

• allow_non_cachable (bool) – If True, allow cache_dependents to be non-cachables. If False, any cache_dependents that is not a ZfitGraphCachable will raise an error.

Raises:

TypeError – if one of the cache_dependents is not a ZfitGraphCachable _and_ allow_non_cachable if False.

property dtype: DType#

The dtype of the object.

classmethod from_asdf(asdf_obj, *, reuse_params=None)#

Load an object from an asdf file.

## Args#

asdf_obj: Object reuse_params:​If parameters, the parameters

will be reused if they are given. If a parameter is given, it will be used as the parameter with the same name. If a parameter is not given, a new parameter will be created.​

classmethod from_dict(dict_, *, reuse_params=None)#

Creates an object from a dictionary structure as generated by to_dict.

Parameters:
• dict – Dictionary structure.

• reuse_params – ​If parameters, the parameters will be reused if they are given. If a parameter is given, it will be used as the parameter with the same name. If a parameter is not given, a new parameter will be created.​

Returns:

The deserialized object.

classmethod from_json(cls, json, *, reuse_params=None)#

Load an object from a json string.

Parameters:
• json (str) – Serialized object in a JSON string.

• reuse_params – ​If parameters, the parameters will be reused if they are given. If a parameter is given, it will be used as the parameter with the same name. If a parameter is not given, a new parameter will be created.​

Return type:

object

Returns:

The deserialized object.

get_cache_deps(only_floating=True)#

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

Parameters:

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

Return type:

OrderedSet

get_dependencies(only_floating: bool = True) ztyping.DependentsType#

DEPRECATED FUNCTION

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

Return type:

OrderedSet

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

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

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

parameters that are fixed.

• True: only return parameters that fulfil this criterion

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

only parameters that are not floating.

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

Return type:

set[ZfitParameter]

classmethod get_repr()#

Abstract representation of the object for serialization.

This objects knows how to serialize and deserialize the object and is used by the to_json, from_json, to_dict and from_dict methods.

Returns:

The representation of the object.

Return type:

pydantic.BaseModel

property name: str#

The name of the object.

property observation#

Return the observed values of the parameters constrained.

register_cacher(cacher)#

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

Parameters:

cacher (ztyping.CacherOrCachersType)

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 – The number of samples to be generated.

Returns:

to_asdf()#

Convert the object to an asdf file.

to_dict()#

Convert the object to a nested dictionary structure.

Returns:

The dictionary structure.

Return type:

dict

to_json()#

Convert the object to a json string.

Returns:

The json string.

Return type:

str

to_yaml()#

Convert the object to a yaml string.

Returns:

The yaml string.

Return type:

str