Figures and data
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig1.tif/full/max/0/default.jpg)
Overview of the Constrained Subspace Variational Autoencoder (CS-VAE). The latent space is divided in three parts: (1) the supervised latents decode the labeled body positions, (2) the unsupervised latents model the individual’s behavior that is not explained by the supervised latents, and (3) the constrained subspace latents model the continuously varying features of the image, e.g., relating to multi-subject or social behavior. After training the network, the generated latents can be applied to several downstream tasks. Here we show two example tasks: (1) Motif generation: we apply state space models such as hidden Markov models (HMM) and switched linear dynamical systems (SLDS), with the behavioral latent variables as the observations; (2) Neural decoding: with neural recordings such as widefield calcium imaging, corresponding behaviors can be efficiently predicted for novel subjects.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig2.tif/full/max/0/default.jpg)
(A) Simulated dataset: behavioral videos from one mouse with artificially simulated differences in contrast. (B) Distribution occupied by the 3 CS latents.The constrained latents are distributed according to the pre-defined prior: a Swiss roll distribution. Different contrast ratios separate well in space. (C) Left: R2 values for label reconstruction; Right: visualization of label reconstruction for an example trial. Latent traversals for (D) CS latents, each of which captures lower, medium, and higher contrast rate. (E) An example supervised latent captures lever movement, and (F) an example unsupervised latent which captures jaw movement.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig3.tif/full/max/0/default.jpg)
Modeling the behavior of four different mice. A. Image reconstruction result for an example frame from each mouse. B. Label reconstruction result for an example trial. C. R2 value for label reconstruction for all mice. D. (Left) CS latent and (Right) unsupervised latent distributions for all mice generated using our CS-VAE model. On the left, we see that the CS latent distribution follows the pre-defined prior distribution and is well separated; on the right, we see that the unsupervised latent distribution is well overlapped across mice. E. Unsupervised latent distribution for all mice generated using the comparison PS-VAE model, where the latents from different mice are separate from each other. F. SVM classification accuracy for classifying different mice using the CS-VAE and PS-VAE latents. The unsupervised latents generated by the CS-VAE has low classification accuracy, indicating across-subject representations, and the CS latents have a classification accuracy close to one, indicating good separation.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig4.tif/full/max/0/default.jpg)
Latent traversals for behavioral modeling of four different mice for A. an example supervised latent that captures the left spout across all the subjects, B. an example unsupervised latent that captures the chest of the mice, and C. an example CS latent that successfully captures the mouse appearance. D. Changing the value of the CS latent in an example frame leads to a change in subject, while keeping the same action as in the example frame.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig5.tif/full/max/0/default.jpg)
Motif generation for across-subject (supervised and unsupervised) behavioral latents using CS-VAE. SLDS results for CS-VAE latents: A. Supervised latents relating to equipment in the field of view. The equipment actions are similar for each trial. B. Supervised latents relating to tracked body parts. The ethograms for each trial across subjects and between subjects are very similar. The histogram indicates the number of frames occupied by each action per mouse. This further confirms the similarities between the supervised latents across subjects. C. Unsupervised latents also look similar across mice. Here, some example consecutive frames from the ‘raise pow’ motif are shown, which show the mouse grooming. D. As a comparison, SLDS results for the latents generated by a VAE, which failed to produce across-subject motifs.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig6.tif/full/max/0/default.jpg)
A. Transfer learning model framework. Each of the four mice has a specific dense layer for aligning the neural activities. After the model is trained using three mice, the across-subject Recurrent Neural Network (RNN) layer is fixed and transferred to the fourth mouse. As a comparison, we trained a novel RNN model for the fourth mouse and compared the accuracy with the transfer learning model B. R2 and training time trade-off for individual vs. transfer learning model as the size of the training set decreases. As the training set decreases, the transfer learning has a better performance than the individually trained model with regards to both time and R2 accuracy.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig7.tif/full/max/0/default.jpg)
A.The overall workflow for comparing the neural activities for different subjects performing similar spontaneous behaviors: First, the behavioral videos are encoded into behavior latents by CS-VAE. Then, the behavior latents would be clustered into different motifs. After that, similar behaviors are grouped based on their mean and standard deviation values. We can therefore obtain the corresponding neural activities. Finally, the neural activities from different subjects are aligned using the MCCA. B. Behavior latents are cut into small fragments. Similar behavior fragments are grouped together based on their mean and standard deviation values. The corresponding neural activities are obtained based on the grouping results of the behavior. C. Neural activities are being aligned using MCCA. MCCA aligns the neural activities from different subjects by mapping them into the same feature spaces. D. Correlation score for behavioral-based aligned neural activity. The grooming behavior has higher neural correlation scores for cross-subjects than other behaviors.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig8.tif/full/max/0/default.jpg)
A. Image alignment for the social behavior data. B. Model performance on the social behavior dataset. C. Visualization of the CS latents overlaid with the nose-to-tail distance between the two interacting mice. The CS latents separates the frames that contain social interactions from those that do not.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig9.tif/full/max/0/default.jpg)
A. Ethogram for the animals’ behavior recovered using hidden Markov models (HMM) applied to the CS latents. B. Different metrics for analysing the behavioral motifs. Here, the three motifs are a. social interaction; b. non-social interaction with the companion on the upper side of the aligned mouse; c. non-social interaction (the aligned mouse exploring the environment with its companion far away). These metrics show the quantitative differences between the different motifs.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_eqn1.gif/full/max/0/default.jpg)
DCS(p1, p2) equals zero if and only if the two distributions p1(x) and p2(x) are the same. By applying the Parzen window estimation technique to p1(x) and p2(x), we get the entropy form of the Equation [11]:
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_tbl1.tif/full/max/0/default.jpg)
Comparison of different models on the freely-moving social behavior dataset
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_tbl2.tif/full/max/0/default.jpg)
Hyperparameter for different dataset
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_tbl3.tif/full/max/0/default.jpg)
Latent dimensions and the prior distribution for different dataset
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_tbl4.tif/full/max/0/default.jpg)
Training size vs R2 value for multi-subject dataset
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig10.tif/full/max/0/default.jpg)
Loss curve for A. training the multi-subject dataset B. training the freely behaving dataset with the specified hyperparameters as in Tables 1 and 2.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig11.tif/full/max/0/default.jpg)
Latent traversals for the multi-subject dataset for the four mice with the same base image A. an example supervised latent, B. an example unsupervised latent, and C. an example CS latent. We see that the same base image (Mouse 3) is transformed into a different mouse each time when changing the CS latent.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig12.tif/full/max/0/default.jpg)
Latent traversals on the CS-latents for the freely-moving social behavior dataset. We see that the latents all encode for social interactions between the two mice.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_fig13.tif/full/max/0/default.jpg)
Neural decoding for CS-VAE vs. PS-VAE.
![](https://prod--epp.elifesciences.org/iiif/2/88602%2Fv1%2Fcontent%2F506091v2_tbl5.tif/full/max/0/default.jpg)
Training size vs time usage for multi-subject dataset