Algorithmadvanced
Weighted MMSE precoding
Also called WMMSE algorithm.
Maximizes the weighted sum rate of a MIMO broadcast or interference channel by alternating updates of an equivalent MSE problem.
- Time
- O(T (K M^2 + K^2 M + B M^2 (M + K))) worst
- Space
- O(M^2 + M K) extra
- Where
- B = the number of Newton steps for the multiplier; K = the number of users; M = the number of base station antennas; T = the number of iterations
- Model
- Real RAM
- Properties
- deterministicnot global optimumiterativelinearmonotoneneeds channel at transmitter
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Qingjiang Shi, Meisam Razaviyayn, Zhi Quan Luo, Chen He, Søren Skovgaard Christensen, Rajiv Agarwal, Elisabeth de Carvalho, John M. Cioffi, 2011
Weighted MMSE (WMMSE) precoding finds the precoders of a multiuser downlink that maximize a weighted sum rate, . The rate problem is not convex, but it has the same solutions as a weighted mean square error problem with extra variables, and that problem is easy in each block of variables. WMMSE updates the receive gains, the MSE weights and the precoders in turn, and the rate never decreases. Regularized zero-forcing precoding is a closed form with one regularization for all users and no target. WMMSE has the same kind of regularized inverse in each step, but it iterates, adapts a weight for each user, and aims at any weighted sum rate. The cost is several iterations, and the result is a stationary point, which is not always the global optimum.
In plain words
A base station sends to several phones at once, and each phone has a priority. The base station wants the largest total speed, where faster speed for a high priority phone counts more. The direct problem is hard. So the base station pretends each phone has a simple receiver and asks how much error that receiver makes. It then repeats three easy steps: tune each receiver for the current beams, give each phone a weight from its error, and choose the beams that make the weighted errors smallest with the power it has. Each round makes the total speed better or keeps it the same. After some rounds the beams stop changing. The answer is good, but a different start can sometimes give a better one.
The problem
User has one antenna and receives , with known at the base station and . The base station sends with independent unit-energy symbols and the power constraint . With
the goal is to maximize for given weights . This is weighted sum rate maximization for the multiple-input single-output (MISO) downlink. The problem is NP-hard in general. The same method works for users with several antennas and for several base stations, with matrices in place of the scalars and ; the code on this page covers the MISO case.
The algorithm
User estimates as with the mean square error . WMMSE minimizes over the gains , the weights and the precoders, one block at a time.
WMMSE(h₁, ..., h_K, a, P, N0)- 1
V ← a start with Σ‖v_k‖² ≤ P ▷ for example the beams h_k, scaled to the power P repeatfor each user k:T_k ← Σ_j |h_kᴴ v_j|² + N0- 2
u_k ← h_kᴴ v_k / T_k ▷ the MMSE receive gain - 3
w_k ← 1 / (1 - ū_k h_kᴴ v_k) ▷ the inverse of the smallest MSE - 4
A ← Σ_k a_k w_k |u_k|² h_k h_kᴴ; b_k ← a_k w_k u_k h_k - 5
μ ← the smallest μ ≥ 0 with Σ_k ‖(A + μI)⁻¹ b_k‖² ≤ P; v_k ← (A + μI)⁻¹ b_k - 6
R ← Σ_k a_k log₂(1 + SINR_k) - 7
until R grows by less than a tolerance return V
Line L2 is the scalar MMSE receiver for the current beams. Line L3 sets the weight to . Lines L4 and L5 solve a convex quadratic problem with one power constraint, whose KKT conditions give a regularized inverse with a Lagrange multiplier . The power decreases in , so the implementation finds by Newton steps inside a bracket. Each round is one pass of block coordinate descent.
Example
Take three users with orthogonal channels , and , so the gains are . Let the weights be , with and . There is no interference, so the best powers are the weighted water-filling with . With users 1 and 2 active, gives , so and . User 3 gets no power, because is below . The best weighted sum rate is bits per channel use.
WMMSE starts with the beams scaled to the power 3.
| iteration | weighted sum rate | |||
|---|---|---|---|---|
| 0 | 2.286 | 0.571 | 0.143 | 4.722 |
| 1 | 1.924 | 1.042 | 0.034 | 5.198 |
| 2 | 1.669 | 1.323 | 0.008 | 5.376 |
| 3 | 1.500 | 1.498 | 0.002 | 5.450 |
| 10 | 1.186 | 1.814 | 0.000 | 5.505 |
| 35 | 1.167 | 1.833 | 0.000 | 5.508 |
The rate grows in every row and the powers move toward . Equal powers of 1 give only 4.805. With equal weights, water-filling would give and ; the weight 2 of user 2 moves power toward that user.
Correctness
The proof is in proofs/correctness.md. Lemma 1 shows that line L2 minimizes the MSE and that the minimum is . Lemma 2 shows that line L3 is the best weight. Together they give , so the MSE problem and the rate problem have the same solutions. Lemma 3 shows that lines L4 and L5 give the best precoders for fixed and . Theorem 1 shows that each iteration keeps the power at most and never decreases , so the rates converge. Theorem 2 shows that every fixed point satisfies the KKT conditions of the weighted sum rate problem. Theorem 3 shows that with one user WMMSE gives maximum ratio transmission, and Theorem 4 shows that with orthogonal channels the optimum is weighted water-filling, as in the example.
Proof: The WMMSE iteration never decreases the weighted sum rate, meets the power constraint, and its fixed points are KKT points of the weighted sum rate problemfull
The model is for , with , , , and with independent unit-energy symbols. Let and . For weights , the problem is
The receiver of user estimates as . Its MSE is . WMMSE works on
Lines L2, L3 and L4 to L6 minimize over , over and over , in turn.
Lemma 1 (the receive step). For fixed , is minimized by (line L2), with the minimum , which lies in .
Proof. is a convex quadratic in with the positive coefficient , and its gradient with respect to is . At the zero, , which is and equals . It is positive because .
Lemma 2 (the weight step). For , over has the unique minimizer (line L3), with the value .
Proof. The function is strictly convex in , and its derivative is zero only at .
So, with , Lemmas 1 and 2 give
Minimizing is the same as maximizing .
Lemma 3 (the precoder step). For fixed and , let and . Then , where does not depend on . A minimizer over is , with if this choice with is defined and meets the power, and otherwise the with .
Proof. Expand . The quadratic part is , and the linear part is . is positive semidefinite, so the problem is convex, and is strictly feasible, so the KKT conditions are necessary and sufficient: , , and . If is invertible and , where , then satisfies them. Otherwise, in the eigenbasis , , which is continuous and strictly decreasing on (unless all , when is optimal) and tends to 0. Each is 0 or a multiple of with , and then is in the range of , so has no component on the eigenvectors with . So is finite. If , there is a unique with , and it satisfies the KKT conditions. If , the limit gives the minimum norm solution of , which satisfies them with .
The implementation finds the root of by Newton's method on , kept inside a bracket with ; the start is valid because . It stops when , or returns the precoder at , which meets the power.
Theorem 1 (monotone rate). Let be the precoder after iteration , with feasible. Then every is feasible and . The sequence converges.
Proof. Let be the outputs of lines L2 and L3 for . By Lemmas 1 and 2, . By Lemma 3, minimizes over the feasible set, which contains , so is feasible and . By the definition of as a minimum, . So , which is . The rate is bounded: . A bounded nondecreasing sequence converges.
Theorem 2 (fixed points are KKT points). If is a fixed point of one iteration, then satisfies the KKT conditions of the weighted sum rate problem: for all with one , and .
Proof. Lemma 1 gives and Lemma 2 gives as smooth functions of (as functions of the real and imaginary parts), because and . So is smooth, and by the chain rule
since and at the minimizers and , which are interior points. At a fixed point, is the output of Lemma 3 for , so with and . Hence . With , this is , the KKT condition with .
The problem is not convex, so a KKT point can be a local maximum or a saddle point and not the global maximum. The tests include a two-user channel where the default start converges to a worse point than another start.
Theorem 3 (one user). For , every precoder step returns a multiple of , and the only fixed points are , the maximum ratio transmission beam with the rate , which is the global maximum.
Proof. Here with and . is an eigenvector of , so is a multiple of (the minimum norm solution for too). For the fixed points, let with and . If at a fixed point, then , so , and with this gives , which is impossible for . So and . The rate is at most by the Cauchy-Schwarz inequality, with equality exactly for these beams.
Theorem 4 (orthogonal channels). If for orthonormal , the maximum of is with the weighted water-filling powers , where is set by .
Proof. For any feasible , , so with . The right side is a concave function of the powers , and its KKT conditions give for and for (the factor is put into ), which is the formula. The choice gives no interference and , so it reaches the bound.
The tests check Theorem 1 (the rate never drops by more than in 15 iterations, for up to 8 users and 8 antennas), the power within , Theorem 2 by a finite difference gradient at convergence, Theorem 3, Theorem 4 (WMMSE reaches the weighted water-filling value), a grid search over the beam parameters for two users (the best of six starts matches the grid within and is never below it), and the local optimum mentioned after Theorem 2.
Complexity
One iteration computes the matrix of values in and the matrix in . Each Newton step of line L5 solves a linear system with unknowns and right sides in , and steps are needed. With iterations, the time is . An eigendecomposition of once per iteration makes each later evaluation of the power cheaper. The extra space is for and for the precoders. The number of iterations depends on the channel and the start; it is often tens, but there is no small bound.
Properties
- Monotone. The weighted sum rate never decreases from one iteration to the next (theorem).
- Feasible. Each iterate meets the power constraint, and the power is exactly whenever (theorem).
- Stationary limit. Every fixed point is a KKT point of the weighted sum rate problem (theorem).
- Not always global. The problem is not convex, and WMMSE can stop at a local optimum.
- Regularized inverse structure. Each precoder has the form times a scalar, the same structure as the optimal beams.
- Exact special cases. One user gives maximum ratio transmission, and orthogonal channels give weighted water-filling (theorems).
- Linear. The output is a linear precoder, so the cost per symbol is .
Variants and improvements
- Users with several antennas. Replace by a receive matrix and by a weight matrix; the steps stay closed forms, and the method then optimizes the rate of each MIMO link.
- Interfering broadcast channel. Shi, Razaviyayn, Luo and He apply the same steps to several base stations, each with its own power constraint, and each base station can compute its own update.
- Other utilities. A change of the weight update handles proportional fairness, the harmonic mean rate and other utilities of the rates.
- Scheduling weights. In a scheduler, the weights come from queue lengths or from average rates, as in proportional fair scheduling.
- Several starts. Run from the maximum ratio transmission beams, from the zero-forcing beams and from random beams, and keep the best result.
- Linear alternatives. Zero-forcing and block diagonalization are cheaper and close to WMMSE at high SNR; dirty paper coding is the nonlinear scheme that reaches the capacity of the broadcast channel.
When to use it
Use WMMSE when the base station has good channel knowledge, the users have different priorities, and there is time for a few tens of matrix inversions per channel update. It is a standard reference design for the weighted sum rate of the MIMO downlink and for coordinated base stations. When all weights are equal and the SNR is high, regularized zero-forcing precoding is close and much cheaper. In massive MIMO with many more antennas than users, the gain over regularized zero forcing is often small.
Pitfalls
- Local optima. On one random two-user channel with the weights 1 and 1.915 and , the default start converges to a point that serves both users with the weighted sum rate 9.660. Serving only user 2 by maximum ratio transmission gives 10.418. Try several starts.
- A zero start. If , then and user stays off forever. Start with all beams nonzero.
- Singular . When , has a null space, and is not defined. Use the smallest positive , or the minimum norm solution.
- The stopping rule. The rate can grow slowly for many iterations. Stop on a relative change, and also limit the number of iterations.
- Stale channel. The steps use exactly; with old channel estimates the computed SINR values are too high.
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
# Shared helper of the communications pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Complex baseband tools for the communications pages.
Vectors are lists of complex numbers. Matrices are lists of rows. The
functions here are plain building blocks: small linear algebra, convolution,
the DFT as a direct sum, the Gaussian Q function, dB conversion, complex
Gaussian noise and the Wilson score interval. No page algorithm (equalizer,
estimator, synchronizer, detector, precoder, demapper or power allocation)
lives in this file.
Conventions (prompts of the communications area):
- dft is X[k] = sum_n x[n] e^(-j 2 pi k n / N) with no factor; idft has 1/N.
- udft and uidft are the unitary pair, with 1/sqrt(N) on both sides.
- qfunc(x) = 0.5 erfc(x / sqrt(2)); it never computes 1 - Phi(x).
- cn(rng, var) draws CN(0, var): real and imaginary parts are independent
with variance var / 2 each, so E|w|^2 = var.
"""
import cmath
import math
import random
# ---------------------------------------------------------------- vectors and matrices
def zeros(rows: int, cols: int | None = None) -> list:
"""A zero vector of length rows, or a rows by cols zero matrix."""
if cols is None:
return [0j] * rows
return [[0j] * cols for _ in range(rows)]
def eye(n: int) -> list[list[complex]]:
"""The n by n identity matrix."""
return [[1 + 0j if i == k else 0j for k in range(n)] for i in range(n)]
def add(a: list, b: list) -> list:
"""Elementwise a + b for two vectors or two matrices of the same shape."""
if len(a) != len(b):
raise ValueError("shapes differ")
if a and isinstance(a[0], list):
return [add(r, s) for r, s in zip(a, b)]
return [x + y for x, y in zip(a, b)]
def sub(a: list, b: list) -> list:
"""Elementwise a - b for two vectors or two matrices of the same shape."""
if len(a) != len(b):
raise ValueError("shapes differ")
if a and isinstance(a[0], list):
return [sub(r, s) for r, s in zip(a, b)]
return [x - y for x, y in zip(a, b)]
def scale(c: complex, a: list) -> list:
"""The scalar c times a vector or a matrix."""
if a and isinstance(a[0], list):
return [scale(c, r) for r in a]
return [c * x for x in a]
def matmul(a: list[list[complex]], b: list[list[complex]]) -> list[list[complex]]:
"""The matrix product a b."""
if not a or not b or len(a[0]) != len(b):
raise ValueError("inner dimensions differ")
cols = list(zip(*b))
return [[sum(x * y for x, y in zip(row, col)) for col in cols] for row in a]
def matvec(a: list[list[complex]], x: list[complex]) -> list[complex]:
"""The matrix times vector product a x."""
if a and len(a[0]) != len(x):
raise ValueError("inner dimensions differ")
return [sum(p * q for p, q in zip(row, x)) for row in a]
def herm(a: list) -> list:
"""The conjugate transpose of a matrix. A vector gives its conjugate."""
if a and isinstance(a[0], list):
return [[complex(a[i][k]).conjugate() for i in range(len(a))] for k in range(len(a[0]))]
return [complex(x).conjugate() for x in a]
def dot(x: list[complex], y: list[complex]) -> complex:
"""The inner product x^H y = sum of conj(x_i) y_i."""
if len(x) != len(y):
raise ValueError("lengths differ")
return sum(complex(p).conjugate() * q for p, q in zip(x, y))
def norm2(x: list) -> float:
"""The squared Euclidean norm sum |x_i|^2 (squared Frobenius norm for a matrix)."""
if x and isinstance(x[0], list):
return sum(norm2(r) for r in x)
return sum(abs(v) ** 2 for v in x)
# ---------------------------------------------------------------- linear systems
def _lu(a: list[list[complex]]) -> tuple[list[list[complex]], list[int], int]:
"""LU factorization with partial pivoting. Returns (lu, perm, sign)."""
n = len(a)
if any(len(r) != n for r in a):
raise ValueError("matrix is not square")
m = [[complex(v) for v in r] for r in a]
perm = list(range(n))
sign = 1
for k in range(n):
p = max(range(k, n), key=lambda i: abs(m[i][k]))
if abs(m[p][k]) == 0.0:
raise ValueError("matrix is singular")
if p != k:
m[k], m[p] = m[p], m[k]
perm[k], perm[p] = perm[p], perm[k]
sign = -sign
for i in range(k + 1, n):
f = m[i][k] / m[k][k]
m[i][k] = f
if f != 0:
rk, ri = m[k], m[i]
for c in range(k + 1, n):
ri[c] -= f * rk[c]
return m, perm, sign
def _lu_solve(lu: list[list[complex]], perm: list[int], b: list[complex]) -> list[complex]:
n = len(lu)
y = [complex(b[perm[i]]) for i in range(n)]
for i in range(n):
for c in range(i):
y[i] -= lu[i][c] * y[c]
for i in range(n - 1, -1, -1):
for c in range(i + 1, n):
y[i] -= lu[i][c] * y[c]
y[i] /= lu[i][i]
return y
def solve(a: list[list[complex]], b: list) -> list:
"""Solve a x = b by Gaussian elimination with partial pivoting.
b is a vector, or a matrix whose columns are right-hand sides.
Raises ValueError if a is singular.
"""
lu, perm, _ = _lu(a)
if b and isinstance(b[0], list):
cols = [list(c) for c in zip(*b)]
xs = [_lu_solve(lu, perm, c) for c in cols]
return [list(r) for r in zip(*xs)]
if len(b) != len(a):
raise ValueError("lengths differ")
return _lu_solve(lu, perm, b)
def inv(a: list[list[complex]]) -> list[list[complex]]:
"""The inverse of a square matrix."""
return solve(a, eye(len(a)))
def det(a: list[list[complex]]) -> complex:
"""The determinant of a square matrix (0 for a singular matrix)."""
try:
lu, _, sign = _lu(a)
except ValueError as e:
if "singular" in str(e):
return 0j
raise
d = complex(sign)
for i in range(len(lu)):
d *= lu[i][i]
return d
def cholesky(a: list[list[complex]]) -> list[list[complex]]:
"""The lower triangular L with a = L L^H, for a Hermitian positive definite a.
Raises ValueError if a is not positive definite (to rounding).
"""
n = len(a)
low = zeros(n, n)
for i in range(n):
for k in range(i + 1):
s = complex(a[i][k]) - sum(low[i][c] * low[k][c].conjugate() for c in range(k))
if i == k:
if s.real <= 0.0:
raise ValueError("matrix is not positive definite")
low[i][i] = complex(math.sqrt(s.real))
else:
low[i][k] = s / low[k][k].real
return low
# ---------------------------------------------------------------- convolution and the DFT
def conv(a: list[complex], b: list[complex]) -> list[complex]:
"""Linear convolution, of length len(a) + len(b) - 1."""
if not a or not b:
return []
out = [0j] * (len(a) + len(b) - 1)
for i, x in enumerate(a):
for k, y in enumerate(b):
out[i + k] += x * y
return out
def cconv(a: list[complex], b: list[complex], n: int | None = None) -> list[complex]:
"""Circular convolution of length n (default: the longer length).
Both inputs are padded with zeros to length n, or must not be longer than n.
"""
if n is None:
n = max(len(a), len(b))
if len(a) > n or len(b) > n:
raise ValueError("input longer than n")
out = [0j] * n
for i, x in enumerate(a):
for k, y in enumerate(b):
out[(i + k) % n] += x * y
return out
def _twiddles(n: int, sign: int) -> list[complex]:
return [cmath.exp(sign * 2j * math.pi * t / n) for t in range(n)]
def dft(x: list[complex]) -> list[complex]:
"""X[k] = sum over n of x[n] e^(-j 2 pi k n / N), as a direct O(N^2) sum."""
n = len(x)
w = _twiddles(n, -1)
return [sum(x[t] * w[(k * t) % n] for t in range(n)) for k in range(n)]
def idft(xf: list[complex]) -> list[complex]:
"""x[n] = (1/N) sum over k of X[k] e^(j 2 pi k n / N), the inverse of dft."""
n = len(xf)
w = _twiddles(n, 1)
return [sum(xf[k] * w[(k * t) % n] for k in range(n)) / n for t in range(n)]
def udft(x: list[complex]) -> list[complex]:
"""The unitary DFT: dft(x) / sqrt(N)."""
s = 1.0 / math.sqrt(len(x)) if x else 1.0
return [v * s for v in dft(x)]
def uidft(xf: list[complex]) -> list[complex]:
"""The unitary inverse DFT: sqrt(N) idft(X), the inverse of udft."""
s = math.sqrt(len(xf)) if xf else 1.0
return [v * s for v in idft(xf)]
# ---------------------------------------------------------------- Q function and dB
def qfunc(x: float) -> float:
"""Q(x) = P(Z > x) for a standard normal Z, computed as 0.5 erfc(x / sqrt(2))."""
return 0.5 * math.erfc(x / math.sqrt(2.0))
def qinv(p: float) -> float:
"""The x with Q(x) = p, for 0 < p < 1, by bisection on Q (which decreases)."""
if not 0.0 < p < 1.0:
raise ValueError("p must be in (0, 1)")
lo, hi = -40.0, 40.0
for _ in range(200):
mid = 0.5 * (lo + hi)
if qfunc(mid) > p:
lo = mid
else:
hi = mid
if hi - lo <= 1e-15 * max(1.0, abs(mid)):
break
return 0.5 * (lo + hi)
def db(x: float) -> float:
"""10 log10(x), for a ratio of powers or energies."""
return 10.0 * math.log10(x)
def undb(d: float) -> float:
"""10^(d / 10), the inverse of db."""
return 10.0 ** (d / 10.0)
# ---------------------------------------------------------------- noise and statistics
def cn(rng: random.Random, var: float) -> complex:
"""One sample of CN(0, var): independent real and imaginary parts of variance var / 2."""
s = math.sqrt(var / 2.0)
return complex(rng.gauss(0.0, s), rng.gauss(0.0, s))
def awgn(rng: random.Random, x: list[complex], n0: float) -> list[complex]:
"""x plus independent CN(0, n0) noise on each sample."""
return [v + cn(rng, n0) for v in x]
def wilson(k: int, n: int, z: float = 3.29) -> tuple[float, float]:
"""The Wilson score interval for k successes in n trials (z = 3.29 is about 0.999 two-sided)."""
if n <= 0 or not 0 <= k <= n:
raise ValueError("need 0 <= k <= n and n > 0")
p = k / n
z2 = z * z
den = 1.0 + z2 / n
mid = (p + z2 / (2 * n)) / den
half = z * math.sqrt(p * (1 - p) / n + z2 / (4 * n * n)) / den
return max(0.0, mid - half), min(1.0, mid + half)
weighted_mmse_precoding.py 118 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/weighted-mmse-precoding/. The authors are listed in prov/9QVSR3.jsonl.
"""Weighted MMSE (WMMSE) precoding for the multiuser MISO downlink.
User k receives y_k = h_k^H x + w_k with w_k ~ CN(0, N0), and the base
station sends x = sum_k v_k s_k with sum_k ||v_k||^2 <= P. The goal is a
local maximum of the weighted sum rate sum_k a_k log2(1 + SINR_k).
WMMSE solves the equivalent problem
minimize over (u, w, V) sum_k a_k (w_k e_k - log w_k),
e_k = E|conj(u_k) y_k - s_k|^2,
by block coordinate descent: the MMSE receive gains u (line L2), the weights
w = 1 / e (line L3), and the precoders V, a convex problem solved by a
Lagrange multiplier mu found by a safeguarded Newton search (lines L4 to L6). After the u and w
steps the objective equals sum_k a_k (1 - ln(1 + SINR_k)), so the weighted
sum rate never decreases from one iteration to the next.
"""
import math
import cbb
def sinr(h: list[list[complex]], v: list[list[complex]], n0: float) -> list[float]:
"""SINR_k = |h_k^H v_k|^2 / (sum over j != k of |h_k^H v_j|^2 + N0); v has the v_k as columns."""
e = cbb.matmul(h, v)
out = []
for k in range(len(h)):
sig = abs(e[k][k]) ** 2
out.append(sig / (sum(abs(x) ** 2 for x in e[k]) - sig + n0))
return out
def weighted_sum_rate(h, v, n0: float, weights: list[float]) -> float:
"""sum_k a_k log2(1 + SINR_k) in bits per channel use."""
return sum(a * math.log2(1.0 + s) for a, s in zip(weights, sinr(h, v, n0)))
def _solve_mu(a: list[list[complex]], b: list[list[complex]], p_total: float):
"""The precoder (A + mu I)^(-1) B with the smallest mu >= 0 that keeps the power at most P.
The power f(mu) = ||(A + mu I)^(-1) B||_F^2 decreases in mu, and
f(mu) <= ||B||_F^2 / mu^2 because A is positive semidefinite, so
mu = ||B||_F / sqrt(P) is an upper bound. The root of f(mu) = P is found
by Newton's method on f^(-1/2) - P^(-1/2), which is close to linear in
mu, with a bisection step whenever Newton leaves the bracket.
Returns (V, mu).
"""
m = len(a)
def shifted(mu: float):
return [[a[i][j] + (mu if i == j else 0.0) for j in range(m)] for i in range(m)]
lo, hi = 0.0, math.sqrt(cbb.norm2(b) / p_total)
try:
v = cbb.solve(a, b)
if cbb.norm2(v) <= p_total:
return v, 0.0
mu = 0.0
except ValueError:
mu = 1e-9 * hi # A is singular, so start a little above 0
v_hi = None
for _ in range(100):
am = shifted(mu)
v = cbb.solve(am, b)
f = cbb.norm2(v)
if abs(f - p_total) <= 1e-14 * p_total:
return v, mu
if f > p_total:
lo = mu
else:
hi, v_hi = mu, v
y = cbb.solve(am, v)
df = -2.0 * sum((v[i][k].conjugate() * y[i][k]).real for i in range(m) for k in range(len(v[0])))
nxt = mu - (f ** -0.5 - p_total ** -0.5) / (-0.5 * f ** -1.5 * df) if df < 0 else -1.0
mu = nxt if lo < nxt < hi else 0.5 * (lo + hi)
if hi - lo <= 1e-15 * hi:
break
if v_hi is None:
v_hi = cbb.solve(shifted(hi), b)
return v_hi, hi
def wmmse(h: list[list[complex]], p_total: float, n0: float, weights=None, v0=None, iters: int = 200, tol: float = 1e-12):
"""Run WMMSE on the K by M channel h. Returns (v, rates) with the precoders as columns of v.
rates[t] is the weighted sum rate after iteration t (rates[0] is the start).
The start is v0, or by default the matched beams h_k scaled to the power P.
"""
k_users, m = len(h), len(h[0])
a = weights if weights is not None else [1.0] * k_users
if v0 is None:
v0 = cbb.herm(h)
v0 = cbb.scale(math.sqrt(p_total / cbb.norm2(v0)), v0)
v = [row[:] for row in v0] # @line L1
rates = [weighted_sum_rate(h, v, n0, a)]
for _ in range(iters):
e = cbb.matmul(h, v)
tot = [sum(abs(x) ** 2 for x in e[k]) + n0 for k in range(k_users)]
u = [e[k][k] / tot[k] for k in range(k_users)] # @line L2
w = [1.0 / (1.0 - (u[k].conjugate() * e[k][k]).real) for k in range(k_users)] # @line L3
amat = [[0j] * m for _ in range(m)]
bmat = [[0j] * k_users for _ in range(m)]
for k in range(k_users):
c = a[k] * w[k] * abs(u[k]) ** 2
hk = [complex(z).conjugate() for z in h[k]] # the column h_k
for i in range(m):
for j in range(m):
amat[i][j] += c * hk[i] * hk[j].conjugate() # @line L4
bmat[i][k] = a[k] * w[k] * u[k] * hk[i]
v, _ = _solve_mu(amat, bmat, p_total) # @line L5
rates.append(weighted_sum_rate(h, v, n0, a)) # @line L6
if rates[-1] - rates[-2] < tol:
break # @line L7
return v, rates
test_weighted_mmse_precoding.py 151 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/weighted-mmse-precoding/. The authors are listed in prov/9QVSR3.jsonl.
import math
import random
import cbb
from weighted_mmse_precoding import sinr, weighted_sum_rate, wmmse
def rand_h(rng: random.Random, k: int, m: int) -> list[list[complex]]:
return [[cbb.cn(rng, 1.0) for _ in range(m)] for _ in range(k)]
def test_example() -> None:
# Orthogonal channels with gains 4, 1 and 1/4 and weights 1, 2 and 1.5 (the example of the page).
h = [[2, 0, 0], [0, 1, 0], [0, 0, 0.5]]
a = [1.0, 2.0, 1.5]
v, rates = wmmse(h, 3.0, 1.0, weights=a, iters=2000)
p = [cbb.norm2([row[k] for row in v]) for k in range(3)]
assert abs(p[0] - 7 / 6) < 1e-6 and abs(p[1] - 11 / 6) < 1e-6 and p[2] < 1e-6
want = math.log2(1 + 4 * 7 / 6) + 2 * math.log2(1 + 11 / 6)
assert abs(rates[-1] - want) < 1e-9
assert abs(rates[0] - weighted_sum_rate(h, cbb.scale(math.sqrt(3 / 5.25), cbb.herm(h)), 1.0, a)) < 1e-12
def test_single_user_is_maximum_ratio_transmission() -> None:
rng = random.Random(1)
for m in (1, 3, 8):
h = rand_h(rng, 1, m)
v, rates = wmmse(h, 5.0, 0.5)
assert abs(rates[-1] - math.log2(1 + 5.0 * cbb.norm2(h[0]) / 0.5)) < 1e-10
assert abs(abs(cbb.matmul(h, v)[0][0]) ** 2 - 5.0 * cbb.norm2(h[0])) < 1e-9
def test_orthogonal_channels_give_weighted_water_filling() -> None:
# With h_k = g_k e_k, the optimum is p_k = (a_k / lam - 1 / g_k)^+ with sum P.
rng = random.Random(2)
for _ in range(2):
g = [rng.uniform(0.1, 5.0) for _ in range(3)]
a = [rng.uniform(0.5, 2.0) for _ in range(3)]
pt = rng.uniform(0.5, 10.0)
h = [[math.sqrt(g[k]) if i == k else 0.0 for i in range(3)] for k in range(3)]
lo, hi = 1e-12, 1e3
for _ in range(200):
lam = 0.5 * (lo + hi)
if sum(max(0.0, a[k] / lam - 1 / g[k]) for k in range(3)) > pt:
lo = lam
else:
hi = lam
p = [max(0.0, a[k] / lam - 1 / g[k]) for k in range(3)]
want = sum(a[k] * math.log2(1 + g[k] * p[k]) for k in range(3))
_, rates = wmmse(h, pt, 1.0, weights=a, iters=3000, tol=1e-14)
assert abs(rates[-1] - want) < 1e-7
def test_monotone_and_power() -> None:
rng = random.Random(3)
for k, m in [(2, 2), (3, 4), (4, 4), (3, 6), (8, 8)]:
h = rand_h(rng, k, m)
a = [rng.uniform(0.5, 2.0) for _ in range(k)]
pt = rng.uniform(1.0, 30.0)
v, rates = wmmse(h, pt, 1.0, weights=a, iters=15, tol=-1.0)
assert len(rates) == 16
for t in range(15):
assert rates[t + 1] >= rates[t] - 1e-12
assert cbb.norm2(v) <= pt * (1 + 1e-12)
assert abs(cbb.norm2(v) - pt) < 1e-9 * pt
def test_kkt_at_convergence() -> None:
# At a stationary point the gradient of the weighted sum rate is lam v for one lam >= 0.
rng = random.Random(4)
h = rand_h(rng, 3, 3)
a = [1.0, 1.5, 0.7]
v, _ = wmmse(h, 4.0, 1.0, weights=a, iters=3000, tol=1e-15)
eps = 1e-6
grad = [[0j] * 3 for _ in range(3)]
for i in range(3):
for k in range(3):
parts = []
for d in (eps, 1j * eps):
vp = [row[:] for row in v]
vm = [row[:] for row in v]
vp[i][k] += d
vm[i][k] -= d
parts.append((weighted_sum_rate(h, vp, 1.0, a) - weighted_sum_rate(h, vm, 1.0, a)) / (2 * eps))
grad[i][k] = complex(parts[0], parts[1])
lam = sum((grad[i][k] * v[i][k].conjugate()).real for i in range(3) for k in range(3)) / cbb.norm2(v)
assert lam > 0
res = math.sqrt(cbb.norm2(cbb.sub(grad, cbb.scale(lam, v))))
assert res < 1e-5 * math.sqrt(cbb.norm2(grad))
def test_grid_search_two_users() -> None:
# For two users, the best beams have the form (I + sum_j lam_j h_j h_j^H / N0)^(-1) h_k with
# lam_1 + lam_2 = P. A grid over lam_1 and the power split gives a lower bound on the optimum.
# WMMSE finds a stationary point, which can be a local optimum, so the test keeps the best of 6 starts.
rng = random.Random(5)
for _ in range(2):
h = rand_h(rng, 2, 2)
a = [1.0, rng.uniform(0.5, 2.0)]
pt, n0, n = rng.uniform(1.0, 20.0), 1.0, 60
best = -1.0
for start in range(6):
v0 = None
if start > 0:
v0 = rand_h(rng, 2, 2)
v0 = cbb.scale(math.sqrt(pt / cbb.norm2(v0)), v0)
_, rates = wmmse(h, pt, n0, weights=a, v0=v0, iters=400, tol=1e-11)
best = max(best, rates[-1])
cols = cbb.herm(h)
grid = 0.0
for i in range(n + 1):
lam = [pt * i / n, pt * (n - i) / n]
am = [
[(1.0 if r == c else 0.0) + sum(lam[j] * cols[r][j] * cols[c][j].conjugate() for j in range(2)) / n0 for c in range(2)]
for r in range(2)
]
d = cbb.solve(am, cols)
d = [[d[r][k] / math.sqrt(abs(d[0][k]) ** 2 + abs(d[1][k]) ** 2) for k in range(2)] for r in range(2)]
g = [[abs(x) ** 2 for x in row] for row in cbb.matmul(h, d)] # g[q][k] = |h_q^H d_k|^2
for t in range(n + 1):
p = [pt * t / n, pt * (n - t) / n]
s0 = g[0][0] * p[0] / (g[0][1] * p[1] + n0)
s1 = g[1][1] * p[1] / (g[1][0] * p[0] + n0)
grid = max(grid, a[0] * math.log2(1 + s0) + a[1] * math.log2(1 + s1))
assert grid <= best + 1e-9
assert best - grid < 1e-3
def test_local_optimum() -> None:
# On this channel the default start converges to a point that serves both users,
# while serving only user 2 is better. Both points are stationary.
rng = random.Random(5)
h = rand_h(rng, 2, 2)
a = [1.0, rng.uniform(0.5, 2.0)]
pt = rng.uniform(1.0, 20.0)
v, rates = wmmse(h, pt, 1.0, weights=a, iters=1000, tol=1e-13)
assert min(cbb.norm2([row[k] for row in v]) for k in range(2)) > 1.0
v2 = [[0j, math.sqrt(pt) * complex(h[1][r]).conjugate() / math.sqrt(cbb.norm2(h[1]))] for r in range(2)]
one_user = weighted_sum_rate(h, v2, 1.0, a)
assert one_user > rates[-1] + 0.5
def test_sinr_formula() -> None:
h = [[1, 0], [1, 1]]
v = [[1, 0], [0, 2]]
s = sinr(h, v, 0.5)
assert abs(s[0] - 1 / 0.5) < 1e-12
assert abs(s[1] - 4 / (1 + 0.5)) < 1e-12
History
The link between rate and MSE is old: for a Gaussian channel, the rate is of the smallest MSE of the symbol. Christensen, Agarwal, de Carvalho and Cioffi (2008) used this link to design the precoders of the MIMO broadcast channel by an iteration over the receivers, the MSE weights and the precoders. Shi, Razaviyayn, Luo and He (2011) gave the general WMMSE algorithm for the MIMO interfering broadcast channel, showed that the weighted sum rate problem and the weighted MSE problem have the same optimal precoders, and showed that the iteration converges to stationary points of the weighted sum rate. Björnson, Bengtsson and Ottersten (2014) described the structure of the optimal beams as regularized inverses with one parameter per user, and why the weighted sum rate problem is hard.
References
- Qingjiang Shi, Meisam Razaviyayn, Zhi-Quan Luo and Chen He, An iteratively weighted MMSE approach to distributed sum-utility maximization for a MIMO interfering broadcast channel, IEEE Transactions on Signal Processing 59(9), 4331-4340, 2011, the equivalence between weighted sum rate maximization and weighted MSE minimization, the WMMSE algorithm, and its convergence to stationary points
- Søren Skovgaard Christensen, Rajiv Agarwal, Elisabeth de Carvalho and John M. Cioffi, Weighted sum-rate maximization using weighted MMSE for MIMO-BC beamforming design, IEEE Transactions on Wireless Communications 7(12), 4792-4799, 2008, the relation between the weighted sum rate and the weighted MMSE of the MIMO broadcast channel, and the iterative precoder design
- Emil Björnson, Mats Bengtsson and Björn Ottersten, Optimal multiuser transmit beamforming: a difficult problem with a simple solution structure, IEEE Signal Processing Magazine 31(4), 142-148, 2014, the structure of the optimal beams as regularized inverses with one nonnegative parameter per user, and the difficulty of the weighted sum rate problem
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 9QVSR3 Edit this page History Report an error Markdown