https://github.com/GPflow/GPflow
Raw File
Tip revision: d95ef8222e567f4d0e0d8ea99ea64359b9b5ea48 authored by Sergio Diaz on 09 September 2019, 12:51:16 UTC
Merge branch 'awav/gpflow-2.0' into sergio_pasc/gpflow-2.0/move-gplvm-tests
Tip revision: d95ef82
kuus.py
import tensorflow as tf

from ..inducing_variables import InducingPoints, Multiscale
from ..kernels import Kernel, SquaredExponential
from .dispatch import Kuu


@Kuu.register(InducingPoints, Kernel)
def _Kuu(inducing_variable: InducingPoints, kernel: Kernel, *, jitter=0.0):
    Kzz = kernel(inducing_variable.Z)
    Kzz += jitter * tf.eye(len(inducing_variable), dtype=Kzz.dtype)
    return Kzz


@Kuu.register(Multiscale, SquaredExponential)
def _Kuu(inducing_variable: Multiscale, kernel: SquaredExponential, *, jitter=0.0):
    Zmu, Zlen = kernel.slice(inducing_variable.Z, inducing_variable.scales)
    idlengthscale2 = tf.square(kernel.lengthscale + Zlen)
    sc = tf.sqrt(idlengthscale2[None, ...] + idlengthscale2[:, None, ...] -
                 kernel.lengthscale**2)
    d = inducing_variable._cust_square_dist(Zmu, Zmu, sc)
    Kzz = kernel.variance * tf.exp(-d / 2) * tf.reduce_prod(
        kernel.lengthscale / sc, 2)
    Kzz += jitter * tf.eye(len(inducing_variable), dtype=Kzz.dtype)
    return Kzz
back to top