cuthbertlib 0.0.12__tar.gz → 0.0.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/PKG-INFO +1 -1
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/__init__.py +1 -1
- cuthbertlib-0.0.14/cuthbertlib/ensemble_kalman/README.md +15 -0
- cuthbertlib-0.0.14/cuthbertlib/ensemble_kalman/__init__.py +3 -0
- cuthbertlib-0.0.14/cuthbertlib/ensemble_kalman/smoothing.py +36 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linearize/moments.py +2 -2
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/protocols.py +3 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/pyproject.toml +1 -1
- cuthbertlib-0.0.12/cuthbertlib/enkf/README.md +0 -14
- cuthbertlib-0.0.12/cuthbertlib/enkf/__init__.py +0 -1
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/.gitignore +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/discrete/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/discrete/filtering.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/discrete/smoothing.py +0 -0
- {cuthbertlib-0.0.12/cuthbertlib/enkf → cuthbertlib-0.0.14/cuthbertlib/ensemble_kalman}/filtering.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/kalman/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/kalman/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/kalman/filtering.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/kalman/generate.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/kalman/sampling.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/kalman/smoothing.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linalg/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linalg/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linalg/collect_nans_chol.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linalg/marginal_sqrt_cov.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linalg/symmetric_inv_sqrt.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linalg/tria.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linearize/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linearize/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linearize/log_density.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/linearize/taylor.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/common.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/cubature.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/gauss_hermite.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/linearize.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/unscented.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/quadrature/utils.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/adaptive.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/autodiff.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/killing.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/multinomial.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/no_resampling.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/systematic.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/resampling/utils.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/ess.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/smoothing/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/smoothing/exact_sampling.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/smoothing/mcmc.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/smoothing/protocols.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/smc/smoothing/tracing.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/stats/README.md +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/stats/__init__.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/stats/multivariate_normal.py +0 -0
- {cuthbertlib-0.0.12 → cuthbertlib-0.0.14}/cuthbertlib/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cuthbertlib
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.14
|
|
4
4
|
Summary: Atomic building blocks for state-space model inference with JAX
|
|
5
5
|
Author-email: Sam Duffield <s@mduffield.com>, Sahel Iqbal <sahel13miqbal@proton.me>, Adrien Corenflos <adrien.corenflos.stats@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Ensemble Kalman
|
|
2
|
+
|
|
3
|
+
This sub-repository provides modular functions for ensemble Kalman methods, including the ensemble Kalman filter (EnKF) and ensemble RTS smoother (EnRTS smoother).
|
|
4
|
+
|
|
5
|
+
The core functions are:
|
|
6
|
+
|
|
7
|
+
- `predict`: Propagate ensemble members through nonlinear dynamics with additive Gaussian noise.
|
|
8
|
+
- `filter_update`: Update ensemble members with an observation using the EnKF update equation.
|
|
9
|
+
- `smoother_update`: Apply one Ensemble Rauch-Tung-Striebel smoother update.
|
|
10
|
+
|
|
11
|
+
Together, `predict` and `filter_update` can be used to perform an online EnKF filtering step.
|
|
12
|
+
|
|
13
|
+
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.
|
|
14
|
+
|
|
15
|
+
The EnRTS algorithm provides a smoothing counterpart to the EnKF, based on the RTS smoother. It makes an empirical approximation of the RTS smoother gain, which is applied to the ensemble in a backwards pass to obtain a smoothing distribution. Note that, based on the outputs of the EnKF, the EnRTS step is entirely deterministic.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Implements the Ensemble Rauch-Tung-Striebel (EnRTS) smoother update.
|
|
2
|
+
|
|
3
|
+
Cf. [Raanes (2016)[https://doi.org/10.1002/qj.2728].
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import jax.numpy as jnp
|
|
7
|
+
|
|
8
|
+
from cuthbertlib.types import Array
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def update(
|
|
12
|
+
filtered_ensemble: Array,
|
|
13
|
+
predicted_ensemble: Array,
|
|
14
|
+
next_smoothed_ensemble: Array,
|
|
15
|
+
) -> tuple[Array, Array]:
|
|
16
|
+
"""Applies one EnRTS smoother update step.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
filtered_ensemble: Filtered ensemble at time t, shape (N, x_dim).
|
|
20
|
+
predicted_ensemble: Paired forecast ensemble at time t + 1,
|
|
21
|
+
shape (N, next_x_dim).
|
|
22
|
+
next_smoothed_ensemble: Smoothed ensemble at time t + 1,
|
|
23
|
+
shape (N, next_x_dim).
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
Tuple of the smoothed ensemble at time t and the EnRTS gain.
|
|
27
|
+
"""
|
|
28
|
+
filtered_dev = filtered_ensemble - jnp.mean(filtered_ensemble, axis=0)
|
|
29
|
+
predicted_dev = predicted_ensemble - jnp.mean(predicted_ensemble, axis=0)
|
|
30
|
+
|
|
31
|
+
gain = filtered_dev.T @ jnp.linalg.pinv(predicted_dev.T)
|
|
32
|
+
|
|
33
|
+
smoothed_ensemble = (
|
|
34
|
+
filtered_ensemble + (next_smoothed_ensemble - predicted_ensemble) @ gain.T
|
|
35
|
+
)
|
|
36
|
+
return smoothed_ensemble, gain
|
|
@@ -63,14 +63,14 @@ def linearize_moments(
|
|
|
63
63
|
- [sqrt-parallel-smoothers](https://github.com/EEA-sensors/sqrt-parallel-smoothers/blob/main/parsmooth/linearization/_extended.py)
|
|
64
64
|
"""
|
|
65
65
|
if has_aux:
|
|
66
|
-
|
|
66
|
+
mean_and_chol_cov_function_with_aux = cast(
|
|
67
67
|
MeanAndCholCovFuncAux, mean_and_chol_cov_function
|
|
68
68
|
)
|
|
69
69
|
|
|
70
70
|
def mean_and_chol_cov_function_wrapper_aux(
|
|
71
71
|
x: ArrayLike,
|
|
72
72
|
) -> tuple[Array, tuple[Array, Array, ArrayTree]]:
|
|
73
|
-
mean, chol_cov, aux =
|
|
73
|
+
mean, chol_cov, aux = mean_and_chol_cov_function_with_aux(x)
|
|
74
74
|
return mean, (mean, chol_cov, aux)
|
|
75
75
|
|
|
76
76
|
F, (m, *extra) = jax.jacfwd(
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# ty: ignore[invalid-return-type]
|
|
2
|
+
# f-strings are not supported docstrings and ty is confused about this
|
|
3
|
+
# See https://github.com/state-space-models/cuthbert/issues/261
|
|
1
4
|
"""Shared protocols for resampling algorithms."""
|
|
2
5
|
|
|
3
6
|
from typing import Protocol, runtime_checkable
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Ensemble Kalman Filter (EnKF)
|
|
2
|
-
|
|
3
|
-
This sub-repository provides modular functions for the Ensemble Kalman Filter.
|
|
4
|
-
|
|
5
|
-
The core functions are:
|
|
6
|
-
|
|
7
|
-
- `predict`: Propagate ensemble members through nonlinear dynamics with additive Gaussian noise.
|
|
8
|
-
- `update`: Update ensemble members with an observation using the EnKF update equation.
|
|
9
|
-
|
|
10
|
-
Together, `predict` and `update` can be used to perform an online EnKF filtering step.
|
|
11
|
-
|
|
12
|
-
The EnKF uses an ensemble of particles with a Kalman-style measurement update based on
|
|
13
|
-
empirical covariances. Unlike the EKF, it does not require Jacobians, while naturally
|
|
14
|
-
handling nonlinear dynamics.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from cuthbertlib.enkf.filtering import predict, update
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cuthbertlib-0.0.12/cuthbertlib/enkf → cuthbertlib-0.0.14/cuthbertlib/ensemble_kalman}/filtering.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|