hepstats.hypotests.hypotests_object module#

class hepstats.hypotests.hypotests_object.HypotestsObject(input, minimizer, **kwargs)[source]#

Bases: object

Base object in hepstats.hypotests to manipulate a loss function and a minimizer.

Parameters:
  • input – loss or fit result

  • minimizer – minimizer to use to find the minimum of the loss function

property loss#

Returns the loss / likelihood function.

property minimizer#

Returns the minimizer.

property bestfit#

Returns the best fit values of the model parameters.

property model#

Returns the model.

property data#

Returns the data.

property constraints#

Returns the constraints on the loss / likehood function.

get_parameter(name)[source]#

Returns the parameter in loss function with given input name.

Parameters:

name (str) – name of the parameter to return

property parameters#

Returns the list of free parameters in loss / likelihood function.

set_params_to_bestfit()[source]#

Set the values of the parameters in the models to the best fit values

lossbuilder(model, data, weights=None, oldloss=None)[source]#

Method to build a new loss function.

Parameters:
  • model (*) – The model or models to evaluate the data on

  • data (*) – Data to use

  • weights (*) – the data weights

  • oldloss (*) – Previous loss that has data, models, type

Example with zfit:
>>> data = zfit.data.Data.from_numpy(obs=obs, array=np.random.normal(1.2, 0.1, 10000))
>>> mean = zfit.Parameter("mu", 1.2)
>>> sigma = zfit.Parameter("sigma", 0.1)
>>> model = zfit.pdf.Gauss(obs=obs, mu=mean, sigma=sigma)
>>> loss = calc.lossbuilder(model, data)
Returns:

Loss function

class hepstats.hypotests.hypotests_object.ToysObject(input, minimizer, sampler, sample)[source]#

Bases: HypotestsObject

Base object in hepstats.hypotests to manipulate a loss function, a minimizer and sample a model (within the loss function) to do toy experiments.

Args:

input: loss or fit result minimizer: minimizer to use to find the minimum of the loss function sampler: function used to create sampler with models, number of events and floating parameters in the sample. sample: function used to get samples from the sampler.

property bestfit#

Returns the best fit values of the model parameters.

property constraints#

Returns the constraints on the loss / likehood function.

property data#

Returns the data.

get_parameter(name)#

Returns the parameter in loss function with given input name.

Parameters:

name (str) – name of the parameter to return

property loss#

Returns the loss / likelihood function.

lossbuilder(model, data, weights=None, oldloss=None)#

Method to build a new loss function.

Parameters:
  • model (*) – The model or models to evaluate the data on

  • data (*) – Data to use

  • weights (*) – the data weights

  • oldloss (*) – Previous loss that has data, models, type

Example with zfit:
>>> data = zfit.data.Data.from_numpy(obs=obs, array=np.random.normal(1.2, 0.1, 10000))
>>> mean = zfit.Parameter("mu", 1.2)
>>> sigma = zfit.Parameter("sigma", 0.1)
>>> model = zfit.pdf.Gauss(obs=obs, mu=mean, sigma=sigma)
>>> loss = calc.lossbuilder(model, data)
Returns:

Loss function

property minimizer#

Returns the minimizer.

property model#

Returns the model.

property parameters#

Returns the list of free parameters in loss / likelihood function.

sampler()[source]#

Create sampler with models.

>>> sampler = calc.sampler()
set_params_to_bestfit()#

Set the values of the parameters in the models to the best fit values

sample(sampler, ntoys, poi, constraints=None)[source]#

Generator function of samples from the sampler for a given value of a parameter of interest. Returns a dictionnary of samples constraints in any.

Parameters:
  • sampler (list) – generator of samples

  • ntoys (int) – number of samples to generate

  • poi (POI) – in the sampler

  • constraints (list, optional) – list of constraints to sample

Example with zfit:
>>> mean = zfit.Parameter("mean")
>>> sampler = calc.sampler()
>>> sample = calc.sample(sampler, 1000, POI(mean, 1.2))
Returns:

dictionnary of sampled values of the constraints at each iteration

toys_loss(parameter_name)[source]#

Construct a loss function constructed with a sampler for a given floating parameter

Parameters:

parameter_name (str) – name floating parameter in the sampler

Returns:

Loss function

Example with zfit:
>>> loss = calc.toys_loss(zfit.Parameter("mean"))