Hello!
I’m trying to re-implement probabilistic matrix factorization (e.g. as described in section 2 in this paper). Below is the gist of my code. tfidf
is a (somewhat) large scipy.sparse.csr.csr_matrix
, with entries that are positive and no larger than 1.0
. Notice that I’m jumping through hoops with my definition of R_nonzero
in order to avoid having my likelihood take all the zeros into account (i.e., this is how I implement the I_{ij} described in the paper).
rows, columns, entries = scipy.sparse.find(tfidf)
n, m = tfidf.shape
dim = 20
sigma = 0.15
sigma_u = 0.02
sigma_v = 0.02
with pm.Model() as pmf:
U = pm.Normal('U', mu=0, sd=sigma_u, shape=[n, dim])
V = pm.Normal('V', mu=0, sd=sigma_v, shape=[m, dim])
R_nonzero = pm.Normal('R_nonzero',
mu=tt.sum(np.multiply(U[rows, :], V[columns, :]), axis=1),
sd=sigma,
observed=entries)
map_estimate = pm.find_MAP()
The problem is that map_estimate
now comes up with U
and V
to be entirely zero matrices! find_MAP
also only takes 2 iterations in order to converge, which I find a bit suspicious… is it possible that find_MAP
is stopping too early, somehow?
Thanks for your time!