Skip to content
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

Poisson Matrix Factorization #213

Open
sommukh opened this issue Dec 29, 2020 · 0 comments
Open

Poisson Matrix Factorization #213

sommukh opened this issue Dec 29, 2020 · 0 comments

Comments

@sommukh
Copy link

sommukh commented Dec 29, 2020

Hi,

First of all, thank you so much for inferpy. Its an wonderful project. I am trying to implement Poisson Matrix factorization using this library. I first implemented the basic Matrix factorization using the example given in the older version of inferpy. The relevant part of the code is as follows :
`

# definition of a generic model
@inf.probmodel
def mf(M, K):
	w_Item = inf.Normal(loc=tf.zeros([M, K]), scale=1, name="wItem") 
	
	with inf.datamodel():
		w_User = inf.Normal(tf.ones(K), scale=1, name="wUser") 
		Rating = inf.Normal(tf.matmul(w_User, w_Item, transpose_b = True), 1, name="Rating") 
	   
#In variational inference - define Q-model 
@inf.probmodel
def qmodel(M, K):
	qw_Item_loc = inf.Parameter(tf.zeros([M, K]), name="qw_Item_loc")
	qw_Item_scale = tf.math.softplus(inf.Parameter(tf.ones([M, K]),  name="qw_Item_scale"))
	qw_Item = inf.Normal(qw_Item_loc, qw_Item_scale, name="wItem")
	
	with inf.datamodel():
		qw_Userloc = inf.Parameter(np.ones(K), name="qw_Userloc")
		qw_Userscale = tf.math.softplus(inf.Parameter(tf.ones(K), name="qw_Userscale"))
		qw = inf.Normal(qw_Userloc, qw_Userscale, name="wUser")`

This code seems to work ... so I modified the code for Poisson factorization as follows:

`

# definition of a generic model
@inf.probmodel
def mf(M, K):
	w_Item = inf.Normal(loc=tf.zeros([M, K]), scale=1, name="wItem") # shape = [M,K]

	with inf.datamodel():
		w_User = inf.Normal(tf.ones(K), scale=1, name="wUser") # shape = [N,K]
		Rating = inf.Poisson(tf.math.exp(w_User) @  tf.transpose(tf.math.exp(w_Item)), name="Rating")
	   
#In variational inference - define Q-model 
@inf.probmodel
def qmodel(M, K):
	qw_Item_loc = inf.Parameter(tf.zeros([M, K]), name="qw_Item_loc")
	qw_Item_scale = tf.math.softplus(inf.Parameter(tf.ones([M, K]),  name="qw_Item_scale"))
	qw_Item = inf.Normal(qw_Item_loc, qw_Item_scale, name="wItem")
	
	with inf.datamodel():
		qw_Userloc = inf.Parameter(np.ones(K), name="qw_Userloc")
		qw_Userscale = tf.math.softplus(inf.Parameter(tf.ones(K), name="qw_Userscale"))
		qw = inf.Normal(qw_Userloc, qw_Userscale, name="wUser")`

Unfortunately it gives the following error ...
LookupError: No gradient defined for operation 'Rating_46/sample/random_poisson/RandomPoissonV2' (op type: RandomPoissonV2)

I tried to find some examples using Poisson distribution but could not find any ...where am I going wrong ? Kindly help ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant