bpr icon indicating copy to clipboard operation
bpr copied to clipboard

Math OverflowError in update_factors

Open danielegrattarola opened this issue 8 years ago • 4 comments

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

danielegrattarola avatar Nov 28 '16 18:11 danielegrattarola

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

YadalaRamya avatar Jan 23 '17 04:01 YadalaRamya

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 avatar Mar 27 '17 14:03 HongxuChenUQ

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

HongxuChenUQ avatar Mar 28 '17 00:03 HongxuChenUQ

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

fukien avatar May 01 '19 06:05 fukien