question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Periodic kernel for multivariate input

See original GitHub issue

🐛 Bug

Implementation of PeriodicKernel is not positive definite in case of multivariate input Here is how I checked it:

** Code snippet to reproduce **

import torch
from gpytorch import kernels

X = torch.randn(1000, 2, dtype=torch.float64)
kernel = kernels.PeriodicKernel().double()
with torch.no_grad():
    K = kernel(X, X).evaluate()
    eig = torch.symeig(K)[0]

    negative_eig = eig[eig < 0]
    assert torch.allclose(negative_eig, torch.zeros_like(negative_eig))

** Stack trace/error message **

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-2-1d738d7c73d9> in <module>
      9 
     10     negative_eig = eig[eig < 0]
---> 11     assert torch.allclose(negative_eig, torch.zeros_like(negative_eig))

AssertionError: 

Expected Behavior

Positive definite kernel must have non-negative eigenvalues.

The implementation is correct for one-dimensional input. For multidimensional input it should be product of one-dimensional kernels, however, it calculates the norm first and applies sine and exponent to the norm which is not correct: see eq. (47) on page 15 of

MacKay, D. J. (1998). Introduction to Gaussian processes. NATO ASI Series F Computer and Systems Sciences, 168, 133-166.

System information

Please complete the following information:

  • gpytorch=0.3.4
  • torch=1.1.0
  • Ubuntu 19.04

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jacobrgardnercommented, Aug 10, 2019

The periodic kernel is by definition a kernel defined in 1D. To extend to multiple dimensions use e.g. ProductKernel

0reactions
gpleisscommented, Apr 26, 2021

@tawe141 I don’t think we ever got around to this. If you’re interested and willing, we’d love a PR from you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kernel Cookbook
A reference manual for creating covariance functions.
Read more >
Analytic Long Term Forecasting with Periodic Gaussian ...
The Gaussian process models can account for the periodicity by using a periodic kernel. Long term predictions need to deal with uncertain points,...
Read more >
Gaussian processes (3/3) - exploring kernels
The local periodic kernel is a multiplication of the periodic kernel with the exponentiated quadratic kernel to allow the periods to vary over...
Read more >
21 : Advanced Gaussian Processes
kernel function is valid for a GP. A stationary kernel function is invariant under translations of the input space, i.e. it is a...
Read more >
Gaussian process kernels - Towards Data Science
Perhaps the most widely used kernel is probably the radial basis function kernel (also called the quadratic exponential kernel, the squared exponential kernel ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found