Kalman filter Let \mathbf{x} denote the n-dimensional
state vector of a model, and assume that it has
Gaussian probability distribution with mean \mathbf{\mu} and covariance Q, i.e., its PDF is : p(\mathbf{x})\propto\exp\left( -\frac{1}{2}(\mathbf{x}-\mathbf{\mu })^{\mathrm{T}}Q^{-1}(\mathbf{x}-\mathbf{\mu})\right) . Here and below, \propto means proportional; a PDF is always scaled so that its integral over the whole space is one. This p(\mathbf{x}), called the
prior, was evolved in time by running the model and now is to be updated to account for new data. It is natural to assume that the error distribution of the data is known; data have to come with an error estimate, otherwise they are meaningless. Here, the data \mathbf{d} is assumed to have Gaussian PDF with covariance R and mean H\mathbf{x}, where H is the so-called
observation matrix. The covariance matrix R describes the estimate of the error of the data; if the random errors in the entries of the data vector \mathbf{d} are independent, R is diagonal and its diagonal entries are the squares of the
standard deviation (“error size”) of the error of the corresponding entries of the data vector \mathbf{d}. The value H\mathbf{x} is what the value of the data would be for the state \mathbf{x} in the absence of data errors. Then the probability density p(\mathbf{d}|\mathbf{x}) of the data \mathbf{d} conditional of the system state \mathbf{x}, called the
data likelihood, is : p\left( \mathbf{d}|\mathbf{x}\right) \propto\exp\left( -\frac{1}{2}(\mathbf{d}-H\mathbf{x})^{\mathrm{T}}R^{-1}(\mathbf{d}-H\mathbf{x})\right) . The PDF of the state and the
data likelihood are combined to give the new probability density of the system state \mathbf{x} conditional on the value of the data \mathbf{d} (the
posterior) by the
Bayes' theorem, : p\left( \mathbf{x}|\mathbf{d}\right) \propto p\left( \mathbf{d}|\mathbf{x}\right) p(\mathbf{x}). The data \mathbf{d} is fixed once it is received, so denote the posterior state by \mathbf{\hat{x}} instead of \mathbf{x}|\mathbf{d} and the posterior PDF by p\left( \mathbf{\hat{x}}\right) . It can be shown by algebraic manipulations that the posterior PDF is also Gaussian, : p\left( \mathbf{\hat{x}}\right) \propto\exp\left( -\frac{1}{2}(\mathbf{\hat{x}}-\mathbf{\hat{\mu}})^{\mathrm{T}}\hat{Q}^{-1}(\mathbf{\hat{x}}-\mathbf{\hat{\mu}})\right) , with the posterior mean \mathbf{\hat{\mu}} and covariance \hat{Q} given by the Kalman update formulas : \mathbf{\hat{\mu}}=\mathbf{\mu}+K\left( \mathbf{d}-H\mathbf{\mu}\right) ,\quad\hat{Q}=\left( I-KH\right) Q, where : K=QH^{\mathrm{T}}\left( HQH^{\mathrm{T}}+R\right) ^{-1} is the so-called
Kalman gain matrix.
Ensemble Kalman Filter The EnKF is a Monte Carlo approximation of the Kalman filter, which avoids evolving the covariance matrix of the PDF of the state vector \mathbf{x}. Instead, the PDF is represented by an ensemble : X=\left[ \mathbf{x}_{1},\ldots,\mathbf{x}_{N}\right] =\left[ \mathbf{x}_{i}\right]. X is an n\times N matrix whose columns are the ensemble members, and it is called the
prior ensemble. Ideally, ensemble members would form a
sample from the prior distribution. However, the ensemble members are not in general
independent except in the initial ensemble, since every EnKF step ties them together. They are deemed to be approximately independent, and all calculations proceed as if they actually were independent. Replicate the data \mathbf{d} into an m\times N matrix : D=\left[ \mathbf{d}_{1},\ldots,\mathbf{d}_{N}\right] =\left[ \mathbf{d}_{i}\right], \quad \mathbf{d}_{i}=\mathbf{d}+\mathbf{\epsilon_{i}}, \quad \mathbf{\epsilon_{i}} \sim N(0,R), so that each column \mathbf{d}_{i} consists of the data vector \mathbf{d} plus a
random vector from the m-dimensional normal distribution N(0,R). If, in addition, the columns of X are a sample from the
prior probability distribution, then the columns of : \hat{X}=X+K(D-HX) form a sample from the
posterior probability distribution. To see this in the scalar case with H=1: Let x_i = \mu + \xi_i, \; \xi_i \sim N(0, \sigma_x^2), and d_i = d + \epsilon_i, \; \epsilon_i \sim N(0, \sigma_d^2). Then :\hat{x}_i = \left(\frac{1/\sigma_x^2}{1/\sigma_x^2 + 1/\sigma_d^2} \mu + \frac{1/\sigma_d^2}{1/\sigma_x^2 + 1/\sigma_d^2} d \right)+ \left(\frac{1/\sigma_x^2}{1/\sigma_x^2 + 1/\sigma_d^2} \xi_i + \frac{1/\sigma_d^2}{1/\sigma_x^2 + 1/\sigma_d^2} \epsilon_i \right) . The first sum is the posterior mean, and the second sum, in view of the independence, has a variance :\left(\frac{1/\sigma_x^2}{1/\sigma_x^2 + 1/\sigma_d^2}\right)^2 \sigma_x^2 + \left(\frac{1/\sigma_d^2}{1/\sigma_x^2 + 1/\sigma_d^2}\right)^2 \sigma_d^2 = \frac{1}{1/\sigma_x^2 + 1/\sigma_d^2}, which is the posterior variance. The EnKF is now obtained simply by replacing the state covariance Q in Kalman gain matrix K by the sample covariance C computed from the ensemble members (called the
ensemble covariance), that is: K=CH^{\mathrm{T}}\left( HCH^{\mathrm{T}}+R\right) ^{-1} ==Implementation==