Skip to content

Conversation

@pavi-rajes
Copy link
Collaborator

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.

@pavi-rajes pavi-rajes requested a review from rcanfield2 June 8, 2023 21:35
Comment on lines +244 to +245
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).
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Comment on lines +248 to +249
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).
Copy link
Collaborator

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

Comment on lines +165 to +179
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)
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants