thekingofkings / chicago-partition

Automatically partition Chicago into Community Areas (CA), while minize the CA level crime prediction error.
MIT License
1 stars 1 forks source link

Numerical overflow in q_learning.py #16

Closed porterjenkins closed 6 years ago

porterjenkins commented 6 years ago

When we run q_learning.py, we are getting an error when we compute the gain (presumably the change in the energy function F). This occurs at line 210 of q_learning.py: gain = 1 / (1 + math.exp(- F_next + F_cur))

screen shot 2018-08-15 at 10 50 59 am

porterjenkins commented 6 years ago

` try: gain = 1 / (1 + math.exp(- F_next + F_cur)) except OverflowError:

More numerically stable as F_next + F_cur --> -inf?

                gain = math.exp(F_next + F_cur)/(1 + math.exp(F_next + F_cur))`
porterjenkins commented 6 years ago

I think I have a decent solution for this. See commit 3b5581e9c171da640b0d7ec8e9d84c6331cdc10c when you can.