RatInABox-Lab / RatInABox

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

Firingrate norm for BVCs should be unscaled #108

Closed colleenjg closed 3 months ago

colleenjg commented 3 months ago

I noticed that the BVC firingrates weren't scaling correctly if max_fr is not 1. I've traced the source of the issue to self.cell_fr_norm. This value is initialized based on scaled firingrates, but then applied before scaling when calling get_state(), and thus cancels out the subsequent scaling. See L1543 and L1679 of Neurons.py

import numpy as np

from ratinabox import Agent, Environment
from ratinabox.Neurons import BoundaryVectorCells

MAX_FR = 1

np.random.seed(10)

env = Environment()
ag = Agent(env)
BVCs = BoundaryVectorCells(ag, params={"min_fr": 0, "max_fr": MAX_FR})

for i in range (500):
    ag.update()
    BVCs.update()

min = np.asarray(BVCs.history["firingrate"]).min()
max = np.asarray(BVCs.history["firingrate"]).max()

print(f"{min:.4f} to {max:.4f}")

gives 0.0000 to 1.0165 (FYI: you can see there's a slight overshoot of the max, which might be for another issue.)

But, if you set MAX_FR = 10, you still get 0.0000 to 1.0165.

I'll create a PR in a moment to propose a solution.

colleenjg commented 3 months ago

Minor edit: I hadn't pulled the latest version. The error is still present, but the exact values for both MAX_FR values are 0.0000 to 1.0088.

TomGeorge1234 commented 3 months ago

Oh yes I see that is a bit of a bug, it totally cancels itself out. Not sure how I'd missed that/when it crept in. I'll take a look at your PR and leave this open until it's solved