hypney package

Subpackages

Submodules

hypney.all module

hypney.basics module

class hypney.basics.NotChanged

Bases: object

Default argument used where None would be ambiguous or unclear

(for example, would data=None set data to None, or keep data unchanged?)

class hypney.basics.Observable(name: str, min: float = -inf, max: float = inf, integer: bool = False)

Bases: tuple

Description of a observable space: name and limits

Attributes
integer

Alias for field number 3

max

Alias for field number 2

min

Alias for field number 1

name

Alias for field number 0

Methods

count(value, /)

Return number of occurrences of value.

index(value[, start, stop])

Return first index of value.

integer: bool

Alias for field number 3

max: float

Alias for field number 2

min: float

Alias for field number 1

name: str

Alias for field number 0

class hypney.basics.Parameter(name: str, default: float = 0.0, min: float = -inf, max: float = inf, share: bool = False, anchors: tuple = ())

Bases: tuple

Description of a parameter: name, default, and limits

Attributes
anchors

Alias for field number 5

default

Alias for field number 1

max

Alias for field number 3

min

Alias for field number 2

name

Alias for field number 0

share

Alias for field number 4

Methods

count(value, /)

Return number of occurrences of value.

index(value[, start, stop])

Return first index of value.

anchors: tuple

Alias for field number 5

default: float

Alias for field number 1

max: float

Alias for field number 3

min: float

Alias for field number 2

name: str

Alias for field number 0

share: bool

Alias for field number 4

hypney.basics.make_rate_grid(max_mu=1200)

hypney.estimator module

hypney.model module

class hypney.model.Model(*, name=<class 'hypney.basics.NotChanged'>, data=None, params=<class 'hypney.basics.NotChanged'>, param_specs=<class 'hypney.basics.NotChanged'>, observables=<class 'hypney.basics.NotChanged'>, quantiles=<class 'hypney.basics.NotChanged'>, validate_defaults=True, backend=None, **kwargs)

Bases: object

Attributes
backend

Return tensor backend module (ep.xxx)

data
defaults
n_dim
param_names
quantiles
simulate_partially_efficient

Methods

__call__(**kwargs)

Call self as a function.

cut(*args[, cut_data, cut_type, ...])

Return new model with observables cut to a rectangular region

fix([params])

Return model with parameters in fix fixed

fix_except([keep])

Return new model with only parameters named in keep; other parameters will be fixed to their defaults.

freeze()

Return new model that takes no parameters.

load(filename)

Load model from a gzipped pickle file

normalized_data()

Return model for data that was normalized using the current model's mean and standard deviation.

save(filename)

Save model to a gzipped pickle file

scale([scale])

Return model for data that has been scaled

set(*[, name, data, quantiles, params])

Return a model with possibly changed name, defaults, data, or parameters

shift([shift])

Return model for data that has been shifted

shift_and_scale([shift, scale])

Return model for data that has been shifted, then scaled, by constants.

validate_data(data)

Return eagerpy tensor from data

validate_params([params, set_defaults])

Return dictionary of parameters for the model

validate_quantiles(quantiles)

Return an (n_events) eagerpy tensor from quantiles

cdf

diff_rate

log_diff_rate

logpdf

max

mean

min

mix_with

param_spec_for

pdf

plot_cdf

plot_diff_rate

plot_pdf

ppf

rate

reparametrize

rvs

simulate

std

support

tensor_with

var

property backend

Return tensor backend module (ep.xxx)

cdf(data=<class 'hypney.basics.NotChanged'>, params: ~typing.Optional[dict] = None, **kwargs) TensorType
cut(*args, cut_data=False, cut_type='halfopen', fixed_cut_efficiency=None, **kwargs)

Return new model with observables cut to a rectangular region

Args: left-right boundaries, specified in one of many legal ways. Just try some :-)

Args:
  • cut_data: if True, applies cut to data associated with model

    before associating it with the new cut model.

data: Tensor = None
property defaults
diff_rate(data=<class 'hypney.basics.NotChanged'>, params: ~typing.Optional[dict] = None, **kwargs) TensorType
fix(params=None, **kwargs)

Return model with parameters in fix fixed

Args:
  • params: sequence of parameter names to fix, or dict of parameters

    to fix to specific values.

Other keyword arguments will be added to params.

fix_except(keep=())

Return new model with only parameters named in keep; other parameters will be fixed to their defaults.

Args:
  • keep: sequence of parameters that should remain

freeze()

Return new model that takes no parameters. All parameters are fixed to their defaults

classmethod load(filename)

Load model from a gzipped pickle file

log_diff_rate(data=<class 'hypney.basics.NotChanged'>, params: ~typing.Optional[dict] = None, **kwargs) TensorType
logpdf(data=<class 'hypney.basics.NotChanged'>, params: ~typing.Optional[dict] = None, **kwargs) TensorType
max(params: Optional[dict] = None, **kwargs) float
mean(params: Optional[dict] = None, **kwargs) float
min(params: Optional[dict] = None, **kwargs) float
mix_with(*others)
property n_dim
name: str = ''
normalized_data()

Return model for data that was normalized using the current model’s mean and standard deviation.

observables: Tuple[Observable] = (Observable(name='x', min=-inf, max=inf, integer=False),)
property param_names
param_spec_for(pname)
param_specs: Tuple[Parameter] = (Parameter(name='rate', default=1.0, min=0, max=inf, share=False, anchors=()),)
pdf(data=<class 'hypney.basics.NotChanged'>, params: ~typing.Optional[dict] = None, **kwargs) TensorType
plot_cdf(x=None, params=None, auto_labels=True, **kwargs)
plot_diff_rate(x=None, params=None, auto_labels=True, **kwargs)
plot_pdf(x=None, params=None, auto_labels=True, **kwargs)
ppf(quantiles=<class 'hypney.basics.NotChanged'>, params: ~typing.Optional[dict] = None, **kwargs) TensorType
quantiles: Tensor = None
rate(params: Optional[dict] = None, **kwargs) float
reparametrize(transform_params: callable, *args, **kwargs)
rvs(size: int = 1, params: Optional[dict] = None, **kwargs) ndarray
save(filename)

Save model to a gzipped pickle file

scale(scale=0.0)

Return model for data that has been scaled

set(*, name=<class 'hypney.basics.NotChanged'>, data=<class 'hypney.basics.NotChanged'>, quantiles=<class 'hypney.basics.NotChanged'>, params=<class 'hypney.basics.NotChanged'>, **kwargs)

Return a model with possibly changed name, defaults, data, or parameters

shift(shift=0.0)

Return model for data that has been shifted

shift_and_scale(shift=0.0, scale=1)

Return model for data that has been shifted, then scaled, by constants.

simulate(params: Optional[dict] = None, **kwargs) ndarray
property simulate_partially_efficient
std(params: Optional[dict] = None, **kwargs) float
support(params: Optional[dict] = None, **kwargs) float
tensor_with(*others)
validate_data(data) TensorType

Return eagerpy tensor from data

validate_params(params: Optional[dict] = None, set_defaults=True, **kwargs) dict

Return dictionary of parameters for the model

Args:
  • params: Dictionary of parameters

  • set_defaults: Whether missing parameters should be set

    to their defaults (default True).

Other keyword arguments are merged with params.

validate_quantiles(quantiles) TensorType

Return an (n_events) eagerpy tensor from quantiles

var(params: Optional[dict] = None, **kwargs) float
class hypney.model.WrappedModel(orig_model: ~hypney.model.Model = <class 'hypney.basics.NotChanged'>, *args, **kwargs)

Bases: Model

A model wrapping another model

Attributes
backend

Return tensor backend module (ep.xxx)

data
defaults
n_dim
param_names
quantiles
simulate_partially_efficient

Methods

__call__(**kwargs)

Call self as a function.

cut(*args[, cut_data, cut_type, ...])

Return new model with observables cut to a rectangular region

fix([params])

Return model with parameters in fix fixed

fix_except([keep])

Return new model with only parameters named in keep; other parameters will be fixed to their defaults.

freeze()

Return new model that takes no parameters.

load(filename)

Load model from a gzipped pickle file

normalized_data()

Return model for data that was normalized using the current model's mean and standard deviation.

save(filename)

Save model to a gzipped pickle file

scale([scale])

Return model for data that has been scaled

set(*[, name, data, quantiles, params])

Return a model with possibly changed name, defaults, data, or parameters

shift([shift])

Return model for data that has been shifted

shift_and_scale([shift, scale])

Return model for data that has been shifted, then scaled, by constants.

validate_data(data)

Return eagerpy tensor from data

validate_params([params, set_defaults])

Return dictionary of parameters for the model

validate_quantiles(quantiles)

Return an (n_events) eagerpy tensor from quantiles

cdf

diff_rate

log_diff_rate

logpdf

max

mean

min

mix_with

param_spec_for

pdf

plot_cdf

plot_diff_rate

plot_pdf

ppf

rate

reparametrize

rvs

simulate

std

support

tensor_with

var

hypney.statistic module

class hypney.statistic.Statistic(model: ~hypney.model.Model, data=<class 'hypney.basics.NotChanged'>, params=<class 'hypney.basics.NotChanged'>, dist=None, **kwargs)

Bases: object

Attributes
data
dist

Methods

__call__([data, dist, params])

Call self as a function.

dist_from_toys([params, n_toys, transform, ...])

Return an estimated distribution of the statistic given params from running simulations.

interpolate_dist_from_toys(anchors[, ...])

Estimate this statistic's distribution by Monte Carlo.

rvs([size, params, transform, ...])

Return statistic evaluated on simulated data, generated from model with params

set([data, dist, params])

Return a statistic with possibly changed data or distribution

with_stored_dist(dist_filename[, n_toys, ...])

Return statistic with distribution loaded from cache_dir, or rebuilt from toy mc if file does not exist

compute

compute(data=<class 'hypney.basics.NotChanged'>, params: ~typing.Optional[dict] = None, **kwargs) TensorType
property data: Tensor
property dist
dist_from_toys(params=<class 'hypney.basics.NotChanged'>, n_toys=1000, transform=<built-in function asarray>, options=None, nan_on_exception=False, simulate_from_model=None, pass_params_to_sim_model=False, **kwargs)

Return an estimated distribution of the statistic given params from running simulations.

interpolate_dist_from_toys(anchors: dict, progress=True, methods='ppf', map=<class 'map'>, **kwargs)

Estimate this statistic’s distribution by Monte Carlo.

This draws toys at a grid specified by the anchors. By default, we then interpolate the ppf, since this is what you need for confidence interval setting.

Arguments:
  • anchors: dict {param_name: anchor_values} of parameter values at

    which to run dist_from_toys. For multiple parameter, a grid is built

  • map: map function for task distribution. Can use e.g.

    ProcessPoolExecutor.map instead of the default map.

  • progress: whether to show a progress bar

  • methods: which distribution methods to interpolate

  • simulate_from_model: alternate model to simulate toys from.

    This will be passed the anchor parameters.

model: Model
rvs(size=1, params=<class 'hypney.basics.NotChanged'>, transform=<built-in function asarray>, nan_on_exception=False, simulate_from_model=None, **kwargs) ndarray

Return statistic evaluated on simulated data, generated from model with params

Args:
  • size: number of toys to draw

  • params, **kwargs: parameters at which to simulate toys

  • transform: run numpy data through this function before passing

    it to statistic. Useful to convert to an autograd library, e.g. torch.from_numpy / tf.convert_to_tensor.

  • simulate_from_model: alternate model to simulate data from,

    if different from the model the statistic uses for evaluation.

  • pass_params_to_sim_model: If True, pass any params and **kwargs

    also to the model given in simulate_from_model.

set(data=<class 'hypney.basics.NotChanged'>, dist=<class 'hypney.basics.NotChanged'>, params=<class 'hypney.basics.NotChanged'>, **kwargs)

Return a statistic with possibly changed data or distribution

with_stored_dist(dist_filename, n_toys=None, rate_anchors=array([1.00e-01, 2.00e-01, 3.00e-01, 4.00e-01, 5.00e-01, 6.00e-01, 7.00e-01, 8.00e-01, 9.00e-01, 1.00e+00, 1.10e+00, 1.20e+00, 1.30e+00, 1.40e+00, 1.50e+00, 1.60e+00, 1.70e+00, 1.80e+00, 1.90e+00, 2.00e+00, 2.10e+00, 2.20e+00, 2.30e+00, 2.40e+00, 2.60e+00, 2.70e+00, 2.80e+00, 3.00e+00, 3.10e+00, 3.30e+00, 3.40e+00, 3.60e+00, 3.80e+00, 4.00e+00, 4.20e+00, 4.40e+00, 4.60e+00, 4.80e+00, 5.00e+00, 5.30e+00, 5.60e+00, 5.80e+00, 6.10e+00, 6.40e+00, 6.80e+00, 7.10e+00, 7.50e+00, 7.80e+00, 8.20e+00, 8.60e+00, 9.10e+00, 9.50e+00, 1.00e+01, 1.05e+01, 1.10e+01, 1.16e+01, 1.22e+01, 1.28e+01, 1.34e+01, 1.41e+01, 1.48e+01, 1.55e+01, 1.63e+01, 1.71e+01, 1.80e+01, 1.89e+01, 1.98e+01, 2.08e+01, 2.18e+01, 2.29e+01, 2.41e+01, 2.53e+01, 2.65e+01, 2.79e+01, 2.93e+01, 3.07e+01, 3.23e+01, 3.39e+01, 3.56e+01, 3.74e+01, 3.92e+01, 4.12e+01, 4.32e+01, 4.54e+01, 4.77e+01, 5.01e+01, 5.26e+01, 5.52e+01, 5.80e+01, 6.09e+01, 6.39e+01, 6.71e+01, 7.04e+01, 7.40e+01, 7.77e+01, 8.15e+01, 8.56e+01, 8.99e+01, 9.44e+01, 9.91e+01, 1.04e+02, 1.09e+02, 1.15e+02, 1.20e+02, 1.27e+02, 1.33e+02, 1.39e+02, 1.46e+02, 1.54e+02, 1.61e+02, 1.70e+02, 1.78e+02, 1.87e+02, 1.96e+02, 2.06e+02, 2.16e+02, 2.27e+02, 2.39e+02, 2.50e+02, 2.63e+02, 2.76e+02, 2.90e+02, 3.04e+02, 3.20e+02, 3.36e+02, 3.52e+02, 3.70e+02, 3.89e+02, 4.08e+02, 4.28e+02, 4.50e+02, 4.72e+02, 4.96e+02, 5.21e+02, 5.47e+02, 5.74e+02, 6.03e+02, 6.33e+02, 6.65e+02, 6.98e+02, 7.33e+02, 7.69e+02, 8.08e+02, 8.48e+02, 8.91e+02, 9.35e+02, 9.82e+02, 1.03e+03, 1.08e+03, 1.14e+03, 1.19e+03, 1.25e+03]), max_workers=None, build_if_not_found=True, dist_dir='cached_dists', **kwargs)

Return statistic with distribution loaded from cache_dir, or rebuilt from toy mc if file does not exist

TODO: describe rate anchors or generalize

Module contents

hypney.exporter(*, also_export=(), export_self=False)

Export utility modified from https://stackoverflow.com/a/41895194 Returns export decorator, __all__ list