tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.25k stars 1.1k forks source link

Samples from Edward Model different than Edward Model of Samples #521

Closed OlfwayAdbayIgbay closed 4 years ago

OlfwayAdbayIgbay commented 5 years ago

I wrote an Edward Model like this:

#Constants
b_ = 24e-3
h_ = 2e-3
L_ = 120e-3
h = tf.constant(2e-3)
mbar = tf.constant(0.377)
b = ed.Normal(loc = b_, scale = b_/100)
h = ed.Normal(loc = h_,scale  = h_/100)
L = ed.LogNormal(loc = tf.math.log(L_), scale = tf.abs(tf.math.log(L_)/1000))

#Model
def omega_fn(b,h,L):
    return tf.sqrt(E*b*h**3/(12*mbar))*(3.1415/L)**2

def model_omega(b,h,L):
    return ed.Normal(loc = omega_fn(b,h,L),scale=1.0,name='omega')

log_joint_model = ed.make_log_joint_fn(model_omega)

for trying out variational inference. At some point I noticed that I don't get good convergence, so I tried to just sample a histogram like this:


with tf.Session() as sess:
    plt.figure()
    samps = model_omega(b,h,L).distribution.sample(100000).eval()
    plt.hist(samps,normed = True,bins=75)

And then I noticed that I get different results every time I sample a histogram for the same input distributions.

I compared it with letting the samples from the input distributions run through my omega_fn():

with tf.Session() as sess:
    plt.figure()
    for i in range(10):
        samps = model_omega(b,h,L).distribution.sample(100000).eval()
        plt.hist(samps,normed = True,bins=75)

    plt.figure()
    for i in range(10):
        samps = omega_fn(b.distribution.sample(1000),h.distribution.sample(1000),L.distribution.sample(1000)).eval()
        plt.hist(samps,normed = True,bins=75)

And surely enough, this produces a consistant result. Letting the scale parameter in model_omega go to zero also doesn't change anything for the first case. I attached the two plots from the code below. Presampling Inconsistent

srvasude commented 4 years ago

Closing this as Edward2 has moved to https://github.com/google/edward2. Please reopen there if this is still an issue.