RatInABox-Lab / RatInABox

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

Can't get firingrate when using import_trajectory with interpolate=False #114

Closed PikaPei closed 3 weeks ago

PikaPei commented 3 weeks ago

Hi Tom,

Great to see RatInABox has become so wonderful!

I have a question: When I used Ag.import_trajectory with interpolate=False, I would get nan values in neuron output firingrate list.

Here is an example:

from ratinabox.Environment import Environment
from ratinabox.Agent import Agent
from ratinabox.Neurons import *

dt = 0.01

Env = Environment(params={"dx": 0.001})

Ag = Agent(Env)

times = [0.01, 0.02, 0.03, 0.04, 0.05]
positions = [[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]
Ag.import_trajectory(times=times, positions=positions, interpolate=False)

PCs = PlaceCells(Ag)

for i in range(int(times[-1] / dt)):
    Ag.update(dt=dt)
    PCs.update()

print(PCs.history["firingrate"])

I also tried interpolate=True, but I got weird values from the beginning and the end of Ag.history["vel"]. I haven't figured out how to control it, so I change to interpolate=False. Thank you!

TomGeorge1234 commented 3 weeks ago

Good spot. It was a small bug originating from the fact that dt is calculated on the fly when interpolation=False but the initial time is offset to zero, as is self.t, giving dt=0 and some divide-by-error errors when trying to calculate speeds etc.

Should be fixed now in version v1.14.1, let me know if you think otherwise.

TomGeorge1234 commented 3 weeks ago

marking as closed for now