Garland
Garland

Reputation: 65

Evaluating PDF of a transformed multivariate normal in Tensorflow?

I am trying to evaluate the log pdf of a transformed multivariate distribution in Tensorflow. Whilst it will sample correctly, it produces two separate log probabilities for one sample. An example sample would be

[[  1.05516054e-03,   1.50635891e+01]]

which would return a log prob of

[[ 2.64074564, -4.21384382]] 

instead of a single log probability.

To make this clearer, I have attached what I hope is a reproducible example.

from tensorflow.contrib.distributions.python.ops import bijectors as bijector

ds = tf.contrib.distributions

mean = tf.constant([-5.,  15.])
chol = tf.constant([[0.77909118,  0.],
                [-0.02230092,  0.8150183]])

mvn_sftpls = ds.TransformedDistribution(distribution=ds.MultivariateNormalTriL(
loc=mean, scale_tril=chol), bijector=bijector.Softplus())

sample = mvn_sftpls.sample(1)
output = mvn_sftpls.log_prob(sample)

with tf.Session() as sess:
    print(sess.run(output))

Upvotes: 0

Views: 382

Answers (2)

srvasude
srvasude

Reputation: 161

For posteriority (as well as for in the future), in the nightly version of Tensorflow (and I am guessing the next release), this should be automatically inferred, and so you don't need to specify event_ndims = 1.

Upvotes: 1

Garland
Garland

Reputation: 65

Answer (for anyone curious) was to set the event_ndims in the softplus bijector to the appropriate number of dimensions in the multivariate norm. In my case:

bijector=bijector.Softplus(event_ndims = 1) 

Upvotes: 1

Related Questions