|
9 | 9 | from jax import numpy as jnp |
10 | 10 | from jax import random as jr |
11 | 11 |
|
12 | | -from sbijax import SABC, MultiEps, abs_distance, inference_data_as_dictionary |
| 12 | +from sbijax import MultiEps, abs_distance, sabc |
13 | 13 |
|
14 | 14 |
|
15 | 15 | def run(name: str, seed: int, budget: dict, out: str) -> None: |
16 | 16 | """Run sbijax SABC on task ``name`` and write samples + timing to ``out``.""" |
17 | 17 | prior, simulator, _ = tasks.build_jax_task(name) |
18 | 18 | observed = jnp.asarray(tasks.load_observed(name)) |
19 | | - model = SABC((lambda: prior, simulator), distance_fn=abs_distance) |
| 19 | + sampler = sabc(prior, simulator, distance_fn=abs_distance) |
20 | 20 |
|
21 | 21 | def sample_to_numpy(key): |
22 | | - idata, _ = model.sample_posterior( |
| 22 | + particles, _ = sampler.sample( |
23 | 23 | key, |
24 | 24 | observed, |
25 | 25 | n_particles=budget["n_particles"], |
26 | 26 | n_simulation=budget["n_simulation"], |
27 | 27 | schedule=MultiEps(v=1.0), |
28 | 28 | ) |
29 | | - d = inference_data_as_dictionary(idata.posterior) |
30 | 29 | cols = [ |
31 | | - np.asarray(d[k]).reshape(-1, np.asarray(d[k]).shape[-1]) |
32 | | - for k in sorted(d) |
| 30 | + np.asarray(particles[k]).reshape(-1, np.asarray(particles[k]).shape[-1]) |
| 31 | + for k in sorted(particles) |
33 | 32 | ] |
34 | 33 | return np.concatenate(cols, 1) |
35 | 34 |
|
|
0 commit comments