spey.interface.statistical_model.statistical_model_wrapper

spey.interface.statistical_model.statistical_model_wrapper#

spey.interface.statistical_model.statistical_model_wrapper(func: BackendBase) Callable[[Any], StatisticalModel][source]#

Decorator that promotes a BackendBase constructor into a StatisticalModel factory.

get_backend() applies this decorator automatically before returning a backend to the user, so direct use is only required when registering a custom backend outside of spey’s plugin system.

The returned callable accepts all backend-specific positional and keyword arguments plus the three universal keyword arguments documented below, and returns a fully initialised StatisticalModel.

Example usage for custom backend registration:

from spey.interface.statistical_model import statistical_model_wrapper
from my_package import MyBackend

MyModel = statistical_model_wrapper(MyBackend)
model = MyModel(
    *backend_args,
    analysis="my_analysis",
    xsection=0.05,
)
Parameters:

func (BackendBase) – Backend class (or callable) whose constructor will be wrapped. Must produce an instance that inherits BackendBase.

Raises:

AssertionError – If the object returned by func does not inherit BackendBase.

Returns:

A wrapper callable that accepts the following inputs:

  • *args: Backend-specific positional arguments forwarded to func.

  • analysis (str, default "__unknown_analysis__"): Unique identifier of the statistical model used for book-keeping purposes.

  • xsection (float, default nan): Signal cross section in user-defined units. Only required for cross-section upper-limit computations.

  • ntoys (int, default 1000): Number of toy pseudo-experiments for toy-based hypothesis testing.

  • **kwargs: Backend-specific keyword arguments forwarded to func.

Return type:

Callable[[Any], StatisticalModel]