Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions sbi/inference/trainers/npe/npe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,19 +606,21 @@ def _get_start_index(self, context: StartIndexContext) -> int:
# Load data from most recent round.
self._round = max(self._data_round_index)

if self._round == 0 and self._neural_net is not None:
assert context.force_first_round_loss or context.resume_training, (
"You have already trained this neural network. After you had trained "
"the network, you again appended simulations with `append_simulations"
"(theta, x)`, but you did not provide a proposal. If the new "
"simulations are sampled from the prior, you can set "
"`.train(..., force_first_round_loss=True`). However, if the new "
"simulations were not sampled from the prior, you should pass the "
"proposal, i.e. `append_simulations(theta, x, proposal)`. If "
"your samples are not sampled from the prior and you do not pass a "
"proposal and you set `force_first_round_loss=True`, the result of "
"SNPE will not be the true posterior. Instead, it will be the proposal "
"posterior, which (usually) is more narrow than the true posterior."
if (
self._round == 0
and self._neural_net is not None
and not (context.force_first_round_loss or context.resume_training)
):
Comment on lines +609 to +613
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

raise ValueError(
"This neural network has already been trained. "
"If you want to continue training without adding new simulations, "
"set resume_training=True. "
"If you appended new simulations, you must either provide a proposal "
"in append_simulations(), or set force_first_round_loss=True for "
"simulations drawn from the prior. "
"Warning: Setting force_first_round_loss=True with simulations not "
"drawn from the prior will produce the proposal posterior instead of "
"the true posterior, which is typically more narrow."
)

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