Example 2: Extract single-trial neural trajectories from raw spike trains


This video walks through the steps of inputting raw spike trains into DimReduce, preprocessing the spike trains, performing dimensionality reduction, and automatically uploading the extracted single-trial neural trajectories for visualization in DataHigh.



Download video



Detailed Step-by-step tutorial


The same tutorial can be found in the DataHigh User Guide .pdf in the main folder of the DataHigh software package. It corresponds to ex2_dimreduce.m in /DataHigh/examples/.

1.

Navigate to the examples folder in the main DataHigh directory. Enter ex2_dimreduce into the Matlab command console to input raw spike trains into DimReduce. The example dataset contains two different experimental conditions. Each condition has 56 trials, and each trial has spike trains from 61 neurons. Each spike train has a length between 1018ms and 1526ms and binned at 1ms resolution.

2.

The DimReduce figure will pop up. The top right corner has Next Step instructions, so that the user can walk through the steps of performing dimensionality reduction. Note that clicking Next Step will move the large red number to the next location where a choice is needed by the user. Each option also has a ? button nearby to provide more information about that step.

3.

For this example dataset, in the time bin width box, enter 20ms (if not there by default). The "Type" will read "Trajs" for neural trajectories. DimReduce will take 20ms non-overlapping bins over the raw spike trains. We recommend that you start with 20ms bins, as we have found this to work well with population activity recorded in the motor and visual cortices.

4.

For the mean spikes/sec threshold, enter 1.0 spike/sec. DataHigh removes 3 neurons from the analyses. Neurons with firing rates less than 1 spike/sec can sometimes be problematic, so so we leave them out. Leave the "Trial-averaged neural trajs" box unchecked.

5.

Under Method, choose "GPFA" for Gaussian Process Factor Analysis. GPFA reduces the high-dimensional population activity to a smaller number of latent variables that vary smoothly over time, where the amount of smoothing is determined by the data.

6.

GPFA typically takes less than a minute to fit to data from tens of neurons and hundreds of trials. However, when we do cross-validation, we may need to fit GPFA hundreds of times (depending on the number of candidate dimensionalities and cross-validation folds). For the purposes of visualization, we can avoid the long wait by fitting a GPFA model with a large number of dimensions, looking at the parameters returned by the fitting procedure, and removing the dimensions that appear to not be needed. Slide the Select dimensionality scrollbar to 40. Click Upload Results, which performs dimensionality reduction for the selected dimensionality. A progress bar pops up. It should take about 30 seconds to fit the parameters and extract the neural trajectories.

7.

After the progress bar finishes, the PostDimreduce figure then pops up. We will now decide how many of the 40 dimensions are actually needed to describe the data.

8.

Click View Loading Matrix. The loading matrix defines the linear mapping between latent variables (columns) and the neural activity (rows). Check to see whether any of the columns of the loading matrix show contributions from only a small number (e.g., 2 or 3) of neurons. This indicates that the spike counts for those neurons are highly correlated, which could be an indication of electrode cross-talk. Under normal conditions, we expect each column to have contributions from many of the neurons, which is the case here. Close the figure.

9.

Click the View Each Dim button. DimReduce automatically orthonormalized the latent variables, and ordered them based on the amount of variability they explain. In the SingleDim figure, you can see each latent variable plotted individually. Each trace corresponds to a single trial. Click the Next button to scan through the latent variables. As you scan, you will notice that past a certain latent variable, the neural trajectories do not vary across time or experimental condition. These latent variables are not contributing much to describing the data, and will be removed for visualization. Close the SingleDim figure.

10.

Click the Eigenspectrum button. This plots the cumulative percent shared variance explained by the number of latent variables. A good selection of the dimensionality would explain around 90% of the shared variance and have temporal fluctuations for each single dimension. However, the selection can be subjective, unlike the optimal dimensionality identified with cross-validation. Close the Eigenspectrum figure.

11.

In the Select final dimensionality menu list, select a dimensionality of 15. DimReduce will remove latent variables 16 through 40 from the analyses, and keep the top fifteen latent variables. Thus, we reduced the original 58-d space to 15 dimensions. Click Upload to DataHigh. The DataHigh interface fills the screen.



      Visualize single-trial neural trajectories in DataHigh

      Return to Tutorial Videos

      Return to the DataHigh main page