Generalized filtering

From HandWiki
Revision as of 16:15, 6 February 2024 by John Stpola (talk | contribs) (linkage)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Generalized filtering is a generic Bayesian filtering scheme for nonlinear state-space models.[1] It is based on a variational principle of least action, formulated in generalized coordinates of motion.[2] Note that "generalized coordinates of motion" are related to—but distinct from—generalized coordinates as used in (multibody) dynamical systems analysis. Generalized filtering furnishes posterior densities over hidden states (and parameters) generating observed data using a generalized gradient descent on variational free energy, under the Laplace assumption. Unlike classical (e.g. Kalman-Bucy or particle) filtering, generalized filtering eschews Markovian assumptions about random fluctuations. Furthermore, it operates online, assimilating data to approximate the posterior density over unknown quantities, without the need for a backward pass. Special cases include variational filtering,[3] dynamic expectation maximization[4] and generalized predictive coding.

Definition

Definition: Generalized filtering rests on the tuple [math]\displaystyle{ (\Omega,U,X,S,p,q) }[/math]:

  • A sample space [math]\displaystyle{ \Omega }[/math] from which random fluctuations [math]\displaystyle{ \omega \in \Omega }[/math] are drawn
  • Control states [math]\displaystyle{ U \in \mathbb{R} }[/math] – that act as external causes, input or forcing terms
  • Hidden states [math]\displaystyle{ X:X \times U \times \Omega \to \mathbb{R} }[/math] – that cause sensory states and depend on control states
  • Sensor states [math]\displaystyle{ S:X \times U \times \Omega \to \mathbb{R} }[/math] – a probabilistic mapping from hidden and control states
  • Generative density [math]\displaystyle{ p(\tilde{s},\tilde{x},\tilde{u}\mid m) }[/math] – over sensory, hidden and control states under a generative model [math]\displaystyle{ m }[/math]
  • Variational density [math]\displaystyle{ q(\tilde{x},\tilde{u}\mid \tilde{\mu}) }[/math] – over hidden and control states with mean [math]\displaystyle{ \tilde{\mu} \in \mathbb{R} }[/math]


Here ~ denotes a variable in generalized coordinates of motion: [math]\displaystyle{ \tilde{u} = [u,u',u'',\ldots]^T }[/math]

Generalized filtering

The objective is to approximate the posterior density over hidden and control states, given sensor states and a generative model – and estimate the (path integral of) model evidence [math]\displaystyle{ p(\tilde{s}(t)\vert m) }[/math] to compare different models. This generally involves an intractable marginalization over hidden states, so model evidence (or marginal likelihood) is replaced with a variational free energy bound.[5] Given the following definitions:

[math]\displaystyle{ \tilde{\mu}(t) = \underset{\tilde{\mu}}{\operatorname{arg\,min}} \{F(\tilde{{s}}(t),\tilde{{\mu }})\} }[/math]
[math]\displaystyle{ G(\tilde{s},\tilde{x},\tilde{u})=-\ln p(\tilde{s},\tilde{x},\tilde{u}\vert m) }[/math]

Denote the Shannon entropy of the density [math]\displaystyle{ q }[/math] by [math]\displaystyle{ H[q]=E_q[-\log(q)] }[/math]. We can then write the variational free energy in two ways:

[math]\displaystyle{ F(\tilde{s}, \tilde\mu)=E_q [G(\tilde{s},\tilde{x},\tilde{u})]-H[q(\tilde{x},\tilde{u} \vert \tilde{\mu})] =-\ln p(\tilde{s} \vert m)+D_{KL} [q(\tilde{x},\tilde{u} \vert \tilde{\mu})\vert \vert p(\tilde{x},\tilde{u} \vert \tilde{s},m)] }[/math]

The second equality shows that minimizing variational free energy (i) minimizes the Kullback-Leibler divergence between the variational and true posterior density and (ii) renders the variational free energy (a bound approximation to) the negative log evidence (because the divergence can never be less than zero).[6] Under the Laplace assumption [math]\displaystyle{ q(\tilde{x},\tilde{{u}}\mid \tilde{\mu})=\mathcal{N}(\tilde{\mu},C) }[/math] the variational density is Gaussian and the precision that minimizes free energy is [math]\displaystyle{ C^{-1}=\Pi =\partial_{\tilde{\mu}\tilde{\mu}} G(\tilde{\mu}) }[/math]. This means that free-energy can be expressed in terms of the variational mean [7] (omitting constants):

[math]\displaystyle{ F=G(\tilde{\mu})+\textstyle{1 \over 2}\ln \vert \partial_{\tilde{\mu}\tilde{\mu}} G(\tilde{\mu})\vert }[/math]

The variational means that minimize the (path integral) of free energy can now be recovered by solving the generalized filter:

[math]\displaystyle{ \dot{\tilde{\mu}}=D\tilde{\mu}-\partial_{\tilde{\mu}} F(\tilde{s},\tilde{\mu}) }[/math]

where [math]\displaystyle{ D }[/math] is a block matrix derivative operator of identify matrices such that [math]\displaystyle{ D\tilde{u}=[u',u'',\ldots ]^T }[/math]

Variational basis

Generalized filtering is based on the following lemma: The self-consistent solution to [math]\displaystyle{ \dot{\tilde{\mu}}=D\tilde{\mu}-\partial_{\tilde{\mu}} F(s,\tilde{\mu}) }[/math] satisfies the variational principle of stationary action, where action is the path integral of variational free energy

[math]\displaystyle{ S=\int dt\, F(\tilde{s}(t),\tilde{\mu}(t)) }[/math]

Proof: self-consistency requires the motion of the mean to be the mean of the motion and (by the fundamental lemma of variational calculus)

[math]\displaystyle{ \dot{\tilde{\mu}} = D\tilde{\mu}\Leftrightarrow \partial_{\tilde{\mu}} F(\tilde{s},\tilde{\mu}) = 0\Leftrightarrow \delta_{\tilde{\mu}} S=0 }[/math]

Put simply, small perturbations to the path of the mean do not change variational free energy and it has the least action of all possible (local) paths.

Remarks: Heuristically, generalized filtering performs a gradient descent on variational free energy in a moving frame of reference: [math]\displaystyle{ \dot{{\tilde{{\mu }}}}-D\tilde{{\mu }}=-\partial_{\tilde{\mu}} F(s,\tilde{\mu}) }[/math], where the frame itself minimizes variational free energy. For a related example in statistical physics, see Kerr and Graham [8] who use ensemble dynamics in generalized coordinates to provide a generalized phase-space version of Langevin and associated Fokker-Planck equations.

In practice, generalized filtering uses local linearization[9] over intervals [math]\displaystyle{ \Delta t }[/math] to recover discrete updates

[math]\displaystyle{ \begin{align} \Delta \tilde{\mu} & =(\exp (\Delta t\cdot J)-I)J^{-1}\dot{\tilde{\mu}} \\ J & =\partial_{\tilde{\mu}} \dot{\tilde{\mu}} =D-\partial _{\tilde{\mu}\tilde{\mu}} F(\tilde{s},\tilde{\mu}) \end{align} }[/math]

This updates the means of hidden variables at each interval (usually the interval between observations).

Generative (state-space) models in generalized coordinates

Usually, the generative density or model is specified in terms of a nonlinear input-state-output model with continuous nonlinear functions:

[math]\displaystyle{ \begin{align} s & = g(x,u)+\omega_s \\ \dot{{x}} & = f(x,u)+\omega_x \end{align} }[/math]

The corresponding generalized model (under local linearity assumptions) obtains the from the chain rule

[math]\displaystyle{ \begin{align} \tilde{s} & =\tilde{g}(\tilde{x},\tilde{u})+\tilde{\omega}_s \\ \\ s & =g(x,u)+\omega_s \\ s' & =\partial_x g\cdot x'+\partial_u g\cdot u'+\omega'_s \\ s'' & =\partial_x g\cdot x''+\partial_u g\cdot u''+\omega''_s \\ & \vdots \\ \end{align} \qquad \begin{align} \dot{\tilde{x}} & =\tilde{f}(\tilde{x},\tilde{u})+\tilde{\omega}_x \\ \\ \dot{x} & =f(x,u)+\omega_x \\ \dot{x}' & =\partial_x f\cdot x'+\partial_u f\cdot u'+\omega'_x \\ \dot{x}''& =\partial_x f\cdot x''+\partial_u f\cdot u''+\omega''_x \\ & \vdots \end{align} }[/math]

Gaussian assumptions about the random fluctuations [math]\displaystyle{ \omega }[/math] then prescribe the likelihood and empirical priors on the motion of hidden states

[math]\displaystyle{ \begin{align} p\left( \tilde{s},\tilde{x},\tilde{u}\vert m \right) & = p\left( \tilde{s}\vert \tilde{x},\tilde{u},m \right)p\left( {D\tilde{x}\vert x,\tilde{u},m} \right)p(x\vert m)p(\tilde{u}\vert m) \\ p\left( \tilde{s}\vert \tilde{x},\tilde{u},m \right) & = \mathcal{N}(\tilde{g}(\tilde{x},\tilde{u}),\tilde{\Sigma}(\tilde{x},\tilde{u})_s) \\ p\left( {D\tilde{{x}}\vert x,\tilde{{u}},m} \right) & = {\mathcal{N}}(\tilde{f}(\tilde{x},\tilde{u}),\tilde{\Sigma}(\tilde{x},\tilde{u})_x ) \\ \end{align} }[/math]

The covariances [math]\displaystyle{ \tilde{{\Sigma }}=V\otimes \Sigma }[/math] factorize into a covariance among variables and correlations [math]\displaystyle{ V }[/math] among generalized fluctuations that encodes their autocorrelation:

[math]\displaystyle{ V=\begin{bmatrix} 1 & 0 & \ddot{\rho}(0) & \cdots \\ 0 & -\ddot{\rho}(0) & 0 \ & \ \\ \ddot{\rho}(0) \ & 0 \ & \ddot{\ddot{\rho}}(0) \ & \ \\ \vdots \ & \ & \ & \ddots \ \\ \end{bmatrix} }[/math]

Here, [math]\displaystyle{ \ddot{{\rho }}(0) }[/math] is the second derivative of the autocorrelation function evaluated at zero. This is a ubiquitous measure of roughness in the theory of stochastic processes.[10] Crucially, the precision (inverse variance) of high order derivatives fall to zero fairly quickly, which means it is only necessary to model relatively low order generalized motion (usually between two and eight) for any given or parameterized autocorrelation function.

Special cases

Filtering discrete time series

When time series are observed as a discrete sequence of [math]\displaystyle{ N }[/math] observations, the implicit sampling is treated as part of the generative process, where (using Taylor's theorem)

[math]\displaystyle{ [s_1 ,\dots ,s_N ]^T = (E\otimes I)\cdot \tilde{s}(t): \qquad E_{ij} =\frac{(i-t)^{(j-1)}}{(j-1)!} }[/math]

In principle, the entire sequence could be used to estimate hidden variables at each point in time. However, the precision of samples in the past and future falls quickly and can be ignored. This allows the scheme to assimilate data online, using local observations around each time point (typically between two and eight).

Generalized filtering and model parameters

For any slowly varying model parameters of the equations of motion [math]\displaystyle{ f(x,u,\theta ) }[/math] or precision [math]\displaystyle{ \tilde{{\Pi }}(x,u,\theta ) }[/math] generalized filtering takes the following form (where [math]\displaystyle{ \mu }[/math] corresponds to the variational mean of the parameters)

[math]\displaystyle{ \begin{align} \dot{\mu} & = \mu' \\ \dot{\mu'} & = -\partial_\mu F(\tilde{s},\mu )-\kappa \mu' \end{align} }[/math]

Here, the solution [math]\displaystyle{ \dot{{\tilde{{\mu }}}}=0 }[/math] minimizes variational free energy, when the motion of the mean is small. This can be seen by noting [math]\displaystyle{ \dot{{\mu }}={\dot{{\mu }}}'=0\Rightarrow \partial_{\mu } F=0\Rightarrow \delta_{\mu } S=0 }[/math]. It is straightforward to show that this solution corresponds to a classical Newton update.[11]

Relationship to Bayesian filtering and predictive coding

Generalized filtering and Kalman filtering

Classical filtering under Markovian or Wiener assumptions is equivalent to assuming the precision of the motion of random fluctuations is zero. In this limiting case, one only has to consider the states and their first derivative [math]\displaystyle{ \tilde{{\mu }}=(\mu ,{\mu }') }[/math]. This means generalized filtering takes the form of a Kalman-Bucy filter, with prediction and correction terms:

[math]\displaystyle{ \begin{align} \dot{\mu} & = \mu'-\partial_\mu F(s,\tilde{\mu}) \\ \dot{\mu'} & =-\partial_{\mu'} F(s,\tilde{\mu}) \end{align} }[/math]

Substituting this first-order filtering into the discrete update scheme above gives the equivalent of (extended) Kalman filtering.[12]

Generalized filtering and particle filtering

Particle filtering is a sampling-based scheme that relaxes assumptions about the form of the variational or approximate posterior density. The corresponding generalized filtering scheme is called variational filtering.[3] In variational filtering, an ensemble of particles diffuse over the free energy landscape in a frame of reference that moves with the expected (generalized) motion of the ensemble. This provides a relatively simple scheme that eschews Gaussian (unimodal) assumptions. Unlike particle filtering it does not require proposal densities—or the elimination or creation of particles.

Generalized filtering and variational Bayes

Variational Bayes rests on a mean field partition of the variational density:

[math]\displaystyle{ q(\tilde{x},\tilde{u},\theta \dots \vert \tilde{\mu},\mu )=q(\tilde{x},\tilde{u}\vert \tilde{\mu})q(\theta \vert \mu )\dots }[/math]

This partition induces a variational update or step for each marginal density—that is usually solved analytically using conjugate priors. In generalized filtering, this leads to dynamic expectation maximisation.[4] that comprises a D-step that optimizes the sufficient statistics of unknown states, an E-step for parameters and an M-step for precisions.

Generalized filtering and predictive coding

Generalized filtering is usually used to invert hierarchical models of the following form

[math]\displaystyle{ \begin{align} \tilde{s} & =\tilde{{g}}^1 (\tilde{x}^1,\tilde{u}^{(1)})+\tilde{\omega}_s^{(1)} \\ \dot{\tilde{x}}^{(1)} & =\tilde{f}^{(1)}(\tilde{x}^{(1)},\tilde{u}^{(1)})+\tilde{\omega}_{x}^{(1)} \\ \vdots \\ \tilde{u}^{(i-1)} & =\tilde{g}^{(i)}(\tilde{x}^{(i)},\tilde{u}^{(i)})+\tilde{\omega}_u^{(i)} \\ \dot{\tilde{x}}^{(i)} & =\tilde{f}^{(i)}(\tilde{x}^{(i)},\tilde{u}^{(i)})+\tilde{\omega}_x^{(i)} \\ \vdots \end{align} }[/math]

The ensuing generalized gradient descent on free energy can then be expressed compactly in terms of prediction errors, where (omitting high order terms):

[math]\displaystyle{ \begin{align} \dot{\tilde{\mu}}_u^{(i)} & =D\tilde{\mu}^{(u,i)}-\partial_u \tilde{\varepsilon}^{(i)}\cdot \Pi^{(i)}\tilde{\varepsilon}^{(i)} -\Pi^{(i+1)}\tilde{\varepsilon}_u^{(i+1)} \\ \dot{\tilde{\mu}}_x^{(i)} & =D\tilde{\mu}^{(x,i)}-\partial_x \tilde{\varepsilon}^{(i)}\cdot \Pi^{(i)}\tilde{\varepsilon}^{(i)} \\ \\ \tilde{\varepsilon}_u^{(i)} & =\tilde{\mu}_u^{(i-1)} -\tilde{g}^{(i)} \\ \tilde{\varepsilon}_x^{(i)} & =D\tilde{\mu}_x^{(i)} -\tilde{f}^{(i)} \end{align} }[/math]

Here, [math]\displaystyle{ \Pi^{(i)} }[/math] is the precision of random fluctuations at the i-th level. This is known as generalized predictive coding [11], with linear predictive coding as a special case.

Applications

Generalized filtering has been primarily applied to biological timeseries—in particular functional magnetic resonance imaging and electrophysiological data. This is usually in the context of dynamic causal modelling to make inferences about the underlying architectures of (neuronal) systems generating data.[13] It is also used to simulate inference in terms of generalized (hierarchical) predictive coding in the brain.[14]

See also

References

  1. K Friston, K Stephan, B Li, and J. Daunizeau, "Generalised Filtering," Mathematical Problems in Engineering, vol. vol., 2010, p. 621670, 2010.
  2. B Balaji and K Friston, "Bayesian state estimation using generalized coordinates," Proc. SPIE, p. 80501Y, 2011
  3. 3.0 3.1 K J Friston, "Variational filtering," Neuroimage, vol. 41, no. 3, pp. 747-66, 2008.
  4. 4.0 4.1 K J Friston, N Trujillo-Barreto, and J Daunizeau, "DEM: A variational treatment of dynamic systems," Neuroimage, vol. 41, no. 3, pp. 849-85, 2008
  5. R P Feynman, Statistical mechanics. Reading MA: Benjamin, 1972
  6. M J Beal, "Variational Algorithms for Approximate Bayesian Inference," PhD. Thesis, University College London, 2003.
  7. K Friston, J Mattout, N Trujillo-Barreto, J Ashburner, and W Penny, "Variational free energy and the Laplace approximation," NeuroImage, vol. 34, no. 1, pp. 220-34, 2007
  8. W C Kerr and A J Graham, "Generalised phase space version of Langevin equations and associated Fokker-Planck equations," Eur. Phys. J. B., vol. 15, pp. 305-11, 2000.
  9. T Ozaki, "A bridge between nonlinear time-series models and nonlinear stochastic dynamical systems: A local linearization approach," Statistica Sin., vol. 2, pp. 113-135, 1992
  10. D R Cox and H D Miller, The theory of stochastic processes. London: Methuen, 1965.
  11. K Friston, K Stephan, B Li, and J. Daunizeau, "Generalised Filtering," Mathematical Problems in Engineering, vol. vol., 2010, p. 621670, 2010.
  12. K J Friston, N Trujillo-Barreto, and J Daunizeau, "DEM: A variational treatment of dynamic systems," Neuroimage, vol. 41, no. 3, pp. 849-85, 2008
  13. J Daunizeau, O David, and K E Stephan, "Dynamic causal modelling: a critical review of the biophysical and statistical foundations ," Neuroimage, vol. 58, no. 2, pp. 312-22, 2011
  14. K Friston, "Hierarchical models in the brain," PLoS Comput. Biol., vol. 4, no. 11, p. e1000211, 2008.

External links

  • software demonstrations and applications are available as academic freeware (as Matlab code) in the DEM toolbox of SPM
  • papers collection of technical and application papers