b-remy / gems

GEnerative Morphology for Shear
MIT License
0 stars 0 forks source link

U/b remy/blocknvp tf1 #18

Open b-remy opened 1 year ago

b-remy commented 1 year ago

This PR contains copy pasted code from tensorflow-probability that I adapted to enable the following features:

Here is an example of training 6 RealNVPs in parallel on 2-dimensional 2 moons: image

Although the fit is not perfect due for Flow prior not necessarily centered, this can be used for NeuTra sampling: image

ess_hmc = tfp.mcmc.effective_sample_size(tf.reshape(samples_hmc, [-1, 2]))
print("ESS, HMC", sess.run(ess_hmc))
# ESS, HMC [600000.   410844.72]
ess_neutra = tfp.mcmc.effective_sample_size(tf.reshape(samples_neutra, [-1, 2]))
print("ESS, NeuTra", sess.run(ess_neutra))
# ESS, NeuTra [600000.   463283.94]

Colab does not support tensorflow 1 anymore so I uploaded the associated notebook on Gist.