Definitioncore
Mutual coherence
Also called coherence of a dictionary.
The largest absolute normalized inner product between two distinct columns of a sensing matrix, which bounds the sparsity that recovery can guarantee.
The mutual coherence of a matrix is the largest absolute inner product between two of its distinct normalized columns. It is the simplest number that measures how well a matrix can separate sparse vectors: when no two columns are close, a sparse combination of columns determines its coefficients. It is cheap to compute, in contrast with the restricted isometry constants and the null space property, which look at all sets of columns and are NP-hard to compute. The price is that the guarantees it gives are weaker: they apply only for sparsity of order , while restricted isometry gives sparsity of order up to a logarithm. Coherence is also the standard measure of quality for a learned dictionary, for example one from K-SVD.
Definition
Let have nonzero columns . The mutual coherence of is
It does not change when a column is scaled by a nonzero number, so one can assume that the columns have norm 1, and then is the largest absolute entry off the diagonal of the Gram matrix . Always . means that the columns are orthogonal, which needs , and means that two columns are parallel.
The direct computation takes time:
COHERENCE(A)- 1
for j = 1 to n: c_j ← a_j / ‖a_j‖ - 2
μ ← 0 - 3
for i = 1 to n - 1 - 4
for j = i + 1 to n - 5
μ ← max(μ, |⟨c_i, c_j⟩|) - 6
return μ
Lower bound (Welch 1974). For unit vectors in ,
Proof. Let be the Gram matrix. It has trace and rank at most , so by the Cauchy-Schwarz inequality on its at most nonzero eigenvalues, . The diagonal gives and each of the entries off the diagonal is at most in squared absolute value, so . Solve for .
Equality holds exactly for equiangular tight frames, where all are equal and . For the bound is about . See the Welch bound page for the bound on sequences.
What coherence guarantees. Let the columns have norm 1 and let .
- Every set of columns with is linearly independent, and the restricted isometry constant satisfies . The Gram matrix of columns has diagonal 1 and off-diagonal entries of absolute value at most , so by the Gershgorin circle theorem its eigenvalues are in . For this is an equality: .
- The spark of , the least number of linearly dependent columns, satisfies . This follows from item 1.
- If and has nonzero entries with , then is the unique sparsest solution of (Donoho and Elad 2003), and both basis pursuit and orthogonal matching pursuit find it (Donoho and Huo 2001 for a pair of orthonormal bases, Donoho and Elad 2003 and Gribonval and Nielsen 2003 for basis pursuit with more general dictionaries, Tropp 2004 for OMP and basis pursuit). With noise, the same condition with a stricter constant gives stable recovery.
The Welch bound makes at most about when is a multiple of , so item 3 never gives more than about nonzeros. This limit is called the square root bottleneck. It is a limit of the coherence argument, not of the matrices: a random Gaussian matrix has of order , so coherence gives of order , while the same matrix has the restricted isometry property for of order .
Examples and non-examples
Identity and Hadamard. In let with the Sylvester Hadamard matrix
The columns have norm 1. Two identity columns are orthogonal, and so are two Hadamard columns. An identity column and a Hadamard column meet with inner product . So . The Welch bound for 8 vectors in is , so this matrix is not optimal. The coherence bound gives and uniqueness for , that is . The true spark is 4: the first two Hadamard columns add up to . For every power of two the matrix has , and the analogous pair of identity and unitary DFT has the same coherence; these are the pairs of bases of Donoho and Huo. The compressed sensing page uses the same construction.
Regular simplex. Three unit vectors in the plane at 120 degrees have , which equals the Welch bound . More generally, the vertices of a regular simplex centered at the origin in give , which also equals the Welch bound. They form an equiangular tight frame.
Repeated column. A matrix with two parallel columns has , and the bounds above say nothing. Indeed and times the same column give the same measurement.
Non-example of a good bound. Coherence is a worst case over pairs. A matrix can have one bad pair of columns and still recover most sparse vectors; and a matrix with small coherence can still fail for some sets of columns with , as the identity and Hadamard example shows at : the vectors and are two different 2-sparse solutions of the same measurement.
Measurement. For 20 random Gaussian matrices of size (seeds 0 to 19 of Python's random.Random), the measured coherence was between 0.43 and 0.56, with mean 0.47. The Welch bound for this size is 0.089. So for these matrices the coherence bound guarantees recovery only for , while the asymptotic Donoho-Tanner phase transition for basis pursuit at lies at about , that is near 25 nonzeros, for typical sparse vectors.
Related definitions
- Restricted isometry property. The constant bounds the eigenvalues of all Gram submatrices, not just the entries. for unit columns, and .
- Null space property. The exact condition for basis pursuit to recover every -sparse vector. Coherence below implies it. See null space property.
- Spark. The least number of dependent columns. Every -sparse vector is the unique sparsest solution if and only if . The spark is NP-hard to compute in general, and is a cheap lower bound.
- Babel function or cumulative coherence. (Tropp 2004). It is at most , and conditions in terms of it are sharper when a few pairs are much worse than the rest.
- Coherence between two bases. For orthonormal bases and of , is the coherence of . In compressed sensing the scaled version , between 1 and , sets how many random samples in are needed to recover a signal sparse in .
Code
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
# Shared helper of the imaging and inverse problems pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Dense linear algebra on lists of rows (float, complex or Fraction entries).
A matrix is a list of rows. A vector is a list of numbers. The inner product
is <u, v> = sum_i conj(u_i) v_i, linear in the second argument, so that the
adjoint A^H satisfies <A x, y> = <x, A^H y>.
"""
import math
def _flat(x):
"""Flatten a list of rows (an image) into one list; a vector is returned as is."""
if x and isinstance(x[0], (list, tuple)):
return [v for row in x for v in row]
return x
def zeros(m, n):
"""The m x n zero matrix."""
return [[0.0] * n for _ in range(m)]
def eye(n):
"""The n x n identity matrix."""
out = zeros(n, n)
for i in range(n):
out[i][i] = 1.0
return out
def transpose(a):
"""A^T."""
return [list(col) for col in zip(*a)]
def conj_transpose(a):
"""A^H, the conjugate transpose."""
return [[v.conjugate() for v in col] for col in zip(*a)]
def matmul(a, b):
"""The product A B."""
bt = list(zip(*b))
return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]
def matvec(a, x):
"""The product A x."""
return [sum(v * w for v, w in zip(row, x)) for row in a]
def rmatvec(a, y):
"""The product A^H y."""
n = len(a[0]) if a else 0
out = [0.0] * n
for row, yi in zip(a, y):
if yi == 0:
continue
for j, v in enumerate(row):
out[j] += v.conjugate() * yi
return out
def dot(u, v):
"""<u, v> = sum_i conj(u_i) v_i. Images (lists of rows) are flattened."""
return sum(a.conjugate() * b for a, b in zip(_flat(u), _flat(v)))
def norm2(x):
"""The Euclidean norm. Images (lists of rows) are flattened."""
return math.sqrt(sum(abs(v) ** 2 for v in _flat(x)))
def solve(a, b):
"""Solve A x = b by Gaussian elimination with partial pivoting.
b is a vector or a matrix (a list of rows). A must be square and
nonsingular; a zero pivot raises ValueError. Fractions stay exact.
"""
n = len(a)
vec = not (b and isinstance(b[0], (list, tuple)))
rhs = [[bi] for bi in b] if vec else [list(r) for r in b]
m = [list(row) + rhs[i] for i, row in enumerate(a)]
w = len(m[0])
for c in range(n):
p = max(range(c, n), key=lambda r: abs(m[r][c]))
if m[p][c] == 0:
raise ValueError("singular matrix")
m[c], m[p] = m[p], m[c]
piv = m[c][c]
for r in range(c + 1, n):
f = m[r][c] / piv
if f != 0:
mr, mc = m[r], m[c]
for j in range(c, w):
mr[j] -= f * mc[j]
x = [[0.0] * (w - n) for _ in range(n)]
for r in range(n - 1, -1, -1):
for j in range(w - n):
s = m[r][n + j] - sum(m[r][k] * x[k][j] for k in range(r + 1, n))
x[r][j] = s / m[r][r]
return [row[0] for row in x] if vec else x
def cholesky(a):
"""Lower triangular L with A = L L^H for a Hermitian positive definite A."""
n = len(a)
low = zeros(n, n)
for j in range(n):
d = a[j][j] - sum(abs(low[j][k]) ** 2 for k in range(j))
d = d.real if isinstance(d, complex) else d
if not d > 0:
raise ValueError("matrix is not positive definite")
ljj = math.sqrt(d)
low[j][j] = ljj
for i in range(j + 1, n):
s = a[i][j] - sum(low[i][k] * low[j][k].conjugate() for k in range(j))
low[i][j] = s / ljj
return low
def cho_solve(low, b):
"""Solve (L L^H) x = b, with L from cholesky."""
n = len(low)
z = [0.0] * n
for i in range(n):
z[i] = (b[i] - sum(low[i][k] * z[k] for k in range(i))) / low[i][i]
x = [0.0] * n
for i in range(n - 1, -1, -1):
s = z[i] - sum(low[k][i].conjugate() * x[k] for k in range(i + 1, n))
x[i] = s / low[i][i].conjugate()
return x
def _rot_params(app, aqq, apq):
"""c, s of the Jacobi rotation that zeroes the (p, q) entry of [[app, apq], [apq, aqq]]."""
theta = (aqq - app) / (2.0 * apq)
t = (1.0 if theta >= 0 else -1.0) / (abs(theta) + math.sqrt(theta * theta + 1.0))
c = 1.0 / math.sqrt(1.0 + t * t)
return c, c * t
def sym_eig(a, tol=1e-15, max_sweeps=100):
"""Eigenvalues (ascending) and eigenvectors (as columns) of a real symmetric matrix.
Cyclic Jacobi method. Returns (w, Q) with A = Q diag(w) Q^T.
"""
n = len(a)
m = [[float(v) for v in row] for row in a]
q = eye(n)
for _ in range(max_sweeps):
off = sum(m[i][j] ** 2 for i in range(n) for j in range(n) if i != j)
scale = sum(m[i][i] ** 2 for i in range(n)) + off
if off <= (tol * tol) * scale or off == 0.0:
break
for p in range(n - 1):
for r in range(p + 1, n):
apq = m[p][r]
if apq == 0.0:
continue
c, s = _rot_params(m[p][p], m[r][r], apq)
for k in range(n):
mkp, mkr = m[k][p], m[k][r]
m[k][p] = c * mkp - s * mkr
m[k][r] = s * mkp + c * mkr
mp, mr = m[p], m[r]
for k in range(n):
mpk, mrk = mp[k], mr[k]
mp[k] = c * mpk - s * mrk
mr[k] = s * mpk + c * mrk
m[p][r] = m[r][p] = 0.0
for k in range(n):
qkp, qkr = q[k][p], q[k][r]
q[k][p] = c * qkp - s * qkr
q[k][r] = s * qkp + c * qkr
order = sorted(range(n), key=lambda i: m[i][i])
w = [m[i][i] for i in order]
qs = [[q[k][i] for i in order] for k in range(n)]
return w, qs
def _complete(cols, m):
"""Replace zero columns of an m-row column list by unit vectors orthogonal to the others."""
for idx, col in enumerate(cols):
if any(v != 0.0 for v in col):
continue
for e in range(m):
cand = [0.0] * m
cand[e] = 1.0
for _ in range(2):
for jdx, other in enumerate(cols):
if jdx == idx or not any(v != 0.0 for v in other):
continue
h = sum(a * b for a, b in zip(other, cand))
cand = [a - h * b for a, b in zip(cand, other)]
nrm = math.sqrt(sum(v * v for v in cand))
if nrm > 0.5:
cols[idx] = [v / nrm for v in cand]
break
return cols
def svd(a, tol=1e-15, max_sweeps=100):
"""Thin SVD of a real m x n matrix by one-sided Jacobi (Hestenes).
Returns (U, S, V) with p = min(m, n): U is m x p, S a list of p values in
descending order, V is n x p, U^T U = I, V^T V = I and A = U diag(S) V^T.
"""
m, n = len(a), len(a[0])
if m < n:
v, s, u = svd(transpose(a), tol, max_sweeps)
return u, s, v
cols = [[float(a[i][j]) for i in range(m)] for j in range(n)]
vcols = [[1.0 if i == j else 0.0 for i in range(n)] for j in range(n)]
for _ in range(max_sweeps):
rotated = False
for p in range(n - 1):
for r in range(p + 1, n):
cp, cr = cols[p], cols[r]
alpha = sum(x * x for x in cp)
beta = sum(x * x for x in cr)
gamma = sum(x * y for x, y in zip(cp, cr))
if gamma == 0.0 or abs(gamma) <= tol * math.sqrt(alpha * beta):
continue
rotated = True
c, s = _rot_params(alpha, beta, gamma)
cols[p] = [c * x - s * y for x, y in zip(cp, cr)]
cols[r] = [s * x + c * y for x, y in zip(cp, cr)]
vp, vr = vcols[p], vcols[r]
vcols[p] = [c * x - s * y for x, y in zip(vp, vr)]
vcols[r] = [s * x + c * y for x, y in zip(vp, vr)]
if not rotated:
break
sig = [math.sqrt(sum(x * x for x in col)) for col in cols]
# A column below 1e-150 times the largest one is zero to working precision;
# its squares underflow, so its direction carries no information.
floor = max(sig) * 1e-150 if sig else 0.0
sig = [t if t > floor and t > 1e-150 else 0.0 for t in sig]
order = sorted(range(n), key=lambda j: -sig[j])
s_out = [sig[j] for j in order]
ucols = [[x / sig[j] for x in cols[j]] if sig[j] > 0.0 else [0.0] * m for j in order]
ucols = _complete(ucols, m)
u = [[ucols[j][i] for j in range(n)] for i in range(m)]
v = [[vcols[j][i] for j in order] for i in range(n)]
return u, s_out, v
def adjoint_gap(apply_a, apply_ah, x, y):
"""|<A x, y> - <x, A^H y>| / (||A x|| ||y||) for given functions A and A^H.
x and y may be vectors or images (lists of rows). If the denominator is
zero, the absolute gap is returned.
"""
ax = apply_a(x)
gap = abs(dot(ax, y) - dot(x, apply_ah(y)))
den = norm2(ax) * norm2(y)
return gap / den if den > 0.0 else gap
mutual_coherence.py 78 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/mutual-coherence/. The authors are listed in prov/1VF7YK.jsonl.
"""Mutual coherence of a matrix, the Welch bound, and brute force checks of the bounds it gives.
A matrix is a list of m rows of length n, with real or complex entries. Its
columns are the atoms. The mutual coherence is the largest absolute inner
product of two distinct normalized columns.
"""
import math
from itertools import combinations
from imgla import sym_eig
def columns(a):
return [[row[j] for row in a] for j in range(len(a[0]))]
def coherence(a):
"""Return (mu, i, j): the mutual coherence and a pair of columns that attains it."""
cols = []
for c in columns(a): # @line L1
nrm = math.sqrt(sum(abs(v) ** 2 for v in c))
if nrm == 0.0:
raise ValueError("zero column")
cols.append([v / nrm for v in c])
mu, best = 0.0, (0, 1) # @line L2
n = len(cols)
for i in range(n - 1): # @line L3
for j in range(i + 1, n): # @line L4
g = abs(sum(p.conjugate() * q for p, q in zip(cols[i], cols[j])))
if g > mu: # @line L5
mu, best = g, (i, j)
return mu, best[0], best[1] # @line L6
def welch_bound(m, n):
"""The lower bound sqrt((n - m) / (m (n - 1))) on the coherence of n unit vectors in m dimensions."""
if n <= m:
return 0.0
return math.sqrt((n - m) / (m * (n - 1)))
def max_sparsity_for_uniqueness(mu):
"""The largest integer s with s < (1 + 1/mu) / 2."""
bound = (1.0 + 1.0 / mu) / 2.0
s = math.ceil(bound) - 1
return max(s, 0)
def _gram(cols, idx):
return [[sum(p * q for p, q in zip(cols[i], cols[j])) for j in idx] for i in idx]
def spark(a, tol=1e-10):
"""The least number of linearly dependent columns (real matrices), by brute force.
Returns n + 1 if all n columns are independent.
"""
cols = columns(a)
n = len(cols)
for k in range(1, n + 1):
for idx in combinations(range(n), k):
w, _ = sym_eig(_gram(cols, idx))
if w[0] <= tol * max(1.0, w[-1]):
return k
return n + 1
def restricted_isometry_constant(a, s):
"""delta_s of a real matrix whose columns have norm 1, by enumerating all supports of size s."""
cols = columns(a)
delta = 0.0
for idx in combinations(range(len(cols)), s):
w, _ = sym_eig(_gram(cols, idx))
delta = max(delta, 1.0 - w[0], w[-1] - 1.0)
return delta
test_mutual_coherence.py 95 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/mutual-coherence/. The authors are listed in prov/1VF7YK.jsonl.
import cmath
import math
import random
from mutual_coherence import (
coherence,
max_sparsity_for_uniqueness,
restricted_isometry_constant,
spark,
welch_bound,
)
def hadamard(m):
h = [[1.0]]
while len(h) < m:
h = [row + row for row in h] + [row + [-v for v in row] for row in h]
return h
def identity_hadamard(m):
h = hadamard(m)
r = math.sqrt(m)
return [[1.0 if i == j else 0.0 for j in range(m)] + [v / r for v in h[i]] for i in range(m)]
def gauss_unit(rng, m, n):
a = [[rng.gauss(0.0, 1.0) for _ in range(n)] for _ in range(m)]
for j in range(n):
nrm = math.sqrt(sum(a[i][j] ** 2 for i in range(m)))
for i in range(m):
a[i][j] /= nrm
return a
def test_identity_and_hadamard():
# [I | H/2] in R^4: every identity column meets every Hadamard column with |<.,.>| = 1/2.
a = identity_hadamard(4)
mu, i, j = coherence(a)
assert abs(mu - 0.5) <= 1e-15
assert i < 4 <= j
assert max_sparsity_for_uniqueness(mu) == 1
# The spark is 4, above the bound 1 + 1/mu = 3: (h1 + h2) / 2 = e1 + e3.
assert spark(a) == 4
def test_identity_and_unitary_dft():
m = 4
f = [[cmath.exp(-2j * math.pi * r * c / m) / math.sqrt(m) for c in range(m)] for r in range(m)]
a = [[complex(1.0 if i == j else 0.0) for j in range(m)] + f[i] for i in range(m)]
mu, _, _ = coherence(a)
assert abs(mu - 1.0 / math.sqrt(m)) <= 1e-15
def test_simplex_frame_meets_the_welch_bound():
# Three unit vectors at 120 degrees in the plane, and m + 1 vertices of a regular simplex in R^m.
a = [[math.cos(2 * math.pi * k / 3) for k in range(3)], [math.sin(2 * math.pi * k / 3) for k in range(3)]]
mu, _, _ = coherence(a)
assert abs(mu - 0.5) <= 1e-15
assert abs(welch_bound(2, 3) - 0.5) <= 1e-15
for m in range(2, 6):
# The centered standard basis of R^(m+1) spans an m-dimensional space;
# the coherence does not depend on the coordinates chosen in it.
cols = [[(1.0 if i == k else 0.0) - 1.0 / (m + 1) for i in range(m + 1)] for k in range(m + 1)]
a = [[cols[k][i] for k in range(m + 1)] for i in range(m + 1)]
mu, _, _ = coherence(a)
assert abs(mu - 1.0 / m) <= 1e-14
assert abs(welch_bound(m, m + 1) - 1.0 / m) <= 1e-15
def test_welch_bound_holds_on_random_matrices():
rng = random.Random(1)
for m in range(2, 7):
for n in (m + 1, 2 * m, 3 * m):
a = gauss_unit(rng, m, n)
assert coherence(a)[0] >= welch_bound(m, n) - 1e-15
def test_gershgorin_bound_and_spark_bound():
rng = random.Random(2)
for _ in range(4):
a = gauss_unit(rng, 5, 8)
mu, _, _ = coherence(a)
assert abs(restricted_isometry_constant(a, 2) - mu) <= 1e-12
for s in (2, 3):
assert restricted_isometry_constant(a, s) <= (s - 1) * mu + 1e-12
assert spark(a) >= 1.0 + 1.0 / mu
a = identity_hadamard(8)
mu, _, _ = coherence(a)
assert abs(mu - 1.0 / math.sqrt(8)) <= 1e-15
for s in (2, 3):
assert restricted_isometry_constant(a, s) <= (s - 1) * mu + 1e-12
References
- David L. Donoho and Xiaoming Huo, Uncertainty principles and ideal atomic decomposition, IEEE Transactions on Information Theory 47(7), 2001, pages 2845 to 2862 (the pair of orthonormal bases, the uncertainty principle and exact recovery by l1 minimization)
- David L. Donoho and Michael Elad, Optimally sparse representation in general (nonorthogonal) dictionaries via l1 minimization, Proceedings of the National Academy of Sciences 100(5), 2003, pages 2197 to 2202 (the spark, the bound of the spark by the coherence, and recovery for s < (1 + 1/mu)/2)
- Joel A. Tropp, Greed is good, algorithmic results for sparse approximation, IEEE Transactions on Information Theory 50(10), 2004, pages 2231 to 2242 (the exact recovery condition, and recovery by OMP and basis pursuit for s < (1 + 1/mu)/2)
- Lloyd R. Welch, Lower bounds on the maximum cross correlation of signals, IEEE Transactions on Information Theory 20(3), 1974, pages 397 to 399
- Simon Foucart and Holger Rauhut, A Mathematical Introduction to Compressive Sensing, Birkhauser, 2013, the chapter on coherence
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 | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 1VF7YK Edit this page History Report an error Markdown