Algorithmadvanced
Ensemble square root filter
Also called EnSRF, deterministic ensemble Kalman filter.
Updates the ensemble mean by the Kalman gain and the perturbations by a deterministic transform, with no perturbed observations.
- Time
- Θ(p N (n + p)) worst
- Space
- Θ(N (n + p)) extra
- Where
- N = the ensemble size; n = the size of the state; p = the number of observations
- Model
- Real RAM
- Properties
- deterministicnot perturbed observations
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Jeffrey S. Whitaker, Thomas M. Hamill, 2002
An ensemble square root filter is an ensemble Kalman filter that does not perturb the observations. It moves the ensemble mean with the Kalman gain, like the EnKF, and it changes the perturbations about the mean by a deterministic linear map, chosen so that their sample covariance is exactly the Kalman analysis covariance. The name comes from that map: it is a square root of the analysis covariance written in terms of the forecast perturbations. This page gives the serial form of Whitaker and Hamill (2002), which takes one scalar observation at a time and needs only one extra scalar, the reduced gain factor . The ETKF and the EAKF are other members of the same family.
In plain words
Think of the ensemble as a cloud of points around its centre. An observation should move the centre towards the data and should make the cloud smaller, because we now know more. The perturbed observation EnKF does this by giving each point its own noisy copy of the data, which adds random noise to the result. The square root filter moves the centre by the usual Kalman amount and then shrinks the cloud by an exact factor, the same for every member, so the cloud has the right size without any added noise. With one number observed at a time, the shrink factor is a simple formula in the spread of the ensemble at the observation and the error of the observation.
The problem
Input. A forecast ensemble , observations whose errors are independent with variances (a diagonal ), an observation operator , and optional localization weights between each observation and each state value or other observation. The notation is that of Ide, Courtier, Ghil and Lorenc (1997). In the letters of the Kalman filter page, is its , the model is its , the forecast and are its predicted and , and the analysis and are its filtered and .
Output. An analysis ensemble with mean and sample covariance , where is the sample covariance of the forecast and (for a linear and no localization).
The algorithm
and hold the unscaled perturbations of the state and of the predicted observations, one row per variable. A correlated can first be made diagonal by a change of variables of the observations.
EnSRF(x_1..x_N, y^o, H, r)- 1
xbar, X <- mean and perturbations of x_i; ybar, Y <- of y_i = H(x_i) - 2
for k <- 1 to p do ▷ one scalar observation at a time - 3
s <- Y_k Y_k^T / (N - 1) ▷ forecast variance of observation k - 4
b <- X Y_k^T / (N - 1); c <- Y Y_k^T / (N - 1) ▷ covariances with observation k (localized) - 5
K <- b / (s + r_k); K_y <- c / (s + r_k) - 6
alpha <- 1 / (1 + sqrt(r_k / (s + r_k))) - 7
d <- y^o_k - ybar_k - 8
xbar <- xbar + K d; ybar <- ybar + K_y d - 9
X <- X - alpha K Y_k; Y <- Y - alpha K_y Y_k - 10
return x^a_i <- xbar + X_i for each member i
Line L1 is the only place where the observation operator is used. After that the filter updates the predicted observations together with the state, which is exact for a linear and avoids running again. Lines L3 to L5 form the scalar Kalman gain from the ensemble. Line L6 is the factor that makes the perturbations shrink by the right amount. Line L8 moves the means with the full gain and line L9 moves the perturbations with the reduced gain . With localization, line L4 multiplies and entry by entry by the weights of observation .
Example
Take a state with two values, two members and , both values observed, and . The forecast mean is and both values have the perturbations , so .
The first observation has , , and . The mean moves to and all perturbations shrink by the factor . The predicted second observation moves to in the same step. The second observation then has , and , so the mean moves to and the perturbations shrink by to . The analysis covariance is . The batch Kalman update with gives , the same mean and the same covariance, as Theorem 3 of the proof says.
For the check value of the page group: with two members (sample mean , variance ), and , the filter returns the mean and the variance to rounding.
A measurement. On the Lorenz-96 model with , , RK4 with step , every other variable observed every time units with , , multiplicative inflation of the forecast covariance and a Gaspari-Cohn weight with half-width grid units, the mean analysis RMSE over cycles 501 to 1500 was (one seed, about 3 ms for each analysis in pure Python):
| 4 | 6 | 8 | 10 | 15 | none | |
|---|---|---|---|---|---|---|
| 0.373 | 0.321 | 0.314 | 0.303 | 0.292 | 4.52 |
With and the RMSE was again , and with and gave . Without localization the filter needed to reach , the same value as the ETKF on the same run, as it should be, since both filters give the same mean and covariance.
Correctness
The proof shows three facts for a linear and no localization. For one scalar observation, the factor of line L6 is the root in of , which is exactly the condition for the new perturbations to have the covariance (Lemma 1). The predicted observations stay equal to applied to the state ensemble (Lemma 2). With a diagonal , taking the observations one at a time gives the same mean and covariance as the batch Kalman update (Theorem 3, a theorem). As for a linear Gaussian model the filter converges to the Kalman filter (Kwiatkowski and Mandel 2015). With localization the update is no longer exact and the order of the observations matters a little; this is a heuristic.
Proof: The serial EnSRF gives exactly the Kalman analysis mean and covariance of the sample priorfull
Setting. There are forecast members and observations with a linear operator (rows ) and independent errors of variances , so . () holds the unscaled perturbations and is the sample covariance. () holds the perturbations of the predicted observations (line L1). There is no localization in Lemmas 1 to 3.
Lemma 1 (one scalar observation). Let , , (line L3), (lines L4 and L5), and (line L6). Lines L8 and L9 give a new mean and new perturbations with
Proof. The sample covariance of and is , so line L5 is the scalar Kalman gain and line L8 the Kalman mean. Line L9 is . Then
because and also . The Kalman covariance is . The two agree if . Write and divide by : the condition is , that is , and is a root. If then and both sides equal .
The other root also gives the right covariance, but it is larger than and flips the sign of the observed part of the perturbations. The root of line L6 lies in .
Lemma 2 (the observation ensemble stays consistent). After each pass of the loop of line L2, the predicted observation ensemble equals applied to the state ensemble: and .
Proof. It holds after line L1. If it holds before a pass, then the vector of lines L4 and L5 for the observations is . So lines L8 and L9 change by and by , which is times the change of and of .
Theorem 3 (serial equals batch). With a diagonal , a linear and no localization, the output ensemble has the mean and the sample covariance , with the batch gain .
Proof. Let , a Gaussian vector ( may be singular), and with independent . For a Gaussian prior and a linear observation with positive definite noise covariance, the Kalman formulas give the mean and the covariance of the conditional distribution of given the data. By Lemma 1 and Lemma 2, after the pass for observation the ensemble mean and covariance are the moments of given : the conditional distribution given the first values is Gaussian with the moments before the pass, and is a linear observation of it with noise independent of the earlier ones. After the last pass these are the moments of given all of , which are the batch Kalman mean and covariance. These moments do not depend on being Gaussian: they are a function of , , , and only.
With , , , and , , , and the ensemble has the mean and the variance .
Corollary 4. The analysis members lie in , because every pass multiplies on the left by and lies in the range of , which is the range of .
With localization. If the weights multiply entry by entry, Lemma 1 becomes a statement about and is no longer exact: the perturbations of the state change by , which is not the square root update of a localized covariance in general, and Lemma 2 fails because . The serial order then matters a little. The use of localization is a heuristic whose value is measured, not proved.
Termination. The loop of line L2 makes passes, and each pass is a finite number of sums over members. Line L6 divides by and line L5 by , so no step fails. The algorithm returns at line L10.
Complexity
Each pass of the loop costs for lines L4 and L9, and for the rest, so the analysis costs plus applications of . With localization only the state values and observations with a nonzero weight need work, which brings the cost of one pass down to for and local values. The extra space is the two perturbation matrices. Updating the observation ensemble costs in total, which can dominate when is much larger than .
Properties
- No perturbed observations. The analysis is deterministic. Whitaker and Hamill (2002) showed that the perturbed observations of the EnKF add sampling error, and the square root form removes it.
- Exact second moments. For a linear and a diagonal , without localization, the mean and covariance are the Kalman values for the sample covariance.
- Serial. Each observation is a rank one update, so no matrix is inverted and localization by distance is easy to apply.
- Low rank. The analysis stays in the span of the forecast perturbations.
- Same moments as the other square root filters. The ETKF and the EAKF give the same mean and covariance; the members differ by an orthogonal transform in ensemble space (Tippett et al. 2003).
Variants and improvements
- Batch square root. Process all observations together with an transform: the ETKF, or a square root of computed in another way.
- EAKF. Anderson's ensemble adjustment Kalman filter does the same scalar update in observation space and regresses the increments onto the state; for one scalar observation the members are the same (see the EAKF).
- Localized serial filter. Multiply and by a Gaspari-Cohn weight of the distance, which is covariance localization applied to the gain.
- Batches. Houtekamer and Mitchell (2001) split the observations into batches and processed one batch at a time, which is between the serial and the batch forms.
- The DEnKF of Sakov and Oke. Sakov and Oke (2008) give a scheme that uses half the gain for the perturbations, . It is not exactly a square root filter: it matches the Kalman covariance only up to a term of second order in .
When to use it
Use the serial EnSRF when the observation errors are independent or can be made so, when localization by distance is needed, and when the code should be simple. It is a good choice for models of moderate size and for research systems. For very many observations on a parallel computer, the serial loop is a bottleneck, and the LETKF is easier to run in parallel.
Pitfalls
- The wrong root (line L6). The equation for has two roots. The other one, , gives the right covariance but flips the sign of the observed part of the perturbations.
- Stale predicted observations (line L9). The observation ensemble must be updated with each observation. Using the original for all observations counts the information of the earlier observations twice.
- Correlated errors. The serial form needs a diagonal . For correlated errors, first transform the observations with a square root of .
- The serial order with localization (line L4). With localization the result depends a little on the order of the observations. The effect is usually small, but it makes runs with different orders differ.
- Spread collapse. Like every ensemble filter with few members, the filter underestimates its error. Without inflation or localization it can stop using the data, as the measurement without localization shows.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/ensemble-square-root-filter/. The authors are listed in prov/W0YQYW.jsonl.
"""Serial ensemble square root filter (EnSRF) of Whitaker and Hamill (2002).
Notation of Ide, Courtier, Ghil and Lorenc (1997). The forecast ensemble has
N members in R^n. The p observations have independent errors with variances
r_k, so R is diagonal and the observations can be taken one at a time.
The filter keeps the state ensemble and the ensemble of predicted
observations y_i = h(x_i), and updates both with each scalar observation k:
s = var(y_k), K = cov(x, y_k) / (s + r_k), alpha = 1 / (1 + sqrt(r_k / (s + r_k)))
mean <- mean + K (y^o_k - ybar_k), x'_i <- x'_i - alpha K y'_{k,i}
The mean moves by the Kalman gain and the perturbations by the reduced gain
alpha K, with no perturbed observations. Optional localization weights
multiply K entry by entry (the Schur product applied to the gain). Cost:
O(p N (n + p)) for the p observations.
"""
import math
def ensrf_analysis(ens, yo, h, r_var, loc_state=None, loc_obs=None):
"""Return the EnSRF analysis ensemble (a list of N members).
ens: forecast members (lists of n floats). yo: the p observations.
h(x): the observation operator, evaluated once per member. r_var: the
error variances of the observations. loc_state[k][j] and loc_obs[k][l]:
optional localization weights between observation k and state value j,
or observation l. None means weight 1.
"""
N, n, p = len(ens), len(ens[0]), len(yo)
xbar = [sum(x[j] for x in ens) / N for j in range(n)] # @line L1
X = [[x[j] - xbar[j] for x in ens] for j in range(n)]
hx = [list(h(x)) for x in ens]
ybar = [sum(v[k] for v in hx) / N for k in range(p)]
Y = [[hx[i][k] - ybar[k] for i in range(N)] for k in range(p)]
for k in range(p): # @line L2
yk = list(Y[k])
s = sum(v * v for v in yk) / (N - 1) # @line L3
b = [sum(a * v for a, v in zip(X[j], yk)) / (N - 1) for j in range(n)] # @line L4
c = [sum(a * v for a, v in zip(Y[l], yk)) / (N - 1) for l in range(p)]
if loc_state is not None:
b = [bj * wj for bj, wj in zip(b, loc_state[k])]
if loc_obs is not None:
c = [cl * wl for cl, wl in zip(c, loc_obs[k])]
K = [bj / (s + r_var[k]) for bj in b] # @line L5
Ky = [cl / (s + r_var[k]) for cl in c]
alpha = 1.0 / (1.0 + math.sqrt(r_var[k] / (s + r_var[k]))) # @line L6
d = yo[k] - ybar[k] # @line L7
xbar = [m + kj * d for m, kj in zip(xbar, K)] # @line L8
ybar = [m + kl * d for m, kl in zip(ybar, Ky)]
X = [[a - alpha * kj * v for a, v in zip(X[j], yk)] for j, kj in enumerate(K)] # @line L9
Y = [[a - alpha * kl * v for a, v in zip(Y[l], yk)] for l, kl in enumerate(Ky)]
return [[xbar[j] + X[j][i] for j in range(n)] for i in range(N)] # @line L10
def ensemble_moments(ens):
"""Return (mean, P): the ensemble mean and the sample covariance with divisor N - 1."""
N, n = len(ens), len(ens[0])
mean = [sum(x[j] for x in ens) / N for j in range(n)]
P = [[sum((x[a] - mean[a]) * (x[b] - mean[b]) for x in ens) / (N - 1) for b in range(n)] for a in range(n)]
return mean, P
scimat.py 227 lines
# SPDX-License-Identifier: MIT
# Shared helper of the scientific-computing pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small dense linear algebra and error norms for the scientific-computing pages.
A matrix is a list of rows and a vector is a list. Entries may be int,
float or fractions.Fraction. The routines that do not take a square root
(solve, inv, det and the arithmetic) keep Fraction entries exact.
cholesky, cholesky_solve and norm2 take square roots and return floats.
API (fixed; other pages copy this file byte for byte):
zeros(m, n=None) m by n zero matrix (n = m if not given)
eye(n) n by n identity
add(A, B), sub(A, B) entrywise sum and difference (vectors or matrices)
scale(c, A) c times A (vector or matrix)
matmul(A, B) matrix product
matvec(A, x) matrix times vector
transpose(A) transpose
dot(x, y) inner product of two vectors
norm2(x) Euclidean norm of a vector, as a float
outer(x, y) outer product x y^T
solve(A, b) Gaussian elimination with partial pivoting;
b is a vector or a matrix of right sides
inv(A) inverse of A
det(A) determinant of A
cholesky(A) lower triangular L with A = L L^T (floats)
cholesky_solve(L, b) solve L L^T x = b for a vector b
err_l1(e, dx=1) sum |e_j| dx
err_l2(e, dx=1) sqrt(sum e_j^2 dx), as a float
err_linf(e, dx=1) max |e_j| (dx is not used)
observed_order(errors) [log2(E_i / E_(i+1)) for successive errors]
"""
import math
def zeros(m, n=None):
"""Return an m by n matrix of zeros (n = m if n is None)."""
if n is None:
n = m
return [[0] * n for _ in range(m)]
def eye(n):
"""Return the n by n identity matrix."""
out = zeros(n, n)
for i in range(n):
out[i][i] = 1
return out
def _is_matrix(a):
return len(a) > 0 and isinstance(a[0], list)
def add(a, b):
"""Return a + b for two vectors or two matrices of the same shape."""
if _is_matrix(a):
return [[x + y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]
return [x + y for x, y in zip(a, b)]
def sub(a, b):
"""Return a - b for two vectors or two matrices of the same shape."""
if _is_matrix(a):
return [[x - y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]
return [x - y for x, y in zip(a, b)]
def scale(c, a):
"""Return c times a, for a vector or a matrix a."""
if _is_matrix(a):
return [[c * x for x in row] for row in a]
return [c * x for x in a]
def transpose(a):
"""Return the transpose of the matrix a."""
return [list(col) for col in zip(*a)]
def matmul(a, b):
"""Return the matrix product a b."""
bt = transpose(b)
return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]
def matvec(a, x):
"""Return the product of the matrix a and the vector x."""
return [sum(aij * xj for aij, xj in zip(row, x)) for row in a]
def dot(x, y):
"""Return the inner product of the vectors x and y."""
return sum(a * b for a, b in zip(x, y))
def norm2(x):
"""Return the Euclidean norm of the vector x, as a float."""
return math.sqrt(float(dot(x, x)))
def outer(x, y):
"""Return the outer product x y^T as a matrix."""
return [[a * b for b in y] for a in x]
def _eliminate(a, rhs):
"""Reduce a to upper triangular form with partial pivoting.
a is a copy of the square matrix, rhs a list of right side rows (one
row per row of a) that receives the same row operations. Return the
number of row swaps. Raise ValueError if a pivot is zero.
"""
n = len(a)
swaps = 0
for k in range(n):
p = max(range(k, n), key=lambda i: abs(a[i][k]))
if a[p][k] == 0:
raise ValueError("matrix is singular")
if p != k:
a[k], a[p] = a[p], a[k]
rhs[k], rhs[p] = rhs[p], rhs[k]
swaps += 1
for i in range(k + 1, n):
f = a[i][k] / a[k][k]
if f == 0:
continue
for j in range(k, n):
a[i][j] -= f * a[k][j]
for j in range(len(rhs[i])):
rhs[i][j] -= f * rhs[k][j]
return swaps
def solve(a, b):
"""Solve a x = b by Gaussian elimination with partial pivoting.
b is a vector (the result is a vector) or a matrix with one column per
right side (the result is a matrix). Fraction entries stay exact.
Raise ValueError if a is singular.
"""
n = len(a)
work = [list(row) for row in a]
vector = not _is_matrix(b)
rhs = [[v] for v in b] if vector else [list(row) for row in b]
_eliminate(work, rhs)
m = len(rhs[0]) if n else 0
x = [[0] * m for _ in range(n)]
for i in range(n - 1, -1, -1):
for j in range(m):
s = rhs[i][j]
for k in range(i + 1, n):
s -= work[i][k] * x[k][j]
x[i][j] = s / work[i][i]
if vector:
return [row[0] for row in x]
return x
def inv(a):
"""Return the inverse of the square matrix a."""
return solve(a, eye(len(a)))
def det(a):
"""Return the determinant of the square matrix a (0 if singular)."""
work = [list(row) for row in a]
rhs = [[] for _ in a]
try:
swaps = _eliminate(work, rhs)
except ValueError:
return 0
d = -1 if swaps % 2 else 1
for i in range(len(a)):
d *= work[i][i]
return d
def cholesky(a):
"""Return the lower triangular L with a = L L^T, in floats.
Raise ValueError if a is not symmetric positive definite.
"""
n = len(a)
low = [[0.0] * n for _ in range(n)]
for j in range(n):
s = float(a[j][j]) - sum(low[j][k] ** 2 for k in range(j))
if s <= 0.0:
raise ValueError("matrix is not positive definite")
low[j][j] = math.sqrt(s)
for i in range(j + 1, n):
t = float(a[i][j]) - sum(low[i][k] * low[j][k] for k in range(j))
low[i][j] = t / low[j][j]
return low
def cholesky_solve(low, b):
"""Solve L L^T x = b, with L from cholesky, for a vector b."""
n = len(low)
y = [0.0] * n
for i in range(n):
y[i] = (float(b[i]) - sum(low[i][k] * y[k] for k in range(i))) / low[i][i]
x = [0.0] * n
for i in range(n - 1, -1, -1):
x[i] = (y[i] - sum(low[k][i] * x[k] for k in range(i + 1, n))) / low[i][i]
return x
def err_l1(e, dx=1):
"""Return the discrete L1 norm sum |e_j| dx."""
return sum(abs(v) for v in e) * dx
def err_l2(e, dx=1):
"""Return the discrete L2 norm sqrt(sum e_j^2 dx), as a float."""
return math.sqrt(float(sum(v * v for v in e) * dx))
def err_linf(e, dx=1):
"""Return the max norm max |e_j|. dx is accepted for a uniform call and not used."""
return max(abs(v) for v in e)
def observed_order(errors):
"""Return [log2(E_i / E_(i+1))] for a list of errors on meshes h, h/2, h/4, ..."""
return [math.log2(float(errors[i]) / float(errors[i + 1])) for i in range(len(errors) - 1)]
test_ensemble_square_root_filter.py 116 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/ensemble-square-root-filter/. The authors are listed in prov/W0YQYW.jsonl.
import math
import random
import scimat
from ensemble_square_root_filter import ensemble_moments, ensrf_analysis
def kalman_moments(ens, yo, H, r):
"""Oracle: the batch Kalman analysis mean and covariance for the sample covariance."""
n = len(ens[0])
xbar, P = ensemble_moments(ens)
R = [[r[a] if a == b else 0.0 for b in range(len(r))] for a in range(len(r))]
PHt = scimat.matmul(P, scimat.transpose(H))
S = scimat.add(scimat.matmul(H, PHt), R)
K = scimat.transpose(scimat.solve(S, scimat.transpose(PHt)))
xa = scimat.add(xbar, scimat.matvec(K, scimat.sub(yo, scimat.matvec(H, xbar))))
Pa = scimat.matmul(scimat.sub(scimat.eye(n), scimat.matmul(K, H)), P)
return xa, Pa
def close_moments(ens, xa, Pa, tol=1e-9):
ma, Pe = ensemble_moments(ens)
n = len(xa)
for a in range(n):
assert abs(ma[a] - xa[a]) < tol * (1 + abs(xa[a]))
for b in range(n):
assert abs(Pe[a][b] - Pa[a][b]) < tol * (1 + abs(Pa[a][b]))
def test_scalar_check_value():
s = 1 / math.sqrt(2.0)
out = ensrf_analysis([[-s], [s]], [1.0], lambda x: [x[0]], [1.0])
mean, P = ensemble_moments(out)
assert abs(mean[0] - 0.5) < 1e-12
assert abs(P[0][0] - 0.5) < 1e-12
def test_two_member_scalar():
out = ensrf_analysis([[-1.0], [1.0]], [1.0], lambda x: [x[0]], [1.0])
assert abs(out[0][0] - (2 / 3 - 1 / math.sqrt(3))) < 1e-12
assert abs(out[1][0] - (2 / 3 + 1 / math.sqrt(3))) < 1e-12
def test_page_example_two_observations():
out = ensrf_analysis([[-1.0, 0.0], [1.0, 2.0]], [1.0, 2.0], lambda x: list(x), [1.0, 1.0])
mean, P = ensemble_moments(out)
assert abs(mean[0] - 0.8) < 1e-12 and abs(mean[1] - 1.8) < 1e-12
for a in range(2):
for b in range(2):
assert abs(P[a][b] - 0.4) < 1e-12
assert abs(out[1][0] - (0.8 + 1 / math.sqrt(5))) < 1e-12
def test_serial_equals_batch_kalman_moments():
rng = random.Random(31)
for _ in range(80):
n, p, N = rng.randint(1, 5), rng.randint(1, 5), rng.randint(2, 8)
ens = [[rng.gauss(0, 1) for _ in range(n)] for _ in range(N)]
H = [[rng.uniform(-1, 1) for _ in range(n)] for _ in range(p)]
r = [rng.uniform(0.1, 2.0) for _ in range(p)]
yo = [rng.gauss(0, 2) for _ in range(p)]
out = ensrf_analysis(ens, yo, lambda x: scimat.matvec(H, x), r)
xa, Pa = kalman_moments(ens, yo, H, r)
close_moments(out, xa, Pa)
def test_order_of_observations_does_not_change_moments():
rng = random.Random(32)
n, p, N = 4, 4, 6
ens = [[rng.gauss(0, 1) for _ in range(n)] for _ in range(N)]
H = [[rng.uniform(-1, 1) for _ in range(n)] for _ in range(p)]
r = [0.5, 1.0, 1.5, 2.0]
yo = [1.0, -1.0, 0.5, 2.0]
m1, P1 = ensemble_moments(ensrf_analysis(ens, yo, lambda x: scimat.matvec(H, x), r))
perm = [2, 0, 3, 1]
Hp = [H[k] for k in perm]
m2, P2 = ensemble_moments(ensrf_analysis(ens, [yo[k] for k in perm], lambda x: scimat.matvec(Hp, x),
[r[k] for k in perm]))
for a in range(n):
assert abs(m1[a] - m2[a]) < 1e-10
for b in range(n):
assert abs(P1[a][b] - P2[a][b]) < 1e-10
def test_perturbed_reduction_factor():
# One scalar observation: the perturbations of the observed value shrink by sqrt(r / (s + r)).
rng = random.Random(33)
for _ in range(20):
N = rng.randint(2, 9)
ens = [[rng.gauss(0, 2), rng.gauss(0, 1)] for _ in range(N)]
r = rng.uniform(0.2, 3.0)
out = ensrf_analysis(ens, [0.7], lambda x: [x[0]], [r])
xb, _ = ensemble_moments(ens)
xa, _ = ensemble_moments(out)
s = sum((x[0] - xb[0]) ** 2 for x in ens) / (N - 1)
f = math.sqrt(r / (s + r))
for x, z in zip(ens, out):
assert abs((z[0] - xa[0]) - f * (x[0] - xb[0])) < 1e-12
def test_localization_weight_zero_freezes_value():
rng = random.Random(34)
N = 5
ens = [[rng.gauss(0, 1) for _ in range(3)] for _ in range(N)]
loc = [[1.0, 0.5, 0.0]]
out = ensrf_analysis(ens, [2.0], lambda x: [x[0]], [0.5], loc_state=loc)
for x, z in zip(ens, out):
assert abs(z[2] - x[2]) < 1e-14
assert abs(z[0] - x[0]) > 0
# Weight 1 everywhere is the same as no localization.
a = ensrf_analysis(ens, [2.0], lambda x: [x[0]], [0.5], loc_state=[[1.0, 1.0, 1.0]], loc_obs=[[1.0]])
b = ensrf_analysis(ens, [2.0], lambda x: [x[0]], [0.5])
assert a == b
History
Square root forms of the Kalman filter were used in engineering long before ensembles, to keep the covariance positive definite in finite precision. For ensembles, Burgers, van Leeuwen and Evensen showed in 1998 that the EnKF needs perturbed observations to give the right analysis spread. Anderson's ensemble adjustment filter of 2001, the ETKF of Bishop, Etherton and Majumdar of 2001, and the serial filter of Whitaker and Hamill of 2002 did without them. Tippett, Anderson, Bishop, Hamill and Whitaker showed in 2003 that these filters are all square root filters and differ only in the choice of the square root.
References
- J. S. Whitaker and T. M. Hamill, Ensemble data assimilation without perturbed observations, Monthly Weather Review 130(7) (2002) 1913-1924, the serial square root update with the reduced gain alpha K, and the sampling error that perturbed observations add
- M. K. Tippett, J. L. Anderson, C. H. Bishop, T. M. Hamill and J. S. Whitaker, Ensemble square root filters, Monthly Weather Review 131(7) (2003) 1485-1490, the common form of the square root filters and the nonuniqueness of the square root
- J. L. Anderson, A local least squares framework for ensemble filtering, Monthly Weather Review 131(4) (2003) 634-642, serial processing of scalar observations by regression on the observed variable
- P. L. Houtekamer and H. L. Mitchell, A sequential ensemble Kalman filter for atmospheric data assimilation, Monthly Weather Review 129(1) (2001) 123-137, sequential processing of batches of observations with a localized gain
- P. Sakov and P. R. Oke, A deterministic formulation of the ensemble Kalman filter: an alternative to ensemble square root filters, Tellus A 60(2) (2008), from page 361, the DEnKF, a different scheme that uses the name deterministic EnKF
- E. Kwiatkowski and J. Mandel, Convergence of the square root ensemble Kalman filter in the large ensemble limit, SIAM/ASA Journal on Uncertainty Quantification 3(1) (2015) 1-17, convergence of the square root filters to the Kalman filter as N goes to infinity, for linear models
- Geir Evensen, Data Assimilation: The Ensemble Kalman Filter, 2nd edition, Springer, 2009, Chapter 13, Square root analysis schemes
- K. Ide, P. Courtier, M. Ghil and A. C. Lorenc, Unified notation for data assimilation, operational, sequential and variational, Journal of the Meteorological Society of Japan 75(1B) (1997) 181-189, the notation used here
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag W0YQYW Edit this page History Report an error Markdown