New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NormalWishart-Normal model #471
Comments
I was working on a similar problem, but used only tf.float32 and it ran fine. I understand this may not be relevant to you anymore, but it may help someone else! |
@bertini36 Were you able to resolve this? I am facing the same problem. @AlexLewandowski Any links to your code? |
Nop.. sorry @gundeep59 I tried it using float32 but it didn't work for me. Same error. |
@AlexLewandowski Can you tell us what Edward and Tensorflow versions you use? |
@AlexLewandowski Also did you use WishartCholesky or WishartFull from the models? I tried both, but WishartFull too returned an error. |
Can you report your versions of Edward and TensorFlow? |
Edward : 1.2.4 Tensorflow : 1.0.1 |
Latest versions: |
Looks like a bug with the For now, if you replace the prior hyperparameters with v_prior = tf.constant(3., dtype=tf.float64)
W_prior = tf.constant(np.array([[1., 0.], [0., 1.]]),
dtype=tf.float64)
m_prior = tf.constant(np.array([0.5, 0.5]), dtype=tf.float64)
k_prior = tf.constant(0.6, dtype=tf.float64) this will run. (Note an additional error appears, as the multivariate normal's covariance matrix is overparameterized and does not guarantee positive semi-definiteness; optimizing it freely would be easier if you use a multivariate normal cholesky.) |
@dustinvtran Thanks for the help! I am tried using MultivariateNormalCholesky for mu as well as xn and in the variational model for qmu but facing the error for cholesky decomposition. |
The Cholesky decomposition only raises an error if it's trying to decompose a matrix that isn't positive definite. This shouldn't be an issue if you're directly optimizing with respect to a lower triangular matrix (by construction its outer product with itself will always be positive definite). Can you provide more details on the error and modified code? |
Sure. The code for the probabilistic model and the inference is as below. # Probabilistic model
sigma = WishartCholesky(df=v_prior, scale=W_prior)
mu = MultivariateNormalCholesky(m_prior, k_prior * sigma)
xn = MultivariateNormalCholesky(tf.reshape(tf.tile(mu, [N]), [N, D]),
tf.reshape(tf.tile(sigma, [N, 1]), [N, D, D]))
print('***** PROBABILISTIC MODEL *****')
print('mu: {}'.format(mu))
print('sigma: {}'.format(sigma))
print('xn: {}'.format(xn))
# Variational model
qmu = MultivariateNormalCholesky(
tf.Variable(tf.random_normal([D], dtype=tf.float64), name='v1'),
tf.nn.softplus(
tf.Variable(tf.random_normal([D, D], dtype=tf.float64), name='v2')))
qsigma = WishartCholesky(
tf.nn.softplus(
tf.Variable(tf.random_normal([], dtype=tf.float64), name='v3')),
tf.nn.softplus(
tf.Variable(tf.random_normal([D, D], dtype=tf.float64), name='v4')))
print('***** VARIATIONAL MODEL *****')
print('qmu: {}'.format(qmu))
print('qsigma: {}'.format(qsigma))
inference = ed.KLqp({mu: qmu, sigma: qsigma}, data={xn: xn_data})
inference.run(n_iter=2000, n_samples=20,n_print=100) And the error is
This "WishartCholesky_6" is for qsigma. |
I was trying with positive definite matrices generation in this way:
But same error |
@gundeep59 | you overparameterized @bertini36 | I think this runs into the same issue? In general, it's worth debugging where things go wrong. For exapmle, first you should try doing the optimization with a fixed |
Struggling with the same errors, I resolved them by constraining qsigma like this:
The problem with the code posted by @bertini36 and @gundeep59 is probably that the df parameter is not constrained to be greater or equal to the dimensionality D, and that the scale is not lower triangular. |
Thanks @deoxyribose. Closing issue. |
Hi there!
I'm trying to implement a NormalWishart-Normal model with Edward. I think the model representation is OK but, what do you think?. Here is the code:
But it seems there is a type error:
Do you think it is a Tensorflow's WishartCholesky problem? Do you have some model example using Wishart distribution in Edward?
The text was updated successfully, but these errors were encountered: