gongdols icon indicating copy to clipboard operation
gongdols copied to clipboard

Potential NaN bugs in code

Open limbo-wg opened this issue 4 years ago • 0 comments

Hi~ Thank you very much for sharing the code, it really helped me a lot ^_^!

However, I found a problem when I executed the program (gongdols/머신러닝/restricted_boltzmann_machine/denoising_RBM.py), as well as the similar code in main.py. Sometimes, the output of the program would be NAN. I figured out the reason

temp = torch.log(torch.exp(wx_b) + 1)

That is because when the input of torch.exp is 88, torch.exp(88) would output INF (Infinity), and further cause the program to output NAN. It might be better if we use torch.clamp to the program to avoid torch.exp(88)

wx_b = torch.clamp(wx_b, -87, 87)
temp = torch.log(torch.exp(wx_b) + 1)

Looking forward to receiving your reply~

Thanks in advance!

limbo-wg avatar Jan 16 '21 12:01 limbo-wg