Algorithmintro
Nudging
Also called Newtonian relaxation.
Adds a term G (y^o - H x) to the model equations that pulls the state toward the observations with a time scale 1/g; the simplest continuous data assimilation.
- Time
- Θ(m (c + n + p + z)) worst
- Space
- Θ(n + p + z) extra
- Where
- c = the cost of one evaluation of the model tendency; m = the number of time steps; n = the state dimension; p = the number of observed quantities; z = the number of nonzero entries of H and G
- Model
- Real RAM
- Properties
- continuous in timedeterministic
- Evidence
- Proof sketchCode in 1 languages
- Origin
- John E. Hoke, Richard A. Anthes, 1976
Nudging, also called Newtonian relaxation, assimilates observations by adding a relaxation term to the equations of the model, , and integrating the result in time. The term pulls each observed quantity toward its observed value with the rate set by the gain , and the model dynamics carry the information to the unobserved parts of the state. The gain is a tuned constant, not a quantity derived from error statistics, so nudging is cheap, easy to add to any model and continuous in time, but it is not an optimal estimator. With a constant gain the nudged model is a Luenberger observer for the model, and with full exact observations and a large enough gain the nudged state converges to the truth even for a chaotic model.
In plain words
Take a weather model and run it forward. At the same time, look at the measurements. Wherever the model has a value that is measured, push the model a little toward the measurement at every time step. The push is stronger when the model is farther from the measurement, like a spring. The model then moves the corrected values to the places that are not measured, through its own physics. If the spring is too weak, the model drifts away on its own. If it is too strong for poor or sparse measurements, the model copies the noise or is pulled into a state that its physics do not like. The strength of the spring is chosen by trial, not by a formula.
The problem
Input. A model tendency , an initial state , a linear observation operator (), observations given at every time, usually by interpolation in time between observation times, a gain (), a time step and a number of steps . Here is the state dimension and the number of observed quantities. The common choice is , which relaxes each observed quantity with the rate and the time scale .
Output. An approximation , , of the solution of
The algorithm
NUDGE(f, x_0, H, G, y^o, dt, m)- 1
x <- x_0 - 2
for k <- 0 to m - 1 do - 3
q(t, z) := f(z) + G (y^o(t) - H z) ▷ model plus relaxation - 4
x_{k+1} <- RK4 step of dz/dt = q(t, z) from t_k to t_{k+1} - 5
return x_0, x_1, ..., x_m
Line L3 is the only change to the model. Line L4 is one step of the classical Runge-Kutta method, which evaluates at , twice at and at , so must be available between observation times. The reference code interpolates it linearly in time. The step must also be stable for the relaxation: for this needs about , the limit of RK4 on the negative real axis. With the algorithm is the free model run.
Example
Scalar check. For with constants, the solution is with . With , , and , the state relaxes to , not to : the model and the observation compromise.
Lorenz-96 with full exact observations. A truth run of the Lorenz-96 model with and , RK4 with , is observed at every variable without error. The nudged run starts from the truth plus Gaussian noise of standard deviation 3 (seed 1), with and . The table gives the root mean square error over the 40 variables (measurements).
| 0 (free run) | 2.49 | 5.50 | 4.80 | 4.49 |
| 0.5 | 2.49 | 2.19 | 4.15 | 3.38 |
| 1 | 2.49 | 1.35 | 2.37 | 2.39 |
| 1.5 | 2.49 | 1.05 | 0.34 | 1.64 |
| 2 | 2.49 | 0.11 | 0.006 | 0.003 |
| 3 | 2.49 | 0.003 | 0.001 | 0.002 |
| 5 | 2.49 | 0.0009 | 0.0009 | 0.001 |
For the error stays of the order of the spread of the attractor. For the nudged run locks onto the truth. The remaining error of about comes from the linear interpolation of the truth in time at the half steps of RK4. The largest growth rate of small errors on this attractor is about 1.7, which is close to the measured threshold (measurement, see the Lorenz-96 page). The sufficient condition of Corollary 5 in the proof, , is far from sharp.
Noisy observations. The same truth is observed every time units with Gaussian errors of standard deviation , and the observations are interpolated linearly in time. The mean root mean square error between and is 3.93 for , 2.44 for , 0.71 for , 0.40 for and 0.46 for (measurements). A moderate gain averages the noise over a time of about ; a large gain follows the noise more closely.
Half the variables observed. With only the even variables observed and , the error after was 2.7 for , 0.3 for , 0.003 for and 0.6 for (measurements). Here a gain that is too large is worse than a moderate one.
Correctness
The proof shows that the loop stops after Runge-Kutta steps of the nudged equation, and three facts about that equation. For a linear scalar model it relaxes to the weighted mean with the rate . If the model satisfies the one-sided bound along the truth, and the observations are full and exact with , then (a theorem). For Lorenz-96 the bound holds with , because the advection term conserves energy. With partial observations, convergence needs more: Azouani, Olson and Titi (2014) prove it for the 2D Navier-Stokes equations when the observations resolve the flow finely enough and the gain is large enough, but not too large for that resolution.
Proof: Nudging integrates the relaxed model, and a large enough gain makes the error decayfull
Setting. The model is on with a locally Lipschitz . The observations are , is a matrix and an matrix. The nudged equation is
Termination and what the code computes. Line L1 sets . Line L3 defines the right side of (1). The loop of line L2 runs times, and each pass does one classical Runge-Kutta step of (1) in line L4, with four evaluations of . So the algorithm stops after evaluations of and returns at line L5. The output is the Runge-Kutta solution of (1). For a with four continuous derivatives its global error on a fixed interval is , the order of the method. With linear in time between observation times, is only continuous in at those times, and the error of the forcing term is ; the tests use a tolerance that allows for this. The statements below are about the exact solution of (1).
Theorem 1 (linear scalar case). For with constants , , and , the solution is
Proof. The equation is , a linear equation for with the solution .
For the solution relaxes to with the time scale . The limit is between the free equilibrium and the observation : nudging does not reach the observation unless the model agrees with it.
Theorem 2 (error decay with full observations). Let the truth solve and be observed exactly and completely, , with and . Suppose that along the truth
Then the error of the solution of (1) satisfies . So for the nudged solution converges to the truth exponentially, whatever its initial value.
Proof. Subtract the two equations: . Then
So , which gives .
If with a skew-symmetric , then , so (2) holds with and the proof gives the equality . The tests check this for a rotation.
Lemma 3 (energy conservation of the Lorenz-96 advection). For with indices modulo , for every .
Proof. . Replace by in the second sum: it becomes , the first sum.
Lemma 4 (one-sided bound for Lorenz-96). For the Lorenz-96 tendency and any , ,
Proof. Expand: . By Lemma 3, . The other terms give
whose absolute value is at most . Each sum is at most by the Cauchy-Schwarz inequality, because the shift does not change the norm. So these terms are at most . The linear term gives , and the constant cancels.
Corollary 5 (synchronization of Lorenz-96). With full exact observations, and , let bound for all and . If , the nudged Lorenz-96 solution converges to the truth exponentially, at the rate .
Proof. Lemma 4 gives (2) with , and Theorem 2 applies.
The truth enters the bound only through , so the bound holds for any initial value of the nudged run. The condition is sufficient, not necessary: the measured threshold on the page is much smaller than .
Summary. The algorithm stops after Runge-Kutta steps of the nudged equation (1). For a linear scalar model the nudged solution relaxes to a weighted mean of the model equilibrium and the observation. With full exact observations, and a model that satisfies the one-sided bound (2), the error decays like , and for Lorenz-96 the bound holds with .
Complexity
Each step evaluates the tendency four times, at the cost each, and forms four times in time with sparse and ( nonzero entries). So steps cost , which for a local is a small fraction more than the free model run. The extra memory is the current state and the observations needed for the current step. This is much less than for any method that stores or evolves a covariance matrix.
Properties
- Not optimal. The gain does not come from and , so the result is not the minimum variance estimate. With noisy observations the error does not go to zero; it settles at a level set by the gain, the noise and the model.
- Continuous in time. The state is corrected at every step, so there are no jumps in the forecast at analysis times, and the run is smooth enough to drive other models.
- Balance. A gentle relaxation lets the model adjust the unobserved fields to the observed ones, which is why it was first used to initialize models (Hoke and Anthes 1976).
- Observer form. For a constant the nudged model is a Luenberger observer of the model. The Kalman filter gives the gain that minimizes the error variance for linear Gaussian models.
- Synchronization. For full exact observations, convergence of the nudged run to the truth is synchronization of two copies of the model through a coupling, which needs a coupling strength above a threshold set by the instability of the model.
Variants and improvements
- Observation nudging and analysis nudging. Relax toward individual observations, with weights that fall off with distance and time from each observation, or toward gridded analyses. Regional models use both.
- Spectral nudging. Relax only the large scales of the model toward a global analysis, and leave the small scales free. Regional climate runs use this.
- Back and forth nudging. Run the nudged model forward and then backward in time with the opposite sign of relaxation, several times, to improve the initial state (Asch, Bocquet and Nodet 2016, Chapter 4).
- Interpolant observables. Replace by an interpolant of the coarse observations, as in Azouani, Olson and Titi (2014), which gives proofs of convergence for dissipative partial differential equations.
- Statistical gains. Take from optimal interpolation weights, or from a Kalman gain computed once, to give more weight to good observations.
When to use it
Use nudging when a cheap continuous assimilation is needed for a model with no tangent linear or adjoint code, for example to keep a regional or climate model close to a reanalysis, to spin up a model, or to prepare initial conditions with balanced fields. Use it also as a baseline in an observing system simulation experiment. For the best estimate from noisy observations, use optimal interpolation, 3D-Var or an ensemble Kalman filter.
Pitfalls
- Gain too large for the time step (line L4). RK4 is unstable for the relaxation term when is larger than about , and the run blows up. Reduce or treat the relaxation implicitly.
- Sign of the relaxation (line L3). Writing in place of pushes the model away from the observations, and the error grows like . A test with and a constant observation shows it at once.
- Observations only at the observation times (line L3). If is used only at the exact observation times and the term is set to zero between them, the effective gain depends on the time step. Interpolate the observations in time, or spread each one over a time window.
- Gain too large for partial or noisy data. A strong relaxation of a few observed quantities forces the model into states that its dynamics do not support, and it copies the noise. In the half observed example above, was worse than . Tune the gain by experiment.
- Treating the output as an error estimate. Nudging gives no analysis error variance. Measure the error against independent observations or in a twin experiment.
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/nudging/. The authors are listed in prov/A44WD4.jsonl.
"""Nudging (Newtonian relaxation) of a model toward observations.
The model dx/dt = f(x) gets a relaxation term:
dx/dt = f(x) + G (y^o(t) - H x),
where H (p by n) maps the state to the observed quantities, y^o(t) gives the
observations at any time t (usually by interpolation in time between
observation times), and G (n by p) is the nudging gain. The common choice
G = g H^T relaxes each observed component with the time scale 1/g.
The nudged equation is integrated with the classical Runge-Kutta method.
The module also holds the Lorenz-96 tendency for the tests and the page.
"""
def lorenz96(F):
"""Return the Lorenz-96 tendency f(x)_j = (x_{j+1} - x_{j-2}) x_{j-1} - x_j + F."""
def f(x):
n = len(x)
return [(x[(j + 1) % n] - x[j - 2]) * x[j - 1] - x[j] + F for j in range(n)]
return f
def rk4_step(q, t, x, dt):
"""Return one classical Runge-Kutta step of dx/dt = q(t, x)."""
k1 = q(t, x)
k2 = q(t + dt / 2, [a + dt / 2 * b for a, b in zip(x, k1)])
k3 = q(t + dt / 2, [a + dt / 2 * b for a, b in zip(x, k2)])
k4 = q(t + dt, [a + dt * b for a, b in zip(x, k3)])
return [a + dt / 6 * (b + 2 * c + 2 * d + e) for a, b, c, d, e in zip(x, k1, k2, k3, k4)]
def nudge(f, x0, H, G, yobs, dt, m, t0=0.0):
"""Return the nudged trajectory [x_0, x_1, ..., x_m] at t_k = t0 + k dt.
f(x) is the model tendency, H a p by n matrix, G an n by p matrix and
yobs(t) the list of p observed values at time t. With G = 0 this is
the free model run.
"""
n, p = len(x0), len(H)
# Keep only the nonzero entries: H and G are usually very sparse.
Hs = [[(j, H[k][j]) for j in range(n) if H[k][j] != 0] for k in range(p)]
Gs = [[(k, G[i][k]) for k in range(p) if G[i][k] != 0] for i in range(n)]
x = [float(v) for v in x0] # @line L1
path = [list(x)]
def q(t, z): # @line L3
y = yobs(t)
r = [y[k] - sum(h * z[j] for j, h in Hs[k]) for k in range(p)]
fz = f(z)
return [fz[i] + sum(gik * r[k] for k, gik in Gs[i]) for i in range(n)]
for k in range(m): # @line L2
x = rk4_step(q, t0 + k * dt, x, dt) # @line L4
path.append(x)
return path # @line L5
def gain(H, g):
"""Return G = g H^T, which relaxes each observed quantity with the rate g."""
return [[g * H[k][i] for k in range(len(H))] for i in range(len(H[0]))]
def time_interpolant(times, values):
"""Return y(t), linear in t between the given times and constant outside them.
times must be equally spaced and increasing.
"""
t0, step, last = times[0], times[1] - times[0], len(times) - 1
def y(t):
s = (t - t0) / step
if s <= 0:
return list(values[0])
if s >= last:
return list(values[last])
k = int(s)
a = s - k
return [(1 - a) * u + a * v for u, v in zip(values[k], values[k + 1])]
return y
test_nudging.py 120 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/nudging/. The authors are listed in prov/A44WD4.jsonl.
import math
import random
from nudging import gain, lorenz96, nudge, rk4_step, time_interpolant
N, F, DT = 40, 8.0, 0.01
def rmse(a, b):
return math.sqrt(sum((u - v) ** 2 for u, v in zip(a, b)) / len(a))
def identity(n):
return [[1.0 if i == j else 0.0 for j in range(n)] for i in range(n)]
def lorenz96_truth(steps, seed=1):
f = lorenz96(F)
x = [F + (0.01 if j == 0 else 0.0) for j in range(N)]
for _ in range(1000): # spin-up onto the attractor
x = rk4_step(lambda t, z: f(z), 0.0, x, DT)
truth = [x]
for _ in range(steps):
truth.append(rk4_step(lambda t, z: f(z), 0.0, truth[-1], DT))
rng = random.Random(seed)
x0 = [v + rng.gauss(0, 3) for v in truth[0]]
return f, truth, [k * DT for k in range(steps + 1)], x0
def test_scalar_linear_exact_solution():
# dx/dt = -a x + g (y - x) with a constant y.
a, g, y, x0, dt = 0.7, 2.5, 3.0, -1.0, 0.01
path = nudge(lambda x: [-a * x[0]], [x0], [[1.0]], [[g]], lambda t: [y], dt, 300)
xe = g * y / (a + g)
for k in (0, 50, 300):
exact = xe + (x0 - xe) * math.exp(-(a + g) * k * dt)
assert abs(path[k][0] - exact) < 1e-7 # RK4 error for (a + g) dt = 0.032
def test_zero_gain_is_the_free_run():
f, truth, times, x0 = lorenz96_truth(50)
G = [[0.0] * N for _ in range(N)]
path = nudge(f, x0, identity(N), G, time_interpolant(times, truth), DT, 50)
free = [list(map(float, x0))]
for _ in range(50):
free.append(rk4_step(lambda t, z: f(z), 0.0, free[-1], DT))
assert path == free
def test_rotation_error_decays_at_rate_g():
# f(x) = A x with A skew-symmetric; truth is a rotation, observed exactly.
g, dt = 1.5, 0.01
f = lambda x: [x[1], -x[0]]
truth = lambda t: [math.cos(t), -math.sin(t)]
x0 = [3.0, 2.0]
path = nudge(f, x0, identity(2), gain(identity(2), g), truth, dt, 400)
e0 = math.hypot(x0[0] - 1.0, x0[1])
for k in (100, 200, 400):
xt = truth(k * dt)
e = math.hypot(path[k][0] - xt[0], path[k][1] - xt[1])
assert abs(e - math.exp(-g * k * dt) * e0) < 1e-8
def test_error_bound_for_large_gain():
# Theorem: with H = I and G = g I, |e(t)| <= exp((4M - 1 - g) t) |e(0)| for M = max |x^t_j|.
steps = 300
f, truth, times, x0 = lorenz96_truth(steps)
M = max(max(abs(v) for v in s) for s in truth)
g = 4 * M
path = nudge(f, x0, identity(N), gain(identity(N), g), time_interpolant(times, truth), DT, steps)
e0 = math.sqrt(sum((a - b) ** 2 for a, b in zip(path[0], truth[0])))
for k in range(0, steps + 1, 10):
e = math.sqrt(sum((a - b) ** 2 for a, b in zip(path[k], truth[k])))
assert e <= math.exp((4 * M - 1 - g) * k * DT) * e0 + 1e-4
def test_error_identity_bound():
# e^T (f(x^t + e) - f(x^t)) <= (4 max|x^t_j| - 1) |e|^2 for Lorenz-96.
rng = random.Random(5)
f = lorenz96(F)
for _ in range(300):
n = rng.randint(4, 12)
xt = [rng.uniform(-10, 10) for _ in range(n)]
e = [rng.uniform(-10, 10) for _ in range(n)]
lhs = sum(ei * (a - b) for ei, a, b in zip(e, f([u + v for u, v in zip(xt, e)]), f(xt)))
rhs = (4 * max(abs(v) for v in xt) - 1) * sum(v * v for v in e)
assert lhs <= rhs + 1e-9
def test_lorenz96_synchronizes_with_full_observations():
steps = 500
f, truth, times, x0 = lorenz96_truth(steps)
y = time_interpolant(times, truth)
path = nudge(f, x0, identity(N), gain(identity(N), 5.0), y, DT, steps)
assert rmse(path[0], truth[0]) > 2.0
assert rmse(path[steps], truth[steps]) < 5e-3
free = nudge(f, x0, identity(N), gain(identity(N), 0.0), y, DT, steps)
assert rmse(free[steps], truth[steps]) > 1.0
def test_noisy_observations_error_below_observation_error():
steps, sigma = 1500, 1.0
f, truth, times, x0 = lorenz96_truth(steps)
rng = random.Random(7)
otimes = times[::5]
ovals = [[v + rng.gauss(0, sigma) for v in truth[5 * i]] for i in range(len(otimes))]
path = nudge(f, x0, identity(N), gain(identity(N), 5.0), time_interpolant(otimes, ovals), DT, steps)
e = [rmse(path[k], truth[k]) for k in range(500, steps + 1)]
assert sum(e) / len(e) < 0.6 * sigma
def test_time_interpolant():
y = time_interpolant([0.0, 0.5, 1.0], [[0.0, 1.0], [1.0, 1.0], [3.0, 0.0]])
assert y(-1.0) == [0.0, 1.0]
assert y(0.25) == [0.5, 1.0]
assert y(0.75) == [2.0, 0.5]
assert y(2.0) == [3.0, 0.0]
History
Hoke and Anthes in 1976 used Newtonian relaxation for dynamic initialization, adding a relaxation term to the equations of a numerical weather prediction model so that the model adjusts gradually to the observed fields. The method then spread to continuous assimilation in regional models and to nudged climate runs. Its mathematical analysis as continuous data assimilation came later: Azouani, Olson and Titi gave in 2014 a proof of convergence for the 2D Navier-Stokes equations with general interpolant observables, and Law, Stuart and Zygalakis (2015) analyze the closely related synchronization filter.
References
- J. E. Hoke and R. A. Anthes, The initialization of numerical models by a dynamic-initialization technique, Monthly Weather Review 104 (1976) 1551-1556, the relaxation term added to the model equations
- A. Azouani, E. Olson and E. S. Titi, Continuous data assimilation using general interpolant observables, Journal of Nonlinear Science 24(2) (2014) 277-304, exponential convergence of nudging with interpolated coarse observations for the 2D Navier-Stokes equations
- M. Asch, M. Bocquet and M. Nodet, Data Assimilation, Methods, Algorithms, and Applications, SIAM, 2016, Chapter 4 (nudging methods)
- K. Law, A. Stuart and K. Zygalakis, Data Assimilation, A Mathematical Introduction, Springer, 2015, Section 4.4.3 (the synchronization filter)
- Eugenia Kalnay, Atmospheric Modeling, Data Assimilation and Predictability, Cambridge University Press, 2003, Chapter 5 (data assimilation)
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 A44WD4 Edit this page History Report an error Markdown