RatInABox-Lab / RatInABox

A python package for modelling locomotion in complex environments and spatially/velocity selective cell activity.
MIT License
175 stars 31 forks source link

Occasionally Ag.update() returns nan velocity and position #11

Closed cngzlsh closed 1 year ago

cngzlsh commented 1 year ago

Hi Tom, Please see this example of error I encountered:

Ag = Agent(Env)
Ag.dt = 0.1
print(Ag.pos, Ag.velocity)
# [0.79958237 0.76560547]  [0.51603493 0.49723318])

random_drift_velocity = np.random.random(2)
print(random_drift_velocity)
# [0.51777053 0.88738508]

Ag.update(drift_velocity=random_drift_velocity,
          drift_to_random_strength_ratio=2.0)
print(Ag.pos, Ag.velocity)
# [nan nan]  [nan nan]
TomGeorge1234 commented 1 year ago

We discovered tis bug originates in the utils.rayleigh_to_normal() function. Will be fixed at next update. Current work around is to either only pass in small drift velocities (of order Ag.speed_std) or increase the mean speed of the Agent Ag.speed_std.

TomGeorge1234 commented 1 year ago

Hi Daniel, thanks for raising this issue. It should be fixed now. Any chance you could confirm this then I'll close it

cngzlsh commented 1 year ago

Thanks Tom, can confirm this has been fixed. Merry Christmas!