shine.validation.extraction¶
Extract structured results from ArviZ InferenceData.
Provides method-aware convergence diagnostics (R-hat, ESS, divergences, BFMI)
and shear summary statistics from posterior samples. Automatically adapts
to the inference method (NUTS, MAP, or VI) via the inference_method
attribute on the posterior.
extraction
¶
Extract structured results from ArviZ InferenceData.
ConvergenceDiagnostics(rhat, ess, divergences, divergence_frac, bfmi, n_samples, n_chains)
dataclass
¶
MCMC convergence diagnostic results.
Attributes:
| Name | Type | Description |
|---|---|---|
rhat |
Dict[str, float]
|
R-hat statistic per parameter. |
ess |
Dict[str, float]
|
Effective sample size per parameter. |
divergences |
int
|
Total number of divergent transitions. |
divergence_frac |
float
|
Fraction of divergent transitions. |
bfmi |
List[float]
|
Bayesian Fraction of Missing Information per chain. |
n_samples |
int
|
Total number of posterior samples. |
n_chains |
int
|
Number of MCMC chains. |
ShearEstimates(mean, median, std, percentiles)
dataclass
¶
Summary statistics for a shear component posterior.
Attributes:
| Name | Type | Description |
|---|---|---|
mean |
float
|
Posterior mean. |
median |
float
|
Posterior median. |
std |
float
|
Posterior standard deviation. |
percentiles |
Dict[float, float]
|
Dictionary mapping percentile levels to values. |
RealizationResult(run_id, g1_true, g2_true, g1, g2, diagnostics, passed_convergence, seed)
dataclass
¶
Complete result for a single bias measurement realization.
Attributes:
| Name | Type | Description |
|---|---|---|
run_id |
str
|
Unique identifier for this realization. |
g1_true |
float
|
True g1 shear value. |
g2_true |
float
|
True g2 shear value. |
g1 |
ShearEstimates
|
Shear estimates for g1 component. |
g2 |
ShearEstimates
|
Shear estimates for g2 component. |
diagnostics |
ConvergenceDiagnostics
|
MCMC convergence diagnostics. |
passed_convergence |
bool
|
Whether convergence criteria were met. |
seed |
int
|
Random seed used for this realization. |
extract_convergence_diagnostics(idata, params=None)
¶
Extract convergence diagnostics from an InferenceData object.
Method-aware: reads inference_method from idata.posterior.attrs
to determine which diagnostics are applicable.
- MAP (1 chain, 1 draw): returns sentinel values (rhat=1, ess=1).
- VI (1 chain, N draws): computes ESS, sets rhat=1, no MCMC stats.
- NUTS (default): full MCMC diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idata
|
InferenceData
|
ArviZ InferenceData with posterior and sample_stats groups. |
required |
params
|
Optional[List[str]]
|
Parameter names to compute diagnostics for (default: ["g1", "g2"]). |
None
|
Returns:
| Type | Description |
|---|---|
ConvergenceDiagnostics
|
ConvergenceDiagnostics with rhat, ess, divergences, bfmi. |
Source code in shine/validation/extraction.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
extract_shear_estimates(idata, param)
¶
Extract summary statistics for a shear parameter from posterior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idata
|
InferenceData
|
ArviZ InferenceData with posterior group. |
required |
param
|
str
|
Parameter name (e.g., "g1" or "g2"). |
required |
Returns:
| Type | Description |
|---|---|
ShearEstimates
|
ShearEstimates with mean, median, std, and percentiles. |
Source code in shine/validation/extraction.py
check_convergence(diagnostics, thresholds, method='nuts')
¶
Check if convergence diagnostics meet thresholds.
Method-aware: - MAP: always returns True (point estimate, no convergence to check). - VI: only checks ESS. - NUTS: all four checks (rhat, ESS, divergences, BFMI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostics
|
ConvergenceDiagnostics
|
Computed convergence diagnostics. |
required |
thresholds
|
ConvergenceThresholds
|
Threshold criteria to check against. |
required |
method
|
str
|
Inference method ("nuts", "map", or "vi"). |
'nuts'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if all applicable diagnostics pass, False otherwise. |
Source code in shine/validation/extraction.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
extract_realization(idata, g1_true, g2_true, run_id, seed, thresholds)
¶
Extract a complete realization result from InferenceData.
This is the main entry point for Stage 2 (extraction).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idata
|
InferenceData
|
ArviZ InferenceData with posterior and sample_stats groups. |
required |
g1_true
|
float
|
True g1 shear value. |
required |
g2_true
|
float
|
True g2 shear value. |
required |
run_id
|
str
|
Unique identifier for this realization. |
required |
seed
|
int
|
Random seed used for this realization. |
required |
thresholds
|
ConvergenceThresholds
|
Convergence diagnostic thresholds. |
required |
Returns:
| Type | Description |
|---|---|
RealizationResult
|
RealizationResult with estimates, diagnostics, and pass/fail status. |
Source code in shine/validation/extraction.py
split_batched_idata(idata, n_batch, run_ids)
¶
Split a batched InferenceData into per-realization InferenceData objects.
The batched posterior has variables with shape (n_chains, n_samples, n_batch). For each batch index i, slice [:, :, i] and create a new InferenceData with the standard (n_chains, n_samples) shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idata
|
InferenceData
|
ArviZ InferenceData from a batched MCMC run. |
required |
n_batch
|
int
|
Number of batch elements. |
required |
run_ids
|
List[str]
|
List of run identifiers, one per batch element. |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple[str, InferenceData]]
|
List of (run_id, InferenceData) tuples, one per batch element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If run_ids length doesn't match n_batch. |