petitRADTRANS.sbi.inference#
User-facing amortized inference services.
Classes#
Describe whether an observation is inside the training support. |
|
Return type for amortized inference queries. |
|
Serve trained SBI models through a retrieval-like interface. |
Functions#
|
|
|
Module Contents#
- petitRADTRANS.sbi.inference._coerce_block_array(values: Any, target_size: int) numpy.ndarray | None#
- petitRADTRANS.sbi.inference._robust_score_summary(values: numpy.ndarray, center: numpy.ndarray, scale: numpy.ndarray, valid_mask: numpy.ndarray) tuple[float, float]#
- class petitRADTRANS.sbi.inference.OODDiagnostic#
Describe whether an observation is inside the training support.
Attributes#
- score:
Scalar out-of-distribution score.
- threshold:
Optional threshold used to convert the score into a pass/fail decision.
- passed:
Optional boolean indicating whether the observation passed the OOD test.
- metadata:
Auxiliary diagnostic metadata.
- score: float#
- threshold: float | None = None#
- passed: bool | None = None#
- metadata: Mapping[str, Any]#
- class petitRADTRANS.sbi.inference.AmortizedRetrievalResult#
Return type for amortized inference queries.
Attributes#
- posterior:
Posterior samples and any attached diagnostics.
- posterior_predictive:
Optional posterior-predictive report for the same observation.
- ood_diagnostic:
Optional in/out-of-distribution assessment.
- metadata:
Additional metadata such as preprocessing usage during inference.
- posterior_predictive: Any = None#
- ood_diagnostic: OODDiagnostic | None = None#
- metadata: Mapping[str, Any]#
- class petitRADTRANS.sbi.inference.AmortizedRetrieval(task: petitRADTRANS.sbi.task.SBITask, posterior_estimator: petitRADTRANS.sbi.posterior.PosteriorEstimator, simulator: petitRADTRANS.sbi.simulator.RuntimeSimulator | None = None, preprocessing_metadata: petitRADTRANS.sbi.preprocessing.TaskPreprocessingMetadata | Mapping[str, Any] | None = None)#
Serve trained SBI models through a retrieval-like interface.
Parameters#
- task:
SBI task compatible with the trained posterior.
- posterior_estimator:
Trained posterior estimator used for encoding and sampling.
- simulator:
Optional simulator override used for posterior-predictive generation.
- preprocessing_metadata:
Optional preprocessing metadata or payload. When omitted the inference service attempts to recover the preprocessing payload saved inside the posterior artifact.
Notes#
Raw user-facing observation blocks are normalized internally before encoding when preprocessing metadata is available, but posterior-predictive comparisons remain on the original observation scale.
- task#
- posterior_estimator#
- simulator = None#
- preprocessing_metadata#
- _resolve_preprocessing_metadata(preprocessing_metadata: petitRADTRANS.sbi.preprocessing.TaskPreprocessingMetadata | Mapping[str, Any] | None) petitRADTRANS.sbi.preprocessing.TaskPreprocessingMetadata | None#
- prepare_observation_blocks(observation_blocks: list[petitRADTRANS.sbi.observation.ObservationBlock]) list[petitRADTRANS.sbi.observation.ObservationBlock]#
Normalize user-facing observation blocks when preprocessing metadata is available.
Parameters#
- observation_blocks:
Raw observation blocks provided by the caller.
Returns#
- list[ObservationBlock]
Either the original blocks or normalized copies, depending on whether preprocessing metadata is available.
- infer(observation_blocks: list[petitRADTRANS.sbi.observation.ObservationBlock], n_posterior_samples: int = 1000, include_posterior_predictive: bool = False, posterior_predictive_interval_level: float = 0.9, n_predictive_forward_model_samples: int | None = None, seed: int | None = None) AmortizedRetrievalResult#
Infer a posterior for one structured observation.
Parameters#
- observation_blocks:
Raw observation blocks for one target system.
- n_posterior_samples:
Number of posterior draws to generate.
- include_posterior_predictive:
Whether to also generate a posterior-predictive summary.
- posterior_predictive_interval_level:
Predictive interval level used when generating the optional posterior-predictive report.
- n_predictive_forward_model_samples:
Number of posterior draws passed through the forward model when generating the posterior-predictive summary. When
Nonealln_posterior_samplesdraws are forwarded. Set this to a small value (e.g. 50–200) to avoid a multi-hour hang whenn_posterior_samplesis large.- seed:
Optional seed for posterior and posterior-predictive sampling.
Returns#
- AmortizedRetrievalResult
Posterior samples and any optional predictive metadata.
- posterior_predictive(posterior: petitRADTRANS.sbi.posterior.PosteriorSamples, observation_blocks: list[petitRADTRANS.sbi.observation.ObservationBlock], interval_level: float = 0.9, n_predictive_forward_model_samples: int | None = None, seed: int | None = None) petitRADTRANS.sbi.calibration.PosteriorPredictiveReport#
Generate posterior-predictive draws for a fitted observation.
Parameters#
- posterior:
Posterior samples associated with one observed system.
- observation_blocks:
Original observation blocks used for user-facing comparison.
- interval_level:
Central predictive interval level to report.
- n_predictive_forward_model_samples:
Number of posterior draws passed through the forward model. When
Noneall samples inposteriorare used. Set this to a small value (e.g. 50–200) to keep the number of expensive petitRADTRANS calls manageable.- seed:
Optional seed for predictive simulation.
Returns#
- PosteriorPredictiveReport
Predictive summary for the supplied posterior samples.
- diagnose_domain(observation_blocks: list[petitRADTRANS.sbi.observation.ObservationBlock]) OODDiagnostic | None#
Estimate whether the observation is in-distribution for the model.
Parameters#
- observation_blocks:
Observation blocks to diagnose.
Returns#
- OODDiagnostic | None
Robust support-distance diagnostic derived from preprocessing statistics, or
Nonewhen preprocessing metadata is unavailable.