angeloyeo / gongdols

공돌이의 수학정리노트 Blog/Youtube 소스코드
https://angeloyeo.github.io
MIT License
175 stars 50 forks source link

Potential NaN bugs in code #2

Closed limbo-wg closed 2 years ago

limbo-wg commented 3 years ago

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!

angeloyeo commented 2 years ago

Thank you for your suggestion. It looks okay to me. I added the change in the source code.

I will close this issue. Thanks.