BinnedSamplerData#
- class zfit.data.BinnedSamplerData(h, *, sample_and_variances_func=None, sample_holder=None, variances_holder=None, n=None, params=None, name=None, label=None)[source]#
Bases:
BinnedDataThe
BinnedSampleris a binned data object that can be resampled, i.e. modified in-place.Use
from_samplerto create aBinnedSampler.- Parameters:
h (
BinnedHolder|NamedHist|ZfitBinnedData) – The data holder that contains the sample and the variances.sample_and_variances_func (
Callable|None) – 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 (
Union[int,float,complex,tf.Tensor,ZfitParameter,Callable]) – The number of samples to produce. If theSamplerDatawas created with anything else then a numerical or tf.Tensor, this can’t be used.params (
Mapping[Union[str,ZfitParameter],Union[int,float,complex,tf.Tensor,ZfitParameter,None]]) – A mapping fromParameterto a fixed value that should be used for the sampling.
- property fixed_params#
DEPRECATED FUNCTION
Deprecated: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use
paramsinstead.
- 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 (
Union[int,float,complex,tf.Tensor,ZfitParameter]) – The number of samples to produce.params (
Mapping[Union[str,ZfitParameter],Union[int,float,complex,tf.Tensor,ZfitParameter,None]]) – A mapping from :py:class:~`zfit.Parameter` or string (the name) to a fixed value that should be used for the sampling.
- 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
paramswill use their current value for the creation of the new sample. The value can also be overwritten for one sampling by providing a mapping withparam_valuesfromParameterto the temporaryvalue.- Parameters:
params (
Mapping[Union[str,ZfitParameter],Union[int,float,complex,tf.Tensor,ZfitParameter,None]]) – a mapping fromParameterto avaluethat should be used for the sampling. Any parameter that is not in this mapping will use the value inparams.n (
int|tf.Tensor) – the number of samples to produce. If theSamplerDatawas 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.
- 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
Noneif 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
histhistogram.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:
- 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 thatvalueshave 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
- property nevents#
DEPRECATED FUNCTION
Deprecated: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use
num_entries(for the int) orsamplesize(for a total sum of all weights) instead.
- 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.
- with_variances(variances)#
Return a new binned data object with updated variances.
- Parameters:
variances (
array) – The new variances- Return type: