Inference¶
- class InferenceHandler(prior_path)[source]¶
- Parameters:
prior_path (Path)
- set_dataset(data_folder)[source]¶
Point the handler at a folder of
.feathersimulation files.- Parameters:
data_folder (
Path) – Directory containing.featherfiles.- Return type:
None
- create_posterior(config)[source]¶
Build the NPE inference object and density estimator network.
Only the kwargs that the chosen model family actually accepts are forwarded to
posterior_nn; unsupported kwargs (e.g.num_blocksfor zuko-backed flows) are dropped with a DEBUG log line rather than raising aTypeErrorat runtime.- Parameters:
config (
PosteriorConfig) – Architecture and hyperparameter settings.- Return type:
None
- train_posterior(config, model_config=None)[source]¶
Train the density estimator from scratch using PyTorch Lightning.
Requires
load_training_data()andcreate_posterior()to have been called first.- Parameters:
config (
TrainingConfig) – Training loop settings.model_config (
PosteriorConfig|None) – Architecture config embedded in every checkpoint.
- Raises:
ValueError – If training data or the NPE object are missing.
- Return type:
None
- get_log_likelihood(theta, x, **kwargs)[source]¶
Evaluate the log-likelihood of theta given observed data x.
- Parameters:
theta (
ndarray[tuple[Any,...],dtype[float32]]) – Parameter array of shape(n_samples, n_params).x (
list[float] |ndarray) – Observed data vector x_o.
- Return type:
Tensor- Returns:
Log-probability tensor of shape
(n_samples,).
- load_posterior(checkpoint_path)[source]¶
Load a trained density estimator from a checkpoint for inference only.
The
PosteriorConfigis read from the checkpoint’s"model_config"key._build_posterior_nn_kwargsfiltering applies, so loading a zuko checkpoint works even ifnum_blocksis present in the stored config (it will simply be dropped).- Parameters:
checkpoint_path (
Path) – Path to a.pt/.ckptcheckpoint.- Raises:
FileNotFoundError – If checkpoint_path does not exist.
ValueError – If no model config can be determined.
Trainer¶
- lightning_module¶
alias of <module ‘mach3sbitools.inference.lightning_module’ from ‘/home/runner/work/MaCh3SbiTools/MaCh3SbiTools/src/mach3sbitools/inference/lightning_module.py’>