I have a couple of questions regarding flow control in tensor flow/ Edward.
I define the following random variables:
z = Poisson(tf.ones(1))
x = Gamma(concentration=tf.ones(1), rate=z)
y = Normal(loc=x + tf.ones(1), scale=0.005 * tf.ones(1))
After starting a session, I sample from them.
sess = ed.get_session() [z.sample().eval(), x.sample().eval(), y.sample().eval()]
a) Every time I sample a variable the entire graph is traverse until that node and the value is returned but the intermediate values are not stored. Is this correct?
b) is there a way of sampling the entire graph once and report the value of every node at that particular sample?
Now, I redefine the model introducing flow control. Depending on the value of a previous variable, I sample from a Gamma distribution or from a Gaussian:
z = Poisson(tf.ones(1)) zp = tf.multiply(tf.constant(1, dtype=tf.float32), z) with tf.control_dependencies([zp]): comparison = tf.equal(zp, tf.zeros(1)) with tf.control_dependencies([comparison]): def if_false(): y = Gamma(concentration=tf.ones(1), rate=zp) return y def if_true(): x = Normal(loc=zp, scale=0.005 * tf.ones(1)) return x new_rv = tf.where(comparison, if_true(), if_false())
a) Is this the most compact way of writing this code?
b) in this case, I can sample from z and new_rv but not from the intermediate variables. Again, is there any way of accessing all the node values from a sample?