-
Notifications
You must be signed in to change notification settings - Fork 0
Code for align dynamics using CCA #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| La (ndarray): Latent dynamics of Dataset A with shape (m, n_timepoints). Usually first dimension is time, however Juancho's code has it as (m, n_t). Keeping it similar to his paper is easier for the computations below. | ||
| Lb (ndarray): Latent dynamics of Dataset B with shape (m, n_timepoints). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to make things consistent for aopy we should keep the input data shapes the same other functions with time as the first dimension. Then the first couple lines in the function can transpose them and the transposed variables can be used throughout the rest of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, should the input data be raw neural data or data projected into a lower dimensional latent space?
| CCs_unaligned (ndarray): Pairwise Pearson correlation between unaligned latent dynamics (La and Lb) with shape (m). | ||
| CCs_aligned (ndarray): Pairwise Pearson correlation between aligned latent dynamics (La_tilde and Lb_tilde) with shape (m). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also include the optional return args
| def test_align_latent_dynamics_samedata(self): | ||
|
|
||
| np.random.seed(42) | ||
| La = np.random.rand(1000, 10).T | ||
| Lb = La.copy() | ||
|
|
||
| # Call the align_latent_dynamics function | ||
| CCs_unaligned, CCs_aligned = aopy.analysis.align_latent_dynamics(La, Lb, False) | ||
|
|
||
| # Assert the shapes of the computed correlations | ||
| assert CCs_unaligned.shape == (10,) | ||
| assert CCs_aligned.shape == (10,) | ||
|
|
||
| # Assert that the pairwise correlation for aligned dynamics is approximately 0.99 | ||
| assert np.allclose(CCs_aligned, 0.99, atol=0.01) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have a similar test with orthogonal data. I'm not exactly sure how to do this but maybe you run PCA on a dataset. Then, for La project data onto a few of the PCs, and for Lb project data onto the remaining PCs.
I implemented align dyanmics using CCA from scratch based on Galeego 2020 Long term stability of cortical dynamics paper. Please review and let me know if any other comments or tests would be helpful.