Ensemble Kalman Filtering
Together, predict and filter_update can be used to perform an online EnKF filtering step.
The EnKF uses an ensemble of particles with a Kalman-style measurement update based on empirical covariances. Unlike the EKF, it does not require Jacobians, while naturally handling nonlinear dynamics.
Large observation dimensions
By default, filter_update forms the empirical cross-covariance \(C_{xy}\) and a generalized Cholesky factor of the innovation covariance \(S = C_{yy} + R\), costing \(\mathcal{O}(y_{\rm dim}^3 + N y_{\rm dim} x_{\rm dim})\) and storing arrays of size \(y_{\rm dim}^2\) and \(x_{\rm dim}y_{\rm dim}\).
Passing ensemble_subspace=True instead carries out the analysis in the \(N\)-dimensional subspace spanned by the ensemble, using the Woodbury identity. The update becomes \(X C^{-1} Y^\intercal R^{-1}\delta\) with \(C = I_N + Y^\intercal R^{-1} Y\), so the only factorization is \(N \times N\) and neither \(C_{xy}\), \(S\), nor the Kalman gain is ever formed. The cost is \(\mathcal{O}(N^2 x_{\rm dim} + N^2 y_{\rm dim} + N^3)\) plus the cost of applying \(R^{-1}\). This is algebraically exact and is preferable whenever \(N \ll y_{\rm dim}\); for \(y_{\rm dim} \lesssim N\) the default path is cheaper.
When \(R^{-1}\) is applied by a dense Cholesky factor, this incurs a cost of \(\mathcal{O}(Nd_y^2)\). One can reduce this to \(\mathcal{O}(Nd_y)\) by passing a structured chol_R: a scalar for \(\sigma^2 I\), or a 1D array of length \(y_{\rm dim}\) for a diagonal factor. Note that the default path always requires a 2D chol_R.
Both localization hooks below are rejected with ensemble_subspace=True, as the Woodbury identity is inapplicable with tapering.
cuthbertlib.ensemble_kalman.filtering
Implements the Ensemble Kalman Filter (EnKF) predict and update steps.
See Algorithm 10.2, Sanz-Alonso et al., Inverse Problems and Data Assimilation. Based in part on the CD-Dynamax implementation.
ObservationFn = Callable[[Array], Array]
module-attribute
DynamicsFn = Callable[[Array, KeyArray], Array]
module-attribute
CrossCovarianceModifier = Callable[[Array], Array]
module-attribute
ConstructCholInnovationCovariance = Callable[[Array, Array], Array]
module-attribute
no_covariance_modifier(covariance)
Return an empirical covariance unchanged.
The identity covariance modifier, used as the default when no modification (e.g. localization) is requested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
covariance
|
Array
|
Empirical covariance matrix. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The covariance matrix, unchanged. |
Source code in cuthbertlib/ensemble_kalman/filtering.py
predict(key, ensemble, dynamics_fn, inflation=0.0)
Propagate ensemble members through an arbitrary simulator p(x_{t+1} | x_t).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
KeyArray
|
JAX PRNG key. |
required |
ensemble
|
Array
|
Ensemble of state vectors, shape (N, x_dim). |
required |
dynamics_fn
|
DynamicsFn
|
Dynamics function mapping (state, key) -> state. |
required |
inflation
|
float
|
Multiplicative inflation factor applied to ensemble deviations. |
0.0
|
Returns:
| Type | Description |
|---|---|
Array
|
Predicted ensemble, shape (N, x_dim). |
Source code in cuthbertlib/ensemble_kalman/filtering.py
update(key, predicted_ensemble, observation_fn, chol_R, y, perturbed_obs=True, cross_covariance_modifier=no_covariance_modifier, construct_chol_innovation_covariance=None, ensemble_subspace=False)
Update ensemble members with an observation using the EnKF update.
NaNs in y are treated as missing dimensions and are excluded from the
update. When y is entirely NaN, the update is a no-op: the predicted
ensemble is returned unchanged with zero log-likelihood contribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
KeyArray
|
JAX PRNG key. |
required |
predicted_ensemble
|
Array
|
Predicted ensemble, shape (N, x_dim). |
required |
observation_fn
|
ObservationFn
|
Observation function mapping state -> obs. |
required |
chol_R
|
Array
|
Generalized Cholesky factor of the observation noise covariance,
shape (y_dim, y_dim). Square roots that are not generalized Cholesky
factors, such as a symmetric R ** 0.5, are not supported.
When |
required |
y
|
Array
|
Observation vector, shape (y_dim,). NaNs indicate missing dimensions. |
required |
perturbed_obs
|
bool
|
If True, use perturbed observations (stochastic EnKF). If False, use deterministic update. |
True
|
cross_covariance_modifier
|
CrossCovarianceModifier
|
Function that modifies the empirical state-observation cross-covariance, shape (x_dim, y_dim), and returns an array with the same shape. Defaults to the identity. |
no_covariance_modifier
|
construct_chol_innovation_covariance
|
ConstructCholInnovationCovariance | None
|
Optional function that
receives normalized observation deviations with shape (y_dim, N) and
|
None
|
ensemble_subspace
|
bool
|
If True, perform the analysis in the N-dimensional
ensemble subspace. This is algebraically exact and costs
O(N ** 2 * x_dim) in the state dimension rather than
O(N * x_dim * y_dim), so it is preferable when |
False
|
Returns:
| Type | Description |
|---|---|
tuple[Array, ScalarArray]
|
Tuple of (updated_ensemble, log_likelihood). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in cuthbertlib/ensemble_kalman/filtering.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |