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

Access to built-in "uniform" function for PlaceCells / Agent velocity initialization #5

Closed PikaPei closed 1 year ago

PikaPei commented 1 year ago

Great work, it's simple and pretty!

I'm trying the 1D version. Here are some small questions/suggestions.

1. In the class PlaceCells, place_cell_centres uses "uniform_jitter" method to sample the position. Although I can pass an array into place_cell_centres, I think it's easier to use the built-in "uniform" method?

  1. When initializing Agent, if I didn't use the argument params but changed speed_mean directly, the initial velocity wouldn't be updated (it's still the default value). However, if using the params, it's correct. Not sure if this would be a problem or not.

    
    Ag.speed_mean = 0.20
    # Ag.velocity = 0.08

Ag = Agent(Env, params={"speed_mean": 0.20})

Ag.velocity = 0.20

TomGeorge1234 commented 1 year ago

Thank you! And thank you for raising this issue.

  1. I see. Yes, you have understood this correctly. I assume you would like evenly spaced place cells WITHOUT jitter. Currently the only way to do this is do sample these positions yourself (using Environment.sample_positions(method="uniform"), or just np.linspace()) and pass this in at initialisation. Ultimately there are many examples where it would be nice to control things like this at initialisation but this comes at the expense of complexity and elegance which was why I didn't include it. However I'm happy for you to add it. Feel free to edit the class and open a pull request: I would suggest the most elegant solution would be that the place_cell_centres parameter could be used to hand in a string "uniform" or "uniform_jitter" controlling the argument method which is passed to sample_positions(method=self.place_cell_centres) on line 554.

  2. Yes, this is intended behaviour. The Ag.speed_mean attribute just sets the mean speed towards which the stochastic process will cause the speed to drift, not the speed itself. So changing it after initialisation will not immediately change the actual speed of the Agent, as you observe, but after a short period of exploration you will find the velocity varying around the new mean of 0.2. On the other hand, at initialisation the velocity is set to the speed_mean parameter, hence why this change is visible immediately. Ultimately, both will work and will produce very similar data where the Agents mean speed sits around 0.2.

PikaPei commented 1 year ago

Thank you for the explanation!

  1. Now I know why you didn't include these methods. And thanks for the suggestion, I'll try to make a pull request! (although I personally would like to use the built-in method, I don't know if it's necessary for this package or not 😅)

  2. Ok, I see! I totally forgot I can set Ag.velocity directly...


After updating the package, the 1D version raised an error.

Env = Environment(params={"dimensionality": "1D"})
Ag = Agent(Env)
PCs = PlaceCells(Ag)
Warning you have solid 1D boundary conditions and non-zero speed mean. 
Traceback (most recent call last):
  File "/home/hsulab/project/RatInABox/demos/test.py", line 10, in <module>
    PCs = PlaceCells(Ag)
  File "/home/hsulab/.local/lib/python3.10/site-packages/ratinabox/Neurons.py", line 574, in __init__
    len(self.Agent.Environment.walls) > 5
AttributeError: 'Environment' object has no attribute 'walls'

It seems that it didn't detect the 1D environment?

TomGeorge1234 commented 1 year ago

I'm happy for the change to be made. I agree it might be restrictive to enforce jitter on the place cell position. I leave it up to you if you want to PR it.

Sorry, that's a trivial bug I knew about. I think I've fixed it now, please can you confirm if it is working.

PikaPei commented 1 year ago

Yes, it works well now! Thanks for the quick update. I've also made a PR about place_cell_centres.

TomGeorge1234 commented 1 year ago

Glad it's working! I'll close this issue.

TomGeorge1234 commented 1 year ago

Hi there,

Thanks again for you contributions to RatInABox. I was wondering if I could ask you a favour.

I’m putting together a small talk to be given here at UCL and wanted to “showcase” the package being used in the broader science community. Would you have any simple figures, which demonstrate core RiaB functionality, I would be able to put in my slides crediting you of course.

Very much appreciate your help.

Tom

On 27 Oct 2022, at 18:14, PikaPei @.***> wrote:

Yes, it works well now! Thanks for the quick update. I've also made a PR about place_cell_centres.

— Reply to this email directly, view it on GitHub https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1293832283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ4G2JOCNWUNY4BIJEJ3MLTWFKZ7HANCNFSM6AAAAAARO2GBME. You are receiving this because you commented.

PikaPei commented 1 year ago

Hi George,

Thanks for the kind invitation. I think I can't help because I just played this package and did nothing more than your great demos. Actually, I still try to figure out how to incorporate this package into my project (also synaptic plasticity-related). I may get some hints from another of your paper and repo (Rapid learning of predictive maps with STDP and theta phase precession)!

By the way, after seeing this package, I'd like to generate some fake data and do simple persistent homology analysis, like Fig. 2b in "The intrinsic attractor manifold and population dynamics of a canonical cognitive circuit across waking and sleep https://doi.org/10.1038/s41593-019-0460-x". Basically, I would just let the agent run in the open field randomly and record HeadDirectionCell or GridCell to see whether they form the ring or torus structure. (Although I am not really familiar with this field and not sure if it'll work or not, just for fun 😅)

How do you feel about this? I may try it on the weekend. If you think it is related to your topic, I can email you the result later!

Best regards, Hsuan-Pei

Tom George @.***> 於 2022年11月8日 週二 凌晨1:18寫道:

Hi there,

Thanks again for you contributions to RatInABox. I was wondering if I could ask you a favour.

I’m putting together a small talk to be given here at UCL and wanted to “showcase” the package being used in the broader science community. Would you have any simple figures, which demonstrate core RiaB functionality, I would be able to put in my slides crediting you of course.

Very much appreciate your help.

Tom

On 27 Oct 2022, at 18:14, PikaPei @.***> wrote:

Yes, it works well now! Thanks for the quick update. I've also made a PR about place_cell_centres.

— Reply to this email directly, view it on GitHub < https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1293832283>, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AJ4G2JOCNWUNY4BIJEJ3MLTWFKZ7HANCNFSM6AAAAAARO2GBME . You are receiving this because you commented.

— Reply to this email directly, view it on GitHub https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1305938421, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGJCWHYBQRE5SOBLKGY5S5TWHE2XBANCNFSM6AAAAAARO2GBME . You are receiving this because you authored the thread.Message ID: @.***>

TomGeorge1234 commented 1 year ago

This is a great idea. I would be happy to support you if you wanted to make an STDP layer of neurons and add it to RiaB. The best thing would be to build this off “FeedForwardlayer”. You may find some help looking at https://github.com/TomGeorge1234/STDP-SR/blob/main/mazeAgentUtils_reviewResponses.py this code for my other paper (line 508). It’s a bit of a mess but you will see how I sample spikes, update traces and use these to learn weights.

I think your idea about homology would definitely work and I’d love to see it! However for the torus you’d have to be careful to choose fixed grid frequencies (by default they are sampled randomly in RiaB). With fixed frequencies you should find a donut (I assume you are familiar with these two papers https://www.nature.com/articles/s41586-021-04268-7, https://reader.elsevier.com/reader/sd/pii/S0896627322009072?token=A7B5846F0A4A93EF4CB8BDE1AE407BBC155DF0C837099DD10972A5C912E6AC8F1FCD47CF8F55D1C9D72E48D18B5ABA25&originRegion=eu-west-1&originCreation=20221109113712)!

Good luck and let me know if you need help. If you do generate anything interesting I really would love to have a figure to put in my talk. Doesn’t need to be anything complex !

Tom

On 9 Nov 2022, at 00:18, PikaPei @.***> wrote:

Hi George,

Thanks for the kind invitation. I think I can't help because I just played this package and did nothing more than your great demos. Actually, I still try to figure out how to incorporate this package into my project (also synaptic plasticity-related). I may get some hints from another of your paper and repo (Rapid learning of predictive maps with STDP and theta phase precession)!

By the way, after seeing this package, I'd like to generate some fake data and do simple persistent homology analysis, like Fig. 2b in "The intrinsic attractor manifold and population dynamics of a canonical cognitive circuit across waking and sleep https://doi.org/10.1038/s41593-019-0460-x". Basically, I would just let the agent run in the open field randomly and record HeadDirectionCell or GridCell to see whether they form the ring or torus structure. (Although I am not really familiar with this field and not sure if it'll work or not, just for fun 😅)

How do you feel about this? I may try it on the weekend. If you think it is related to your topic, I can email you the result later!

Best regards, Hsuan-Pei

Tom George @.***> 於 2022年11月8日 週二 凌晨1:18寫道:

Hi there,

Thanks again for you contributions to RatInABox. I was wondering if I could ask you a favour.

I’m putting together a small talk to be given here at UCL and wanted to “showcase” the package being used in the broader science community. Would you have any simple figures, which demonstrate core RiaB functionality, I would be able to put in my slides crediting you of course.

Very much appreciate your help.

Tom

On 27 Oct 2022, at 18:14, PikaPei @.***> wrote:

Yes, it works well now! Thanks for the quick update. I've also made a PR about place_cell_centres.

— Reply to this email directly, view it on GitHub < https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1293832283>, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AJ4G2JOCNWUNY4BIJEJ3MLTWFKZ7HANCNFSM6AAAAAARO2GBME . You are receiving this because you commented.

— Reply to this email directly, view it on GitHub https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1305938421, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGJCWHYBQRE5SOBLKGY5S5TWHE2XBANCNFSM6AAAAAARO2GBME . You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1308014825, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ4G2JJGTORKZJRRSP4FXITWHLUUFANCNFSM6AAAAAARO2GBME. You are receiving this because you modified the open/close state.

PikaPei commented 1 year ago

Hello George,

I'm sorry for the late reply. (There was an emergency initially, but after a while, I felt embarrassed to email back suddenly.)

Anyway, I have to thank you for giving me the entrypoint of your code. Although the paper "the hippocampus as a predictive map" has been published for several years. How to apply TD learning and STDP into this framework is relatively new to me. It's fascinating, and I'll definitely take time to see how you coded it!

In addition, thanks for providing the other two papers about the manifold of the grid cells. Recently, I try to use the firing rate output from HD cells or grid cells, then do the homology analysis & dimension reduction for visualization. If you don't mind, please allow me to share something I did with you!

Last, when I modified the properties of grid cell, I did something to RatInABox: (1) added a line to avoid the error when "random_gridscales": False (2) added a function to make organized phase_offsets I'm not sure whether it should raise an issue or not, so I just mention it here first.

Hope your talk is going well! Hsuan-Pei

Tom George @.***> 於 2022年11月9日 週三 晚上7:38寫道:

This is a great idea. I would be happy to support you if you wanted to make an STDP layer of neurons and add it to RiaB. The best thing would be to build this off “FeedForwardlayer”. You may find some help looking at https://github.com/TomGeorge1234/STDP-SR/blob/main/mazeAgentUtils_reviewResponses.py this code for my other paper (line 508). It’s a bit of a mess but you will see how I sample spikes, update traces and use these to learn weights.

I think your idea about homology would definitely work and I’d love to see it! However for the torus you’d have to be careful to choose fixed grid frequencies (by default they are sampled randomly in RiaB). With fixed frequencies you should find a donut (I assume you are familiar with these two papers https://www.nature.com/articles/s41586-021-04268-7, https://reader.elsevier.com/reader/sd/pii/S0896627322009072?token=A7B5846F0A4A93EF4CB8BDE1AE407BBC155DF0C837099DD10972A5C912E6AC8F1FCD47CF8F55D1C9D72E48D18B5ABA25&originRegion=eu-west-1&originCreation=20221109113712)!

Good luck and let me know if you need help. If you do generate anything interesting I really would love to have a figure to put in my talk. Doesn’t need to be anything complex !

Tom

On 9 Nov 2022, at 00:18, PikaPei @.***> wrote:

Hi George,

Thanks for the kind invitation. I think I can't help because I just played this package and did nothing more than your great demos. Actually, I still try to figure out how to incorporate this package into my project (also synaptic plasticity-related). I may get some hints from another of your paper and repo (Rapid learning of predictive maps with STDP and theta phase precession)!

By the way, after seeing this package, I'd like to generate some fake data and do simple persistent homology analysis, like Fig. 2b in "The intrinsic attractor manifold and population dynamics of a canonical cognitive circuit across waking and sleep https://doi.org/10.1038/s41593-019-0460-x". Basically, I would just let the agent run in the open field randomly and record HeadDirectionCell or GridCell to see whether they form the ring or torus structure. (Although I am not really familiar with this field and not sure if it'll work or not, just for fun 😅)

How do you feel about this? I may try it on the weekend. If you think it is related to your topic, I can email you the result later!

Best regards, Hsuan-Pei

Tom George @.***> 於 2022年11月8日 週二 凌晨1:18寫道:

Hi there,

Thanks again for you contributions to RatInABox. I was wondering if I could ask you a favour.

I’m putting together a small talk to be given here at UCL and wanted to “showcase” the package being used in the broader science community. Would you have any simple figures, which demonstrate core RiaB functionality, I would be able to put in my slides crediting you of course.

Very much appreciate your help.

Tom

On 27 Oct 2022, at 18:14, PikaPei @.***> wrote:

Yes, it works well now! Thanks for the quick update. I've also made a PR about place_cell_centres.

— Reply to this email directly, view it on GitHub <

https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1293832283 , or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AJ4G2JOCNWUNY4BIJEJ3MLTWFKZ7HANCNFSM6AAAAAARO2GBME

. You are receiving this because you commented.

— Reply to this email directly, view it on GitHub < https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1305938421 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AGJCWHYBQRE5SOBLKGY5S5TWHE2XBANCNFSM6AAAAAARO2GBME

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1308014825>, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AJ4G2JJGTORKZJRRSP4FXITWHLUUFANCNFSM6AAAAAARO2GBME . You are receiving this because you modified the open/close state.

— Reply to this email directly, view it on GitHub https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1308621867, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGJCWHYYNNJGSPPLY6OK4DLWHOEMRANCNFSM6AAAAAARO2GBME . You are receiving this because you authored the thread.Message ID: @.***>

TomGeorge1234 commented 1 year ago

Hi Hsuan-Pei,

Great to hear from you, sorry about your emergency!

This is really cool analysis, I’m impressed and happy to hear that head cells and grids cells give ring and torus structure respectively. Unfortunately the image did not send, could you send it separately (then I will include it in my talk which I have not yet given).

I don’t have many ideas, here’s a couple • What 3D dimensionality reduction method did they use in the paper? I suspect PCs won’t work as it’s linear but something non-linear might. • I think you are correct in setting the gridscales and orientations not to be random (like real grids). I think the orientations and scales should all be identical and only the phase offsets change. How big are your grid scales, maybe worth making it smaller than the environment (ie ~0.4m). • What are your boundary conditions, things may be harder if they are periodic as you need to consider how grid cells wrap around so maybe keep them solid for now. • Do you have enough grid cells? I suspect O(100) would be roughly enough.

Please open a pull request for the grid scale bug. I’m happy for the phase offsets to be included if you think it’s simple and necessary, otherwise this is easy enough for users to implement themselves.

Best,

Tom

On 29 Nov 2022, at 19:09, PikaPei @.***> wrote:

Hsuan-Pei

PikaPei commented 1 year ago

Hi George,

Oh, I didn't notice the picture didn't be sent. Here is it!

Just for the record, the followings are some details:

PS. I open the issue to the wrong repo (so stupid...)

Thank you for these suggestions! Hsuan-Pei

Tom George @.***> 於 2022年11月30日 週三 清晨5:58寫道:

Hi Hsuan-Pei,

Great to hear from you, sorry about your emergency!

This is really cool analysis, I’m impressed and happy to hear that head cells and grids cells give ring and torus structure respectively. Unfortunately the image did not send, could you send it separately (then I will include it in my talk which I have not yet given).

I don’t have many ideas, here’s a couple • What 3D dimensionality reduction method did they use in the paper? I suspect PCs won’t work as it’s linear but something non-linear might. • I think you are correct in setting the gridscales and orientations not to be random (like real grids). I think the orientations and scales should all be identical and only the phase offsets change. How big are your grid scales, maybe worth making it smaller than the environment (ie ~0.4m). • What are your boundary conditions, things may be harder if they are periodic as you need to consider how grid cells wrap around so maybe keep them solid for now. • Do you have enough grid cells? I suspect O(100) would be roughly enough.

Please open a pull request for the grid scale bug. I’m happy for the phase offsets to be included if you think it’s simple and necessary, otherwise this is easy enough for users to implement themselves.

Best,

Tom

On 29 Nov 2022, at 19:09, PikaPei @.***> wrote:

Hsuan-Pei

— Reply to this email directly, view it on GitHub https://github.com/TomGeorge1234/RatInABox/issues/5#issuecomment-1331373411, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGJCWH42SBIQ4TQL4BNXEH3WKZ36RANCNFSM6AAAAAARO2GBME . You are receiving this because you authored the thread.Message ID: @.***>