maho3 / ltu-ili

Robust ML in Astro
https://ltu-ili.readthedocs.io/en/latest/
43 stars 8 forks source link

Add variational inference posteriors #81

Closed maho3 closed 9 months ago

maho3 commented 11 months ago

Some of the VIPosteriors in sbi actually converge quite quickly (~3s) for the toy example, and can provide many samples. It would be useful to add this functionality for ltu-ili, at least for computing the RankStatistics quickly.

Snippet of example code for turning general posteriors into VIPosteriors:

vip = VIPosterior(posterior.potential_fn, prior, 'maf')
vip.set_default_x(x[i])
vip.train(max_num_iters = 3000, n_particles = 8, 
                                    learning_rate = 1e-3, quality_control=False, show_progress_bar=False)
t = vip.sample((1000,))