jesterTOV.inference.result.InferenceResult#
- class InferenceResult(sampler_type, posterior, metadata, histories=None, fixed_params=None)[source]#
Bases:
objectUnified HDF5-based storage for JESTER inference results.
This class provides a clean interface for saving and loading inference results from all sampler types. It stores: - Posterior samples (parameters + derived EOS quantities + sampler-specific data) - Metadata (sampler configuration + run statistics) - Histories (time-series data for diagnostics)
- Variables:
sampler_type (SamplerType) – Sampler backend type (“flowmc”, “blackjax_smc_rw”, “blackjax_smc_nuts”, or “blackjax_ns_aw”)
posterior (Dict[str, np.ndarray]) – All posterior samples including parameters, derived quantities, and sampler-specific data
metadata (Dict[str, Any]) – Sampler configuration and run statistics
histories (Dict[str, np.ndarray] | None) – Time-series histories (ESS, acceptance, etc.) for diagnostics
Examples
Creating a result from a sampler:
>>> result = InferenceResult.from_sampler(sampler, config, runtime=3600.0) >>> result.add_derived_eos(eos_quantities) >>> result.save("output/results.h5")
Loading a result:
>>> result = InferenceResult.load("output/results.h5") >>> print(result.summary()) >>> masses = result.posterior["masses_EOS"]
- __init__(
- sampler_type,
- posterior,
- metadata,
- histories=None,
- fixed_params=None,
Initialize InferenceResult.
- Parameters:
sampler_type (SamplerType) – Sampler backend type
posterior (Dict[str, np.ndarray]) – Posterior samples (parameters + derived + sampler-specific)
metadata (Dict[str, Any]) – Sampler configuration and run statistics
histories (Dict[str, np.ndarray] | None, optional) – Time-series histories for diagnostics
fixed_params (Dict[str, float] | None, optional) – Parameters that were pinned to constant values during inference. E.g.
{"lambda_BL": 0.0, "lambda_DY": 0.0}.
Methods
__init__(sampler_type, posterior, metadata)Initialize InferenceResult.
add_derived_eos(eos_dict)Add derived EOS quantities to posterior.
add_eos_from_transform(transform[, ...])Apply transform to posterior samples to add EOS quantities.
from_sampler(sampler, config, runtime[, ...])Create InferenceResult from sampler output.
load(filepath)Load from HDF5 file.
save(filepath)Save to HDF5 file.
summary()Generate human-readable summary of results.
Attributes
Deserialize configuration JSON to dictionary.
- add_derived_eos(eos_dict)[source]#
Add derived EOS quantities to posterior.
This should be called after TOV solver generates M-R-Lambda curves.
- add_eos_from_transform(transform, n_eos_samples=None, batch_size=1000)[source]#
Apply transform to posterior samples to add EOS quantities.
- Parameters:
transform (JesterTransform) – Transform to apply (should be TOV solver transform)
n_eos_samples (int, optional) – Number of EOS samples to generate. If None or greater than available samples, generates EOS for all samples. If less than total samples, randomly selects a subset and filters log_prob/sampler fields to match.
batch_size (int, optional) – Batch size for JAX computation, by default 1000
- Return type:
Notes
When n_eos_samples < total samples:
Randomly selects n_eos_samples from posterior
Applies transform to selected samples
Filters log_prob and sampler-specific fields (weights, ess, logL, logL_birth) to match selected samples
Backs up full arrays as
*_fullbefore filtering
- property config_dict: Dict[str, Any]#
Deserialize configuration JSON to dictionary.
- Returns:
Dict[str, Any] – Configuration dictionary
- classmethod from_sampler(sampler, config, runtime, fixed_params=None)[source]#
Create InferenceResult from sampler output.
Extracts production/final samples from the sampler (not training samples).
- Parameters:
sampler (JesterSampler) – Sampler instance after sampling is complete
config (InferenceConfig) – Configuration used for inference
runtime (float) – Total runtime in seconds
fixed_params (Dict[str, float] | None, optional) – Parameters pinned to constant values during inference. Stored in metadata for later retrieval.
- Return type:
- Returns:
InferenceResult – Result object with production/final samples and metadata
- classmethod load(filepath)[source]#
Load from HDF5 file.
- Parameters:
filepath (str | Path) – Path to HDF5 file
- Return type:
- Returns:
InferenceResult – Loaded result object
- Raises:
FileNotFoundError – If file does not exist
OSError – If file cannot be read