Predictive Coding, Variational Autoencoders, and Biological Connections
Abstract
Predictive coding, within theoretical neuroscience, and variational autoencoders, within machine learning, both involve latent Gaussian models and variational inference. While these areas share a common origin, they have evolved largely independently.
We outline connections and contrasts between these areas, using their relationships to identify new parallels between machine learning and neuroscience. We then discuss speciﬁc frontiers at this intersection: backpropagation, normalizing ﬂows, and attention, with mutual beneﬁts for both ﬁelds.
Introduction
Perception has been conventionally formulated as hierarchical feature detection [51], similar to discriminative deep networks [33]. In contrast, predictive coding [47, 13] and variational autoencoders (VAEs) [30, 50] frame perception as a generative process, modeling data observations to learn and infer aspects of the external environment. Speciﬁcally, both areas model observations, x , using latent variables, z , through a probabilistic model, p θ ( x , z ) =
p θ ( x | z ) p θ ( z ) .
Both areas also use variational inference, introducing an approximate posterior, q ( z | x ) , to infer z and learn the model parameters, θ .
These similarities are the result of a common origin, with Mumford [44], Dayan et al.
[8], and others [45] formalizing earlier ideas [58, 37].
However, since their inception, these areas have developed largely independently.
We explore their relationships (see also [57, 36]) and highlight opportunities for the transfer of ideas. In identifying these ties, we hope to strengthen this promising, close connection between neuroscience and machine learning, prompting further investigation.
Background
Predictive Coding Predictive coding [7] is a theory of thalamocortical function, in which the cortex constructs a probabilistic generative model of sensory inputs, using approximate inference to perform state estimation.
Top-down neural projections convey predictions of lower-level activity, while bottom-up projections convert the prediction error at each level into an updated state estimate.
Such models are often formulated with hierarchies of Gaussian distributions, with analytical non-linear (e.g. polynomial) functions parameterizing the generative mappings [47, 13]: [Equation]
Variational inference is performed using gradient-based optimization on the mean of q ( z | x ) = N ( z (cid:96) ; µ q,(cid:96) , Σ q,(cid:96) ) , yielding gradients which are linear combinations of (prediction) errors, e.g. [Equation] where L is the objective, J = ∂ µ θ, x /∂ µ q, 1 is the Jacobian, and ε x and ε 1 are weighted errors, i.e. ε x = Σ − 1 x ( x − µ θ, x ) .
Parameter learning can also be performed using gradient-based optimization. We discuss connections between these models and neuroscience in Section 3.
z x COMPUTATION/NEURAL DIAGRAM (a) z x " z p ✓ ( x | z ) p ✓ ( z ) " x q ( z | x ) COMPUTATION/NEURAL DIAGRAM (b) q  ( z | x ) z " z p ✓ ( x | z ) p ✓ ( z ) " x COMPUTATION/NEURAL DIAGRAM x (c) z x " z p ✓ ( x | z ) p ✓ ( z ) " x
COMPUTATION/NEURAL DIAGRAM q  ( z | x ) (d) Variational Autoencoders VAEs are a class of Bayesian machine learning models, combining latent Gaussian models with deep neural networks.
They consist of an encoder network with parameters φ , parameterizing q φ ( z | x ) , and a decoder network, parameterizing p θ ( x | z ) .
Thus, rather than performing gradient-based inference, VAEs amortize inference optimization with a learned network [18], improving computational efﬁciency.
These networks can either take a direct form [8], e.g. µ q ← NN φ ( x ) , or an iterative form [41, 40], e.g. µ q ← NN φ ( µ q , ∇ µ q L ) , where NN φ denotes a deep neural network. In both cases, gradients are obtained by reparameterizing stochastic samples, z ∼ q ( z | x ) , separating stochastic and deterministic dependencies [30, 50].
The parameters, θ and φ , are learned using gradient-based optimization, with gradients calculated via backpropagation [53].
Connections, Contrasts, and Biological Correspondences
Predictive coding and VAEs are both formulated in terms of hierarchical latent Gaussian models, with non-linear functions parameterizing the conditional dependencies between variables. In the case of predictive coding, these functions are polynomials, whereas VAEs use deep networks, which are composed of layers of linear and non-linear operations.
In predictive coding, Gaussian covariance matrices, e.g. Σ x , are separate parameters, implemented as lateral weights between units at each level. A similar, but more general, mechanism was independently developed for VAEs, known as normalizing ﬂows [49, 29] (Section 4.2).
Both areas have been extended to sequential models. In this setting, predictive coding tends to model dynamics explicitly, directly modeling orders of motion or generalized coordinates [14].
VAEs, in contrast, tend to rely on less rigid forms of dynamics, often using recurrent networks, e.g. [6], though some works have explored structured dynamics [25, 26, 39].
Both areas use gradient-based learning. In practice, however, learning in predictive coding tends to be minimal, while VAEs use learning extensively, scaling to large image and audio datasets, e.g. [48].
Predictive coding and VAEs both use variational inference, setting q ( z | x ) as Gaussian. Predictive coding uses errors (Eq. 2) to perform gradient-based inference, whereas VAEs use amortized inference, learning to infer. This offers a solution to the so-called “weight transport” problem [35] for predictive coding; inference gradients require the Jacobian of the generative model, which includes the transpose of generative weight matrices.
Learning a separate set of inference weights avoids this problem. The beneﬁt of identifying these connections and contrasts is that they link neuroscience, through predictive coding and VAEs, to machine learning (and vice versa). While still under debate [19], biological correspondences of predictive coding have been proposed [2, 27]. Variable estimates and errors are hypothesized to be represented by neural activity (ﬁring rate or potential).
These neurons would occur within the same cortical column, with variable neurons and error neurons in separate cortical layers.
Interneurons could mediate inversion of errors and predictions, as well as lateral inhibition necessary for covariance matrices and attention (Section 4.3). Although many of the biological details remain unclear, one intriguing point emerges from this analysis: following this [Figure] [Figure]
connection, deep networks are analogous to the mappings between neurons at separate levels in the hierarchy.
Thus, deep networks may more closely correspond with (a parallel ensemble of) dendrites.
We discuss this implication (Section 4.1) and others in the following section.  Frontiers 4.1 Backpropagation & Learning The biological correspondence of backpropagation [53] remains an open question.
Backprop requires global information, whereas biology seems to rely largely on local learning rules [23, 42, 5].
A number of biologically-plausible formulations of backprop have been proposed [55, 32, 62, 24, 35], attempting to reconcile this disparity and others. However, recent formulations of learning in latent variable models [4, 34, 60] offer an alternative perspective: prediction errors at each level of the latent hierarchy provide a local signal [13], capable of driving learning of inference and generative weights.
In Section 3, we noted that deep networks appear between each latent level, suggesting a correspondence with dendrites rather than the traditional analogy as networks of neurons. This implies the following set-up: learning across the cortical hierarchy is handled via local errors at each level, whereas learning within the neurons at each level is mediated through a mechanism similar to backpropagation.
Indeed, looking at the literature, we see ample evidence of non-linear dendritic computation [43] and backpropagating action potentials within neurons (Fig. 2a) From this perspective, segmented dendrites [3, 21] for top-down and bottom-up inputs to pyramidal neurons could implement separate inference computations for errors at different levels (Eq. 2). While the mechanisms underlying these processes remain unclear, focusing efforts on formulating biologically plausible backpropagation from this perspective (and not supervised learning) could prove fruitful.
We often consider factorized parametric distributions, as they enable efﬁcient evaluation and sampling.
However, simple distributions are limiting.
Normalizing ﬂows (NFs)
[52, 9, 49] provide added complexity while maintaining tractable evaluation and sampling.
They consist of a tractable base distribution and one or more invertible transforms .
With the base distribution as p θ ( u ) and the transforms as v = f θ ( u ) , the probability p θ ( v ) is given by the change of variables formula:
[Equation]
where det( · ) denotes matrix determinant and | · | denotes absolute value.
The determinant term corrects for the local scaling of space when moving from u to v .
A popular family of transforms is that of autoregressive afﬁne transforms [29, 46].
One example is given by
[Equation]
where v i is the i th dimension of v and α θ and β θ are functions.
The inverse transform (Fig. 2b) is
[Equation]
a normalization (whitening) operation.
Thus, we can sample from complex distributions by starting with simple distributions and applying local afﬁne transforms.
Conversely, we can evaluate inputs from complex distributions by applying normalization transforms, then evaluating in a simpler space.
Local inhibition is ubiquitous in neural systems, thought to implement normalization [12].
These circuits, modeled with subtractive and divisive operations (Eq. 5), give rise to decorrelation in retina [20], LGN [10], and cortex [28].
NFs offer a novel description of these circuits and agree with predictive coding.
For instance, evaluating ﬂow-based conditional likelihoods [1] involves whitening the observations, as performed by Rao & Ballard [47], to remove low-level spatial correlations.
The same principle can be applied across time, where NFs resemble temporal derivatives [39], which are the basis of Friston’s generalized coordinates [14].
Likewise, Friston’s proposal [13] of implementing prior covariance matrices with lateral weights in cortex corresponds to a linear NF [29].
Local inhibition is also present in central pattern generator (CPG) circuits [38], giving rise to correlations in muscle activation. NFs are also being explored in the context of action selection in reinforcement learning [56, 59]. By providing a basis of correlated motor outputs, NFs improve action selection and learning, which can take place in a less correlated space that is easier to model. CPGs would likely be a form of inverse autoregressive ﬂow [29] to maintain efﬁcient sampling.
Predictive coding has proposed that prior covariance matrices, which weight prediction errors, could implement a form of attention [54, 15]. Intuitively, decreasing the variance of a predicted variable pushes the model to more accurately infer and predict that variable. Biologically, this is hypothesized to be implemented via gain modulation of error-encoding neurons, mediated through neurotransmitters and synchronizing gamma oscillations [11].
This attentional control mechanism could bias a model toward representing task-relevant information. Deep latent variable models have largely ignored this functionality; when combined with active components, variances are typically held constant, e g. [22]. Enabling this capacity for task-dependent perceptual modulation may prove useful or even essential in applying deep latent variable models to complex tasks.  Conclusion
We have identiﬁed commonalities between predictive coding and VAEs, discussing new frontiers resulting from this perspective. Reuniting these areas may strengthen the connection between neuroscience and machine learning. Further reﬁning this connection could lead to mutual beneﬁts: neuroscience can offer inspiration for investigation in machine learning and machine learning can evaluate ideas on real-world datasets and environments. Indeed, despite some push back [16] if predictive coding and related theories [17] are to become validated descriptions of the brain and overcome their apparent generality they will likely require the computational tools and ideas of modern machine learning to pin down and empirically compare design choices.