Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
StatisticInterface.StatisticInterface Class Reference

Public Member Functions

None __init__ (self, StatisticConfig config, ObservableInterface observable_interface)
 
None select_experiment (self, str experiment)
 
None select_experiments (self, Sequence[str] experiments)
 
None select_experiments_all (self)
 
bool has_experiment_selection (self)
 
List[str] selected_experiments (self)
 
None select_experiment_observables (self, Sequence[ExperimentObs] observables)
 
None select_experiment_observables_all (self)
 
bool has_experiment_observable_selection (self)
 
List[ExperimentObsselected_experiment_observables (self)
 
None reload_nuisance_specs (self)
 
None set_nuisance_user_file (self, str|Path user_yaml_path)
 
None clear_nuisance_user_file (self)
 
None update_cache (self, Optional[Sequence[ParamId]] p_specs=None)
 
Dict[BinnedObservableId, GaussianSummarycompute_uncertainties (self)
 
MCResult compute_uncertainties_and_sampling (self)
 
FitResultWithMaps compute_MLE (self, Optional[Sequence[ParamId]] p_specs=None)
 
Contour compute_confidence_contour (self, ParamId p1, ParamId p2, float z, Sequence[float] bounds, Optional[ContourOptions] options=None)
 
None prepare_likelihood_for_scan (self, Optional[Sequence[ParamId]] p_specs=None)
 
None set_manual_scan_point (self, Mapping[ParamId, float] p_hat, Mapping[ParamId, float] eta_hat)
 
LikelihoodScanGrid scan_likelihood_around_current_point (self, ParamId p1, ParamId p2, float x_half_width, float y_half_width, int nx, int ny)
 
None save_likelihood_scan_csv (self, str|Path path, LikelihoodScanGrid grid)
 
Dict[ParamId, float] get_all_obss_deps (self)
 
Dict[ParamId, float] get_active_observable_dependencies (self)
 
Dict[ParamId, float] get_p_specs (self, Optional[Sequence[ParamId]] p_specs=None)
 
Dict[ParamId, Dict[ParamId, float]] get_all_correlations (self)
 
Dict[ExperimentObs, Dict[ExperimentObs, float]] get_all_obs_correlations (self)
 
Dict[ExperimentObs, float] get_obs_exp (self)
 
None print_cache (self)
 

Public Attributes

 config
 

Protected Member Functions

 _to_cpp (self)
 

Protected Attributes

 _cpp
 

Detailed Description

High-level Python facade for statistical fits and scans.

Args:
    config: Statistic configuration. Python-only fields such as ``p_specs``
        and ``selected_experiments`` are used by this wrapper.
    observable_interface: Observable interface already configured with the
        observables to compute.

Examples:
    A typical workflow is::

        stat_cfg = StatisticConfig(MC_draws=1000)
        stat_cfg.p_specs = [my_param_id]
        stat = StatisticInterface(stat_cfg, observable_interface=obs_int)

        fit = stat.compute_MLE()
        print(fit.fit_ok, fit.p_hat)

        contour = stat.compute_confidence_contour(
            p1=my_param_id,
            p2=other_param_id,
            z=1.0,
            bounds=[-1.0, 1.0, -1.0, 1.0],
        )

Definition at line 438 of file StatisticInterface.py.

Constructor & Destructor Documentation

◆ __init__()

None StatisticInterface.StatisticInterface.__init__ (   self,
StatisticConfig  config,
ObservableInterface  observable_interface 
)
Create the C++ statistic interface and apply initial selections.

Definition at line 465 of file StatisticInterface.py.

Member Function Documentation

◆ _to_cpp()

StatisticInterface.StatisticInterface._to_cpp (   self)
protected
Return the underlying C++ statistic interface.

Definition at line 474 of file StatisticInterface.py.

◆ clear_nuisance_user_file()

None StatisticInterface.StatisticInterface.clear_nuisance_user_file (   self)
Return to the default user nuisance-specification path.

Definition at line 540 of file StatisticInterface.py.

◆ compute_confidence_contour()

Contour StatisticInterface.StatisticInterface.compute_confidence_contour (   self,
ParamId  p1,
ParamId  p2,
float  z,
Sequence[float]  bounds,
Optional[ContourOptions]   options = None 
)
Compute a two-dimensional confidence contour.

Args:
    p1: First fit parameter.
    p2: Second fit parameter.
    z: Gaussian-equivalent confidence level, for example ``1.0`` for an
        approximate one-sigma contour.
    bounds: Four values ``[xmin, xmax, ymin, ymax]`` defining the search
        rectangle.
    options: Optional contour/profiling options. Defaults to
        ``ContourOptions()``.

Returns:
    ``Contour`` wrapper exposing ``paths``, ``level`` and ``success``.

Raises:
    ValueError: If ``bounds`` does not contain exactly four values.
    Exception: Propagates backend failures, for example if MLE has not
        been computed before requesting the contour.

Definition at line 593 of file StatisticInterface.py.

◆ compute_MLE()

FitResultWithMaps StatisticInterface.StatisticInterface.compute_MLE (   self,
Optional[Sequence[ParamId]]   p_specs = None 
)
Compute the maximum-likelihood estimate for selected fit parameters.

Args:
    p_specs: Fit parameters. When omitted, ``self.config.p_specs`` is
        used.

Returns:
    Fit result containing best-fit values, profiled nuisances,
    uncertainties, correlations and minimum NLL.

Raises:
    Exception: Propagates C++ errors raised by cache construction,
        likelihood evaluation or minimization.

Definition at line 573 of file StatisticInterface.py.

◆ compute_uncertainties()

Dict[BinnedObservableId, GaussianSummary] StatisticInterface.StatisticInterface.compute_uncertainties (   self)
Propagate nuisance uncertainties and return Gaussian summaries.

Returns:
    Mapping from observable id to Gaussian or split-Gaussian summary.

Definition at line 554 of file StatisticInterface.py.

◆ compute_uncertainties_and_sampling()

MCResult StatisticInterface.StatisticInterface.compute_uncertainties_and_sampling (   self)
Run Monte-Carlo uncertainty propagation and keep raw samples.

Returns:
    ``MCResult`` containing raw samples, summaries and covariance.

Definition at line 565 of file StatisticInterface.py.

◆ get_active_observable_dependencies()

Dict[ParamId, float] StatisticInterface.StatisticInterface.get_active_observable_dependencies (   self)
Return dependencies currently visible to the Statistic manager.

This method is useful for runtime/lambda observables: it verifies that
dependencies declared on ``LambdaObservableConfig`` and propagated from
custom Wilson lambdas reached the statistic layer.

Definition at line 709 of file StatisticInterface.py.

◆ get_all_correlations()

Dict[ParamId, Dict[ParamId, float]] StatisticInterface.StatisticInterface.get_all_correlations (   self)
Return the nuisance correlation matrix as nested parameter maps.

Definition at line 727 of file StatisticInterface.py.

◆ get_all_obs_correlations()

Dict[ExperimentObs, Dict[ExperimentObs, float]] StatisticInterface.StatisticInterface.get_all_obs_correlations (   self)
Return experimental-observable correlations as nested maps.

Definition at line 731 of file StatisticInterface.py.

◆ get_all_obss_deps()

Dict[ParamId, float] StatisticInterface.StatisticInterface.get_all_obss_deps (   self)
Return all selected observable dependencies after nuisance pruning.

Definition at line 705 of file StatisticInterface.py.

◆ get_obs_exp()

Dict[ExperimentObs, float] StatisticInterface.StatisticInterface.get_obs_exp (   self)
Return experimental central values used by the statistic manager.

Definition at line 735 of file StatisticInterface.py.

◆ get_p_specs()

Dict[ParamId, float] StatisticInterface.StatisticInterface.get_p_specs (   self,
Optional[Sequence[ParamId]]   p_specs = None 
)
Return central values for selected fit parameters.

Args:
    p_specs: Fit parameters to query. Defaults to ``self.config.p_specs``.

Definition at line 718 of file StatisticInterface.py.

◆ has_experiment_observable_selection()

bool StatisticInterface.StatisticInterface.has_experiment_observable_selection (   self)
Return whether an exact measurement filter is active.

Definition at line 519 of file StatisticInterface.py.

◆ has_experiment_selection()

bool StatisticInterface.StatisticInterface.has_experiment_selection (   self)
Return whether an experiment filter is currently active.

Definition at line 498 of file StatisticInterface.py.

◆ prepare_likelihood_for_scan()

None StatisticInterface.StatisticInterface.prepare_likelihood_for_scan (   self,
Optional[Sequence[ParamId]]   p_specs = None 
)
Prepare and cache a likelihood object for manual two-dimensional scans.

Args:
    p_specs: Fit parameters used by the likelihood. Defaults to
        ``self.config.p_specs``.

Definition at line 638 of file StatisticInterface.py.

◆ print_cache()

None StatisticInterface.StatisticInterface.print_cache (   self)
Print the current C++ statistic cache for debugging.

Definition at line 739 of file StatisticInterface.py.

◆ reload_nuisance_specs()

None StatisticInterface.StatisticInterface.reload_nuisance_specs (   self)
Reload default and user nuisance specifications in the C++ manager.

Definition at line 527 of file StatisticInterface.py.

◆ save_likelihood_scan_csv()

None StatisticInterface.StatisticInterface.save_likelihood_scan_csv (   self,
str | Path  path,
LikelihoodScanGrid  grid 
)
Save a likelihood scan grid to a CSV file.

Args:
    path: Output CSV path.
    grid: Scan grid returned by :meth:`scan_likelihood_around_current_point`.

Definition at line 694 of file StatisticInterface.py.

◆ scan_likelihood_around_current_point()

LikelihoodScanGrid StatisticInterface.StatisticInterface.scan_likelihood_around_current_point (   self,
ParamId  p1,
ParamId  p2,
float  x_half_width,
float  y_half_width,
int  nx,
int  ny 
)
Evaluate the likelihood on a rectangular grid around the current point.

Args:
    p1: First scanned parameter.
    p2: Second scanned parameter.
    x_half_width: Half-width of the scan range in the first parameter.
    y_half_width: Half-width of the scan range in the second parameter.
    nx: Number of grid points in the x direction.
    ny: Number of grid points in the y direction.

Returns:
    A ``LikelihoodScanGrid`` containing all evaluated points.

Definition at line 661 of file StatisticInterface.py.

◆ select_experiment()

None StatisticInterface.StatisticInterface.select_experiment (   self,
str  experiment 
)
Restrict the statistic manager to one experiment.

Args:
    experiment: Experiment name as stored in the experimental database.

Definition at line 478 of file StatisticInterface.py.

◆ select_experiment_observables()

None StatisticInterface.StatisticInterface.select_experiment_observables (   self,
Sequence[ExperimentObs observables 
)
Restrict statistics to exact experiment/observable/bin entries.

Args:
    observables: Exact measurements to retain. Each item combines an
        experiment label with a binned observable identifier.

Definition at line 506 of file StatisticInterface.py.

◆ select_experiment_observables_all()

None StatisticInterface.StatisticInterface.select_experiment_observables_all (   self)
Clear the exact experimental-observable selection.

Definition at line 515 of file StatisticInterface.py.

◆ select_experiments()

None StatisticInterface.StatisticInterface.select_experiments (   self,
Sequence[str]  experiments 
)
Restrict the statistic manager to a set of experiments.

Args:
    experiments: Experiment names to keep.

Definition at line 486 of file StatisticInterface.py.

◆ select_experiments_all()

None StatisticInterface.StatisticInterface.select_experiments_all (   self)
Clear any experiment selection and use all available experiments.

Definition at line 494 of file StatisticInterface.py.

◆ selected_experiment_observables()

List[ExperimentObs] StatisticInterface.StatisticInterface.selected_experiment_observables (   self)
Return the active exact measurement selection.

Definition at line 523 of file StatisticInterface.py.

◆ selected_experiments()

List[str] StatisticInterface.StatisticInterface.selected_experiments (   self)
Return the currently selected experiment names.

Definition at line 502 of file StatisticInterface.py.

◆ set_manual_scan_point()

None StatisticInterface.StatisticInterface.set_manual_scan_point (   self,
Mapping[ParamId, float]  p_hat,
Mapping[ParamId, float]   eta_hat 
)
Override the scan reference point manually.

Args:
    p_hat: Fit-parameter values used as scan center/reference.
    eta_hat: Nuisance values used as scan reference.

Definition at line 648 of file StatisticInterface.py.

◆ set_nuisance_user_file()

None StatisticInterface.StatisticInterface.set_nuisance_user_file (   self,
str | Path  user_yaml_path 
)
Use a custom user nuisance-specification file.

Args:
    user_yaml_path: Path to the YAML file overriding default nuisance
        specifications.

Definition at line 531 of file StatisticInterface.py.

◆ update_cache()

None StatisticInterface.StatisticInterface.update_cache (   self,
Optional[Sequence[ParamId]]   p_specs = None 
)
Refresh the C++ statistic cache.

Args:
    p_specs: Fit parameters to detach from the nuisance set. When
        omitted, ``self.config.p_specs`` is used.

Definition at line 544 of file StatisticInterface.py.

Member Data Documentation

◆ _cpp

StatisticInterface.StatisticInterface._cpp
protected

Definition at line 470 of file StatisticInterface.py.

◆ config

StatisticInterface.StatisticInterface.config

Definition at line 469 of file StatisticInterface.py.


The documentation for this class was generated from the following file: