Search

Search papers and lessons

Spectral Mixture Kernel

Level 4 · 12 min read

The spectral mixture kernel is a covariance function built as a sum of cosines under Gaussian envelopes, so a Gaussian process can learn repeating patterns and extend them beyond the data.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Discrete math
  • Calculus
  • Inference
  • Stochastic processes
  • ReadReady to readNot yet

TL;DR

A Gaussian process model needs a kernel, a function that says how strongly two inputs should agree. The spectral mixture kernel is a kernel built from cosines multiplied by Gaussian envelopes, and its parameters are chosen so that the kernel's Fourier view matches a few frequency bumps. A model with this kernel can find repeating patterns in data and extend them past the last observation.

Builds on: Gaussian Process Regression, Kernel Function, Stationary Process, Fourier Transform · Leads to: Power Spectral Density (the same Fourier view, from the signal side)

Where it's used

Forecasting demand with cycles. A utility records electricity use every hour. The load has a daily cycle, a weekly cycle, and a slow drift that is not periodic. A team fitting a Gaussian process with a spectral mixture kernel can let the data choose the daily and weekly periods, then forecast the next several days with error bars that widen as the forecast moves away from the data.

Filling gaps in sensor records. A weather station goes offline for a day. A model that knows the record repeats every 24 hours can fill the gap from the same hours on other days, and it reports how uncertain the filled values are. A plain smooth kernel would simply fade toward the average in the gap.

Searching for periodic signals. An astronomer watching the brightness of a star sees dips that might repeat. The spectral mixture kernel has a frequency parameter for each component, so the fitted frequencies show which periods the data support. The model is a tool for finding candidate periods, which then need checking with other evidence.

How it works

Take the simplest case: one component, with weight 1, frequency μ=1/6\mu = 1/6 cycles per unit time, and spectral variance v=1/(4π2)v = 1/(4\pi^2). The kernel depends only on the time gap τ between two inputs. We want its values at τ = 0, 1 and 2.

  1. Write the component. The kernel is the weight times a Gaussian envelope times a cosine: k(τ)=exp⁡(−τ22)cos⁡(πτ3)k(\tau) = \exp(-\tfrac{\tau^2}{2}) \cos(\tfrac{\pi \tau}{3}). Here the cosine uses frequency 1/6, so 2π⋅16⋅τ=πτ32\pi \cdot \tfrac{1}{6} \cdot \tau = \tfrac{\pi \tau}{3}. Check: the parameters were chosen so that 2π2v=122\pi^2 v = \tfrac{1}{2}, which gives the envelope exp⁡(−τ22)\exp(-\tfrac{\tau^2}{2}).
  2. Evaluate at τ = 0. The envelope is exp⁡(0)=1\exp(0) = 1 and the cosine is cos⁡(0)=1\cos(0) = 1, so k(0)=1k(0) = 1. Check: a point always agrees with itself fully, and this is the prior variance.
  3. Evaluate at τ = 1. The envelope is exp⁡(−0.5)≈0.607\exp(-0.5) \approx 0.607 and the cosine is cos⁡(π/3)=0.5\cos(\pi/3) = 0.5. So k(1)≈0.607×0.5=0.303k(1) \approx 0.607 \times 0.5 = 0.303. Check: the value is positive, and it is smaller than k(0)k(0).
  4. Evaluate at τ = 2. The envelope is exp⁡(−2)≈0.135\exp(-2) \approx 0.135 and the cosine is cos⁡(2π/3)=−0.5\cos(2\pi/3) = -0.5. So k(2)≈−0.068k(2) \approx -0.068. Check: the sign has flipped, so inputs two units apart are negatively related. That is the cosine at work.
  5. Read the shape. The kernel starts at 1, falls, and turns negative, while the envelope shrinks it toward zero for large gaps. A single component is a wave whose height fades with distance.

The figure shows the same single-component kernel over a wider range of gaps.

−6−4−20246−0.500.51time gap taucovariance
  • one component
  • envelope
One spectral mixture component: a cosine of period 6 under a Gaussian envelope. The dashed curve is the envelope that shrinks the wave toward zero.

The math

Definition

A spectral mixture kernel with QQ components is

k(τ)=∑q=1Qwq exp⁡ ⁣(−2π2vqτ2)cos⁡ ⁣(2πμqτ),k(\tau) = \sum_{q=1}^{Q} w_q \, \exp\!\big(-2\pi^2 v_q \tau^2\big) \cos\!\big(2\pi \mu_q \tau\big),

where τ=x−x′\tau = x - x' is the gap between two inputs, wq≥0w_q \geq 0 is the weight of component qq, μq\mu_q is its frequency (the centre of the spectral bump), and vq>0v_q > 0 is its spectral variance. The kernel is stationary: it depends only on τ\tau, as required by stationarity.

Step 1 in symbols: the envelope and the wave

Each term is a product of two pieces. The Gaussian envelope exp⁡(−2π2vqτ2)\exp(-2\pi^2 v_q \tau^2) decays with the gap, and the cosine cos⁡(2πμqτ)\cos(2\pi \mu_q \tau) oscillates with period 1/μq1/\mu_q. The length scale of the envelope is ℓq=1/(2πvq)\ell_q = 1/(2\pi\sqrt{v_q}), because exp⁡(−2π2vqτ2)=exp⁡(−τ2/(2ℓq2))\exp(-2\pi^2 v_q \tau^2) = \exp(-\tau^2/(2\ell_q^2)). Check: this is the same envelope as a squared-exponential kernel with length scale ℓq\ell_q.

Step 2 in symbols: the spectral density

The Fourier view of a stationary kernel is its spectral density S(ω)S(\omega), linked to the kernel by k(τ)=∫S(ω) e2πiωτ dωk(\tau) = \int S(\omega)\, e^{2\pi i \omega \tau}\, d\omega, the form the Wiener-Khinchin relation takes for a stationary process. For the spectral mixture kernel,

S(ω)=∑q=1Qwq2[N(ω; μq,vq)+N(ω; −μq,vq)],S(\omega) = \sum_{q=1}^{Q} \frac{w_q}{2}\Big[\mathcal{N}(\omega;\, \mu_q, v_q) + \mathcal{N}(\omega;\, -\mu_q, v_q)\Big],

where N(ω;m,v)\mathcal{N}(\omega; m, v) is a normal density in ω\omega with mean mm and variance vv. Each component is a pair of Gaussian bumps, one at +μq+\mu_q and one at −μq-\mu_q, which is why the kernel is symmetric in τ\tau.

Step 3 in symbols: why the two views agree

The characteristic function of a normal variable with mean mm and variance vv is E[eitX]=eitm−t2v/2\mathbb{E}[e^{itX}] = e^{itm - t^2 v/2}. Put t=2πτt = 2\pi\tau and m=μm = \mu, and you get

∫N(ω; μ,v) e2πiωτ dω=e2πiμτ e−2π2vτ2.\int \mathcal{N}(\omega;\, \mu, v)\, e^{2\pi i \omega \tau}\, d\omega = e^{2\pi i \mu \tau}\, e^{-2\pi^2 v \tau^2}.

Add the mirror bump at −μ-\mu, which gives e−2πiμτe^{-2\pi i \mu \tau}, and the two terms combine as w2(e2πiμτ+e−2πiμτ)=wcos⁡(2πμτ)\tfrac{w}{2}(e^{2\pi i \mu\tau} + e^{-2\pi i \mu\tau}) = w\cos(2\pi\mu\tau). The envelope comes out unchanged. So the kernel and its spectral density are a Fourier pair, as the formula in step 2 claims.

Step 4 in symbols: the prior variance and validity

Setting τ=0\tau = 0 gives k(0)=∑qwqk(0) = \sum_q w_q. This is the prior variance of every function value. Validity follows from step 2: because the weights are nonnegative and each spectral bump is a density, S(ω)≥0S(\omega) \geq 0, and a stationary kernel with a nonnegative spectral density is positive semidefinite. That is what lets it stand in for a covariance function, as described in Kernel Function.

Step 5 in symbols: the Gaussian process prediction

With the kernel built, the model is an ordinary Gaussian Process Regression. For training inputs XX with values y\mathbf{y}, noise variance σ2\sigma^2, and test input x∗x_*, the predictive mean is μ∗=k∗T(K+σ2I)−1y\mu_* = \mathbf{k}_*^{T}(K + \sigma^2 I)^{-1}\mathbf{y}, and the predictive variance is k(x∗,x∗)−k∗T(K+σ2I)−1k∗k(x_*, x_*) - \mathbf{k}_*^{T}(K + \sigma^2 I)^{-1}\mathbf{k}_*, where KK holds k(xi−xj)k(x_i - x_j) and k∗\mathbf{k}_* holds k(x∗−xi)k(x_* - x_i). The kernel's periodic part makes the mean repeat, and the envelope makes the variance grow with the distance from the data.

Worked examples

Example
1. One component, tiny numbers
  1. Kernel: k(τ)=exp⁡(−τ2/2)cos⁡(πτ/3)k(\tau) = \exp(-\tau^2/2)\cos(\pi\tau/3), with weight 1.
  2. At τ=0\tau = 0: exp⁡(0)cos⁡(0)=1\exp(0)\cos(0) = 1.
  3. At τ=1\tau = 1: exp⁡(−0.5)cos⁡(π/3)=0.607×0.5=0.303\exp(-0.5)\cos(\pi/3) = 0.607 \times 0.5 = 0.303.
  4. At τ=2\tau = 2: exp⁡(−2)cos⁡(2π/3)=0.135×(−0.5)=−0.068\exp(-2)\cos(2\pi/3) = 0.135 \times (-0.5) = -0.068.
  5. Interpretation: points one unit apart agree moderately, and points two units apart disagree a little. The period of the wave is 6, so the pattern repeats only after 6 units, and the envelope keeps the repeat weak.
Example
2. Two components (standard case)

Take two components with the same envelope exp⁡(−τ2/2)\exp(-\tau^2/2). Component 1 has weight 1 and frequency 1/6. Component 2 has weight 0.5 and frequency 1 (period 1). The kernel is

k(τ)=exp⁡ ⁣(−τ22)[cos⁡ ⁣(πτ3)+0.5cos⁡(2πτ)].k(\tau) = \exp\!\big(-\tfrac{\tau^2}{2}\big)\Big[\cos\!\big(\tfrac{\pi\tau}{3}\big) + 0.5\cos(2\pi\tau)\Big].
  1. At τ=0\tau = 0: the bracket is 1+0.5=1.51 + 0.5 = 1.5 and the envelope is 1, so k(0)=1.5k(0) = 1.5. Check: this equals w1+w2=1.5w_1 + w_2 = 1.5, the prior variance from step 4.
  2. At τ=1\tau = 1: the envelope is 0.6070.607. The bracket is cos⁡(π/3)+0.5cos⁡(2π)=0.5+0.5=1\cos(\pi/3) + 0.5\cos(2\pi) = 0.5 + 0.5 = 1. So k(1)=0.607k(1) = 0.607.
  3. At τ=2\tau = 2: the envelope is exp⁡(−2)=0.135\exp(-2) = 0.135. The bracket is cos⁡(2π/3)+0.5cos⁡(4π)=−0.5+0.5=0\cos(2\pi/3) + 0.5\cos(4\pi) = -0.5 + 0.5 = 0. So k(2)=0k(2) = 0.
  4. Interpretation: component 2 repeats at every whole unit, and component 1 cancels it at two units. Two inputs two units apart are uncorrelated here, while one unit apart they are moderately correlated: k(1)/k(0)=0.607/1.5≈0.4k(1) / k(0) = 0.607 / 1.5 \approx 0.4.
Example
3. A realistic hourly sensor

An hourly temperature sensor shows a daily cycle, a weekly pattern, and no long-term trend. The fitted model has two components. Component 1 has weight 1, frequency 1/24 cycles per hour, and spectral variance v1=10−4v_1 = 10^{-4}. Component 2 has weight 0.2, frequency 1/168 cycles per hour, and spectral variance v2=10−5v_2 = 10^{-5}. We evaluate the covariance between a reading now and one 24 hours earlier.

  1. The envelope of component 1 at τ=24\tau = 24: 2π2v1τ2=2π2×10−4×576≈1.1372\pi^2 v_1 \tau^2 = 2\pi^2 \times 10^{-4} \times 576 \approx 1.137, so the envelope is exp⁡(−1.137)≈0.321\exp(-1.137) \approx 0.321.
  2. Its cosine at τ=24\tau = 24: cos⁡(2π×24/24)=cos⁡(2π)=1\cos(2\pi \times 24/24) = \cos(2\pi) = 1. Its contribution is 1×0.321×1=0.3211 \times 0.321 \times 1 = 0.321.
  3. The envelope of component 2 at τ=24\tau = 24: 2π2×10−5×576≈0.1142\pi^2 \times 10^{-5} \times 576 \approx 0.114, so the envelope is exp⁡(−0.114)≈0.893\exp(-0.114) \approx 0.893.
  4. Its cosine at τ=24\tau = 24: cos⁡(2π×24/168)=cos⁡(2π/7)≈0.623\cos(2\pi \times 24/168) = \cos(2\pi/7) \approx 0.623. Its contribution is 0.2×0.893×0.623≈0.1110.2 \times 0.893 \times 0.623 \approx 0.111.
  5. Total: k(24)≈0.321+0.111=0.432k(24) \approx 0.321 + 0.111 = 0.432. The prior variance is k(0)=1+0.2=1.2k(0) = 1 + 0.2 = 1.2, so the correlation at a 24-hour gap is 0.432/1.2≈0.360.432 / 1.2 \approx 0.36.
  6. Interpretation: a reading now is moderately related to the reading at the same hour yesterday. The daily component carries most of the relation, and the weekly one adds a little.

Try it: using the same two components, what is k(168)k(168), the covariance one week apart? Answer: component 1 gives 2π2×10−4×1682≈55.72\pi^2 \times 10^{-4} \times 168^2 \approx 55.7, so its envelope is essentially zero. Component 2 gives 2π2×10−5×1682≈5.572\pi^2 \times 10^{-5} \times 168^2 \approx 5.57, so its envelope is exp⁡(−5.57)≈0.0038\exp(-5.57) \approx 0.0038, and its cosine is cos⁡(2π)=1\cos(2\pi) = 1. Then k(168)≈0.2×0.0038=0.0008k(168) \approx 0.2 \times 0.0038 = 0.0008, which is close to zero. The model says that a week later the readings are unrelated, because these parameters let the weekly wave fade within a few days.

Common mistakes and tradeoffs

It is tempting to think that a cosine kernel makes a model predict a perfect repeat forever. In fact the Gaussian envelope always shrinks the repeat with distance, and the length scale ℓq=1/(2πvq)\ell_q = 1/(2\pi\sqrt{v_q}) sets how fast. A large spectral variance gives a short length scale, and the pattern is forgotten quickly. Extrapolation far beyond the data relies on small spectral variances, which the data must support.

It is tempting to think that more components always help. In fact each component adds frequency, weight and variance parameters, and the marginal likelihood used to fit them can have many local optima. With few data points, extra components fit noise and extrapolate badly. Start with one or two components, and add more only if the fit and the held-out data both improve.

It is tempting to think the frequencies μq\mu_q are periods you can read off directly. In fact a sharp μq\mu_q is only as good as the data behind it. Short records give broad or unreliable frequency estimates, and the kernel can place a frequency at an alias of the true one when the sampling is coarse.

Use this kernel when the signal is smooth, stationary, and has one or more repeating patterns of unknown period. Do not use it when the series has a clear trend, since a trend needs its own term or a non-stationary kernel, or when the data are too few to pin down the frequencies. Simpler alternatives are the squared-exponential kernel, which assumes smoothness only, and a single periodic kernel with a fixed period when the period is known in advance.

History

Gaussian process models were long used in geostatistics and in machine learning, with kernels chosen by hand for smoothness. The standard references, such as the 2006 book by Rasmussen and Williams, showed how to fit kernel hyperparameters by maximising the marginal likelihood, but the kernels in common use were stationary and smooth without a built-in notion of repeating structure. In 2013 Andrew Wilson and Ryan Adams proposed the spectral mixture kernel in a paper at the International Conference on Machine Learning. Their idea was to write the kernel through its spectral density, as a mixture of Gaussian bumps, so that the data could reveal periodic structure and the model could extrapolate it. The idea caught on because it turned an opaque kernel choice into a few interpretable frequencies and widths.

Recap

  • A stationary kernel is equivalent to a spectral density: the Fourier transform of one is the other.
  • The spectral mixture kernel makes that density a sum of Gaussian bumps at chosen frequencies, which gives a sum of Gaussian-enveloped cosines in the time domain.
  • Each component has a frequency for the repeat, a spectral variance that sets the length scale of the envelope, and a weight that sets its share of the prior variance.
  • Plugged into a Gaussian process, the kernel gives predictions that repeat where the data repeat and widen their error bars away from the data.

Read next: Power Spectral Density, for the signal-side view of the same spectrum, and Marginal Likelihood, which is how the frequencies and widths are fitted.

Check yourself

QuestionA spectral mixture component has weight 2 and spectral variance v=0v = 0. Why is that not allowed, and what goes wrong?Show answer
The variance must be positive because each spectral bump is a Gaussian density with variance vv, and a Gaussian density needs v>0v > 0. With v=0v = 0 the envelope exp⁡(−2π2vτ2)\exp(-2\pi^2 v\tau^2) is 1 for every gap, so the component is a pure cosine that never decays. That is a valid periodic kernel, but it is no longer a spectral mixture component, and the model can no longer express the fading that lets it extrapolate.
QuestionA kernel has two components with weights 0.7 and 0.3. What is the prior variance of each function value, and why?Show answer
The prior variance is k(0)=w1+w2=0.7+0.3=1.0k(0) = w_1 + w_2 = 0.7 + 0.3 = 1.0. At gap zero each cosine is 1 and each envelope is 1, so every component contributes its weight.
QuestionCompute exp⁡(−2π2vτ2)\exp(-2\pi^2 v\tau^2) for v=0.001v = 0.001 and τ=5\tau = 5, to two decimal places.Show answer
The exponent is 2π2×0.001×25=2π2×0.025≈0.49352\pi^2 \times 0.001 \times 25 = 2\pi^2 \times 0.025 \approx 0.4935. So the envelope is exp⁡(−0.4935)≈0.61\exp(-0.4935) \approx 0.61.
QuestionWhy does a spectral mixture kernel extrapolate a repeating pattern, rather than only interpolate between the data?Show answer
The cosine part is defined at every gap, so it predicts a repeat at any distance. The envelope fades that repeat, so the prediction far from the data reverts toward the mean with growing uncertainty. The model keeps the periodic shape while accounting for how much the pattern can be trusted at that distance.
QuestionIn a realistic fit, the daily component has a large weight but the model still shows near-zero correlation a week apart. Explain how the envelope and the cosine both contribute to this.Show answer
The daily component's envelope is tiny at a 168-hour gap, so its large weight does not survive. The weekly component's cosine is 1 at that gap, but its envelope has also shrunk, so the total correlation is small. The envelopes, not the weights, decide whether a repeat still counts a week later.

Sources