Algorithmresearch
Proper generalized decomposition
Builds a separated representation of the solution as sums of products of functions of each variable by greedy alternating enrichment.
- Time
- O(M (M + s) (M + s + I) N) total
- Space
- O((M + s) N) extra
- Where
- I = the largest number of alternating steps per mode; M = the number of modes; N = the sum nx + ny of the grid sizes; s = the number of terms of the right side
- Model
- Real RAM
- Properties
- deterministicnot exactiterativemonotone-energy
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Amine Ammar, Béchir Mokdad, Francisco Chinesta, Roland Keunings, 2006
The proper generalized decomposition (PGD) computes the solution of a partial differential equation in many variables as a sum of products of functions of one variable each, . It does not need the solution first. It adds one product at a time: for the current approximation it finds a new product that lowers the energy of the error, by solving in turn a small problem for with fixed and a small problem for with fixed. Each small problem is a one-dimensional Galerkin problem. So the cost grows with the sum of the grid sizes, not with their product, and this is the reason to use it in high dimensions, where a grid in all variables is too large.
The POD-Galerkin model and the reduced basis method are a posteriori: they first compute full solutions, then compress them. PGD is a priori: it builds the separated form from the operator and the right side, and it never forms a full solution. The truncated SVD of the exact solution gives the best sum of products in the Frobenius norm, but it needs the exact solution. PGD is greedy, so at a given it is usually less accurate than the SVD, but it costs much less. Alternating least squares also fixes one factor and solves for the other, but it fits a known matrix; PGD solves an equation whose solution is unknown.
In plain words
You want the temperature on a square, but you write it as a short list of "a curve in times a curve in ". Start with nothing. Look at what the equation still misses, and find the one product that helps the most: guess the curve, find the best curve for it, then the best curve for that curve, and repeat a few times. Add the product and look again. Each step only solves problems on a line, never on the whole square.
The problem
The model problem is on with on the boundary, with central finite differences on interior points. With , the discrete system is the Sylvester equation
or with the Kronecker product. The right side is given in separated form . The output is a list of modes with . The operator is symmetric positive definite for the inner product , so minimizes the energy
The algorithm
PGD(K_x, K_y, separated F, M, tol)- 1
U ← 0, the empty sum of products - 2
for m = 1 to M - 3
R ← F - K_x U - U K_y, kept as a sum of products - 4
if ‖R‖_F ≤ tol ‖F‖_F then stop - 5
Y ← R^T w for a fixed w with R^T w ≠ 0 - 6
repeat until X Y^T stops changing, at most I times - 7
X ← the solution of (‖Y‖² K_x + (Y^T K_y Y) I) X = R Y - 8
Y ← the solution of ((X^T K_x X) I + ‖X‖² K_y) Y = R^T X - 9
U ← U + X Y^T - 10
return the modes of U
Line L3 never forms as an matrix. It is the list of the terms of and the terms and . Then and cost , and line L4 uses . Lines L7 and L8 are the conditions that the derivative of with respect to , and then , is 0. Each matrix is a positive combination of a tridiagonal matrix and the identity, so the Thomas algorithm solves it in . Line L5 picks , or a unit vector if that gives 0, so that .
Example
By hand. Let be a product of eigenvectors, and . Then and line L5 gives . Line L7 reads , so , and . This is the exact solution, so the next residual is 0 and the method stops after one mode. The test file checks this on a grid.
The unit load. Take , (one term, ) and a grid. The reference is the exact discrete solution by the discrete sine transform in each direction. The table compares PGD with the truncated SVD of the reference, which is the best possible in the Frobenius norm. These numbers come from the test file and a scratch run.
| relative energy error of PGD | relative Frobenius error of PGD | relative Frobenius error of the SVD | alternating steps | |
|---|---|---|---|---|
| 1 | 6 | |||
| 2 | 7 | |||
| 3 | 11 | |||
| 4 | 30 | |||
| 6 | 6 | |||
| 8 | 9 |
The energy error goes down at each mode, as the proof shows. One mode is almost as good as the best rank one, but later modes are far from the SVD: a greedy sum of the best single products is not the best sum. Eight modes store numbers, against 900 for the grid; in dimensions with points each the ratio is against .
Correctness
The proof file shows, in exact arithmetic, that lines L7 and L8 each give the unique minimizer of over one factor with the other fixed, so does not increase inside the loop. The first step of line L7 lowers by , where is its matrix. With the identity , the energy error goes down strictly at each mode while . It also shows that the method stops after one mode when is a product of eigenvectors. Convergence of the energy error to 0 as grows is proved by Le Bris, Lelièvre and Maday for the greedy method with the best rank-one product at each step. The alternating steps find a stationary point, not always the best product, so the page cites this result and does not claim it for the implementation.
Proof: Each PGD step is a one-factor energy minimizer, so the energy error does not grow, and the method stopsfull
We assume exact arithmetic. and are symmetric positive definite, , , is the solution of , and .
Lemma 1 (the energy identity). is symmetric positive definite for , and for every .
Proof. , which is symmetric in and because and are symmetric. With the eigendecompositions and and , for . Expand with : it is .
Fix the current sum and its residual . For a product ,
Lemma 2 (the half steps). For a fixed , is a strictly convex quadratic with the unique minimizer given by line L7, and with . The same holds for line L8 with the roles of and exchanged.
Proof. and , so . is positive definite, since , is positive definite and . So the unique minimizer solves , which is line L7, and the minimum value is . The proof for uses in the same way.
Lemma 3 (the start vector). If , line L5 returns with .
Proof. Some row of is not 0, so , and the loop over finds a with . Then , so .
Theorem 1 (the energy error does not grow). Let at line L4. Then the new sum of line L9 satisfies .
Proof. Let be the vector of line L5 and the iterates of lines L7 and L8. By Lemma 2, each half step does not increase : . By Lemmas 2 and 3, , since is positive definite and . So the final product has , that is, , and Lemma 1 turns this into the claim.
Theorem 2 (one mode for a product of eigenvectors). If with and , then the first mode is , and the method stops at the next line L4.
Proof. With , , and line L5 gives with by Lemma 3. Line L7 gives , so . Line L8 then has and , so and again. The product does not change, so the loop stops, and . It solves the equation, since . Then the next residual is 0.
Termination. Line L2 runs at most times and line L6 at most times, and each of lines L3, L5, L7 and L8 does a finite amount of work. No division by 0 occurs: the tridiagonal matrices of lines L7 and L8 are positive definite by Lemma 2, so all pivots of the Thomas algorithm are positive. Line L5 only runs when , and then Lemma 3 gives a nonzero , so is positive definite at the first step; every later and is nonzero because it solves with , which follows by induction from (a zero factor gives , and does not increase).
What is not proved here. The energy error goes to 0 as when each mode is the best rank-one product; this is the result of Le Bris, Lelièvre and Maday, and it is cited, not proved. The alternating loop of lines L6 to L8 gives a product with but not always the best one, so for this implementation only the monotone decrease is proved.
Complexity
In the real RAM model, with : at mode the residual has terms. One alternating step costs for or and for the tridiagonal solves. The norm check costs . Over modes with at most steps each, the time is . The memory is for the modes and the right side. A direct solve on the grid needs unknowns, and in dimensions ; PGD needs .
Properties
- A priori. It needs the operator and the right side, not snapshots of the solution.
- Monotone in energy. The energy error does not grow when a mode is added, for a symmetric positive definite operator.
- Linear in the dimension. The cost per mode grows with , not with .
- Not optimal. The sum of greedy modes is usually worse than the best rank- approximation.
- Separated input. The right side and the operator must have a separated form with few terms.
Variants and improvements
- More than two variables. For , add products , and update each factor in turn with the others fixed. Parameters and time can be extra variables, which gives a solution for all parameter values at once.
- Update of the earlier modes. After adding a mode, recompute the coefficients, or all factors in one direction, by a Galerkin projection on the current modes. This improves the accuracy per mode.
- Non-symmetric problems. For an operator that is not symmetric, the Galerkin conditions no longer minimize an energy. Minimal residual or Petrov-Galerkin versions keep a monotone error.
- Nonlinear problems. Linearize, for example by a fixed point or Newton iteration, and apply PGD at each step.
- Other tensor formats. Tensor-train or hierarchical Tucker formats replace the sum of products when the canonical sum needs too many terms.
When to use it
Use PGD when the equation has many variables, or when you want the solution as an explicit function of parameters, and when the operator and the data have a separated form with few terms. It fits the forward problems of stochastic Galerkin type, where the random variables are extra coordinates. For a problem in two or three space variables only, a direct or multigrid solver on the grid is usually better. When you can afford full solutions at chosen parameters, the reduced basis method gives certified errors.
Pitfalls
- Not separable data. A right side or a coefficient with no short separated form, such as a load on a disc, needs many terms, and the cost grows with .
- Slow convergence. For rough data the modes decay slowly. For a random right side of rank 3 on an grid in the tests, the relative energy error after 10 modes is still , although the exact solution has rank at most 6.
- Stagnation of the alternating steps. The loop can need many steps or stop at a poor product. Limit the steps, and do not expect the best product.
- The residual floor. The Gram formula for computes a square, so cancellation limits the relative residual to about the square root of the machine precision, near . Do not set the tolerance below that.
- Scaling of the factors. does not change when is multiplied by and by . Compare products, not factors, when you test for a fixed point.
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/proper-generalized-decomposition/. The authors are listed in prov/TWTF98.jsonl.
"""Proper generalized decomposition (PGD) by greedy rank-one enrichment with alternating directions.
The model problem is -a u_xx - b u_yy = f on the unit square with u = 0 on the boundary, with
central differences on nx by ny interior points. With U[i][j] = u(x_i, y_j), the discrete system is
Kx U + U Ky = F,
where Kx = (a / hx^2) tridiag(-1, 2, -1) and Ky = (b / hy^2) tridiag(-1, 2, -1). This is the
Kronecker system (Kx (x) I + I (x) Ky) vec(U) = vec(F). PGD writes U as a sum of products
X_1 Y_1^T + ... + X_M Y_M^T and never forms a matrix of size nx * ny: F is given in the
separated form F = sum_s fx_s fy_s^T, and every residual is kept as a list of products.
"""
import math
Vector = list[float]
Terms = list[tuple[Vector, Vector]] # a matrix sum_t p_t q_t^T
def dot(u: Vector, v: Vector) -> float:
return sum(a * b for a, b in zip(u, v))
def tri_apply(d: float, o: float, v: Vector) -> Vector:
"""(d on the diagonal, o off the diagonal) times v."""
n = len(v)
return [d * v[i] + o * ((v[i - 1] if i > 0 else 0.0) + (v[i + 1] if i < n - 1 else 0.0)) for i in range(n)]
def tri_solve(d: float, o: float, rhs: Vector) -> Vector:
"""Solve the constant tridiagonal system (d, o) z = rhs by the Thomas algorithm."""
n = len(rhs)
c = [0.0] * n
g = [0.0] * n
m = d
c[0], g[0] = o / m, rhs[0] / m
for i in range(1, n):
m = d - o * c[i - 1]
c[i] = o / m
g[i] = (rhs[i] - o * g[i - 1]) / m
z = [0.0] * n
z[-1] = g[-1]
for i in range(n - 2, -1, -1):
z[i] = g[i] - c[i] * z[i + 1]
return z
class Laplace2D:
def __init__(self, nx: int, ny: int, a: float = 1.0, b: float = 1.0):
self.nx, self.ny = nx, ny
hx, hy = 1.0 / (nx + 1), 1.0 / (ny + 1)
self.kx = (2.0 * a / hx ** 2, -a / hx ** 2)
self.ky = (2.0 * b / hy ** 2, -b / hy ** 2)
def kx_apply(self, v: Vector) -> Vector:
return tri_apply(self.kx[0], self.kx[1], v)
def ky_apply(self, v: Vector) -> Vector:
return tri_apply(self.ky[0], self.ky[1], v)
def residual_terms(op: Laplace2D, f: Terms, modes: Terms) -> Terms:
"""R = F - Kx U - U Ky for U = sum X_m Y_m^T, as a list of products."""
out = list(f)
for x, y in modes:
out.append(([-t for t in op.kx_apply(x)], y))
out.append(([-t for t in x], op.ky_apply(y)))
return out
def norm2(terms: Terms) -> float:
"""Squared Frobenius norm of sum p_t q_t^T, by the Gram identity."""
total = 0.0
for i, (p, q) in enumerate(terms):
total += dot(p, p) * dot(q, q)
for p2, q2 in terms[i + 1:]:
total += 2.0 * dot(p, p2) * dot(q, q2)
return max(total, 0.0)
def times_right(terms: Terms, y: Vector) -> Vector:
"""R y."""
out = [0.0] * len(terms[0][0])
for p, q in terms:
c = dot(q, y)
out = [a + c * b for a, b in zip(out, p)]
return out
def times_left(terms: Terms, x: Vector) -> Vector:
"""R^T x."""
out = [0.0] * len(terms[0][1])
for p, q in terms:
c = dot(p, x)
out = [a + c * b for a, b in zip(out, q)]
return out
def start_vector(terms: Terms, nx: int) -> Vector:
"""A Y with R Y != 0 when R != 0: Y = R^T w for w = (1, ..., 1), then w = e_1, e_2, ..."""
for w in [[1.0] * nx] + [[1.0 if i == j else 0.0 for i in range(nx)] for j in range(nx)]:
y = times_left(terms, w)
if any(t != 0.0 for t in y):
return y
raise ValueError("the residual is zero")
def solve_x(op: Laplace2D, terms: Terms, y: Vector) -> Vector:
"""The minimizer over X of the energy for a fixed Y: (|Y|^2 Kx + (Y^T Ky Y) I) X = R Y."""
yy, yky = dot(y, y), dot(y, op.ky_apply(y))
return tri_solve(yy * op.kx[0] + yky, yy * op.kx[1], times_right(terms, y))
def solve_y(op: Laplace2D, terms: Terms, x: Vector) -> Vector:
"""The minimizer over Y for a fixed X: ((X^T Kx X) I + |X|^2 Ky) Y = R^T X."""
xx, xkx = dot(x, x), dot(x, op.kx_apply(x))
return tri_solve(xx * op.ky[0] + xkx, xx * op.ky[1], times_left(terms, x))
def pgd(op: Laplace2D, f: Terms, m_max: int, tol: float = 1e-8, inner_tol: float = 1e-10, inner_max: int = 50) -> tuple[Terms, list[float], list[int]]:
"""Return the modes (X_m, Y_m), the relative residuals before each step, and the inner counts."""
modes: Terms = [] # @line L1: U <- 0
fnorm = math.sqrt(norm2(f))
res: list[float] = []
inner: list[int] = []
for _ in range(m_max): # @line L2
terms = residual_terms(op, f, modes) # @line L3: R = F - Kx U - U Ky
res.append(math.sqrt(norm2(terms)) / fnorm)
if res[-1] <= tol: # @line L4: stop when the residual is small
break
y = start_vector(terms, op.nx) # @line L5
it = 0
for it in range(inner_max): # @line L6: alternating directions
x = solve_x(op, terms, y) # @line L7
y_new = solve_y(op, terms, x) # @line L8
# the change from X Y^T to X Y_new^T in the Frobenius norm, relative
xx = dot(x, x)
ch = xx * (dot(y_new, y_new) - 2.0 * dot(y, y_new) + dot(y, y))
y = y_new
if ch <= inner_tol ** 2 * xx * dot(y, y):
break
inner.append(it + 1)
modes.append((x, y)) # @line L9: U <- U + X Y^T
return modes, res, inner # @line L10
def to_dense(modes: Terms, nx: int, ny: int) -> list[Vector]:
u = [[0.0] * ny for _ in range(nx)]
for x, y in modes:
for i in range(nx):
for j in range(ny):
u[i][j] += x[i] * y[j]
return u
test_proper_generalized_decomposition.py 212 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/proper-generalized-decomposition/. The authors are listed in prov/TWTF98.jsonl.
import math
import random
import pytest
from proper_generalized_decomposition import (
Laplace2D,
dot,
norm2,
pgd,
residual_terms,
times_left,
times_right,
to_dense,
tri_apply,
tri_solve,
)
def dense(terms, nx, ny):
return to_dense(terms, nx, ny)
def apply_a(op, v):
"""Kx V + V Ky for a dense nx by ny matrix V."""
nx, ny = op.nx, op.ny
out = [[0.0] * ny for _ in range(nx)]
for j in range(ny):
col = op.kx_apply([v[i][j] for i in range(nx)])
for i in range(nx):
out[i][j] += col[i]
for i in range(nx):
row = op.ky_apply(v[i])
for j in range(ny):
out[i][j] += row[j]
return out
def inner(p, q):
return sum(a * b for ra, rb in zip(p, q) for a, b in zip(ra, rb))
def energy_functional(op, fd, v):
"""J(V) = 1/2 <V, A V> - <F, V>."""
return 0.5 * inner(v, apply_a(op, v)) - inner(fd, v)
def sine_solve(op, fd):
"""Reference solution of Kx U + U Ky = F by the discrete sine transform in each direction."""
nx, ny = op.nx, op.ny
sx = [[math.sqrt(2.0 / (nx + 1)) * math.sin((i + 1) * (k + 1) * math.pi / (nx + 1)) for k in range(nx)] for i in range(nx)]
sy = [[math.sqrt(2.0 / (ny + 1)) * math.sin((i + 1) * (k + 1) * math.pi / (ny + 1)) for k in range(ny)] for i in range(ny)]
lx = [op.kx[0] + 2 * op.kx[1] * math.cos((k + 1) * math.pi / (nx + 1)) for k in range(nx)]
ly = [op.ky[0] + 2 * op.ky[1] * math.cos((k + 1) * math.pi / (ny + 1)) for k in range(ny)]
t = [[sum(sx[i][k] * fd[i][j] for i in range(nx)) for j in range(ny)] for k in range(nx)]
g = [[sum(t[k][j] * sy[j][l] for j in range(ny)) / (lx[k] + ly[l]) for l in range(ny)] for k in range(nx)]
t2 = [[sum(sx[i][k] * g[k][l] for k in range(nx)) for l in range(ny)] for i in range(nx)]
return [[sum(t2[i][l] * sy[j][l] for l in range(ny)) for j in range(ny)] for i in range(nx)]
def gauss_solve(m, b):
n = len(b)
a = [list(row) + [bi] for row, bi in zip(m, b)]
for k in range(n):
piv = max(range(k, n), key=lambda i: abs(a[i][k]))
a[k], a[piv] = a[piv], a[k]
for i in range(k + 1, n):
c = a[i][k] / a[k][k]
for j in range(k, n + 1):
a[i][j] -= c * a[k][j]
x = [0.0] * n
for i in range(n - 1, -1, -1):
x[i] = (a[i][n] - sum(a[i][j] * x[j] for j in range(i + 1, n))) / a[i][i]
return x
def jacobi_eigenvalues(a, sweeps=60):
n = len(a)
a = [list(r) for r in a]
for _ in range(sweeps):
off = sum(a[i][j] ** 2 for i in range(n) for j in range(n) if i != j)
if off <= 1e-30 * sum(a[i][i] ** 2 for i in range(n)):
break
for p in range(n - 1):
for q in range(p + 1, n):
if a[p][q] == 0.0:
continue
th = (a[q][q] - a[p][p]) / (2 * a[p][q])
t = (1.0 if th >= 0 else -1.0) / (abs(th) + math.sqrt(th * th + 1))
c = 1 / math.sqrt(t * t + 1)
s = t * c
for k in range(n):
a[k][p], a[k][q] = c * a[k][p] - s * a[k][q], s * a[k][p] + c * a[k][q]
for k in range(n):
a[p][k], a[q][k] = c * a[p][k] - s * a[q][k], s * a[p][k] + c * a[q][k]
return sorted((a[i][i] for i in range(n)), reverse=True)
def rel_errors(op, u, modes):
"""Relative energy and Frobenius errors of the first m modes, m = 1..len(modes)."""
eu, fu = inner(u, apply_a(op, u)), inner(u, u)
out = []
for m in range(1, len(modes) + 1):
um = dense(modes[:m], op.nx, op.ny)
e = [[p - q for p, q in zip(ra, rb)] for ra, rb in zip(u, um)]
out.append((math.sqrt(max(inner(e, apply_a(op, e)), 0.0) / eu), math.sqrt(inner(e, e) / fu)))
return out
def random_rhs(rng, nx, ny, s):
return [([rng.gauss(0, 1) for _ in range(nx)], [rng.gauss(0, 1) for _ in range(ny)]) for _ in range(s)]
def test_tridiagonal_solve():
rng = random.Random(1)
rhs = [rng.gauss(0, 1) for _ in range(9)]
z = tri_solve(5.0, -2.0, rhs)
assert tri_apply(5.0, -2.0, z) == pytest.approx(rhs, abs=1e-12)
assert tri_solve(3.0, -1.0, [6.0]) == [2.0]
def test_sine_reference_against_the_kronecker_system():
rng = random.Random(2)
op = Laplace2D(4, 3, 1.0, 0.3)
nx, ny = 4, 3
fd = [[rng.gauss(0, 1) for _ in range(ny)] for _ in range(nx)]
cols = []
for c in range(nx * ny):
e = [[1.0 if i * ny + j == c else 0.0 for j in range(ny)] for i in range(nx)]
ae = apply_a(op, e)
cols.append([ae[i][j] for i in range(nx) for j in range(ny)])
mat = [[cols[c][r] for c in range(nx * ny)] for r in range(nx * ny)]
x = gauss_solve(mat, [fd[i][j] for i in range(nx) for j in range(ny)])
u = sine_solve(op, fd)
assert [u[i][j] for i in range(nx) for j in range(ny)] == pytest.approx(x, rel=1e-10, abs=1e-12)
def test_separated_operations_against_dense():
rng = random.Random(3)
op = Laplace2D(6, 5, 1.0, 2.0)
f = random_rhs(rng, 6, 5, 2)
modes = random_rhs(rng, 6, 5, 3)
terms = residual_terms(op, f, modes)
rd = dense(terms, 6, 5)
ad = apply_a(op, dense(modes, 6, 5))
fd = dense(f, 6, 5)
assert max(abs(rd[i][j] - fd[i][j] + ad[i][j]) for i in range(6) for j in range(5)) < 1e-9
assert norm2(terms) == pytest.approx(inner(rd, rd), rel=1e-10)
x, y = [rng.gauss(0, 1) for _ in range(6)], [rng.gauss(0, 1) for _ in range(5)]
assert times_right(terms, y) == pytest.approx([dot(row, y) for row in rd], rel=1e-10, abs=1e-9)
assert times_left(terms, x) == pytest.approx([sum(x[i] * rd[i][j] for i in range(6)) for j in range(5)], rel=1e-10, abs=1e-9)
def test_one_mode_for_a_product_of_eigenvectors():
nx, ny = 10, 7
op = Laplace2D(nx, ny, 1.0, 1.0)
sx = [math.sin(2 * (i + 1) * math.pi / (nx + 1)) for i in range(nx)]
sy = [math.sin(3 * (j + 1) * math.pi / (ny + 1)) for j in range(ny)]
modes, res, _ = pgd(op, [(sx, sy)], 5, tol=1e-9)
assert len(modes) == 1 and res[-1] <= 1e-9
u = sine_solve(op, dense([(sx, sy)], nx, ny))
um = dense(modes, nx, ny)
assert max(abs(a - b) for ra, rb in zip(u, um) for a, b in zip(ra, rb)) < 1e-12
def test_half_steps_minimize_and_the_energy_error_does_not_grow():
rng = random.Random(4)
nx, ny = 8, 6
op = Laplace2D(nx, ny, 1.0, 2.0)
f = random_rhs(rng, nx, ny, 3)
fd = dense(f, nx, ny)
u = sine_solve(op, fd)
modes, _, _ = pgd(op, f, 30, tol=1e-14)
errs = [e for e, _ in rel_errors(op, u, modes)]
assert all(b <= a * (1 + 1e-12) for a, b in zip([1.0] + errs, errs))
assert errs[9] == pytest.approx(1.074e-3, rel=1e-2) and errs[-1] < 1e-5
# the energy identity |U - V|_A^2 = 2 (J(V) - J(U))
v = dense(modes[:3], nx, ny)
e = [[p - q for p, q in zip(ra, rb)] for ra, rb in zip(u, v)]
assert inner(e, apply_a(op, e)) == pytest.approx(2 * (energy_functional(op, fd, v) - energy_functional(op, fd, u)), rel=1e-8)
# the X step is the exact minimizer for its Y: random changes of X raise J
from proper_generalized_decomposition import solve_x
base = modes[:2]
terms = residual_terms(op, f, base)
y = [rng.gauss(0, 1) for _ in range(ny)]
x = solve_x(op, terms, y)
j0 = energy_functional(op, fd, dense(base + [(x, y)], nx, ny))
assert j0 < energy_functional(op, fd, dense(base, nx, ny))
for _ in range(10):
dx = [t + 1e-3 * rng.gauss(0, 1) for t in x]
assert energy_functional(op, fd, dense(base + [(dx, y)], nx, ny)) > j0
def test_example_numbers():
n = 30
op = Laplace2D(n, n, 1.0, 1.0)
f = [([1.0] * n, [1.0] * n)]
u = sine_solve(op, dense(f, n, n))
modes, res, _ = pgd(op, f, 8, tol=1e-12)
errs = rel_errors(op, u, modes)
assert [e for e, _ in errs[:3]] == pytest.approx([3.199e-2, 3.482e-3, 8.037e-4], rel=1e-3)
assert errs[5][0] == pytest.approx(2.052e-5, rel=1e-2) and errs[7][0] == pytest.approx(5.166e-7, rel=1e-2)
assert [fr for _, fr in errs[:3]] == pytest.approx([9.193e-3, 7.118e-4, 3.793e-4], rel=1e-3)
assert res[1] == pytest.approx(0.1226, rel=1e-3)
# the SVD of the exact solution is better in the Frobenius norm at the same rank
lam = jacobi_eigenvalues([[sum(u[k][i] * u[k][j] for k in range(n)) for j in range(n)] for i in range(n)])
tail = [math.sqrt(sum(lam[m:]) / sum(lam)) for m in (1, 2, 3)]
assert tail == pytest.approx([9.146e-3, 5.040e-4, 4.624e-5], rel=1e-2)
assert all(t <= fr for t, (_, fr) in zip(tail, errs))
History
Ammar, Mokdad, Chinesta and Keunings introduced the method in 2006 to solve high-dimensional equations of the kinetic theory of complex fluids, where a grid in all configuration variables is too large. In 2009 Le Bris, Lelièvre and Maday analysed the greedy rank-one algorithm for the Poisson problem in separated form and proved its convergence. Chinesta, Keunings and Leygue wrote a primer on the method in 2014.
References
- Amine Ammar, Béchir Mokdad, Francisco Chinesta and Roland Keunings, A new family of solvers for some classes of multidimensional partial differential equations encountered in kinetic theory modeling of complex fluids, Journal of Non-Newtonian Fluid Mechanics 139(3), 2006, 153-176, the separated representation and the enrichment by alternating directions
- Claude Le Bris, Tony Lelièvre and Yvon Maday, Results and questions on a nonlinear approximation approach for solving high-dimensional partial differential equations, Constructive Approximation 30(3), 2009, 621-651, the greedy algorithm for the Poisson problem in separated form and its convergence
- Francisco Chinesta, Roland Keunings and Adrien Leygue, The Proper Generalized Decomposition for Advanced Numerical Simulations, A Primer, SpringerBriefs in Applied Sciences and Technology, Springer, 2014, the construction of the separated representation for the Poisson problem and the alternating directions
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 TWTF98 Edit this page History Report an error Markdown