setu.tune_nre#
- setu.tune_nre(dataset, *, x_dim=None, theta_dim=None, condition_dim=0, search_space=None, n_trials=50, val_fraction=0.1, batch_size=200, max_epochs=1000, max_patience=30, pruning=True, seed=None, study_name=None, storage=None, show_progress=True, baseline_params=None, key)[source]#
Tune NRE hyperparameters with Optuna.
Searches over classifier architecture, embedding size, number of contrastive classes, and training parameters, returning the best NRE by validation loss.
Requires optuna:
pip install setu-sbi[tuning].- Parameters:
dataset (
SimulationDataset) – Training data (parameters and observations) to tune on.x_dim (
int|None) – Observation dimension. Inferred fromdatasetifNone.theta_dim (
int|None) – Parameter dimension. Inferred fromdatasetifNone.condition_dim (
int) – Per-trial condition dimension;0for no conditions.search_space (
NRESearchSpace|None) – Hyperparameter ranges to search. A defaultNRESearchSpaceis used ifNone.n_trials (
int) – Number of Optuna trials (architectures) to evaluate.val_fraction (
float) – Fraction ofdatasetheld out to compute validation loss.batch_size (
int) – Minibatch size used when training each trial. Must be at least twice the upper bound of thenum_classessearch range.max_epochs (
int) – Maximum training epochs per trial.max_patience (
int) – Early-stopping patience, in epochs without validation improvement.pruning (
bool) – IfTrue, prune unpromising trials early with Optuna’s median pruner.seed (
int|None) – Seed for the Optuna sampler, for reproducible searches.storage (
str|None) – Optuna storage URL (e.g. an SQLite path) for persisting the study; in-memory ifNone.show_progress (
bool) – IfTrue, display Optuna’s progress bar.baseline_params (
dict[str,Any] |None) – Hyperparameters for a baseline trial enqueued before the search, for comparison against the tuned result.key (
Array) – JAX PRNG key for model initialization and training.
- Return type:
- Returns:
A
TuningResultholding the best NRE, its hyperparameters, and the completed Optuna study.- Raises:
ValueError – If
batch_sizeis smaller than twice the maximumnum_classesin the search space.