Hi,
While implementing Correlated Topic Model with ADVI I get inf average loss. What does it mean? Now I’m unsure whether I’m implementing it in a correct way or not.
Here is my code:
import numpy as np
import pymc3 as pm, theano.tensor as t
import matplotlib.pyplot as plt
K = 4
V = 4 # number of words
D = 10 # number of documents
data = np.random.randint(V,size=(D,4))
alpha = np.ones((1, K))
beta = np.ones((1, V))
model = pm.Model()
mu = np.ones((1,K),dtype = np.float64)
cov = np.random.random_sample(size=(K,K))
Wd = [len(doc) for doc in data]
(D, W) = data.shape
def log_lda(theta,phi):
def ll_lda(value):
dixs, vixs = value.nonzero()
vfreqs = value[dixs, vixs]
ll =vfreqs* pm.math.logsumexp(t.log(theta[dixs]) + t.log(phi.T[vixs]), axis = 1).ravel()
return t.sum(ll)
return ll_lda
with model:
eta = pm.MvNormal('eta',mu = mu,cov = cov, shape = (D,K))
theta = t.nnet.softmax(eta)
phi = pm.Dirichlet("phi", a=beta, shape=(K, V))
doc = pm.DensityDist('doc', log_lda(theta,phi), observed=data)
with model:
inference = pm.ADVI()
approx = pm.fit(n=10000,method= inference,callbacks=[pm.callbacks.CheckParametersConvergence(diff='absolute')])
#inference
tr1 = approx.sample(draws=1000)
pm.plots.traceplot(tr1);
pm.plot_posterior(tr1, color='LightSeaGreen');
plt.plot(approx.hist)
Can someone please guide me with this?
Help much appreciated.
Thanks