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

Coordinates statistical inputs, nuisance distributions, MLE fits and contour/scan computations. More...

#include <StatisticManager.h>

Public Member Functions

 StatisticManager (StatisticConfig config, std::shared_ptr< IModel > obs_int, std::shared_ptr< IStatCorrelationProxy > pscp, std::shared_ptr< IStatParameterProxy > pspp, std::shared_ptr< IStatSourcesProxy > sp, std::shared_ptr< IStatDependencyPruner > dp, std::shared_ptr< INuisanceReader > nuisance_reader, std::shared_ptr< IStatParamOptimizerProxy > spop)
 Constructs a statistic manager and initializes observable/nuisance state.
 
std::vector< std::unique_ptr< IMarginalDistribution > > build_nuisance_marginal_distributions ()
 Builds marginal distributions for all currently cached nuisances.
 
std::unique_ptr< JointDistributionbuild_nuisance_distribution ()
 Builds the joint nuisance distribution from cached nuisance marginals and correlations.
 
std::unique_ptr< JointDistributionbuild_exp_data_distribution ()
 Builds the joint experimental-data distribution from cached observables and correlations.
 
void reload_nuisance_specs ()
 Reloads default and user nuisance specifications and invalidates fit state.
 
void set_nuisance_user_file (const fs::path &user_yaml_path)
 Selects a custom user nuisance-definition file and reloads nuisance specifications.
 
void clear_nuisance_user_file ()
 Clears the custom user nuisance file and reloads the default configured user file.
 
const NuisanceRegistrydefault_nuisance_specs () const
 
const NuisanceRegistryuser_nuisance_specs () const
 
const NuisanceRegistrymerged_nuisance_specs () const
 
std::map< BinnedObservableId, GaussianSummarycompute_uncertainties ()
 Computes Gaussian summaries for MC-propagated observable uncertainties.
 
MCResult compute_uncertainties_and_sampling ()
 Runs MC uncertainty propagation and returns both samples and summaries.
 
FitResultWithMaps compute_MLE (const std::vector< ParamId > &p_specs)
 Computes the maximum-likelihood fit for a selected set of fit parameters.
 
Contour confidence_contour (ParamId p1, ParamId p2, double z, std::array< double, 4 > bounds, ContourOptions options)
 Computes a two-dimensional confidence contour for the last successful MLE.
 
void prepare_likelihood_for_scan (const std::vector< ParamId > &p_specs)
 Prepares a likelihood object for manual scans without running a full MLE.
 
void set_manual_scan_point (const std::map< ParamId, double > &p_hat, const std::map< ParamId, double > &eta_hat)
 Sets the reference point used by subsequent likelihood scans.
 
LikelihoodScanGrid scan_likelihood_around_current_point (ParamId p1, ParamId p2, double x_half_width, double y_half_width, std::size_t nx, std::size_t ny) const
 Evaluates the current likelihood on a regular 2D grid around the active reference point.
 
void save_likelihood_scan_csv (const std::string &path, const LikelihoodScanGrid &grid) const
 Writes a likelihood scan grid to a CSV file.
 
void update_cache (const std::vector< ParamId > &p_specs=std::vector< ParamId >())
 Updates the full statistical cache for the selected fit parameters.
 
void select_experiment (const std::string &experiment)
 Restricts subsequent statistics to a single experiment name.
 
void select_experiments (const std::set< std::string > &experiments)
 Restricts subsequent statistics to the provided set of experiment names.
 
void select_experiments (const std::vector< std::string > &experiments)
 Restricts subsequent statistics to the provided vector of experiment names.
 
void select_experiments_all ()
 Clears any experiment selection and uses all available experiments.
 
bool has_experiment_selection () const noexcept
 
std::set< std::string > selected_experiments () const
 
void select_experiment_observables (const std::set< ExperimentObs > &observables)
 Restricts subsequent statistics to an explicit list of experimental measurements.
 
void select_experiment_observables (const std::vector< ExperimentObs > &observables)
 Vector overload for select_experiment_observables.
 
void select_experiment_observables_all ()
 Clears the explicit experimental-observable selection.
 
bool has_experiment_observable_selection () const noexcept
 
std::set< ExperimentObsselected_experiment_observables () const
 
std::map< ParamId, double > get_all_obss_deps ()
 Selects all nuisance dependencies relevant to the current observable set.
 
std::map< ParamId, double > get_p_specs (const std::vector< ParamId > &p_specs)
 Resolves initial fit-parameter values from the parameter proxy.
 
std::map< ParamId, std::map< ParamId, double > > get_all_correlations ()
 
std::map< ExperimentObs, std::map< ExperimentObs, double > > get_all_obs_correlations ()
 
std::map< ExperimentObs, double > get_obs_exp ()
 
void print_cache ()
 Prints the current internal cache to standard output for debugging.
 

Detailed Description

Coordinates statistical inputs, nuisance distributions, MLE fits and contour/scan computations.

The manager owns no low-level physics data itself. Instead, it delegates model predictions to IModel, parameter values and uncertainties to the statistical proxies, and nuisance metadata to INuisanceReader. Its role is to assemble those sources into the distributions and likelihoods required by the fitting workflow.

Definition at line 210 of file StatisticManager.h.

Constructor & Destructor Documentation

◆ StatisticManager()

StatisticManager::StatisticManager ( StatisticConfig  config,
std::shared_ptr< IModel obs_int,
std::shared_ptr< IStatCorrelationProxy pscp,
std::shared_ptr< IStatParameterProxy pspp,
std::shared_ptr< IStatSourcesProxy sp,
std::shared_ptr< IStatDependencyPruner dp,
std::shared_ptr< INuisanceReader nuisance_reader,
std::shared_ptr< IStatParamOptimizerProxy spop 
)

Constructs a statistic manager and initializes observable/nuisance state.

The constructor computes the model observables once, loads default and user nuisance specifications, merges them, and invalidates any previous fit state.

Parameters
configRuntime statistical configuration.
obs_intModel used to compute and predict observables.
pscpCorrelation proxy for parameters and observables.
psppParameter proxy providing central values and uncertainties.
spSource proxy used to resolve leaf dependencies.
dpDependency pruner used to detach fit parameters from nuisance dependencies.
nuisance_readerReader used to load default/user nuisance specifications.
spopOptional/statistical parameter optimizer proxy used by the surrounding workflow.
Exceptions
std::invalid_argumentif nuisance_reader is null.

Definition at line 514 of file StatisticManager.cpp.

Member Function Documentation

◆ build_exp_data_distribution()

std::unique_ptr< JointDistribution > StatisticManager::build_exp_data_distribution ( )

Builds the joint experimental-data distribution from cached observables and correlations.

Returns
Joint distribution over selected experimental observables.

Definition at line 601 of file StatisticManager.cpp.

◆ build_nuisance_distribution()

std::unique_ptr< JointDistribution > StatisticManager::build_nuisance_distribution ( )

Builds the joint nuisance distribution from cached nuisance marginals and correlations.

Returns
Joint distribution over selected nuisance parameters.

Definition at line 573 of file StatisticManager.cpp.

◆ build_nuisance_marginal_distributions()

std::vector< std::unique_ptr< IMarginalDistribution > > StatisticManager::build_nuisance_marginal_distributions ( )

Builds marginal distributions for all currently cached nuisances.

Returns
Marginal distributions ordered consistently with StatCache::eta_specs_real.

Definition at line 541 of file StatisticManager.cpp.

◆ clear_nuisance_user_file()

void StatisticManager::clear_nuisance_user_file ( )

Clears the custom user nuisance file and reloads the default configured user file.

Definition at line 1284 of file StatisticManager.cpp.

◆ compute_MLE()

FitResultWithMaps StatisticManager::compute_MLE ( const std::vector< ParamId > &  p_specs)

Computes the maximum-likelihood fit for a selected set of fit parameters.

The likelihood backend is selected through StatisticConfig::likelihood_mode. This method also updates the internal state required by contour and scan methods.

Parameters
p_specsOrdered list of fit-parameter identifiers.
Returns
Map-based fit result.
Exceptions
std::invalid_argumentif p_specs resolves to an empty fit-parameter set.

Definition at line 683 of file StatisticManager.cpp.

◆ compute_uncertainties()

std::map< BinnedObservableId, GaussianSummary > StatisticManager::compute_uncertainties ( )

Computes Gaussian summaries for MC-propagated observable uncertainties.

Returns
Map from binned observable identifiers to Gaussian summaries.

Definition at line 642 of file StatisticManager.cpp.

◆ compute_uncertainties_and_sampling()

MCResult StatisticManager::compute_uncertainties_and_sampling ( )

Runs MC uncertainty propagation and returns both samples and summaries.

Returns
Full MC result including accepted samples, Gaussian summaries and covariance.

Definition at line 668 of file StatisticManager.cpp.

◆ confidence_contour()

Contour StatisticManager::confidence_contour ( ParamId  p1,
ParamId  p2,
double  z,
std::array< double, 4 >  bounds,
ContourOptions  options 
)

Computes a two-dimensional confidence contour for the last successful MLE.

Parameters
p1First fit parameter.
p2Second fit parameter.
zGaussian-equivalent significance level.
boundsBounds as {xmin, xmax, ymin, ymax}.
optionsContour and profiling options.
Returns
Extracted contour.
Exceptions
std::runtime_errorif no MLE has been computed.
std::invalid_argumentif the parameters are not part of the last fit or are identical.

Definition at line 949 of file StatisticManager.cpp.

◆ default_nuisance_specs()

const NuisanceRegistry & StatisticManager::default_nuisance_specs ( ) const
inline
Returns
Default nuisance specifications loaded from the default nuisance file.

Definition at line 273 of file StatisticManager.h.

◆ get_all_correlations()

std::map< ParamId, std::map< ParamId, double > > StatisticManager::get_all_correlations ( )
Returns
Correlation matrix for the currently cached nuisance parameters.

Definition at line 1700 of file StatisticManager.cpp.

◆ get_all_obs_correlations()

std::map< ExperimentObs, std::map< ExperimentObs, double > > StatisticManager::get_all_obs_correlations ( )
Returns
Correlation matrix for the currently cached experimental observables.

Definition at line 1707 of file StatisticManager.cpp.

◆ get_all_obss_deps()

std::map< ParamId, double > StatisticManager::get_all_obss_deps ( )

Selects all nuisance dependencies relevant to the current observable set.

Returns
Map of selected nuisance identifiers to central values.

Definition at line 1382 of file StatisticManager.cpp.

◆ get_obs_exp()

std::map< ExperimentObs, double > StatisticManager::get_obs_exp ( )
Returns
Experimental central values selected for the current observable/experiment set.

Definition at line 1715 of file StatisticManager.cpp.

◆ get_p_specs()

std::map< ParamId, double > StatisticManager::get_p_specs ( const std::vector< ParamId > &  p_specs)

Resolves initial fit-parameter values from the parameter proxy.

Parameters
p_specsFit-parameter identifiers.
Returns
Map of parameter identifiers to central values.

Definition at line 1693 of file StatisticManager.cpp.

◆ has_experiment_observable_selection()

bool StatisticManager::has_experiment_observable_selection ( ) const
noexcept
Returns
True if an explicit experimental-observable selection is active.

Definition at line 2045 of file StatisticManager.cpp.

◆ has_experiment_selection()

bool StatisticManager::has_experiment_selection ( ) const
noexcept
Returns
True if an experiment selection is currently active.

Definition at line 1996 of file StatisticManager.cpp.

◆ merged_nuisance_specs()

const NuisanceRegistry & StatisticManager::merged_nuisance_specs ( ) const
inline
Returns
Merged nuisance specifications, with user entries overriding default ones.

Definition at line 279 of file StatisticManager.h.

◆ prepare_likelihood_for_scan()

void StatisticManager::prepare_likelihood_for_scan ( const std::vector< ParamId > &  p_specs)

Prepares a likelihood object for manual scans without running a full MLE.

The current central values of the fit parameters and nuisance parameters are stored as the default scan reference point. A later call to compute_MLE(...) or set_manual_scan_point(...) overrides this reference.

Parameters
p_specsOrdered list of fit parameters to expose in the scan.

Definition at line 1733 of file StatisticManager.cpp.

◆ print_cache()

void StatisticManager::print_cache ( )

Prints the current internal cache to standard output for debugging.

Definition at line 1172 of file StatisticManager.cpp.

◆ reload_nuisance_specs()

void StatisticManager::reload_nuisance_specs ( )

Reloads default and user nuisance specifications and invalidates fit state.

Definition at line 1266 of file StatisticManager.cpp.

◆ save_likelihood_scan_csv()

void StatisticManager::save_likelihood_scan_csv ( const std::string &  path,
const LikelihoodScanGrid grid 
) const

Writes a likelihood scan grid to a CSV file.

Parameters
pathOutput CSV path.
gridScan grid to serialize.

Definition at line 1949 of file StatisticManager.cpp.

◆ scan_likelihood_around_current_point()

LikelihoodScanGrid StatisticManager::scan_likelihood_around_current_point ( ParamId  p1,
ParamId  p2,
double  x_half_width,
double  y_half_width,
std::size_t  nx,
std::size_t  ny 
) const

Evaluates the current likelihood on a regular 2D grid around the active reference point.

Parameters
p1First scanned parameter.
p2Second scanned parameter.
x_half_widthHalf-width of the scan window along p1.
y_half_widthHalf-width of the scan window along p2.
nxNumber of x grid points.
nyNumber of y grid points.
Returns
Filled scan grid with NLL and delta-NLL values.

Definition at line 1841 of file StatisticManager.cpp.

◆ select_experiment()

void StatisticManager::select_experiment ( const std::string &  experiment)

Restricts subsequent statistics to a single experiment name.

Definition at line 1969 of file StatisticManager.cpp.

◆ select_experiment_observables() [1/2]

void StatisticManager::select_experiment_observables ( const std::set< ExperimentObs > &  observables)

Restricts subsequent statistics to an explicit list of experimental measurements.

This is stricter than select_experiments(): the experiment-name filter keeps every measurement from the selected experiments whose theory observable has been registered, whereas this method keeps only the exact (experiment, observable/bin) entries listed here. It is useful to reproduce SuperIso myobs.in / arXiv ancillary observable lists exactly.

Definition at line 2029 of file StatisticManager.cpp.

◆ select_experiment_observables() [2/2]

void StatisticManager::select_experiment_observables ( const std::vector< ExperimentObs > &  observables)

Vector overload for select_experiment_observables.

Definition at line 2022 of file StatisticManager.cpp.

◆ select_experiment_observables_all()

void StatisticManager::select_experiment_observables_all ( )

Clears the explicit experimental-observable selection.

Definition at line 2040 of file StatisticManager.cpp.

◆ select_experiments() [1/2]

void StatisticManager::select_experiments ( const std::set< std::string > &  experiments)

Restricts subsequent statistics to the provided set of experiment names.

Definition at line 1980 of file StatisticManager.cpp.

◆ select_experiments() [2/2]

void StatisticManager::select_experiments ( const std::vector< std::string > &  experiments)

Restricts subsequent statistics to the provided vector of experiment names.

Definition at line 1973 of file StatisticManager.cpp.

◆ select_experiments_all()

void StatisticManager::select_experiments_all ( )

Clears any experiment selection and uses all available experiments.

Definition at line 1991 of file StatisticManager.cpp.

◆ selected_experiment_observables()

std::set< ExperimentObs > StatisticManager::selected_experiment_observables ( ) const
Returns
Active explicit experimental-observable selection, or an empty set when inactive.

Definition at line 2049 of file StatisticManager.cpp.

◆ selected_experiments()

std::set< std::string > StatisticManager::selected_experiments ( ) const
Returns
Active experiment selection, or an empty set when all experiments are selected.

Definition at line 2000 of file StatisticManager.cpp.

◆ set_manual_scan_point()

void StatisticManager::set_manual_scan_point ( const std::map< ParamId, double > &  p_hat,
const std::map< ParamId, double > &  eta_hat 
)

Sets the reference point used by subsequent likelihood scans.

Parameters
p_hatMap of fit-parameter values at the manual reference point.
eta_hatMap of nuisance values at the manual reference point.
Exceptions
std::runtime_errorif no likelihood has been prepared.
std::invalid_argumentif one required parameter value is missing.

Definition at line 1809 of file StatisticManager.cpp.

◆ set_nuisance_user_file()

void StatisticManager::set_nuisance_user_file ( const fs::path &  user_yaml_path)

Selects a custom user nuisance-definition file and reloads nuisance specifications.

Parameters
user_yaml_pathPath to the user YAML/JSON nuisance file.

Definition at line 1279 of file StatisticManager.cpp.

◆ update_cache()

void StatisticManager::update_cache ( const std::vector< ParamId > &  p_specs = std::vector<ParamId>())

Updates the full statistical cache for the selected fit parameters.

Parameters
p_specsFit parameters to detach from the nuisance set.

Definition at line 1181 of file StatisticManager.cpp.

◆ user_nuisance_specs()

const NuisanceRegistry & StatisticManager::user_nuisance_specs ( ) const
inline
Returns
User nuisance specifications loaded from the active user nuisance file.

Definition at line 276 of file StatisticManager.h.


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