Algorithmadvanced
Empirical interpolation method
Approximates a parametrized nonlinear function by interpolation at greedily chosen points in a basis of its snapshots, so online cost is mesh independent.
- Time
- O(m n M^2 + m M^3) offlineO(M^2) online
- Space
- O(m n + M n) extra
- Where
- M = the number of terms; m = the number of training parameters; n = the number of points of the grid that stands for the domain
- Model
- Real RAM
- Properties
- deterministicnot exactinterpolatoryiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Maxime Barrault, Yvon Maday, Ngoc Cuong Nguyen, Anthony T. Patera, 2004
The empirical interpolation method (EIM) replaces a function of a space variable and a parameter by a sum with fixed basis functions . The coefficients come from interpolation: they make the sum equal to at points , the magic points. A greedy loop over a training set of parameters chooses the basis and the points together. At each step it finds the parameter whose function is worst interpolated, takes its interpolation error as the next basis function, and takes the point where that error is largest as the next point. The online stage then needs only the values and a triangular solve of size . In a reduced basis method, this turns a coefficient that is not affine in into an affine sum with terms, so the online cost no longer depends on the mesh. The discrete empirical interpolation method is the variant for vectors: it takes a POD basis that is computed first and then chooses only the points, with the same greedy rule. EIM chooses the basis and the points in the same loop, from the functions themselves.
In plain words
A coefficient such as changes shape with . If you store it on the mesh for each new , every reduced solve has to touch the whole mesh again. EIM finds a few fixed shapes and a few special points. For a new you evaluate the function at those few points only, and the shapes, weighted to match those values, give the function everywhere. The points are chosen where the current approximation is worst, and the shapes are the errors that the earlier shapes left. So each new shape fixes the largest remaining error, and the points stay well spread.
The problem
Let be a grid of points that stands for the domain, for example the quadrature points of a finite element mesh, and let . A function can be evaluated for and in a parameter set . A training set has points. The input is , , , a tolerance and a largest size . The output is parameters , points and functions on , such that the interpolant
has , or . The matrix of the interpolation system must be invertible, and the method makes it lower triangular with a unit diagonal.
The algorithm
EIM(g, Ω_h, Ξ, ε_tol, M_max)- 1
M ← 0; r_μ ← g(·; μ) on Ω_h for each μ in Ξ ▷ I_0 g = 0 - 2
e(μ) ← max over Ω_h of |r_μ| for each μ in Ξ - 3
μ* ← the μ in Ξ with the largest e(μ) - 4
if e(μ*) ≤ ε_tol or M = M_max then - 5
return μ_1..μ_M, x_1..x_M, q_1..q_M, B - 6
M ← M + 1; μ_M ← μ*; r ← r_μ* ▷ the worst residual - 7
x_M ← the point of Ω_h with the largest |r(x)| - 8
q_M ← r / r(x_M) - 9
B_Mj ← q_j(x_M) for j = 1..M; B_iM ← 0 for i < M ▷ B_MM = 1 - 10
r_μ ← g(·; μ) - I_M g(·; μ) for each μ in Ξ, with B c = (g(x_i; μ))_i; go to L2
Line L1 starts with the empty interpolant, so the first residuals are the functions. Lines L2 and L3 find the worst interpolated training function in the max norm. Line L6 takes its residual . Line L7 chooses the new point where this residual is largest, and line L8 scales it to the value 1 there. The residual is 0 at the earlier points , because interpolates there. So for , and line L9 only adds a row to . Line L10 computes the new interpolants by forward substitution. The online stage for a new is the last part of line L10 for one function: evaluate for , solve in , and use as the affine coefficients.
Example
By hand. Take the grid , and . The functions are and . Their max norms are 2 and 4, so , and . The interpolant of is , so the residual is , with its largest value at . Then , , and
The span of and is the span of and , so the residuals are now 0 and the loop stops with . For the new parameter the online stage uses the values and : and , and on the grid.
A singular family. Take on equispaced points of , with the training values , , and . The table is a measurement from the test file. The column is the largest max-norm error over after terms.
| 0 | 20.0 | ||
| 1 | 0.050 | 0.000 | 1.802 |
| 2 | 0.126 | 0.080 | 0.3554 |
| 3 | 0.544 | 0.505 | |
| 5 | 1.000 | 1.000 | |
| 8 | 0.354 | 0.315 | |
| 11 | 0.107 | 0.125 |
The loop stops at . The first parameter is the one with the largest function, , and its peak at is the first point. The points gather near , where the functions change fastest: 0, 0.005, 0.02, 0.045, 0.08 and 0.125 are among the eleven. The second row of is . The Lebesgue constant is 1.00, 1.12, 1.63, 2.68, 3.87 and 3.53 for , far below the bound , which is 2047 for . On a 101, 401 or 801 point grid the loop also stops at . On 400 test parameters between the training points, the largest error is for and for , so the training set is too coarse near ; see the pitfalls.
Correctness
The proof file shows, in exact arithmetic, that the loop is well defined and stops, and that the interpolant has the bounds of a good interpolation scheme.
- Each chosen residual is not 0, so line L8 does not divide by 0, and for and . So is lower triangular with a unit diagonal and is invertible. Also .
- interpolates: . It reproduces the span: for , and this span is the span of .
- With the Lagrange functions of the points (, in the span) and the Lebesgue constant , every satisfies
- On the finite set , the loop stops after at most steps, and if it stops by the tolerance, the error is at most at every .
The bound is a worst case. In practice the Lebesgue constant grows slowly, as in the example. Compare it with the Lebesgue constant of Lagrange interpolation at fixed nodes: there the space is fixed and only the points are chosen; here both are adapted to the family.
Proof: The EIM matrix is unit lower triangular, the interpolant is quasi-optimal with a Lebesgue constant at most 2^M - 1, and the loop stopsfull
We assume exact arithmetic. Functions live on the finite grid , , and . We write for the interpolant of line L10 when is invertible, and , with .
Lemma 1 (one step). Suppose that after steps the matrix of size is lower triangular with a unit diagonal, that interpolates at , and that line L4 does not stop. Then the residual of line L6 is not 0, , and the new function satisfies for , and . The new is lower triangular with a unit diagonal.
Proof. Line L4 did not stop, so . Line L7 takes a point where reaches , so and , with equality at . For , by interpolation, so . So the new column of has the entries above the diagonal, which line L9 stores, and . The earlier rows do not change. In particular differs from , where is 0.
Lemma 2 (interpolation and reproduction). If is lower triangular with a unit diagonal, then for every the system has one solution, satisfies for , and for every . Also .
Proof. , so exists and is unique, and . For , the vector solves , so by uniqueness and . For the span, is a nonzero multiple of , where . By induction , and gives the other inclusion.
By induction on with Lemmas 1 and 2, every step of the loop is well defined, stays lower triangular with a unit diagonal, and for all .
Lemma 3 (Lagrange functions). Let with for . These exist and are unique, , and for
Proof. Existence and uniqueness: applied to the grid function with values at , by Lemma 2, and the formula for follows by linearity of the system. The recursion: has the values by Lemma 1. For , the right side is in . At with it equals , and at it equals . Uniqueness gives the identity.
Theorem 1 (Lebesgue constant). .
Proof. . For , Lemma 3 and give, at each ,
So and .
Theorem 2 (quasi-optimality). For every grid function , .
Proof. For , by Lemma 2, so . By Lemma 3, . So . The minimum exists because has finite dimension.
Theorem 3 (termination and the stopping error). The loop stops after at most steps. If it stops by the tolerance, then for every .
Proof. If step chooses , its residual is not 0 by Lemma 1, so by Lemma 2. Each chosen lies in by Lemma 2, so a chosen parameter has residual 0 at all later steps and is never chosen again. So at most parameters are chosen. After steps every training function is in and all residuals are 0, so line L4 stops; it also stops at . The second claim is the test of line L4 with the maximum of line L3.
Complexity
In the real RAM model, line L1 costs evaluations of . In step , line L10 solves a triangular system of size for each training function, , and forms the interpolants on the grid, . Lines L2, L3 and L7 cost . The sum over steps is . Since for the residual of , an implementation can update each residual by one term, , at a cost of per step and in total. The implementation here solves again for simplicity. The online stage costs evaluations of and for the solve, with no dependence on . Memory is for the training functions and for the basis.
Properties
- Interpolatory. The approximation is exact at the magic points, and exact for the training functions that were chosen.
- Triangular. is lower triangular with a unit diagonal, so the online solve is a forward substitution and is always possible.
- Online cost independent of the mesh. Only values of are needed.
- Adapted points. The points move to where the family changes fastest, without any knowledge of the formula of .
- Quasi-optimal up to . The error is within the factor of the best max-norm approximation in the same space.
- No certified bound. The error away from the training set is not bounded by the method.
Variants and improvements
- DEIM. The discrete empirical interpolation method takes the basis from the POD of snapshots and chooses only the points by the same rule. It is the usual choice for the nonlinear term of a POD-Galerkin model.
- Generalized EIM. Replace the point values by linear functionals, such as local averages or sensor responses, so the method works for functions in and for measured data.
- Error estimate with one more point. Use as an estimate of the error. It is cheap, but it is a bound only under an assumption on the next term.
- Discrete versions on the quadrature points. In a finite element code the grid is the set of quadrature points, and the online assembly evaluates only in the elements that contain the magic points.
- Nonlinear operators. The same construction applies to , where depends on the solution, inside a Newton loop.
When to use it
Use EIM inside a reduced basis or POD model when a coefficient, a source term or a nonlinear term depends on the parameter in a way that is not affine, and when the family of functions is smooth in the parameter, so that a few terms are enough. It needs point evaluations of and nothing else. Do not use it when the family has a slowly decaying Kolmogorov width, for example a moving front or a moving peak, because then becomes large. When the basis must come from data that is given as vectors, use DEIM.
Pitfalls
- A coarse training set. The error is controlled only at the training parameters. In the example, the error between the training points is 80 times the training error at . Refine where changes fast, or check on a test set.
- The stopping tolerance near rounding. When the residual is near the rounding level, line L8 divides by a tiny number and the new basis function is noise. Stop with a tolerance well above .
- Using the Euclidean norm in line L2 but the max in line L7. Both are valid, but the bound with is for the max norm. Keep the norms consistent with the claims.
- Forgetting that the error adds to the model error. In a reduced basis method with EIM, the error bound of the reduced model must account for the interpolation error, or it is no longer a bound.
- Evaluating on the whole mesh online. The gain is lost if the online stage forms on all of and then samples it. Only the values are needed.
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/empirical-interpolation-method/. The authors are listed in prov/003ET5.jsonl.
"""The empirical interpolation method (EIM) of Barrault, Maday, Nguyen and Patera.
A parametrized function g(x; mu) is sampled on a grid of points x (the grid stands for the
domain, and the sup norm is the max over the grid). The offline stage chooses parameters
mu_1..mu_M, magic points x_1..x_M and basis functions q_1..q_M by a greedy loop. The online
stage needs the M values g(x_i; mu) only, and solves a lower triangular system.
"""
from typing import Callable
Vector = list[float]
def sup_norm(v: Vector) -> float:
return max(abs(t) for t in v)
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 forward_solve(b: list[Vector], rhs: Vector) -> Vector:
"""Solve the lower triangular system b c = rhs (b has a unit diagonal)."""
c: Vector = []
for i in range(len(rhs)):
c.append((rhs[i] - sum(b[i][j] * c[j] for j in range(i))) / b[i][i])
return c
class EIM:
"""The output of the offline stage: parameters, magic point indices, basis and the matrix B."""
def __init__(self) -> None:
self.mus: list[float] = []
self.pts: list[int] = [] # indices of the magic points in the grid
self.q: list[Vector] = [] # basis functions on the grid
self.b: list[Vector] = [] # b[i][j] = q_j(x_i), lower triangular with a unit diagonal
def coefficients(self, values: Vector) -> Vector:
"""Coefficients of the interpolant from the values at the magic points."""
return forward_solve(self.b, values)
def interpolate(self, gvec: Vector) -> Vector:
"""I_M g on the grid, for a function given on the grid (only its magic point values are used)."""
c = self.coefficients([gvec[i] for i in self.pts])
return [sum(cj * qj[k] for cj, qj in zip(c, self.q)) for k in range(len(gvec))]
def lebesgue_constant(self) -> float:
"""max over the grid of sum_j |l_j(x)|, with the Lagrange functions l_j(x_i) = delta_ij."""
m = len(self.q)
lag = []
for j in range(m):
e = [1.0 if i == j else 0.0 for i in range(m)]
c = forward_solve(self.b, e)
lag.append([sum(ck * qk[x] for ck, qk in zip(c, self.q)) for x in range(len(self.q[0]))])
return max(sum(abs(l[x]) for l in lag) for x in range(len(self.q[0])))
def eim_offline(g: Callable[[float, float], float], xs: Vector, train: list[float], tol: float, m_max: int) -> tuple[EIM, list[float]]:
"""Run the greedy loop. Return the EIM data and the list err_0, err_1, ... of the largest
sup norm error over train after M = 0, 1, ... terms (err_0 = max ||g(.; mu)||)."""
snaps = [[g(x, mu) for x in xs] for mu in train]
eim = EIM()
errs: list[float] = []
res = [list(s) for s in snaps] # @line L1: residuals g - I_M g on the grid; I_0 g = 0
while True:
norms = [sup_norm(r) for r in res] # @line L2: the error of every training function
k = max(range(len(train)), key=lambda i: norms[i]) # @line L3
errs.append(norms[k])
if norms[k] <= tol or len(eim.q) >= m_max: # @line L4
return eim, errs # @line L5
r = res[k] # @line L6: the residual at the chosen parameter
p = argmax_abs(r) # @line L7: the new magic point
qn = [t / r[p] for t in r] # @line L8
eim.mus.append(train[k])
for i in range(len(eim.b)): # @line L9: extend B by a row; the new column is 0 above the diagonal
eim.b[i].append(0.0)
eim.b.append([qj[p] for qj in eim.q] + [1.0])
eim.pts.append(p)
eim.q.append(qn)
# @line L10: residuals of all training functions for the new interpolant
res =[[a - b for a, b in zip(s, eim.interpolate(s))] for s in snaps]
test_empirical_interpolation_method.py 120 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/empirical-interpolation-method/. The authors are listed in prov/003ET5.jsonl.
import random
import pytest
from empirical_interpolation_method import EIM, eim_offline, sup_norm
XS = [i / 200 for i in range(201)]
TRAIN = [0.05 + 0.019 * i for i in range(51)]
def g_inv(x, mu):
return 1.0 / (x + mu)
def dense_solve(a, b):
"""Reference: 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]))
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 table_function(vectors):
"""g(x, mu) for a table: mu is an index into the list of grid vectors, x a grid index."""
return lambda x, mu: vectors[mu][x]
def test_hand_example():
xs = [0.0, 0.5, 1.0]
eim, errs = eim_offline(lambda x, mu: 1.0 + mu * x * x, xs, [1.0, 3.0], 1e-12, 5)
assert eim.mus == [3.0, 1.0]
assert [xs[p] for p in eim.pts] == [1.0, 0.0]
assert eim.q[0] == pytest.approx([0.25, 0.4375, 1.0])
assert eim.q[1] == pytest.approx([1.0, 0.75, 0.0])
assert eim.b == [[1.0, 0.0], [0.25, 1.0]]
assert errs[:2] == [4.0, 0.5] and errs[2] < 1e-15
# the function is affine in mu, so two terms reproduce every mu
assert eim.coefficients([3.0, 1.0]) == pytest.approx([3.0, 0.25])
assert eim.interpolate([1.0, 1.5, 3.0]) == pytest.approx([1.0, 1.5, 3.0])
def test_structure_on_random_tables():
rng = random.Random(1)
for _ in range(20):
npts, nf = rng.randint(6, 12), rng.randint(3, 6)
vecs = [[rng.gauss(0, 1) for _ in range(npts)] for _ in range(nf)]
eim, errs = eim_offline(table_function(vecs), list(range(npts)), list(range(nf)), 1e-9, nf)
m = len(eim.q)
assert len(set(eim.pts)) == m and len(set(eim.mus)) == m
for i in range(m):
assert eim.b[i][i] == 1.0
for j in range(m):
if j <= i:
assert eim.b[i][j] == eim.q[j][eim.pts[i]]
else:
# q_j vanishes at the earlier points up to rounding; B stores an exact 0
assert eim.b[i][j] == 0.0 and abs(eim.q[j][eim.pts[i]]) < 1e-12
assert all(sup_norm(q) <= 1.0 + 1e-12 for q in eim.q)
# interpolation against a dense reference solve, and the interpolation property
for v in vecs:
ref = dense_solve(eim.b, [v[p] for p in eim.pts])
assert eim.coefficients([v[p] for p in eim.pts]) == pytest.approx(ref, rel=1e-9, abs=1e-9)
iv = eim.interpolate(v)
assert [iv[p] for p in eim.pts] == pytest.approx([v[p] for p in eim.pts], abs=1e-9)
def test_termination_and_exactness_on_a_finite_set():
rng = random.Random(2)
for _ in range(10):
npts, nf = 10, rng.randint(2, 5)
vecs = [[rng.gauss(0, 1) for _ in range(npts)] for _ in range(nf)]
eim, errs = eim_offline(table_function(vecs), list(range(npts)), list(range(nf)), 1e-9, 100)
assert len(eim.q) <= nf and errs[-1] <= 1e-9
def test_lebesgue_constant_bound_and_inequality():
rng = random.Random(3)
eim, errs = eim_offline(g_inv, XS, TRAIN, 1e-8, 40)
for m in range(1, len(eim.q) + 1):
sub = EIM()
sub.pts, sub.q, sub.b = eim.pts[:m], eim.q[:m], [row[:m] for row in eim.b[:m]]
lam = sub.lebesgue_constant()
assert 1.0 - 1e-12 <= lam <= 2 ** m - 1 + 1e-9
# ||g - I g|| <= (1 + Lambda) ||g - v|| for every v in the span: try perturbed interpolants
for mu in rng.sample(TRAIN, 5):
gv = [g_inv(x, mu) for x in XS]
err = sup_norm([a - b for a, b in zip(gv, sub.interpolate(gv))])
c = sub.coefficients([gv[p] for p in sub.pts])
for _ in range(5):
a = [cj + rng.gauss(0, 1e-3 * (1 + abs(cj))) for cj in c]
v = [sum(aj * qj[k] for aj, qj in zip(a, sub.q)) for k in range(len(XS))]
assert err <= (1 + lam) * sup_norm([s - t for s, t in zip(gv, v)]) * (1 + 1e-9) + 1e-12
def test_example_run():
eim, errs = eim_offline(g_inv, XS, TRAIN, 1e-8, 40)
assert len(eim.q) == 11
assert eim.mus[:3] == pytest.approx([0.05, 0.126, 0.544])
assert [XS[p] for p in eim.pts[:3]] == pytest.approx([0.0, 0.08, 0.505])
assert errs[0] == pytest.approx(20.0) and errs[1] == pytest.approx(1.802, rel=1e-3)
assert errs[-1] <= 1e-8 < errs[-2]
assert eim.lebesgue_constant() == pytest.approx(3.528, rel=1e-3)
def test_online_stage_uses_only_the_magic_points():
eim, errs = eim_offline(g_inv, XS, TRAIN, 1e-8, 40)
gv = [g_inv(x, 0.3) for x in XS]
other = [t if k in eim.pts else 1e6 for k, t in enumerate(gv)]
assert eim.interpolate(other) == eim.interpolate(gv)
History
Barrault, Maday, Nguyen and Patera introduced the empirical interpolation method in 2004, to keep the offline-online split of reduced basis methods for coefficients that are not affine in the parameter. Their note gives the greedy construction and the bound of the Lebesgue constant. Maday, Nguyen, Patera and Pau presented the construction in 2009 as a general interpolation procedure, with the name magic points. Chaturantabut and Sorensen gave the discrete version DEIM in 2010.
References
- 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 construction of the basis and the interpolation points, and the bound 2^M - 1 of the Lebesgue constant
- Yvon Maday, Ngoc Cuong Nguyen, Anthony T. Patera and George S. H. Pau, A general multipurpose interpolation procedure, the magic points, Communications on Pure and Applied Analysis 8(1), 2009, 383-404, the magic points for a general family of functions, and the Lebesgue constant of the construction
- Jan S. Hesthaven, Gianluigi Rozza and Benjamin Stamm, Certified Reduced Basis Methods for Parametrized Partial Differential Equations, SpringerBriefs in Mathematics, Springer, 2016, Chapter 5, Section 5.2 (the empirical interpolation method)
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 003ET5 Edit this page History Report an error Markdown