Algorithmadvanced
Discrete empirical interpolation method
Also called DEIM.
Picks interpolation indices greedily from POD modes of snapshots of the nonlinear term, so a reduced model evaluates it at few points.
- Time
- O(m^2) onlineO(n m^2 + m^4) selection
- Space
- O(n m) extra
- Where
- m = the number of basis vectors and indices; n = the length of the vectors
- Model
- Real RAM
- Properties
- deterministicnot exactinterpolatorynot iterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Saifon Chaturantabut, Danny C. Sorensen, 2010
The discrete empirical interpolation method (DEIM) chooses entries of a vector of length , so that the vector can be rebuilt from those entries alone. It works with a basis that is given, usually the leading POD modes of snapshots of a nonlinear term . The approximation is
where picks the chosen entries. DEIM picks the indices one at a time. The first index is where is largest. Each later index is where the residual of is largest, after is interpolated by the earlier vectors at the earlier indices. In a POD-Galerkin model this means that the nonlinear term is computed at entries in place of , so the online cost no longer depends on when each entry of depends on a few entries of . DEIM is the discrete form of the empirical interpolation method. The difference is in the basis: EIM builds the basis from the functions in the same greedy loop that picks the points, and controls the max-norm error on a training set. DEIM takes a basis that is already computed, often by an SVD, and only picks the indices, and its error bound is in the 2-norm, relative to the POD projection error.
In plain words
A reduced model has a few unknowns, but its nonlinear term is still a long vector, and computing it touches the whole mesh. If that vector always looks like a mix of a few known shapes, then a few of its entries are enough to know the mix. DEIM decides which entries to look at. It looks where the shapes are large and where each new shape differs most from what the earlier shapes can already explain at the earlier entries. Then the full vector is rebuilt from those few entries.
The problem
The input is a matrix with linearly independent columns . The output is a list of distinct indices such that is invertible, where . For a vector , the DEIM approximation is the vector in the range of that agrees with at the chosen indices.
In a model with a Galerkin basis and , the reduced nonlinear term becomes . The matrix is computed once. If acts entry by entry, needs only the rows . For a stencil, it needs the rows of the neighbours too.
The algorithm
DEIM(u_1..u_m) ▷ columns of length n, linearly independent- 1
p_1 ← the index of the largest |u_1(i)|; U ← [u_1]; P ← [e_p1] - 2
for l ← 2 to m do - 3
solve (P^T U) c = P^T u_l - 4
r ← u_l - U c - 5
p_l ← the index of the largest |r(i)|; U ← [U u_l]; P ← [P e_pl] - 6
return p_1..p_m
Line L3 interpolates by the first columns at the first indices. Line L4 forms the residual, which is 0 at those indices. Line L5 picks the index where the residual is largest. The order of the columns matters: the POD modes come in the order of their singular values, so the first indices serve the most important modes. The online stage stores an LU factorization of and solves with it for each new , in , plus the cost of the entries of .
Example
By hand. Take and . The largest entry of is the second, so . Interpolation of at index 2 gives , and the residual is . Its largest entry is the third, so . Then . For , gives and , which agrees with at the indices 2 and 3.
A parametrized function. Take on equispaced points of , a test function of the kind that Chaturantabut and Sorensen use, with 51 snapshots at equispaced . The singular values of the snapshot matrix fall from 24.8 to 0.476 at the 11th and to at the 21st. The first six DEIM indices are at , near the left end, where the functions are largest. The table is a measurement from the test file. It gives the largest 2-norm error over 20 test values of between the snapshots, where .
| DEIM error | POD projection error | ratio | ||
|---|---|---|---|---|
| 2 | 2.79 | 3.744 | 3.555 | 1.05 |
| 6 | 3.68 | 0.7186 | 0.6316 | 1.14 |
| 10 | 7.11 | 0.1645 | 0.1051 | 1.57 |
| 15 | 5.31 | 1.59 | ||
| 20 | 5.66 | 2.26 |
The DEIM error is within a factor 2.3 of the best error in the same space, and the factor stays below 8, while the proved bound of Chaturantabut and Sorensen is for , and the bound of Sorensen and Embree is .
Correctness
The proof file shows, in exact arithmetic:
- The indices are distinct and is invertible at each step. In fact , where is lower triangular with the nonzero residual values on its diagonal and is upper triangular with a unit diagonal, so line L3 can always be solved.
- is the unique vector in the range of with , and when is in the range.
- If has orthonormal columns, then
So the DEIM error is the POD projection error times a factor that depends only on and the indices. The proof writes in terms of only, splits it into a part orthogonal to the range of and a part in it, and uses that the rows of are orthonormal. The bounds of the factor, and , are cited, not proved here. The tests check the error bound, both factor bounds and, by brute force over all index sets for , that the best index set is not worse than DEIM.
Proof: DEIM picks distinct indices with an invertible P^T U, and its error is at most the norm of (P^T U)^-1 times the POD projection errorfull
We assume exact arithmetic. and are the matrices after step , the columns of length are linearly independent, and is the residual of step , with .
Lemma 1 (the selection is well defined). For each : is invertible, , for , , and differs from . Moreover , where is lower triangular with the diagonal and is upper triangular with a unit diagonal. So is invertible.
Proof. By induction on . For , by independence, so its largest entry in absolute value is not 0, and . Let and assume the claim for . Then line L3 has a unique solution . The residual is not 0, since is not in the range of . Its entries at the old indices are . Line L5 picks with , so is not an old index. Let . Each , and by induction each column of is a combination of , so with upper triangular with a unit diagonal. The entry of is , which is 0 for and for . So is lower triangular with a nonzero diagonal, and has the determinant .
Write , , and .
Lemma 2 (interpolation and reproduction). is the unique vector in the range of with . In particular , and if is in the range of .
Proof. . If and both agree with at the indices, then , so . For , .
Theorem (error bound). If the columns of are orthonormal, then for every
Proof. If , then and by Lemma 2, and both sides are 0. Let , and complete to an orthogonal matrix with . Let with , so . Since (Lemma 2), , so
with . The two parts are orthogonal, so .
The matrix has orthonormal rows, because and is orthogonal. So . Since is invertible (Lemma 1), is positive definite, so every eigenvalue of is below 1, and so is every eigenvalue of , because the two matrices have the same nonzero eigenvalues. Let . Then is invertible, and the identity gives . So
Hence , since the eigenvalues of are at least . On the other side, . So .
The bound is attained: with an eigenvector of for the eigenvalue , the inequality in the last step is an equality, so the factor cannot be lowered for the given indices. The bounds of Chaturantabut and Sorensen and of Sorensen and Embree are cited, not proved here, and the tests check both on random bases.
Complexity
In the real RAM model, step of the selection solves a system of size in and forms the residual in , so the selection costs . An LU factorization that grows by one row and one column per step gives . The POD basis costs more than the selection: for snapshots by the method of snapshots, as in the implementation. The online stage needs entries of and for the two triangular solves. Memory is for .
Properties
- Interpolatory. equals at the chosen indices and is exact on the range of .
- Greedy and deterministic. No search over index sets; the result depends on the order of the columns.
- Error relative to POD. The error is at most times the best 2-norm error in the range of .
- Independent of the basis scaling of each column. Scaling a column does not change the indices, because the residual of line L4 scales with it.
- Online cost independent of . For an entry-wise or local nonlinear term.
Variants and improvements
- Q-DEIM. Choose the indices by a QR factorization with column pivoting of . It gives a better worst-case bound of the factor and uses standard QR software.
- Oversampling. Take more than indices and use least squares, which lowers the factor and makes the approximation less sensitive to noise.
- Localized and adaptive DEIM. Use several local bases for different regions of the state space, or update the basis and the indices online.
- DEIM for CUR. The same indices, applied to the left and right singular vectors, choose the rows and columns of a CUR factorization of a matrix.
- Unassembled DEIM. For finite elements, apply DEIM to the element contributions, so each chosen entry needs one element.
When to use it
Use DEIM in a POD-Galerkin model, such as a reduced model of Burgers' equation, when the nonlinear term is local, so that a few of its entries need a few entries of the state, and when snapshots of the nonlinear term have fast singular value decay. Use EIM when you work with functions and want the basis and the points from the same greedy loop. Use operator inference when the nonlinearity is polynomial and you cannot change the code; then the reduced operators are learned and no entries are sampled. Do not use DEIM for a dense nonlinear term, such as an integral operator, because each entry then needs the whole state.
Pitfalls
- Snapshots of the wrong quantity. The basis must come from snapshots of , not of . A basis of the state can represent the nonlinear term badly.
- Too few modes for the nonlinear term. If is smaller than the Galerkin size , the DEIM error can dominate and the reduced model can become unstable. Choose from the singular values of the nonlinear snapshots.
- Stencils. For a finite difference term, depends on . The rows of for all these entries must be kept, so the cost is a small multiple of .
- Forming the factor online. Solve with a stored LU factorization of ; do not form and do not recompute the selection.
- Loss of accuracy in the POD. The method of snapshots squares the singular values, so modes with are inaccurate. Use an SVD of the snapshot matrix for very small singular values.
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/discrete-empirical-interpolation-method/. The authors are listed in prov/RHRTRM.jsonl.
"""The discrete empirical interpolation method (DEIM) of Chaturantabut and Sorensen.
A basis U = [u_1 .. u_m] of R^n is given as a list of m columns. DEIM chooses m row indices
p_1..p_m, and the DEIM approximation of a vector f is U (P^T U)^-1 P^T f, which needs only the
m entries f[p_1], .., f[p_m]. The POD basis of the example is computed from the Gram matrix of
the snapshots with the cyclic Jacobi eigenvalue method.
"""
import math
Vector = list[float]
Matrix = list[list[float]]
def argmax_abs(v: Vector) -> int:
"""Index of the largest |v_i|; ties go to the first index."""
best = 0
for i in range(1, len(v)):
if abs(v[i]) > abs(v[best]):
best = i
return best
def gauss_solve(a: Matrix, b: Vector) -> Vector:
"""Solve a x = b by Gaussian elimination with partial pivoting."""
n = len(b)
m = [list(row) + [bi] for row, bi in zip(a, b)]
for k in range(n):
p = max(range(k, n), key=lambda i: abs(m[i][k]))
if m[p][k] == 0.0:
raise ValueError("P^T U is singular")
m[k], m[p] = m[p], m[k]
for i in range(k + 1, n):
f = m[i][k] / m[k][k]
for j in range(k, n + 1):
m[i][j] -= f * m[k][j]
x = [0.0] * n
for i in range(n - 1, -1, -1):
x[i] = (m[i][n] - sum(m[i][j] * x[j] for j in range(i + 1, n))) / m[i][i]
return x
def deim(u: list[Vector]) -> list[int]:
"""Return the DEIM indices of the basis u (a list of m linearly independent columns)."""
p = [argmax_abs(u[0])] # @line L1
for l in range(1, len(u)): # @line L2
a = [[u[j][pi] for j in range(l)] for pi in p] # the l by l matrix P^T U
c = gauss_solve(a, [u[l][pi] for pi in p]) # @line L3: (P^T U) c = P^T u_l
r = [u[l][i] - sum(c[j] * u[j][i] for j in range(l)) for i in range(len(u[0]))] # @line L4
p.append(argmax_abs(r)) # @line L5: the new index, where r is largest
return p # @line L6
def deim_approx(u: list[Vector], p: list[int], fp: Vector) -> Vector:
"""The DEIM approximation U (P^T U)^-1 (f at p), from the m values fp = P^T f."""
a = [[u[j][pi] for j in range(len(u))] for pi in p]
c = gauss_solve(a, fp)
return [sum(cj * uj[i] for cj, uj in zip(c, u)) for i in range(len(u[0]))]
def jacobi_eigh(a: Matrix, tol: float = 1e-15, sweeps: int = 60) -> tuple[Vector, Matrix]:
"""Eigenvalues (in decreasing order) and eigenvectors (as columns of v) of a symmetric a."""
n = len(a)
a = [list(row) for row in a]
v = [[1.0 if i == j else 0.0 for j in range(n)] for i in range(n)]
for _ in range(sweeps):
off = math.sqrt(sum(a[i][j] ** 2 for i in range(n) for j in range(n) if i != j))
scale = math.sqrt(sum(a[i][i] ** 2 for i in range(n))) or 1.0
if off <= tol * scale:
break
for p in range(n - 1):
for q in range(p + 1, n):
if a[p][q] == 0.0:
continue
theta = (a[q][q] - a[p][p]) / (2.0 * a[p][q])
t = (1.0 if theta >= 0 else -1.0) / (abs(theta) + math.sqrt(theta * theta + 1.0))
c = 1.0 / math.sqrt(t * t + 1.0)
s = t * c
for k in range(n):
akp, akq = a[k][p], a[k][q]
a[k][p], a[k][q] = c * akp - s * akq, s * akp + c * akq
for k in range(n):
apk, aqk = a[p][k], a[q][k]
a[p][k], a[q][k] = c * apk - s * aqk, s * apk + c * aqk
for k in range(n):
vkp, vkq = v[k][p], v[k][q]
v[k][p], v[k][q] = c * vkp - s * vkq, s * vkp + c * vkq
order = sorted(range(n), key=lambda i: -a[i][i])
return [a[i][i] for i in order], [[v[k][i] for i in order] for k in range(n)]
def pod(snaps: list[Vector], m: int) -> tuple[list[Vector], Vector]:
"""The first m POD modes (orthonormal columns) and all singular values of the snapshots,
by the method of snapshots: eigenvectors of the Gram matrix S^T S."""
k = len(snaps)
gram = [[sum(a * b for a, b in zip(snaps[i], snaps[j])) for j in range(k)] for i in range(k)]
lam, w = jacobi_eigh(gram)
sig = [math.sqrt(max(t, 0.0)) for t in lam]
modes = []
for j in range(m):
col = [sum(w[i][j] * snaps[i][x] for i in range(k)) / sig[j] for x in range(len(snaps[0]))]
nrm = math.sqrt(sum(t * t for t in col))
modes.append([t / nrm for t in col])
return modes, sig
def inv_norm2(a: Matrix) -> float:
"""The spectral norm of a^-1, that is 1 / sigma_min(a), from the eigenvalues of a^T a."""
n = len(a)
ata = [[sum(a[k][i] * a[k][j] for k in range(n)) for j in range(n)] for i in range(n)]
lam, _ = jacobi_eigh(ata)
return 1.0 / math.sqrt(lam[-1])
test_discrete_empirical_interpolation_method.py 138 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/discrete-empirical-interpolation-method/. The authors are listed in prov/RHRTRM.jsonl.
import itertools
import math
import random
import pytest
from discrete_empirical_interpolation_method import deim, deim_approx, gauss_solve, inv_norm2, jacobi_eigh, pod
N = 100
XS = [-1 + 2 * i / (N - 1) for i in range(N)]
MUS = [1 + (math.pi - 1) * i / 50 for i in range(51)]
TEST = [1 + (math.pi - 1) * (i + 0.5) / 20 for i in range(20)]
def s(x, mu):
return (1 - x) * math.cos(3 * math.pi * mu * (x + 1)) * math.exp(-(1 + x) * mu)
def norm(v):
return math.sqrt(sum(t * t for t in v))
def orthonormal(cols):
out = []
for c in cols:
w = list(c)
for _ in range(2):
for q in out:
d = sum(a * b for a, b in zip(q, w))
w = [a - d * b for a, b in zip(w, q)]
nw = norm(w)
out.append([t / nw for t in w])
return out
def proj_err(u, f):
c = [sum(a * b for a, b in zip(uj, f)) for uj in u]
return norm([f[i] - sum(cj * uj[i] for cj, uj in zip(c, u)) for i in range(len(f))])
def factor(u, p):
return inv_norm2([[u[j][pi] for j in range(len(u))] for pi in p])
def test_hand_example():
u = [[1.0, 3.0, 2.0], [2.0, 1.0, 4.0]]
p = deim(u)
assert p == [1, 2]
assert deim_approx(u, p, [1.0, 1.0]) == pytest.approx([0.5, 1.0, 1.0])
def test_jacobi_against_the_definition():
rng = random.Random(4)
for n in (2, 3, 6):
b = [[rng.gauss(0, 1) for _ in range(n)] for _ in range(n)]
a = [[b[i][j] + b[j][i] for j in range(n)] for i in range(n)]
lam, v = jacobi_eigh(a)
assert all(lam[i] >= lam[i + 1] for i in range(n - 1))
assert sum(lam) == pytest.approx(sum(a[i][i] for i in range(n)))
for k in range(n):
col = [v[i][k] for i in range(n)]
av = [sum(a[i][j] * col[j] for j in range(n)) for i in range(n)]
assert av == pytest.approx([lam[k] * t for t in col], abs=1e-10)
for k2 in range(n):
col2 = [v[i][k2] for i in range(n)]
assert sum(x * y for x, y in zip(col, col2)) == pytest.approx(1.0 if k == k2 else 0.0, abs=1e-12)
# 2 by 2 closed form
lam, _ = jacobi_eigh([[2.0, 1.0], [1.0, 2.0]])
assert lam == pytest.approx([3.0, 1.0])
def test_pod_projection_error_is_the_tail_of_the_singular_values():
rng = random.Random(5)
snaps = [[rng.gauss(0, 1) for _ in range(12)] for _ in range(7)]
for m in (1, 3, 5):
u, sig = pod(snaps, m)
assert sum(proj_err(u, f) ** 2 for f in snaps) == pytest.approx(sum(t * t for t in sig[m:]), rel=1e-8)
def test_structure_on_random_bases():
rng = random.Random(6)
for _ in range(30):
n, m = rng.randint(6, 12), rng.randint(1, 5)
u = [[rng.gauss(0, 1) for _ in range(n)] for _ in range(m)]
p = deim(u)
assert len(set(p)) == m
# P^T U is nonsingular, the approximation interpolates at p and reproduces the span
f = [rng.gauss(0, 1) for _ in range(n)]
fh = deim_approx(u, p, [f[i] for i in p])
assert [fh[i] for i in p] == pytest.approx([f[i] for i in p], abs=1e-9)
a = [rng.gauss(0, 1) for _ in range(m)]
v = [sum(aj * uj[i] for aj, uj in zip(a, u)) for i in range(n)]
assert deim_approx(u, p, [v[i] for i in p]) == pytest.approx(v, abs=1e-8)
def test_error_bound_and_factor_bounds_against_brute_force():
rng = random.Random(7)
for _ in range(20):
n, m = rng.randint(5, 8), rng.randint(1, 4)
u = orthonormal([[rng.gauss(0, 1) for _ in range(n)] for _ in range(m)])
p = deim(u)
fac = factor(u, p)
for _ in range(5):
f = [rng.gauss(0, 1) for _ in range(n)]
fh = deim_approx(u, p, [f[i] for i in p])
assert norm([a - b for a, b in zip(f, fh)]) <= fac * proj_err(u, f) * (1 + 1e-9) + 1e-12
# the best index set by brute force is at least as good; DEIM is within the proved bounds
best = min(_safe_factor(u, list(q)) for q in itertools.combinations(range(n), m))
assert best <= fac * (1 + 1e-9)
assert fac <= (1 + math.sqrt(2 * n)) ** (m - 1) / max(abs(t) for t in u[0]) * (1 + 1e-9)
assert fac < math.sqrt(n * m / 3) * 2 ** m
def _safe_factor(u, q):
"""||(P^T U)^-1||_2 for the index set q, or infinity if P^T U is singular."""
try:
gauss_solve([[u[j][pi] for j in range(len(u))] for pi in q], [1.0] * len(q))
return factor(u, q)
except (ValueError, ZeroDivisionError):
return math.inf
def test_example_run():
snaps = [[s(x, mu) for x in XS] for mu in MUS]
modes, sig = pod(snaps, 20)
assert sig[0] == pytest.approx(24.8, rel=1e-2) and sig[10] == pytest.approx(0.476, rel=1e-2)
p = deim(modes)
assert p[:6] == [0, 12, 16, 21, 25, 38]
for m, fac_ref in ((2, 2.79), (10, 7.11), (20, 5.66)):
u, pm = modes[:m], p[:m]
fac = factor(u, pm)
assert fac == pytest.approx(fac_ref, rel=1e-2)
for mu in TEST:
f = [s(x, mu) for x in XS]
fh = deim_approx(u, pm, [f[i] for i in pm])
assert norm([a - b for a, b in zip(f, fh)]) <= fac * proj_err(u, f) * (1 + 1e-6) + 1e-12
History
Chaturantabut and Sorensen introduced DEIM in 2010, as a discrete version of the empirical interpolation method of Barrault, Maday, Nguyen and Patera from 2004, made for POD-Galerkin models of systems of ODEs from discretized nonlinear PDEs. They proved the error bound with the factor and a first bound of this factor. Sorensen and Embree used the same index selection for CUR factorizations in 2014 and gave a sharper bound of the factor.
References
- Saifon Chaturantabut and Danny C. Sorensen, Nonlinear model reduction via discrete empirical interpolation, SIAM Journal on Scientific Computing 32(5), 2010, 2737-2764, the DEIM index selection, the error bound with the factor of the inverse of P^T U, and the bound (1 + sqrt(2n))^(m-1) / |u_1|_inf of that factor (Lemma 3.2)
- Danny C. Sorensen and Mark Embree, A DEIM induced CUR factorization, 2014 (published in SIAM Journal on Scientific Computing, 2016), Lemma 4.4 of the arXiv version, the sharper bound sqrt(n m / 3) 2^m of the DEIM factor
- Maxime Barrault, Yvon Maday, Ngoc Cuong Nguyen and Anthony T. Patera, An empirical interpolation method, application to efficient reduced-basis discretization of partial differential equations, Comptes Rendus Mathematique 339(9), 2004, 667-672, the greedy choice of interpolation points that DEIM applies to vectors
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 RHRTRM Edit this page History Report an error Markdown