SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Shirui Chen*  
Department of Applied Mathematics  
University of Washington, Seattle  
sc256@uw.edu
Rajesh P. N. Rao
Paul G. Allen School of Computer Science & Engineering and Center for Neurotechnology University of Washington, Seattle rao@cs.washington.edu
Linxing Preston Jiang  
Paul G. Allen School of Computer Science & Engineering  
University of Washington, Seattle  
prestonj@cs.washington.edu
Eric Shea-Brown  
Department of Applied Mathematics  
Computational Neuroscience Center  
University of Washington, Seattle  
etsb@uw.edu
In sampling-based Bayesian models of brain function, neural activities are assumed to be samples from probability distributions that the brain uses for probabilistic computation. However, a comprehensive understanding of how mechanistic models of neural dynamics can sample from arbitrary distributions is still lacking. We use tools from functional analysis and stochastic differential equations to explore the minimum architectural requirements for recurrent neural circuits to sample from complex distributions. We first consider the traditional sampling model consisting of a network of neurons whose outputs directly represent the samples (sampler-only network). We argue that synaptic current and firing-rate dynamics in the traditional model have limited capacity to sample from a complex probability distribution. We show that the firing rate dynamics of a recurrent neural circuit with a separate set of output units can sample from an arbitrary probability distribution. We call such circuits reservoir-sampler networks (RSNs). We propose an efficient training procedure based on denoising score matching that finds recurrent and output weights such that the RSN implements Langevin sampling. We empirically demonstrate our model's ability to sample from several complex data distributions using the proposed neural dynamics and discuss its applicability to developing the next generation of sampling-based Bayesian brain models.
There is growing evidence that humans and other animals make decisions by representing uncertainty internally and carrying out probabilistic computations that approximate Bayesian inference [42, 30, 18, 23, 34]. How networks of neurons in the brain represent probability distributions for Bayesian inference has remained a major open question. There exist two major theories: one assumes that the neural activities encode the parameters of the underlying posterior distributions over sensory stimuli [5, 35, 52]. The other is the sampling-based hypothesis, which assumes that the neural responses can be interpreted as samples from a posterior distribution [28]. Under this hypothesis, recurrent neural circuits make use of their inherent stochasticity to produce samples from posterior distributions. The
sampling-based theory has explained various experimental observations regarding neural variability [19, 20, 40], perceptual decision-making [24] and spontaneous cortical activity [7].
Many studies have proposed biologically plausible spiking rules and membrane dynamics models to implement sampling-based probabilistic inference. However, most of these studies mainly consider sampling from discrete Boltzmann distributions [12] and multivariate Gaussian distributions [17, 1, 38, 25], only match the first two moments of the distribution [19], or employ a Monte-Carlo approximation [29]. Although these studies use algorithmic substrates that can sample from any distribution with a density function in theory, it is not clear whether the underlying neural dynamics are capable of implementing a sufficiently expressive version of these sampling methods. Furthermore, natural image statistics are strongly non-Gaussian [39], and experimental evidence shows that humans use non-Gaussian prior representations to support cognitive judgments [27, 22]. It is known that deep artificial neural networks can be used to generate samples from complex data distributions [48, 49] using a "U-net" [43] backbone. However, the neural circuits in the cortex are highly coupled with an abundance of recurrent synapses. Therefore, an outstanding question for probabilistic computation in the brain is: what kind of recurrent neural network is capable of efficiently learning to produce samples from an arbitrarily complex posterior distribution?
In this paper, we study this question under the basic assumption that the dynamics of recurrent neural circuits can be described by stochastic differential equations (SDEs). Note that this assumption is common to a broad range of past research that uses rate-based neural dynamics to implement sampling-based coding[1, 19, 17]. Moreover, spike-based models [46, 45, 38] that implement balanced spiking networks (BSNs) [11, 13] essentially train spiking networks to follow underlying continuous-time SDEs, so our work applies to this line of research as well (details in Appendix G).
The contributions of this paper are as follows (Figure 1):
1. We establish the relationship between the sampling power of the neural dynamics and the ability of the dynamics to approximate the score function, which is the gradient of the log probability density function. (Section 3.1)
2. We show that the synaptic current dynamics of a network of neurons whose outputs directly represent the samples (traditional sampler-only network) is only able to approximate score functions that are in a finite-dimensional function space. (Section 3.2, Proposition 2)
3. We prove that the firing rate dynamics of our proposed reservoir-sampler network can sample from a distribution whose score function can approximate that of arbitrary target distributions (with mild restrictions) to arbitrary precision (Section 3.3, Theorem 3).
4. We derive a computationally efficient and biologically-plausible learning rule for our proposed model (Section 3.4) that sidesteps the demands of backpropagation through time, and we empirically demonstrate how our model can sample from several complex data distributions (Section 4).
And interpretation of our contributions in biological terms is as follows: 1. Flexible synaptic connectivity within a circuit itself is not enough to allow that circuit to flexibly produce arbitrary patterns of variability involving all of its neurons. 2. In order for circuit to achieve full flexibility in its output patterns, there need to be hidden variables involved, e.g. states of neurons in an upstream brain area or possibly non-synaptic signalling. If this condition is met, concrete and fairly efficient plasticity rules may be capable of shaping the output patterns as desired.
2.1 Fokker-Planck equation and stationary distribution
We consider a general time-homogeneous SDE with drift vector  $\mathbf{b}(X_t)$  and diffusion matrix  $\Sigma = \frac{1}{2}\sigma\sigma^T$ :
$$
d X _ {t} = \mathbf {b} (X _ {t}) d t + \sigma d B _ {t} \tag {1}
$$
where  $\sigma \in \mathbb{R}^{n\times m}$  is the diffusion coefficient, and  $B_{t}$  is an  $m$ -dimensional standard Wiener process. The Fokker-Planck equation of this SDE describes the time evolution of the probability density  $p(x,t)$  for a given SDE, assuming the initial density  $p(x,0)$  is known:
Figure 1: Reservoir-Sampler Networks versus Traditional Sampler-Only Networks. The sampler neurons which produce samples from the target distribution are present for both the sampler-only (SO) network and the reservoir-sampler (RS) network. The reservoir neurons (shown within the large black circle) are only present in the RS network. We explore the firing rate (FR) dynamics (Section 3.3) for both networks and the synaptic current (SC) dynamics (Section 3.2) only for the sampler-only network because the stationary distribution of the output neurons is intractable in the RS-SC case. We evaluate the approximation power of the function set represented by the drift term of the neural dynamics, and list the number of basis functions that span the set, whether these basis functions are fixed, and whether the function set is closed under addition (shown in the table).
$$
\partial_ {t} p = \nabla \cdot (\Sigma \nabla p - \mathbf {b} p) \tag {2}
$$
where  $\partial_t = \partial/\partial t$ ,  $\nabla \cdot$  is the divergence operator, and  $\nabla$  is the gradient operator. A stationary probability density function is one for which the right-hand-side of equation (2) is 0. Mild regularity conditions guaranteeing the existence and uniqueness of a stationary density function are discussed in, for example, Cerrai [14]. We assume these are satisfied by the SDEs considered in this paper. Moreover, to ensure ergodicity and a well-defined score function, we assume that  $p$  is supported on  $\mathbb{R}^n$ , i.e.  $p(x) > 0$  for all  $x \in \mathbb{R}^n$ .
As a special case, consider the following Langevin dynamics, in which the drift term is given by the gradient of the log stationary probability density  $\nabla p(x)$ ,
$$
d X _ {t} = \nabla \log p (X _ {t}) d t + \sqrt {2} d B _ {t}. \tag {3}
$$
It can be verified through the Fokker-Planck equation that  $p(x)$  in the dynamics above is indeed a stationary probability density function of the dynamics. Therefore the Langevin dynamics can sample from the distribution  $p(x)$  as  $t \to \infty$ . While the drift term in the Langevin dynamics is a gradient vector field, this is not true in general and is often not the case for recurrent neural dynamics (Proposition 5 in Appendix B).
2.2 Score-based generative modeling
If we would like a particular dynamics to implement Langevin dynamics, we need to fit the drift term of an SDE to the score  $s_{\theta}(\mathbf{x}) = \nabla \log p(\mathbf{x})$  of the probability distribution that we are trying to sample from. This procedure of fitting the score function  $s_{\theta}(\mathbf{x})$  is called score matching. In this section, we give a brief summary of one of the major methods of score matching that we will use in this paper, denoising score matching (DSM) [51]. The general idea of DSM is to match the score of a noise-perturbed version of the target distribution. More specifically, the explicit score matching loss
(left-hand side) and the denoising score matching loss (right-hand side) are related to each other as follows [51]:
$$
\mathbb {E} _ {q _ {\sigma} (\tilde {\mathbf {x}})} \left[ \frac {1}{2} \| s _ {\theta} (\tilde {\mathbf {x}}) - \nabla_ {\tilde {\mathbf {x}}} \log q _ {\sigma} (\tilde {\mathbf {x}}) \| ^ {2} \right] = \mathbb {E} _ {q _ {\sigma} (\tilde {\mathbf {x}}, \mathbf {x})} \left[ \frac {1}{2} \| s _ {\theta} (\tilde {\mathbf {x}}) - \nabla_ {\tilde {\mathbf {x}}} \log q _ {\sigma} (\tilde {\mathbf {x}} | \mathbf {x}) \| ^ {2} \right] + C _ {\sigma} \tag {4}
$$
where  $\tilde{\mathbf{x}}$  is a noise-perturbed version of  $\mathbf{x}$ , so  $q_{\sigma}(\tilde{\mathbf{x}}|\mathbf{x}) = \mathcal{N}(\mathbf{x},\sigma)$ , and  $C$  is a constant depending on  $\sigma$  but not on  $\theta$ . When the noise is 0, i.e.  $\tilde{\mathbf{x}} = \mathbf{x}$ , the left-hand side of the equation above is the explicit score matching loss. Although in theory we can start from extremely small Gaussian noise, and directly optimize the right hand of equation (4), empirically it is beneficial to start with large Gaussian noise and gradually decrease the noise magnitude until  $q_{\sigma}(\mathbf{x}) \approx p(\mathbf{x})$  and  $s_{\theta}(\mathbf{x}) \approx \nabla_{\mathbf{x}}\log q_{\sigma}(\mathbf{x}) \approx \nabla_{\mathbf{x}}\log p(\mathbf{x})$ . Specifically, this has been shown to stabilize the training and improve score estimation [48].
3.1 Do we really need to match the score?
The Langevin dynamics provides an elegant way to construct an SDE given a specific stationary distribution. However, as noted above, the neural network dynamics seldom have a drift term that is a gradient field (Appendix B). A natural question is therefore whether an SDE with a drift term that is not a gradient field (also known as irreversibility) also gives rise to a specific stationary distribution. The answer requires us to look at the Fokker-Planck equation:
$$
\partial_ {t} p (\mathbf {v}, t) = \nabla \cdot \left(\Sigma \nabla p - p F _ {\theta} (\mathbf {v})\right) \tag {5}
$$
where  $p(\mathbf{v},t)$  is the probability density function of the variable of interest  $\mathbf{v}$  at time  $t$ ,  $F_{\theta}(\mathbf{v})$  is the drift term of the neural dynamics parametrized by  $\theta$ , and  $\Sigma = \frac{1}{2}\sigma \sigma^T$  is the diffusion matrix. Since the right-hand side of (5) needs to be 0 for a given stationary distribution  $p(\mathbf{v})$ , we have
$$
\nabla \cdot (\Sigma \nabla p - p F _ {\theta} (\mathbf {v})) = 0. \tag {6}
$$
Therefore  $G \coloneqq -\Sigma \nabla p + pF_{\theta}(\mathbf{v})$  needs to be a divergence-free (DF) vector field. In other words,  $pF_{\theta}(\mathbf{v})$  is unique up to a DF field given a fixed stationary distribution  $p$ . Ma et al. [36] shows that there exists a skew-symmetric matrix  $Q$  such that the DF field can be written as  $G = Q\nabla p + p\sum_{j}\frac{\partial}{\partial\mathbf{v}_{j}} Q_{ij}$ , however, this does not shed more light on how expressive  $\{F_{\theta}\}_{\theta}$  needs to be without more knowledge of  $Q$  and its derivative. We show below that under certain conditions, the DF field  $G$  can be regarded as a component that is orthogonal to the score function. Therefore the function space  $\{F_{\theta}\}_{\theta}$  needs to have enough basis functions so that (when projected) it is able to approximate the score function of the target distribution.
We first note that it would be convenient if  $F_{\theta}(\mathbf{v})$  could approximate the gradient fields  $\Sigma^{-1}\nabla \log p$  for any  $p$ , in which case  $G = 0$ . To find out if this is a necessary condition for the dynamics to sample from an arbitrary target distribution  $p$ , we let  $\Sigma = \mathbf{I}$  and invoke the Helmholtz-Hodge decomposition (HHD) [8, 37]. The decomposition theorem states that any sufficiently smooth vector field in  $L^2 (\mathbb{R}^n;\mathbb{R}^n)$  can be uniquely decomposed into a DF vector field and a pure gradient field. In other words, the function space of all DF fields  $G$  and the function space of all gradient fields  $\nabla p$  are the orthogonal complement of each other. Therefore the projection of  $pF_{\theta}(\mathbf{v})$  onto the subspace of smooth gradient fields still needs to be able to approximate  $\nabla p$  despite the freedom to choose arbitrary DF field  $G$ .
For example, in the 1-D case, if we assume that both  $pF_{\theta}(\mathbf{v})$  and  $\nabla p$  are square-integrable (so they vanish at infinity), then the divergence-free vector field  $G$  (which must be constant in 1-D) is 0, therefore  $F_{\theta}(\mathbf{v}) = \nabla \log p$ . As a result,  $\{F_{\theta}\}_{\theta}$  indeed needs to be able to approximate  $\nabla \log p$  for every  $p$ . In higher dimensions, the same conclusion holds under the assumption of a strict orthogonality constraint:
Proposition 1. Let  $p$  be the stationary distribution of the neural dynamics, and the diffusion matrix be the identity matrix. If the DF field  $G$  is strictly orthogonal to the gradient field  $\nabla p$ , meaning that  $G(\mathbf{v}) \cdot \nabla p(\mathbf{v}) = 0$  for all  $\mathbf{v}$ , then the drift term  $F_{\theta}(\mathbf{v})$  can be written as the sum of a divergence-free field  $p^{-1}G$  and a gradient field  $\nabla \log p$ .
The proof and further detail is in Appendix A. The form of the above decomposition coincides with that of the HHD [8, 9]. Therefore if we enforce the normal-parallel boundary condition [15] for the gradient component, the HHD theorem [8] says that the orthogonal projection of the function space  $\{F_{\theta}\}_{\theta}$  onto the space of gradient fields is the function space of gradient fields  $\{\nabla \log p\}_{p}$  satisfying the boundary condition given the strict orthogonality constraint on  $G$ . The upshot is that  $\{F_{\theta}\}_{\theta}$  needs to admit enough basis functions (Appendix A). Note that the boundary condition will not be restrictive if we take a sufficiently large bounded region. Therefore it is essential for the neural dynamics to have an expressive functional form that is able to approximate complex score functions, even if their dynamics are not gradient fields.
Previous work has rigorously established that the strict orthogonality constraint holds, in particular, when the nonlinear dynamics is linearized around fixed points of  $\mathbf{v}$  (where the drift term is zero [2, 31, 41]). As a consequence, the conditions of Proposition 1 are true locally around fixed points.
In what follows, we assume that the conditions of the Proposition 1 hold. Under this assumption, without loss of generality, we set  $G$  to be  $\mathbf{0}$  in the following text and explore whether  $\Sigma^{-1}F_{\theta}$ , which is determined by the specific neural dynamics (Figure 1), is able to approximate complex score function  $\nabla \log p$ .
3.2 Synaptic current dynamics: sampler-only networks with limited capacity
We consider the following stochastic synaptic current dynamics [16] (cf. eq. 7.39) that describe a recurrent neural network in terms of the synaptic current that each neuron receives:
$$
d \mathbf {v} = D (- \mathbf {v} + W \phi (\mathbf {v}) + I) d t + \sigma d \mathbf {B} _ {t} := F _ {\theta} ^ {\mathrm {S C}} (\mathbf {v}) d t + \sigma d \mathbf {B} _ {t} \tag {7}
$$
where  $F_{\theta}^{\mathrm{SC}}(\mathbf{v}) \coloneqq D(-\mathbf{v} + W\phi (\mathbf{v}) + I)$ ,  $\mathbf{v} = [v_1,\dots ,v_m]^T \in \mathbb{R}^m$  is the synaptic current of the  $m$  neurons in the recurrent network,  $D \in \mathbb{R}^{m\times m}$  is a diagonal matrix where diagonal elements are the decay constants,  $d_{i} = \tau_{i}^{-1}$ ,  $W \in \mathbb{R}^{m\times m}$  is the connection matrix,  $\phi (\cdot)$  is a nonlinear transfer function,  $I \in \mathbb{R}^m$  is the external input,  $\sigma \in \mathbb{R}^{m\times l}$  is the diffusion coefficient and  $\mathbf{B}_t$  is an  $l$ -dimensional standard Wiener process. The diffusion term can be interpreted as input from other brain areas (due to the large number of incoming connections, the assumption of Gaussianity can be justified by the central limit theorem [21]). We assume that  $\theta = \{D,W,I\}$  are tunable parameters through biological learning. To show the limited expressivity of  $F_{\theta}^{\mathrm{SC}}$ , we have the following corollary from the Hilbert projection theorem showing that  $F_{\theta}^{\mathrm{SC}}$  is only able to approximate functions in a finite-dimensional function space.
Proposition 2. Let  $H: \mathbb{R}^m \to \mathbb{R}^m$ , a function in the Hilbert space  $L_2(\mathbb{R}^m, \mathbb{R}^m; p)$ . Let  $\Pi$  be the orthogonal projection operator onto the vector subspace
$$
E = \left\{A \mathbf {v} + B \phi (\mathbf {v}) + I | A, B \in \mathbb {R} ^ {m \times m}, I \in \mathbb {R} ^ {m \times 1} \right\}
$$
If  $\| H - \Pi H\| >0$  , then  $\inf_{\theta}\left\| H(\mathbf{v}) - F_{\theta}^{\mathrm{SC}}(\mathbf{v})\right\| \geq \| (1 - \Pi)H\| >0.$
Proof of the proposition is given in Appendix B.1. The proposition says that no matter how the parameter of  $F_{\theta}^{\mathrm{SC}}$  is tuned, the difference between  $F_{\theta}^{\mathrm{SC}}$  and the target function cannot approach 0, and the lower bound of the error is given by the norm of the component in the target function that is orthogonal to the finite-dimensional function space  $E$ . Therefore, synaptic current dynamics have a limited ability to match the score function and hence limited ability to sample from complex probability distributions under the strict orthogonality constraint in Section 3.1. The conclusion holds even if we let the diffusion coefficient  $\sigma$  be tunable. Since  $\Sigma^{-1}$  is linear,  $\left\{F_{\theta}^{\mathrm{SC}}\right\}_{\theta}$  share the same set of basis functions as  $\left\{\Sigma^{-1}F_{\theta}^{\mathrm{SC}}\right\}_{\theta,\sigma}$ . As we will see in the next section, the firing rate dynamics of a recurrent neural circuit with a separate output layer (a reservoir-sampler network) and a learnable diffusion coefficient  $\sigma$  can sample from arbitrary stationary distributions.
3.3 Firing-rate dynamics could be a universal sampler
3.3.1 Sampler-only networks
In this section, we consider the firing rate dynamics [16] (cf. eq. 7.11) that describe a recurrent neural circuit in terms of firing rates of the neurons. We first consider the sampler-only network:
$$
d \mathbf {r} = D (- \mathbf {r} + \phi \left(W _ {\mathrm {r e c}} \mathbf {r} + I\right)) d t + \sigma d B _ {t} := F _ {\theta} ^ {\mathrm {F R}} (\mathbf {v}) d t + \sigma d \mathbf {B} _ {t}. \tag {8}
$$
2We later need it to be non-polynomial in Theorem 3
Here,  $F_{\theta}^{\mathrm{FR}}(\mathbf{v}) = D(-\mathbf{r} + \phi (W_{\mathrm{rec}}\mathbf{r} + I))$  and  $D$  is a diagonal matrix with decay constants as its diagonal elements. The stationary solution of the corresponding Fokker-Planck equation satisfies
$$
\nabla \cdot \left(\Sigma \nabla p - p F _ {\theta} ^ {\mathrm {F R}}\right) = 0 \tag {9}
$$
where  $\Sigma := \frac{1}{2}\sigma\sigma^T$  is symmetric positive definite (SPD) and  $F_{\theta}^{\mathrm{FR}} = D(-\mathbf{r} + \phi(W_{\mathrm{rec}}\mathbf{r} + I))$ . Here  $\theta = \{D, W_{\mathrm{rec}}, I\}$  are tunable parameters. If  $\Sigma$  is invertible, equation (9) becomes  $\nabla \cdot (\Sigma(\nabla p - p\Sigma^{-1}F_{\theta}^{\mathrm{FR}}))$ . Therefore if  $\Sigma^{-1}F_{\theta}^{\mathrm{FR}} = \nabla \log p$  is a gradient field, then the stochastic dynamics of the recurrent neural network described by equation (8) have a stationary distribution  $p^*$  such that the score of this distribution  $\nabla \log p^* = \Sigma^{-1}F_{\theta}^{\mathrm{FR}}$ .
Compared to the synaptic current dynamics where we could only have functional basis  $\mathbf{v}_i$  and  $\phi (\mathbf{v})_i$ , we can now freely choose the functional basis spanning  $\left\{F_{\theta}^{\mathrm{FR}}\right\}_{\theta}$  depending on  $W_{\mathrm{rec}}$  and  $I$ , but since there is no linear term before the nonlinear transformation  $\phi$ , the function set  $\left\{F_{\theta}^{\mathrm{FR}}\right\}_{\theta}$  is not closed under addition. If we view  $\Sigma^{-1}F_{\theta}^{\mathrm{FR}}$  as a neural network with one hidden layer, the number of hidden neurons must be the same as the input dimension, and the diffusion matrix  $\Sigma$  (hence  $\Sigma^{-1}$ ) is restricted to be an SPD matrix. Therefore, we do not get universal approximation power from  $\Sigma^{-1}F_{\theta}^{\mathrm{FR}}$ , and combined with results in Section 3.2, we see that an RNN by itself does not intrinsically produce samples from arbitrary distributions. As we will see below, if we let a population of output neurons receive inputs from a large reservoir of recurrently connected neurons (a reservoir-sampler network), we are able to obtain samples from complex distributions from the output neurons.
3.3.2 Reservoir-sampler networks
Now we consider the reservoir-sampler network where there is a linear readout layer  $W_{\mathrm{out}} \in \mathbb{R}^{m \times n}$  of the reservoir whose dynamics is given by equation (8) (see also the upper row of Figure 1). As a special case of Ito's lemma, we have
$$
\begin{array}{l} W _ {\text {o u t}} d \mathbf {r} = d W _ {\text {o u t}} \mathbf {r} = W _ {\text {o u t}} F _ {\theta} ^ {\mathrm {F R}} d t + W _ {\text {o u t}} \sigma d B _ {t} \\ \begin{array}{l} - W _ {\text {o u t}} r _ {\theta} d t + W _ {\text {o u t}} \sigma d B _ {t} \\ = (- W _ {\text {o u t}} D \mathbf {r} + W _ {\text {o u t}} D \phi (W _ {\text {r e c}} \mathbf {r} + I)) d t + W _ {\text {o u t}} \sigma d B _ {t}. \end{array} \tag {10} \\ \end{array}
$$
Now we assume that  $W_{\mathrm{rec}}$  is the product of  $\widetilde{W}_{\mathrm{rec}}$  and  $W_{\mathrm{out}}$ , i.e.  $W_{\mathrm{rec}} = \widetilde{W}_{\mathrm{rec}}W_{\mathrm{out}}$  and  $D = \alpha \mathbf{I}$  is a scaled identity matrix. If we denote the output of the recurrent neural network as  $\mathbf{x} \coloneqq W_{\mathrm{out}}\mathbf{r} \in \mathbb{R}^{m}$ , we derive the following stochastic dynamics for output neurons: