Title: Extraction and Recovery of Spatio-Temporal Structure in Latent Dynamics Alignment with Diffusion Models
Venue: NeurIPS 2023
Accepted: yes
Keywords: Neural distribution alignment

Diffusion model

Neuroscience

Neural decoding
Abstract: In the field of behavior-related brain computation, it is necessary to align raw neural signals against the drastic domain shift among them. A foundational framework within neuroscience research posits that trial-based neural population activities rely on low-dimensional latent dynamics, thus focusing on the latter greatly facilitates the alignment procedure. Despite this field's progress, existing methods ignore the intrinsic spatio-temporal structure during the alignment phase. Hence, their solutions usually lead to poor quality in latent dynamics structures and overall performance. To tackle this problem, we propose an alignment method ERDiff, which leverages the expressivity of the diffusion model to preserve the spatio-temporal structure of latent dynamics. Specifically, the latent dynamics structures of the source domain are first extracted by a diffusion model. Then, under the guidance of this diffusion model, such structures are well-recovered through a maximum likelihood alignment procedure in the target domain. We first demonstrate the effectiveness of our proposed method on a synthetic dataset. Then, when applied to neural recordings from the non-human primate motor cortex, under both cross-day and inter-subject settings, our method consistently manifests its capability of preserving the spatio-temporal structure of latent dynamics and outperforms existing approaches in alignment goodness-of-fit and neural decoding performance.

Extraction and Recovery of Spatio-Temporal Structure in Latent Dynamics Alignment with Diffusion Models

Abstract

In the field of behavior-related brain computation, it is necessary to align raw neural signals against the drastic domain shift among them. A foundational framework within neuroscience research posits that trial-based neural population activities rely on low-dimensional latent dynamics, thus focusing on the latter greatly facilitates the alignment procedure. Despite this field's progress, existing methods ignore the intrinsic spatio-temporal structure during the alignment phase. Hence, their solutions usually lead to poor quality in latent dynamics structures and overall performance. To tackle this problem, we propose an alignment method ERDiff, which leverages the expressivity of the diffusion model to preserve the spatiotemporal structure of latent dynamics. Specifically, the latent dynamics structures of the source domain are first extracted by a diffusion model. Then, under the guidance of this diffusion model, such structures are well-recovered through a maximum likelihood alignment procedure in the target domain. We first demonstrate the effectiveness of our proposed method on a synthetic dataset. Then, when applied to neural recordings from the non-human primate motor cortex, under both crossday and inter-subject settings, our method consistently manifests its capability of preserving the spatio-temporal structure of latent dynamics and outperforms existing approaches in alignment goodness-of-fit and neural decoding performance. Codes are available at: https://github.com/alexwangNTL/ERDiff .

1 Introduction

A key challenge severely impeding the scalability of behavior-related neural computational applications is their robustness to the distribution shift of neural recordings over time and subjects [1]. Given a behavior model trained on previous neural recordings (e.g., velocity predictor for human with paralysis [2]), it usually suffers performance degradation when applied to new neural recordings due to the neural distribution shift [3, 4]. Thus, for long-term usability and stable performance of the trained neural decoding model, high-quality alignment between the neural recordings used for training (i.e., source domain) and new recordings for testing (i.e., target domain) is of vital importance.

Distribution alignment is an important task at the heart of unsupervised transfer learning [5, 6]. The goal is to align the target domain to the source domain so that the trained model in the source domain can be applied to the target domain after eliminating the distribution shift. However, due to issues such as instabilities and low signal-to-noise ratio [7], raw neural spiking activities are noisy and ambiguous [8, 9], causing difficulties in aligning the distributions of these high-dimensional signals directly.

One promising research direction [10] points out that the trial-based neural activities can always be understood in terms of low-dimensional latent dynamics [11, 12, 13]. Such latent dynamics manifest coordinated patterns of evolution constrained to certain "neural manifolds" [14, 15]. Hence, early studies focusing on the alignment of latent dynamics reach comparably satisfactory results [16, 17]. Generally, most previous methods [16, 18, 19] are based on a pre-defined metric for optimization during latent dynamics alignment, i.e., minimizing the difference evaluated by the metric, between source and target domains within the low-dimensional latent space. However, those metrics are usually non-parametric and handcrafted, which are not guaranteed to suit specific neural recordings or problems well. Methods based on adversarial-learning [20, 21] thus have been introduced since they can implicitly find an adapted metric [22]. However, they suffer from mode collapse and instability issues in practice [23].

Moreover, during the alignment process, we note that the above-mentioned works lack the necessary awareness of the latent dynamics structure, especially when aligning non-linear and lengthy trials. Through an empirical study on the motor cortex of non-human primate (NHP) [8] (shown in Figure 1), we can observe that: a state-of-the-art alignment method JSDM [24] (minimizing the symmetric Jensen-Shannon divergence between distributions) fails to recover the latent dynamics structures of the source domain since JSDM neglects those structures during alignment. From another perspective, in the alignment phase, existing methods fail to effectively model and leverage the information-rich correlations between each time bin and each latent dimension within latent dynamics.

In this paper, we focus on preserving the temporal evolution of each individual latent dimension and the spatial covariation between latent dimensions of the source domain during alignment. The main idea is that we first extract the spatio-temporal structure of latent dynamics from the source domain; and then, we align the target domain by recovering the source domain's underlying structure. However, such a workflow is non-trivial since the underlying spatio-temporal structure is both implicit and complex.

To tackle this problem, we propose a novel alignment method that is capable of E xtracting and R ecovering the latent dynamics structure with Diff usion model (ERDiff). Firstly, given the source-domain neural observations, we use a diffusion model (DM) [25, 26] to extract the spatiotemporal structure of latent dynamics. Then, in the alignment phase, we propose a maximum likelihood alignment procedure through the guidance of DM, by which the spatio-temporal structure of source-domain latent dynamics can be recovered well in the target domain. The proposed extract-and-recover method nicely encodes and preserves the spatio-temporal structure of latent dynamics, which are significant inductive biases for neural latent dynamics alignment. Furthermore, from the perspective

Spatio-temporal

Structure

Source

JSDM Aligned

Spatio-temporal

of core machine learning, ERDiff introduces an approach of extracting structure knowledge from one distribution and imposing it as the prior to constrain the alignment of another distribution. Note that although we have been emphasizing extraction and recovery of the source-domain structure, ERDiff is not performing a copy-and-paste of the source domain distribution to the target domain. As ERDiff preserves the dynamics structure of the source domain, it also maintains the original characteristics of the target domain. We present experimental results to support this argument. Finally, we conduct extensive experiments to verify the effectiveness of ERDiff on a synthetic dataset and two real-world neural datasets [8, 27]. Visualization of latent dynamics also demonstrates that ERDiff is capable of preserving the spatio-temporal structure consistently during the alignment phase.

2 Preliminary

Distribution alignment. We denote the source-domain observations of single-trial neural population activities as X ( s ) = [ x ( s ) 1 , . . . , x ( s ) l ] ⊤ ∈ R l × n , where l is the trial length ( i.e. , number of time bins), and n is the number of observed neurons. We denote its low-dimensional latent dynamics as Z ( s ) = [ z ( s ) 1 , . . . , z ( s ) l ] ⊤ ∈ R l × d , where d is the latent dimension size. Generally, we build a variational autoencoder (VAE) to estimate the latent Z ( s ) given the observations X ( s ) . The VAE

consists of a probabilistic encoder q ( Z ( s ) | X ( s ) ; ϕ s ) and a probabilistic decoder p ( X ( s ) | Z ( s ) , ψ s ) . ϕ s and ψ s are the parameters of the encoder and decoder. The encoder also serves as an approximated posterior distribution to the intractable true posterior p ( Z ( s ) | X ( s ) ) . Then in the target domain, given the neural population activities X ( t ) = [ x ( t ) 1 , . . . , x ( t ) l ] ⊤ ∈ R l × n , we perform distribution alignment by linear probing the probabilistic encoder q ( Z | X ; ϕ ) . This alignment phase is conducted by minimizing certain probability divergence D ( · | · ) between the two posterior distributions:

Diffusion (probabilistic) model (DM). Given l × d -dimensional i.i.d. samples Z from an unknown data distribution, a DM [28] aims to approximate such distribution by fitting the parameters of a neural network p θ ( Z ) . DMis composed of a forward process followed by a reverse process . In the forward process , isotropic Gaussian noise is added to diffuse the original data, which can be defined in a linear stochastic differential equation (SDE) form:

where f ( · ) : R l × d × R ↦→ R l × d is the drift coefficient, g ( · ) : R ↦→ R is the diffusion coefficient, and w is the standard Wiener process. The solution of the SDE is a diffusion process { Z t } t ∈ [0 ,T ] , in which [0 , T ] is a fixed time zone. In this paper, we implement them with VP-SDE [25]. { Z t } t ∈ [0 ,T ] approaches the standard normal prior distribution π ( Z ) when t = T . Under mild conditions on drift and diffusion coefficients [25], the denoising reverse process can be solved in the following closed-form SDE:

where ∇ Z log p t ( Z ) is the score function, and w is a reverse-time Wiener process. We train a parameterized network s ( Z , t ; θ ) to fit the score function ∇ Z log p t ( Z ) . However, ∇ Z log p t ( Z ) is not directly accessible and we resort to the denoising score matching (DSM) [29] for optimization:

where U represents the uniform distribution and λ ( t ) is the weighting function. Under VP-SDE, the transition probability p 0 t ( Z t | Z 0 ) also follows a Gaussian distribution N ( µ t Z 0 , Σ t ) , in which µ t , Σ t ∈ R l × d . On the other hand, according to [28], we can define a noise estimator with the score function as ϵ ( Z t , t ; θ ) = -K -T t s ( Z t , t ; θ ) , in which K t K T t = Σ t . Invoking these expressions, we can thus reformulate the form of DSM loss based on the Fisher Divergence between noise terms:

in which w ( t ) = K t λ ( t ) and Z t = µ t Z 0 + K t ϵ .

3 Methodology

In this section, we introduce our proposed latent dynamics alignment method ERDiff in detail.

3.1 Maximum likelihood alignment

Given the source-domain neural activities X ( s ) , we infer their latent dynamics Z ( s ) by building a V AE. We use variational inference to find the probabilistic encoder q ( Z ( s ) | X ( s ) ; ϕ s ) and probabilistic decoder p ( X ( s ) | Z ( s ) ; ψ s ) through maximization of the evidence lower bound (ELBO) [30]:

in which ¯ q ( Z ( s ) ) is the normal prior. Note that we introduce ERDiff with this basic V AE architecture. But ERDiff can be combined with many variants of latent variable models (LVM) [31, 32]. The essence of ERDiff is to tune the parameter set ϕ of the probabilistic encoder, regardless of the model architecture of the encoder and decoder.

(B)

(A)

x k

ST Block

Spatio

Temporal

/epsilon1

θ

Source Latent

Dynamics

Extracted Spatio-

Temporal Structure

Unaligned Latent

Dynamics

Structure-aware

MLA Guidance

Source-Domain

Target-Domain

Extraction

Recovery

Practically, alignment methods that directly match the discrete samples from the source and target domains in a pair-wise fashion may lead to sub-optimal solutions [33, 34], especially when the collected samples from the target domain are limited. Thus given the target-domain neural activity X ( t ) , we propose to perform neural distribution alignment via maximum likelihood estimation (MLE):

in which p s ( Z ) represents the ground-truth probabilistic density of latent dynamics in the source domain and h ( · ) refers to the non-linear transformation from X to Z underlying the probabilistic encoder q ( Z | X ; ϕ ) . The objective in Eq. 7 implies that, instead of minimizing a distance metric between source observations and target observations, we aim at maximizing the likelihood where the density comes from the source domain and the data comes from the target domain. The left-hand-side (LHS) is the MLE for observation X and the right-hand-side (RHS) is the MLE for latent Z . We will focus on the RHS in the following sections. We note that the RHS objective implies that we will optimize the encoder parameter ϕ during alignment so that the latent encoder will map X ( t ) to a proper latent Z ( t ) who fits the source density p s ( Z ) well.

3.2 Spatio-temporal structure extraction and source domain learning

In order to calculate the objective function in Eq. 7, we need to know two density functions: q ( Z | X ; ϕ ) is defined in the original V AE model with the learnable parameter ϕ ; p s ( Z ) is the density of latent Z for the source domain. The latter is inaccessible by building a V AE alone. Therefore, the first step is to learn p s ( Z ) given only X ( s ) . We propose to learn p s ( Z ) through training a DM.

To fully capture p s ( Z ) , the DM should consider the overall spatio-temporal structure of latent dynamics. To extract such a structure, the DM can not treat each latent state or time bin within latent dynamics as mutually independent and feed them into the model sequentially. We thus take the entire trial of latent dynamics Z ( s ) 0 ∼ q ( · | X ( s ) ; ϕ s ) as input to the DM for training. Specifically, the DM fits p s ( Z ) through the training of a denoiser ϵ ( Z , t ; θ s ) : ( R l × d × R ) → R l × d .

Next, we describe the architecture of ϵ ( Z , t ; θ s ) , which is refined for extracting the global spatiotemporal structure of latent dynamics. Traditional architecture based on 2D-Convolution Layers [35] focuses on capturing the local features within latent dynamics, which can hardly extract its global spatio-temporal dependency or structure. Thus, we adopt an architecture mainly derived from Diffusion Transformer (DiT) [36, 37]. Specifically, we propose to use S patioT emporal Transformer Block (STBlock), shown in Figure 2(A). Each STBlock is composed of a Spatio Transformer layer followed by a Temporal Transformer layer, which are 1-layer encoders based on multi-head selfattention. The Spatio Transformer layer takes latent states of each time bin as inputs to extract spatial structure, whereas the Temporal Transformer layer takes the entire latent trajectory of each latent space dimension as inputs to extract temporal structure. (see Appendix A for details of the architecture of DM).

For the training objective of ϵ ( · ; θ s ) , we sample noisy targets Z ( s ) t and minimize the following DSM loss function:

We note that Z ( s ) 0 here are actually latent dynamics inferred via V AE in Eq. 6. To enrich the input samples and adequately estimate the source density p s ( Z ) as motivated earlier, we propose to learn the VAE objective (Eq. 6) and the diffusion objective (Eq. 8) simultaneously. In each training iteration, conditioning on the current value of ϕ s and ψ s , we obtain a set of Z 0 = h ( X ( s ) ; ϕ s ) and use it as Z ( s ) 0 to optimize Eq. 8. We can also optimize VAE first, obtain an optimal ϕ s , and use it to optimize Eq. 8. Experimental results show that the former approach achieves higher density estimation performance compared to the latter (see Appendix A for details).

3.3 Spatio-temporal structure recovery and distribution alignment

Given the trained denoiser ϵ ( Z , t ; θ s ) , we go through the reverse process from t = T to t = 0 in Eq.(3) and obtain the marginal distribution p 0 ( Z ; θ s ) . We use p 0 ( Z ; θ s ) to approximate p s ( Z ) in Eq. (7). The maximum likelihood estimation can thus be written as

We perform alignment by tuning the parameter set ϕ of the probabilistic encoder while keeping the DM p 0 ( Z ; θ s ) fixed. Note that we have already optimized the VAE objective to obtain an optimal ϕ s using source data. During alignment, we first set ϕ as ϕ s and then linear probe ϕ (e.g., neural observation read-in layer). Consequently, we not only initialize the model with a good encoder but also make optimization during alignment much faster and more efficient.

In the reverse process, the computation of log p 0 ( Z ; θ s ) is tractable through the probability flow ODE [25] whose marginal distribution at each time step t matches that of our VP-SDE. However, the direct computation of log p 0 ( Z ; θ s ) will require invoking the ODE solver in each intermediate time step [38, 39]. Such complexity is prohibitively costly for online neural applications. To circumvent this issue, we can reform Eq. (9) as follows:

where the first term is the KL divergence from the DM marginal distribution p 0 ( Z ; θ s ) to the probabilistic encoder distribution q ( Z | X ( t ) ; ϕ ) , and the second term H ( · ) denotes the differential entropy. For the D KL ( · ) term in Eq. (10), via the Girsanov theorem [40, 41], we have

where L DSM is the denoising score matching loss in Eq. (5), and p T ( · ) is the distribution at final time step T of Eq. (2). Consequently, we could obtain an upper bound of the maximum likelihood objective, as follows (we provide detailed derivation in Appendix B):

Since π ( Z ) is a fixed prior distribution, it does not depend on parameter ϕ . Thus, our optimization objective will include only the latter two terms, which are more computationally tractable. The first objective simplifies to a weighted noise residual for the parameter set ϕ and the second divergence objective can be approximated using the Hutchinson-Skilling trace estimator [42]. We note that the recovery of spatio-temporal structure is primarily conducted by the weighted noise residual part, in which the probabilistic encoder obtains alignment guidance in awareness of the spatio-temporal structure from ϵ ( Z , t ; θ s ) . This procedure is illustrated in Figure 2(B).

In distribution alignment, it is a common practice to directly leverage the ground-truth data samples by introducing a regularizer term in the optimization function. To encourage the diversity of latent dynamics after alignment, here we further compute and penalize the Sinkhorn Divergence [43] between the latent dynamics samples of source domain Z ( s ) ∼ q ( · | X ( s ) ; ϕ s ) and that of target domain Z ( t ) ∼ q ( · | X ( t ) ; ϕ ) :

where each value C [ i ][ j ] = ∥ ∥ ∥ Z ( s ) i -Z ( t ) j ∥ ∥ ∥ 2 2 in matrix C denotes the squared Euclidean cost to move a probability mass from Z ( s ) i to Z ( t ) j , and H ( γ ) computes the entropy of transport plan γ . The total loss for distribution alignment is composed of the term in (13) and the latter two terms on the right side of (12). We note that the total loss is minimized only with respect to the probabilistic encoder parameter set ϕ . (see Appendix C for the total loss formula and the detailed algorithm of ERDiff.)

4 Experiments

Datasets. We first train and evaluate ERDiff with a synthetic dataset. Then we apply ERDiff to a non-human primate (NHP) dataset with neural recordings from the primary motor cortex (M1), in which the primates are performing a center-out reaching task in 8 different directions. The NHP dataset contains rich cross-day and inter-subject settings that provide us with an ideal test bed.

Baselines for comparison. We compare ERDiff against the following two strong baselines proposed for the neural distribution alignment task:

JSDM [24]: a metric-based method that leverages discrete samples from both the source and target domains. The alignment is performed through the symmetric Jensen-Shannon divergence [44].

Cycle-GAN [21]: a state-of-the-art GAN-based method that uses cycle-consistent adversarial networks to align the distributions of latent dynamics.

Considering the neural observations and latent dynamics are in the format of multi-variate time series, we also compare ERDiff with the following methods aiming at distribution alignment for general time series data:

SASA [45]: a metric-based distribution alignment method for time series data regression task through the extraction of domain-invariant representation.

DANN [46]: an adversarial learning framework in which a domain classifier is followed by a feature extractor through a gradient reversal layer. This layer adjusts the gradient by multiplying it with a predefined negative constant during the training process.

RDA-MMD [47]: a distribution alignment method via minimizing MMD Loss between the latent dynamics extracted from LSTM.

DAF [48]: an adversarial learning framework that uses a transformer-based shared module with a domain discriminator. During the adaptation step, the domain-invariant features are invariant ( Q , K of self-attention); the domain-specific features ( V of self-attention) keep tuning.

4.1 Synthetic dataset

Data synthesis and evaluation metrics. We first generate a simulated latent dynamics dataset to illustrate the effect of our ERDiff method on spatio-temporal structure-preserving and distribution alignment performance. In this setting, we consider modeling the nonlinear latent dynamics to follow conditionally Continuous Bernoulli (CB) [49] distribution. For each single-trial latent dynamics, we generate 2 -dimensional latent variables Z = { z 1: L } and their 32 -dimensional observations X = { x 1: L } , where L = 32 . We use the following synthesis process and parameter settings to generate samples for the source and target domains, respectively:

where l ∈ { 1 , . . . , L } , and { W ( s ) , R ( s ) } , { W ( t ) , R ( t ) } are the specific parameter sets of the source and target domains. To compare and evaluate the latent dynamics alignment performance, we estimate the trial-average log density of the aligned latent dynamics evaluated at the optimal generation

(A)

KLD

NLL

(B)

Source

ERDiff (Ours)

JSDM

7.0

3.5

2.5

5.0

2

2

Cycle-GAN

RDA-MMD

1.5

JSDM

SASA

DAF

ERDiff

3.0

Z1

distribution: 1 /L ∑ L -1 l =0 log q ∗ ( z ( t ) l ) , and the trial-averaged KL Divergence to the optimal latent dynamics distribution: 1 /L ∑ L -1 l =0 D KL ( p ϕ ∗ ( z ( t ) l +1 | z ( t ) l ) ∥ p ϕ ( t ) ( z ( t ) l +1 | z ( t ) l ) ) .

Results on synthetic dataset. We repeat the simulation experiment five times and report the mean and standard deviation of each method in the above two quantitative evaluation metrics, shown in Figure 3(A). We observe that ERDiff achieves higher alignment performance on both two evaluation metrics compared to baseline methods. For further analysis, we plot the phase portrait of the true source domain and those inferred by ERDiff and JSDM in Figure 3(B). Compared to JSDM, ERDiff can extract and recover the spatio-temporal structure of the synthetic latent dynamics more precisely and be much closer to the ground truth. These results mainly due to the fact that ERDiff obtains structure-aware alignment signals from the DM while JSDM neglects this structural information.

4.2 Neural datasets

We conduct extensive experiments on two real-world neural datasets: the non-human-primate (NHP) primary motor cortex (M1) [8] and Rat hippocampal CA1 [27]. Experiments on these two datasets use a nearly identical setup. Here we primarily discuss the experimental approach and results related to the NHP motor cortex dataset. (See Appendix D for the detailed results on the rat hippocampal CA1 dataset.)

Motor cortex dataset description. We conduct experiments with datasets collected from the primary motor cortex (M1) of two non-human primates ('C' & 'M') [8]. The primates have been trained to reach one of eight targets at different angles (Figure 4A). Neural recordings from these two primates have been widely studied [20, 50]. During such a process, their neural spike activities (signals) in the primary motor cortex (M1) along with the reaching behavior velocity were recorded. They performed the center-out reaching task multiple times in each direction and only successful trials were saved. For our experimental evaluation purpose, we select the trials from three recording sessions for each primate per day. In total, we have 3 days for each primate. We will perform cross-day (recordings of the same primate performing the task on different days) and inter-subject (recordings of different primates) experiments.

Data processing and evaluation metrics. The neural recordings of each day and each primate consist of about 180-220 trials across 3 sessions. For each trial, about 200 neurons are recorded and the number of time bins is 39 with 20ms intervals. We also bin the velocity of the primate's behavior into 39 bins. Therefore, we have time-aligned neural data and behavioral data. When training with the source data, we optimize the V AE model together with the DM. One thing we need to emphasize here is that we also include a velocity-decoding loss to the V AE loss. The decoder maps the neural latent to the velocity values, which is a ridge regression model. Therefore, the inferred latent contains a rich amount of velocity information. During testing, we align the test neural data to the training neural data so that we can directly apply the velocity decoder to the latent in the test data without performance degradation. In the training session, the ratio of training and validation set is split as 80%:20% through 5-fold cross-validation. The post-processed dataset of primate 'C' contains 586 trials in total while that of primate 'M' contains 632 trials. For the evaluation protocol, since

ERDiff (Ours)

(C)

(A)

(B)

Cross

Day

Inter

Subject

DAF

JSDM

Source

the ground-truth source domain distribution of latent dynamics is inaccessible, we use the behavior decoding performance to evaluate the performance of latent dynamics alignment. Here we compare the true behavior velocity with the decoded one in the test data using coefficient of determination values ( R 2 , in %) and root-mean-square error ( RMSE ). To verify the generalization of each method in latent dynamics alignment, we make full use of the dataset collected in chronological order. We perform 6 sets of cross-day experiments and 10 sets of inter-subject experiments, all repeated over 5 different random seeds.

Experimental setup. The VAE is based on a sequential architecture [51], in which recurrent units are applied in both the probabilistic encoder and decoder. We also add domain knowledge of our alignment task into the model structure: a behavior regression decoder is cooperatively trained from the latent dynamics so that the behavior semantics information is complementarily provided during the neural manifold learning. Poisson negative log-likelihood loss is used for firing rate reconstruction and mean squared error is used for behavior regression. We use the Adam Optimizer [52] for optimization and the learning rate is chosen among { 0 . 005 , 0 . 01 } . The batch size is uniformly set as 64. Despite the varying size of the input dimension (due to the varying number of recorded neurons in different sessions), the latent space dimension size is set as 8 for all the methods for a fair comparison. We use the dropout technique [53] and the ELU activation function [54] between layers in our probabilistic encoder and decoder architectures. During latent dynamics alignment, we perform linear probing only on the read-in layer of the probabilistic encoder while keeping the remaining layers fixed.

Neural manifold analysis. Considering the interpretability [50] and strong latent semantics contained in neural manifold [8], we conduct a case study based on the visualization of neural manifolds to verify the spatio-temporal structure preserving capability and alignment performance of ERDiff. In Figure 4(B), we plot the averaged latent dynamics of each direction in the source domain, which is based on one recording on primate 'C' using demixed Principle Component Analysis (dPCA) [55]. The parameters of dPCA fit with the source-domain latent dynamics while being fixed when applied to perform the transformation in the target domain. In Figure 4(C), we plot the averaged latent dynamics of each direction aligned by ERDiff and two representative baseline methods (DAF and JSDM) under both cross-day and inter-subject settings.

Under both experimental settings, the overall observation is that the spatio-temporal structure of the aligned results of ERDiff is much more coherent with that of the source domain. The results of DAF and JSDM roughly recover the direction of dynamics but fail to preserve the spatio-temporal

X

Y

(A)

Source

ERDiff (Ours)

JSDM

2

R

R² = 0.257

R²

=-0.032

√

2

0

ERDiff

1

JSDM

2

DAF

3

4

5

b

50%

45%

40%

35%

30%

25%

20%

15%

10%

structure tightly. That is because JSDM neglects the spatio-temporal structure during alignment and it is difficult for adversarial networks to capture such structure implicitly in DAF. Additionally, the averaged latent dynamics of each direction are much more clearly separated through ERDiff. We owe this outcome to the fact that providing extra guidance on the spatio-temporal structure would also facilitate the model to align directions properly. Additionally, without any mean offset alignment, the starting points (from the bottom center) and ending points of latent dynamics are also aligned well with the source domain, further verifying the structure recovering ability of ERDiff.

Decoding performance comparison. Table 1 shows a comparison of the r-squared value ( R 2 ) and average RMSE on both the cross-day and inter-subject settings. While Figure 5(A) depicted the decoded velocity trajectories of a subset of trials on the cross-day setting given the method. We have the following observations: (1) Compared to traditional alignment methods specially designed for neural data, deep learning-based methods additionally model the sequential information of the latent dynamics, thus achieving better alignment results, which reflects the importance of spatio-temporal structure modeling. In most cases, ERDiff achieves the highest decoding accuracy and alignment performance among all methods. (2) From the ablation study shown at the bottom of Table 1, we find that both the Spatial Transformer layer and Temporal Transformer layer are key components in ERDiff, verifying the effectiveness of spatio-temporal structure modeling. (3) As shown in Figure 5(A), the spatio-temporal structure of the latent dynamics is well-preserved in the result of ERDiff. Compared to baselines, the smoothness and continuity of the trajectory decoded by ERDiff are also more satisfying.

Impact of sampling density in the target domain. We verify the consistent performance of ERDiff in few-shot target-sample circumstances. In Figure 5(B), we analyze the impact of the sampling density of the target domain on decoding performance. The setting is that we sample a portion

of target-domain data to learn the alignment and apply the alignment to the entire target domain. Despite the sampling density drops from 50% to 10% , our results demonstrate that ERDiff continues to produce fairly consistent decoding accuracy with a small drop. This result validates our argument that ERDiff both preserves the dynamics structure underlying neural activities and maintains the characteristics of the target domain. In comparison, the performance of baseline methods shrinks drastically because they lack prior knowledge of the spatio-temporal structure.

We can conclude that the DM in ERDiff is capable of extracting the spatio-temporal structure in the source domain latent dynamics, providing a valuable inductive bias in recovering such structure during distribution alignment.

5 Discussion

In this work, we propose a new method named ERDiff, for solving the neural distribution alignment issue in real-world neuroscience applications (e.g., brain-computer interfaces). Firstly, with the source domain, we propose to use a diffusion model to extract the spatio-temporal structure within the latent dynamics of trials. Next, in the alignment phase with the target domain, the spatio-temporal structure of latent dynamics is recovered through the maximum likelihood alignment based on the diffusion model. Experimental results on synthetic and real-world motor cortex datasets verify the effectiveness of ERDiff in the enhancement of long-term robustness and behavior decoding performance from neural latent dynamics.

To be in line with the conventions of previous studies on neural distribution alignment [4, 16], the behavioral (velocity) signals of the source domain are present during the V AE training. These signals do help in learning a more interpretable neural latent space. However, we emphasize that ERDiff does not incorporate any behavioral signals of the target domain during the distribution alignment phase. Hence, ERDiff is entirely an unsupervised neural distribution alignment (i.e., test-time adaptation) method. As for the computational cost analysis, In the source domain training phase, the additional computation cost of ERDiff primarily comes from the diffusion model (DM) training. We note that the DM is trained in the latent space Z , which is significantly lower in dimensionality than the raw neural spiking signal space X . Therefore, the computational overhead of this one-time training phase is acceptable, especially given that it can be conducted offline in real-world BCI applications. In the alignment phase, we would like to emphasize that ERDiff maintains a comparable computational cost with baseline methods. Please refer to Appendix E for a comprehensive analysis of ERDiff's computational cost and time complexity.

Limitation and future work. (1) Currently, ERDiff can align well with a single source domain neural latent distribution. An intriguing direction for future work would be learning a unified latent space across multiple source domains using the diffusion model. Thus the method would be applicable to domain generalization problems. (2) Generalization on alternative latent variable models (LVM). In this paper, ERDiff identifies the latent variables of raw neural spiking signals with a canonical version of VAE. However, the architecture of the LVM within ERDiff is actually disentangled from the diffusion model training or MLA procedure. Future work includes validating ERDiff given more advanced implementations of LVM, e.g., LFADS [56], STNDT [32].

Broader impact. Not confined to practical applications in systems neuroscience, the maximum likelihood alignment (MLA) with diffusion model algorithm proposed in ERDiff has great potential to apply to broader domain adaptation tasks across general time-series datasets (e.g., weather forecasting, and seismology). We also expect that our method can be applied or extended to other real-world scenarios and the broader field of neuroscience/AI.

References

F. Briggs, G. R. Mangun, and W. M. Usrey, 'Attention enhances synaptic efficacy and the signal-to-noise ratio in neural circuits,' Nature , vol. 499, no. 7459, pp. 476-480, 2013.

A. Fourtounas and S. J. Thomas, 'Cognitive factors predicting checking, procrastination and other maladaptive behaviours: prospective versus inhibitory intolerance of uncertainty,' Journal of Obsessive-Compulsive and Related Disorders , vol. 9, pp. 30-35, 2016.

J. R. Manning, J. Jacobs, I. Fried, and M. J. Kahana, 'Broadband shifts in local field potential power spectra are correlated with single-neuron spiking in humans,' Journal of Neuroscience , vol. 29, no. 43, pp. 13613-13620, 2009.

J. Jude, M. G. Perich, L. E. Miller, and M. H. Hennig, 'Robust alignment of cross-session recordings of neural population activity by behaviour via unsupervised domain adaptation,' arXiv preprint arXiv:2202.06159 , 2022.

Z. Wan, R. Yang, M. Huang, N. Zeng, and X. Liu, 'A review on transfer learning in eeg signal analysis,' Neurocomputing , vol. 421, pp. 1-14, 2021.

S. Niu, Y. Liu, J. Wang, and H. Song, 'A decade survey of transfer learning (2010-2020),' IEEE Transactions on Artificial Intelligence , vol. 1, no. 2, pp. 151-166, 2020.

L. Hu, A. Mouraux, Y. Hu, and G. D. Iannetti, 'A novel approach for enhancing the signal-tonoise ratio and detecting automatically event-related potentials (erps) in single trials,' Neuroimage , vol. 50, no. 1, pp. 99-111, 2010.

J. A. Gallego, M. G. Perich, R. H. Chowdhury, S. A. Solla, and L. E. Miller, 'Long-term stability of cortical population dynamics underlying consistent behavior,' Nature neuroscience , vol. 23, no. 2, pp. 260-270, 2020.

J. A. Gallego, M. G. Perich, R. H. Chowdhury, S. A. Solla, and L. E. Miller, 'A stable, long-term cortical signature underlying consistent behavior,' BioRxiv , p. 447441, 2018.

M. M. Churchland, J. P. Cunningham, M. T. Kaufman, J. D. Foster, P. Nuyujukian, S. I. Ryu, and K. V. Shenoy, 'Neural population dynamics during reaching,' Nature , vol. 487, no. 7405, pp. 51-56, 2012.

H. Sohn, D. Narain, N. Meirhaeghe, and M. Jazayeri, 'Bayesian computation through cortical latent dynamics,' Neuron , vol. 103, no. 5, pp. 934-947, 2019.

S. Saxena, A. A. Russo, J. Cunningham, and M. M. Churchland, 'Motor cortex activity across movement speeds is predicted by network-level strategies for generating muscle activity,' Elife , vol. 11, p. e67620, 2022.

R. Liu, M. Azabou, M. Dabagia, C.-H. Lin, M. Gheshlaghi Azar, K. Hengen, M. Valko, and E. Dyer, 'Drop, swap, and generate: A self-supervised approach for generating neural activity,' Advances in neural information processing systems , vol. 34, pp. 10587-10599, 2021.

J. A. Gallego, M. G. Perich, S. N. Naufel, C. Ethier, S. A. Solla, and L. E. Miller, 'Cortical population activity within a preserved neural manifold underlies multiple motor behaviors,' Nature communications , vol. 9, no. 1, p. 4233, 2018.

R. Mitchell-Heggs, S. Prado, G. P. Gava, M. A. Go, and S. R. Schultz, 'Neural manifold analysis of brain circuit dynamics in health and disease,' Journal of Computational Neuroscience , vol. 51, no. 1, pp. 1-21, 2023.

B. M. Karpowicz, Y. H. Ali, L. N. Wimalasena, A. R. Sedler, M. R. Keshtkaran, K. Bodkin, X. Ma, L. E. Miller, and C. Pandarinath, 'Stabilizing brain-computer interfaces through alignment of latent dynamics,' bioRxiv , 2022.

A. D. Degenhart, W. E. Bishop, E. R. Oby, E. C. Tyler-Kabara, S. M. Chase, A. P. Batista, and B. M. Yu, 'Stabilization of a brain-computer interface via the alignment of low-dimensional spaces of neural activity,' Nature biomedical engineering , vol. 4, no. 7, pp. 672-685, 2020.

J. Lee, M. Dabagia, E. Dyer, and C. Rozell, 'Hierarchical optimal transport for multimodal distribution alignment,' Advances in Neural Information Processing Systems , vol. 32, 2019.

R. Liu, M. Azabou, M. Dabagia, J. Xiao, and E. Dyer, 'Seeing the forest and the tree: Building representations of both individual and collective dynamics with transformers,' Advances in neural information processing systems , vol. 35, pp. 2377-2391, 2022.

A. Farshchian, J. A. Gallego, J. P. Cohen, Y. Bengio, L. E. Miller, and S. A. Solla, 'Adversarial domain adaptation for stable brain-machine interfaces,' arXiv preprint arXiv:1810.00045 , 2018.

X. Ma, F. Rizzoglio, E. J. Perreault, L. E. Miller, and A. Kennedy, 'Using adversarial networks to extend brain computer interface decoding accuracy over time,' bioRxiv , pp. 2022-08, 2022.

W. Zhao, L. Mou, J. Chen, Y. Bo, and W. J. Emery, 'Incorporating metric learning and adversarial network for seasonal invariant change detection,' IEEE Transactions on Geoscience and Remote Sensing , vol. 58, no. 4, pp. 2720-2731, 2019.

Z. Zhang, M. Li, and J. Yu, 'On the convergence and mode collapse of gan,' in SIGGRAPH Asia 2018 Technical Briefs , pp. 1-4, 2018.

Y. Wu, E. Winston, D. Kaushik, and Z. Lipton, 'Domain adaptation with asymmetrically-relaxed distribution alignment,' in International Conference on Machine Learning , pp. 6872-6881, PMLR, 2019.

Y. Song, J. Sohl-Dickstein, D. P. Kingma, A. Kumar, S. Ermon, and B. Poole, 'Score-based generative modeling through stochastic differential equations,' arXiv preprint arXiv:2011.13456 , 2020.

H. Xue, A. Araujo, B. Hu, and Y. Chen, 'Diffusion-based adversarial sample generation for improved stealthiness and controllability,' arXiv preprint arXiv:2305.16494 , 2023.

A. Grosmark, J. Long, and G. Buzsáki, 'Recordings from hippocampal area ca1, pre, during and post novel spatial learning,' CRCNS. org , vol. 10, p. K0862DC5, 2016.

J. Ho, A. Jain, and P. Abbeel, 'Denoising diffusion probabilistic models,' Advances in Neural Information Processing Systems , vol. 33, pp. 6840-6851, 2020.

P. Vincent, 'A connection between score matching and denoising autoencoders,' Neural computation , vol. 23, no. 7, pp. 1661-1674, 2011.

R. Wei and A. Mahmood, 'Recent advances in variational autoencoders with representation learning for biomedical informatics: A survey,' Ieee Access , vol. 9, pp. 4939-4956, 2020.

C. Pandarinath, D. J. O'Shea, J. Collins, R. Jozefowicz, S. D. Stavisky, J. C. Kao, E. M. Trautmann, M. T. Kaufman, S. I. Ryu, L. R. Hochberg, et al. , 'Inferring single-trial neural population dynamics using sequential auto-encoders,' Nature methods , vol. 15, no. 10, pp. 805815, 2018.

T. Le and E. Shlizerman, 'Stndt: Modeling neural population activity with a spatiotemporal transformer,' arXiv preprint arXiv:2206.04727 , 2022.

N. Courty, R. Flamary, A. Habrard, and A. Rakotomamonjy, 'Joint distribution optimal transportation for domain adaptation,' Advances in neural information processing systems , vol. 30, 2017.

T. Kerdoncuff, R. Emonet, and M. Sebban, 'Metric learning in optimal transport for domain adaptation,' in Proceedings of the Twenty-Ninth International Conference on International Joint Conferences on Artificial Intelligence , pp. 2162-2168, 2021.

O. Ronneberger, P. Fischer, and T. Brox, 'U-net: Convolutional networks for biomedical image segmentation,' in International Conference on Medical image computing and computer-assisted intervention , pp. 234-241, Springer, 2015.

W. Peebles and S. Xie, 'Scalable diffusion models with transformers,' arXiv preprint arXiv:2212.09748 , 2022.

Y. Tashiro, J. Song, Y. Song, and S. Ermon, 'Csdi: Conditional score-based diffusion models for probabilistic time series imputation,' Advances in Neural Information Processing Systems , vol. 34, pp. 24804-24816, 2021.

R. T. Chen, Y. Rubanova, J. Bettencourt, and D. K. Duvenaud, 'Neural ordinary differential equations,' Advances in neural information processing systems , vol. 31, 2018.

W. Grathwohl, R. T. Chen, J. Bettencourt, I. Sutskever, and D. Duvenaud, 'Ffjord: Free-form continuous dynamics for scalable reversible generative models,' arXiv preprint arXiv:1810.01367 , 2018.

B. Oksendal, Stochastic differential equations: an introduction with applications . Springer Science & Business Media, 2013.

Y. Song, C. Durkan, I. Murray, and S. Ermon, 'Maximum likelihood training of score-based diffusion models,' Advances in Neural Information Processing Systems , vol. 34, pp. 1415-1428, 2021.

J. Skilling, 'The eigenvalues of mega-dimensional matrices,' Maximum Entropy and Bayesian Methods: Cambridge, England, 1988 , pp. 455-466, 1989.

M. Cuturi, 'Sinkhorn distances: Lightspeed computation of optimal transport,' Advances in neural information processing systems , vol. 26, 2013.

M. Menéndez, J. Pardo, L. Pardo, and M. Pardo, 'The jensen-shannon divergence,' Journal of the Franklin Institute , vol. 334, no. 2, pp. 307-318, 1997.

R. Cai, J. Chen, Z. Li, W. Chen, K. Zhang, J. Ye, Z. Li, X. Yang, and Z. Zhang, 'Time series domain adaptation via sparse associative structure alignment,' in Proceedings of the AAAI Conference on Artificial Intelligence , vol. 35, pp. 6859-6867, 2021.

Y. Ganin, E. Ustinova, H. Ajakan, P. Germain, H. Larochelle, F. Laviolette, M. Marchand, and V. Lempitsky, 'Domain-adversarial training of neural networks,' The journal of machine learning research , vol. 17, no. 1, pp. 2096-2030, 2016.

C.-L. Li, W.-C. Chang, Y. Cheng, Y. Yang, and B. Póczos, 'Mmd gan: Towards deeper understanding of moment matching network,' Advances in neural information processing systems , vol. 30, 2017.

Y. Park, D. Maddix, F.-X. Aubet, K. Kan, J. Gasthaus, and Y. Wang, 'Learning quantile functions without quantile crossing for distribution-free time series forecasting,' in International Conference on Artificial Intelligence and Statistics , pp. 8127-8150, PMLR, 2022.

G. Loaiza-Ganem and J. P. Cunningham, 'The continuous bernoulli: fixing a pervasive error in variational autoencoders,' Advances in Neural Information Processing Systems , vol. 32, 2019.

D. Zhou and X.-X. Wei, 'Learning identifiable and interpretable latent models of highdimensional neural activity using pi-vae,' Advances in Neural Information Processing Systems , vol. 33, pp. 7234-7247, 2020.

O. Fabius and J. R. Van Amersfoort, 'Variational recurrent auto-encoders,' arXiv preprint arXiv:1412.6581 , 2014.

D. P. Kingma and J. Ba, 'Adam: A method for stochastic optimization,' arXiv preprint arXiv:1412.6980 , 2014.

N. Srivastava, G. Hinton, A. Krizhevsky, I. Sutskever, and R. Salakhutdinov, 'Dropout: a simple way to prevent neural networks from overfitting,' The journal of machine learning research , vol. 15, no. 1, pp. 1929-1958, 2014.

A. D. Rasamoelina, F. Adjailia, and P. Sinˇ cák, 'A review of activation function for artificial neural network,' in 2020 IEEE 18th World Symposium on Applied Machine Intelligence and Informatics (SAMI) , pp. 281-286, IEEE, 2020.

D. Kobak, W. Brendel, C. Constantinidis, C. E. Feierstein, A. Kepecs, Z. F. Mainen, X.-L. Qi, R. Romo, N. Uchida, and C. K. Machens, 'Demixed principal component analysis of neural population data,' Elife , vol. 5, p. e10989, 2016.

D. Sussillo, R. Jozefowicz, L. Abbott, and C. Pandarinath, 'Lfads-latent factor analysis via dynamical systems,' arXiv preprint arXiv:1608.06315 , 2016.

K. Han, Y. Wang, H. Chen, X. Chen, J. Guo, Z. Liu, Y. Tang, A. Xiao, C. Xu, Y. Xu, et al. , 'A survey on vision transformer,' IEEE transactions on pattern analysis and machine intelligence , vol. 45, no. 1, pp. 87-110, 2022.

A. Dosovitskiy, L. Beyer, A. Kolesnikov, D. Weissenborn, X. Zhai, T. Unterthiner, M. Dehghani, M. Minderer, G. Heigold, S. Gelly, et al. , 'An image is worth 16x16 words: Transformers for image recognition at scale,' arXiv preprint arXiv:2010.11929 , 2020.

A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, 'Attention is all you need,' Advances in neural information processing systems , vol. 30, 2017.

A. Paszke, S. Gross, F. Massa, A. Lerer, J. Bradbury, G. Chanan, T. Killeen, Z. Lin, N. Gimelshein, L. Antiga, et al. , 'Pytorch: An imperative style, high-performance deep learning library,' Advances in neural information processing systems , vol. 32, 2019.

P. Major and P. Major, Multiple Wiener-Itô integrals . Springer, 1981.

Appendix to "Extraction and Recovery of Spatio-Temporal Structure in Latent Dynamics Alignment with Diffusion Model"

A Methodology details

A.1 DMarchitecture details

We adopt the architecture of DM mainly derived from Diffusion Transformer (DiT) [36]. The canonical DiT architecture is based on techniques like patchify [57] and transformer layer for tokens [58], which are well-suited for image feature extraction. This is because the above techniques focus on local feature extraction and the global feature can also be implicitly captured through the stacking of token-based Transformer layers. However, considering the neural observations and latent dynamics are in the format of multi-variate time series, patchify and local feature extraction loses their semantic meaning. There doesn't exist a theoretical guarantee or bio-plausible observation that adjacent latent dimensions of the data matrix have a stronger connection than far-apart latent dimensions. Thus, directly adopting the traditional DiT architecture into this setting may lead to sub-optimal solutions.

To fully utilize the domain knowledge of our task, we propose to use the Spatio-Temporal Transformer Block (STBlock). Each STBlock is mainly composed of a Spatio Transformer layer followed by a Temporal Transformer layer, which are 1-layer encoders based on multi-head self-attention. Since there exists underlying dependency and structure between latent state dimensions, the Spatio Transformer layer takes latent states of each time bin as inputs to extract their spatial structure. Whereas the Temporal Transformer layer takes the entire latent trajectory of each latent space dimension as inputs to extract its underlying temporal structure. We note that we use the sinusoidal position embeddings [59] to encode the timestep t (i.e., noise scale) into the deep neural network of DM. In each STBlock, the input sequentially goes through:

Spatio Transformer : Layer Normalization → Multi-head Self-attention Layer (along time bins) → Point-wise Feed-forward.

Temporal Transformer : Layer Normalization → Multi-head Self-attention Layer (along latent space dimensions) → Point-wise Feed-forward.

We illustrate the main architecture of DM in Figure 2(A), and implement the DM in Pytorch [60].

A.2 VAE and DM cooperative source domain learning details

In DM training, we note that Z ( s ) 0 here are actually latent dynamics inferred via V AE in Eq. 6. Considering the limited number of source-domain latent dynamics, we wish to perform data augmentation so that the DM can adequately estimate p s ( Z ) . Here we propose to enrich the input samples by learning the VAE objective (Eq. 6) and the diffusion objective (Eq. 8) cooperatively. Through the learning process of the V AE objective (i.e., ELBO), the optimization process with stochastic gradient descent (SGD) adds auxiliary perturbation to the original data samples Z ( s ) 0 rather than pure Gaussian noise. This technique further fills the sample space of Z ( s ) 0 , leading to better density estimation. Specifically, in each training iteration, conditioning on the current value of ϕ s , we infer a set of Z 0 = h ( X ( s ) ; ϕ s ) and use it as the temporal Z ( s ) 0 to optimize Eq. 8. The traditionally sequential approach is that we fully

(A)

(B)

(C)

4.5

Sequential

4.5

Sequential

4.0

Sequential

4.0

Cooperative

4.0

Cooperative

3.5

Cooperative

3.5

3.5

3.0

3.0

SSO"

3.0

2.5

2.5

2.0

2.5

2.0

1.5

2.0

1.5

1.0

1.5

1.0

0

100

200

Epoch

300

400

500

0

100

200

Epoch

300

400

500

0

100

200

Epoch

300

400

500

optimize VAE first, obtain an optimal ϕ s , and use it to optimize Eq. 8. Experimental results show that the former approach achieves higher density estimation and alignment performance. Figure 6 manifests the training loss curve in three source-target neural recording session pairs. We observe that despite the relatively under-fitting at the early stage, the cooperative source domain learning paradigm converges to solutions with lower losses and better fits. Table 2 manifests that our cooperative source domain learning paradigm leads to higher distribution alignment and neural decoding performance.

B Detailed derivation of maximum likelihood alignment

B.1 Relationship between KL-Divergence and DSM Loss

Under assumptions in Appendix A of [41], the KL divergence between the ground truth density q ( Z | X ( t ) ; ϕ ) and the DM marginal distribution p 0 ( Z ; θ s ) can be derived as:

in which ( i ) is due to Girsanov Theorem [40], in ( ii ) we invoke the martingale property of Itô integrals [61], and in ( iii ) we use the denoising score matching (DSM) technique [29]. Thus we can draw to Eq. 11.

B.2 Upper bound of maximum likelihood alignment objective

In Section 3.3, by substituting Eq. 11 into Eq. 10, we have

We note that the third term H ( · ) depends on the parameter set ϕ of the probabilistic encoder. As q ( Z | X ( t ) ; ϕ ) ≈ p 0 ( Z ; θ s ) , we have

where in both (i) and (ii) we use integration by parts, and in (iii) we use denoising score matching (DSM) [29]. Putting the second term on the LHS of Eq. 17 into RHS and then substituting the third term on the RHS of Eq. 16, we have

Since the transition probability p 0 t ( Z t | Z 0 ) is a fixed Gaussian distribution and it is independent of the parameter set ϕ , we can eliminate the term in Eq. 20 and rewrite the above Eqs as:

By substituting denoiser function ϵ ( Z t , t ; θ ) into score function s ( Z t , t ; θ ) of Eq. 24, we have:

C Detailed algorithm

C.1 Overall alignment loss function in ERDiff

Extracting the latter two terms from Eq. 12, we have the following main Maximum Likelihood Alignment (MLA) loss:

Then, considering the Sinkhorn Regularizer term in Eq. 13:

where each value C [ i ][ j ] = ∥ ∥ ∥ Z ( s ) i -Z ( t ) j ∥ ∥ ∥ 2 2 in cost matrix C denotes the squared Euclidean cost from Z ( s ) i to Z ( t ) j , H ( γ ) computes the entropy of transport plan γ , and λ refers to the weight of the entropy term. Then, we can find the optimal ϕ t via the minimization of the following total loss function:

where α ∈ [0 , 1] is a trade-off parameter that weights the importance of Sinkhorn Regularizer term.

C.2 Algorithm for source domain learning of ERDiff

Algorithm 1 Source Domain Learning of ERDiff

Input: Source-domain neural observations X ( s ) ; Learning rate η

Output: Parameter set ϕ of source-domain probabilistic encoder; Parameter set ψ of sourcedomain probabilistic decoder; Parameter set θ ( s ) of source-domain diffusion model.

and all other hyperparameters. ( s ) ( s )

1: Initialize ϕ , ψ , and θ ;

2: while not converge do

3: L ELBO ← Compute the loss function based on evidence lower bound according to Eq. 6;

4: Parameter Update: ϕ ← ϕ -η · ∂ L ELBO /∂ ϕ ;

5: Parameter Update: ψ ← ψ -η · ∂ L ELBO /∂ ψ ;

6: Inference Z ( s ) 0 ∼ q ( · | X ( s ) ; ϕ ) , and Noise Sampling ϵ ∼ N (0 , I l × d ) ;

7: L DSM ← Compute the denoising score matching loss according to Eq. 5;

8: Parameter Update: θ ← θ -η · ∂ L DSM /∂ θ ;

9: end while

10: return ϕ , ψ , and θ .

C.3 Algorithm for maximum likelihood alignment of ERDiff

Algorithm 2 Maximum Likelihood Alignment of ERDiff

Input: Target-domain neural observations X ( t ) ; Learning rate

Output: Parameter set ϕ

η and all other hyperparameters. ( t ) of target-domain probabilistic encoder;

1: while not converge do

2: Inference Z ( t ) 0 ∼ q ( · | X ( t ) ; ϕ ) , and Noise Sampling ϵ ∼ N (0 , I l × d ) ;

3: L MLA ← Compute the main Maximum Likelihood Alignment Loss according to Eq. 26;

4: L SHD ← Compute the Sinkhorn Regularizer according to Eq. 27;

5: Parameter Update: ϕ ← ϕ -η · ∂ [(1 -α ) L MLA + α L SHD ] /∂ ϕ ;

6: end while

7: return ϕ .

D Experimental results on rat hippocampal CA1 dataset

We further verify the effectiveness of ERDiff on a publicly available rat hippocampus dataset [27]. In this study, a rat navigated a 1.6m linear track, receiving rewards at both terminals (L & R) as depicted in Figure 4 (A). Concurrently, neural activity from the hippocampal CA1 region was captured, in which the neuron numbers across all recorded sessions are around 120. The neural spiking activities were binned into 25ms intervals. A single round trip by the rat from one end of the track to the opposite was categorized as one lap. We chose 5 sessions in total, and in each session, 80 laps were sampled. The 2 -dimensional neural latent manifolds can be observed in Figure 7 (B) and (C). We also list the neural decoding results of the rat's position in Table 3.

ERDiff (Ours)

(C)

(A)

(B)

DAF

JSDM

L

R

Source

E Computational cost analysis

Here we conduct time complexity analysis with respect to the batch size B for the alignment phase. The ERDiff's alignment objective function is composed of two main terms: Diffusion Noise Residual and Sinkhorn Divergence. We note that in the diffusion noise residual computation, it does not go through the entire T diffusion steps. Instead, it just samples a single time step (noise scale) t and calculates the noise residual specific to that step. Thus, the total complexity of this part takes O ( K 1 ∗ B ∗ d ) , in which the coefficient K 1 relates to the inference complexity of the DM denoiser ϵ ( Z , t ) ; d denotes the latent dimension size. For the Sinkhorn Divergence, it has to compute the distance matrix, costing O ( K 2 ∗ B 2 ) ; K 2 is a relatively small coefficient in magnitude. By summing up, the total complexity of ERDiff is given by O ( K 1 ∗ B ∗ d + K 2 ∗ B 2 ) . This O ( B 2 ) complexity is applicable since the non-adversarial baseline methods we compared (i.e., JSDM, and SASA) require quadratic complexities as well.

For any given target domain, ERDiff can stably align it to the source domain in a comparable overhead with baselines. In Table 4, we conduct a comparative analysis between ERDiff and baseline methods in terms of additional parameter number, additional model size, stability, and alignment time. The demonstrated alignment time corresponds to the execution time for aligning one iteration (a batch of size 64) on a MacBook Pro (2019 equipped with 8-Core Intel Core i9 and 4 GB RAM).

Peer reviews:
{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThe authors address the problem of aligning behavior-related neural population dynamics, either within-subject but across different experimental sessions, or between subjects. This problem exists due to inter-subject variability in terms of which neurons are recorded or drift in the recording and is an important problem for systems neuroscience and for the development of brain-machine interfaces. Importantly, neural activity dynamics in many regions of the brain during behavior lie on a low-dimensional manifold and therefore have a defined spatio-temporal structure. While many state-of-the-art alignment approaches do not take into account this structure and therefore do not preserve it, the authors introduce a diffusion-guided method that does. The approach first uses a diffusional model to discover the manifold on which neural activity evolves (ie the spatiotemporal structure), then it uses this model to guide the alignment, which is done using MLE.\n\nSTRENGTHS:\nOriginality + quality: The authors developed a novel approach for time-series alignment that also discovers latent structure (the low-D manifold on which the neural activity evolves). \n\nQuality: The authors validate their model against a number of state-of-the-art alignment methods on both synthetic and real-world data, demonstrating the practical applicability of their method.\n\nClarity: The authors clearly state the problem and its details, as well as how their method differs from existing ones, and its advantages.\n\nSignificance: The method has significance to the alignment of timeseries with latent spatiotemporal structure, which is broadly relevant in systems neuroscience. Although the authors mainly focus on behaviorally relevant neural data, timeseries in other fields also often possess lower-dimensional latent structure, so this method could be broadly applicable. The authors approach could also be relevant to identifying latent structure outside of alignment context, although I am not familiar with how it compares to existing approaches to do so.\n\nWEAKNESSES:\nClarity: Figure and table legends should be more clear (see Questions section)\n\nOriginality: Authors should state whether existing methods for discovering latent structures using diffusional models exist, and how their methods (e.g. architecture) differs from existing methods.\n\nQuality: The method is validated in data with strong, low-dimensional latent structure (monkey reaching tasks). The generalizability to other types of neural dynamics time series of varying dimensionality should be evaluated to determine limitations.\n\nQUESTIONS:\nFigure 3B: Can the authors describe better what the takeaway from this panel is? In what ways does ERDiff improve on JSDM. The legend should tell the reader what the pink dots are (presumably critical points?).\n\nFigure 4: Please note in the legend or figure that the R-squared value is in %. I was confused at first as to how the R-squared could be negative before reading Table 1.\n\nTable 1: It is unclear to me what the denominator for the R-squared % calculation is. Can the authors make it more apparent in the table legend?\n\nIf the time-series do not belong on a well-defined low-dimensional manifold, will the method hallucinate something? How well does the method work for more unstructured data?\n\nAs the dimensionality of the latent structure increases, how much more badly does the method perform? The authors should quantify this.\n\nLIMITATIONS:\nThe authors should address in more detail the kinds of latent structures/time series that would pose more of an issue for their method. Otherwise, limitations are adequately addressed.", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 3, "SOUNDNESS_CORRECTNESS": 4, "DATE": "2023-06-30"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nBrain-computer interfaces require recalibration to accommodate drifts in the recorded neural populations over time. While there has been some success in aligning neural recordings based on their latent dynamics, deep learning-based alignment methods have also gained popularity since they ignore some of the implicit assumptions made by latent space methods, providing additional flexibility. However, deep learning neural alignment often ignores the temporal structure of the dynamics. The proposed model overcomes these limitations by first extracting the spatio-temporal structure in the source domain via a diffusion model and then aligning the target domain to the source dynamics. The authors demonstrated the success of the method in simulated and neural data, where it outperforms alternative alignment methods.\n\nSTRENGTHS:\nThe paper is adequately written and technically sound. The method was tested and shown to work well when applied to a simulated dataset and neural data. The method introduced here uses deep learning-based alignment while still exploiting the temporal dynamics that are critical in neural datasets. Robust alignment of neural recordings is crucial for the success of BCI applications, and in this work, they showed how this method outperforms existing alignment methods in both synthetic and neural datasets. Moreover, they also showed that the alignment can be performed not only across sessions of the same animal but also across animals.\n\nWEAKNESSES:\nWhile the authors show the promise of their method to align neural responses, they overlooked other methods based on the alignment of latent dynamics that have been shown to be successful for BCI applications, as mentioned in the introduction. I believe that a systematic comparison to such methods is critical to fully grasp the significance of this work. For example, CCA, multiset CCA, hyperalignment, or Procrustes-based alignment. In the context of latent space alignment methods, another relevant piece of literature is the method introduced in (https://proceedings.neurips.cc/paper/2021/hash/aad64398a969ec3186800d412fa7ab31-Abstract.html), which also uses neural dynamics for alignment.\nDeep learning-based methods allow for more expressive functions, but they often come with additional computational costs, data demands, and the need for careful hyperparameter selection. None of these limitations are addressed in the manuscript, nor is there an explicit comparison across methods (latent space vs. deep learning-based), which could help demonstrate the promise of the method for practical BCI applications. The authors minimally showed the effect of dataset size on performance, but the lowest dataset size tested still had dozens of trials, which could be unrealistic in most practical settings. Additionally, it would be important to report the training times as a function of dataset size, as long training times would render the approach useless for real-time alignment.\nThe method defines the alignment between a single source and target dataset, but ideally, one would pool data across all sessions for BCI decoding. It would be interesting to note if the proposed method also allows for multi-session alignment.\nThe authors showed the success of the approach in the context of a single data simulation. However, to fully assess the robustness of the method, they could further test it under different conditions, such as measurement or latent noise, dimensionality, or tasks.\n\nQUESTIONS:\nIt is unclear from the text how the training and testing are performed. In the sentence \"During testing, we align the test neural data to the training neural data so that we can directly apply the velocity decoder,\" it is not clear whether the authors include test data for alignment. Additionally, the authors mentioned that behavioral data is used for alignment, but it is also used to evaluate the success of the approach via decoding. This raises the question of whether there is a circular evaluation of the method.\nReferences 9 and 10 cite the preprint and peer-reviewed versions of the same article.\n\nLIMITATIONS:\nThe authors should include a section or provide a clear description of the limitations and assumptions of the method. They should also address the computational cost, data demands, and potential implications of the presented work.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 3, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-04"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\n* One of the key challenges in analyzing neural recordings is the scalability of models that link behavior and neural population activity across recording sessions or in inter-subject settings.\n• When analyzing single-trial neural population activity, past studies have pointed out that neural activity can be understood in terms of low-dimensional latent dynamics. Such low-dimensional latent dynamics are helpful when visualizing neural profiles across different task conditions and trials.\n• Generally, existing methods try to align latent dynamics by minimizing the difference evaluated by the metric between source and target domains. The paper proposes a method to align the source and target domains of multivariate neural data by learning/capturing latent spatiotemporal structure in the source domain with a diffusion model and applying it as a prior on learning/capturing spatiotemporal structure in the target domain.\n• The authors applied their model to the non-human primate motor cortex, testing both cross-day and inter-subject recordings.\n\nSTRENGTHS:\n* The authors motivate their approach clearly by arguing that naively aligning time series using domain adaptation is ineffective as\nmultivariate neural data has low SNR. Thus, leveraging low-dimension representation is a viable option.\n• The paper seeks to achieve a form of domain adaptation by aligning the spatiotemporal structure of latent dynamics of the target to the source using a novel alignment method (ERDiff).\n• The model and derivations are presented clearly.\n• An exhaustive comparison is provided showing that the their model outperforms standard models on both motor cortex and synthetic datasets.\n\nWEAKNESSES:\n* The authors must clarify why diffusion models are necessary. How about considerably simpler two-step approaches -- like extracting latents with GPFA (Yu et al, 2009) and aligning them with the proposed ML alignment?\n* Alternatively how about comparisons with alternative approaches of comparable complexity -- e.g. adversarial alignment with DANN (Ganin et al, 2015)?\n\nQUESTIONS:\n* Overall: there are many approaches for extracting latent structure from time series data (GPFA, CEBRA, T-PHATE, CILDS) -- one could readily realign the latents extracted from these approaches with the second stage alignment algorithm.\n* Apriori, why would one expect the diffusion model to be more effective at aligning the latents than these other approaches?\n* Because data from non-human primates is used, please clarify whether appropriate IRB approvals were obtained. Or if this is only a secondary analysis of existing datasets, the approvals obtained in the original studies could be mentioned.\n\nLIMITATIONS:\n* No significant negative societal impact envisioned -- the potential use in BCI may suggest a positive social impact.", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-07"}

comments: SUMMARY:
This paper proposes a distribution alignment method (ERDiff), which combines extraction of spatio-temporal structures in latent dynamics from the source distribution and maximum likelihood alignment procedure on the target domain.  The proposed method was evaluated on both synthetic and real data (neural recordings from non-human primate motor cortex), outperforms other methods under both cross-day and inter-subject settings.

STRENGTHS:
- The proposed method is novel and is technically sold
- Performance of the method is well demonstrated on real data under inter-session/subject setup suggest that it could be an important tool with potential broad use in many field not just in neuroscience.

WEAKNESSES:
-I don’t have any major concerns. Although the methods has been shown to outperform some of the current techniques, advantage of the proposed approach is not well demonstrated. I would like to see some analysis on computational cost

QUESTIONS:
- Although the authors clearly mentioned the limitation of alignment method based on pre-defined metric, it would be nice see how the proposed method performs compared to these.

LIMITATIONS:
- Limitations is not addressed in the draft
TITLE: Official Review
SOUNDNESS_CORRECTNESS: 4
DATE: 2023-07-13

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThe paper focuses on aligning highly variable neural population activities across days and subjects to stabilize the learning proposes and advance applications such as the brain computer interface. The idea is to train a VAE on one dataset that is hopefully self-consistent and then using a VAE trained on a dataset from another day or subject align the conditional distributions (encoders) for the latent spaces maximizing the likelihood of the source domain latent space under the new encoder distribution. The difficulty is the need to model the marginal source distribution of the latent space, which the work does using a diffusion model. The approach is demonstrated in comparison with alternative models on a synthetic dataset and actual neural recordings.\n\nSTRENGTHS:\n1. A well written paper (but the abstract).\n2. An interesting application of diffusion models.\n3. Potentially impactful in practice of the BCI, more work, including further evaluation, is needed here however.\n\nWEAKNESSES:\n1. A niche application and demonstration. A cellular neuroscience focused paper with no additional effort to demonstrate a general applicability of the approach in evaluations.\n2. Poorly written abstract, especially in contrast to the rest of the paper.\n\nQUESTIONS:\n1. Is the code going to be released publicly? Looks like the success of the approach depends less on the high level probabilistic descriptions in the paper than on the details of the actual implementation.\n2. Is the data going to be released publicly for reproducibility?\n\nLIMITATIONS:\nPotentially, the applicability of this work may be limited only to the demonstrated use in intracranial multicellular recordings, and it may not contribute to advancements in other areas of Machine Learning (ML). No demonstration was provided to counter this potential limitation.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 2, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-13"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nInter-individual and inter-session variability significantly complicate direct comparison of neural recordings collected over time, degrading trained behavioral models. This can be cast as a more general distribution alignment problem, shared across unsupervised learning. To address neural distribution alignment, the authors introduce a novel \"ERDiff\" method, which co-trains a variational autoencoder and a diffusion model to extract latent spatiotemporal structure in a source dataset. To align with a desired target dataset, parameter finetuning is performed on the read-in layer of the probabilistic encoder learned during training to match the target dataset.\nSimulation and experimental results suggest that ERDiff captures relevant spatiotemporal structure, performing competitively against other baseline methods including those based on overall minimizing distribution divergence as well as based on adversarial methods. Overall, the authors argue that ERDiff is better able to capture the important spatiotemporal structure of their trialwise data; for example, from a monkey center-out reaching task in the experimental results. This focus differentiates ERDiff from many other alignment methods, which ignore unfolding dynamics in their alignments.\n\nSTRENGTHS:\nIncorporating spatiotemporal structure into the alignment of neural recordings is a novel approach, as these methods traditionally consider successive data points as independent samples or learn a set of low-dimensional latent dynamics which can then be aligned. These dynamics are particularly critical where the the trialwise dynamics strongly influence both behavior and neural activity over time. By directly learning and aligning the latent spatiotemporal structure, ERDiff shows stable performance even over relatively low sampling density, retaining relatively high decoding performance compared to other baseline methods even with decreasing numbers of trials in the target domain. These properties suggest that it is also likely that the general ERDiff approach may be useful in other cases where distribution shift between a source and target domain obscures but does not remove a shared latent structure.\nThe general approach of combining variational autoencoders (VAEs) and diffusion models (DMs) has been previously introduced (e.g., Panday et al., TMLR, 2023); however, ERDiff is a significantly different formulation of the idea and represents a novel approach in leveraging the relative strengths of these methods through cooperative training.\n\nWEAKNESSES:\nWhile the current experiments extensively compare inter-session and inter-subject differences in real neural recordings --- in addition to the simulated experiments --- it is not clear to what extent the presented findings might generalize to data sources without such a clear trial structure. For example, in recordings collected during unconstrained exploration or sleep, low-dimensional latent factors may still drive a successful alignment. Nonetheless, it is not clear how ERDiff would best be deployed in that context. This is particularly relevant as the described real-data experiments additionally incorporated velocity information, and the performance of ERDiff without a behavioral signal during training is thus unclear. \nIn the current paper, my additional concern with the experiments is on the relative baselines against which ERDiff is compared. It would be informative to see a direct comparison with canonical correlation analysis (CCA) approaches, which have been used to date in aligning neural datasets with a strong temporal correspondence (e.g., Gallego et al., Nat Neuro, 2020).\n\nQUESTIONS:\nWould the authors be able to directly comment on the relationship between their work and other field-standard methods to identify low-dimensional, latent factors such as LFADS (Pandarinath et al., Nat Methods, 2018) ? In particular, the relative benefits of learning the low-dimensional latent structure as part of the alignment --- as compared to other existing methods which learn low-dimensional dynamics which can then be aligned --- is not clearly explained. This would help to better situate the work in the literature.\n\nLIMITATIONS:\nAlthough I do not see a Broader Impact section included in the current submission, I do not anticipate potential negative societal impacts given the constrained focus of the work.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 3, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-18"}