Tutorials › Stochastic Differential Equations in Pharmacokinetics › EKF Updates with Nonlinear Concentration Measurements

Kalman Filter and Extended Kalman Filter · Tutorial 65 of 100

EKF Updates with Nonlinear Concentration Measurements

Learn how to linearize a nonlinear assay around the predicted state, calculate the EKF update, and diagnose when its local Gaussian approximation is unreliable.

Advanced 11 min read

What You'll Learn

  • Linearize a differentiable assay function at the predicted state mean.
  • Calculate the observation Jacobian, innovation, innovation covariance, and Kalman gain.
  • Derive the mean and covariance update for the linearized Gaussian observation model.
  • Distinguish exact conditioning in that surrogate model from approximate inference under the original nonlinear assay.
  • Diagnose misleading updates using standardized innovations and physical constraints.
  • Compare the EKF with linear filtering and other nonlinear measurement approaches.

Why a Nonlinear Assay Changes the Update

In a linear Gaussian state-space model, the measurement update conditions a Gaussian state distribution on a linear observation. Many concentration assays do not have that form: their expected response may saturate at high concentration, transform concentration to a signal, or combine concentrations through a nonlinear calibration curve. The extended Kalman filter (EKF) handles such an observation by replacing it locally with a linear function, then applying a Gaussian update to that approximation.

The result depends on where the assay is linearized. The observation Jacobian describes local sensitivity at the predicted state mean, while the innovation covariance accounts for both uncertainty in the predicted state and assay error. These quantities are useful diagnostics as well as ingredients in the update.

Definition: Let \(X\) be a \(d\)-dimensional state with predicted mean \(m^-\) and covariance \(P^-\), and let the \(q\)-dimensional measurement be \(Z=h(X)+V\). The function \(h:\mathbb R^d\to\mathbb R^q\) is differentiable at \(m^-\). The observation noise \(V\sim N(0,R)\) is independent of \(X\), with \(R\) positive definite. The EKF linearizes the measurement function at \(m^-\), using \(H=\left.\frac{\partial h(x)}{\partial x^\mathsf T}\right|_{x=m^-}\), the \(q\times d\) observation Jacobian.

The predicted distribution used for the update is usually supplied by the state-prediction step. For the derivation below, assume it is Gaussian, \(X\sim N(m^-,P^-)\), with \(P^-\) positive definite. The assay noise is Gaussian as specified above. These assumptions make conditioning on the linearized observation exact for that surrogate model. They do not make the update exact for the original nonlinear observation.

The Local Measurement Model and EKF Formulas

A first-order Taylor expansion of \(h\) around \(m^-\) gives

$$ h(X)\approx h(m^-)+H(X-m^-). $$

For an observed value \(z\), define the innovation \(r=z-h(m^-)\). Under the linearized model, \(Z-h(m^-)\) is approximately \(H(X-m^-)+V\). Its mean is zero and its covariance is \(S=HP^-H^\mathsf T+R\), called the innovation covariance. Since \(R\) is positive definite, \(S\) is positive definite and invertible.

$$ K=P^-H^\mathsf T S^{-1},\qquad m^+=m^-+Kr,\qquad P^+=P^- - P^-H^\mathsf T S^{-1}HP^-. $$

Here \(K\) is the Kalman gain, \(m^+\) is the updated state mean, and \(P^+\) is the updated state covariance. The gain maps the measurement discrepancy into a state correction. Its size and direction depend on prior state uncertainty, assay sensitivity, and measurement noise.

Worked Example: A Saturating Assay for One Concentration

Suppose the concentration state has predicted distribution \(C\sim N(2,0.25)\). A normalized saturating assay has mean response \(h(C)=C/(1+C)\), and the observed response is \(z=0.70\). The assay-error variance is \(R=0.01\). Calculate the EKF update.

At the predicted mean, \(h(2)=2/3\), so the innovation is \(r=0.70-2/3=1/30\approx0.03333\). The derivative is \(h'(C)=1/(1+C)^2\), giving \(H=h'(2)=1/9\).

The innovation covariance is \(S=H^2P^-+R=(1/81)(0.25)+0.01=1/324+1/100=53/4050\approx0.0130864\). Thus the gain is \(K=(0.25)(1/9)/S=112.5/53\approx2.12264\).

The updated mean is \(m^+=2+(2.12264)(1/30)\approx2.07075\). For the scalar covariance, \(P^+=P^- - (P^-H)^2/S=0.25-(1/36)^2/(53/4050)\approx0.19104\). The assay response is only moderately sensitive near \(C=2\), so the update shifts the concentration modestly despite a positive residual. The covariance decreases because the measurement supplies information under the linearized model.

Why the Formulas Hold for the Linearized Model

The Taylor approximation defines an affine observation model. Conditional on the Gaussian predicted state and independent Gaussian assay error, that model is jointly Gaussian with the state. The following derivation makes clear both why the update has its familiar form and what its exactness applies to.

Theorem: Suppose \(X\sim N(m^-,P^-)\) with \(P^-\) positive definite, \(V\sim N(0,R)\) independently with \(R\) positive definite, and replace \(h(X)\) by \(h(m^-)+H(X-m^-)\). Then the conditional mean and covariance of \(X\) given \(Z=z\) in this affine observation model are \(m^+=m^-+P^-H^\mathsf T S^{-1}r\) and \(P^+=P^- - P^-H^\mathsf T S^{-1}HP^-\), where \(r=z-h(m^-)\) and \(S=HP^-H^\mathsf T+R\).

To derive the result, write \(u=X-m^-\). The prior density contributes a quadratic term \(u^\mathsf T(P^-)^{-1}u\) to the negative twice-log-density. The observation likelihood contributes \((r-Hu)^\mathsf T R^{-1}(r-Hu)\). Collecting the terms that depend on \(u\) gives

$$ u^\mathsf T\big((P^-)^{-1}+H^\mathsf T R^{-1}H\big)u -2u^\mathsf T H^\mathsf T R^{-1}r. $$

Completing the square shows that the conditional covariance is \(C=((P^-)^{-1}+H^\mathsf T R^{-1}H)^{-1}\), and the conditional mean displacement \(\delta\) solves \(((P^-)^{-1}+H^\mathsf T R^{-1}H)\delta=H^\mathsf T R^{-1}r\). Set \(\delta=P^-H^\mathsf T S^{-1}r\). Substitution into the left side gives \(H^\mathsf T S^{-1}r+H^\mathsf T R^{-1}HP^-H^\mathsf T S^{-1}r\). Since \(HP^-H^\mathsf T=S-R\), this equals \(H^\mathsf T S^{-1}r+H^\mathsf T R^{-1}(S-R)S^{-1}r=H^\mathsf T R^{-1}r\). Thus the displacement is \(Kr\).

The covariance identity \(C=P^- -P^-H^\mathsf T S^{-1}HP^-\) follows by multiplying the right-hand side by \((P^-)^{-1}+H^\mathsf T R^{-1}H\), which yields the identity matrix. Therefore \(C=P^+\), proving the stated formulas for the affine model. Since the original model uses \(h(X)\), not its affine approximation, this proof does not establish exact conditional moments for the original nonlinear model. \(\square\)

State Uncertainty and a Correlated Two-Compartment Example

The covariance update has a useful equivalent form. In the affine model, the updated error is the prior error after applying the gain, minus the part explained by the observation. More explicitly, if the prior estimation error is \(e^-=X-m^-\), then the updated error is \(e^+=(I-KH)e^- - KV\). Independence of \(e^-\) and \(V\) gives

$$ P^+=(I-KH)P^-(I-KH)^\mathsf T+KRK^\mathsf T =P^- -P^-H^\mathsf T S^{-1}HP^-. $$

The first expression, often called the Joseph form, makes nonnegative covariance contributions visible and can be more stable in numerical computation. The second expression makes the uncertainty reduction transparent. For any vector \(a\), \(a^\mathsf T(P^- -P^+)a=(HP^-a)^\mathsf T S^{-1}(HP^-a)\geq0\). Thus the update cannot increase uncertainty in any linear combination of states in this affine Gaussian model.

Worked Example: An Assay of Total Concentration

Let the state be \(X=(C_1,C_2)^\mathsf T\), with predicted mean \((1,2)^\mathsf T\) and covariance \(P^-=\begin{pmatrix}0.16&0.04\\0.04&0.25\end{pmatrix}\). An assay responds to total concentration through \(h(X)=(C_1+C_2)/(1+C_1+C_2)\). The observed response is \(z=0.80\), and \(R=0.0025\).

At total concentration 3, the predicted response is \(h(m^-)=3/4=0.75\), so \(r=0.05\). Differentiating with respect to either component gives \(1/(1+C_1+C_2)^2\), hence \(H=(1/16,1/16)\).

The scalar \(HP^-H^\mathsf T\) is \((1/256)(0.16+0.04+0.04+0.25)=0.49/256=0.0019140625\). Therefore \(S=0.0019140625+0.0025=0.0044140625\). Also, \(P^-H^\mathsf T=(0.0125,0.018125)^\mathsf T\), so \(K\approx(2.83186,4.10619)^\mathsf T\).

The updated mean is \((1,2)^\mathsf T+K(0.05)\approx(1.14159,2.20531)^\mathsf T\). For the covariance, subtract \((P^-H^\mathsf T)(P^-H^\mathsf T)^\mathsf T/S\) from \(P^-\):

$$ P^+\approx \begin{pmatrix} 0.12460&-0.01133\\ -0.01133&0.17558 \end{pmatrix}. $$

The assay measures total concentration, not the two components separately. The update raises both component means because the response exceeds its prediction, while the negative updated covariance reflects their shared contribution to the measured total. A negative covariance is not itself an error; the covariance matrix must be positive semidefinite, not entrywise nonnegative.

Diagnostics, Alternatives, and Limits

A small residual does not by itself guarantee a reliable update. The EKF uses the slope at one point to represent the assay over the range of plausible states. That approximation is suspect when the prior uncertainty spans strong curvature, a saturation plateau, a threshold, or a physical boundary. Useful checks include the predicted response \(h(m^-)\), the innovation \(r\), the innovation standard deviation \(\sqrt{S}\), and whether the updated state remains physically plausible. The standardized innovation \(r/\sqrt{S}\) is a discrepancy scaled by both predicted state uncertainty and assay error; a large magnitude signals tension with the predicted measurement distribution, though it does not identify the cause by itself.

For example, let \(C\) have predicted mean 1 and variance 0.04, use \(h(C)=C/(1+C)\), and observe \(z=0.04\) with \(R=0.0001\). Here \(h(1)=0.5\), \(H=1/4\), and \(r=-0.46\). The innovation variance is \(S=(1/16)(0.04)+0.0001=0.0026\), so \(\sqrt S\approx0.05099\), and the standardized innovation is about \(-9.02\). The gain is \(K=(0.04)(0.25)/0.0026\approx3.84615\), yielding \(m^+=1+3.84615(-0.46)\approx-0.76923\). The covariance becomes \(P^+=0.04-(0.01)^2/0.0026\approx0.001538\). The very small updated variance does not rescue the physically implausible negative mean: this is a warning that the local approximation is inappropriate for this observation.

The assay response at \(C=0\) is zero. The observed value \(0.04\) is therefore four assay-error standard deviations above that baseline, because \(\sqrt R=0.01\). This is distinct from the innovation at the predicted mean: relative to the predicted response of \(0.5\), the residual is \(-0.46\). Keeping the baseline residual, the prior-prediction innovation, and their different uncertainty scales separate prevents misstatements about standardized discrepancies.

When \(h\) is linear, the ordinary Kalman filter gives the exact Gaussian update under the same Gaussian assumptions. For a genuinely nonlinear \(h\), the EKF is a first-order, moment-based approximation. Iterated linearization can reconsider the expansion point, while sigma-point methods approximate nonlinear transformations using selected points rather than one Jacobian. Direct integration of the nonlinear likelihood is another option when accuracy matters and the state dimension permits it. These alternatives do not make the EKF formulas exact for the original nonlinear model.

The EKF is most defensible when the predicted state is reasonably concentrated around \(m^-\), the assay function is smooth over that region, and the resulting update respects the model's physical constraints. It can mislead when the response is nearly flat, when multiple state values produce similar assay responses, or when a local Gaussian update crosses a boundary such as zero concentration. In those cases, inspect the observation model and uncertainty assumptions rather than interpreting a numerically precise \(P^+\) as proof of a reliable approximation.

Key takeaway: The EKF measurement update uses \(H\), \(S\), and \(K\) to condition a Gaussian prior on a locally linearized assay. Its formulas are exact for that affine Gaussian surrogate, but only approximate for the original nonlinear concentration measurement.

Check Your Understanding

Try each question, then compare your reasoning with the solutions.

  1. For \(h(C)=C/(2+C)\), find the observation Jacobian at predicted mean \(C=2\).
  2. In the scalar case, explain why increasing \(R\) while holding other quantities fixed generally reduces the magnitude of the gain.
  3. Suppose \(P^-=0.5\), \(H=2\), and \(R=1\). Calculate \(S\) and \(K\).
  4. Does a positive definite prior covariance guarantee a positive updated mean concentration? Explain.

Solutions. (1) Differentiate: \(h'(C)=2/(2+C)^2\), so \(H=h'(2)=2/16=1/8\). (2) In the scalar case, \(K=P^-H/(H^2P^-+R)\). For fixed \(P^-\) and \(H\), increasing positive \(R\) increases the denominator without changing the numerator, reducing \(|K|\); the observation has less influence. (3) \(S=H^2P^-+R=4(0.5)+1=3\), and \(K=P^-H/S=(0.5)(2)/3=1/3\). (4) No. The update adds \(Kr\), whose sign and size depend on the observation. As the negative-mean example shows, a locally Gaussian update can violate a physical boundary even when the prior covariance is positive definite.

Clinical Biostats