Seeking Clarification on Calculation Details in local_correlations
#1190
-
Hi Caiman developers and community, I hope this message finds you all well! Firstly, I want to extend my appreciation to all the contributors of the Caiman project. Having discovered the project late last week, I've spent the whole week working with the tools and studying the theory supporting them, which has been both helpful and interesting. Recently, while delving into the In the process of calculating correlations with diagonal neighbors, two matrices, Here's a succinct breakdown of my observation and queries: Matrix
Matrix
In summary, with the current method, for a point
In essence, whilst the existing schema does correlate the reference point with its upper-right and lower-right neighbors, it seems to simultaneously correlate two pairs of its immediate neighbors (top-and-left pair and bottom-and-left pair) rather than the reference point with all four diagonal directions, which, if my understanding serves me correctly, was the intent behind the implementation. Please do enlighten me if there's something I might have misunderstood or overlooked. I'm eager to learn more about the inner workings of Caiman and to contribute in any way that I can. Thank you so much for your time and for fostering such a collaborative environment within the Caiman community. I'm looking forward to your insights. Sincerely, Robert Alfredson |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
@rcalfredson thanks for the question. I have to admit I haven't dug into the details of this function. It definitely seems worth taking some time to work through it as you are doing. At best we should better document this function. I would need to take some time to work through this before I have a reply. @j-friedrich not sure if you have any thoughts here. I should add that |
Beta Was this translation helpful? Give feedback.
-
@rcalfredson you are correct, Here the corrected code:
|
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for noticing this @rcalfredson and for checking in on it @j-friedrich . I will do a PR on it, and add a test! |
Beta Was this translation helpful? Give feedback.
-
Thank you both for being so responsive to my message- it’s much appreciated! I will also try the FFT variant as well of the local correlation calculation- had missed that one before. |
Beta Was this translation helpful? Give feedback.
@rcalfredson you are correct,$\rho_{d1}$ and $\rho_{d2}$ need to be swapped in lines 257 and 259. Thanks for the heads up. I personally use a PyTorch version of this function (it's ~10x faster on GPU than either of the CaImAn implementations) but haven't yet noticed the bug. If you run the corrected
local_correlations
andlocal_correlations_fft
you'll see that the results now agree within numerical precision. (Someone with time on their hands could add this as a unit test)Here the corrected code: