Techniqueadvanced
Whittle likelihood
Also called Whittle approximation, Whittle estimator.
Approximates the Gaussian likelihood of a stationary series by a sum over Fourier frequencies of log f plus the periodogram over f, with f the spectral density.
The Whittle likelihood replaces the Gaussian likelihood of a stationary series by a sum over the Fourier frequencies :
where is the model spectral density, is the periodogram, and is a set of frequencies. Whittle (1953) derived it by noting that the discrete Fourier transform nearly diagonalizes the covariance matrix of a stationary series. It is the exact likelihood of a circular version of the process, it costs with the fast Fourier transform, and for short-memory models its minimizer has the same asymptotic law as the Gaussian maximum likelihood estimate. For short series and peaked spectra it is biased, and tapering or the debiased Whittle likelihood reduce the bias.
In plain words
A stationary series can be split into waves of different frequencies. The model says how much power each frequency should carry. The data say how much power each frequency actually carries, as measured by the periodogram. For a long series, the measured power at different frequencies is almost independent, and at each frequency it is about the model power times a random factor with mean 1. So you can score a model by comparing the two at every frequency and adding up, as if each frequency were its own small, independent experiment. This is much faster than working with the full matrix of covariances between all pairs of time points, and for long series it gives almost the same answer.
When it applies
- The series is weakly stationary with a known mean, or with the mean removed. The model gives the spectral density in closed form, for example the ARMA density .
- The data are equally spaced with no gaps. Missing values break the Fourier transform.
- The asymptotic theory needs short memory: continuous and bounded away from 0, as for a causal invertible ARMA model. Long-memory models need separate theory (see the classic examples).
- is large enough for errors to be small next to . The method is most useful when the exact likelihood is expensive: long series, long-memory models, spatial grids and multivariate series.
The template
The data are . The holes are the spectral family for , the frequency set , and the minimizer MINIMIZE.
WHITTLE(x[1..n], f_θ, Θ, J, MINIMIZE) ▷ returns θ̂ and -2 log L_W(θ̂)- 1
I[j] ← |Σ_{t=1}^{n} x[t] e^{-itω_j}|² / (2πn) for j = 0, ..., n - 1 ▷ one FFT, ω_j = 2πj/n - 2
ℓ(θ): for each j ∈ J do f_j ← f_θ(ω_j) - 3
term_j ← log(2π f_j) + I[j] / f_j - 4
ℓ(θ) ← |J| log(2π) + Σ_{j ∈ J} term_j - 5
return θ̂ ← MINIMIZE(ℓ, Θ), with ℓ(θ̂)
Common choices for :
- Known mean 0: all . Then and the scale matches the exact .
- Mean removed: subtract and use , because after centering. The code does this.
- Half the frequencies: and are symmetric, , so many texts sum over only. This halves the objective and does not change the minimizer.
- A band: only the lowest frequencies, for the local Whittle estimator.
Profiling the scale. Write , where does not depend on . Minimizing over gives , and the profiled objective . The code minimizes this over . For a causal invertible ARMA model, is within of 0 for some , by Kolmogorov's formula on the grid (the tests check for ). So the minimizer is close to the minimizer of , a weighted least squares fit of the periodogram.
Why it works: the circulant approximation. Let be the covariance matrix and let be the circulant matrix with first row . Every circulant is diagonalized by the Fourier vectors, and the eigenvalue of at is . With , this gives and . So with all frequencies, is exactly the Gaussian of a series with covariance , a process that wraps around the circle. For short memory, and differ mainly in the corners, and the two log likelihoods differ by while each grows like (Brockwell and Davis 1991, Section 10.8). For white noise , and the Whittle likelihood is exact (this is Parseval's identity, checked in the tests).
What is proved and what is measured. For a causal invertible ARMA model with IID noise of finite variance, the Whittle estimator is consistent and has the same normal limit as the Gaussian maximum likelihood estimator (Brockwell and Davis 1991, Section 10.8, cited, not proved here). Normal noise is not needed. The values below were measured with the code. At the true parameters of an AR(1) model with and (seed 3), the exact was 180.574 and the Whittle value 180.065 for , and 680.140 and 681.014 for . The gap stays of order 1 while the values grow like .
Cost. Line L1 is one FFT, when is a power of 2. The code uses its own radix-2 FFT, which falls back to the direct sum on an odd factor, and the tests check it against the direct transform. Each evaluation of then costs for an ARMA(, ) model. The exact likelihood costs per evaluation with the innovations algorithm or a Kalman filter, for a general stationary model by Durbin-Levinson, and for a general covariance matrix by Cholesky. The gain is small for a low-order ARMA model and large for long-memory models, spatial grids and long multivariate series.
Classic examples
-
AR(1) has a closed form. With known mean 0 and all frequencies, and , with and the circular sum (indices mod ). The log term is , which is exponentially small. Without it, the profiled objective is minimized at the circular lag-1 autocorrelation , which is at most 1 in absolute value. A numerical check on a series of length 200 (seed 9) gave and the minimizer of the full Whittle objective . Compare the Yule-Walker estimate, which uses the ordinary lag-1 autocorrelation.
-
ARMA fitting. The code fits a causal invertible ARMA(, ) model by Nelder-Mead over unconstrained parameters , mapped to and through partial autocorrelations and the Durbin-Levinson step-up recursion, so every candidate is causal and invertible. For AR(1), 100 series per row (seed 21), comparing the Whittle estimate (W), the exact Gaussian maximum likelihood estimate (MLE) and the Yule-Walker estimate (YW):
mean W mean MLE mean YW RMSE W RMSE MLE RMSE YW mean W - MLE 0.6 128 0.5920 0.5834 0.5791 0.0756 0.0756 0.0761 0.0120 0.6 512 0.5981 0.5962 0.5951 0.0365 0.0368 0.0371 0.0031 0.9 128 0.8779 0.8687 0.8594 0.0577 0.0581 0.0651 0.0156 0.9 512 0.8961 0.8949 0.8927 0.0203 0.0185 0.0205 0.0045 The three estimators have nearly the same error. The difference between the Whittle and exact estimates falls by about 4 when grows by 4, faster than the error itself, as the gap between them predicts. An ARMA(1,1) fit with , and (seed 7) is also in the tests.
-
Long memory. For a fractionally integrated ARMA model, with . The process has no finite state space form, so the exact likelihood costs per evaluation by Durbin-Levinson. The Whittle estimator costs once and per evaluation. Fox and Taqqu (1986) proved that it stays consistent and asymptotically normal for Gaussian long-memory processes.
-
Spatial data on a grid. For a stationary random field on an grid, the exact likelihood needs a factorization of an matrix with , which is . The Whittle likelihood uses a two-dimensional FFT, . Here the edge effects are larger: on a -dimensional grid with side , the bias is of order while the standard error is of order . For they are of the same order, and for the bias dominates, so tapering or a debiased form is needed for valid inference (Guyon 1982; Dahlhaus and Künsch 1987).
Variations
- Tapered Whittle. Multiply the data by a taper that goes smoothly to 0 at both ends before line L1. This reduces the leakage of power from strong frequencies into weak ones, at the cost of some variance (Dahlhaus 1988 for time series; Dahlhaus and Künsch 1987 for random fields).
- Debiased Whittle. Sykulski et al. (2019) replace by the expected periodogram , which is smoothed by the Fejér kernel. It can be computed from the autocovariance in . This removes the main bias term and keeps the cost.
- Local Whittle. Use only the lowest frequencies and the model near 0, to estimate the memory parameter without modelling the short-range part (Künsch 1987; Robinson 1995).
- Multivariate Whittle. For a -dimensional series, use with the spectral density matrix and the periodogram matrix .
- Frequency-domain least squares. Minimizing alone, without the log term, gives the same first-order asymptotics for ARMA models, because the log term averages to about 0.
Pitfalls
- The mean. The periodogram at is . If the mean is not 0, remove it and drop . Otherwise the fit tries to explain the mean by power at frequency 0.
- Small samples and peaked spectra. differs from by leakage from nearby frequencies. When the spectrum has a sharp peak or a large dynamic range, the bias can be much larger than the standard error. Use a taper or the debiased form.
- Nonstationary data. A trend or a unit root puts huge power at the lowest frequencies, and the fit becomes meaningless. Difference or detrend first, as in the ARIMA approach.
- Identifiability. The spectral density does not change when a root of or is replaced by its reciprocal (with a change of ). Restrict the search to causal and invertible parameters, as the code does with its partial autocorrelation map.
- The value is not the exact likelihood. The Whittle value differs from the exact by . Do not mix Whittle and exact values in one likelihood ratio or information criterion. Within the Whittle family, likelihood ratio tests and AIC work to first order.
- Sampled continuous-time processes. For data sampled every time units, the model spectrum must be the aliased density , not itself.
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
# Part of https://algorithm.tamnd.com/whittle-likelihood/. The authors are listed in prov/F9TJBR.jsonl.
"""The Whittle likelihood of a stationary series and the Whittle estimate of an ARMA(p, q) model.
Conventions:
omega_j = 2 pi j / n, j = 0, ..., n - 1 (the Fourier frequencies)
I(omega_j) = |sum_(t=1..n) X_t exp(-i t omega_j)|^2 / (2 pi n) (the periodogram)
f(lambda) = (1 / (2 pi)) sum_h gamma(h) exp(-i h lambda) (the spectral density)
-2 log L_W = N log(2 pi) + sum_j [log(2 pi f(omega_j)) + I(omega_j) / f(omega_j)]
The sum runs over N frequencies: all n of them for a known zero mean, or j = 1..n-1 after
the sample mean is removed (the periodogram at j = 0 is then 0).
"""
from __future__ import annotations
import cmath
import math
from typing import Callable, Sequence
def fft(x: Sequence[complex]) -> list[complex]:
"""The DFT y_k = sum_t x_t exp(-2 pi i t k / n), t = 0..n-1.
Radix-2 splitting while n is even, and the direct O(m^2) sum on an odd factor m, so a
power of two costs O(n log n).
"""
n = len(x)
if n == 0:
return []
if n % 2 == 1:
w = [cmath.exp(-2j * math.pi * k / n) for k in range(n)]
return [sum(x[t] * w[(t * k) % n] for t in range(n)) for k in range(n)]
even = fft(x[0::2])
odd = fft(x[1::2])
half = n // 2
out = [0j] * n
for k in range(half):
tw = cmath.exp(-2j * math.pi * k / n) * odd[k]
out[k] = even[k] + tw
out[k + half] = even[k] - tw
return out
def periodogram(x: Sequence[float]) -> list[float]:
"""I(omega_j) for j = 0..n-1 with the 1 / (2 pi n) scaling."""
n = len(x)
d = fft([complex(v) for v in x])
return [abs(z) ** 2 / (2 * math.pi * n) for z in d] # @line L1
def arma_spectral_density(phi: Sequence[float], theta: Sequence[float], sigma2: float,
lam: float) -> float:
"""f(lam) = sigma2 / (2 pi) |theta(e^(-i lam))|^2 / |phi(e^(-i lam))|^2."""
z = cmath.exp(-1j * lam)
num = 1 + sum(t * z ** (k + 1) for k, t in enumerate(theta))
den = 1 - sum(a * z ** (k + 1) for k, a in enumerate(phi))
return sigma2 / (2 * math.pi) * abs(num) ** 2 / abs(den) ** 2
def whittle_neg2loglik(x: Sequence[float], f: Callable[[float], float],
demean: bool = False) -> float:
"""-2 log L_W for the spectral density f. With demean, the mean is removed and j = 0 is dropped."""
n = len(x)
if demean:
m = math.fsum(x) / n
x = [v - m for v in x]
per = periodogram(x)
js = range(1, n) if demean else range(n)
terms = []
for j in js:
fj = f(2 * math.pi * j / n) # @line L2
terms.append(math.log(2 * math.pi * fj) + per[j] / fj) # @line L3
return len(terms) * math.log(2 * math.pi) + math.fsum(terms) # @line L4
def pacf_to_ar(r: Sequence[float]) -> list[float]:
"""Step-up (Durbin-Levinson) map from partial autocorrelations in (-1, 1) to a causal AR."""
a: list[float] = []
for k, rk in enumerate(r, start=1):
a = [a[j] - rk * a[k - 2 - j] for j in range(k - 1)] + [rk]
return a
def _unpack(u: Sequence[float], p: int, q: int) -> tuple[list[float], list[float]]:
phi = pacf_to_ar([math.tanh(v) for v in u[:p]])
theta = [-c for c in pacf_to_ar([math.tanh(v) for v in u[p:p + q]])]
return phi, theta
def profiled_objective(per: Sequence[float], n: int, phi: Sequence[float],
theta: Sequence[float]) -> tuple[float, float]:
"""(-2 log L_W with sigma^2 profiled out, sigma2_hat), over j = 1..n-1."""
g = [2 * math.pi * arma_spectral_density(phi, theta, 1.0, 2 * math.pi * j / n)
for j in range(1, n)]
big_n = n - 1
sigma2 = 2 * math.pi * math.fsum(per[j] / g[j - 1] for j in range(1, n)) / big_n
value = big_n * math.log(2 * math.pi) + big_n * math.log(sigma2) + \
math.fsum(math.log(gj) for gj in g) + big_n
return value, sigma2
def nelder_mead(fun: Callable[[list[float]], float], x0: Sequence[float], step: float = 0.3,
tol: float = 1e-10, max_iter: int = 2000) -> list[float]:
"""Minimize fun by the Nelder-Mead simplex method with the standard coefficients."""
d = len(x0)
pts = [list(x0)] + [[x0[i] + (step if i == k else 0.0) for i in range(d)] for k in range(d)]
vals = [fun(p) for p in pts]
for _ in range(max_iter):
order = sorted(range(d + 1), key=vals.__getitem__)
pts = [pts[i] for i in order]
vals = [vals[i] for i in order]
if abs(vals[-1] - vals[0]) <= tol * (1 + abs(vals[0])):
break
cen = [math.fsum(p[i] for p in pts[:-1]) / d for i in range(d)]
xr = [cen[i] + (cen[i] - pts[-1][i]) for i in range(d)]
fr = fun(xr)
if fr < vals[0]:
xe = [cen[i] + 2 * (cen[i] - pts[-1][i]) for i in range(d)]
fe = fun(xe)
pts[-1], vals[-1] = (xe, fe) if fe < fr else (xr, fr)
elif fr < vals[-2]:
pts[-1], vals[-1] = xr, fr
else:
xc = [cen[i] + 0.5 * (pts[-1][i] - cen[i]) for i in range(d)]
fc = fun(xc)
if fc < vals[-1]:
pts[-1], vals[-1] = xc, fc
else:
for k in range(1, d + 1):
pts[k] = [pts[0][i] + 0.5 * (pts[k][i] - pts[0][i]) for i in range(d)]
vals[k] = fun(pts[k])
best = min(range(d + 1), key=vals.__getitem__)
return pts[best]
def whittle_fit_arma(x: Sequence[float], p: int, q: int) -> tuple[list[float], list[float], float]:
"""Whittle estimate (phi_hat, theta_hat, sigma2_hat) of a causal invertible ARMA(p, q).
The mean is removed, the periodogram is computed once by the FFT, and the profiled
objective is minimized over unconstrained u with phi and theta built from tanh(u).
"""
n = len(x)
m = math.fsum(x) / n
per = periodogram([v - m for v in x])
if p + q == 0:
return [], [], profiled_objective(per, n, [], [])[1]
u = nelder_mead(lambda w: profiled_objective(per, n, *_unpack(w, p, q))[0], [0.0] * (p + q)) # @line L5
phi, theta = _unpack(u, p, q)
return phi, theta, profiled_objective(per, n, phi, theta)[1]
test_whittle_likelihood.py 146 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/whittle-likelihood/. The authors are listed in prov/F9TJBR.jsonl.
import cmath
import math
import random
import pytest
from whittle_likelihood import (
arma_spectral_density,
fft,
pacf_to_ar,
periodogram,
whittle_fit_arma,
whittle_neg2loglik,
)
def simulate_arma(phi, theta, n, rng, burn=300):
e = [rng.gauss(0.0, 1.0) for _ in range(n + burn)]
x = [0.0] * (n + burn)
for t in range(n + burn):
s = e[t] + sum(theta[j] * e[t - 1 - j] for j in range(len(theta)) if t - 1 - j >= 0)
s += sum(phi[j] * x[t - 1 - j] for j in range(len(phi)) if t - 1 - j >= 0)
x[t] = s
return x[burn:]
def ar1_exact_neg2loglik(x, phi, sigma2):
"""Exact -2 log L of a zero-mean Gaussian AR(1) (the reference)."""
n = len(x)
s = (1 - phi * phi) * x[0] ** 2 + math.fsum((x[t] - phi * x[t - 1]) ** 2 for t in range(1, n))
return n * math.log(2 * math.pi * sigma2) - math.log(1 - phi * phi) + s / sigma2
def ar1_exact_mle(x):
"""Exact Gaussian MLE of phi for a demeaned AR(1), by golden-section search."""
n = len(x)
m = math.fsum(x) / n
d = [v - m for v in x]
def obj(a):
s = (1 - a * a) * d[0] ** 2 + math.fsum((d[t] - a * d[t - 1]) ** 2 for t in range(1, n))
return n * math.log(s / n) - math.log(1 - a * a)
lo, hi, gr = -0.9999, 0.9999, (math.sqrt(5) - 1) / 2
for _ in range(80):
c, e = hi - gr * (hi - lo), lo + gr * (hi - lo)
if obj(c) < obj(e):
hi = e
else:
lo = c
return (lo + hi) / 2
def test_fft_matches_direct_dft():
rng = random.Random(1)
for n in list(range(1, 41)) + [64, 96, 128]:
x = [complex(rng.gauss(0, 1), rng.gauss(0, 1)) for _ in range(n)]
direct = [sum(x[t] * cmath.exp(-2j * math.pi * t * k / n) for t in range(n)) for k in range(n)]
assert max(abs(a - b) for a, b in zip(fft(x), direct)) < 1e-9 * n
def test_periodogram_parseval_and_symmetry():
rng = random.Random(2)
x = [rng.gauss(0, 1) for _ in range(50)]
per = periodogram(x)
assert math.fsum(per) == pytest.approx(math.fsum(v * v for v in x) / (2 * math.pi), rel=1e-12)
assert all(per[j] == pytest.approx(per[50 - j], rel=1e-9, abs=1e-12) for j in range(1, 50))
def test_whittle_is_exact_for_white_noise():
rng = random.Random(3)
for n in (1, 7, 32, 45):
x = [rng.gauss(0, 2) for _ in range(n)]
s2 = 1.7
exact = n * math.log(2 * math.pi * s2) + math.fsum(v * v for v in x) / s2
assert whittle_neg2loglik(x, lambda lam: s2 / (2 * math.pi)) == pytest.approx(exact, rel=1e-12)
def test_spectral_density_integrates_to_the_autocovariance():
phi, n = 0.6, 256
for h in range(5):
riemann = 2 * math.pi / n * math.fsum(
arma_spectral_density([phi], [], 1.0, 2 * math.pi * j / n) * math.cos(h * 2 * math.pi * j / n)
for j in range(n))
assert riemann == pytest.approx(phi ** h / (1 - phi * phi), abs=1e-12)
def test_kolmogorov_formula_on_the_grid():
# For a causal invertible ARMA, each factor (1 - a z) with |a| < 1 of phi or theta gives
# prod_j (1 - a exp(-i omega_j)) = 1 - a^n, so the average of log(2 pi f / sigma^2) over the
# n Fourier frequencies is a sum of terms (2 / n) log|1 - a^n|, which is tiny.
for phi, theta in (([0.5], [0.4]), ([0.9], []), ([1.0, -0.5], [-0.3])):
n = 512
avg = math.fsum(math.log(2 * math.pi * arma_spectral_density(phi, theta, 1.0, 2 * math.pi * j / n))
for j in range(n)) / n
assert abs(avg) < 1e-12
def test_pacf_to_ar_round_trip():
rng = random.Random(4)
for _ in range(50):
p = rng.randint(1, 5)
r = [rng.uniform(-0.95, 0.95) for _ in range(p)]
a = pacf_to_ar(r)
# step down: recover the partial autocorrelations
back = []
cur = a[:]
for k in range(p, 0, -1):
rk = cur[k - 1]
back.append(rk)
cur = [(cur[j] + rk * cur[k - 2 - j]) / (1 - rk * rk) for j in range(k - 1)]
assert back[::-1] == pytest.approx(r, abs=1e-9)
def test_whittle_close_to_exact_likelihood_at_true_parameters():
# Measured: the gap is O(1) while both values grow like n.
rng = random.Random(5)
for n in (128, 512):
x = simulate_arma([0.6], [], n, rng)
exact = ar1_exact_neg2loglik(x, 0.6, 1.0)
wh = whittle_neg2loglik(x, lambda lam: arma_spectral_density([0.6], [], 1.0, lam))
assert abs(wh - exact) / n < 0.02
def test_whittle_estimate_agrees_with_exact_mle():
# Measured: r = 15 series of n = 256 from AR(1) with phi = 0.6, seed 6.
rng = random.Random(6)
diffs = []
for _ in range(15):
x = simulate_arma([0.6], [], 256, rng)
phi_w = whittle_fit_arma(x, 1, 0)[0][0]
diffs.append(abs(phi_w - ar1_exact_mle(x)))
assert sum(diffs) / len(diffs) < 0.02
def test_arma11_fit_is_causal_invertible_and_near_truth():
rng = random.Random(7)
x = simulate_arma([0.5], [0.4], 1024, rng)
phi, theta, s2 = whittle_fit_arma(x, 1, 1)
assert abs(phi[0]) < 1 and abs(theta[0]) < 1
# Asymptotic standard deviations are about 0.04 here; allow 4 of them.
assert abs(phi[0] - 0.5) < 0.16 and abs(theta[0] - 0.4) < 0.16
assert abs(s2 - 1.0) < 0.15
Exercises
- Show that for white noise, , the Whittle value with all frequencies equals the exact Gaussian . Hint: Parseval's identity gives .
- Derive the profiled scale and the profiled objective.
- Show that for . Hint: .
- Prove that the AR(1) Whittle estimate with known mean, without the term , is , and that .
- Show that the circulant with first row has eigenvalues .
References
- Peter Whittle, Estimation and information in stationary time series, Arkiv för Matematik 2(5), 1953, pp. 423 to 434 (the frequency-domain approximation of the Gaussian likelihood and the asymptotic information)
- Peter J. Brockwell and Richard A. Davis, Time Series: Theory and Methods, second edition, Springer, 1991, Section 10.3 (asymptotic properties of the periodogram, p. 342), Section 10.7 (the fast Fourier transform, p. 373) and Section 10.8 (asymptotic behaviour of the maximum likelihood and Whittle estimators of ARMA coefficients, p. 375)
- Peter J. Brockwell and Richard A. Davis, Introduction to Time Series and Forecasting, third edition, Springer, 2016, Section 4.2 (the periodogram, p. 106)
- Adam M. Sykulski, Sofia C. Olhede, Arthur P. Guillaumin, Jonathan M. Lilly and Jeffrey J. Early, The debiased Whittle likelihood, Biometrika 106(2), 2019, the expected periodogram in place of the spectral density, its O(n log n) computation, and the reduction of the small-sample bias
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 | W3 standard |
|
Tag F9TJBR Edit this page History Report an error Markdown