CosineKernel

class pmrf.stats.CosineKernel(period: Array | ndarray | bool | number | bool | int | float | complex, *, name: str | None = None, metadata: Any = None)

Bases: AbstractCovarianceKernel

Cosine kernel.

Models zero-mean oscillatory correlation with a single period, which can be negative. Unlike PeriodicKernel, the correlation goes to \(-1\) at half a period.

\[k(x_1, x_2) = \cos\left(\frac{2\pi\, \mathbf{1}^\top (x_1 - x_2)}{p}\right)\]

where \(p\) is the period.

For \(d\)-dimensional inputs the oscillation runs along the all-ones direction: the differences are summed, not combined into a Euclidean distance, since \(\cos(2\pi \lVert x_1 - x_2 \rVert / p)\) is not positive semi-definite for \(d > 1\).

Its Gram matrix has rank two, so it is singular on its own. Multiply by a decaying kernel (e.g. Matern52Kernel) for a damped oscillation, and by a float for its variance.

Parameters:

period (ArrayLike) – The period of the oscillation. A period of shape (D,) gives D batched kernels, as for PeriodicKernel.

__call__(x1, x2, key=None)

Evaluate the kernel between two points.

Parameters:
  • x1 (jnp.ndarray) – First input point.

  • x2 (jnp.ndarray) – Second input point.

  • key (jax.random.PRNGKey, optional) – Random key for stochastic kernels.

Returns:

Kernel covariance scalar.

Return type:

jnp.ndarray

period: Array | ndarray | bool | number | bool | int | float | complex

The period.