Skip to content

Commit e186adb

Browse files
authored
docs: misleading assertion message in NPE train (#1706)
* Fix misleading assertion message in NPE train * Replace assert with ValueError
1 parent f3222f9 commit e186adb

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

sbi/inference/trainers/npe/npe_base.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -606,19 +606,21 @@ def _get_start_index(self, context: StartIndexContext) -> int:
606606
# Load data from most recent round.
607607
self._round = max(self._data_round_index)
608608

609-
if self._round == 0 and self._neural_net is not None:
610-
assert context.force_first_round_loss or context.resume_training, (
611-
"You have already trained this neural network. After you had trained "
612-
"the network, you again appended simulations with `append_simulations"
613-
"(theta, x)`, but you did not provide a proposal. If the new "
614-
"simulations are sampled from the prior, you can set "
615-
"`.train(..., force_first_round_loss=True`). However, if the new "
616-
"simulations were not sampled from the prior, you should pass the "
617-
"proposal, i.e. `append_simulations(theta, x, proposal)`. If "
618-
"your samples are not sampled from the prior and you do not pass a "
619-
"proposal and you set `force_first_round_loss=True`, the result of "
620-
"SNPE will not be the true posterior. Instead, it will be the proposal "
621-
"posterior, which (usually) is more narrow than the true posterior."
609+
if (
610+
self._round == 0
611+
and self._neural_net is not None
612+
and not (context.force_first_round_loss or context.resume_training)
613+
):
614+
raise ValueError(
615+
"This neural network has already been trained. "
616+
"If you want to continue training without adding new simulations, "
617+
"set resume_training=True. "
618+
"If you appended new simulations, you must either provide a proposal "
619+
"in append_simulations(), or set force_first_round_loss=True for "
620+
"simulations drawn from the prior. "
621+
"Warning: Setting force_first_round_loss=True with simulations not "
622+
"drawn from the prior will produce the proposal posterior instead of "
623+
"the true posterior, which is typically more narrow."
622624
)
623625

624626
# Starting index for the training set (1 = discard round-0 samples).

0 commit comments

Comments
 (0)