-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NeuralPosteriorEnsemble & multi-rounds #783
Comments
Hi, |
You mean that the new def train_nn(rng, num_rounds, num_simul):
utils.sbiutils.seed_all_backends(rng)
density_estimator_build_fun = posterior_nn(model="maf", hidden_features=64)
inference = SNPE(prior=prior, device=device,
density_estimator=density_estimator_build_fun)
proposal = prior
for _ in range(num_rounds):
theta, x = simulate_for_sbi(simulator, proposal, num_simul)
# only for SNLE & SNPE proposal=proposal
density_estimator = inference.append_simulations(
theta, x, proposal=proposal
).train()
posterior = inference.build_posterior(density_estimator)
proposal = posterior.set_default_x(x_o)
return posterior |
yes. |
Yes, that's the case
Well what do you mean? |
the total number of simulations will be |
Well I have a crash on Google Colab (CPU): def train_nn(rng, num_rounds, num_simul):
utils.sbiutils.seed_all_backends(rng)
density_estimator_build_fun = posterior_nn(model="maf", hidden_features=64)
inference = SNPE(prior=prior, device=device,
density_estimator=density_estimator_build_fun)
proposal = prior
for _ in range(num_rounds):
theta, x = simulate_for_sbi(cond_simulator, proposal, num_simul)
# only for SNLE & SNPE proposal=proposal
density_estimator = inference.append_simulations(
theta, x, proposal=proposal
).train()
posterior = inference.build_posterior(density_estimator)
proposal = posterior.set_default_x(x_o)
return posterior
ensemble_size = 3
np.random.seed(10)
random_state = np.random.randint(1_000_000, size=ensemble_size)
num_rounds=2
num_simul=10_000
posteriors = Parallel(n_jobs=-1)(delayed(train_nn)(rng,num_rounds,num_simul) for rng in random_state)
final_posterior = NeuralPosteriorEnsemble(posteriors)
After investigation it seems that the statement that crashes is |
can you show the full traceback? where is |
I have exectuted the train_nn function w/o the joblib Parallel and it fails also def train_nn(rng, num_rounds, num_simul):
print("train, rng: ",rng)
utils.sbiutils.seed_all_backends(rng)
density_estimator_build_fun = posterior_nn(model="maf", hidden_features=64)
inference = SNPE(prior=prior, device=device,
density_estimator=density_estimator_build_fun)
proposal = prior
for ir in range(num_rounds):
print("train, rng: ",rng, " round:", ir)
theta, x = simulate_for_sbi(cond_simulator, proposal, num_simul)
# only for SNLE & SNPE proposal=proposal
density_estimator = inference.append_simulations(
theta, x, proposal=proposal
).train()
print("\n build_posterior")
posterior = inference.build_posterior(density_estimator)
print("new proposal")
proposal = posterior.set_default_x(x_o)
print("end this round")
print("all done..")
return posterior
tmp = train_nn(random_state[0], num_rounds=1, num_simul=100) leads to
|
Ha! I found the problem... it is my fault (of course) : using a JAX simulator, I must use posterior.set_default_x(x_o_tensor) with
Now it is working :) |
Hello,
Is it possible to use NeuralPosteriorEnsemble as in the snippet
but with a multi-rounds for each trained posterior?
The text was updated successfully, but these errors were encountered: