BinnedSamplerData#

class zfit.data.BinnedSamplerData(dataset, *, sample_and_variances_func, sample_holder=None, variances_holder=None, n=None, params=None, name=None, label=None)[source]#

Bases: BinnedData

The BinnedSampler is a binned data object that can be resampled, i.e. modified in-place.

Use from_sampler to create a BinnedSampler.

Parameters:
  • dataset (BinnedHolder) – The data holder that contains the sample and the variances.

  • sample_and_variances_func (Callable) – A function that samples the data and returns the sample and the variances.

  • sample_holder (tf.Variable) – The tensor that holds the sample.

  • variances_holder (tf.Variable) – The tensor that holds the variances.

  • n (ztyping.NumericalScalarType | Callable) – The number of samples to produce. If the SamplerData was created with anything else then a numerical or tf.Tensor, this can’t be used.

  • params (ztyping.ParamValuesMap) – A mapping from Parameter to a fixed value that should be used for the sampling.

  • name (str | None) – The name of the data object.

  • label (str | None) – The label of the data object.

property fixed_params#

DEPRECATED FUNCTION

Deprecated: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use params instead.

classmethod from_sampler(*, sample_func=None, sample_and_variances_func=None, n, obs, params=None, fixed_params=None, name=None, label=None)[source]#

Create a binned sampler from a sample function.

This is a binned data object that can be modified in-place by updating/resampling the sample.

Parameters:
  • sample_func (Callable | None) – A function that samples the data.

  • sample_and_variances_func (Callable | None) – A function that samples the data and returns the sample and the variances.

  • n (ztyping.NumericalScalarType) – The number of samples to produce.

  • obs (ztyping.AxesTypeInput) – The observables of the data.

  • params (ztyping.ParamValuesMap) – A mapping from :py:class:~`zfit.Parameter` or string (the name) to a fixed value that should be used for the sampling.

  • name (str | None) – The name of the data object.

  • label (str | None) – The label of the data object.

resample(params=None, *, n=None, param_values=None)[source]#

Update the sample by new sampling inplace; This affects any object that used this data already.

All params that are not in the attribute params will use their current value for the creation of the new sample. The value can also be overwritten for one sampling by providing a mapping with param_values from Parameter to the temporary value.

Parameters:
  • params (ztyping.ParamValuesMap) – a mapping from Parameter to a value that should be used for the sampling. Any parameter that is not in this mapping will use the value in params.

  • n (int | tf.Tensor) – the number of samples to produce. If the SamplerData was created with anything else then a numerical or tf.Tensor, this can’t be used.

update_data(sample, variances=None)[source]#

Update the data, and optionally the variances, of the sampler in-place.

This change will be reflected in any object that used this data already.

Parameters:
  • sample (Any) – The new sample.

  • variances (Any | None) – The new variances. Can only be provided if the sampler was initialized with variances and must be provided if the sampler was initialized with variances.

values()[source]#

Values/counts of the histogram as an ndim array.

Return type:

array

Returns:

Tensor of shape (nbins0, nbins1, …) with nbins the number of bins in each observable.

variances()[source]#

Variances of the histogram as an ndim array or None if no variances are available.

Return type:

array

Returns:

Tensor of shape (nbins0, nbins1, …) with nbins the number of bins in each observable.

counts()#

Effective counts of the histogram as a ndim array.

Compared to hist, zfit does not make a difference between a view and a copy; tensors are immutable. This distinction is made in the traced function by the compilation backend.

Returns:

Tensor of shape (nbins0, nbins1, …) with nbins the number of bins in each observable.

enable_hashing()#

Enable hashing for this data object if it was disabled.

A hash allows some objects to be cached and reused. If a hash is enabled, the data object will be hashed and the hash _can_ be used for caching. This can speedup various objects, however, it maybe doesn’t have an effect at all. For example, if an object was already called before with the data object, the hash will probably not be used, as the object is already compiled.

classmethod from_hist(h)#

Create a binned dataset from a hist histogram.

A histogram (following the UHI definition) with named axes.

Parameters:

h (NamedHist) – A NamedHist. The axes will be used as the binning in zfit.

Return type:

BinnedData

classmethod from_tensor(space, values, variances=None, name=None, label=None, use_hash=None)#

Create a binned dataset defined in space where values are considered to be the counts.

Parameters:
  • space (ZfitSpace) – ​Binned space of the data. The space is used to define the binning and the limits of the data.​

  • values (znp.array) – ​Corresponds to the counts of the histogram. Follows the definition of the Unified Histogram Interface (UHI).​

  • variances (znp.array | None) –

    ​Corresponds to the uncertainties of the histogram. If True, the uncertainties are created assuming that values have been drawn from a Poisson distribution. Follows the definition of the Unified Histogram Interface (UHI).​

Return type:

BinnedData

classmethod from_unbinned(space, data, *, use_hash=None, name=None, label=None)#

Convert an unbinned dataset to a binned dataset.

Parameters:
  • space (ZfitSpace) – ​Binned space of the data. The space is used to define the binning and the limits of the data.​

  • data (ZfitData) – Unbinned data to be converted to binned data

Returns:

The binned data

Return type:

ZfitBinnedData

to_hist()#

Convert the binned data to a NamedHist.

While a binned data object can be used inside zfit (PDFs,…), it lacks many convenience features that the hist library offers, such as plots.

Return type:

Hist

to_unbinned()#

Use the bincenters as unbinned data with values as counts.

Returns:

Unbinned data

Return type:

ZfitData

with_obs(obs)#

Return a subset of the data in the ordering of obs.

Parameters:

obs (ztyping.ObsTypeInput) – Which obs to return

Return type:

BinnedData

with_variances(variances)#

Return a new binned data object with updated variances.

Parameters:

variances (array) – The new variances

Return type:

BinnedData