gamboviol / bpr

Bayesian Personalized Ranking
212 stars 87 forks source link

Math OverflowError in update_factors #6

Open danielegrattarola opened 7 years ago

danielegrattarola commented 7 years ago

Hello, I'm trying to use you code to learn and predict on a binary sparse matrix (meaning I only have 1s in the matrix), but during the training phase it will crash and throw this error: Traceback (most recent call last): File "bpr.py", line 260, in <module> model.train(data,sampler,num_iters) File "bpr.py", line 52, in train self.update_factors(u,i,j) File "bpr.py", line 81, in update_factors z = 1.0/(1.0+exp(x)) OverflowError: math range error

I've checked to see who's guilty of this, and apparently the x variable of the fucntion is diverging, therefore causing the exp operator to overflow. Have you encountered this issue? Can you suggest a fix?

Thanks

YadalaRamya commented 7 years ago

What is the input data for bpr.py code?? can u provide a sample input

HongxuChenUQ commented 7 years ago

sampling 9993 <user,item i,item j> triples... initial loss = 5242.5237869 starting iteration 0 Traceback (most recent call last): File "testTopK.py", line 303, in model.train(data,sampler,num_iters) File "testTopK.py", line 52, in train self.update_factors(u,i,j) File "testTopK.py", line 80, in update_factors z = 1.0/(1.0+exp(x)) OverflowError: math range error

Same problem, Any ideas?

HongxuChenUQ commented 7 years ago

Hi, please try this to fix try: z = 1.0/(1.0+exp(x)) except OverflowError: z = float('inf')

fukien commented 5 years ago

I met the same problem, and I tune the learning rate smaller to resolve the math range error