Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
GaussianSummary.py
Go to the documentation of this file.
1"""Summary statistics for Monte-Carlo observable distributions."""
2
3from __future__ import annotations
4
5from dataclasses import dataclass
6from typing import Any
7
8from pyhyperiso.phyperiso.pyhyperiso import statistic as _cpp_stat
9from pyhyperiso.core.Common.BinnedObservableId import BinnedObservableId
10
11
12@dataclass
14 """Gaussian or split-Gaussian approximation of one observable distribution.
15
16 This class mirrors the C++ ``GaussianSummary`` struct returned by the
17 Monte-Carlo uncertainty machinery. When the empirical skewness is small, the
18 distribution is summarized by ``mu`` and ``sigma``. Otherwise, the backend
19 also provides a mode and asymmetric widths ``sigma_p`` and ``sigma_m``.
20
21 Attributes:
22 id: Binned observable identifier.
23 mu: Population mean of the sampled observable.
24 sigma: Unbiased standard deviation used in the symmetric approximation.
25 sigma_p: Right-side width for a split-Gaussian approximation.
26 sigma_m: Left-side width for a split-Gaussian approximation.
27 mode: Estimated population mode.
28 skew: Empirical skewness estimator.
29 symmetric: Whether the backend classified the sample as symmetric.
30
31 Examples:
32 >>> summary = GaussianSummary(id=obs_id, mu=1.0, sigma=0.1, symmetric=True)
33 >>> summary.mu, summary.sigma
34 (1.0, 0.1)
35 """
36
37 id: BinnedObservableId
38 mu: float = 0.0
39 sigma: float = 0.0
40 sigma_p: float = 0.0
41 sigma_m: float = 0.0
42 mode: float = 0.0
43 skew: float = 0.0
44 symmetric: bool = False
45
46 @classmethod
47 def from_cpp(cls, cpp_obj: Any) -> "GaussianSummary":
48 """Create a Python summary from a bound C++ summary.
49
50 Args:
51 cpp_obj: Bound C++ ``GaussianSummary`` instance.
52
53 Returns:
54 The equivalent Python dataclass.
55 """
56 return cls(
57 id=BinnedObservableId.from_cpp(cpp_obj.id),
58 mu=float(cpp_obj.mu),
59 sigma=float(cpp_obj.sigma),
60 sigma_p=float(cpp_obj.sigma_p),
61 sigma_m=float(cpp_obj.sigma_m),
62 mode=float(cpp_obj.mode),
63 skew=float(cpp_obj.skew),
64 symmetric=bool(cpp_obj.symmetric),
65 )
66
67 def to_cpp(self):
68 """Convert this dataclass to a bound C++ ``GaussianSummary``.
69
70 Returns:
71 A newly allocated bound C++ summary object.
72 """
73 cpp = _cpp_stat.GaussianSummary()
74 cpp.id = self.id.to_cpp()
75 cpp.mu = float(self.mu)
76 cpp.sigma = float(self.sigma)
77 cpp.sigma_p = float(self.sigma_p)
78 cpp.sigma_m = float(self.sigma_m)
79 cpp.mode = float(self.mode)
80 cpp.skew = float(self.skew)
81 cpp.symmetric = bool(self.symmetric)
82 return cpp
"GaussianSummary" from_cpp(cls, Any cpp_obj)