_ModelConfig

class pyhf.pdf._ModelConfig(spec, **config_kwargs)[source]

Bases: pyhf.mixins._ChannelSummaryMixin

Configuration for the Model.

Note

_ModelConfig should not be called directly. It should instead by accessed through the config attribute of Model.

__init__(spec, **config_kwargs)[source]
Parameters:

spec (jsonable) – The HistFactory JSON specification.

Attributes

auxdata

Return the auxiliary data in the model.

channel_nbins

Dictionary mapping channel name to number of bins in the channel.

channel_slices

Dictionary mapping channel name to the bin slices in the model.

channels

Ordered list of channel names in the model.

modifiers

Ordered list of pairs of modifier name/type in the model.

nauxdata

Return the length of data in the constraint model.

nmaindata

Return the length of data in the main model.

par_names

The names of the parameters in the model including binned-parameter indexing.

Returns:

Names of the model parameters.

Return type:

list

Example

>>> import pyhf
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> model.config.par_names
['mu', 'uncorr_bkguncrt[0]', 'uncorr_bkguncrt[1]']

Changed in version 0.7.0: Changed from method to property attribute.

par_order

Return an ordered list of paramset names in the model.

poi_index

Return the index of the POI parameter in the model.

poi_name

Return the name of the POI parameter in the model.

samples

Ordered list of sample names in the model.

Methods

_create_and_register_paramsets(required_paramsets)[source]
par_slice(name)[source]

The slice of the model parameter tensor corresponding to the model parameter name.

Returns:

Slice of the model parameter tensor.

Return type:

slice

Example

>>> import pyhf
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> model.config.par_slice("uncorr_bkguncrt")
slice(1, 3, None)
param_set(name)[source]

The paramset for the model parameter name.

Returns:

Corresponding paramset.

Return type:

paramsets

Example

>>> import pyhf
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> param_set = model.config.param_set("uncorr_bkguncrt")
>>> param_set.pdf_type
'poisson'
set_auxinfo(auxdata, auxdata_order)[source]

Sets a group of configuration data for the constraint terms.

set_parameters(_required_paramsets)[source]

Evaluate the required parameters for the model configuration.

set_poi(name)[source]

Set the model parameter of interest to be model parameter name.

If name is None, this will unset the parameter of interest.

Example

>>> import pyhf
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> model.config.set_poi("mu")
>>> model.config.poi_name
'mu'
suggested_bounds()[source]

Return suggested parameter bounds for the model.

Returns:

Suggested bounds on model parameters.

Return type:

list

Example

>>> import pyhf
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> model.config.suggested_bounds()
[(0, 10), (1e-10, 10.0), (1e-10, 10.0)]
suggested_fixed() List[bool][source]

Identify the fixed parameters in the model.

Returns:

A list of booleans, True for fixed and False for not fixed.

Return type:

list

Example

>>> import pyhf
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> model.config.suggested_fixed()
[False, False, False]

Something like the following to build fixed_vals appropriately:

fixed_pars = model.config.suggested_fixed()
inits = model.config.suggested_init()
fixed_vals = [
    (index, init)
    for index, (init, is_fixed) in enumerate(zip(inits, fixed_pars))
    if is_fixed
]
suggested_init()[source]

Return suggested initial parameter values for the model.

Returns:

Suggested initial model parameters.

Return type:

list

Example

>>> import pyhf
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> model.config.suggested_init()
[1.0, 1.0, 1.0]