Skip to content
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

Problems understanding how to generate firingRates array (MATLAB) #44

Closed
maristanye opened this issue Dec 1, 2023 · 4 comments
Closed

Comments

@maristanye
Copy link

Dear Dmitry,

thanks for the code and the elife paper on dPCA. I am trying to get started with it for my data set, however I struggle in understanding how to generate the firingRates matrix (despite looking through the demo)

Lets say I have:

N= 30 neurons;
T= A trial length of 60 data points
maxTrialNum= 135.

So e.g. this is represented as a 3D 30x60x135 matrix already in my data structure.

And then I have two different conditions (S) and two different Decisions (D) in my behaviour which are represented as two different 1D 135x1 arrays (with 0 and 1 for right/left stimuli/decisions).

I struggle wrapping my head around how to produce from this your

firingRates: N x S x D x T x maxTrialNum

data structure to get started with the dPCA (should it end up being a 30x2x2x60x135 array?). I guess my head stops working at 3 dimensions.
Anyhow thanks a lot for the tool and have a nice weekend,
Eduardo

@dkobak
Copy link
Collaborator

dkobak commented Dec 1, 2023

Dear Eduardo,

it's been a while since I worked with Matlab... In Python this would look something like this:

import numpy as np

X = np.random.randn(30, 60, 135)
S = np.random.randint(2, size=135)
D = np.random.randint(2, size=135)

firingRates = np.zeros((30, 2, 2, 60, 135)) * np.nan

maxTrialNum = 0

for s in (0, 1):
    for d in (0, 1):
        trials = (S == s) & (D == d)
        firingRates[:, s, t, :, :np.sum(trials)] = X[:, :, trials]
        
        if np.sum(trials) > maxTrialNum:
            maxTrialNum = np.sum(trials)
            
firingRates = firingRates[:, :, :, :, :maxTrialNum]

Does this help?

@maristanye
Copy link
Author

Dear dkobak,

thanks a lot for the help and sorry for the late reply. Yes that was very helpful and I was able to run the analysis. I have one more question. Can I combinedata from different imaging sessions from different neurons in this analysis? An example:

Day1:
N= 42 neurons;
T= A trial length of 60 data points
Trials= 48.
->42x60x48
Day2:
N= 28 neurons;
T= A trial length of 60 data points
Trials= 52.
->28x60x52

would the resulting firingRates be a 70x2x2x60xmaxTrialNum where some of the values in the 1D (70 neurons =42neurons[day1]+28neurons[day2]) are NaNs depending if it is data from the corresponding session or not?

Cheers,
Eduardo

@dkobak
Copy link
Collaborator

dkobak commented Dec 13, 2023

Yes you can combine data from different sessions. All datasets analyzed in our eLife paper were constructed like that (from recordings obtained over many sessions).

You have two arrays, 42 x 60 x 48 and 28 x 60 x 52. You can rearrange both as I explained earlier, so they will become 42 x 2 x 2 x 60 x maxTrialNum1 and 28 x 2 x 2 x 60 x maxTrialNum2. To combine, find maxTrialNum = max(maxTrialNum1, maxTrialNum2) and pad one of the arrays with nans along the 5th dimension so that the arrays become 42 x 2 x 2 x 60 x maxTrialNum and 28 x 2 x 2 x 60 x maxTrialNum. Now you can concatenate along the 1st dimension, to get 70 x 2 x 2 x 60 x maxTrialNum.

@maristanye
Copy link
Author

yes, thanks, thats what I just figured out. I wrote a MATLAB function to do these steps and generate firingRates and trialNum. Let me know if you are interested.

Thanks a lot again,
Eduardo

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

No branches or pull requests

2 participants