def rational_quadratic(alpha, lengthscale, kernel_variance, r):
    """
    The rational quadratic kernel as featured in equation 4.19 on pg. 86 of Rasmussen and Williams. The rational quadratic
    kernel can be seen as a scale mixture (an infinite sum) of squared exponential kernels with different characteristic lengthscales.

    :param alpha: as alpha goes to infinity the RQ kernel becomes the SQE kernel.
    :param lengthscale: the lengthscale
    :param kernel_variance: the kernel variance
    :param r: The absolute distance in input space
    :return: The kernel function evaluated at a list of values r.
    """

    fract = (r/lengthscale)**2 * 1/(2*alpha)
    k_rq = (1 + fract)**(-alpha)
    k_rq *= kernel_variance

    return k_rq