Get MAP parameters and value


#1

Sorry for the noob question, but I am having trouble understanding the standard pipeline that Edward seems to use. I am following the MAP tutorial, and I seem to have it running, but I don’t understand how to obtain the results of the maximisation. The “run” method returns nothing, and I don’t know what other methods I am supposed to call to get the results. This is what I have:

import edward as ed
import edward.models as em

mu = em.Uniform(low=-5., high=5.)
X = em.Normal(loc=mu, scale=1.)
inference = ed.MAP([mu],data={X: 3.})
inference.run()

How do I get the actual inferred parameters and posterior value from this?


#2

Is this not a standard thing? I looked through all the examples and docs but I still have no idea how to do basic things like this. Or are these some standard tensorflow objects that it is assumed I already know how to use?


#3

Sadly, I believe that task falls under the general category of “standard Tensorflow for which it is assumed you already know how to use”. Though it definitely would have been helpful for me too to have an Edward tutorial for absolute beginners.

To infer parameters using MAP, you will need to specify your parameters as Tensorflow Variables (https://www.tensorflow.org/api_docs/python/tf/Variable). These represent nodes in Tensorflow’s computation graph that can store data across “run” calls.

Your example would look something like the following instead:

mu = tf.Variable(0., dtype=tf.float32)
X = em.Normal(loc=mu, scale=1.)
inference = ed.MAP(data={X: 3.})
inference.run()
sess = ed.get_session()
print sess.run([mu])

The first two lines build a computation graph in Tensorflow. The third line computes the loss function and the gradient of that loss function with respect to all variables. The fourth line minimizes the loss. The fifth line returns the Tensorflow object referring to the Session that Edward uses (https://www.tensorflow.org/api_docs/python/tf/Session). The sixth line uses this session to “run” the Variable node in the computation graph (i.e. simply returns its value).